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

Commit 8b5ab656 authored by Christian Frank's avatar Christian Frank Committed by Automerger Merge Worker
Browse files

Merge "Address corner case in which empty audio is requested and...

Merge "Address corner case in which empty audio is requested and MusicRecognitionManagerService crashes." into sc-dev am: 2b14f17e am: 6c491f07

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15208796

Change-Id: I75b2dd7d3977b6a06cbd29da09a127b04baa93b9
parents f8b094f6 6c491f07
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -208,6 +208,24 @@ public final class MusicRecognitionManagerPerUserService extends
            @NonNull RecognitionRequest recognitionRequest,
            IMusicRecognitionManagerCallback clientCallback,
            ParcelFileDescriptor audioSink) {
        int maxAudioLengthSeconds = Math.min(recognitionRequest.getMaxAudioLengthSeconds(),
                MAX_STREAMING_SECONDS);
        if (maxAudioLengthSeconds <= 0) {
            // TODO(b/192992319): A request to stream 0s of audio can be used to initialize the
            //  music recognition service implementation, hence not reporting an error here.
            // The TODO for Android T is to move this functionality into an init() API call.
            Slog.i(TAG, "No audio requested. Closing stream.");
            try {
                audioSink.close();
                clientCallback.onAudioStreamClosed();
            } catch (IOException e) {
                Slog.e(TAG, "Problem closing stream.", e);
            } catch (RemoteException ignored) {
                // Ignored.
            }
            return;
        }

        try {
            startRecordAudioOp(attributionTag);
        } catch (SecurityException e) {
@@ -224,8 +242,6 @@ public final class MusicRecognitionManagerPerUserService extends
            return;
        }

        int maxAudioLengthSeconds = Math.min(recognitionRequest.getMaxAudioLengthSeconds(),
                MAX_STREAMING_SECONDS);
        AudioRecord audioRecord = createAudioRecord(recognitionRequest, maxAudioLengthSeconds);
        try (OutputStream fos =
                     new ParcelFileDescriptor.AutoCloseOutputStream(audioSink)) {