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

Commit 5c723d25 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "VIS : SoundTriggerService: follow up fix in createAudioRecordForEvent()"

parents 2abdecc7 1a668976
Loading
Loading
Loading
Loading
+16 −21
Original line number Original line Diff line number Diff line
@@ -1276,7 +1276,8 @@ public class SoundTriggerService extends SystemService {
         * @return The initialized AudioRecord
         * @return The initialized AudioRecord
         */
         */
        private @NonNull AudioRecord createAudioRecordForEvent(
        private @NonNull AudioRecord createAudioRecordForEvent(
                @NonNull SoundTrigger.GenericRecognitionEvent event) {
                @NonNull SoundTrigger.GenericRecognitionEvent event)
                throws IllegalArgumentException, UnsupportedOperationException {
            AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder();
            AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder();
            attributesBuilder.setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD);
            attributesBuilder.setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD);
            AudioAttributes attributes = attributesBuilder.build();
            AudioAttributes attributes = attributesBuilder.build();
@@ -1285,7 +1286,6 @@ public class SoundTriggerService extends SystemService {


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


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


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