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

Commit 2e6c8518 authored by Mark Punzalan's avatar Mark Punzalan
Browse files

Remove dependency on Identity in HotwordAudioStreamManager

android.media.permission.Identity is not needed for AppOpsManager calls
and is an unnecessary coupling.

Bug: 258323047
Test: None with this change; pure refactoring
Change-Id: I1c70f95a73e36c2793e87116b426d55ce359b74b
parent 3959b354
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.android.server.voiceinteraction.HotwordDetectionConnection.DEB

import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.media.permission.Identity;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.service.voice.HotwordAudioStream;
@@ -52,13 +51,18 @@ final class HotwordAudioStreamManager {
    private static final int MAX_COPY_BUFFER_LENGTH_BYTES = 65_536;

    private final AppOpsManager mAppOpsManager;
    private final Identity mVoiceInteractorIdentity;
    private final int mVoiceInteractorUid;
    private final String mVoiceInteractorPackageName;
    private final String mVoiceInteractorAttributionTag;
    private final ExecutorService mExecutorService = Executors.newCachedThreadPool();

    HotwordAudioStreamManager(@NonNull AppOpsManager appOpsManager,
            @NonNull Identity voiceInteractorIdentity) {
            int voiceInteractorUid, @NonNull String voiceInteractorPackageName,
            @NonNull String voiceInteractorAttributionTag) {
        mAppOpsManager = appOpsManager;
        mVoiceInteractorIdentity = voiceInteractorIdentity;
        mVoiceInteractorUid = voiceInteractorUid;
        mVoiceInteractorPackageName = voiceInteractorPackageName;
        mVoiceInteractorAttributionTag = voiceInteractorAttributionTag;
    }

    /**
@@ -152,8 +156,8 @@ final class HotwordAudioStreamManager {
            }

            if (mAppOpsManager.startOpNoThrow(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
                    mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
                    mVoiceInteractorIdentity.attributionTag, OP_MESSAGE) == MODE_ALLOWED) {
                    mVoiceInteractorUid, mVoiceInteractorPackageName,
                    mVoiceInteractorAttributionTag, OP_MESSAGE) == MODE_ALLOWED) {
                try {
                    // TODO(b/244599891): Set timeout, close after inactivity
                    mExecutorService.invokeAll(tasks);
@@ -162,14 +166,15 @@ final class HotwordAudioStreamManager {
                    bestEffortPropagateError(e.getMessage());
                } finally {
                    mAppOpsManager.finishOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
                            mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
                            mVoiceInteractorIdentity.attributionTag);
                            mVoiceInteractorUid, mVoiceInteractorPackageName,
                            mVoiceInteractorAttributionTag);
                }
            } else {
                bestEffortPropagateError(
                        "Failed to obtain RECORD_AUDIO_HOTWORD permission for "
                                + SoundTriggerSessionPermissionsDecorator.toString(
                                mVoiceInteractorIdentity));
                        "Failed to obtain RECORD_AUDIO_HOTWORD permission for voice interactor with"
                                + " uid=" + mVoiceInteractorUid
                                + " packageName=" + mVoiceInteractorPackageName
                                + " attributionTag=" + mVoiceInteractorAttributionTag);
            }
        }

+2 −1
Original line number Diff line number Diff line
@@ -246,7 +246,8 @@ final class HotwordDetectionConnection {
        mVoiceInteractorIdentity = voiceInteractorIdentity;
        mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
        mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
                mVoiceInteractorIdentity);
                mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
                mVoiceInteractorIdentity.attributionTag);
        mDetectionComponentName = serviceName;
        mUser = userId;
        mCallback = callback;
+2 −1
Original line number Diff line number Diff line
@@ -246,7 +246,8 @@ final class TrustedHotwordDetectorSession {
        mVoiceInteractorIdentity = voiceInteractorIdentity;
        mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
        mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
                mVoiceInteractorIdentity);
                mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
                mVoiceInteractorIdentity.attributionTag);
        mDetectionComponentName = serviceName;
        mUser = userId;
        mCallback = callback;