Fix NPE when content visibility changes
Content view inactive listeners can modify the list of listeners
indirectly by adding/removing content views, so we copy the list so that
the iteration doesn't run into any undefined bevavior.
Bug: 156636869
Test: manual, atest
Change-Id: Ie13e81a3217a698fe60db4b11b45e0336cb73b69
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
index e9849ec..9925909 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
@@ -64,6 +64,7 @@
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.util.ArrayList;
/**
* A frame layout containing the actual payload of the notification, including the contracted,
@@ -518,9 +519,12 @@
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
updateVisibility();
- if (visibility != VISIBLE) {
+ if (visibility != VISIBLE && !mOnContentViewInactiveListeners.isEmpty()) {
// View is no longer visible so all content views are inactive.
- for (Runnable r : mOnContentViewInactiveListeners.values()) {
+ // Clone list as runnables may modify the list of listeners
+ ArrayList<Runnable> listeners = new ArrayList<>(
+ mOnContentViewInactiveListeners.values());
+ for (Runnable r : listeners) {
r.run();
}
mOnContentViewInactiveListeners.clear();