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 /services/voiceinteraction | |
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 'services/voiceinteraction')
3 files changed, 77 insertions, 44 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 42f879c..b57c413 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -448,7 +448,7 @@ public class VoiceInteractionManagerService extends SystemService { } final long caller = Binder.clearCallingIdentity(); try { - mImpl.showSessionLocked(args, flags, null /* showCallback */); + mImpl.showSessionLocked(args, flags, null, null); } finally { Binder.restoreCallingIdentity(caller); } @@ -463,12 +463,9 @@ public class VoiceInteractionManagerService extends SystemService { throw new SecurityException( "deliverNewSession without running voice interaction service"); } - final int callingPid = Binder.getCallingPid(); - final int callingUid = Binder.getCallingUid(); final long caller = Binder.clearCallingIdentity(); try { - return mImpl.deliverNewSessionLocked(callingPid, callingUid, token, session, - interactor); + return mImpl.deliverNewSessionLocked(token, session, interactor); } finally { Binder.restoreCallingIdentity(caller); } @@ -484,7 +481,7 @@ public class VoiceInteractionManagerService extends SystemService { } final long caller = Binder.clearCallingIdentity(); try { - return mImpl.showSessionLocked(sessionArgs, flags, null /* showCallback */); + return mImpl.showSessionLocked(sessionArgs, flags, null, null); } finally { Binder.restoreCallingIdentity(caller); } @@ -533,11 +530,9 @@ public class VoiceInteractionManagerService extends SystemService { Slog.w(TAG, "setKeepAwake without running voice interaction service"); return; } - final int callingPid = Binder.getCallingPid(); - final int callingUid = Binder.getCallingUid(); final long caller = Binder.clearCallingIdentity(); try { - mImpl.setKeepAwakeLocked(callingPid, callingUid, token, keepAwake); + mImpl.setKeepAwakeLocked(token, keepAwake); } finally { Binder.restoreCallingIdentity(caller); } @@ -551,11 +546,9 @@ public class VoiceInteractionManagerService extends SystemService { Slog.w(TAG, "closeSystemDialogs without running voice interaction service"); return; } - final int callingPid = Binder.getCallingPid(); - final int callingUid = Binder.getCallingUid(); final long caller = Binder.clearCallingIdentity(); try { - mImpl.closeSystemDialogsLocked(callingPid, callingUid, token); + mImpl.closeSystemDialogsLocked(token); } finally { Binder.restoreCallingIdentity(caller); } @@ -585,16 +578,14 @@ public class VoiceInteractionManagerService extends SystemService { Slog.w(TAG, "setDisabledShowContext without running voice interaction service"); return; } - final int callingPid = Binder.getCallingPid(); final int callingUid = Binder.getCallingUid(); final long caller = Binder.clearCallingIdentity(); try { - mImpl.setDisabledShowContextLocked(callingPid, callingUid, flags); + mImpl.setDisabledShowContextLocked(callingUid, flags); } finally { Binder.restoreCallingIdentity(caller); } } - } @Override @@ -604,16 +595,32 @@ public class VoiceInteractionManagerService extends SystemService { Slog.w(TAG, "getDisabledShowContext without running voice interaction service"); return 0; } - final int callingPid = Binder.getCallingPid(); final int callingUid = Binder.getCallingUid(); final long caller = Binder.clearCallingIdentity(); try { - return mImpl.getDisabledShowContextLocked(callingPid, callingUid); + return mImpl.getDisabledShowContextLocked(callingUid); } finally { Binder.restoreCallingIdentity(caller); } } + } + @Override + public int getUserDisabledShowContext() { + synchronized (this) { + if (mImpl == null) { + Slog.w(TAG, + "getUserDisabledShowContext without running voice interaction service"); + return 0; + } + final int callingUid = Binder.getCallingUid(); + final long caller = Binder.clearCallingIdentity(); + try { + return mImpl.getUserDisabledShowContextLocked(callingUid); + } finally { + Binder.restoreCallingIdentity(caller); + } + } } //----------------- Model management APIs --------------------------------// @@ -799,22 +806,22 @@ public class VoiceInteractionManagerService extends SystemService { } @Override - public void showSessionForActiveService(Bundle args, - IVoiceInteractionSessionShowCallback showCallback) { + public boolean showSessionForActiveService(Bundle args, int sourceFlags, + IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); synchronized (this) { if (mImpl == null) { Slog.w(TAG, "showSessionForActiveService without running voice interaction" + "service"); - return; + return false; } final long caller = Binder.clearCallingIdentity(); try { - mImpl.showSessionLocked(args, - VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE + return mImpl.showSessionLocked(args, + sourceFlags | VoiceInteractionSession.SHOW_WITH_ASSIST | VoiceInteractionSession.SHOW_WITH_SCREENSHOT, - showCallback); + showCallback, activityToken); } finally { Binder.restoreCallingIdentity(caller); } @@ -908,7 +915,8 @@ public class VoiceInteractionManagerService extends SystemService { } private void enforceCallingPermission(String permission) { - if (mContext.checkCallingPermission(permission) != PackageManager.PERMISSION_GRANTED) { + if (mContext.checkCallingOrSelfPermission(permission) + != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Caller does not hold the permission " + permission); } } diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index 7409f99..a4facc1 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -142,12 +142,13 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne } public boolean showSessionLocked(Bundle args, int flags, - IVoiceInteractionSessionShowCallback showCallback) { + IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { if (mActiveSession == null) { mActiveSession = new VoiceInteractionSessionConnection(mLock, mSessionComponentName, mUser, mContext, this, mInfo.getServiceInfo().applicationInfo.uid, mHandler); } - return mActiveSession.showLocked(args, flags, mDisabledShowContext, showCallback); + return mActiveSession.showLocked(args, flags, mDisabledShowContext, showCallback, + activityToken); } public boolean hideSessionLocked() { @@ -157,7 +158,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne return false; } - public boolean deliverNewSessionLocked(int callingPid, int callingUid, IBinder token, + public boolean deliverNewSessionLocked(IBinder token, IVoiceInteractionSession session, IVoiceInteractor interactor) { if (mActiveSession == null || token != mActiveSession.mToken) { Slog.w(TAG, "deliverNewSession does not match active session"); @@ -189,8 +190,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne } } - public void setKeepAwakeLocked(int callingPid, int callingUid, IBinder token, - boolean keepAwake) { + public void setKeepAwakeLocked(IBinder token, boolean keepAwake) { try { if (mActiveSession == null || token != mActiveSession.mToken) { Slog.w(TAG, "setKeepAwake does not match active session"); @@ -202,7 +202,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne } } - public void closeSystemDialogsLocked(int callingPid, int callingUid, IBinder token) { + public void closeSystemDialogsLocked(IBinder token) { try { if (mActiveSession == null || token != mActiveSession.mToken) { Slog.w(TAG, "closeSystemDialogs does not match active session"); @@ -223,7 +223,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mActiveSession = null; } - public void setDisabledShowContextLocked(int callingPid, int callingUid, int flags) { + public void setDisabledShowContextLocked(int callingUid, int flags) { int activeUid = mInfo.getServiceInfo().applicationInfo.uid; if (callingUid != activeUid) { throw new SecurityException("Calling uid " + callingUid @@ -232,7 +232,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mDisabledShowContext = flags; } - public int getDisabledShowContextLocked(int callingPid, int callingUid) { + public int getDisabledShowContextLocked(int callingUid) { int activeUid = mInfo.getServiceInfo().applicationInfo.uid; if (callingUid != activeUid) { throw new SecurityException("Calling uid " + callingUid @@ -241,6 +241,15 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne return mDisabledShowContext; } + public int getUserDisabledShowContextLocked(int callingUid) { + int activeUid = mInfo.getServiceInfo().applicationInfo.uid; + if (callingUid != activeUid) { + throw new SecurityException("Calling uid " + callingUid + + " does not match active uid " + activeUid); + } + return mActiveSession != null ? mActiveSession.getUserDisabledShowContextLocked() : 0; + } + public void dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args) { if (!mValid) { pw.print(" NOT VALID: "); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java index dfdd639..47a9fcd 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java @@ -183,8 +183,21 @@ final class VoiceInteractionSessionConnection implements ServiceConnection { } } + public int getUserDisabledShowContextLocked() { + int flags = 0; + if (Settings.Secure.getIntForUser(mContext.getContentResolver(), + Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, mUser) == 0) { + flags |= VoiceInteractionSession.SHOW_WITH_ASSIST; + } + if (Settings.Secure.getIntForUser(mContext.getContentResolver(), + Settings.Secure.ASSIST_SCREENSHOT_ENABLED, 1, mUser) == 0) { + flags |= VoiceInteractionSession.SHOW_WITH_SCREENSHOT; + } + return flags; + } + public boolean showLocked(Bundle args, int flags, int disabledContext, - IVoiceInteractionSessionShowCallback showCallback) { + IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { if (mBound) { if (!mFullyBound) { mFullyBound = mContext.bindServiceAsUser(mBindIntent, mFullConnection, @@ -193,18 +206,15 @@ final class VoiceInteractionSessionConnection implements ServiceConnection { new UserHandle(mUser)); } mShown = true; - boolean isScreenCaptureAllowed = true; + boolean isAssistDataAllowed = true; try { - isScreenCaptureAllowed = mAm.isScreenCaptureAllowedOnCurrentActivity(); + isAssistDataAllowed = mAm.isAssistDataAllowedOnCurrentActivity(); } catch (RemoteException e) { } - boolean structureEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), - Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, mUser) != 0 - && isScreenCaptureAllowed + disabledContext |= getUserDisabledShowContextLocked(); + boolean structureEnabled = isAssistDataAllowed && (disabledContext&VoiceInteractionSession.SHOW_WITH_ASSIST) == 0; - boolean screenshotEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), - Settings.Secure.ASSIST_SCREENSHOT_ENABLED, 1, mUser) != 0 - && isScreenCaptureAllowed + boolean screenshotEnabled = isAssistDataAllowed && (disabledContext&VoiceInteractionSession.SHOW_WITH_SCREENSHOT) == 0; mShowArgs = args; mShowFlags = flags; @@ -215,9 +225,15 @@ final class VoiceInteractionSessionConnection implements ServiceConnection { mSessionComponentName.getPackageName()) == AppOpsManager.MODE_ALLOWED && structureEnabled) { try { - needDisclosure = true; - mAm.requestAssistContextExtras(ActivityManager.ASSIST_CONTEXT_FULL, - mAssistReceiver); + if (mAm.requestAssistContextExtras(ActivityManager.ASSIST_CONTEXT_FULL, + mAssistReceiver, activityToken)) { + needDisclosure = true; + } else { + // Wasn't allowed... given that, let's not do the screenshot either. + mHaveAssistData = true; + mAssistData = null; + screenshotEnabled = false; + } } catch (RemoteException e) { } } else { |