From c86c4cae910930283adce341c4ae8139bf02a727 Mon Sep 17 00:00:00 2001 From: Bhalchandra Gajare Date: Sun, 24 Jan 2021 07:21:59 -0800 Subject: [PATCH] AudioAttributes: add ability to set Hotword mode for capture Allow setting Hotword mode for capture usecases that want to use the low power DSP based hotword source for capturing audio. This will be only available for AudioSource.VOICE_RECOGNITION. There is no guarantee that this mode will be available on the device. The caller must have the CAPTURE_AUDIO_HOTWORD permission granted. Bug 178317696 Test: Able to setHotwordMode from AGSA application. Confirmed HAL receives the flag and audioSource correctly in open_input_stream. Merged-In: I1fb80a047654e2abb8a587bf2f6ff82fcacd67b6 Change-Id: I1fb80a047654e2abb8a587bf2f6ff82fcacd67b6 (cherry picked from commit 25c32fbd9e6b2a5e31524da57ececbfe3462fa04) --- core/api/system-current.txt | 1 + media/java/android/media/AudioAttributes.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 0a0f77e33ed49..e1025c88b21cd 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -4622,6 +4622,7 @@ package android.media { public static class AudioAttributes.Builder { method public android.media.AudioAttributes.Builder addBundle(@NonNull android.os.Bundle); method public android.media.AudioAttributes.Builder setCapturePreset(int); + method @NonNull @RequiresPermission(android.Manifest.permission.CAPTURE_AUDIO_HOTWORD) public android.media.AudioAttributes.Builder setHotwordMode(); method public android.media.AudioAttributes.Builder setInternalCapturePreset(int); method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public android.media.AudioAttributes.Builder setSystemUsage(int); } diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index bcc846b6d7f85..bb1dbd436e0bd 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -739,6 +739,13 @@ public final class AudioAttributes implements Parcelable { if (mBundle != null) { aa.mBundle = new Bundle(mBundle); } + + // Allow the FLAG_HW_HOTWORD only for AudioSource.VOICE_RECOGNITION + if (mSource != MediaRecorder.AudioSource.VOICE_RECOGNITION + && (mFlags & FLAG_HW_HOTWORD) == FLAG_HW_HOTWORD) { + aa.mFlags &= ~FLAG_HW_HOTWORD; + } + return aa; } @@ -851,6 +858,23 @@ public final class AudioAttributes implements Parcelable { return this; } + /** + * @hide + * Request for capture in hotword mode. + * + * Requests an audio path optimized for Hotword detection use cases from + * the low power audio DSP. This is valid only for capture with + * audio source {@link MediaRecorder.AudioSource#VOICE_RECOGNITION}. + * There is no guarantee that this mode is available on the device. + * @return the same Builder instance. + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.CAPTURE_AUDIO_HOTWORD) + public @NonNull Builder setHotwordMode() { + mFlags |= FLAG_HW_HOTWORD; + return this; + } + /** * Specifies whether the audio may or may not be captured by other apps or the system. *