Merge "Disable keyguard text marquee when the display turns off." into klp-dev
diff --git a/api/current.txt b/api/current.txt
index 548433e..9251d39 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -7255,6 +7255,7 @@
method public abstract java.util.List<android.content.pm.InstrumentationInfo> queryInstrumentation(java.lang.String, int);
method public abstract java.util.List<android.content.pm.ResolveInfo> queryIntentActivities(android.content.Intent, int);
method public abstract java.util.List<android.content.pm.ResolveInfo> queryIntentActivityOptions(android.content.ComponentName, android.content.Intent[], android.content.Intent, int);
+ method public abstract java.util.List<android.content.pm.ResolveInfo> queryIntentContentProviders(android.content.Intent, int);
method public abstract java.util.List<android.content.pm.ResolveInfo> queryIntentServices(android.content.Intent, int);
method public abstract java.util.List<android.content.pm.PermissionInfo> queryPermissionsByGroup(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
method public abstract deprecated void removePackageFromPreferred(java.lang.String);
@@ -7420,6 +7421,7 @@
ctor public ProviderInfo();
ctor public ProviderInfo(android.content.pm.ProviderInfo);
method public int describeContents();
+ method public void dump(android.util.Printer, java.lang.String);
field public static final android.os.Parcelable.Creator CREATOR;
field public static final int FLAG_SINGLE_USER = 1073741824; // 0x40000000
field public java.lang.String authority;
@@ -7453,6 +7455,7 @@
field public java.lang.CharSequence nonLocalizedLabel;
field public int preferredOrder;
field public int priority;
+ field public android.content.pm.ProviderInfo providerInfo;
field public java.lang.String resolvePackageName;
field public android.content.pm.ServiceInfo serviceInfo;
field public int specificIndex;
@@ -20982,6 +20985,7 @@
field public static final java.lang.String EXTRA_ERROR = "error";
field public static final java.lang.String EXTRA_INFO = "info";
field public static final java.lang.String EXTRA_LOADING = "loading";
+ field public static final java.lang.String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER";
}
public static final class DocumentsContract.Document {
@@ -24477,6 +24481,7 @@
method public java.util.List<android.content.pm.InstrumentationInfo> queryInstrumentation(java.lang.String, int);
method public java.util.List<android.content.pm.ResolveInfo> queryIntentActivities(android.content.Intent, int);
method public java.util.List<android.content.pm.ResolveInfo> queryIntentActivityOptions(android.content.ComponentName, android.content.Intent[], android.content.Intent, int);
+ method public java.util.List<android.content.pm.ResolveInfo> queryIntentContentProviders(android.content.Intent, int);
method public java.util.List<android.content.pm.ResolveInfo> queryIntentServices(android.content.Intent, int);
method public java.util.List<android.content.pm.PermissionInfo> queryPermissionsByGroup(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
method public void removePackageFromPreferred(java.lang.String);
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 55c66726..b505d4f 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -585,6 +585,22 @@
}
@Override
+ public List<ResolveInfo> queryIntentContentProvidersAsUser(
+ Intent intent, int flags, int userId) {
+ try {
+ return mPM.queryIntentContentProviders(intent,
+ intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
+ } catch (RemoteException e) {
+ throw new RuntimeException("Package manager has died", e);
+ }
+ }
+
+ @Override
+ public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
+ return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
+ }
+
+ @Override
public ProviderInfo resolveContentProvider(String name,
int flags) {
try {
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index acd4ffa..267fb2a 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -123,6 +123,9 @@
List<ResolveInfo> queryIntentServices(in Intent intent,
String resolvedType, int flags, int userId);
+ List<ResolveInfo> queryIntentContentProviders(in Intent intent,
+ String resolvedType, int flags, int userId);
+
/**
* This implements getInstalledPackages via a "last returned row"
* mechanism that is not exposed in the API. This is to get around the IPC
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index b63db8a..8b8c58b 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -2210,6 +2210,24 @@
public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent,
int flags, int userId);
+ /** {@hide} */
+ public abstract List<ResolveInfo> queryIntentContentProvidersAsUser(
+ Intent intent, int flags, int userId);
+
+ /**
+ * Retrieve all providers that can match the given intent.
+ *
+ * @param intent An intent containing all of the desired specification
+ * (action, data, type, category, and/or component).
+ * @param flags Additional option flags.
+ * @return A List<ResolveInfo> containing one entry for each matching
+ * ProviderInfo. These are ordered from best to worst match. If
+ * there are no matching providers, an empty list is returned.
+ * @see #GET_INTENT_FILTERS
+ * @see #GET_RESOLVED_FILTER
+ */
+ public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags);
+
/**
* Find a single content provider by its base path name.
*
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index b489ee9e..17d13e5 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -2819,7 +2819,14 @@
continue;
}
- if (parser.getName().equals("meta-data")) {
+ if (parser.getName().equals("intent-filter")) {
+ ProviderIntentInfo intent = new ProviderIntentInfo(outInfo);
+ if (!parseIntent(res, parser, attrs, true, intent, outError)) {
+ return false;
+ }
+ outInfo.intents.add(intent);
+
+ } else if (parser.getName().equals("meta-data")) {
if ((outInfo.metaData=parseMetaData(res, parser, attrs,
outInfo.metaData, outError)) == null) {
return false;
@@ -3982,7 +3989,7 @@
return si;
}
- public final static class Provider extends Component {
+ public final static class Provider extends Component<ProviderIntentInfo> {
public final ProviderInfo info;
public boolean syncable;
@@ -4116,6 +4123,24 @@
}
}
+ public static final class ProviderIntentInfo extends IntentInfo {
+ public final Provider provider;
+
+ public ProviderIntentInfo(Provider provider) {
+ this.provider = provider;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("ProviderIntentInfo{");
+ sb.append(Integer.toHexString(System.identityHashCode(this)));
+ sb.append(' ');
+ provider.appendComponentShortName(sb);
+ sb.append('}');
+ return sb.toString();
+ }
+ }
+
/**
* @hide
*/
diff --git a/core/java/android/content/pm/ProviderInfo.java b/core/java/android/content/pm/ProviderInfo.java
index a534176..f6ea058 100644
--- a/core/java/android/content/pm/ProviderInfo.java
+++ b/core/java/android/content/pm/ProviderInfo.java
@@ -19,6 +19,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PatternMatcher;
+import android.util.Printer;
/**
* Holds information about a specific
@@ -112,7 +113,13 @@
flags = orig.flags;
isSyncable = orig.isSyncable;
}
-
+
+ public void dump(Printer pw, String prefix) {
+ super.dumpFront(pw, prefix);
+ pw.println(prefix + "authority=" + authority);
+ pw.println(prefix + "flags=0x" + Integer.toHexString(flags));
+ }
+
public int describeContents() {
return 0;
}
diff --git a/core/java/android/content/pm/ResolveInfo.java b/core/java/android/content/pm/ResolveInfo.java
index e360e40..1ff41c0 100644
--- a/core/java/android/content/pm/ResolveInfo.java
+++ b/core/java/android/content/pm/ResolveInfo.java
@@ -23,6 +23,7 @@
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Printer;
+import android.util.Slog;
import java.text.Collator;
import java.util.Comparator;
@@ -34,20 +35,30 @@
* <intent> tags.
*/
public class ResolveInfo implements Parcelable {
+ private static final String TAG = "ResolveInfo";
+
/**
- * The activity or broadcast receiver that corresponds to this resolution match,
- * if this resolution is for an activity or broadcast receiver. One and only one of this and
- * serviceInfo must be non-null.
+ * The activity or broadcast receiver that corresponds to this resolution
+ * match, if this resolution is for an activity or broadcast receiver.
+ * Exactly one of {@link #activityInfo}, {@link #serviceInfo}, or
+ * {@link #providerInfo} will be non-null.
*/
public ActivityInfo activityInfo;
/**
- * The service that corresponds to this resolution match, if this
- * resolution is for a service. One and only one of this and
- * activityInfo must be non-null.
+ * The service that corresponds to this resolution match, if this resolution
+ * is for a service. Exactly one of {@link #activityInfo},
+ * {@link #serviceInfo}, or {@link #providerInfo} will be non-null.
*/
public ServiceInfo serviceInfo;
-
+
+ /**
+ * The provider that corresponds to this resolution match, if this
+ * resolution is for a provider. Exactly one of {@link #activityInfo},
+ * {@link #serviceInfo}, or {@link #providerInfo} will be non-null.
+ */
+ public ProviderInfo providerInfo;
+
/**
* The IntentFilter that was matched for this ResolveInfo.
*/
@@ -120,6 +131,13 @@
*/
public boolean system;
+ private ComponentInfo getComponentInfo() {
+ if (activityInfo != null) return activityInfo;
+ if (serviceInfo != null) return serviceInfo;
+ if (providerInfo != null) return providerInfo;
+ throw new IllegalStateException("Missing ComponentInfo!");
+ }
+
/**
* Retrieve the current textual label associated with this resolution. This
* will call back on the given PackageManager to load the label from
@@ -142,7 +160,7 @@
return label.toString().trim();
}
}
- ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
+ ComponentInfo ci = getComponentInfo();
ApplicationInfo ai = ci.applicationInfo;
if (labelRes != 0) {
label = pm.getText(ci.packageName, labelRes, ai);
@@ -176,7 +194,7 @@
return dr;
}
}
- ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
+ ComponentInfo ci = getComponentInfo();
ApplicationInfo ai = ci.applicationInfo;
if (icon != 0) {
dr = pm.getDrawable(ci.packageName, icon, ai);
@@ -196,8 +214,8 @@
*/
public final int getIconResource() {
if (icon != 0) return icon;
- if (activityInfo != null) return activityInfo.getIconResource();
- if (serviceInfo != null) return serviceInfo.getIconResource();
+ final ComponentInfo ci = getComponentInfo();
+ if (ci != null) return ci.getIconResource();
return 0;
}
@@ -225,6 +243,9 @@
} else if (serviceInfo != null) {
pw.println(prefix + "ServiceInfo:");
serviceInfo.dump(pw, prefix + " ");
+ } else if (providerInfo != null) {
+ pw.println(prefix + "ProviderInfo:");
+ providerInfo.dump(pw, prefix + " ");
}
}
@@ -234,6 +255,7 @@
public ResolveInfo(ResolveInfo orig) {
activityInfo = orig.activityInfo;
serviceInfo = orig.serviceInfo;
+ providerInfo = orig.providerInfo;
filter = orig.filter;
priority = orig.priority;
preferredOrder = orig.preferredOrder;
@@ -247,7 +269,7 @@
}
public String toString() {
- ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
+ final ComponentInfo ci = getComponentInfo();
StringBuilder sb = new StringBuilder(128);
sb.append("ResolveInfo{");
sb.append(Integer.toHexString(System.identityHashCode(this)));
@@ -278,6 +300,9 @@
} else if (serviceInfo != null) {
dest.writeInt(2);
serviceInfo.writeToParcel(dest, parcelableFlags);
+ } else if (providerInfo != null) {
+ dest.writeInt(3);
+ providerInfo.writeToParcel(dest, parcelableFlags);
} else {
dest.writeInt(0);
}
@@ -309,18 +334,21 @@
};
private ResolveInfo(Parcel source) {
+ activityInfo = null;
+ serviceInfo = null;
+ providerInfo = null;
switch (source.readInt()) {
case 1:
activityInfo = ActivityInfo.CREATOR.createFromParcel(source);
- serviceInfo = null;
break;
case 2:
serviceInfo = ServiceInfo.CREATOR.createFromParcel(source);
- activityInfo = null;
+ break;
+ case 3:
+ providerInfo = ProviderInfo.CREATOR.createFromParcel(source);
break;
default:
- activityInfo = null;
- serviceInfo = null;
+ Slog.w(TAG, "Missing ComponentInfo!");
break;
}
if (source.readInt() != 0) {
diff --git a/core/java/android/hardware/camera2/CameraDevice.java b/core/java/android/hardware/camera2/CameraDevice.java
index a9a72b0..7095e4d 100644
--- a/core/java/android/hardware/camera2/CameraDevice.java
+++ b/core/java/android/hardware/camera2/CameraDevice.java
@@ -197,26 +197,33 @@
* if the format is user-visible, it must be one of android.scaler.availableFormats;
* and the size must be one of android.scaler.available[Processed|Jpeg]Sizes).</p>
*
- * <p>To change the output, the camera device must be idle. The device is considered
- * to be idle once all in-flight and pending capture requests have been processed,
- * and all output image buffers from the captures have been sent to their destination
- * Surfaces.</p>
+ * <p>When this method is called with valid Surfaces, the device will transition to the {@link
+ * StateListener#onBusy busy state}. Once configuration is complete, the device will transition
+ * into the {@link StateListener#onIdle idle state}. Capture requests using the newly-configured
+ * Surfaces may then be submitted with {@link #capture}, {@link #captureBurst}, {@link
+ * #setRepeatingRequest}, or {@link #setRepeatingBurst}.</p>
*
- * <p>To reach an idle state without cancelling any submitted captures, first
- * stop any repeating request/burst with {@link #stopRepeating}, and then
- * wait for the {@link StateListener#onIdle} callback to be
- * called. To idle as fast as possible, use {@link #flush} and wait for the
- * idle callback.</p>
+ * <p>If this method is called while the camera device is still actively processing previously
+ * submitted captures, then the following sequence of events occurs: The device transitions to
+ * the busy state and calls the {@link StateListener#onBusy} callback. Second, if a repeating
+ * request is set it is cleared. Third, the device finishes up all in-flight and pending
+ * requests. Finally, once the device is idle, it then reconfigures its outputs, and calls the
+ * {@link StateListener#onIdle} method once it is again ready to accept capture
+ * requests. Therefore, no submitted work is discarded. To idle as fast as possible, use {@link
+ * #flush} and wait for the idle callback before calling configureOutputs. This will discard
+ * work, but reaches the new configuration sooner.</p>
*
* <p>Using larger resolution outputs, or more outputs, can result in slower
* output rate from the device.</p>
*
- * <p>Configuring the outputs with an empty or null list will transition
- * the camera into an {@link StateListener#onUnconfigured unconfigured state}.
- * </p>
+ * <p>Configuring the outputs with an empty or null list will transition the camera into an
+ * {@link StateListener#onUnconfigured unconfigured state} instead of the {@link
+ * StateListener#onIdle idle state}. </p>
*
* <p>Calling configureOutputs with the same arguments as the last call to
- * configureOutputs has no effect.</p>
+ * configureOutputs has no effect, and the {@link StateListener#onBusy busy}
+ * and {@link StateListener#onIdle idle} state transitions will happen
+ * immediately.</p>
*
* @param outputs The new set of Surfaces that should be made available as
* targets for captured image data.
@@ -228,7 +235,10 @@
* @throws IllegalStateException if the camera device is not idle, or
* if the camera device has been closed
*
+ * @see StateListener#onBusy
* @see StateListener#onIdle
+ * @see StateListener#onActive
+ * @see StateListener#onUnconfigured
* @see #stopRepeating
* @see #flush
*/
@@ -516,31 +526,6 @@
public void waitUntilIdle() throws CameraAccessException;
/**
- * Set the listener object to call when an asynchronous device event occurs,
- * such as errors or idle notifications.
- *
- * <p>The events reported here are device-wide; notifications about
- * individual capture requests or capture results are reported through
- * {@link CaptureListener}.</p>
- *
- * <p>If the camera device is idle when the listener is set, then the
- * {@link StateListener#onIdle} method will be immediately called,
- * even if the device has never been active before.
- * </p>
- *
- * @param listener the CameraDeviceListener to send device-level event
- * notifications to. Setting this to null will stop notifications.
- * @param handler the handler on which the listener should be invoked, or
- * {@code null} to use the current thread's {@link android.os.Looper looper}.
- *
- * @throws IllegalArgumentException if handler is null, the listener is
- * not null, and the calling thread has no looper
- *
- * @hide
- */
- public void setDeviceListener(StateListener listener, Handler handler);
-
- /**
* Flush all captures currently pending and in-progress as fast as
* possible.
*
@@ -577,13 +562,24 @@
public void flush() throws CameraAccessException;
/**
- * Close the connection to this camera device. After this call, all calls to
+ * Close the connection to this camera device.
+ *
+ * <p>After this call, all calls to
* the camera device interface will throw a {@link IllegalStateException},
- * except for calls to close().
+ * except for calls to close(). Once the device has fully shut down, the
+ * {@link StateListener#onClosed} callback will be called, and the camera is
+ * free to be re-opened.</p>
+ *
+ * <p>After this call, besides the final {@link StateListener#onClosed} call, no calls to the
+ * device's {@link StateListener} will occur, and any remaining submitted capture requests will
+ * not fire their {@link CaptureListener} callbacks.</p>
+ *
+ * <p>To shut down as fast as possible, call the {@link #flush} method and then {@link #close}
+ * once the flush completes. This will discard some capture requests, but results in faster
+ * shutdown.</p>
*/
@Override
public void close();
- // TODO: We should decide on the behavior of in-flight requests should be on close.
/**
* <p>A listener for tracking the progress of a {@link CaptureRequest}
@@ -713,6 +709,9 @@
* A listener for notifications about the state of a camera
* device.
*
+ * <p>A listener must be provided to the {@link CameraManager#openCamera}
+ * method to open a camera device.</p>
+ *
* <p>These events include notifications about the device becoming idle (
* allowing for {@link #configureOutputs} to be called), about device
* disconnection, and about unexpected device errors.</p>
@@ -722,7 +721,7 @@
* the {@link #capture}, {@link #captureBurst}, {@link
* #setRepeatingRequest}, or {@link #setRepeatingBurst} methods.
*
- * @see #setDeviceListener
+ * @see CameraManager#openCamera
*/
public static abstract class StateListener {
/**
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index f5ee367..65b6c7a 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -197,6 +197,8 @@
* {@link #openCamera}.
*
* @param cameraId The unique identifier of the camera device to open
+ * @param listener The listener for the camera. Must not be null.
+ * @param handler The handler to call the listener on. Must not be null.
*
* @throws CameraAccessException if the camera is disabled by device policy,
* or too many camera devices are already open, or the cameraId does not match
@@ -204,11 +206,14 @@
*
* @throws SecurityException if the application does not have permission to
* access the camera
+ * @throws IllegalArgumentException if listener or handler is null.
*
* @see #getCameraIdList
* @see android.app.admin.DevicePolicyManager#setCameraDisabled
*/
- private CameraDevice openCamera(String cameraId) throws CameraAccessException {
+ private void openCameraDeviceUserAsync(String cameraId,
+ CameraDevice.StateListener listener, Handler handler)
+ throws CameraAccessException {
try {
synchronized (mLock) {
@@ -216,7 +221,10 @@
ICameraDeviceUser cameraUser;
android.hardware.camera2.impl.CameraDevice device =
- new android.hardware.camera2.impl.CameraDevice(cameraId);
+ new android.hardware.camera2.impl.CameraDevice(
+ cameraId,
+ listener,
+ handler);
BinderHolder holder = new BinderHolder();
mCameraService.connectDevice(device.getCallbacks(),
@@ -225,10 +233,9 @@
cameraUser = ICameraDeviceUser.Stub.asInterface(holder.getBinder());
// TODO: factor out listener to be non-nested, then move setter to constructor
+ // For now, calling setRemoteDevice will fire initial
+ // onOpened/onUnconfigured callbacks.
device.setRemoteDevice(cameraUser);
-
- return device;
-
}
} catch (NumberFormatException e) {
@@ -238,7 +245,6 @@
throw e.asChecked();
} catch (RemoteException e) {
// impossible
- return null;
}
}
@@ -303,16 +309,7 @@
}
}
- final CameraDevice camera = openCamera(cameraId);
- camera.setDeviceListener(listener, handler);
-
- // TODO: make truly async in the camera service
- handler.post(new Runnable() {
- @Override
- public void run() {
- listener.onOpened(camera);
- }
- });
+ openCameraDeviceUserAsync(cameraId, listener, handler);
}
/**
diff --git a/core/java/android/hardware/camera2/CaptureResult.java b/core/java/android/hardware/camera2/CaptureResult.java
index c9626f1..30bffc4 100644
--- a/core/java/android/hardware/camera2/CaptureResult.java
+++ b/core/java/android/hardware/camera2/CaptureResult.java
@@ -60,11 +60,6 @@
@Override
public <T> T get(Key<T> key) {
- if (key == STATISTICS_FACES) { // Don't throw IllegalArgumentException
- // TODO: Implement android.statistics.faces
- return null;
- }
-
return mResults.get(key);
}
diff --git a/core/java/android/hardware/camera2/Face.java b/core/java/android/hardware/camera2/Face.java
index ef068ca..ded8839d 100644
--- a/core/java/android/hardware/camera2/Face.java
+++ b/core/java/android/hardware/camera2/Face.java
@@ -58,6 +58,9 @@
* Create a new face with all fields set.
*
* <p>The id, leftEyePosition, rightEyePosition, and mouthPosition are considered optional.
+ * They are only required when the {@link CaptureResult} reports that the value of key
+ * {@link CaptureResult#STATISTICS_FACE_DETECT_MODE} is
+ * {@link CameraMetadata#STATISTICS_FACE_DETECT_MODE_FULL}.
* If the id is {@value #ID_UNSUPPORTED} then the leftEyePosition, rightEyePosition, and
* mouthPositions are guaranteed to be {@code null}. Otherwise, each of leftEyePosition,
* rightEyePosition, and mouthPosition may be independently null or not-null.</p>
@@ -107,7 +110,11 @@
* <p>The id, leftEyePosition, rightEyePosition, and mouthPosition are considered optional.
* If the id is {@value #ID_UNSUPPORTED} then the leftEyePosition, rightEyePosition, and
* mouthPositions are guaranteed to be {@code null}. Otherwise, each of leftEyePosition,
- * rightEyePosition, and mouthPosition may be independently null or not-null.</p>
+ * rightEyePosition, and mouthPosition may be independently null or not-null. When devices
+ * report the value of key {@link CaptureResult#STATISTICS_FACE_DETECT_MODE} as
+ * {@link CameraMetadata#STATISTICS_FACE_DETECT_MODE_SIMPLE} in {@link CaptureResult},
+ * the face id of each face is expected to be {@value #ID_UNSUPPORTED}, the leftEyePosition,
+ * rightEyePosition, and mouthPositions are expected to be {@code null} for each face.</p>
*
* @param bounds Bounds of the face.
* @param score Confidence level between {@value #SCORE_MIN}-{@value #SCORE_MAX}.
@@ -168,7 +175,10 @@
* <p>This is an optional field, may not be supported on all devices.
* If the id is {@value #ID_UNSUPPORTED} then the leftEyePosition, rightEyePosition, and
* mouthPositions are guaranteed to be {@code null}. Otherwise, each of leftEyePosition,
- * rightEyePosition, and mouthPosition may be independently null or not-null.</p>
+ * rightEyePosition, and mouthPosition may be independently null or not-null. When devices
+ * report the value of key {@link CaptureResult#STATISTICS_FACE_DETECT_MODE} as
+ * {@link CameraMetadata#STATISTICS_FACE_DETECT_MODE_SIMPLE} in {@link CaptureResult},
+ * the face id of each face is expected to be {@value #ID_UNSUPPORTED}.</p>
*
* <p>This value will either be {@value #ID_UNSUPPORTED} or
* otherwise greater than {@code 0}.</p>
@@ -219,7 +229,7 @@
* field, may not be supported on all devices. If not
* supported, the value will always be set to null.
* This value will always be null only if {@link #getId()} returns
- * {@value #ID_UNSUPPORTED}.</p> them are.
+ * {@value #ID_UNSUPPORTED}.</p>
* </p>
*
* @return The mouth position, or {@code null} if unknown.
diff --git a/core/java/android/hardware/camera2/impl/CameraDevice.java b/core/java/android/hardware/camera2/impl/CameraDevice.java
index 463063c..c5d0999 100644
--- a/core/java/android/hardware/camera2/impl/CameraDevice.java
+++ b/core/java/android/hardware/camera2/impl/CameraDevice.java
@@ -55,8 +55,10 @@
private final Object mLock = new Object();
private final CameraDeviceCallbacks mCallbacks = new CameraDeviceCallbacks();
- private StateListener mDeviceListener;
- private Handler mDeviceHandler;
+ private final StateListener mDeviceListener;
+ private final Handler mDeviceHandler;
+
+ private boolean mIdle = true;
private final SparseArray<CaptureListenerHolder> mCaptureListenerMap =
new SparseArray<CaptureListenerHolder>();
@@ -67,8 +69,72 @@
private final String mCameraId;
- public CameraDevice(String cameraId) {
+ // Runnables for all state transitions, except error, which needs the
+ // error code argument
+
+ private final Runnable mCallOnOpened = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onOpened(CameraDevice.this);
+ }
+ }
+ };
+
+ private final Runnable mCallOnUnconfigured = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onUnconfigured(CameraDevice.this);
+ }
+ }
+ };
+
+ private final Runnable mCallOnActive = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onActive(CameraDevice.this);
+ }
+ }
+ };
+
+ private final Runnable mCallOnBusy = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onBusy(CameraDevice.this);
+ }
+ }
+ };
+
+ private final Runnable mCallOnClosed = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onClosed(CameraDevice.this);
+ }
+ }
+ };
+
+ private final Runnable mCallOnIdle = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onIdle(CameraDevice.this);
+ }
+ }
+ };
+
+ private final Runnable mCallOnDisconnected = new Runnable() {
+ public void run() {
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onDisconnected(CameraDevice.this);
+ }
+ }
+ };
+
+ public CameraDevice(String cameraId, StateListener listener, Handler handler) {
+ if (cameraId == null || listener == null || handler == null) {
+ throw new IllegalArgumentException("Null argument given");
+ }
mCameraId = cameraId;
+ mDeviceListener = listener;
+ mDeviceHandler = handler;
TAG = String.format("CameraDevice-%s-JV", mCameraId);
DEBUG = Log.isLoggable(TAG, Log.DEBUG);
}
@@ -79,7 +145,12 @@
public void setRemoteDevice(ICameraDeviceUser remoteDevice) {
// TODO: Move from decorator to direct binder-mediated exceptions
- mRemoteDevice = CameraBinderDecorator.newInstance(remoteDevice);
+ synchronized(mLock) {
+ mRemoteDevice = CameraBinderDecorator.newInstance(remoteDevice);
+
+ mDeviceHandler.post(mCallOnOpened);
+ mDeviceHandler.post(mCallOnUnconfigured);
+ }
}
@Override
@@ -89,7 +160,13 @@
@Override
public void configureOutputs(List<Surface> outputs) throws CameraAccessException {
+ // Treat a null input the same an empty list
+ if (outputs == null) {
+ outputs = new ArrayList<Surface>();
+ }
synchronized (mLock) {
+ checkIfCameraClosed();
+
HashSet<Surface> addSet = new HashSet<Surface>(outputs); // Streams to create
List<Integer> deleteList = new ArrayList<Integer>(); // Streams to delete
@@ -105,9 +182,13 @@
}
}
- try {
- // TODO: mRemoteDevice.beginConfigure
+ mDeviceHandler.post(mCallOnBusy);
+ stopRepeating();
+ try {
+ mRemoteDevice.waitUntilIdle();
+
+ // TODO: mRemoteDevice.beginConfigure
// Delete all streams first (to free up HW resources)
for (Integer streamId : deleteList) {
mRemoteDevice.deleteStream(streamId);
@@ -126,7 +207,7 @@
} catch (CameraRuntimeException e) {
if (e.getReason() == CAMERA_IN_USE) {
throw new IllegalStateException("The camera is currently busy." +
- " You must call waitUntilIdle before trying to reconfigure.");
+ " You must wait until the previous operation completes.");
}
throw e.asChecked();
@@ -134,6 +215,12 @@
// impossible
return;
}
+
+ if (outputs.size() > 0) {
+ mDeviceHandler.post(mCallOnIdle);
+ } else {
+ mDeviceHandler.post(mCallOnUnconfigured);
+ }
}
}
@@ -141,6 +228,7 @@
public CaptureRequest.Builder createCaptureRequest(int templateType)
throws CameraAccessException {
synchronized (mLock) {
+ checkIfCameraClosed();
CameraMetadataNative templatedRequest = new CameraMetadataNative();
@@ -188,7 +276,7 @@
}
synchronized (mLock) {
-
+ checkIfCameraClosed();
int requestId;
try {
@@ -208,6 +296,11 @@
mRepeatingRequestIdStack.add(requestId);
}
+ if (mIdle) {
+ mDeviceHandler.post(mCallOnActive);
+ }
+ mIdle = false;
+
return requestId;
}
}
@@ -233,7 +326,7 @@
public void stopRepeating() throws CameraAccessException {
synchronized (mLock) {
-
+ checkIfCameraClosed();
while (!mRepeatingRequestIdStack.isEmpty()) {
int requestId = mRepeatingRequestIdStack.pop();
@@ -270,20 +363,11 @@
}
@Override
- public void setDeviceListener(StateListener listener, Handler handler) {
- synchronized (mLock) {
- if (listener != null) {
- handler = checkHandler(handler);
- }
-
- mDeviceListener = listener;
- mDeviceHandler = handler;
- }
- }
-
- @Override
public void flush() throws CameraAccessException {
synchronized (mLock) {
+ checkIfCameraClosed();
+
+ mDeviceHandler.post(mCallOnBusy);
try {
mRemoteDevice.flush();
} catch (CameraRuntimeException e) {
@@ -297,9 +381,6 @@
@Override
public void close() {
-
- // TODO: every method should throw IllegalStateException after close has been called
-
synchronized (mLock) {
try {
@@ -312,8 +393,11 @@
// impossible
}
- mRemoteDevice = null;
+ if (mRemoteDevice != null) {
+ mDeviceHandler.post(mCallOnClosed);
+ }
+ mRemoteDevice = null;
}
}
@@ -399,49 +483,44 @@
@Override
public void onCameraError(final int errorCode) {
- synchronized (mLock) {
- if (CameraDevice.this.mDeviceListener == null) return;
- final StateListener listener = CameraDevice.this.mDeviceListener;
- Runnable r = null;
+ Runnable r = null;
+ if (isClosed()) return;
+
+ synchronized(mLock) {
switch (errorCode) {
case ERROR_CAMERA_DISCONNECTED:
- r = new Runnable() {
- public void run() {
- listener.onDisconnected(CameraDevice.this);
- }
- };
+ r = mCallOnDisconnected;
break;
+ default:
+ Log.e(TAG, "Unknown error from camera device: " + errorCode);
+ // no break
case ERROR_CAMERA_DEVICE:
case ERROR_CAMERA_SERVICE:
r = new Runnable() {
public void run() {
- listener.onError(CameraDevice.this, errorCode);
+ if (!CameraDevice.this.isClosed()) {
+ mDeviceListener.onError(CameraDevice.this, errorCode);
+ }
}
};
break;
- default:
- Log.e(TAG, "Unknown error from camera device: " + errorCode);
}
- if (r != null) {
- CameraDevice.this.mDeviceHandler.post(r);
- }
+ CameraDevice.this.mDeviceHandler.post(r);
}
}
@Override
public void onCameraIdle() {
+ if (isClosed()) return;
+
if (DEBUG) {
Log.d(TAG, "Camera now idle");
}
synchronized (mLock) {
- if (CameraDevice.this.mDeviceListener == null) return;
- final StateListener listener = CameraDevice.this.mDeviceListener;
- Runnable r = new Runnable() {
- public void run() {
- listener.onIdle(CameraDevice.this);
- }
- };
- CameraDevice.this.mDeviceHandler.post(r);
+ if (!CameraDevice.this.mIdle) {
+ CameraDevice.this.mDeviceHandler.post(mCallOnIdle);
+ }
+ CameraDevice.this.mIdle = true;
}
}
@@ -461,14 +540,18 @@
return;
}
+ if (isClosed()) return;
+
// Dispatch capture start notice
holder.getHandler().post(
new Runnable() {
public void run() {
- holder.getListener().onCaptureStarted(
- CameraDevice.this,
- holder.getRequest(),
- timestamp);
+ if (!CameraDevice.this.isClosed()) {
+ holder.getListener().onCaptureStarted(
+ CameraDevice.this,
+ holder.getRequest(),
+ timestamp);
+ }
}
});
}
@@ -503,6 +586,8 @@
return;
}
+ if (isClosed()) return;
+
final CaptureRequest request = holder.getRequest();
final CaptureResult resultAsCapture = new CaptureResult(result, request, requestId);
@@ -510,10 +595,12 @@
new Runnable() {
@Override
public void run() {
- holder.getListener().onCaptureCompleted(
- CameraDevice.this,
- request,
- resultAsCapture);
+ if (!CameraDevice.this.isClosed()){
+ holder.getListener().onCaptureCompleted(
+ CameraDevice.this,
+ request,
+ resultAsCapture);
+ }
}
});
}
@@ -541,4 +628,10 @@
throw new IllegalStateException("CameraDevice was already closed");
}
}
+
+ private boolean isClosed() {
+ synchronized(mLock) {
+ return (mRemoteDevice == null);
+ }
+ }
}
diff --git a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java
index 89ffd93..adccbc5 100644
--- a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java
+++ b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java
@@ -16,7 +16,13 @@
package android.hardware.camera2.impl;
+import android.graphics.ImageFormat;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraMetadata;
+import android.hardware.camera2.CaptureResult;
+import android.hardware.camera2.Face;
import android.hardware.camera2.Rational;
import android.os.Parcelable;
import android.os.Parcel;
@@ -36,6 +42,8 @@
private static final String TAG = "CameraMetadataJV";
private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
+ // this should be in sync with HAL_PIXEL_FORMAT_BLOB defined in graphics.h
+ private static final int NATIVE_JPEG_FORMAT = 0x21;
public CameraMetadataNative() {
super();
@@ -84,16 +92,21 @@
@SuppressWarnings("unchecked")
@Override
public <T> T get(Key<T> key) {
- int tag = key.getTag();
- byte[] values = readValues(tag);
- if (values == null) {
+
+ if (key == CaptureResult.STATISTICS_FACES) {
+ /**
+ * FIXME: Workaround for HAL bug that's missing FACE_DETECT_MODE
+ */
+ Log.w(TAG, "Expected non-null android.statistics.faceDetectMode");
return null;
}
- int nativeType = getNativeType(tag);
+ T value = getOverride(key);
+ if (value != null) {
+ return value;
+ }
- ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder());
- return unpackSingle(buffer, key.getType(), nativeType);
+ return getBase(key);
}
public void readFromParcel(Parcel in) {
@@ -110,24 +123,11 @@
* type to the key.
*/
public <T> void set(Key<T> key, T value) {
- int tag = key.getTag();
-
- if (value == null) {
- writeValues(tag, null);
+ if (setOverride(key, value)) {
return;
}
- int nativeType = getNativeType(tag);
-
- int size = packSingle(value, null, key.getType(), nativeType, /* sizeOnly */true);
-
- // TODO: Optimization. Cache the byte[] and reuse if the size is big enough.
- byte[] values = new byte[size];
-
- ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder());
- packSingle(value, buffer, key.getType(), nativeType, /*sizeOnly*/false);
-
- writeValues(tag, values);
+ setBase(key, value);
}
// Keep up-to-date with camera_metadata.h
@@ -435,6 +435,157 @@
return (T) array;
}
+ private <T> T getBase(Key<T> key) {
+ int tag = key.getTag();
+ byte[] values = readValues(tag);
+ if (values == null) {
+ return null;
+ }
+
+ int nativeType = getNativeType(tag);
+
+ ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder());
+ return unpackSingle(buffer, key.getType(), nativeType);
+ }
+
+ // Need overwrite some metadata that has different definitions between native
+ // and managed sides.
+ @SuppressWarnings("unchecked")
+ private <T> T getOverride(Key<T> key) {
+ if (key == CameraCharacteristics.SCALER_AVAILABLE_FORMATS) {
+ return (T) getAvailableFormats();
+ } else if (key == CaptureResult.STATISTICS_FACES) {
+ return (T) getFaces();
+ }
+
+ // For other keys, get() falls back to getBase()
+ return null;
+ }
+
+ private int[] getAvailableFormats() {
+ int[] availableFormats = getBase(CameraCharacteristics.SCALER_AVAILABLE_FORMATS);
+ for (int i = 0; i < availableFormats.length; i++) {
+ // JPEG has different value between native and managed side, need override.
+ if (availableFormats[i] == NATIVE_JPEG_FORMAT) {
+ availableFormats[i] = ImageFormat.JPEG;
+ }
+ }
+ return availableFormats;
+ }
+
+ private Face[] getFaces() {
+ final int FACE_LANDMARK_SIZE = 6;
+
+ Integer faceDetectMode = getBase(CaptureResult.STATISTICS_FACE_DETECT_MODE);
+ if (faceDetectMode == null) {
+ throw new AssertionError("Expect non-null face detect mode");
+ }
+
+ if (faceDetectMode == CaptureResult.STATISTICS_FACE_DETECT_MODE_OFF) {
+ return new Face[0];
+ }
+ if (faceDetectMode != CaptureResult.STATISTICS_FACE_DETECT_MODE_SIMPLE &&
+ faceDetectMode != CaptureResult.STATISTICS_FACE_DETECT_MODE_FULL) {
+ throw new AssertionError("Unknown face detect mode: " + faceDetectMode);
+ }
+
+ // Face scores and rectangles are required by SIMPLE and FULL mode.
+ byte[] faceScores = getBase(CaptureResult.STATISTICS_FACE_SCORES);
+ Rect[] faceRectangles = getBase(CaptureResult.STATISTICS_FACE_RECTANGLES);
+ if (faceScores == null || faceRectangles == null) {
+ throw new AssertionError("Expect face scores and rectangles to be non-null");
+ } else if (faceScores.length != faceRectangles.length) {
+ throw new AssertionError(
+ String.format("Face score size(%d) doesn match face rectangle size(%d)!",
+ faceScores.length, faceRectangles.length));
+ }
+
+ // Face id and landmarks are only required by FULL mode.
+ int[] faceIds = getBase(CaptureResult.STATISTICS_FACE_IDS);
+ int[] faceLandmarks = getBase(CaptureResult.STATISTICS_FACE_LANDMARKS);
+ int numFaces = faceScores.length;
+ if (faceDetectMode == CaptureResult.STATISTICS_FACE_DETECT_MODE_FULL) {
+ if (faceIds == null || faceLandmarks == null) {
+ throw new AssertionError("Expect face ids and landmarks to be non-null for " +
+ "FULL mode");
+ } else if (faceIds.length != numFaces ||
+ faceLandmarks.length != numFaces * FACE_LANDMARK_SIZE) {
+ throw new AssertionError(
+ String.format("Face id size(%d), or face landmark size(%d) don't match " +
+ "face number(%d)!",
+ faceIds.length, faceLandmarks.length * FACE_LANDMARK_SIZE,
+ numFaces));
+ }
+ }
+
+ Face[] faces = new Face[numFaces];
+ if (faceDetectMode == CaptureResult.STATISTICS_FACE_DETECT_MODE_SIMPLE) {
+ for (int i = 0; i < numFaces; i++) {
+ faces[i] = new Face(faceRectangles[i], faceScores[i]);
+ }
+ } else {
+ // CaptureResult.STATISTICS_FACE_DETECT_MODE_FULL
+ for (int i = 0; i < numFaces; i++) {
+ Point leftEye = new Point(faceLandmarks[i*6], faceLandmarks[i*6+1]);
+ Point rightEye = new Point(faceLandmarks[i*6+2], faceLandmarks[i*6+3]);
+ Point mouth = new Point(faceLandmarks[i*6+4], faceLandmarks[i*6+5]);
+ faces[i] = new Face(faceRectangles[i], faceScores[i], faceIds[i],
+ leftEye, rightEye, mouth);
+ }
+ }
+ return faces;
+ }
+
+ private <T> void setBase(Key<T> key, T value) {
+ int tag = key.getTag();
+
+ if (value == null) {
+ writeValues(tag, null);
+ return;
+ }
+
+ int nativeType = getNativeType(tag);
+
+ int size = packSingle(value, null, key.getType(), nativeType, /* sizeOnly */true);
+
+ // TODO: Optimization. Cache the byte[] and reuse if the size is big enough.
+ byte[] values = new byte[size];
+
+ ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder());
+ packSingle(value, buffer, key.getType(), nativeType, /*sizeOnly*/false);
+
+ writeValues(tag, values);
+ }
+
+ // Set the camera metadata override.
+ private <T> boolean setOverride(Key<T> key, T value) {
+ if (key == CameraCharacteristics.SCALER_AVAILABLE_FORMATS) {
+ return setAvailableFormats((int[]) value);
+ }
+
+ // For other keys, set() falls back to setBase().
+ return false;
+ }
+
+ private boolean setAvailableFormats(int[] value) {
+ int[] availableFormat = value;
+ if (value == null) {
+ // Let setBase() to handle the null value case.
+ return false;
+ }
+
+ int[] newValues = new int[availableFormat.length];
+ for (int i = 0; i < availableFormat.length; i++) {
+ newValues[i] = availableFormat[i];
+ if (availableFormat[i] == ImageFormat.JPEG) {
+ newValues[i] = NATIVE_JPEG_FORMAT;
+ }
+ }
+
+ setBase(CameraCharacteristics.SCALER_AVAILABLE_FORMATS, newValues);
+ return true;
+ }
+
private long mMetadataPtr; // native CameraMetadata*
private native long nativeAllocate();
@@ -538,7 +689,7 @@
* @hide
*/
public byte[] readValues(int tag) {
- // TODO: Optimization. Native code returns a ByteBuffer instead.
+ // TODO: Optimization. Native code returns a ByteBuffer instead.
return nativeReadValues(tag);
}
diff --git a/core/java/android/print/PrintAttributes.java b/core/java/android/print/PrintAttributes.java
index ec979b3..e1a9cb7 100644
--- a/core/java/android/print/PrintAttributes.java
+++ b/core/java/android/print/PrintAttributes.java
@@ -282,7 +282,7 @@
*/
public static final MediaSize UNKNOWN_PORTRAIT =
new MediaSize("UNKNOWN_PORTRAIT", "android",
- R.string.mediasize_unknown_portrait, Integer.MAX_VALUE, 1);
+ R.string.mediasize_unknown_portrait, 1, Integer.MAX_VALUE);
/**
* Unknown media size in landscape mode.
@@ -293,7 +293,7 @@
*/
public static final MediaSize UNKNOWN_LANDSCAPE =
new MediaSize("UNKNOWN_LANDSCAPE", "android",
- R.string.mediasize_unknown_landscape, 1, Integer.MAX_VALUE);
+ R.string.mediasize_unknown_landscape, Integer.MAX_VALUE, 1);
// ISO sizes
diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java
index 631a8d4..1c14c38 100644
--- a/core/java/android/provider/DocumentsContract.java
+++ b/core/java/android/provider/DocumentsContract.java
@@ -70,8 +70,14 @@
}
/** {@hide} */
+ @Deprecated
public static final String META_DATA_DOCUMENT_PROVIDER = "android.content.DOCUMENT_PROVIDER";
+ /**
+ * Intent action used to identify {@link DocumentsProvider} instances.
+ */
+ public static final String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER";
+
/** {@hide} */
public static final String ACTION_MANAGE_ROOT = "android.provider.action.MANAGE_ROOT";
/** {@hide} */
diff --git a/graphics/java/android/graphics/Path.java b/graphics/java/android/graphics/Path.java
index ef858eb..5b04a91 100644
--- a/graphics/java/android/graphics/Path.java
+++ b/graphics/java/android/graphics/Path.java
@@ -78,7 +78,11 @@
mLastDirection = null;
if (rects != null) rects.setEmpty();
}
+ // We promised not to change this, so preserve it around the native
+ // call, which does now reset fill type.
+ final FillType fillType = getFillType();
native_reset(mNativePath);
+ setFillType(fillType);
}
/**
diff --git a/graphics/tests/graphicstests/src/android/graphics/PathTest.java b/graphics/tests/graphicstests/src/android/graphics/PathTest.java
new file mode 100644
index 0000000..96200bc
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/PathTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.TestCase;
+
+
+public class PathTest extends TestCase {
+
+ @SmallTest
+ public void testResetPreservesFillType() throws Exception {
+ Path path = new Path();
+
+ final Path.FillType defaultFillType = path.getFillType();
+ final Path.FillType fillType = Path.FillType.INVERSE_EVEN_ODD;
+ assertFalse(fillType.equals(defaultFillType)); // Sanity check for the test itself.
+
+ path.setFillType(fillType);
+ path.reset();
+ assertEquals(path.getFillType(), fillType);
+ }
+}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java
index 874e078..3f17aa9 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java
@@ -18,9 +18,11 @@
import android.os.Parcel;
import android.test.suitebuilder.annotation.SmallTest;
-import android.graphics.ImageFormat;
+import android.graphics.Point;
import android.graphics.Rect;
-import android.hardware.camera2.CameraMetadata;
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CaptureResult;
+import android.hardware.camera2.Face;
import android.hardware.camera2.Rational;
import android.hardware.camera2.Size;
import android.hardware.camera2.impl.CameraMetadataNative;
@@ -30,9 +32,6 @@
import java.lang.reflect.Array;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.nio.IntBuffer;
-
-import static org.junit.Assert.assertArrayEquals;
/**
* <pre>
@@ -57,6 +56,7 @@
// Tags
static final int ANDROID_COLOR_CORRECTION_MODE = ANDROID_COLOR_CORRECTION_START;
static final int ANDROID_COLOR_CORRECTION_TRANSFORM = ANDROID_COLOR_CORRECTION_START + 1;
+ static final int ANDROID_COLOR_CORRECTION_GAINS = ANDROID_COLOR_CORRECTION_START + 2;
static final int ANDROID_CONTROL_AE_ANTIBANDING_MODE = ANDROID_CONTROL_START;
static final int ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION = ANDROID_CONTROL_START + 1;
@@ -131,7 +131,8 @@
@SmallTest
public void testGetTypeFromTag() {
assertEquals(TYPE_BYTE, CameraMetadataNative.getNativeType(ANDROID_COLOR_CORRECTION_MODE));
- assertEquals(TYPE_FLOAT, CameraMetadataNative.getNativeType(ANDROID_COLOR_CORRECTION_TRANSFORM));
+ assertEquals(TYPE_RATIONAL, CameraMetadataNative.getNativeType(ANDROID_COLOR_CORRECTION_TRANSFORM));
+ assertEquals(TYPE_FLOAT, CameraMetadataNative.getNativeType(ANDROID_COLOR_CORRECTION_GAINS));
assertEquals(TYPE_BYTE, CameraMetadataNative.getNativeType(ANDROID_CONTROL_AE_ANTIBANDING_MODE));
assertEquals(TYPE_INT32,
CameraMetadataNative.getNativeType(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION));
@@ -187,30 +188,30 @@
assertEquals(false, mMetadata.isEmpty());
//
- // android.colorCorrection.transform (3x3 matrix)
+ // android.colorCorrection.colorCorrectionGains (float x 4 array)
//
- final float[] transformMatrix = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- byte[] transformMatrixAsByteArray = new byte[transformMatrix.length * 4];
- ByteBuffer transformMatrixByteBuffer =
- ByteBuffer.wrap(transformMatrixAsByteArray).order(ByteOrder.nativeOrder());
- for (float f : transformMatrix)
- transformMatrixByteBuffer.putFloat(f);
+ final float[] colorCorrectionGains = new float[] { 1.0f, 2.0f, 3.0f, 4.0f};
+ byte[] colorCorrectionGainsAsByteArray = new byte[colorCorrectionGains.length * 4];
+ ByteBuffer colorCorrectionGainsByteBuffer =
+ ByteBuffer.wrap(colorCorrectionGainsAsByteArray).order(ByteOrder.nativeOrder());
+ for (float f : colorCorrectionGains)
+ colorCorrectionGainsByteBuffer.putFloat(f);
// Read
- assertNull(mMetadata.readValues(ANDROID_COLOR_CORRECTION_TRANSFORM));
- mMetadata.writeValues(ANDROID_COLOR_CORRECTION_TRANSFORM, transformMatrixAsByteArray);
+ assertNull(mMetadata.readValues(ANDROID_COLOR_CORRECTION_GAINS));
+ mMetadata.writeValues(ANDROID_COLOR_CORRECTION_GAINS, colorCorrectionGainsAsByteArray);
// Write
- assertArrayEquals(transformMatrixAsByteArray,
- mMetadata.readValues(ANDROID_COLOR_CORRECTION_TRANSFORM));
+ assertArrayEquals(colorCorrectionGainsAsByteArray,
+ mMetadata.readValues(ANDROID_COLOR_CORRECTION_GAINS));
assertEquals(2, mMetadata.getEntryCount());
assertEquals(false, mMetadata.isEmpty());
// Erase
- mMetadata.writeValues(ANDROID_COLOR_CORRECTION_TRANSFORM, null);
- assertNull(mMetadata.readValues(ANDROID_COLOR_CORRECTION_TRANSFORM));
+ mMetadata.writeValues(ANDROID_COLOR_CORRECTION_GAINS, null);
+ assertNull(mMetadata.readValues(ANDROID_COLOR_CORRECTION_GAINS));
assertEquals(1, mMetadata.getEntryCount());
}
@@ -279,7 +280,7 @@
@SmallTest
public void testReadWritePrimitiveArray() {
// int32 (n)
- checkKeyGetAndSetArray("android.sensor.info.availableSensitivities", int[].class,
+ checkKeyGetAndSetArray("android.sensor.info.sensitivityRange", int[].class,
new int[] {
0xC0FFEE, 0xDEADF00D
});
@@ -379,7 +380,9 @@
new AvailableFormat[] {
AvailableFormat.RAW_SENSOR,
AvailableFormat.YV12,
- AvailableFormat.IMPLEMENTATION_DEFINED
+ AvailableFormat.IMPLEMENTATION_DEFINED,
+ AvailableFormat.YCbCr_420_888,
+ AvailableFormat.BLOB
});
}
@@ -431,12 +434,13 @@
AvailableFormat.RAW_SENSOR,
AvailableFormat.YV12,
AvailableFormat.IMPLEMENTATION_DEFINED,
- AvailableFormat.YCbCr_420_888
+ AvailableFormat.YCbCr_420_888,
+ AvailableFormat.BLOB
});
- Key<AeAntibandingMode> availableFormatsKey =
- new Key<AeAntibandingMode>("android.scaler.availableFormats",
- AeAntibandingMode.class);
+ Key<AvailableFormat[]> availableFormatsKey =
+ new Key<AvailableFormat[]>("android.scaler.availableFormats",
+ AvailableFormat[].class);
byte[] availableFormatValues = mMetadata.readValues(CameraMetadataNative
.getTag(availableFormatsKey.getName()));
@@ -444,7 +448,8 @@
0x20,
0x32315659,
0x22,
- 0x23
+ 0x23,
+ 0x21
};
ByteBuffer bf = ByteBuffer.wrap(availableFormatValues).order(ByteOrder.nativeOrder());
@@ -523,4 +528,115 @@
<T> void compareGeneric(T expected, T actual) {
assertEquals(expected, actual);
}
+
+ @SmallTest
+ public void testReadWriteOverride() {
+ //
+ // android.scaler.availableFormats (int x n array)
+ //
+ int[] availableFormats = new int[] {
+ 0x20, // RAW_SENSOR
+ 0x32315659, // YV12
+ 0x11, // YCrCb_420_SP
+ 0x100, // ImageFormat.JPEG
+ 0x22, // IMPLEMENTATION_DEFINED
+ 0x23, // YCbCr_420_888
+ };
+ int[] expectedIntValues = new int[] {
+ 0x20, // RAW_SENSOR
+ 0x32315659, // YV12
+ 0x11, // YCrCb_420_SP
+ 0x21, // BLOB
+ 0x22, // IMPLEMENTATION_DEFINED
+ 0x23, // YCbCr_420_888
+ };
+ int availableFormatTag = CameraMetadataNative.getTag("android.scaler.availableFormats");
+
+ // Write
+ mMetadata.set(CameraCharacteristics.SCALER_AVAILABLE_FORMATS, availableFormats);
+
+ byte[] availableFormatValues = mMetadata.readValues(availableFormatTag);
+
+ ByteBuffer bf = ByteBuffer.wrap(availableFormatValues).order(ByteOrder.nativeOrder());
+
+ assertEquals(expectedIntValues.length * 4, availableFormatValues.length);
+ for (int i = 0; i < expectedIntValues.length; ++i) {
+ assertEquals(expectedIntValues[i], bf.getInt());
+ }
+ // Read
+ byte[] availableFormatsAsByteArray = new byte[expectedIntValues.length * 4];
+ ByteBuffer availableFormatsByteBuffer =
+ ByteBuffer.wrap(availableFormatsAsByteArray).order(ByteOrder.nativeOrder());
+ for (int value : expectedIntValues) {
+ availableFormatsByteBuffer.putInt(value);
+ }
+ mMetadata.writeValues(availableFormatTag, availableFormatsAsByteArray);
+
+ int[] resultFormats = mMetadata.get(CameraCharacteristics.SCALER_AVAILABLE_FORMATS);
+ assertNotNull("result available formats shouldn't be null", resultFormats);
+ assertArrayEquals(availableFormats, resultFormats);
+
+ //
+ // android.statistics.faces (Face x n array)
+ //
+ int[] expectedFaceIds = new int[] {1, 2, 3, 4, 5};
+ byte[] expectedFaceScores = new byte[] {10, 20, 30, 40, 50};
+ int numFaces = expectedFaceIds.length;
+ Rect[] expectedRects = new Rect[numFaces];
+ for (int i = 0; i < numFaces; i++) {
+ expectedRects[i] = new Rect(i*4 + 1, i * 4 + 2, i * 4 + 3, i * 4 + 4);
+ }
+ int[] expectedFaceLM = new int[] {
+ 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18,
+ 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30,
+ };
+ Point[] expectedFaceLMPoints = new Point[numFaces * 3];
+ for (int i = 0; i < numFaces; i++) {
+ expectedFaceLMPoints[i*3] = new Point(expectedFaceLM[i*6], expectedFaceLM[i*6+1]);
+ expectedFaceLMPoints[i*3+1] = new Point(expectedFaceLM[i*6+2], expectedFaceLM[i*6+3]);
+ expectedFaceLMPoints[i*3+2] = new Point(expectedFaceLM[i*6+4], expectedFaceLM[i*6+5]);
+ }
+
+ /**
+ * Read - FACE_DETECT_MODE == FULL
+ */
+ mMetadata.set(CaptureResult.STATISTICS_FACE_DETECT_MODE,
+ CaptureResult.STATISTICS_FACE_DETECT_MODE_FULL);
+ mMetadata.set(CaptureResult.STATISTICS_FACE_IDS, expectedFaceIds);
+ mMetadata.set(CaptureResult.STATISTICS_FACE_SCORES, expectedFaceScores);
+ mMetadata.set(CaptureResult.STATISTICS_FACE_RECTANGLES, expectedRects);
+ mMetadata.set(CaptureResult.STATISTICS_FACE_LANDMARKS, expectedFaceLM);
+ Face[] resultFaces = mMetadata.get(CaptureResult.STATISTICS_FACES);
+ assertEquals(numFaces, resultFaces.length);
+ for (int i = 0; i < numFaces; i++) {
+ assertEquals(expectedFaceIds[i], resultFaces[i].getId());
+ assertEquals(expectedFaceScores[i], resultFaces[i].getScore());
+ assertEquals(expectedRects[i], resultFaces[i].getBounds());
+ assertEquals(expectedFaceLMPoints[i*3], resultFaces[i].getLeftEyePosition());
+ assertEquals(expectedFaceLMPoints[i*3+1], resultFaces[i].getRightEyePosition());
+ assertEquals(expectedFaceLMPoints[i*3+2], resultFaces[i].getMouthPosition());
+ }
+
+ /**
+ * Read - FACE_DETECT_MODE == SIMPLE
+ */
+ mMetadata.set(CaptureResult.STATISTICS_FACE_DETECT_MODE,
+ CaptureResult.STATISTICS_FACE_DETECT_MODE_SIMPLE);
+ mMetadata.set(CaptureResult.STATISTICS_FACE_SCORES, expectedFaceScores);
+ mMetadata.set(CaptureResult.STATISTICS_FACE_RECTANGLES, expectedRects);
+ Face[] resultSimpleFaces = mMetadata.get(CaptureResult.STATISTICS_FACES);
+ assertEquals(numFaces, resultSimpleFaces.length);
+ for (int i = 0; i < numFaces; i++) {
+ assertEquals(Face.ID_UNSUPPORTED, resultSimpleFaces[i].getId());
+ assertEquals(expectedFaceScores[i], resultSimpleFaces[i].getScore());
+ assertEquals(expectedRects[i], resultSimpleFaces[i].getBounds());
+ assertNull(resultSimpleFaces[i].getLeftEyePosition());
+ assertNull(resultSimpleFaces[i].getRightEyePosition());
+ assertNull(resultSimpleFaces[i].getMouthPosition());
+ }
+
+ }
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
index 4d410d5..1f3901c 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
@@ -295,6 +295,11 @@
updateDisplayState();
+ // When launched into empty recents, show drawer
+ if (mType == TYPE_RECENT_OPEN && mAdapter.isEmpty() && !state.stackTouched) {
+ ((DocumentsActivity) context).setRootsDrawerOpen(true);
+ }
+
// Restore any previous instance state
final SparseArray<Parcelable> container = state.dirState.remove(mStateKey);
if (container != null && !getArguments().getBoolean(EXTRA_IGNORE_STATE, false)) {
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RecentsCreateFragment.java b/packages/DocumentsUI/src/com/android/documentsui/RecentsCreateFragment.java
index 3954173..05766f5 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RecentsCreateFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RecentsCreateFragment.java
@@ -109,6 +109,11 @@
public void onLoadFinished(
Loader<List<DocumentStack>> loader, List<DocumentStack> data) {
mAdapter.swapStacks(data);
+
+ // When launched into empty recents, show drawer
+ if (mAdapter.isEmpty() && !state.stackTouched) {
+ ((DocumentsActivity) context).setRootsDrawerOpen(true);
+ }
}
@Override
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
index bad0a96..eb56765 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
@@ -21,9 +21,11 @@
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
+import android.content.pm.ResolveInfo;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
@@ -158,6 +160,9 @@
private class UpdateTask extends AsyncTask<Void, Void, Void> {
private final String mFilterPackage;
+ private final Multimap<String, RootInfo> mTaskRoots = ArrayListMultimap.create();
+ private final HashSet<String> mTaskStoppedAuthorities = Sets.newHashSet();
+
/**
* Update all roots.
*/
@@ -177,54 +182,64 @@
protected Void doInBackground(Void... params) {
final long start = SystemClock.elapsedRealtime();
- final Multimap<String, RootInfo> roots = ArrayListMultimap.create();
- final HashSet<String> stoppedAuthorities = Sets.newHashSet();
-
- roots.put(mRecentsRoot.authority, mRecentsRoot);
+ mTaskRoots.put(mRecentsRoot.authority, mRecentsRoot);
final ContentResolver resolver = mContext.getContentResolver();
final PackageManager pm = mContext.getPackageManager();
- final List<ProviderInfo> providers = pm.queryContentProviders(
+
+ // Pick up provider with action string
+ final Intent intent = new Intent(DocumentsContract.PROVIDER_INTERFACE);
+ final List<ResolveInfo> providers = pm.queryIntentContentProviders(intent, 0);
+ for (ResolveInfo info : providers) {
+ handleDocumentsProvider(info.providerInfo);
+ }
+
+ // Pick up legacy providers
+ final List<ProviderInfo> legacyProviders = pm.queryContentProviders(
null, -1, PackageManager.GET_META_DATA);
- for (ProviderInfo info : providers) {
+ for (ProviderInfo info : legacyProviders) {
if (info.metaData != null && info.metaData.containsKey(
DocumentsContract.META_DATA_DOCUMENT_PROVIDER)) {
- // Ignore stopped packages for now; we might query them
- // later during UI interaction.
- if ((info.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
- if (LOGD) Log.d(TAG, "Ignoring stopped authority " + info.authority);
- stoppedAuthorities.add(info.authority);
- continue;
- }
-
- // Try using cached roots if filtering
- boolean cacheHit = false;
- if (mFilterPackage != null && !mFilterPackage.equals(info.packageName)) {
- synchronized (mLock) {
- if (roots.putAll(info.authority, mRoots.get(info.authority))) {
- if (LOGD) Log.d(TAG, "Used cached roots for " + info.authority);
- cacheHit = true;
- }
- }
- }
-
- // Cache miss, or loading everything
- if (!cacheHit) {
- roots.putAll(
- info.authority, loadRootsForAuthority(resolver, info.authority));
- }
+ handleDocumentsProvider(info);
}
}
final long delta = SystemClock.elapsedRealtime() - start;
- Log.d(TAG, "Update found " + roots.size() + " roots in " + delta + "ms");
+ Log.d(TAG, "Update found " + mTaskRoots.size() + " roots in " + delta + "ms");
synchronized (mLock) {
- mStoppedAuthorities = stoppedAuthorities;
- mRoots = roots;
+ mRoots = mTaskRoots;
+ mStoppedAuthorities = mTaskStoppedAuthorities;
}
mFirstLoad.countDown();
return null;
}
+
+ private void handleDocumentsProvider(ProviderInfo info) {
+ // Ignore stopped packages for now; we might query them
+ // later during UI interaction.
+ if ((info.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
+ if (LOGD) Log.d(TAG, "Ignoring stopped authority " + info.authority);
+ mTaskStoppedAuthorities.add(info.authority);
+ return;
+ }
+
+ // Try using cached roots if filtering
+ boolean cacheHit = false;
+ if (mFilterPackage != null && !mFilterPackage.equals(info.packageName)) {
+ synchronized (mLock) {
+ if (mTaskRoots.putAll(info.authority, mRoots.get(info.authority))) {
+ if (LOGD) Log.d(TAG, "Used cached roots for " + info.authority);
+ cacheHit = true;
+ }
+ }
+ }
+
+ // Cache miss, or loading everything
+ if (!cacheHit) {
+ mTaskRoots.putAll(info.authority,
+ loadRootsForAuthority(mContext.getContentResolver(), info.authority));
+ }
+ }
}
/**
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java b/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java
index 2fb12bb..fdbc3ab 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java
@@ -142,9 +142,12 @@
final RootInfo root = ((DocumentsActivity) getActivity()).getCurrentRoot();
for (int i = 0; i < mAdapter.getCount(); i++) {
final Object item = mAdapter.getItem(i);
- if (Objects.equal(item, root)) {
- mList.setItemChecked(i, true);
- return;
+ if (item instanceof RootItem) {
+ final RootInfo testRoot = ((RootItem) item).root;
+ if (Objects.equal(testRoot, root)) {
+ mList.setItemChecked(i, true);
+ return;
+ }
}
}
}
diff --git a/packages/ExternalStorageProvider/AndroidManifest.xml b/packages/ExternalStorageProvider/AndroidManifest.xml
index 7094efc..99a4260 100644
--- a/packages/ExternalStorageProvider/AndroidManifest.xml
+++ b/packages/ExternalStorageProvider/AndroidManifest.xml
@@ -11,9 +11,9 @@
android:grantUriPermissions="true"
android:exported="true"
android:permission="android.permission.MANAGE_DOCUMENTS">
- <meta-data
- android:name="android.content.DOCUMENT_PROVIDER"
- android:value="true" />
+ <intent-filter>
+ <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
+ </intent-filter>
</provider>
<!-- TODO: find a better place for tests to live -->
@@ -24,9 +24,9 @@
android:exported="true"
android:permission="android.permission.MANAGE_DOCUMENTS"
android:enabled="false">
- <meta-data
- android:name="android.content.DOCUMENT_PROVIDER"
- android:value="true" />
+ <intent-filter>
+ <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
+ </intent-filter>
</provider>
</application>
</manifest>
diff --git a/services/java/com/android/server/am/ActiveServices.java b/services/java/com/android/server/am/ActiveServices.java
index 27ca7a0..b69a0c8 100644
--- a/services/java/com/android/server/am/ActiveServices.java
+++ b/services/java/com/android/server/am/ActiveServices.java
@@ -25,6 +25,7 @@
import java.util.List;
import android.os.Handler;
+import android.os.Looper;
import android.util.ArrayMap;
import com.android.internal.app.ProcessStats;
import com.android.internal.os.BatteryStatsImpl;
@@ -166,7 +167,8 @@
static final int MSG_BG_START_TIMEOUT = 1;
- ServiceMap(int userId) {
+ ServiceMap(Looper looper, int userId) {
+ super(looper);
mUserId = userId;
}
@@ -255,7 +257,7 @@
private ServiceMap getServiceMap(int callingUser) {
ServiceMap smap = mServiceMap.get(callingUser);
if (smap == null) {
- smap = new ServiceMap(callingUser);
+ smap = new ServiceMap(mAm.mHandler.getLooper(), callingUser);
mServiceMap.put(callingUser, smap);
}
return smap;
@@ -2417,7 +2419,11 @@
int[] users = mAm.getUsersLocked();
if ("all".equals(name)) {
for (int user : users) {
- ArrayMap<ComponentName, ServiceRecord> alls = getServices(user);
+ ServiceMap smap = mServiceMap.get(user);
+ if (smap == null) {
+ continue;
+ }
+ ArrayMap<ComponentName, ServiceRecord> alls = smap.mServicesByName;
for (int i=0; i<alls.size(); i++) {
ServiceRecord r1 = alls.valueAt(i);
services.add(r1);
@@ -2438,7 +2444,11 @@
}
for (int user : users) {
- ArrayMap<ComponentName, ServiceRecord> alls = getServices(user);
+ ServiceMap smap = mServiceMap.get(user);
+ if (smap == null) {
+ continue;
+ }
+ ArrayMap<ComponentName, ServiceRecord> alls = smap.mServicesByName;
for (int i=0; i<alls.size(); i++) {
ServiceRecord r1 = alls.valueAt(i);
if (componentName != null) {
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index e84f90e..fb6e9edc 100755
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -383,13 +383,12 @@
// All available services, for your resolving pleasure.
final ServiceIntentResolver mServices = new ServiceIntentResolver();
- // Keys are String (provider class name), values are Provider.
- final HashMap<ComponentName, PackageParser.Provider> mProvidersByComponent =
- new HashMap<ComponentName, PackageParser.Provider>();
+ // All available providers, for your resolving pleasure.
+ final ProviderIntentResolver mProviders = new ProviderIntentResolver();
// Mapping from provider base names (first directory in content URI codePath)
// to the provider information.
- final HashMap<String, PackageParser.Provider> mProviders =
+ final HashMap<String, PackageParser.Provider> mProvidersByAuthority =
new HashMap<String, PackageParser.Provider>();
// Mapping from instrumentation class names to info about them.
@@ -2095,7 +2094,7 @@
if (!sUserManager.exists(userId)) return null;
enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get provider info");
synchronized (mPackages) {
- PackageParser.Provider p = mProvidersByComponent.get(component);
+ PackageParser.Provider p = mProviders.mProviders.get(component);
if (DEBUG_PACKAGE_INFO) Log.v(
TAG, "getProviderInfo " + component + ": " + p);
if (p != null && mSettings.isEnabledLPr(p.info, flags, userId)) {
@@ -3121,6 +3120,43 @@
}
@Override
+ public List<ResolveInfo> queryIntentContentProviders(
+ Intent intent, String resolvedType, int flags, int userId) {
+ if (!sUserManager.exists(userId)) return Collections.emptyList();
+ ComponentName comp = intent.getComponent();
+ if (comp == null) {
+ if (intent.getSelector() != null) {
+ intent = intent.getSelector();
+ comp = intent.getComponent();
+ }
+ }
+ if (comp != null) {
+ final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
+ final ProviderInfo pi = getProviderInfo(comp, flags, userId);
+ if (pi != null) {
+ final ResolveInfo ri = new ResolveInfo();
+ ri.providerInfo = pi;
+ list.add(ri);
+ }
+ return list;
+ }
+
+ // reader
+ synchronized (mPackages) {
+ String pkgName = intent.getPackage();
+ if (pkgName == null) {
+ return mProviders.queryIntent(intent, resolvedType, flags, userId);
+ }
+ final PackageParser.Package pkg = mPackages.get(pkgName);
+ if (pkg != null) {
+ return mProviders.queryIntentForPackage(
+ intent, resolvedType, flags, pkg.providers, userId);
+ }
+ return null;
+ }
+ }
+
+ @Override
public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, int userId) {
final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
@@ -3293,7 +3329,7 @@
if (!sUserManager.exists(userId)) return null;
// reader
synchronized (mPackages) {
- final PackageParser.Provider provider = mProviders.get(name);
+ final PackageParser.Provider provider = mProvidersByAuthority.get(name);
PackageSetting ps = provider != null
? mSettings.mPackages.get(provider.owner.packageName)
: null;
@@ -3314,8 +3350,8 @@
public void querySyncProviders(List<String> outNames, List<ProviderInfo> outInfo) {
// reader
synchronized (mPackages) {
- final Iterator<Map.Entry<String, PackageParser.Provider>> i = mProviders.entrySet()
- .iterator();
+ final Iterator<Map.Entry<String, PackageParser.Provider>> i = mProvidersByAuthority
+ .entrySet().iterator();
final int userId = UserHandle.getCallingUserId();
while (i.hasNext()) {
Map.Entry<String, PackageParser.Provider> entry = i.next();
@@ -3341,7 +3377,7 @@
ArrayList<ProviderInfo> finalList = null;
// reader
synchronized (mPackages) {
- final Iterator<PackageParser.Provider> i = mProvidersByComponent.values().iterator();
+ final Iterator<PackageParser.Provider> i = mProviders.mProviders.values().iterator();
final int userId = processName != null ?
UserHandle.getUserId(uid) : UserHandle.getCallingUserId();
while (i.hasNext()) {
@@ -4313,8 +4349,8 @@
if (p.info.authority != null) {
String names[] = p.info.authority.split(";");
for (int j = 0; j < names.length; j++) {
- if (mProviders.containsKey(names[j])) {
- PackageParser.Provider other = mProviders.get(names[j]);
+ if (mProvidersByAuthority.containsKey(names[j])) {
+ PackageParser.Provider other = mProvidersByAuthority.get(names[j]);
Slog.w(TAG, "Can't install because provider name " + names[j] +
" (in package " + pkg.applicationInfo.packageName +
") is already used by "
@@ -4745,8 +4781,7 @@
PackageParser.Provider p = pkg.providers.get(i);
p.info.processName = fixProcessName(pkg.applicationInfo.processName,
p.info.processName, pkg.applicationInfo.uid);
- mProvidersByComponent.put(new ComponentName(p.info.packageName,
- p.info.name), p);
+ mProviders.addProvider(p);
p.syncable = p.info.isSyncable;
if (p.info.authority != null) {
String names[] = p.info.authority.split(";");
@@ -4763,8 +4798,8 @@
p = new PackageParser.Provider(p);
p.syncable = false;
}
- if (!mProviders.containsKey(names[j])) {
- mProviders.put(names[j], p);
+ if (!mProvidersByAuthority.containsKey(names[j])) {
+ mProvidersByAuthority.put(names[j], p);
if (p.info.authority == null) {
p.info.authority = names[j];
} else {
@@ -4777,7 +4812,7 @@
+ p.info.isSyncable);
}
} else {
- PackageParser.Provider other = mProviders.get(names[j]);
+ PackageParser.Provider other = mProvidersByAuthority.get(names[j]);
Slog.w(TAG, "Skipping provider name " + names[j] +
" (in package " + pkg.applicationInfo.packageName +
"): name already used by "
@@ -5108,8 +5143,7 @@
int i;
for (i=0; i<N; i++) {
PackageParser.Provider p = pkg.providers.get(i);
- mProvidersByComponent.remove(new ComponentName(p.info.packageName,
- p.info.name));
+ mProviders.removeProvider(p);
if (p.info.authority == null) {
/* There was another ContentProvider with this authority when
@@ -5120,8 +5154,8 @@
}
String names[] = p.info.authority.split(";");
for (int j = 0; j < names.length; j++) {
- if (mProviders.get(names[j]) == p) {
- mProviders.remove(names[j]);
+ if (mProvidersByAuthority.get(names[j]) == p) {
+ mProvidersByAuthority.remove(names[j]);
if (DEBUG_REMOVE) {
if (chatty)
Log.d(TAG, "Unregistered content provider: " + names[j]
@@ -5962,6 +5996,195 @@
private int mFlags;
};
+ private final class ProviderIntentResolver
+ extends IntentResolver<PackageParser.ProviderIntentInfo, ResolveInfo> {
+ public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
+ boolean defaultOnly, int userId) {
+ mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
+ return super.queryIntent(intent, resolvedType, defaultOnly, userId);
+ }
+
+ public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
+ int userId) {
+ if (!sUserManager.exists(userId))
+ return null;
+ mFlags = flags;
+ return super.queryIntent(intent, resolvedType,
+ (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
+ }
+
+ public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
+ int flags, ArrayList<PackageParser.Provider> packageProviders, int userId) {
+ if (!sUserManager.exists(userId))
+ return null;
+ if (packageProviders == null) {
+ return null;
+ }
+ mFlags = flags;
+ final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
+ final int N = packageProviders.size();
+ ArrayList<PackageParser.ProviderIntentInfo[]> listCut =
+ new ArrayList<PackageParser.ProviderIntentInfo[]>(N);
+
+ ArrayList<PackageParser.ProviderIntentInfo> intentFilters;
+ for (int i = 0; i < N; ++i) {
+ intentFilters = packageProviders.get(i).intents;
+ if (intentFilters != null && intentFilters.size() > 0) {
+ PackageParser.ProviderIntentInfo[] array =
+ new PackageParser.ProviderIntentInfo[intentFilters.size()];
+ intentFilters.toArray(array);
+ listCut.add(array);
+ }
+ }
+ return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
+ }
+
+ public final void addProvider(PackageParser.Provider p) {
+ mProviders.put(p.getComponentName(), p);
+ if (DEBUG_SHOW_INFO) {
+ Log.v(TAG, " "
+ + (p.info.nonLocalizedLabel != null
+ ? p.info.nonLocalizedLabel : p.info.name) + ":");
+ Log.v(TAG, " Class=" + p.info.name);
+ }
+ final int NI = p.intents.size();
+ int j;
+ for (j = 0; j < NI; j++) {
+ PackageParser.ProviderIntentInfo intent = p.intents.get(j);
+ if (DEBUG_SHOW_INFO) {
+ Log.v(TAG, " IntentFilter:");
+ intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
+ }
+ if (!intent.debugCheck()) {
+ Log.w(TAG, "==> For Provider " + p.info.name);
+ }
+ addFilter(intent);
+ }
+ }
+
+ public final void removeProvider(PackageParser.Provider p) {
+ mProviders.remove(p.getComponentName());
+ if (DEBUG_SHOW_INFO) {
+ Log.v(TAG, " " + (p.info.nonLocalizedLabel != null
+ ? p.info.nonLocalizedLabel : p.info.name) + ":");
+ Log.v(TAG, " Class=" + p.info.name);
+ }
+ final int NI = p.intents.size();
+ int j;
+ for (j = 0; j < NI; j++) {
+ PackageParser.ProviderIntentInfo intent = p.intents.get(j);
+ if (DEBUG_SHOW_INFO) {
+ Log.v(TAG, " IntentFilter:");
+ intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
+ }
+ removeFilter(intent);
+ }
+ }
+
+ @Override
+ protected boolean allowFilterResult(
+ PackageParser.ProviderIntentInfo filter, List<ResolveInfo> dest) {
+ ProviderInfo filterPi = filter.provider.info;
+ for (int i = dest.size() - 1; i >= 0; i--) {
+ ProviderInfo destPi = dest.get(i).providerInfo;
+ if (destPi.name == filterPi.name
+ && destPi.packageName == filterPi.packageName) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ protected PackageParser.ProviderIntentInfo[] newArray(int size) {
+ return new PackageParser.ProviderIntentInfo[size];
+ }
+
+ @Override
+ protected boolean isFilterStopped(PackageParser.ProviderIntentInfo filter, int userId) {
+ if (!sUserManager.exists(userId))
+ return true;
+ PackageParser.Package p = filter.provider.owner;
+ if (p != null) {
+ PackageSetting ps = (PackageSetting) p.mExtras;
+ if (ps != null) {
+ // System apps are never considered stopped for purposes of
+ // filtering, because there may be no way for the user to
+ // actually re-launch them.
+ return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
+ && ps.getStopped(userId);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected boolean isPackageForFilter(String packageName,
+ PackageParser.ProviderIntentInfo info) {
+ return packageName.equals(info.provider.owner.packageName);
+ }
+
+ @Override
+ protected ResolveInfo newResult(PackageParser.ProviderIntentInfo filter,
+ int match, int userId) {
+ if (!sUserManager.exists(userId))
+ return null;
+ final PackageParser.ProviderIntentInfo info = filter;
+ if (!mSettings.isEnabledLPr(info.provider.info, mFlags, userId)) {
+ return null;
+ }
+ final PackageParser.Provider provider = info.provider;
+ if (mSafeMode && (provider.info.applicationInfo.flags
+ & ApplicationInfo.FLAG_SYSTEM) == 0) {
+ return null;
+ }
+ PackageSetting ps = (PackageSetting) provider.owner.mExtras;
+ if (ps == null) {
+ return null;
+ }
+ ProviderInfo pi = PackageParser.generateProviderInfo(provider, mFlags,
+ ps.readUserState(userId), userId);
+ if (pi == null) {
+ return null;
+ }
+ final ResolveInfo res = new ResolveInfo();
+ res.providerInfo = pi;
+ if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
+ res.filter = filter;
+ }
+ res.priority = info.getPriority();
+ res.preferredOrder = provider.owner.mPreferredOrder;
+ res.match = match;
+ res.isDefault = info.hasDefault;
+ res.labelRes = info.labelRes;
+ res.nonLocalizedLabel = info.nonLocalizedLabel;
+ res.icon = info.icon;
+ res.system = isSystemApp(res.providerInfo.applicationInfo);
+ return res;
+ }
+
+ @Override
+ protected void sortResults(List<ResolveInfo> results) {
+ Collections.sort(results, mResolvePrioritySorter);
+ }
+
+ @Override
+ protected void dumpFilter(PrintWriter out, String prefix,
+ PackageParser.ProviderIntentInfo filter) {
+ out.print(prefix);
+ out.print(
+ Integer.toHexString(System.identityHashCode(filter.provider)));
+ out.print(' ');
+ filter.provider.printComponentShortName(out);
+ out.print(" filter ");
+ out.println(Integer.toHexString(System.identityHashCode(filter)));
+ }
+
+ private final HashMap<ComponentName, PackageParser.Provider> mProviders
+ = new HashMap<ComponentName, PackageParser.Provider>();
+ private int mFlags;
+ };
+
private static final Comparator<ResolveInfo> mResolvePrioritySorter =
new Comparator<ResolveInfo>() {
public int compare(ResolveInfo r1, ResolveInfo r2) {
@@ -10454,6 +10677,11 @@
dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
dumpState.setTitlePrinted(true);
}
+ if (mProviders.dump(pw, dumpState.getTitlePrinted() ? "\nProvider Resolver Table:"
+ : "Provider Resolver Table:", " ", packageName,
+ dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
+ dumpState.setTitlePrinted(true);
+ }
}
if (dumpState.isDumping(DumpState.DUMP_PREFERRED)) {
@@ -10498,7 +10726,7 @@
if (dumpState.isDumping(DumpState.DUMP_PROVIDERS)) {
boolean printedSomething = false;
- for (PackageParser.Provider p : mProvidersByComponent.values()) {
+ for (PackageParser.Provider p : mProviders.mProviders.values()) {
if (packageName != null && !packageName.equals(p.info.packageName)) {
continue;
}
@@ -10512,7 +10740,8 @@
pw.print(" "); pw.println(p.toString());
}
printedSomething = false;
- for (Map.Entry<String, PackageParser.Provider> entry : mProviders.entrySet()) {
+ for (Map.Entry<String, PackageParser.Provider> entry :
+ mProvidersByAuthority.entrySet()) {
PackageParser.Provider p = entry.getValue();
if (packageName != null && !packageName.equals(p.info.packageName)) {
continue;
diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java
index 5f944f6..661bd41 100644
--- a/test-runner/src/android/test/mock/MockPackageManager.java
+++ b/test-runner/src/android/test/mock/MockPackageManager.java
@@ -282,6 +282,18 @@
throw new UnsupportedOperationException();
}
+ /** @hide */
+ @Override
+ public List<ResolveInfo> queryIntentContentProvidersAsUser(
+ Intent intent, int flags, int userId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public ProviderInfo resolveContentProvider(String name, int flags) {
throw new UnsupportedOperationException();
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 52ebaf0..f2e5254 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -636,6 +636,30 @@
return false;
}
+/*
+ * A simple container that holds a resource type and name. It is ordered first by type then
+ * by name.
+ */
+struct type_ident_pair_t {
+ String16 type;
+ String16 ident;
+
+ type_ident_pair_t() { };
+ type_ident_pair_t(const String16& t, const String16& i) : type(t), ident(i) { }
+ type_ident_pair_t(const type_ident_pair_t& o) : type(o.type), ident(o.ident) { }
+ inline bool operator < (const type_ident_pair_t& o) const {
+ int cmp = compare_type(type, o.type);
+ if (cmp < 0) {
+ return true;
+ } else if (cmp > 0) {
+ return false;
+ } else {
+ return strictly_order_type(ident, o.ident);
+ }
+ }
+};
+
+
status_t parseAndAddEntry(Bundle* bundle,
const sp<AaptFile>& in,
ResXMLTree* block,
@@ -650,6 +674,7 @@
const String16& product,
bool pseudolocalize,
const bool overwrite,
+ KeyedVector<type_ident_pair_t, bool>* skippedResourceNames,
ResourceTable* outTable)
{
status_t err;
@@ -684,6 +709,13 @@
if (bundleProduct[0] == '\0') {
if (strcmp16(String16("default").string(), product.string()) != 0) {
+ /*
+ * This string has a product other than 'default'. Do not add it,
+ * but record it so that if we do not see the same string with
+ * product 'default' or no product, then report an error.
+ */
+ skippedResourceNames->replaceValueFor(
+ type_ident_pair_t(curType, ident), true);
return NO_ERROR;
}
} else {
@@ -797,6 +829,11 @@
DefaultKeyedVector<String16, uint32_t> nextPublicId(0);
+ // Stores the resource names that were skipped. Typically this happens when
+ // AAPT is invoked without a product specified and a resource has no
+ // 'default' product attribute.
+ KeyedVector<type_ident_pair_t, bool> skippedResourceNames;
+
ResXMLTree::event_code_t code;
do {
code = block.next();
@@ -1544,7 +1581,7 @@
err = parseAndAddEntry(bundle, in, &block, curParams, myPackage, curType, ident,
*curTag, curIsStyled, curFormat, curIsFormatted,
- product, false, overwrite, outTable);
+ product, false, overwrite, &skippedResourceNames, outTable);
if (err < NO_ERROR) { // Why err < NO_ERROR instead of err != NO_ERROR?
hasErrors = localHasErrors = true;
@@ -1557,7 +1594,7 @@
err = parseAndAddEntry(bundle, in, &block, pseudoParams, myPackage, curType,
ident, *curTag, curIsStyled, curFormat,
curIsFormatted, product,
- true, overwrite, outTable);
+ true, overwrite, &skippedResourceNames, outTable);
if (err != NO_ERROR) {
hasErrors = localHasErrors = true;
}
@@ -1596,6 +1633,30 @@
}
}
+ // For every resource defined, there must be exist one variant with a product attribute
+ // set to 'default' (or no product attribute at all).
+ // We check to see that for every resource that was ignored because of a mismatched
+ // product attribute, some product variant of that resource was processed.
+ for (size_t i = 0; i < skippedResourceNames.size(); i++) {
+ if (skippedResourceNames[i]) {
+ const type_ident_pair_t& p = skippedResourceNames.keyAt(i);
+ if (!outTable->hasBagOrEntry(myPackage, p.type, p.ident)) {
+ const char* bundleProduct =
+ (bundle->getProduct() == NULL) ? "" : bundle->getProduct();
+ fprintf(stderr, "In resource file %s: %s\n",
+ in->getPrintableSource().string(),
+ curParams.toString().string());
+
+ fprintf(stderr, "\t%s '%s' does not match product %s.\n"
+ "\tYou may have forgotten to include a 'default' product variant"
+ " of the resource.\n",
+ String8(p.type).string(), String8(p.ident).string(),
+ bundleProduct[0] == 0 ? "default" : bundleProduct);
+ return UNKNOWN_ERROR;
+ }
+ }
+ }
+
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
}
@@ -2483,8 +2544,8 @@
String16 comment(c->getComment());
typeSymbols->appendComment(String8(c->getName()), comment, c->getPos());
- //printf("Type symbol %s comment: %s\n", String8(e->getName()).string(),
- // String8(comment).string());
+ //printf("Type symbol [%08x] %s comment: %s\n", rid,
+ // String8(c->getName()).string(), String8(comment).string());
comment = c->getTypeComment();
typeSymbols->appendTypeComment(String8(c->getName()), comment);
} else {