Fix CME crashes

Create a copy of the listeners list before iterating over it, and add an
assert for notification entry updates
Those should only happen on the main thread, so adding the assert will allow us
to find if that is not happening somewhere in the notification pipeline.

Fixes: 156863310
Test: manual
Change-Id: I157dafdba0c1cecb26dd7e969f3be26ca4e45472
This commit is contained in:
Beth Thibodeau
2020-05-26 19:57:42 -04:00
parent 8032fd3d0c
commit 8a2af3b3bd

View File

@@ -36,6 +36,7 @@ import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.statusbar.notification.MediaNotificationProcessor
import com.android.systemui.statusbar.notification.row.HybridGroupManager
import com.android.systemui.util.Assert
import com.android.systemui.util.Utils
import java.io.IOException
import java.util.concurrent.Executor
@@ -85,6 +86,7 @@ class MediaDataManager @Inject constructor(
fun onNotificationAdded(key: String, sbn: StatusBarNotification) {
if (Utils.useQsMediaPlayer(context) && isMediaNotification(sbn)) {
Assert.isMainThread()
if (!mediaEntries.containsKey(key)) {
mediaEntries.put(key, LOADING)
}
@@ -269,19 +271,23 @@ class MediaDataManager @Inject constructor(
}
fun onMediaDataLoaded(key: String, data: MediaData) {
Assert.isMainThread()
if (mediaEntries.containsKey(key)) {
// Otherwise this was removed already
mediaEntries.put(key, data)
listeners.forEach {
val listenersCopy = listeners.toSet()
listenersCopy.forEach {
it.onMediaDataLoaded(key, data)
}
}
}
fun onNotificationRemoved(key: String) {
Assert.isMainThread()
val removed = mediaEntries.remove(key)
if (removed != null) {
listeners.forEach {
val listenersCopy = listeners.toSet()
listenersCopy.forEach {
it.onMediaDataRemoved(key)
}
}