diff options
| author | 2023-10-17 13:14:34 +0000 | |
|---|---|---|
| committer | 2023-10-17 13:14:34 +0000 | |
| commit | b27d7344c0aa362af3f9c63266f9d5751919d6a8 (patch) | |
| tree | 23570177174f6f15399f70459f6d52ae17687dfa | |
| parent | 15c2cf072488db6eff4997558e9780a6a5aa4f38 (diff) | |
| parent | b41e0c01d01c075169fc074da17938bbd63fd5a1 (diff) | |
Merge "Enforce voice activation permission check on VoiceInteractionManagerService API." into main
| -rw-r--r-- | core/java/android/service/voice/VoiceInteractionService.java | 21 | ||||
| -rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java | 19 |
2 files changed, 38 insertions, 2 deletions
diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 3f41c56ac7f1..d2806217a276 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -520,7 +520,7 @@ public class VoiceInteractionService extends Service { @NonNull String keyphrase, @SuppressLint("UseIcu") @NonNull Locale locale, @NonNull @CallbackExecutor Executor executor, @NonNull AlwaysOnHotwordDetector.Callback callback) { - // TODO (b/269080850): Resolve AndroidFrameworkRequiresPermission lint warning + // TODO(b/269080850): Resolve AndroidFrameworkRequiresPermission lint warning Objects.requireNonNull(keyphrase); Objects.requireNonNull(locale); @@ -546,6 +546,10 @@ public class VoiceInteractionService extends Service { @NonNull SoundTrigger.ModuleProperties moduleProperties, @NonNull @CallbackExecutor Executor executor, @NonNull AlwaysOnHotwordDetector.Callback callback) { + // TODO(b/305787465): Remove the MANAGE_HOTWORD_DETECTION permission enforcement on the + // {@link #createAlwaysOnHotwordDetectorForTest(String, Locale, + // SoundTrigger.ModuleProperties, AlwaysOnHotwordDetector.Callback)} and replace with the + // permission RECEIVE_SANDBOX_TRIGGER_AUDIO when it is fully launched. Objects.requireNonNull(keyphrase); Objects.requireNonNull(locale); @@ -612,6 +616,11 @@ public class VoiceInteractionService extends Service { @Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory, @SuppressLint("MissingNullability") AlwaysOnHotwordDetector.Callback callback) { + // TODO(b/305787465): Remove the MANAGE_HOTWORD_DETECTION permission enforcement on the + // {@link #createAlwaysOnHotwordDetector(String, Locale, PersistableBundle, SharedMemory, + // AlwaysOnHotwordDetector.Callback)} and replace with the permission + // RECEIVE_SANDBOX_TRIGGER_AUDIO when it is fully launched. + return createAlwaysOnHotwordDetectorInternal(keyphrase, locale, /* supportHotwordDetectionService= */ true, options, sharedMemory, /* modulProperties */ null, /* executor= */ null, callback); @@ -663,7 +672,11 @@ public class VoiceInteractionService extends Service { @Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory, @NonNull @CallbackExecutor Executor executor, @NonNull AlwaysOnHotwordDetector.Callback callback) { - // TODO (b/269080850): Resolve AndroidFrameworkRequiresPermission lint warning + // TODO(b/269080850): Resolve AndroidFrameworkRequiresPermission lint warning + // TODO(b/305787465): Remove the MANAGE_HOTWORD_DETECTION permission enforcement on the + // {@link #createAlwaysOnHotwordDetector(String, Locale, PersistableBundle, SharedMemory, + // Executor, AlwaysOnHotwordDetector.Callback)} and replace with the permission + // RECEIVE_SANDBOX_TRIGGER_AUDIO when it is fully launched. Objects.requireNonNull(keyphrase); Objects.requireNonNull(locale); @@ -690,6 +703,10 @@ public class VoiceInteractionService extends Service { @NonNull SoundTrigger.ModuleProperties moduleProperties, @NonNull @CallbackExecutor Executor executor, @NonNull AlwaysOnHotwordDetector.Callback callback) { + // TODO(b/305787465): Remove the MANAGE_HOTWORD_DETECTION permission enforcement on the + // {@link #createAlwaysOnHotwordDetectorForTest(String, Locale, PersistableBundle, + // SharedMemory, SoundTrigger.ModuleProperties, Executor, AlwaysOnHotwordDetector.Callback)} + // and replace with the permission RECEIVE_SANDBOX_TRIGGER_AUDIO when it is fully launched. Objects.requireNonNull(keyphrase); Objects.requireNonNull(locale); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 138e575a6872..1c689d0d5ce3 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -58,6 +58,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Parcel; import android.os.ParcelFileDescriptor; +import android.os.PermissionEnforcer; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.RemoteCallbackList; @@ -67,6 +68,7 @@ import android.os.SharedMemory; import android.os.ShellCallback; import android.os.Trace; import android.os.UserHandle; +import android.permission.flags.Flags; import android.provider.Settings; import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback; import android.service.voice.IVisualQueryDetectionVoiceInteractionCallback; @@ -1286,6 +1288,17 @@ public class VoiceInteractionManagerService extends SystemService { } } + // Enforce permissions that are flag controlled. The flag value decides if the permission + // should be enforced. + private void initAndVerifyDetector_enforcePermissionWithFlags() { + PermissionEnforcer enforcer = mContext.getSystemService(PermissionEnforcer.class); + if (Flags.voiceActivationPermissionApis()) { + enforcer.enforcePermission( + android.Manifest.permission.RECEIVE_SANDBOX_TRIGGER_AUDIO, + getCallingPid(), getCallingUid()); + } + } + @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) @Override public void initAndVerifyDetector( @@ -1295,7 +1308,13 @@ public class VoiceInteractionManagerService extends SystemService { @NonNull IBinder token, IHotwordRecognitionStatusCallback callback, int detectorType) { + // TODO(b/305787465): Remove the MANAGE_HOTWORD_DETECTION permission enforcement on the + // {@link #initAndVerifyDetector(Identity, PersistableBundle, ShareMemory, IBinder, + // IHotwordRecognitionStatusCallback, int)} + // and replace with the permission RECEIVE_SANDBOX_TRIGGER_AUDIO when it is fully + // launched. super.initAndVerifyDetector_enforcePermission(); + initAndVerifyDetector_enforcePermissionWithFlags(); synchronized (this) { enforceIsCurrentVoiceInteractionService(); |