diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-07-15 23:31:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-15 23:31:25 +0000 |
commit | f6586cbde7d4612963eb2e8a2413235630676b83 (patch) | |
tree | 331efab4ff95a97093e82ab9e1cc0b91bcc57867 /services | |
parent | 67e02e60ca58db95b397fde7bfeeebb012e8aff8 (diff) | |
parent | 1de1186d28f0ca7c0b6298edfa8ae497e651ba87 (diff) | |
download | frameworks_base-f6586cbde7d4612963eb2e8a2413235630676b83.zip frameworks_base-f6586cbde7d4612963eb2e8a2413235630676b83.tar.gz frameworks_base-f6586cbde7d4612963eb2e8a2413235630676b83.tar.bz2 |
Merge "Implement issue #22403908: Enable assistant to refuse context sharing" into mnc-dev
Diffstat (limited to 'services')
3 files changed, 69 insertions, 6 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 36478da..42f879c 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -578,6 +578,44 @@ public class VoiceInteractionManagerService extends SystemService { } } + @Override + public void setDisabledShowContext(int flags) { + synchronized (this) { + if (mImpl == null) { + 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); + } finally { + Binder.restoreCallingIdentity(caller); + } + } + + } + + @Override + public int getDisabledShowContext() { + synchronized (this) { + if (mImpl == null) { + 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); + } finally { + Binder.restoreCallingIdentity(caller); + } + } + + } + //----------------- Model management APIs --------------------------------// @Override diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index e5faf4d..7409f99 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -65,6 +65,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne IVoiceInteractionService mService; VoiceInteractionSessionConnection mActiveSession; + int mDisabledShowContext; final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override @@ -146,7 +147,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mActiveSession = new VoiceInteractionSessionConnection(mLock, mSessionComponentName, mUser, mContext, this, mInfo.getServiceInfo().applicationInfo.uid, mHandler); } - return mActiveSession.showLocked(args, flags, showCallback); + return mActiveSession.showLocked(args, flags, mDisabledShowContext, showCallback); } public boolean hideSessionLocked() { @@ -222,6 +223,24 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mActiveSession = null; } + public void setDisabledShowContextLocked(int callingPid, int callingUid, int flags) { + int activeUid = mInfo.getServiceInfo().applicationInfo.uid; + if (callingUid != activeUid) { + throw new SecurityException("Calling uid " + callingUid + + " does not match active uid " + activeUid); + } + mDisabledShowContext = flags; + } + + public int getDisabledShowContextLocked(int callingPid, int callingUid) { + int activeUid = mInfo.getServiceInfo().applicationInfo.uid; + if (callingUid != activeUid) { + throw new SecurityException("Calling uid " + callingUid + + " does not match active uid " + activeUid); + } + return mDisabledShowContext; + } + public void dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args) { if (!mValid) { pw.print(" NOT VALID: "); @@ -235,6 +254,10 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne pw.print(" mComponent="); pw.println(mComponent.flattenToShortString()); pw.print(" Session service="); pw.println(mInfo.getSessionService()); pw.print(" Settings activity="); pw.println(mInfo.getSettingsActivity()); + if (mDisabledShowContext != 0) { + pw.print(" mDisabledShowContext="); + pw.println(Integer.toHexString(mDisabledShowContext)); + } pw.print(" mBound="); pw.print(mBound); pw.print(" mService="); pw.println(mService); if (mActiveSession != null) { pw.println(" Active session:"); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java index bd043ac..dfdd639 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java @@ -183,7 +183,7 @@ final class VoiceInteractionSessionConnection implements ServiceConnection { } } - public boolean showLocked(Bundle args, int flags, + public boolean showLocked(Bundle args, int flags, int disabledContext, IVoiceInteractionSessionShowCallback showCallback) { if (mBound) { if (!mFullyBound) { @@ -200,15 +200,17 @@ final class VoiceInteractionSessionConnection implements ServiceConnection { } boolean structureEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, mUser) != 0 - && isScreenCaptureAllowed; + && isScreenCaptureAllowed + && (disabledContext&VoiceInteractionSession.SHOW_WITH_ASSIST) == 0; boolean screenshotEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.ASSIST_SCREENSHOT_ENABLED, 1, mUser) != 0 - && isScreenCaptureAllowed; + && isScreenCaptureAllowed + && (disabledContext&VoiceInteractionSession.SHOW_WITH_SCREENSHOT) == 0; mShowArgs = args; mShowFlags = flags; mHaveAssistData = false; boolean needDisclosure = false; - if ((flags& VoiceInteractionSession.SHOW_WITH_ASSIST) != 0) { + if ((flags&VoiceInteractionSession.SHOW_WITH_ASSIST) != 0) { if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ASSIST_STRUCTURE, mCallingUid, mSessionComponentName.getPackageName()) == AppOpsManager.MODE_ALLOWED && structureEnabled) { @@ -226,7 +228,7 @@ final class VoiceInteractionSessionConnection implements ServiceConnection { mAssistData = null; } mHaveScreenshot = false; - if ((flags& VoiceInteractionSession.SHOW_WITH_SCREENSHOT) != 0) { + if ((flags&VoiceInteractionSession.SHOW_WITH_SCREENSHOT) != 0) { if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ASSIST_SCREENSHOT, mCallingUid, mSessionComponentName.getPackageName()) == AppOpsManager.MODE_ALLOWED && screenshotEnabled) { |