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

Commit f4df3421 authored by Sergey Volnov's avatar Sergey Volnov Committed by Android (Google) Code Review
Browse files

Merge "Enhance AlwaysOnHotwordDetector.EventPayload with more fields." into sc-dev

parents d240e2be a3f9ee62
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -10381,7 +10381,9 @@ package android.service.voice {
  }
  }
  public static class AlwaysOnHotwordDetector.EventPayload {
  public static class AlwaysOnHotwordDetector.EventPayload {
    method @Nullable public android.os.ParcelFileDescriptor getAudioStream();
    method @Nullable public android.media.AudioFormat getCaptureAudioFormat();
    method @Nullable public android.media.AudioFormat getCaptureAudioFormat();
    method @Nullable public android.service.voice.HotwordDetectedResult getHotwordDetectedResult();
    method @Nullable public byte[] getTriggerAudio();
    method @Nullable public byte[] getTriggerAudio();
  }
  }
+49 −0
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@ import android.os.Build;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Message;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SharedMemory;
import android.os.SharedMemory;
@@ -342,14 +343,35 @@ public class AlwaysOnHotwordDetector {
        // Raw data associated with the event.
        // Raw data associated with the event.
        // This is the audio that triggered the keyphrase if {@code isTriggerAudio} is true.
        // This is the audio that triggered the keyphrase if {@code isTriggerAudio} is true.
        private final byte[] mData;
        private final byte[] mData;
        private final HotwordDetectedResult mHotwordDetectedResult;
        private final ParcelFileDescriptor mAudioStream;


        private EventPayload(boolean triggerAvailable, boolean captureAvailable,
        private EventPayload(boolean triggerAvailable, boolean captureAvailable,
                AudioFormat audioFormat, int captureSession, byte[] data) {
                AudioFormat audioFormat, int captureSession, byte[] data) {
            this(triggerAvailable, captureAvailable, audioFormat, captureSession, data, null,
                    null);
        }

        EventPayload(AudioFormat audioFormat, HotwordDetectedResult hotwordDetectedResult) {
            this(false, false, audioFormat, -1, null, hotwordDetectedResult, null);
        }

        EventPayload(AudioFormat audioFormat,
                HotwordDetectedResult hotwordDetectedResult,
                ParcelFileDescriptor audioStream) {
            this(false, false, audioFormat, -1, null, hotwordDetectedResult, audioStream);
        }

        private EventPayload(boolean triggerAvailable, boolean captureAvailable,
                AudioFormat audioFormat, int captureSession, byte[] data,
                HotwordDetectedResult hotwordDetectedResult, ParcelFileDescriptor audioStream) {
            mTriggerAvailable = triggerAvailable;
            mTriggerAvailable = triggerAvailable;
            mCaptureAvailable = captureAvailable;
            mCaptureAvailable = captureAvailable;
            mCaptureSession = captureSession;
            mCaptureSession = captureSession;
            mAudioFormat = audioFormat;
            mAudioFormat = audioFormat;
            mData = data;
            mData = data;
            mHotwordDetectedResult = hotwordDetectedResult;
            mAudioStream = audioStream;
        }
        }


        /**
        /**
@@ -405,6 +427,33 @@ public class AlwaysOnHotwordDetector {
                return null;
                return null;
            }
            }
        }
        }

        /**
         * Returns {@link HotwordDetectedResult} associated with the hotword event, passed from
         * {@link HotwordDetectionService}.
         */
        @Nullable
        public HotwordDetectedResult getHotwordDetectedResult() {
            return mHotwordDetectedResult;
        }

        /**
         * Returns a stream with bytes corresponding to the open audio stream with hotword data.
         *
         * <p>This data represents an audio stream in the format returned by
         * {@link #getCaptureAudioFormat}.
         *
         * <p>Clients are expected to start consuming the stream within 1 second of receiving the
         * event.
         *
         * <p>When this method returns a non-null, clients must close this stream when it's no
         * longer needed. Failing to do so will result in microphone being open for longer periods
         * of time, and app being attributed for microphone usage.
         */
        @Nullable
        public ParcelFileDescriptor getAudioStream() {
            return mAudioStream;
        }
    }
    }


    /**
    /**