Loading media/java/android/media/flags/media_better_together.aconfig +11 −4 Original line number Diff line number Diff line package: "com.android.media.flags" flag { namespace: "media_solutions" name: "enable_rlp_callbacks_in_media_router2" namespace: "media_solutions" description: "Make RouteListingPreference getter and callbacks public in MediaRouter2." bug: "281067101" } flag { name: "adjust_volume_for_foreground_app_playing_audio_without_media_session" namespace: "media_solutions" description: "Gates whether to adjust local stream volume when the app in the foreground is the last app to play audio or adjust the volume of the last active media session that the user interacted with." bug: "275185436" } services/core/java/com/android/server/media/AudioPlayerStateMonitor.java +18 −1 Original line number Diff line number Diff line Loading @@ -153,6 +153,23 @@ class AudioPlayerStateMonitor { return sortedAudioPlaybackClientUids; } /** * Returns whether the given uid corresponds to the last process to audio or not. * * <p> This is useful for handling the cases where the foreground app is playing media without * a media session. Then, volume events should affect the local music stream rather than other * media sessions. * * @return {@code true} if the given uid corresponds to the last process to audio or * {@code false} otherwise. */ public boolean hasUidPlayedAudioLast(int uid) { synchronized (mLock) { return !mSortedAudioPlaybackClientUids.isEmpty() && uid == mSortedAudioPlaybackClientUids.get(0); } } /** * Returns if the audio playback is active for the uid. */ Loading Loading @@ -234,7 +251,7 @@ class AudioPlayerStateMonitor { } } // Update mSortedAuioPlaybackClientUids. // Update mSortedAudioPlaybackClientUids. for (int i = 0; i < activeAudioPlaybackConfigs.size(); ++i) { AudioPlaybackConfiguration config = activeAudioPlaybackConfigs.valueAt(i); final int uid = config.getClientUid(); Loading services/core/java/com/android/server/media/MediaSessionService.java +16 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.server.media; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; import static android.os.UserHandle.ALL; import static android.os.UserHandle.CURRENT; import static com.android.server.media.MediaKeyDispatcher.KEY_EVENT_LONG_PRESS; import static com.android.server.media.MediaKeyDispatcher.isDoubleTapOverridden; import static com.android.server.media.MediaKeyDispatcher.isLongPressOverridden; Loading Loading @@ -85,6 +84,7 @@ import android.view.ViewConfiguration; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.media.flags.Flags; import com.android.server.LocalManagerRegistry; import com.android.server.LocalServices; import com.android.server.SystemService; Loading Loading @@ -2192,6 +2192,21 @@ public class MediaSessionService extends SystemService implements Monitor { isValidLocalStreamType(suggestedStream) && AudioSystem.isStreamActive(suggestedStream, 0); if (session != null && session.getUid() != uid && mAudioPlayerStateMonitor.hasUidPlayedAudioLast(uid)) { if (Flags.adjustVolumeForForegroundAppPlayingAudioWithoutMediaSession()) { // The app in the foreground has been the last app to play media locally. // Therefore, We ignore the chosen session so that volume events affect the // local music stream instead. See b/275185436 for details. Log.d(TAG, "Ignoring session=" + session + " and adjusting suggestedStream=" + suggestedStream + " instead"); session = null; } else { Log.d(TAG, "Session=" + session + " will not be not ignored and will receive" + " the volume adjustment event"); } } if (session == null || preferSuggestedStream) { if (DEBUG_KEY_EVENT) { Log.d(TAG, "Adjusting suggestedStream=" + suggestedStream + " by " + direction Loading Loading
media/java/android/media/flags/media_better_together.aconfig +11 −4 Original line number Diff line number Diff line package: "com.android.media.flags" flag { namespace: "media_solutions" name: "enable_rlp_callbacks_in_media_router2" namespace: "media_solutions" description: "Make RouteListingPreference getter and callbacks public in MediaRouter2." bug: "281067101" } flag { name: "adjust_volume_for_foreground_app_playing_audio_without_media_session" namespace: "media_solutions" description: "Gates whether to adjust local stream volume when the app in the foreground is the last app to play audio or adjust the volume of the last active media session that the user interacted with." bug: "275185436" }
services/core/java/com/android/server/media/AudioPlayerStateMonitor.java +18 −1 Original line number Diff line number Diff line Loading @@ -153,6 +153,23 @@ class AudioPlayerStateMonitor { return sortedAudioPlaybackClientUids; } /** * Returns whether the given uid corresponds to the last process to audio or not. * * <p> This is useful for handling the cases where the foreground app is playing media without * a media session. Then, volume events should affect the local music stream rather than other * media sessions. * * @return {@code true} if the given uid corresponds to the last process to audio or * {@code false} otherwise. */ public boolean hasUidPlayedAudioLast(int uid) { synchronized (mLock) { return !mSortedAudioPlaybackClientUids.isEmpty() && uid == mSortedAudioPlaybackClientUids.get(0); } } /** * Returns if the audio playback is active for the uid. */ Loading Loading @@ -234,7 +251,7 @@ class AudioPlayerStateMonitor { } } // Update mSortedAuioPlaybackClientUids. // Update mSortedAudioPlaybackClientUids. for (int i = 0; i < activeAudioPlaybackConfigs.size(); ++i) { AudioPlaybackConfiguration config = activeAudioPlaybackConfigs.valueAt(i); final int uid = config.getClientUid(); Loading
services/core/java/com/android/server/media/MediaSessionService.java +16 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.server.media; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; import static android.os.UserHandle.ALL; import static android.os.UserHandle.CURRENT; import static com.android.server.media.MediaKeyDispatcher.KEY_EVENT_LONG_PRESS; import static com.android.server.media.MediaKeyDispatcher.isDoubleTapOverridden; import static com.android.server.media.MediaKeyDispatcher.isLongPressOverridden; Loading Loading @@ -85,6 +84,7 @@ import android.view.ViewConfiguration; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.media.flags.Flags; import com.android.server.LocalManagerRegistry; import com.android.server.LocalServices; import com.android.server.SystemService; Loading Loading @@ -2192,6 +2192,21 @@ public class MediaSessionService extends SystemService implements Monitor { isValidLocalStreamType(suggestedStream) && AudioSystem.isStreamActive(suggestedStream, 0); if (session != null && session.getUid() != uid && mAudioPlayerStateMonitor.hasUidPlayedAudioLast(uid)) { if (Flags.adjustVolumeForForegroundAppPlayingAudioWithoutMediaSession()) { // The app in the foreground has been the last app to play media locally. // Therefore, We ignore the chosen session so that volume events affect the // local music stream instead. See b/275185436 for details. Log.d(TAG, "Ignoring session=" + session + " and adjusting suggestedStream=" + suggestedStream + " instead"); session = null; } else { Log.d(TAG, "Session=" + session + " will not be not ignored and will receive" + " the volume adjustment event"); } } if (session == null || preferSuggestedStream) { if (DEBUG_KEY_EVENT) { Log.d(TAG, "Adjusting suggestedStream=" + suggestedStream + " by " + direction Loading