diff options
| author | 2021-05-27 22:54:46 +0800 | |
|---|---|---|
| committer | 2021-06-03 12:03:56 +0800 | |
| commit | 645623e732c27e21bd1efdee04dc118e18ad6464 (patch) | |
| tree | d591e75b32576b383bf7bf64aa0d131f5735a6f3 | |
| parent | ba76d446ee3ec1bc7cf1b15a3ca44d3b7d309898 (diff) | |
Implement a callback to report HotwordDetectionService status
When the application uses VoiceInteractionService to create a
SoftwareHotwordDetector, we need to report the HotwordDetectionService
status to the application, but we pass null callback into the
updateStateLocked function, it means that we will not receive the
HotwordDetectionService status.
In this change, we implement IHotwordRecognitionStatusCallback and
pass the callback into updateStateLocked function. When we receive
the HotwordDetectionService status, we will pass the status to the
application.
Bug: 183239093
Test: atest CtsVoiceInteractionTestCases
Test: atest CtsVoiceInteractionTestCases --instant
Change-Id: I1a1b8abe5c7e82eddaa2f0a83f54110df74d1efb
| -rw-r--r-- | core/java/android/service/voice/SoftwareHotwordDetector.java | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/core/java/android/service/voice/SoftwareHotwordDetector.java b/core/java/android/service/voice/SoftwareHotwordDetector.java index 87037f4def6a..47f2c6403757 100644 --- a/core/java/android/service/voice/SoftwareHotwordDetector.java +++ b/core/java/android/service/voice/SoftwareHotwordDetector.java @@ -22,6 +22,7 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainMessa import android.annotation.Nullable; import android.annotation.RequiresPermission; +import android.hardware.soundtrigger.SoundTrigger; import android.media.AudioFormat; import android.os.Handler; import android.os.Looper; @@ -31,6 +32,7 @@ import android.os.RemoteException; import android.os.SharedMemory; import android.util.Slog; +import com.android.internal.app.IHotwordRecognitionStatusCallback; import com.android.internal.app.IVoiceInteractionManagerService; import java.io.PrintWriter; @@ -64,7 +66,8 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector { mAudioFormat = audioFormat; mCallback = callback; mHandler = new Handler(Looper.getMainLooper()); - updateStateLocked(options, sharedMemory, null /* callback */); + updateStateLocked(options, sharedMemory, + new InitializationStateListener(mHandler, mCallback)); } @RequiresPermission(RECORD_AUDIO) @@ -133,6 +136,58 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector { } } + private static class InitializationStateListener + extends IHotwordRecognitionStatusCallback.Stub { + private final Handler mHandler; + private final HotwordDetector.Callback mCallback; + + InitializationStateListener(Handler handler, HotwordDetector.Callback callback) { + this.mHandler = handler; + this.mCallback = callback; + } + + @Override + public void onKeyphraseDetected(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent) + throws RemoteException { + + } + + @Override + public void onGenericSoundTriggerDetected( + SoundTrigger.GenericRecognitionEvent recognitionEvent) throws RemoteException { + + } + + @Override + public void onRejected(HotwordRejectedResult result) throws RemoteException { + + } + + @Override + public void onError(int status) throws RemoteException { + + } + + @Override + public void onRecognitionPaused() throws RemoteException { + + } + + @Override + public void onRecognitionResumed() throws RemoteException { + + } + + @Override + public void onStatusReported(int status) { + Slog.v(TAG, "onStatusReported" + (DEBUG ? "(" + status + ")" : "")); + mHandler.sendMessage(obtainMessage( + HotwordDetector.Callback::onHotwordDetectionServiceInitialized, + mCallback, + status)); + } + } + /** @hide */ public void dump(String prefix, PrintWriter pw) { // TODO: implement this |