From 8151b18c52ddfc6bf5438032898b447e2123cebc Mon Sep 17 00:00:00 2001 From: Ahaan Ugale Date: Mon, 22 Mar 2021 13:35:47 -0700 Subject: [PATCH] Allow HotwordDetectionService to return HotwordRejectedResult. This is simply passed through the system to the AlwaysOnHotwordDetector. Bug: 182788844 Bug: 168305377 CTS-Coverage-Bug: 183425641 Test: builds Change-Id: I2b7147b330051d870bfe970e9b5e16aaab52e9bc --- core/api/system-current.txt | 5 ++-- .../voice/AlwaysOnHotwordDetector.java | 29 +++++++------------ .../voice/HotwordDetectionService.java | 9 ++++-- .../voice/IDspHotwordDetectionCallback.aidl | 6 ++-- .../IHotwordRecognitionStatusCallback.aidl | 9 ++++-- .../HotwordDetectionConnection.java | 7 ++--- 6 files changed, 31 insertions(+), 34 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 115edd15539ad..8023cc62d83ac 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -10320,7 +10320,6 @@ package android.service.voice { method @RequiresPermission(allOf={android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAPTURE_AUDIO_HOTWORD}) public boolean stopRecognition(); field public static final int AUDIO_CAPABILITY_ECHO_CANCELLATION = 1; // 0x1 field public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION = 2; // 0x2 - field public static final int HOTWORD_DETECTION_FALSE_ALERT = 0; // 0x0 field public static final int MODEL_PARAM_THRESHOLD_FACTOR = 0; // 0x0 field public static final int RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS = 2; // 0x2 field public static final int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO = 1; // 0x1 @@ -10343,7 +10342,7 @@ package android.service.voice { method public abstract void onError(); method public abstract void onRecognitionPaused(); method public abstract void onRecognitionResumed(); - method public void onRejected(int); + method public void onRejected(@Nullable android.service.voice.HotwordRejectedResult); } public static class AlwaysOnHotwordDetector.EventPayload { @@ -10392,7 +10391,7 @@ package android.service.voice { public static final class HotwordDetectionService.DspHotwordDetectionCallback { method public void onDetected(); - method public void onRejected(); + method public void onRejected(@Nullable android.service.voice.HotwordRejectedResult); } public interface HotwordDetector { diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index def13db41559b..856df351dea5a 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -238,18 +238,6 @@ public class AlwaysOnHotwordDetector { }) public @interface ModelParams {} - /** - * Indicates that the given audio data is a false alert for {@link VoiceInteractionService}. - */ - public static final int HOTWORD_DETECTION_FALSE_ALERT = 0; - - /** @hide */ - @Retention(RetentionPolicy.SOURCE) - @IntDef(flag = true, prefix = { "HOTWORD_DETECTION_" }, value = { - HOTWORD_DETECTION_FALSE_ALERT, - }) - public @interface HotwordDetectionResult {} - /** * Controls the sensitivity threshold adjustment factor for a given model. * Negative value corresponds to less sensitive model (high threshold) and @@ -478,11 +466,14 @@ public class AlwaysOnHotwordDetector { public abstract void onRecognitionResumed(); /** - * Called when the validated result is invalid. + * Called when the {@link HotwordDetectionService second stage detection} did not detect the + * keyphrase. * - * @param reason The reason why the validated result is invalid. + * @param result Info about the second stage detection result, provided by the + * {@link HotwordDetectionService}. */ - public void onRejected(@HotwordDetectionResult int reason) {} + public void onRejected(@Nullable HotwordRejectedResult result) { + } } /** @@ -1069,13 +1060,13 @@ public class AlwaysOnHotwordDetector { } @Override - public void onRejected(int reason) { + public void onRejected(HotwordRejectedResult result) { if (DBG) { - Slog.d(TAG, "onRejected(" + reason + ")"); + Slog.d(TAG, "onRejected(" + result + ")"); } else { Slog.i(TAG, "onRejected"); } - Message.obtain(mHandler, MSG_HOTWORD_REJECTED, reason).sendToTarget(); + Message.obtain(mHandler, MSG_HOTWORD_REJECTED, result).sendToTarget(); } @Override @@ -1124,7 +1115,7 @@ public class AlwaysOnHotwordDetector { mExternalCallback.onRecognitionResumed(); break; case MSG_HOTWORD_REJECTED: - mExternalCallback.onRejected(msg.arg1); + mExternalCallback.onRejected((HotwordRejectedResult) msg.obj); break; default: super.handleMessage(msg); diff --git a/core/java/android/service/voice/HotwordDetectionService.java b/core/java/android/service/voice/HotwordDetectionService.java index fcef26f13dd03..764e8527cc841 100644 --- a/core/java/android/service/voice/HotwordDetectionService.java +++ b/core/java/android/service/voice/HotwordDetectionService.java @@ -180,11 +180,14 @@ public abstract class HotwordDetectionService extends Service { } /** - * Called when the detected result is invalid. + * Informs the {@link AlwaysOnHotwordDetector} that the keyphrase was not detected. + * + * @param result Info about the second stage detection result. This is provided to + * the {@link AlwaysOnHotwordDetector}. */ - public void onRejected() { + public void onRejected(@Nullable HotwordRejectedResult result) { try { - mRemoteCallback.onRejected(); + mRemoteCallback.onRejected(result); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/service/voice/IDspHotwordDetectionCallback.aidl b/core/java/android/service/voice/IDspHotwordDetectionCallback.aidl index bb95bb831decb..6f641e1cd1e75 100644 --- a/core/java/android/service/voice/IDspHotwordDetectionCallback.aidl +++ b/core/java/android/service/voice/IDspHotwordDetectionCallback.aidl @@ -16,6 +16,8 @@ package android.service.voice; +import android.service.voice.HotwordRejectedResult; + /** * Callback for returning the detected result from the HotwordDetectionService. * @@ -28,7 +30,7 @@ oneway interface IDspHotwordDetectionCallback { void onDetected(); /** - * Called when the detected result is invalid. + * Sends {@code result} to the HotwordDetector. */ - void onRejected(); + void onRejected(in HotwordRejectedResult result); } diff --git a/core/java/com/android/internal/app/IHotwordRecognitionStatusCallback.aidl b/core/java/com/android/internal/app/IHotwordRecognitionStatusCallback.aidl index 65bd8415475ea..23314e7be6221 100644 --- a/core/java/com/android/internal/app/IHotwordRecognitionStatusCallback.aidl +++ b/core/java/com/android/internal/app/IHotwordRecognitionStatusCallback.aidl @@ -17,6 +17,7 @@ package com.android.internal.app; import android.hardware.soundtrigger.SoundTrigger; +import android.service.voice.HotwordRejectedResult; /** * @hide @@ -41,11 +42,13 @@ oneway interface IHotwordRecognitionStatusCallback { void onGenericSoundTriggerDetected(in SoundTrigger.GenericRecognitionEvent recognitionEvent); /** - * Called when the validated result is invalid. + * Called when the {@link HotwordDetectionService second stage detection} did not detect the + * keyphrase. * - * @param reason The reason why the validated result is invalid. + * @param result Info about the second stage detection result, provided by the + * {@link HotwordDetectionService}. */ - void onRejected(int reason); + void onRejected(in HotwordRejectedResult result); /** * Called when the detection fails due to an error. diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index e089995a7b1c8..61ed65b191f09 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -30,8 +30,8 @@ import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.os.SharedMemory; -import android.service.voice.AlwaysOnHotwordDetector; import android.service.voice.HotwordDetectionService; +import android.service.voice.HotwordRejectedResult; import android.service.voice.IDspHotwordDetectionCallback; import android.service.voice.IHotwordDetectionService; import android.util.Pair; @@ -206,13 +206,12 @@ final class HotwordDetectionConnection { } @Override - public void onRejected() throws RemoteException { + public void onRejected(HotwordRejectedResult result) throws RemoteException { if (DEBUG) { Slog.d(TAG, "onRejected"); } cancelingFuture.cancel(true); - externalCallback.onRejected( - AlwaysOnHotwordDetector.HOTWORD_DETECTION_FALSE_ALERT); + externalCallback.onRejected(result); } };