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

Commit 1a668976 authored by Eric Laurent's avatar Eric Laurent
Browse files

VIS : SoundTriggerService: follow up fix in createAudioRecordForEvent()

Follow up fix after commit a82281f6:
Let SoundTriggerService.createAudioRecordForEvent() throw exceptions
and let the caller act accordingly.

Bug: 161375011
Test: Manual sound trigger regression with OK Google and Now Playing

Change-Id: I9a3c9085a15248a87f76b682a21d785ac73c9d11
parent 0beeb34e
Loading
Loading
Loading
Loading
+16 −21
Original line number Diff line number Diff line
@@ -1276,7 +1276,8 @@ 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();
@@ -1285,7 +1286,6 @@ public class SoundTriggerService extends SystemService {

            sEventLogger.log(new SoundTriggerLogger.StringEvent("createAudioRecordForEvent"));

            try {
            return (new AudioRecord.Builder())
                        .setAudioAttributes(attributes)
                        .setAudioFormat((new AudioFormat.Builder())
@@ -1295,11 +1295,6 @@ public class SoundTriggerService extends SystemService {
                            .build())
                        .setSessionId(event.getCaptureSession())
                        .build();
            } catch (IllegalArgumentException | UnsupportedOperationException e) {
                Slog.w(TAG, mPuuid + ": createAudioRecordForEvent(" + event
                        + "), failed to create AudioRecord");
                return null;
            }
        }

        @Override
@@ -1325,13 +1320,13 @@ public class SoundTriggerService extends SystemService {
                    // execute if throttled:
                    () -> {
                        if (event.isCaptureAvailable()) {
                            try {
                                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
                            if (capturedData != null) {
                                capturedData.startRecording();
                                capturedData.release();
                            } catch (IllegalArgumentException | UnsupportedOperationException e) {
                                Slog.w(TAG, mPuuid + ": createAudioRecordForEvent(" + event
                                        + "), failed to create AudioRecord");
                            }
                        }
                    }));