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

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

Merge "Create API to allow preinstalled assistant to toggle training data egress." into main

parents 9d03c7ab a20035cb
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -387,7 +387,6 @@ public class VoiceInteractionService extends Service {
                VoiceInteractionService::onShutdownInternal, VoiceInteractionService.this));
    };


    private void onShutdownInternal() {
        onShutdown();
        // Stop any active recognitions when shutting down.
@@ -1025,6 +1024,26 @@ public class VoiceInteractionService extends Service {
        }
    }

    /** Set sandboxed detection training data egress op.
     *
     * <p> This method can be called by a preinstalled assistant to allow/disallow training data
     * egress from trusted process.
     *
     * @return whether was able to update sandboxed detection op successfully.
     * @throws SecurityException if assistant is not a preinstalled assistant.
     *
     * @hide
     */
    @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);
        try {
            return mSystemService.setSandboxedDetectionTrainingDataOp(opMode);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Creates an {@link KeyphraseModelManager} to use for enrolling voice models outside of the
     * pre-bundled system voice models.
+10 −0
Original line number Diff line number Diff line
@@ -388,4 +388,14 @@ interface IVoiceInteractionManagerService {
    oneway void notifyActivityEventChanged(
            in IBinder activityToken,
            int type);

    /**
      * Sets the sandboxed detection training data egress op to provided op-mode.
      * 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.
      */
      boolean setSandboxedDetectionTrainingDataOp(int opMode);
}
+42 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.AppGlobals;
import android.app.AppOpsManager;
import android.app.role.OnRoleHoldersChangedListener;
import android.app.role.RoleManager;
import android.content.ComponentName;
@@ -1565,6 +1566,33 @@ public class VoiceInteractionManagerService extends SystemService {
            }
        }

        @Override
        public boolean setSandboxedDetectionTrainingDataOp(int opMode) {
            synchronized (this) {
                enforceIsCallerPreinstalledAssistant();

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

                int callingUid = Binder.getCallingUid();
                final long caller = Binder.clearCallingIdentity();
                try {
                    AppOpsManager appOpsManager = (AppOpsManager)
                            mContext.getSystemService(Context.APP_OPS_SERVICE);
                    appOpsManager.setUidMode(
                            AppOpsManager.OP_RECEIVE_SANDBOXED_DETECTION_TRAINING_DATA,
                            callingUid, opMode);
                } finally {
                    Binder.restoreCallingIdentity(caller);
                }

                return true;
            }
        }

      //----------------- Model management APIs --------------------------------//

        @Override
@@ -2219,6 +2247,13 @@ public class VoiceInteractionManagerService extends SystemService {
            }
        }

        private void enforceIsCallerPreinstalledAssistant() {
            if (!isCallerPreinstalledAssistant()) {
                throw new
                        SecurityException("Caller is not the pre-installed assistant.");
            }
        }

        private void enforceCallerAllowedToEnrollVoiceModel() {
            if (isCallerHoldingPermission(Manifest.permission.KEYPHRASE_ENROLLMENT_APPLICATION)) {
                return;
@@ -2233,6 +2268,13 @@ public class VoiceInteractionManagerService extends SystemService {
                    && mImpl.mInfo.getServiceInfo().applicationInfo.uid == Binder.getCallingUid();
        }

        private boolean isCallerPreinstalledAssistant() {
            return mImpl != null
                    && mImpl.mInfo.getServiceInfo().applicationInfo.uid == Binder.getCallingUid()
                    && (mImpl.mInfo.getServiceInfo().applicationInfo.isSystemApp()
                    || mImpl.mInfo.getServiceInfo().applicationInfo.isUpdatedSystemApp());
        }

        private void setImplLocked(VoiceInteractionManagerServiceImpl impl) {
            mImpl = impl;
            mAtmInternal.notifyActiveVoiceInteractionServiceChanged(