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

Commit 9c785401 authored by RoboErik's avatar RoboErik
Browse files

Use the suggested stream if it's currently active

This makes the MediaSessionService check if the suggested stream is active
when dispatching a volume event and prefer it to a remote session if it is.
This mostly affects apps that use Activity.setVolumeControlStream.

bug:18318480
Change-Id: Ib8825394bf7a223fbd92bcb2c3ecb7c596ce7c29
parent c08eab81
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -805,7 +805,12 @@ public class MediaSessionService extends SystemService implements Monitor {
                        + flags + ", suggestedStream=" + suggestedStream);

            }
            if (session == null) {
            boolean preferSuggestedStream = false;
            if (isValidLocalStreamType(suggestedStream)
                    && AudioSystem.isStreamActive(suggestedStream, 0)) {
                preferSuggestedStream = true;
            }
            if (session == null || preferSuggestedStream) {
                if ((flags & AudioManager.FLAG_ACTIVE_MEDIA_ONLY) != 0
                        && !AudioSystem.isStreamActive(AudioManager.STREAM_MUSIC, 0)) {
                    if (DEBUG) {
@@ -959,6 +964,12 @@ public class MediaSessionService extends SystemService implements Monitor {
            return keyCode == KeyEvent.KEYCODE_HEADSETHOOK;
        }

        // we only handle public stream types, which are 0-5
        private boolean isValidLocalStreamType(int streamType) {
            return streamType >= AudioManager.STREAM_VOICE_CALL
                    && streamType <= AudioManager.STREAM_NOTIFICATION;
        }

        private KeyEventWakeLockReceiver mKeyEventReceiver = new KeyEventWakeLockReceiver(mHandler);

        class KeyEventWakeLockReceiver extends ResultReceiver implements Runnable,