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

Commit 84728330 authored by Ajay Gopi's avatar Ajay Gopi Committed by Android (Google) Code Review
Browse files

Merge "Create a system API to allow preinstalled assistants to receive...

Merge "Create a system API to allow preinstalled assistants to receive training data events." into main
parents c0a474ca d4051e73
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13040,6 +13040,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);
  }
}
+18 −8
Original line number Diff line number Diff line
@@ -1024,21 +1024,31 @@ public class VoiceInteractionService extends Service {
        }
    }

    /** Set sandboxed detection training data egress op.
    /**
     * Allow/disallow receiving training data from trusted process.
     *
     * <p> This method can be called by a preinstalled assistant to allow/disallow training data
     * egress from trusted process.
     * <p> This method can be called by a preinstalled assistant to receive/stop receiving
     * training data via {@link HotwordDetector.Callback#onTrainingData(HotwordTrainingData)}.
     * These training data events are produced during sandboxed detection (in trusted process).
     *
     * @return whether was able to update sandboxed detection op successfully.
     * @throws SecurityException if assistant is not a preinstalled assistant.
     * @param allowed whether to allow/disallow receiving training data produced during
     *                sandboxed detection (from trusted process).
     * @throws SecurityException if caller is not a preinstalled assistant or if caller is not the
     * active assistant.
     *
     * @hide
     */
    //TODO(b/315053245): Add mitigations to make API no-op once user has modified setting.
    @SystemApi
    @FlaggedApi(Flags.FLAG_ALLOW_TRAINING_DATA_EGRESS_FROM_HDS)
    public boolean setSandboxedDetectionTrainingDataOp(int opMode) {
        Log.i(TAG, "Setting training data egress op-mode to " + opMode);
    @RequiresPermission(Manifest.permission.MANAGE_HOTWORD_DETECTION)
    public void setIsReceiveSandboxedTrainingDataAllowed(boolean allowed) {
        Log.i(TAG, "setIsReceiveSandboxedTrainingDataAllowed to " + allowed);
        if (mSystemService == null) {
            throw new IllegalStateException("Not available until onReady() is called");
        }
        try {
            return mSystemService.setSandboxedDetectionTrainingDataOp(opMode);
            mSystemService.setIsReceiveSandboxedTrainingDataAllowed(allowed);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+5 −5
Original line number Diff line number Diff line
@@ -390,12 +390,12 @@ interface IVoiceInteractionManagerService {
            int type);

    /**
      * Sets the sandboxed detection training data egress op to provided op-mode.
      * Allows/disallows receiving training data from trusted process.
      * Caller must be the active assistant and a preinstalled assistant.
      *
      * @param opMode app-op mode to set training data egress op to.
      *
      * @return whether was able to successfully set training data egress op.
      * @param allowed whether to allow/disallow receiving training data produced during
      * sandboxed detection (from trusted process).
      */
      boolean setSandboxedDetectionTrainingDataOp(int opMode);
      @EnforcePermission("MANAGE_HOTWORD_DETECTION")
      void setIsReceiveSandboxedTrainingDataAllowed(boolean allowed);
}
+12 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.voiceinteraction;

import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.EnforcePermission;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -1567,16 +1568,19 @@ public class VoiceInteractionManagerService extends SystemService {
        }

        @Override
        public boolean setSandboxedDetectionTrainingDataOp(int opMode) {
            synchronized (this) {
                enforceIsCallerPreinstalledAssistant();
        @EnforcePermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION)
        public void setIsReceiveSandboxedTrainingDataAllowed(boolean allowed) {
            super.setIsReceiveSandboxedTrainingDataAllowed_enforcePermission();

            synchronized (this) {
                if (mImpl == null) {
                    Slog.w(TAG, "setSandboxedDetectionTrainingDataop without running"
                            + " voice interaction service");
                    return false;
                    throw new IllegalStateException(
                            "setIsReceiveSandboxedTrainingDataAllowed without running voice "
                                    + "interaction service");
                }

                enforceIsCallerPreinstalledAssistant();

                int callingUid = Binder.getCallingUid();
                final long caller = Binder.clearCallingIdentity();
                try {
@@ -1584,12 +1588,11 @@ public class VoiceInteractionManagerService extends SystemService {
                            mContext.getSystemService(Context.APP_OPS_SERVICE);
                    appOpsManager.setUidMode(
                            AppOpsManager.OP_RECEIVE_SANDBOXED_DETECTION_TRAINING_DATA,
                            callingUid, opMode);
                            callingUid, allowed ? AppOpsManager.MODE_ALLOWED :
                                    AppOpsManager.MODE_ERRORED);
                } finally {
                    Binder.restoreCallingIdentity(caller);
                }

                return true;
            }
        }