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

Commit 1245747b authored by Ian Baker's avatar Ian Baker
Browse files

Remove cooldown for sessionless foreground vol key routing

Previous to this change, vol keys would be routed to the foreground
app if it was the last app to play audio, even if that was hours ago
(and therefore far outside the user's expectation/context). This change
reduces this infinite timeout to zero, so as soon as the foreground
stops playing audio the keys will be routed back to the remote/casting
session. This is aligned with other volume key routing decisions in
AudioService (zero cooldown).

Bug: 432003816
Test: Manual testing & check MediaSessionTest and MediaActivityTest pass with flag enabled
Flag: com.android.media.mediasession.flags.sessionless_vol_key_zero_cooldown
Change-Id: I3b952997d4b77593df598474f215e133199a49d2
parent d0ae4fec
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -35,3 +35,12 @@ flag {
  description: "Filter audio playback uids used for session tracking by audio usage type (to e.g. ignore notification audio)."
  bug: "432003816"
}

flag {
  name: "sessionless_vol_key_zero_cooldown"
  namespace: "media_solutions"
  description: "Decrease the 'cooldown' (time since last audio playback) for routing volume "
               "keys to a foreground session-less app (instead of an active remote session) "
               "from infinity to zero."
  bug: "432003816"
}
+7 −5
Original line number Diff line number Diff line
@@ -2572,11 +2572,13 @@ public class MediaSessionService extends SystemService implements Monitor {
                    isValidLocalStreamType(suggestedStream)
                            && AudioSystem.isStreamActive(suggestedStream, 0);

            if (session != null && session.getUid() != uid
                    && mAudioPlayerStateMonitor.hasUidPlayedAudioLast(uid)) {
                // 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.
            if (session != null
                    && session.getUid() != uid
                    && (com.android.media.mediasession.flags.Flags.sessionlessVolKeyZeroCooldown()
                            ? mAudioPlayerStateMonitor.isPlaybackActive(uid)
                            : mAudioPlayerStateMonitor.hasUidPlayedAudioLast(uid))) {
                // We ignore the chosen session so that volume events affect the local music stream
                // instead. See b/275185436 and b/432003816 for details.
                Log.d(TAG, "Ignoring session=" + session + " and adjusting suggestedStream="
                        + suggestedStream + " instead");
                session = null;