diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-07-17 18:04:14 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2015-07-20 12:49:10 -0700 |
commit | 17f693520da8977c4a60f5b4be3be035cba7146c (patch) | |
tree | 6e3fcf5d6adb3d72ab5b7c2300f3bb8ebe8bc550 /core | |
parent | 5aff3b5489262ccff4b6f9e18e0d990ebfe4d7bc (diff) | |
download | frameworks_base-17f693520da8977c4a60f5b4be3be035cba7146c.zip frameworks_base-17f693520da8977c4a60f5b4be3be035cba7146c.tar.gz frameworks_base-17f693520da8977c4a60f5b4be3be035cba7146c.tar.bz2 |
Fix issue #22531747: Assist info should declare if user has disabled...
...context and/or screenshot
Added new API to find out what contextual data has been globally disabled.
Also updated various documentation to make it clear what kind of contextual
data you will get (and when it will be null).
Also added a new Activity.showAssist() API because... well, I was already
in there, it was easy to do, it is safe, and maybe people will build cool
things with it.
Change-Id: Ia553d6bcdd098dc0fce4b9237fbfaca9652fc74b
Diffstat (limited to 'core')
7 files changed, 109 insertions, 20 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 96c7f84..8d4ce62 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -1545,6 +1545,24 @@ public class Activity extends ContextThemeWrapper } /** + * Ask to have the current assistant shown to the user. This only works if the calling + * activity is the current foreground activity. It is the same as calling + * {@link android.service.voice.VoiceInteractionService#showSession + * VoiceInteractionService.showSession} and requesting all of the possible context. + * The receiver will always see + * {@link android.service.voice.VoiceInteractionSession#SHOW_SOURCE_APPLICATION} set. + * @return Returns true if the assistant was successfully invoked, else false. For example + * false will be returned if the caller is not the current top activity. + */ + public boolean showAssist(Bundle args) { + try { + return ActivityManagerNative.getDefault().showAssistFromActivity(mToken, args); + } catch (RemoteException e) { + } + return false; + } + + /** * Called when you are no longer visible to the user. You will next * receive either {@link #onRestart}, {@link #onDestroy}, or nothing, * depending on later user activity. diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 9ca206a..55b2fd9 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -2807,7 +2807,7 @@ public class ActivityManager { /** * Request that the system start watching for the calling process to exceed a pss - * size as given here. Once called, the system will look for any occassions where it + * size as given here. Once called, the system will look for any occasions where it * sees the associated process with a larger pss size and, when this happens, automatically * pull a heap dump from it and allow the user to share the data. Note that this request * continues running even if the process is killed and restarted. To remove the watch, diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index bfb92c4..b758a7a 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -2193,8 +2193,10 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM data.enforceInterface(IActivityManager.descriptor); int requestType = data.readInt(); IResultReceiver receiver = IResultReceiver.Stub.asInterface(data.readStrongBinder()); - requestAssistContextExtras(requestType, receiver); + IBinder activityToken = data.readStrongBinder(); + boolean res = requestAssistContextExtras(requestType, receiver, activityToken); reply.writeNoException(); + reply.writeInt(res ? 1 : 0); return true; } @@ -2225,7 +2227,17 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM case IS_SCREEN_CAPTURE_ALLOWED_ON_CURRENT_ACTIVITY_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); - boolean res = isScreenCaptureAllowedOnCurrentActivity(); + boolean res = isAssistDataAllowedOnCurrentActivity(); + reply.writeNoException(); + reply.writeInt(res ? 1 : 0); + return true; + } + + case SHOW_ASSIST_FROM_ACTIVITY_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + IBinder token = data.readStrongBinder(); + Bundle args = data.readBundle(); + boolean res = showAssistFromActivity(token, args); reply.writeNoException(); reply.writeInt(res ? 1 : 0); return true; @@ -5377,17 +5389,20 @@ class ActivityManagerProxy implements IActivityManager return res; } - public void requestAssistContextExtras(int requestType, IResultReceiver receiver) - throws RemoteException { + public boolean requestAssistContextExtras(int requestType, IResultReceiver receiver, + IBinder activityToken) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeInt(requestType); data.writeStrongBinder(receiver.asBinder()); + data.writeStrongBinder(activityToken); mRemote.transact(REQUEST_ASSIST_CONTEXT_EXTRAS_TRANSACTION, data, reply, 0); reply.readException(); + boolean res = reply.readInt() != 0; data.recycle(); reply.recycle(); + return res; } public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, @@ -5429,7 +5444,7 @@ class ActivityManagerProxy implements IActivityManager return res; } - public boolean isScreenCaptureAllowedOnCurrentActivity() throws RemoteException { + public boolean isAssistDataAllowedOnCurrentActivity() throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); @@ -5441,6 +5456,20 @@ class ActivityManagerProxy implements IActivityManager return res; } + public boolean showAssistFromActivity(IBinder token, Bundle args) throws RemoteException { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeStrongBinder(token); + data.writeBundle(args); + mRemote.transact(SHOW_ASSIST_FROM_ACTIVITY_TRANSACTION, data, reply, 0); + reply.readException(); + boolean res = reply.readInt() != 0; + data.recycle(); + reply.recycle(); + return res; + } + public void killUid(int uid, String reason) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index 5eb3961..9ebbb9b 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -434,8 +434,8 @@ public interface IActivityManager extends IInterface { public Bundle getAssistContextExtras(int requestType) throws RemoteException; - public void requestAssistContextExtras(int requestType, IResultReceiver receiver) - throws RemoteException; + public boolean requestAssistContextExtras(int requestType, IResultReceiver receiver, + IBinder activityToken) throws RemoteException; public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, AssistContent content, Uri referrer) throws RemoteException; @@ -443,7 +443,9 @@ public interface IActivityManager extends IInterface { public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, Bundle args) throws RemoteException; - public boolean isScreenCaptureAllowedOnCurrentActivity() throws RemoteException; + public boolean isAssistDataAllowedOnCurrentActivity() throws RemoteException; + + public boolean showAssistFromActivity(IBinder token, Bundle args) throws RemoteException; public void killUid(int uid, String reason) throws RemoteException; @@ -858,4 +860,5 @@ public interface IActivityManager extends IInterface { int UNREGISTER_UID_OBSERVER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+298; int IS_SCREEN_CAPTURE_ALLOWED_ON_CURRENT_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+299; + int SHOW_ASSIST_FROM_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+300; } diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java index 95f96e8..a3ccbd3 100644 --- a/core/java/android/service/voice/VoiceInteractionSession.java +++ b/core/java/android/service/voice/VoiceInteractionSession.java @@ -91,6 +91,12 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall */ public static final int SHOW_SOURCE_ASSIST_GESTURE = 1<<2; + /** + * Flag for use with {@link #onShow}: indicates that the application itself has invoked + * the assistant. + */ + public static final int SHOW_SOURCE_APPLICATION = 1<<3; + final Context mContext; final HandlerCaller mHandlerCaller; @@ -936,6 +942,23 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall } /** + * Return which show context flags have been disabled by the user through the system + * settings UI, so the session will never get this data. Returned flags are any combination of + * {@link VoiceInteractionSession#SHOW_WITH_ASSIST VoiceInteractionSession.SHOW_WITH_ASSIST} and + * {@link VoiceInteractionSession#SHOW_WITH_SCREENSHOT + * VoiceInteractionSession.SHOW_WITH_SCREENSHOT}. Note that this only tells you about + * global user settings, not about restrictions that may be applied contextual based on + * the current application the user is in or other transient states. + */ + public int getUserDisabledShowContext() { + try { + return mSystemService.getUserDisabledShowContext(); + } catch (RemoteException e) { + return 0; + } + } + + /** * Show the UI for this session. This asks the system to go through the process of showing * your UI, which will eventually culminate in {@link #onShow}. This is similar to calling * {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}. @@ -1179,23 +1202,33 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall /** * Called to receive data from the application that the user was currently viewing when - * an assist session is started. + * an assist session is started. If the original show request did not specify + * {@link #SHOW_WITH_ASSIST}, this method will not be called. * * @param data Arbitrary data supplied by the app through * {@link android.app.Activity#onProvideAssistData Activity.onProvideAssistData}. + * May be null if assist data has been disabled by the user or device policy. * @param structure If available, the structure definition of all windows currently - * displayed by the app; if structure has been turned off by the user, will be null. + * displayed by the app. May be null if assist data has been disabled by the user + * or device policy; will be an empty stub if the application has disabled assist + * by marking its window as secure. * @param content Additional content data supplied by the app through * {@link android.app.Activity#onProvideAssistContent Activity.onProvideAssistContent}. + * May be null if assist data has been disabled by the user or device policy; will + * not be automatically filled in with data from the app if the app has marked its + * window as secure. */ - public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) { + public void onHandleAssist(@Nullable Bundle data, @Nullable AssistStructure structure, + @Nullable AssistContent content) { } /** * Called to receive a screenshot of what the user was currently viewing when an assist - * session is started. Will be null if screenshots are disabled by the user. + * session is started. May be null if screenshots are disabled by the user, policy, + * or application. If the original show request did not specify + * {@link #SHOW_WITH_SCREENSHOT}, this method will not be called. */ - public void onHandleScreenshot(Bitmap screenshot) { + public void onHandleScreenshot(@Nullable Bitmap screenshot) { } public boolean onKeyDown(int keyCode, KeyEvent event) { diff --git a/core/java/com/android/internal/app/AssistUtils.java b/core/java/com/android/internal/app/AssistUtils.java index 6ba09c9..ff989bd 100644 --- a/core/java/com/android/internal/app/AssistUtils.java +++ b/core/java/com/android/internal/app/AssistUtils.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; @@ -45,13 +46,15 @@ public class AssistUtils { ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE)); } - public void showSessionForActiveService(Bundle args, - IVoiceInteractionSessionShowCallback showCallback) { + public boolean showSessionForActiveService(Bundle args, int sourceFlags, + IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { try { - mVoiceInteractionManagerService.showSessionForActiveService(args, showCallback); + return mVoiceInteractionManagerService.showSessionForActiveService(args, sourceFlags, + showCallback, activityToken); } catch (RemoteException e) { Log.w(TAG, "Failed to call showSessionForActiveService", e); } + return false; } public void launchVoiceAssistFromKeyguard() { diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl index 73ad981..dc946ab 100644 --- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl @@ -39,6 +39,7 @@ interface IVoiceInteractionManagerService { void finish(IBinder token); void setDisabledShowContext(int flags); int getDisabledShowContext(); + int getUserDisabledShowContext(); /** * Gets the registered Sound model for keyphrase detection for the current user. @@ -96,10 +97,12 @@ interface IVoiceInteractionManagerService { * affordances. * * @param args the bundle to pass as arguments to the voice interaction session - * @param showCallback callback to be notified when the session was shown + * @param sourceFlags flags indicating the source of this show + * @param showCallback optional callback to be notified when the session was shown + * @param activityToken optional token of activity that needs to be on top */ - void showSessionForActiveService(in Bundle args, - IVoiceInteractionSessionShowCallback showCallback); + boolean showSessionForActiveService(in Bundle args, int sourceFlags, + IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken); /** * Hides the session from the active service, if it is showing. |