Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c86c4cae authored by Bhalchandra Gajare's avatar Bhalchandra Gajare
Browse files

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 25c32fbd)
parent f3284257
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
  }
+24 −0
Original line number Diff line number Diff line
@@ -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.
         *