Skip to content

Commit 97887cf

Browse files
Sandeep SiddharthaAndroid (Google) Code Review
authored andcommitted
Merge "Remove direct field access from event payload" into lmp-dev
2 parents a3a5af0 + d5730bc commit 97887cf

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed

api/current.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27774,9 +27774,8 @@ package android.service.voice {
2777427774
}
2777527775

2777627776
public static class AlwaysOnHotwordDetector.EventPayload {
27777-
field public final android.media.AudioFormat audioFormat;
27778-
field public final byte[] data;
27779-
field public final boolean triggerAvailable;
27777+
method public android.media.AudioFormat getCaptureAudioFormat();
27778+
method public byte[] getTriggerAudio();
2778027779
}
2778127780

2778227781
public class VoiceInteractionService extends android.app.Service {

core/java/android/service/voice/AlwaysOnHotwordDetector.java

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -187,48 +187,77 @@ public class AlwaysOnHotwordDetector {
187187
* Additional payload for {@link Callback#onDetected}.
188188
*/
189189
public static class EventPayload {
190+
private final boolean mTriggerAvailable;
191+
// Indicates if {@code captureSession} can be used to continue capturing more audio
192+
// from the DSP hardware.
193+
private final boolean mCaptureAvailable;
194+
// The session to use when attempting to capture more audio from the DSP hardware.
195+
private final int mCaptureSession;
196+
private final AudioFormat mAudioFormat;
197+
// Raw data associated with the event.
198+
// This is the audio that triggered the keyphrase if {@code isTriggerAudio} is true.
199+
private final byte[] mData;
200+
201+
private EventPayload(boolean triggerAvailable, boolean captureAvailable,
202+
AudioFormat audioFormat, int captureSession, byte[] data) {
203+
mTriggerAvailable = triggerAvailable;
204+
mCaptureAvailable = captureAvailable;
205+
mCaptureSession = captureSession;
206+
mAudioFormat = audioFormat;
207+
mData = data;
208+
}
209+
190210
/**
191-
* Indicates if {@code data} is the audio that triggered the keyphrase.
211+
* Gets the format of the audio obtained using {@link #getTriggerAudio()}.
212+
* May be null if there's no audio present.
192213
*/
193-
public final boolean triggerAvailable;
214+
@Nullable
215+
public AudioFormat getCaptureAudioFormat() {
216+
return mAudioFormat;
217+
}
218+
194219
/**
195-
* Indicates if {@code captureSession} can be used to continue capturing more audio from
196-
* the DSP hardware.
220+
* Gets the raw audio that triggered the keyphrase.
221+
* This may be null if the trigger audio isn't available.
222+
* If non-null, the format of the audio can be obtained by calling
223+
* {@link #getCaptureAudioFormat()}.
197224
*
198-
* Candidate for public API
199-
* @hide
225+
* @see AlwaysOnHotwordDetector#RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO
200226
*/
201-
public final boolean captureAvailable;
227+
@Nullable
228+
public byte[] getTriggerAudio() {
229+
if (mTriggerAvailable) {
230+
return mData;
231+
} else {
232+
return null;
233+
}
234+
}
235+
202236
/**
203-
* The session to use when attempting to capture more audio from the DSP hardware.
237+
* Gets the session ID to start a capture from the DSP.
238+
* This may be null if streaming capture isn't possible.
239+
* If non-null, the format of the audio that can be captured can be
240+
* obtained using {@link #getCaptureAudioFormat()}.
241+
*
242+
* TODO: Candidate for Public API when the API to start capture with a session ID
243+
* is made public.
244+
*
245+
* TODO: Add this to {@link #getCaptureAudioFormat()}:
246+
* "Gets the format of the audio obtained using {@link #getTriggerAudio()}
247+
* or {@link #getCaptureSession()}. May be null if no audio can be obtained
248+
* for either the trigger or a streaming session."
249+
*
250+
* TODO: Should this return a known invalid value instead?
204251
*
205-
* Candidate for public API
206-
* TODO: When unhiding, change javadoc of audioFormat to -
207-
* "Format of {@code data} or the audio that may be captured using {@code captureSession}.
208-
* May be null if {@code triggerAvailable} and {@code captureAvailable} are false."
209252
* @hide
210253
*/
211-
public final int captureSession;
212-
/**
213-
* Format of {@code data}.
214-
* May be null if {@code triggerAvailable} is false.
215-
*/
216254
@Nullable
217-
public final AudioFormat audioFormat;
218-
/**
219-
* Raw data associated with the event.
220-
* This is the audio that triggered the keyphrase if {@code isTriggerAudio} is true.
221-
*/
222-
@Nullable
223-
public final byte[] data;
224-
225-
private EventPayload(boolean _triggerAvailable, boolean _captureAvailable,
226-
AudioFormat _audioFormat, int _captureSession, byte[] _data) {
227-
triggerAvailable = _triggerAvailable;
228-
captureAvailable = _captureAvailable;
229-
captureSession = _captureSession;
230-
audioFormat = _audioFormat;
231-
data = _data;
255+
public Integer getCaptureSession() {
256+
if (mCaptureAvailable) {
257+
return mCaptureSession;
258+
} else {
259+
return null;
260+
}
232261
}
233262
}
234263

0 commit comments

Comments
 (0)