Merge "Hotword: Add onStopDetection() for software detectors." into sc-dev am: 76660ef721

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14718524

Change-Id: Id52a02d9e7c53b3d8fe373397452d20c36fa6a1c
This commit is contained in:
Sergey Volnov
2021-05-25 22:09:01 +00:00
committed by Automerger Merge Worker
4 changed files with 19 additions and 0 deletions

View File

@@ -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

View File

@@ -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.
*

View File

@@ -53,4 +53,6 @@ oneway interface IHotwordDetectionService {
void updateContentCaptureManager(
in IContentCaptureManager contentCaptureManager,
in ContentCaptureOptions options);
void stopDetection();
}

View File

@@ -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");