Centralize reorder-on-priority-change logic
The visual stability manager has a special exception that allows notifs
to be reordered if their priority changes. Previously, this was tracked
by various members and method spread across a lot of classes: it
was set in one place, read in another, and cleared out in a third. This
CL attemps to centralize this logic as much as possible to be just
contained in the VisualStabilityManager.
Test: atest, manual
Change-Id: I19e047711ef1f8bcb083bdd62f45f2fe68109cc4
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java
index 839b06c..1ed671f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java
@@ -47,7 +47,11 @@
}
/**
- * Called when a notification is updated, before any filtering of notifications have occurred.
+ * Called when a notification is about to be updated. Notification- and ranking-derived fields
+ * on the entry have already been updated but the following have not yet occurred:
+ * (a) View binding (i.e. the associated view has not yet been updated / inflation has not yet
+ * been kicked off.
+ * (b) Notification filtering
*/
default void onPreEntryUpdated(NotificationEntry entry) {
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
index 81d0e25..f24ce6a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
@@ -230,7 +230,6 @@
}
}
}
- entry.setLowPriorityStateUpdated(false);
}
@Override
@@ -384,13 +383,12 @@
mNotificationData.update(entry, ranking, notification);
- getRowBinder().inflateViews(entry, () -> performRemoveNotification(notification),
- mNotificationData.get(entry.key) != null);
-
for (NotificationEntryListener listener : mNotificationEntryListeners) {
listener.onPreEntryUpdated(entry);
}
+ getRowBinder().inflateViews(entry, () -> performRemoveNotification(notification),
+ mNotificationData.get(entry.key) != null);
updateNotifications();
if (DEBUG) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
index 0b8596f..80a7197 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
@@ -226,10 +226,7 @@
StatusBarNotification sbn,
ExpandableNotificationRow row,
boolean isUpdate) {
- boolean isLowPriority = entry.ambient;
- boolean wasLowPriority = row.isLowPriority();
- row.setIsLowPriority(isLowPriority);
- row.setLowPriorityStateUpdated(isUpdate && (wasLowPriority != isLowPriority));
+ row.setIsLowPriority(entry.ambient);
// bind the click event to the content area
checkNotNull(mNotificationClicker).register(row, sbn);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java
index c886685..396a3a7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java
@@ -45,7 +45,7 @@
private boolean mReorderingAllowed;
private VisibilityLocationProvider mVisibilityLocationProvider;
private ArraySet<View> mAllowedReorderViews = new ArraySet<>();
- private ArraySet<View> mLowPriorityReorderingViews = new ArraySet<>();
+ private ArraySet<NotificationEntry> mLowPriorityReorderingViews = new ArraySet<>();
private ArraySet<View> mAddedChildren = new ArraySet<>();
private boolean mPulsing;
@@ -53,14 +53,21 @@
public VisualStabilityManager(NotificationEntryManager notificationEntryManager) {
notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
@Override
- public void onEntryReinflated(NotificationEntry entry) {
- if (entry.hasLowPriorityStateUpdated()) {
- onLowPriorityUpdated(entry);
- if (mPresenter != null) {
- mPresenter.updateNotificationViews();
- }
+ public void onPreEntryUpdated(NotificationEntry entry) {
+ final boolean mAmbientStateHasChanged =
+ entry.ambient != entry.getRow().isLowPriority();
+ if (mAmbientStateHasChanged) {
+ mLowPriorityReorderingViews.add(entry);
}
}
+
+ @Override
+ public void onPostEntryUpdated(NotificationEntry entry) {
+ // This line is technically not required as we'll get called as the hierarchy
+ // manager will call onReorderingFinished() immediately before this.
+ // TODO: Find a way to make this relationship more explicit
+ mLowPriorityReorderingViews.remove(entry);
+ }
});
}
@@ -142,7 +149,7 @@
if (mAddedChildren.contains(row)) {
return true;
}
- if (mLowPriorityReorderingViews.contains(row)) {
+ if (mLowPriorityReorderingViews.contains(row.getEntry())) {
return true;
}
if (mAllowedReorderViews.contains(row)
@@ -172,10 +179,6 @@
}
}
- private void onLowPriorityUpdated(NotificationEntry entry) {
- mLowPriorityReorderingViews.add(entry.getRow());
- }
-
/**
* Notify the visual stability manager that a new view was added and should be allowed to
* reorder next time.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
index f74de5b..f6d4ce22 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
@@ -622,10 +622,6 @@
return null;
}
- public boolean hasLowPriorityStateUpdated() {
- return row != null && row.hasLowPriorityStateUpdated();
- }
-
public void removeRow() {
if (row != null) row.setRemoved();
}
@@ -650,10 +646,6 @@
return parent == null;
}
- public void setLowPriorityStateUpdated(boolean updated) {
- if (row != null) row.setLowPriorityStateUpdated(updated);
- }
-
/**
* @return Can the underlying notification be cleared? This can be different from whether the
* notification can be dismissed in case notifications are sensitive on the lockscreen.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index b8e33a8..1bf2885 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -133,7 +133,6 @@
}
private LayoutListener mLayoutListener;
- private boolean mLowPriorityStateUpdated;
private final NotificationInflater mNotificationInflater;
private int mIconTransformContentShift;
private int mIconTransformContentShiftNoIcon;
@@ -1577,15 +1576,6 @@
}
}
-
- public void setLowPriorityStateUpdated(boolean lowPriorityStateUpdated) {
- mLowPriorityStateUpdated = lowPriorityStateUpdated;
- }
-
- public boolean hasLowPriorityStateUpdated() {
- return mLowPriorityStateUpdated;
- }
-
public boolean isLowPriority() {
return mIsLowPriority;
}