summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhaan Ugale <augale@google.com>2021-05-25 10:29:09 -0700
committerAhaan Ugale <augale@google.com>2021-05-25 18:59:29 +0000
commit31f241cc63c189bc42a89f8cce54c8024840a5a4 (patch)
treec04d713fc90ca732b7ca8e960218bcad8159fdfe
parent87d4c9a9ca5ff67beb37230778f8363cbc49db02 (diff)
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
-rw-r--r--core/api/system-current.txt1
-rw-r--r--core/java/android/service/voice/HotwordDetectionService.java14
-rw-r--r--core/java/android/service/voice/IHotwordDetectionService.aidl2
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java2
4 files changed, 19 insertions, 0 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 6f68e3fe902c..fd72c8d7c60d 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -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
diff --git a/core/java/android/service/voice/HotwordDetectionService.java b/core/java/android/service/voice/HotwordDetectionService.java
index 7dd3a1dd5ea7..deb6c01a3088 100644
--- a/core/java/android/service/voice/HotwordDetectionService.java
+++ b/core/java/android/service/voice/HotwordDetectionService.java
@@ -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
@@ -349,6 +354,15 @@ public abstract class HotwordDetectionService extends Service {
}
/**
+ * 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.
*
* @hide
diff --git a/core/java/android/service/voice/IHotwordDetectionService.aidl b/core/java/android/service/voice/IHotwordDetectionService.aidl
index 7ba00982e6a2..72dd45aeeb0f 100644
--- a/core/java/android/service/voice/IHotwordDetectionService.aidl
+++ b/core/java/android/service/voice/IHotwordDetectionService.aidl
@@ -53,4 +53,6 @@ oneway interface IHotwordDetectionService {
void updateContentCaptureManager(
in IContentCaptureManager contentCaptureManager,
in ContentCaptureOptions options);
+
+ void stopDetection();
}
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
index aec06431c5fb..0bb09a9de07f 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
@@ -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");