Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b27d7344 authored by Faye Yan's avatar Faye Yan Committed by Android (Google) Code Review
Browse files

Merge "Enforce voice activation permission check on VoiceInteractionManagerService API." into main

parents 15c2cf07 b41e0c01
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -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);
@@ -664,6 +673,10 @@ public class VoiceInteractionService extends Service {
            @NonNull @CallbackExecutor Executor executor,
            @NonNull AlwaysOnHotwordDetector.Callback callback) {
        // 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);
+19 −0
Original line number Diff line number Diff line
@@ -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();