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

Commit 84cc4acc authored by lpeter's avatar lpeter
Browse files

Indicate which detector triggered the HotwordDetectionService

Currently we are adding the metrics to find why there is a significant
drop in assistant successful queries for using trusted hotword. In the
metrics, we need to know which detector is used. In this patch, we
first provide the way to distinguish which detector triggered the
HotwordDetectionService.

Bug: 215633663
Test: atest CtsVoiceInteractionTestCases
Test: atest CtsVoiceInteractionTestCases --instant
Change-Id: I2fa904c5a52d714c9ecb545084ffb60e81ed1d8a
parent 08d0c476
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -44,14 +44,17 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
    private final IVoiceInteractionManagerService mManagerService;
    private final Handler mHandler;
    private final HotwordDetector.Callback mCallback;
    private final int mDetectorType;

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

    /**
@@ -104,19 +107,20 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
            Slog.d(TAG, "updateState()");
        }
        synchronized (mLock) {
            updateStateLocked(options, sharedMemory, null /* callback */);
            updateStateLocked(options, sharedMemory, null /* callback */, mDetectorType);
        }
    }

    protected void updateStateLocked(@Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback) {
            @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback,
            int detectorType) {
        if (DEBUG) {
            Slog.d(TAG, "updateStateLocked()");
        }
        Identity identity = new Identity();
        identity.packageName = ActivityThread.currentOpPackageName();
        try {
            mManagerService.updateState(identity, options, sharedMemory, callback);
            mManagerService.updateState(identity, options, sharedMemory, callback, detectorType);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+5 −2
Original line number Diff line number Diff line
@@ -578,7 +578,9 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
            IVoiceInteractionManagerService modelManagementService, int targetSdkVersion,
            boolean supportHotwordDetectionService, @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory) {
        super(modelManagementService, callback);
        super(modelManagementService, callback,
                supportHotwordDetectionService ? DETECTOR_TYPE_TRUSTED_HOTWORD_DSP
                        : DETECTOR_TYPE_NORMAL);

        mHandler = new MyHandler();
        mText = text;
@@ -590,7 +592,8 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
        mTargetSdkVersion = targetSdkVersion;
        mSupportHotwordDetectionService = supportHotwordDetectionService;
        if (mSupportHotwordDetectionService) {
            updateStateLocked(options, sharedMemory, mInternalCallback);
            updateStateLocked(options, sharedMemory, mInternalCallback,
                    DETECTOR_TYPE_TRUSTED_HOTWORD_DSP);
        }
        try {
            Identity identity = new Identity();
+37 −0
Original line number Diff line number Diff line
@@ -36,6 +36,27 @@ import android.os.SharedMemory;
@SystemApi
public interface HotwordDetector {

    /**
     * Indicates that it is a non-trusted hotword detector.
     *
     * @hide
     */
    int DETECTOR_TYPE_NORMAL = 0;

    /**
     * Indicates that it is a DSP trusted hotword detector.
     *
     * @hide
     */
    int DETECTOR_TYPE_TRUSTED_HOTWORD_DSP = 1;

    /**
     * Indicates that it is a software trusted hotword detector.
     *
     * @hide
     */
    int DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE = 2;

    /**
     * Starts hotword recognition.
     * <p>
@@ -97,6 +118,22 @@ public interface HotwordDetector {
     */
    void updateState(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory);

    /**
     * @hide
     */
    static String detectorTypeToString(int detectorType) {
        switch (detectorType) {
            case DETECTOR_TYPE_NORMAL:
                return "normal";
            case DETECTOR_TYPE_TRUSTED_HOTWORD_DSP:
                return "trusted_hotword_dsp";
            case DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE:
                return "trusted_hotword_software";
            default:
                return Integer.toString(detectorType);
        }
    }

    /**
     * The callback to notify of detection events.
     */
+3 −2
Original line number Diff line number Diff line
@@ -60,14 +60,15 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
            PersistableBundle options,
            SharedMemory sharedMemory,
            HotwordDetector.Callback callback) {
        super(managerService, callback);
        super(managerService, callback, DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);

        mManagerService = managerService;
        mAudioFormat = audioFormat;
        mCallback = callback;
        mHandler = new Handler(Looper.getMainLooper());
        updateStateLocked(options, sharedMemory,
                new InitializationStateListener(mHandler, mCallback));
                new InitializationStateListener(mHandler, mCallback),
                DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);
    }

    @RequiresPermission(RECORD_AUDIO)
+3 −1
Original line number Diff line number Diff line
@@ -242,12 +242,14 @@ interface IVoiceInteractionManagerService {
     * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
     * @param callback Use this to report {@link HotwordDetectionService} status.
     * @param detectorType Indicate which detector is used.
     */
    void updateState(
            in Identity originatorIdentity,
            in PersistableBundle options,
            in SharedMemory sharedMemory,
            in IHotwordRecognitionStatusCallback callback);
            in IHotwordRecognitionStatusCallback callback,
            int detectorType);

    /**
     * Requests to shutdown hotword detection service.
Loading