diff options
author | Eric Laurent <elaurent@google.com> | 2020-07-16 10:08:25 -0700 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2020-08-14 18:41:08 +0000 |
commit | cbc302a86e702ba15d446dc38793db838fd0b109 (patch) | |
tree | 9e5e46adb1a58f0d01ff00c4551e7e389499c8e8 /services/voiceinteraction | |
parent | bae844a14d42430ddb2932cc16efefa5b63b41df (diff) |
VIS : SoundTriggerService: fix fake AudioRecord creation
Make sure exceptions that can occur when creating the fake AudioRecord
instance in SoundTriggerService.createAudioRecordForEvent() are caught.
Bug: 161375011
Test: Manual sound trigger regression with OK Google and Now Playing
Squashed commit of:
a82281f6e7643ba08276de8181d44df11ecf8ae7
1a6689766af6831f0ba6b6a01d245caf4ef438c6
Change-Id: Ib973e22a5f1bd43facca1ed8c282fe444a739249
Merged-In: Ie367b9dda6f9e4f3079f5afe2ac92fc98cf8bced
Diffstat (limited to 'services/voiceinteraction')
-rw-r--r-- | services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index 6c13cd799bc2..20e0cfe41791 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -1284,32 +1284,25 @@ public class SoundTriggerService extends SystemService { * @return The initialized AudioRecord */ private @NonNull AudioRecord createAudioRecordForEvent( - @NonNull SoundTrigger.GenericRecognitionEvent event) { + @NonNull SoundTrigger.GenericRecognitionEvent event) + throws IllegalArgumentException, UnsupportedOperationException { AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder(); attributesBuilder.setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD); AudioAttributes attributes = attributesBuilder.build(); - // Use same AudioFormat processing as in RecognitionEvent.fromParcel AudioFormat originalFormat = event.getCaptureFormat(); - AudioFormat captureFormat = (new AudioFormat.Builder()) - .setChannelMask(originalFormat.getChannelMask()) - .setEncoding(originalFormat.getEncoding()) - .setSampleRate(originalFormat.getSampleRate()) - .build(); - - int bufferSize = AudioRecord.getMinBufferSize( - captureFormat.getSampleRate() == AudioFormat.SAMPLE_RATE_UNSPECIFIED - ? AudioFormat.SAMPLE_RATE_HZ_MAX - : captureFormat.getSampleRate(), - captureFormat.getChannelCount() == 2 - ? AudioFormat.CHANNEL_IN_STEREO - : AudioFormat.CHANNEL_IN_MONO, - captureFormat.getEncoding()); sEventLogger.log(new SoundTriggerLogger.StringEvent("createAudioRecordForEvent")); - return new AudioRecord(attributes, captureFormat, bufferSize, - event.getCaptureSession()); + return (new AudioRecord.Builder()) + .setAudioAttributes(attributes) + .setAudioFormat((new AudioFormat.Builder()) + .setChannelMask(originalFormat.getChannelMask()) + .setEncoding(originalFormat.getEncoding()) + .setSampleRate(originalFormat.getSampleRate()) + .build()) + .setSessionId(event.getCaptureSession()) + .build(); } @Override @@ -1335,12 +1328,16 @@ public class SoundTriggerService extends SystemService { // execute if throttled: () -> { if (event.isCaptureAvailable()) { - AudioRecord capturedData = createAudioRecordForEvent(event); - - // Currently we need to start and release the audio record to reset - // the DSP even if we don't want to process the event - capturedData.startRecording(); - capturedData.release(); + try { + // Currently we need to start and release the audio record to reset + // the DSP even if we don't want to process the eve + AudioRecord capturedData = createAudioRecordForEvent(event); + capturedData.startRecording(); + capturedData.release(); + } catch (IllegalArgumentException | UnsupportedOperationException e) { + Slog.w(TAG, mPuuid + ": createAudioRecordForEvent(" + event + + "), failed to create AudioRecord"); + } } })); } |