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

Commit 62b2bbe5 authored by Atneya Nair's avatar Atneya Nair
Browse files

Remove voiceinteraction identity fabrication

VoiceInteractionManagerService uses its own identity instead of its
clients when attaching to the SoundTrigger stack to prevent appop
attribution if an event is actually delivered.

Now that ST has a notion of a trusted client, remove this special
handling, and pass the real client identity.

Attach as trusted middleman.

Bug: 272147641
Fixes: 278626726
Test: AlwaysOnHotwordDetectorTest
Test: Manual verification of hotword, now playing
Change-Id: I4cfc57af0ead5a21baadc3f328551c0011b3c38b
parent 31316ca7
Loading
Loading
Loading
Loading
+10 −50
Original line number Diff line number Diff line
@@ -381,51 +381,21 @@ public class VoiceInteractionManagerService extends SystemService {
                @NonNull Identity originatorIdentity, IBinder client,
                ModuleProperties moduleProperties) {
            Objects.requireNonNull(originatorIdentity);
            boolean forHotwordDetectionService;
            boolean forHotwordDetectionService = false;
            synchronized (VoiceInteractionManagerServiceStub.this) {
                enforceIsCurrentVoiceInteractionService();
                forHotwordDetectionService =
                        mImpl != null && mImpl.mHotwordDetectionConnection != null;
            }
            IVoiceInteractionSoundTriggerSession session;
            if (forHotwordDetectionService) {
                // Use our own identity and handle the permission checks ourselves. This allows
                // properly checking/noting against the voice interactor or hotword detection
                // service as needed.
            if (HotwordDetectionConnection.DEBUG) {
                    Slog.d(TAG, "Creating a SoundTriggerSession for a HotwordDetectionService");
                }
                originatorIdentity.uid = Binder.getCallingUid();
                originatorIdentity.pid = Binder.getCallingPid();
                session = new SoundTriggerSessionPermissionsDecorator(
                        createSoundTriggerSessionForSelfIdentity(client, moduleProperties),
                        mContext,
                        originatorIdentity);
            } else {
                if (HotwordDetectionConnection.DEBUG) {
                    Slog.d(TAG, "Creating a SoundTriggerSession");
                Slog.d(TAG, "Creating a SoundTriggerSession, for HDS: "
                        + forHotwordDetectionService);
            }
            try (SafeCloseable ignored = PermissionUtil.establishIdentityDirect(
                    originatorIdentity)) {
                    session = new SoundTriggerSession(mSoundTriggerInternal.attach(client,
                                moduleProperties, false));
                }
            }
            return new SoundTriggerSessionBinderProxy(session);
                return new SoundTriggerSession(mSoundTriggerInternal.attach(client,
                            moduleProperties, forHotwordDetectionService));
            }

        private IVoiceInteractionSoundTriggerSession createSoundTriggerSessionForSelfIdentity(
                IBinder client, ModuleProperties moduleProperties) {
            Identity identity = new Identity();
            identity.uid = Process.myUid();
            identity.pid = Process.myPid();
            identity.packageName = ActivityThread.currentOpPackageName();
            return Binder.withCleanCallingIdentity(() -> {
                try (SafeCloseable ignored = IdentityContext.create(identity)) {
                    return new SoundTriggerSession(
                            mSoundTriggerInternal.attach(client, moduleProperties, false));
                }
            });
        }

        @Override
@@ -1700,11 +1670,7 @@ public class VoiceInteractionManagerService extends SystemService {
            return null;
        }

        /**
         * Implementation of SoundTriggerSession. Does not implement {@link #asBinder()} as it's
         * intended to be wrapped by an {@link IVoiceInteractionSoundTriggerSession.Stub} object.
         */
        private class SoundTriggerSession implements IVoiceInteractionSoundTriggerSession {
        private class SoundTriggerSession extends IVoiceInteractionSoundTriggerSession.Stub {
            final SoundTriggerInternal.Session mSession;
            private IHotwordRecognitionStatusCallback mSessionExternalCallback;
            private IRecognitionStatusCallback mSessionInternalCallback;
@@ -1850,12 +1816,6 @@ public class VoiceInteractionManagerService extends SystemService {
                }
            }

            @Override
            public IBinder asBinder() {
                throw new UnsupportedOperationException(
                        "This object isn't intended to be used as a Binder.");
            }

            @Override
            public void detach() {
                mSession.detach();