diff options
| author | 2020-12-29 15:55:33 -0800 | |
|---|---|---|
| committer | 2020-12-29 16:01:37 -0800 | |
| commit | fead0fa2f11f449bcff62103671a8745a8d2fddc (patch) | |
| tree | b174f664a0ae9cb0805dbac7e5d267616a8346dd | |
| parent | 3693be0b5e25c330c877a00eacf64dca701e2102 (diff) | |
AudioService: focus abandon notifies focus followers
When a focus owner abandons focus, notify focus
followers.
Bug: 155098568
Test: atest com.google.android.gts.audio.AudioHostTest#testFocusChangeMediaToGuidance
Test: atest com.google.android.gts.audio.AudioHostTest#testFocusAbandonNotification
Change-Id: I5b05663cd526a28c8f537bbd8760ace4e461f168
| -rw-r--r-- | services/core/java/com/android/server/audio/MediaFocusControl.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/audio/MediaFocusControl.java b/services/core/java/com/android/server/audio/MediaFocusControl.java index 5025c4aeaf05..b1633b01df90 100644 --- a/services/core/java/com/android/server/audio/MediaFocusControl.java +++ b/services/core/java/com/android/server/audio/MediaFocusControl.java @@ -288,6 +288,7 @@ public class MediaFocusControl implements PlayerFocusEnforcer { @GuardedBy("mAudioFocusLock") private void removeFocusStackEntry(String clientToRemove, boolean signal, boolean notifyFocusFollowers) { + AudioFocusInfo abandonSource = null; // is the current top of the focus stack abandoning focus? (because of request, not death) if (!mFocusStack.empty() && mFocusStack.peek().hasSameClient(clientToRemove)) { @@ -295,9 +296,7 @@ public class MediaFocusControl implements PlayerFocusEnforcer { FocusRequester fr = mFocusStack.pop(); fr.release(); if (notifyFocusFollowers) { - final AudioFocusInfo afi = fr.toAudioFocusInfo(); - afi.clearLossReceived(); - notifyExtPolicyFocusLoss_syncAf(afi, false); + abandonSource = fr.toAudioFocusInfo(); } if (signal) { // notify the new top of the stack it gained focus @@ -315,11 +314,19 @@ public class MediaFocusControl implements PlayerFocusEnforcer { Log.i(TAG, "AudioFocus removeFocusStackEntry(): removing entry for " + clientToRemove); stackIterator.remove(); + if (notifyFocusFollowers) { + abandonSource = fr.toAudioFocusInfo(); + } // stack entry not used anymore, clear references fr.release(); } } } + // focus followers still want to know focus was abandoned, handled as a loss + if (abandonSource != null) { + abandonSource.clearLossReceived(); + notifyExtPolicyFocusLoss_syncAf(abandonSource, false); + } if (mMultiAudioFocusEnabled && !mMultiAudioFocusList.isEmpty()) { Iterator<FocusRequester> listIterator = mMultiAudioFocusList.iterator(); |