diff options
author | Matt Casey <mrcasey@google.com> | 2013-08-08 09:33:07 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-08-08 09:33:08 +0000 |
commit | 77ece7b192d45351b313ee23270caab373d3c477 (patch) | |
tree | cc2ebf80b6dc0d4489bbeee0eeabda6c344ff551 /core/java | |
parent | 81ba97841089bd23b82c7c6feadd3112ad22966c (diff) | |
parent | dfc7fd7818cda46b914c8a9d69d1ba00443ffe5b (diff) | |
download | frameworks_base-77ece7b192d45351b313ee23270caab373d3c477.zip frameworks_base-77ece7b192d45351b313ee23270caab373d3c477.tar.gz frameworks_base-77ece7b192d45351b313ee23270caab373d3c477.tar.bz2 |
Merge "Extend assist context to foreground services"
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 19 | ||||
-rw-r--r-- | core/java/android/app/ActivityThread.java | 29 | ||||
-rw-r--r-- | core/java/android/app/ApplicationThreadNative.java | 13 | ||||
-rw-r--r-- | core/java/android/app/IActivityManager.java | 9 | ||||
-rw-r--r-- | core/java/android/app/IApplicationThread.java | 6 | ||||
-rw-r--r-- | core/java/android/app/SearchManager.java | 2 | ||||
-rw-r--r-- | core/java/android/app/Service.java | 13 | ||||
-rw-r--r-- | core/java/android/content/Intent.java | 33 | ||||
-rw-r--r-- | core/java/android/content/pm/PackageParser.java | 5 | ||||
-rw-r--r-- | core/java/android/content/pm/ServiceInfo.java | 8 |
10 files changed, 99 insertions, 38 deletions
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index 404f6aa..cc964c2 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -1921,20 +1921,21 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } - case GET_TOP_ACTIVITY_EXTRAS_TRANSACTION: { + case GET_ASSIST_CONTEXT_EXTRAS_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); int requestType = data.readInt(); - Bundle res = getTopActivityExtras(requestType); + Bundle res = getAssistContextExtras(requestType); reply.writeNoException(); reply.writeBundle(res); return true; } - case REPORT_TOP_ACTIVITY_EXTRAS_TRANSACTION: { + case REPORT_ASSIST_CONTEXT_EXTRAS_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); IBinder token = data.readStrongBinder(); Bundle extras = data.readBundle(); - reportTopActivityExtras(token, extras); + int index = data.readInt(); + reportAssistContextExtras(token, extras, index); reply.writeNoException(); return true; } @@ -4456,12 +4457,12 @@ class ActivityManagerProxy implements IActivityManager return res; } - public Bundle getTopActivityExtras(int requestType) throws RemoteException { + public Bundle getAssistContextExtras(int requestType) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeInt(requestType); - mRemote.transact(GET_TOP_ACTIVITY_EXTRAS_TRANSACTION, data, reply, 0); + mRemote.transact(GET_ASSIST_CONTEXT_EXTRAS_TRANSACTION, data, reply, 0); reply.readException(); Bundle res = reply.readBundle(); data.recycle(); @@ -4469,13 +4470,15 @@ class ActivityManagerProxy implements IActivityManager return res; } - public void reportTopActivityExtras(IBinder token, Bundle extras) throws RemoteException { + public void reportAssistContextExtras(IBinder token, Bundle extras, int index) + throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(token); data.writeBundle(extras); - mRemote.transact(REPORT_TOP_ACTIVITY_EXTRAS_TRANSACTION, data, reply, 0); + data.writeInt(index); + mRemote.transact(REPORT_ASSIST_CONTEXT_EXTRAS_TRANSACTION, data, reply, 0); reply.readException(); data.recycle(); reply.recycle(); diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 5300eca..2a28b76 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -529,10 +529,11 @@ public final class ActivityThread { CompatibilityInfo info; } - static final class RequestActivityExtras { + static final class RequestAssistContextExtras { IBinder activityToken; IBinder requestToken; int requestType; + int index; } private native void dumpGraphicsInfo(FileDescriptor fd); @@ -1197,13 +1198,14 @@ public final class ActivityThread { } @Override - public void requestActivityExtras(IBinder activityToken, IBinder requestToken, - int requestType) { - RequestActivityExtras cmd = new RequestActivityExtras(); + public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, + int requestType, int index) { + RequestAssistContextExtras cmd = new RequestAssistContextExtras(); cmd.activityToken = activityToken; cmd.requestToken = requestToken; cmd.requestType = requestType; - queueOrSendMessage(H.REQUEST_ACTIVITY_EXTRAS, cmd); + cmd.index = index; + queueOrSendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); } private void printRow(PrintWriter pw, String format, Object...objs) { @@ -1292,7 +1294,7 @@ public final class ActivityThread { public static final int TRIM_MEMORY = 140; public static final int DUMP_PROVIDER = 141; public static final int UNSTABLE_PROVIDER_DIED = 142; - public static final int REQUEST_ACTIVITY_EXTRAS = 143; + public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; String codeToString(int code) { if (DEBUG_MESSAGES) { @@ -1340,7 +1342,7 @@ public final class ActivityThread { case TRIM_MEMORY: return "TRIM_MEMORY"; case DUMP_PROVIDER: return "DUMP_PROVIDER"; case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; - case REQUEST_ACTIVITY_EXTRAS: return "REQUEST_ACTIVITY_EXTRAS"; + case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; } } @@ -1553,8 +1555,8 @@ public final class ActivityThread { case UNSTABLE_PROVIDER_DIED: handleUnstableProviderDied((IBinder)msg.obj, false); break; - case REQUEST_ACTIVITY_EXTRAS: - handleRequestActivityExtras((RequestActivityExtras)msg.obj); + case REQUEST_ASSIST_CONTEXT_EXTRAS: + handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); break; case TRANSLUCENT_CONVERSION_COMPLETE: handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); @@ -2275,19 +2277,24 @@ public final class ActivityThread { performNewIntents(data.token, data.intents); } - public void handleRequestActivityExtras(RequestActivityExtras cmd) { + public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { Bundle data = new Bundle(); ActivityClientRecord r = mActivities.get(cmd.activityToken); if (r != null) { r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); r.activity.onProvideAssistData(data); + } else { + Service service = mServices.get(cmd.activityToken); + if (service != null) { + service.onProvideAssistData(data); + } } if (data.isEmpty()) { data = null; } IActivityManager mgr = ActivityManagerNative.getDefault(); try { - mgr.reportTopActivityExtras(cmd.requestToken, data); + mgr.reportAssistContextExtras(cmd.requestToken, data, cmd.index); } catch (RemoteException e) { } } diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java index 1465de2..c0080be 100644 --- a/core/java/android/app/ApplicationThreadNative.java +++ b/core/java/android/app/ApplicationThreadNative.java @@ -600,13 +600,14 @@ public abstract class ApplicationThreadNative extends Binder return true; } - case REQUEST_ACTIVITY_EXTRAS_TRANSACTION: + case REQUEST_ASSIST_CONTEXT_EXTRAS_TRANSACTION: { data.enforceInterface(IApplicationThread.descriptor); IBinder activityToken = data.readStrongBinder(); IBinder requestToken = data.readStrongBinder(); int requestType = data.readInt(); - requestActivityExtras(activityToken, requestToken, requestType); + int index = data.readInt(); + requestAssistContextExtras(activityToken, requestToken, requestType, index); reply.writeNoException(); return true; } @@ -1241,14 +1242,16 @@ class ApplicationThreadProxy implements IApplicationThread { } @Override - public void requestActivityExtras(IBinder activityToken, IBinder requestToken, int requestType) - throws RemoteException { + public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, + int requestType, int index) throws RemoteException { Parcel data = Parcel.obtain(); data.writeInterfaceToken(IApplicationThread.descriptor); data.writeStrongBinder(activityToken); data.writeStrongBinder(requestToken); data.writeInt(requestType); - mRemote.transact(REQUEST_ACTIVITY_EXTRAS_TRANSACTION, data, null, IBinder.FLAG_ONEWAY); + data.writeInt(index); + mRemote.transact(REQUEST_ASSIST_CONTEXT_EXTRAS_TRANSACTION, data, null, + IBinder.FLAG_ONEWAY); data.recycle(); } diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index 3eda58c..3851eb3 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -386,9 +386,10 @@ public interface IActivityManager extends IInterface { public long inputDispatchingTimedOut(int pid, boolean aboveSystem) throws RemoteException; - public Bundle getTopActivityExtras(int requestType) throws RemoteException; + public Bundle getAssistContextExtras(int requestType) throws RemoteException; - public void reportTopActivityExtras(IBinder token, Bundle extras) throws RemoteException; + public void reportAssistContextExtras(IBinder token, Bundle extras, int index) + throws RemoteException; public void killUid(int uid, String reason) throws RemoteException; @@ -662,8 +663,8 @@ public interface IActivityManager extends IInterface { int INPUT_DISPATCHING_TIMED_OUT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+158; int CLEAR_PENDING_BACKUP_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+159; int GET_INTENT_FOR_INTENT_SENDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+160; - int GET_TOP_ACTIVITY_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+161; - int REPORT_TOP_ACTIVITY_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+162; + int GET_ASSIST_CONTEXT_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+161; + int REPORT_ASSIST_CONTEXT_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+162; int GET_LAUNCHED_FROM_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+163; int KILL_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+164; int SET_USER_IS_MONKEY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+165; diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java index 61c499a..01a0a91 100644 --- a/core/java/android/app/IApplicationThread.java +++ b/core/java/android/app/IApplicationThread.java @@ -133,8 +133,8 @@ public interface IApplicationThread extends IInterface { void dumpGfxInfo(FileDescriptor fd, String[] args) throws RemoteException; void dumpDbInfo(FileDescriptor fd, String[] args) throws RemoteException; void unstableProviderDied(IBinder provider) throws RemoteException; - void requestActivityExtras(IBinder activityToken, IBinder requestToken, int requestType) - throws RemoteException; + void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, int requestType, + int index) throws RemoteException; void scheduleTranslucentConversionComplete(IBinder token, boolean timeout) throws RemoteException; void setProcessState(int state) throws RemoteException; @@ -187,7 +187,7 @@ public interface IApplicationThread extends IInterface { int DUMP_PROVIDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+44; int DUMP_DB_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+45; int UNSTABLE_PROVIDER_DIED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+46; - int REQUEST_ACTIVITY_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+47; + int REQUEST_ASSIST_CONTEXT_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+47; int SCHEDULE_TRANSLUCENT_CONVERSION_COMPLETE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+48; int SET_PROCESS_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+49; } diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java index 7dfc589..f9c245e 100644 --- a/core/java/android/app/SearchManager.java +++ b/core/java/android/app/SearchManager.java @@ -869,7 +869,7 @@ public class SearchManager intent.setComponent(comp); if (inclContext) { IActivityManager am = ActivityManagerNative.getDefault(); - Bundle extras = am.getTopActivityExtras(0); + Bundle extras = am.getAssistContextExtras(0); if (extras != null) { intent.replaceExtras(extras); } diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java index 3967740..7f8ddfd 100644 --- a/core/java/android/app/Service.java +++ b/core/java/android/app/Service.java @@ -23,6 +23,7 @@ import android.content.ContextWrapper; import android.content.Context; import android.content.res.Configuration; import android.os.Build; +import android.os.Bundle; import android.os.RemoteException; import android.os.IBinder; import android.util.Log; @@ -307,6 +308,18 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac } /** + * This is called on foreground services when the user is requesting an assist, to build a + * full {@link Intent#ACTION_ASSIST} Intent with all of the context of the current + * running foreground services. You can override this method to place into the bundle + * anything you would like to appear as an item in the + * {@link Intent#EXTRA_SERVICES_ASSIST_CONTEXT} part of the assist Intent. + * This method will not be called if this service is not in the foreground. + * The default implementation does nothing. + */ + public void onProvideAssistData(Bundle data) { + } + + /** * @deprecated Implement {@link #onStartCommand(Intent, int, int)} instead. */ @Deprecated diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 205ca6b..ff350b9 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -1152,9 +1152,10 @@ public class Intent implements Parcelable, Cloneable { /** * Activity Action: Perform assist action. * <p> - * Input: {@link #EXTRA_ASSIST_PACKAGE} and {@link #EXTRA_ASSIST_CONTEXT} can provide - * additional optional contextual information about where the user was when they requested - * the assist. + * Input: {@link #EXTRA_ASSIST_PACKAGE}, {@link #EXTRA_ASSIST_CONTEXT}, + * {@link #EXTRA_ASSIST_SERVICES_PACKAGES}, and {@link #EXTRA_ASSIST_SERVICES_CONTEXTS} can + * provide additional optional contextual information about where the user was when they + * requested the assist. * Output: nothing. */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) @@ -1163,9 +1164,10 @@ public class Intent implements Parcelable, Cloneable { /** * Activity Action: Perform voice assist action. * <p> - * Input: {@link #EXTRA_ASSIST_PACKAGE} and {@link #EXTRA_ASSIST_CONTEXT} can provide - * additional optional contextual information about where the user was when they requested - * the voice assist. + * Input: {@link #EXTRA_ASSIST_PACKAGE}, {@link #EXTRA_ASSIST_CONTEXT}, + * {@link #EXTRA_ASSIST_SERVICES_PACKAGES}, and {@link #EXTRA_ASSIST_SERVICES_CONTEXTS} can + * provide additional optional contextual information about where the user was when they + * requested the voice assist. * Output: nothing. */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) @@ -1189,6 +1191,25 @@ public class Intent implements Parcelable, Cloneable { = "android.intent.extra.ASSIST_CONTEXT"; /** + * An optional field on {@link #ACTION_ASSIST} and {@link #ACTION_VOICE_ASSIST} + * containing an the names of the application package of foreground services at the time + * of the assist request. This is an array of {@link String}s, with one entry + * per service. + */ + public static final String EXTRA_ASSIST_SERVICES_PACKAGES + = "android.intent.extra.ASSIST_SERVICES_PACKAGES"; + + /** + * An optional field on {@link #ACTION_ASSIST} and {@link #ACTION_VOICE_ASSIST} + * containing additional contextual information supplied by the current + * foreground services at the time of the assist request. This is an array + * of {@link Bundle}s of additional data, with one {@link Bundle} per service. + */ + public static final String EXTRA_ASSIST_SERVICES_CONTEXTS + = "android.intent.extra.ASSIST_SERVICES_CONTEXTS"; + + + /** * Activity Action: List all available applications * <p>Input: Nothing. * <p>Output: nothing. diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index aaa2640..b432164 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -3005,6 +3005,11 @@ public class PackageParser { s.info.flags = 0; if (sa.getBoolean( + com.android.internal.R.styleable.AndroidManifestService_provideAssistData, + false)) { + s.info.flags |= ServiceInfo.FLAG_PROVIDE_ASSIST_DATA; + } + if (sa.getBoolean( com.android.internal.R.styleable.AndroidManifestService_stopWithTask, false)) { s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java index 796c2a4..a57a853 100644 --- a/core/java/android/content/pm/ServiceInfo.java +++ b/core/java/android/content/pm/ServiceInfo.java @@ -49,6 +49,14 @@ public class ServiceInfo extends ComponentInfo public static final int FLAG_ISOLATED_PROCESS = 0x0002; /** + * Bit in {@link #flags}: If set, + * {@link Service#onProvideAssistData(android.os.Bundle)} will be + * called on the service when it is running in the foreground. Set from + * the {@link android.R.attr#provideAssistData} attribute. + */ + public static final int FLAG_PROVIDE_ASSIST_DATA = 0x0004; + + /** * Bit in {@link #flags}: If set, a single instance of the service will * run for all users on the device. Set from the * {@link android.R.attr#singleUser} attribute. |