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

Commit 31f241cc authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

Hotword: Add onStopDetection() for software detectors.

For DSP-based detection, stopRecognition() disables detection at the
sound trigger layer. For software detection, the HotwordDetectionService
must be notified so it can stop detection.

Bug: 189236104
CTS-Coverage-Bug: 183425641
Test: atest CtsVoiceInteractionTestCases
Change-Id: I220d2255e5e500c22723f6e2fbc34860a529f216
parent 87d4c9a9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10565,6 +10565,7 @@ package android.service.voice {
    method public void onDetect(@NonNull android.service.voice.AlwaysOnHotwordDetector.EventPayload, long, @NonNull android.service.voice.HotwordDetectionService.Callback);
    method public void onDetect(@NonNull android.service.voice.HotwordDetectionService.Callback);
    method public void onDetect(@NonNull android.os.ParcelFileDescriptor, @NonNull android.media.AudioFormat, @Nullable android.os.PersistableBundle, @NonNull android.service.voice.HotwordDetectionService.Callback);
    method public void onStopDetection();
    method public void onUpdateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory, long, @Nullable java.util.function.IntConsumer);
    field public static final int INITIALIZATION_STATUS_SUCCESS = 0; // 0x0
    field public static final int INITIALIZATION_STATUS_UNKNOWN = 100; // 0x64
+14 −0
Original line number Diff line number Diff line
@@ -192,6 +192,11 @@ public abstract class HotwordDetectionService extends Service {
            mContentCaptureManager = new ContentCaptureManager(
                    HotwordDetectionService.this, manager, options);
        }

        @Override
        public void stopDetection() {
            HotwordDetectionService.this.onStopDetection();
        }
    };

    @Override
@@ -348,6 +353,15 @@ public abstract class HotwordDetectionService extends Service {
        onUpdateState(options, sharedMemory, UPDATE_TIMEOUT_MILLIS, intConsumer);
    }

    /**
     * Called when the {@link VoiceInteractionService}
     * {@link HotwordDetector#stopRecognition() requests} that hotword recognition be stopped.
     * <p>
     * Any open {@link android.media.AudioRecord} should be closed here.
     */
    public void onStopDetection() {
    }

    /**
     * Callback for returning the detection result.
     *
+2 −0
Original line number Diff line number Diff line
@@ -53,4 +53,6 @@ oneway interface IHotwordDetectionService {
    void updateContentCaptureManager(
        in IContentCaptureManager contentCaptureManager,
        in ContentCaptureOptions options);

    void stopDetection();
}
+2 −0
Original line number Diff line number Diff line
@@ -287,6 +287,8 @@ final class HotwordDetectionConnection {
            Slog.d(TAG, "stopListening");
        }

        mRemoteHotwordDetectionService.run(service -> service.stopDetection());

        synchronized (mLock) {
            if (mCurrentAudioSink != null) {
                Slog.i(TAG, "Closing audio stream to hotword detector: stopping requested");