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 25c32fbd9e)
This commit is contained in:
Bhalchandra Gajare
2021-01-24 07:21:59 -08:00
parent f32842575b
commit c86c4cae91
2 changed files with 25 additions and 0 deletions

View File

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

View File

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