From 1d87cf0604e5d82bd52792f4d345e3dbfc9996d8 Mon Sep 17 00:00:00 2001 From: Sergey Volnov Date: Fri, 26 Feb 2021 20:48:56 +0000 Subject: Refactor audio flows so that server streams audio to the client. This way server has control over when to stop recording (in case clients time out or don't start consuming bytes) AND it solves the attribution problem (Voice Interaction Service would only get the capture session upon a positive trigger, so would be "blamed" then). Test: atest CtsVoiceInteractionTestCases Bug: 168305377 Change-Id: If5bead87e88cfc9e31393029df5389afb6922183 --- .../service/voice/HotwordDetectionService.java | 29 ++++++++++++++++++---- .../service/voice/IHotwordDetectionService.aidl | 8 +++++- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/service/voice/HotwordDetectionService.java b/core/java/android/service/voice/HotwordDetectionService.java index 3c35d2ca78eb..7f1c5ff96636 100644 --- a/core/java/android/service/voice/HotwordDetectionService.java +++ b/core/java/android/service/voice/HotwordDetectionService.java @@ -19,15 +19,18 @@ package android.service.voice; import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage; import android.annotation.CallSuper; +import android.annotation.DurationMillisLong; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.app.Service; import android.content.Intent; +import android.media.AudioFormat; import android.os.Handler; import android.os.IBinder; import android.os.Looper; +import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.util.Log; @@ -57,14 +60,21 @@ public abstract class HotwordDetectionService extends Service { private final IHotwordDetectionService mInterface = new IHotwordDetectionService.Stub() { @Override - public void detectFromDspSource(int sessionId, IDspHotwordDetectionCallback callback) + public void detectFromDspSource( + ParcelFileDescriptor audioStream, + AudioFormat audioFormat, + long timeoutMillis, + IDspHotwordDetectionCallback callback) throws RemoteException { if (DBG) { Log.d(TAG, "#detectFromDspSource"); } mHandler.sendMessage(obtainMessage(HotwordDetectionService::onDetectFromDspSource, HotwordDetectionService.this, - sessionId, new DspHotwordDetectionCallback(callback))); + audioStream, + audioFormat, + timeoutMillis, + new DspHotwordDetectionCallback(callback))); } }; @@ -89,15 +99,24 @@ public abstract class HotwordDetectionService extends Service { /** * Detect the audio data generated from Dsp. * - * @param sessionId The session to use when attempting to capture more audio from the DSP - * hardware. + *

Note: the clients are supposed to call {@code close} on the input stream when they are + * done with the operation in order to free up resources. + * + * @param audioStream Stream containing audio bytes returned from DSP + * @param audioFormat Format of the supplied audio + * @param timeoutMillis Timeout in milliseconds for the operation to invoke the callback. If + * the application fails to abide by the timeout, system will close the + * microphone and cancel the operation. * @param callback Use {@link HotwordDetectionService#DspHotwordDetectionCallback} to return * the detected result. * * @hide */ @SystemApi - public void onDetectFromDspSource(int sessionId, + public void onDetectFromDspSource( + @NonNull ParcelFileDescriptor audioStream, + @NonNull AudioFormat audioFormat, + @DurationMillisLong long timeoutMillis, @NonNull DspHotwordDetectionCallback callback) { } diff --git a/core/java/android/service/voice/IHotwordDetectionService.aidl b/core/java/android/service/voice/IHotwordDetectionService.aidl index 990ad4574788..cbe76e4bf69f 100644 --- a/core/java/android/service/voice/IHotwordDetectionService.aidl +++ b/core/java/android/service/voice/IHotwordDetectionService.aidl @@ -16,6 +16,8 @@ package android.service.voice; +import android.media.AudioFormat; +import android.os.ParcelFileDescriptor; import android.service.voice.IDspHotwordDetectionCallback; /** @@ -24,5 +26,9 @@ import android.service.voice.IDspHotwordDetectionCallback; * @hide */ oneway interface IHotwordDetectionService { - void detectFromDspSource(int sessionId, in IDspHotwordDetectionCallback callback); + void detectFromDspSource( + in ParcelFileDescriptor audioStream, + in AudioFormat audioFormat, + long timeoutMillis, + in IDspHotwordDetectionCallback callback); } -- cgit v1.2.3