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
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 02c9fcb5..ba18f48 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -805,7 +805,12 @@
+ 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 @@
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,