diff options
| author | 2022-12-21 13:11:49 +0000 | |
|---|---|---|
| committer | 2022-12-21 13:11:49 +0000 | |
| commit | 655beb339eae885110d8ca81d9741244ee17cf68 (patch) | |
| tree | 081c329678dba7cbb916b8d2b3122fe83a86c973 | |
| parent | ccb92936e092663fab41f2dc0dac429fcf98e14f (diff) | |
| parent | 147a9fb5b899d86307567b44d1dab0398a532805 (diff) | |
Merge "Do not keep MediaSession Tokens for Notification accounting" into tm-qpr-dev am: 4d3ec5c88d am: 147a9fb5b8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20794187
Change-Id: Ib967ec25ac8f3e6a380421dc2161a0c7a5fce933
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt index ab93b292308e..d6f941de1b6d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt @@ -58,10 +58,10 @@ constructor( // Keep track of the key used for the session tokens. This information is used to know when to // dispatch a removed event so that a media object for a local session will be removed. - private val keyedTokens: MutableMap<String, MutableSet<MediaSession.Token>> = mutableMapOf() + private val keyedTokens: MutableMap<String, MutableSet<TokenId>> = mutableMapOf() // Keep track of which media session tokens have associated notifications. - private val tokensWithNotifications: MutableSet<MediaSession.Token> = mutableSetOf() + private val tokensWithNotifications: MutableSet<TokenId> = mutableSetOf() private val sessionListener = object : MediaSessionManager.OnActiveSessionsChangedListener { @@ -101,15 +101,15 @@ constructor( isSsReactivated: Boolean ) { backgroundExecutor.execute { - data.token?.let { tokensWithNotifications.add(it) } + data.token?.let { tokensWithNotifications.add(TokenId(it)) } val isMigration = oldKey != null && key != oldKey if (isMigration) { keyedTokens.remove(oldKey)?.let { removed -> keyedTokens.put(key, removed) } } if (data.token != null) { - keyedTokens.get(key)?.let { tokens -> tokens.add(data.token) } + keyedTokens.get(key)?.let { tokens -> tokens.add(TokenId(data.token)) } ?: run { - val tokens = mutableSetOf(data.token) + val tokens = mutableSetOf(TokenId(data.token)) keyedTokens.put(key, tokens) } } @@ -125,7 +125,7 @@ constructor( isMigration || remote == null || remote.sessionToken == data.token || - !tokensWithNotifications.contains(remote.sessionToken) + !tokensWithNotifications.contains(TokenId(remote.sessionToken)) ) { // Not filtering in this case. Passing the event along to listeners. dispatchMediaDataLoaded(key, oldKey, data, immediately) @@ -136,7 +136,7 @@ constructor( // If the local session uses a different notification key, then lets go a step // farther and dismiss the media data so that media controls for the local session // don't hang around while casting. - if (!keyedTokens.get(key)!!.contains(remote.sessionToken)) { + if (!keyedTokens.get(key)!!.contains(TokenId(remote.sessionToken))) { dispatchMediaDataRemoved(key) } } @@ -199,6 +199,15 @@ constructor( packageControllers.put(controller.packageName, tokens) } } - tokensWithNotifications.retainAll(controllers.map { it.sessionToken }) + tokensWithNotifications.retainAll(controllers.map { TokenId(it.sessionToken) }) + } + + /** + * Represents a unique identifier for a [MediaSession.Token]. + * + * It's used to avoid storing strong binders for media session tokens. + */ + private data class TokenId(val id: Int) { + constructor(token: MediaSession.Token) : this(token.hashCode()) } } |