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

Commit 9548a506 authored by Ajay Gopi's avatar Ajay Gopi
Browse files

Address API Review feedback for system API to allow preinstalled assistants to...

Address API Review feedback for system API to allow preinstalled assistants to receive training data events.

Bug: 315966974
Test: atest -c FrameworksVoiceInteractionTests:SetSandboxedTrainingDataAllowedTest
Change-Id: Ie7c6f9aab3ba8fea2c39f9d102506368a0d929a9
parent b797ec26
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13051,7 +13051,7 @@ package android.service.voice {
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public final android.service.voice.HotwordDetector createHotwordDetector(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory, @NonNull java.util.concurrent.Executor, @NonNull android.service.voice.HotwordDetector.Callback);
    method @NonNull @RequiresPermission("android.permission.MANAGE_VOICE_KEYPHRASES") public final android.media.voice.KeyphraseModelManager createKeyphraseModelManager();
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public final android.service.voice.VisualQueryDetector createVisualQueryDetector(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory, @NonNull java.util.concurrent.Executor, @NonNull android.service.voice.VisualQueryDetector.Callback);
    method @FlaggedApi("android.service.voice.flags.allow_training_data_egress_from_hds") @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public void setIsReceiveSandboxedTrainingDataAllowed(boolean);
    method @FlaggedApi("android.service.voice.flags.allow_training_data_egress_from_hds") @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public void setShouldReceiveSandboxedTrainingData(boolean);
  }
}
+3 −3
Original line number Diff line number Diff line
@@ -1042,13 +1042,13 @@ public class VoiceInteractionService extends Service {
    @SystemApi
    @FlaggedApi(Flags.FLAG_ALLOW_TRAINING_DATA_EGRESS_FROM_HDS)
    @RequiresPermission(Manifest.permission.MANAGE_HOTWORD_DETECTION)
    public void setIsReceiveSandboxedTrainingDataAllowed(boolean allowed) {
        Log.i(TAG, "setIsReceiveSandboxedTrainingDataAllowed to " + allowed);
    public void setShouldReceiveSandboxedTrainingData(boolean allowed) {
        Log.i(TAG, "setShouldReceiveSandboxedTrainingData to " + allowed);
        if (mSystemService == null) {
            throw new IllegalStateException("Not available until onReady() is called");
        }
        try {
            mSystemService.setIsReceiveSandboxedTrainingDataAllowed(allowed);
            mSystemService.setShouldReceiveSandboxedTrainingData(allowed);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -397,5 +397,5 @@ interface IVoiceInteractionManagerService {
      * sandboxed detection (from trusted process).
      */
      @EnforcePermission("MANAGE_HOTWORD_DETECTION")
      void setIsReceiveSandboxedTrainingDataAllowed(boolean allowed);
      void setShouldReceiveSandboxedTrainingData(boolean allowed);
}
+8 −8
Original line number Diff line number Diff line
@@ -120,12 +120,12 @@ public class SetSandboxedTrainingDataAllowedTest {
    }

    @Test
    public void setIsReceiveSandboxedTrainingDataAllowed_currentAndPreinstalledAssistant_setsOp() {
    public void setShouldReceiveSandboxedTrainingData_currentAndPreinstalledAssistant_setsOp() {
        // Set application info so current app is the current and preinstalled assistant.
        mApplicationInfo.uid = Process.myUid();
        mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;

        mVoiceInteractionManagerServiceStub.setIsReceiveSandboxedTrainingDataAllowed(
        mVoiceInteractionManagerServiceStub.setShouldReceiveSandboxedTrainingData(
                /* allowed= */ true);

        verify(mAppOpsManager).setUidMode(mOpIdCaptor.capture(), mUidCaptor.capture(),
@@ -137,7 +137,7 @@ public class SetSandboxedTrainingDataAllowedTest {
    }

    @Test
    public void setIsReceiveSandboxedTrainingDataAllowed_missingPermission_doesNotSetOp() {
    public void setShouldReceiveSandboxedTrainingData_missingPermission_doesNotSetOp() {
        // Set application info so current app is the current and preinstalled assistant.
        mApplicationInfo.uid = Process.myUid();
        mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
@@ -146,33 +146,33 @@ public class SetSandboxedTrainingDataAllowedTest {
        mPermissionEnforcer.revoke(Manifest.permission.MANAGE_HOTWORD_DETECTION);

        assertThrows(SecurityException.class,
                () -> mVoiceInteractionManagerServiceStub.setIsReceiveSandboxedTrainingDataAllowed(
                () -> mVoiceInteractionManagerServiceStub.setShouldReceiveSandboxedTrainingData(
                        /* allowed= */ true));

        verify(mAppOpsManager, never()).setUidMode(anyInt(), anyInt(), anyInt());
    }

    @Test
    public void setIsReceiveSandboxedTrainingDataAllowed_notPreinstalledAssistant_doesNotSetOp() {
    public void setShouldReceiveSandboxedTrainingData_notPreinstalledAssistant_doesNotSetOp() {
        // Set application info so current app is not preinstalled assistant.
        mApplicationInfo.uid = Process.myUid();
        mApplicationInfo.flags = ApplicationInfo.FLAG_INSTALLED; // Does not contain FLAG_SYSTEM.

        assertThrows(SecurityException.class,
                () -> mVoiceInteractionManagerServiceStub.setIsReceiveSandboxedTrainingDataAllowed(
                () -> mVoiceInteractionManagerServiceStub.setShouldReceiveSandboxedTrainingData(
                                /* allowed= */ true));

        verify(mAppOpsManager, never()).setUidMode(anyInt(), anyInt(), anyInt());
    }

    @Test
    public void setIsReceiveSandboxedTrainingDataAllowed_notCurrentAssistant_doesNotSetOp() {
    public void setShouldReceiveSandboxedTrainingData_notCurrentAssistant_doesNotSetOp() {
        // Set application info so current app is not current assistant.
        mApplicationInfo.uid = Process.SHELL_UID; // Set current assistant uid to shell UID.
        mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;

        assertThrows(SecurityException.class,
                () -> mVoiceInteractionManagerServiceStub.setIsReceiveSandboxedTrainingDataAllowed(
                () -> mVoiceInteractionManagerServiceStub.setShouldReceiveSandboxedTrainingData(
                                /* allowed= */ true));

        verify(mAppOpsManager, never()).setUidMode(anyInt(), anyInt(), anyInt());
+3 −3
Original line number Diff line number Diff line
@@ -1569,13 +1569,13 @@ public class VoiceInteractionManagerService extends SystemService {

        @Override
        @EnforcePermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION)
        public void setIsReceiveSandboxedTrainingDataAllowed(boolean allowed) {
            super.setIsReceiveSandboxedTrainingDataAllowed_enforcePermission();
        public void setShouldReceiveSandboxedTrainingData(boolean allowed) {
            super.setShouldReceiveSandboxedTrainingData_enforcePermission();

            synchronized (this) {
                if (mImpl == null) {
                    throw new IllegalStateException(
                            "setIsReceiveSandboxedTrainingDataAllowed without running voice "
                            "setShouldReceiveSandboxedTrainingData without running voice "
                                    + "interaction service");
                }