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

Commit 33cef05d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor updateState method for trusted hotword"

parents a52eb3af ec669dde
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -126,21 +126,26 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
            Slog.d(TAG, "updateState()");
        }
        throwIfDetectorIsNoLongerActive();
        synchronized (mLock) {
            updateStateLocked(options, sharedMemory, null /* callback */, mDetectorType);
        try {
            mManagerService.updateState(options, sharedMemory);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    protected void updateStateLocked(@Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback,
    protected void initAndVerifyDetector(
            @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory,
            @NonNull IHotwordRecognitionStatusCallback callback,
            int detectorType) {
        if (DEBUG) {
            Slog.d(TAG, "updateStateLocked()");
            Slog.d(TAG, "initAndVerifyDetector()");
        }
        Identity identity = new Identity();
        identity.packageName = ActivityThread.currentOpPackageName();
        try {
            mManagerService.updateState(identity, options, sharedMemory, callback, detectorType);
            mManagerService.initAndVerifyDetector(identity, options, sharedMemory, callback,
                    detectorType);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −3
Original line number Diff line number Diff line
@@ -817,10 +817,8 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {

    @Override
    void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) {
        // TODO: transition to use an API that is not updateState to provide
        //  onHotwordDetectionServiceInitialized status to external callback
        if (mSupportHotwordDetectionService) {
            updateStateLocked(options, sharedMemory, mInternalCallback,
            initAndVerifyDetector(options, sharedMemory, mInternalCallback,
                    DETECTOR_TYPE_TRUSTED_HOTWORD_DSP);
        }
        try {
+1 −3
Original line number Diff line number Diff line
@@ -69,9 +69,7 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {

    @Override
    void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) {
        // TODO: transition to use an API that is not updateState to provide
        //  onHotwordDetectionServiceInitialized status to external callback
        updateStateLocked(options, sharedMemory,
        initAndVerifyDetector(options, sharedMemory,
                new InitializationStateListener(mHandler, mCallback),
                DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);
    }
+18 −1
Original line number Diff line number Diff line
@@ -245,6 +245,23 @@ interface IVoiceInteractionManagerService {

    /**
     * Set configuration and pass read-only data to hotword detection service.
     *
     * @param options Application configuration data to provide to the
     * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or
     * other contents that can be used to communicate with other processes.
     * @param sharedMemory The unrestricted data blob to provide to the
     * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
     */
    @EnforcePermission("MANAGE_HOTWORD_DETECTION")
    void updateState(
            in PersistableBundle options,
            in SharedMemory sharedMemory);

    /**
     * Set configuration and pass read-only data to hotword detection service when creating
     * the detector.
     *
     * Caller must provide an identity, used for permission tracking purposes.
     * The uid/pid elements of the identity will be ignored by the server and replaced with the ones
     * provided by binder.
@@ -259,7 +276,7 @@ interface IVoiceInteractionManagerService {
     * @param detectorType Indicate which detector is used.
     */
    @EnforcePermission("MANAGE_HOTWORD_DETECTION")
    void updateState(
    void initAndVerifyDetector(
            in Identity originatorIdentity,
            in PersistableBundle options,
            in SharedMemory sharedMemory,
+16 −12
Original line number Diff line number Diff line
@@ -1242,6 +1242,19 @@ public class VoiceInteractionManagerService extends SystemService {
        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION)
        @Override
        public void updateState(
                @Nullable PersistableBundle options,
                @Nullable SharedMemory sharedMemory) {
            synchronized (this) {
                enforceIsCurrentVoiceInteractionService();

                Binder.withCleanCallingIdentity(
                        () -> mImpl.updateStateLocked(options, sharedMemory));
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION)
        @Override
        public void initAndVerifyDetector(
                @NonNull Identity voiceInteractorIdentity,
                @Nullable PersistableBundle options,
                @Nullable SharedMemory sharedMemory,
@@ -1250,21 +1263,12 @@ public class VoiceInteractionManagerService extends SystemService {
            synchronized (this) {
                enforceIsCurrentVoiceInteractionService();

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

                voiceInteractorIdentity.uid = Binder.getCallingUid();
                voiceInteractorIdentity.pid = Binder.getCallingPid();

                final long caller = Binder.clearCallingIdentity();
                try {
                    mImpl.updateStateLocked(
                            voiceInteractorIdentity, options, sharedMemory, callback, detectorType);
                } finally {
                    Binder.restoreCallingIdentity(caller);
                }
                Binder.withCleanCallingIdentity(
                        () -> mImpl.initAndVerifyDetectorLocked(voiceInteractorIdentity, options,
                                sharedMemory, callback, detectorType));
            }
        }

Loading