OSDN Git Service

Fixed a crash with notification children
authorSelim Cinek <cinek@google.com>
Thu, 11 Feb 2016 22:47:06 +0000 (14:47 -0800)
committerSelim Cinek <cinek@google.com>
Thu, 11 Feb 2016 22:47:06 +0000 (14:47 -0800)
When moving children between parents, Sysui could crash
because it wasn't removed yet properly from the old parent.
We are now doing this sequencially, i.e first removing the
children and then adding the new ones.

Bug: 27137301
Change-Id: I1925662a9d7f224f133827d524d080994753ba25

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

index 14376ac..7d14e98 100644 (file)
@@ -1500,8 +1500,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
     }
 
     private void updateNotificationShadeForChildren() {
+        // First let's remove all children which don't belong in the parents
         ArrayList<ExpandableNotificationRow> toRemove = new ArrayList<>();
-        boolean orderChanged = false;
         for (int i = 0; i < mStackScroller.getChildCount(); i++) {
             View view = mStackScroller.getChildAt(i);
             if (!(view instanceof ExpandableNotificationRow)) {
@@ -1513,7 +1513,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
             List<ExpandableNotificationRow> children = parent.getNotificationChildren();
             List<ExpandableNotificationRow> orderedChildren = mTmpChildOrderMap.get(parent);
 
-            // lets first remove all undesired children
             if (children != null) {
                 toRemove.clear();
                 for (ExpandableNotificationRow childRow : children) {
@@ -1526,8 +1525,21 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                     mStackScroller.notifyGroupChildRemoved(remove);
                 }
             }
+        }
+
+        // Let's now add all notification children which are missing
+        boolean orderChanged = false;
+        for (int i = 0; i < mStackScroller.getChildCount(); i++) {
+            View view = mStackScroller.getChildAt(i);
+            if (!(view instanceof ExpandableNotificationRow)) {
+                // We don't care about non-notification views.
+                continue;
+            }
+
+            ExpandableNotificationRow parent = (ExpandableNotificationRow) view;
+            List<ExpandableNotificationRow> children = parent.getNotificationChildren();
+            List<ExpandableNotificationRow> orderedChildren = mTmpChildOrderMap.get(parent);
 
-            // We now add all the children which are not in there already
             for (int childIndex = 0; orderedChildren != null && childIndex < orderedChildren.size();
                     childIndex++) {
                 ExpandableNotificationRow childView = orderedChildren.get(childIndex);