From 7b8da92d49caf965e8616ceeba828275574f09c0 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Mon, 1 May 2017 17:51:14 -0700 Subject: [PATCH] Audio focus: fix notifying apps to pause without an external policy In the absence of an external audio policy that implements ducking, check whether the focus loser has the AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS flag: if yes, do not let the framework handle ducking, notify the app. Test: use app that calls AudioFocusRequest.Builder.setWillPauseWhenDucked(true) and verify it doesn't get ducked by framework Bug: 30258418 Change-Id: I12655b413504ed101dd14d2b60ffdaf16c5b6148 --- .../java/com/android/server/audio/FocusRequester.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/audio/FocusRequester.java b/services/core/java/com/android/server/audio/FocusRequester.java index 3bc603fbd3c1a..93a224949812a 100644 --- a/services/core/java/com/android/server/audio/FocusRequester.java +++ b/services/core/java/com/android/server/audio/FocusRequester.java @@ -342,6 +342,7 @@ public class FocusRequester { mFocusLossWasNotified = false; // before dispatching a focus loss, check if the following conditions are met: // 1/ the framework is not supposed to notify the focus loser on a DUCK loss + // (i.e. it has a focus controller that implements a ducking policy) // 2/ it is a DUCK loss // 3/ the focus loser isn't flagged as pausing in a DUCK loss // if they are, do not notify the focus loser @@ -365,7 +366,14 @@ public class FocusRequester { && fr != null) { // candidate for enforcement by the framework if (fr.mCallingUid != this.mCallingUid) { - handled = mFocusController.duckPlayers(fr, this); + if ((mGrantFlags + & AudioManager.AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS) != 0) { + // the focus loser declared it would pause instead of duck, let it + // handle it (the framework doesn't pause for apps) + handled = false; + } else { + handled = mFocusController.duckPlayers(fr, this); + } } // else: the focus change is within the same app, so let the dispatching // happen as if the framework was not involved. }