diff options
author | Jorim Jaggi <jjaggi@google.com> | 2015-04-02 11:21:39 -0700 |
---|---|---|
committer | Jorim Jaggi <jjaggi@google.com> | 2015-04-03 11:12:13 -0700 |
commit | 0b68ff45125e449dd0b4120f530240093aa6253e (patch) | |
tree | 3ac50e8ba4b6604dfee03f19af5ef0afa97590cb /services/voiceinteraction | |
parent | 225d3b5449d29b43e619d8538d024305f6e81ba9 (diff) | |
download | frameworks_base-0b68ff45125e449dd0b4120f530240093aa6253e.zip frameworks_base-0b68ff45125e449dd0b4120f530240093aa6253e.tar.gz frameworks_base-0b68ff45125e449dd0b4120f530240093aa6253e.tar.bz2 |
Add flag to voice interactor for supporting assist gesture
Add an additional flag to the voice-interaction-service declaration
so it can indicate whether it is able to handle the assist gesture.
Use that information in SystemUI so it only starts the voice
interaction session if the service is able to support it.
Change-Id: I62b035ce4f4cf06ee6e7eb0ddc4bf5edbc0e6737
Diffstat (limited to 'services/voiceinteraction')
-rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java | 79 |
1 files changed, 23 insertions, 56 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 1203735..8a28d51 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -26,7 +26,6 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; -import android.content.pm.PackageParser; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.database.ContentObserver; @@ -522,13 +521,7 @@ public class VoiceInteractionManagerService extends SystemService { @Override public KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, String bcp47Locale) { - synchronized (this) { - if (mContext.checkCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.MANAGE_VOICE_KEYPHRASES); - } - } + enforceCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES); if (bcp47Locale == null) { throw new IllegalArgumentException("Illegal argument(s) in getKeyphraseSoundModel"); @@ -545,15 +538,9 @@ public class VoiceInteractionManagerService extends SystemService { @Override public int updateKeyphraseSoundModel(KeyphraseSoundModel model) { - synchronized (this) { - if (mContext.checkCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.MANAGE_VOICE_KEYPHRASES); - } - if (model == null) { - throw new IllegalArgumentException("Model must not be null"); - } + enforceCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES); + if (model == null) { + throw new IllegalArgumentException("Model must not be null"); } final long caller = Binder.clearCallingIdentity(); @@ -576,13 +563,7 @@ public class VoiceInteractionManagerService extends SystemService { @Override public int deleteKeyphraseSoundModel(int keyphraseId, String bcp47Locale) { - synchronized (this) { - if (mContext.checkCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.MANAGE_VOICE_KEYPHRASES); - } - } + enforceCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES); if (bcp47Locale == null) { throw new IllegalArgumentException( @@ -711,40 +692,17 @@ public class VoiceInteractionManagerService extends SystemService { } @Override - public boolean isServiceActive() { - synchronized (this) { - if (mContext.checkCallingPermission( - Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); - } - return mImpl != null; - } - } - - @Override public ComponentName getActiveServiceComponentName() { + enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); synchronized (this) { - if (mContext.checkCallingPermission( - Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); - } return mImpl != null ? mImpl.mComponent : null; } } @Override public void showSessionForActiveService(IVoiceInteractionSessionShowCallback showCallback) { + enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); synchronized (this) { - if (mContext.checkCallingPermission( - Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); - } if (mImpl == null) { Slog.w(TAG, "showSessionForActiveService without running voice interaction" + "service"); @@ -755,7 +713,7 @@ public class VoiceInteractionManagerService extends SystemService { final long caller = Binder.clearCallingIdentity(); try { mImpl.showSessionLocked(callingPid, callingUid, new Bundle() /* sessionArgs */, - VoiceInteractionService.START_SOURCE_SYSTEM + VoiceInteractionService.START_SOURCE_ASSIST_GESTURE | VoiceInteractionService.START_WITH_ASSIST | VoiceInteractionService.START_WITH_SCREENSHOT, showCallback); @@ -767,18 +725,21 @@ public class VoiceInteractionManagerService extends SystemService { @Override public boolean isSessionRunning() { + enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); synchronized (this) { - if (mContext.checkCallingPermission( - Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Caller does not hold the permission " - + Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); - } return mImpl != null && mImpl.mActiveSession != null; } } @Override + public boolean activeServiceSupportsAssistGesture() { + enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); + synchronized (this) { + return mImpl != null && mImpl.mInfo.getSupportsAssistGesture(); + } + } + + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { @@ -798,6 +759,12 @@ public class VoiceInteractionManagerService extends SystemService { mSoundTriggerHelper.dump(fd, pw, args); } + private void enforceCallingPermission(String permission) { + if (mContext.checkCallingPermission(permission) != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Caller does not hold the permission " + permission); + } + } + class SettingsObserver extends ContentObserver { SettingsObserver(Handler handler) { super(handler); |