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

Commit 6c9d3448 authored by Charles Chen's avatar Charles Chen Committed by Android (Google) Code Review
Browse files

Merge changes from topic "multi_detectors"

* changes:
  Rename IHotwordDetectionService to ISandboxedDetectionService
  Support multiple detectors in VoiceInteractionManagerService
parents c2011ff8 89fd869e
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ import android.app.ActivityThread;
import android.app.compat.CompatChanges;
import android.media.AudioFormat;
import android.media.permission.Identity;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
@@ -49,19 +51,20 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
    private final IVoiceInteractionManagerService mManagerService;
    private final Handler mHandler;
    private final HotwordDetector.Callback mCallback;
    private final int mDetectorType;
    private Consumer<AbstractHotwordDetector> mOnDestroyListener;
    private final AtomicBoolean mIsDetectorActive;
    /**
     * A token which is used by voice interaction system service to identify different detectors.
     */
    private final IBinder mToken = new Binder();

    AbstractHotwordDetector(
            IVoiceInteractionManagerService managerService,
            HotwordDetector.Callback callback,
            int detectorType) {
            HotwordDetector.Callback callback) {
        mManagerService = managerService;
        // TODO: this needs to be supplied from above
        mHandler = new Handler(Looper.getMainLooper());
        mCallback = callback;
        mDetectorType = detectorType;
        mIsDetectorActive = new AtomicBoolean(true);
    }

@@ -94,6 +97,7 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
                    audioStream,
                    audioFormat,
                    options,
                    mToken,
                    new BinderCallback(mHandler, mCallback));
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
@@ -111,7 +115,7 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
        }
        throwIfDetectorIsNoLongerActive();
        try {
            mManagerService.updateState(options, sharedMemory);
            mManagerService.updateState(options, sharedMemory, mToken);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -128,7 +132,7 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
        Identity identity = new Identity();
        identity.packageName = ActivityThread.currentOpPackageName();
        try {
            mManagerService.initAndVerifyDetector(identity, options, sharedMemory, callback,
            mManagerService.initAndVerifyDetector(identity, options, sharedMemory, mToken, callback,
                    detectorType);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -151,6 +155,11 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
            return;
        }
        mIsDetectorActive.set(false);
        try {
            mManagerService.destroyDetector(mToken);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        synchronized (mLock) {
            mOnDestroyListener.accept(this);
        }
+9 −11
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
    private final Handler mHandler;
    private final IBinder mBinder = new Binder();
    private final int mTargetSdkVersion;
    private final boolean mSupportHotwordDetectionService;
    private final boolean mSupportSandboxedDetectionService;

    @GuardedBy("mLock")
    private boolean mIsAvailabilityOverriddenByTestApi = false;
@@ -756,7 +756,7 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
     * @param callback A non-null Callback for receiving the recognition events.
     * @param modelManagementService A service that allows management of sound models.
     * @param targetSdkVersion The target SDK version.
     * @param supportHotwordDetectionService {@code true} if HotwordDetectionService should be
     * @param SupportSandboxedDetectionService {@code true} if HotwordDetectionService should be
     * triggered, otherwise {@code false}.
     *
     * @hide
@@ -764,10 +764,8 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
    public AlwaysOnHotwordDetector(String text, Locale locale, Callback callback,
            KeyphraseEnrollmentInfo keyphraseEnrollmentInfo,
            IVoiceInteractionManagerService modelManagementService, int targetSdkVersion,
            boolean supportHotwordDetectionService) {
        super(modelManagementService, callback,
                supportHotwordDetectionService ? DETECTOR_TYPE_TRUSTED_HOTWORD_DSP
                        : DETECTOR_TYPE_NORMAL);
            boolean supportSandboxedDetectionService) {
        super(modelManagementService, callback);

        mHandler = new MyHandler();
        mText = text;
@@ -777,12 +775,12 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
        mInternalCallback = new SoundTriggerListener(mHandler);
        mModelManagementService = modelManagementService;
        mTargetSdkVersion = targetSdkVersion;
        mSupportHotwordDetectionService = supportHotwordDetectionService;
        mSupportSandboxedDetectionService = supportSandboxedDetectionService;
    }

    @Override
    void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) {
        if (mSupportHotwordDetectionService) {
        if (mSupportSandboxedDetectionService) {
            initAndVerifyDetector(options, sharedMemory, mInternalCallback,
                    DETECTOR_TYPE_TRUSTED_HOTWORD_DSP);
        }
@@ -814,7 +812,7 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
    public final void updateState(@Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory) throws IllegalDetectorStateException {
        synchronized (mLock) {
            if (!mSupportHotwordDetectionService) {
            if (!mSupportSandboxedDetectionService) {
                throw new IllegalStateException(
                        "updateState called, but it doesn't support hotword detection service");
            }
@@ -1410,8 +1408,8 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
     * @hide
     */
    @Override
    public boolean isUsingHotwordDetectionService() {
        return mSupportHotwordDetectionService;
    public boolean isUsingSandboxedDetectionService() {
        return mSupportSandboxedDetectionService;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ public abstract class HotwordDetectionService extends Service {
    @Nullable
    private IRecognitionServiceManager mIRecognitionServiceManager;

    private final IHotwordDetectionService mInterface = new IHotwordDetectionService.Stub() {
    private final ISandboxedDetectionService mInterface = new ISandboxedDetectionService.Stub() {
        @Override
        public void detectFromDspSource(
                SoundTrigger.KeyphraseRecognitionEvent event,
+1 −1
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ public interface HotwordDetector {
    /**
     * @hide
     */
    default boolean isUsingHotwordDetectionService() {
    default boolean isUsingSandboxedDetectionService() {
        throw new UnsupportedOperationException("Not implemented. Must override in a subclass.");
    }

+2 −2
Original line number Diff line number Diff line
@@ -29,11 +29,11 @@ import android.view.contentcapture.IContentCaptureManager;
import android.speech.IRecognitionServiceManager;

/**
 * Provide the interface to communicate with hotword detection service.
 * Provide the interface to communicate with sandboxed detection service.
 *
 * @hide
 */
oneway interface IHotwordDetectionService {
oneway interface ISandboxedDetectionService {
    void detectFromDspSource(
        in SoundTrigger.KeyphraseRecognitionEvent event,
        in AudioFormat audioFormat,
Loading