Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +34 −24 Original line number Original line Diff line number Diff line Loading @@ -151,6 +151,16 @@ public class NotificationEntryManager implements @Override @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("NotificationEntryManager state:"); pw.println("NotificationEntryManager state:"); pw.println(" mAllNotifications="); if (mAllNotifications.size() == 0) { pw.println("null"); } else { int i = 0; for (NotificationEntry entry : mAllNotifications) { dumpEntry(pw, " ", i, entry); i++; } } pw.print(" mPendingNotifications="); pw.print(" mPendingNotifications="); if (mPendingNotifications.size() == 0) { if (mPendingNotifications.size() == 0) { pw.println("null"); pw.println("null"); Loading Loading @@ -350,8 +360,8 @@ public class NotificationEntryManager implements private final NotificationHandler mNotifListener = new NotificationHandler() { private final NotificationHandler mNotifListener = new NotificationHandler() { @Override @Override public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { final boolean isUpdate = mActiveNotifications.containsKey(sbn.getKey()); final boolean isUpdateToInflatedNotif = mActiveNotifications.containsKey(sbn.getKey()); if (isUpdate) { if (isUpdateToInflatedNotif) { updateNotification(sbn, rankingMap); updateNotification(sbn, rankingMap); } else { } else { addNotification(sbn, rankingMap); addNotification(sbn, rankingMap); Loading Loading @@ -442,16 +452,12 @@ public class NotificationEntryManager implements } } if (!lifetimeExtended) { if (!lifetimeExtended) { // At this point, we are guaranteed the notification will be removed // At this point, we are guaranteed the notification will be removed abortExistingInflation(key, "removeNotification"); mAllNotifications.remove(pendingEntry); mAllNotifications.remove(pendingEntry); mLeakDetector.trackGarbage(pendingEntry); } } } } } } else { if (!lifetimeExtended) { abortExistingInflation(key, "removeNotification"); } if (entry != null) { // If a manager needs to keep the notification around for whatever reason, we // If a manager needs to keep the notification around for whatever reason, we // keep the notification // keep the notification boolean entryDismissed = entry.isRowDismissed(); boolean entryDismissed = entry.isRowDismissed(); Loading @@ -469,6 +475,8 @@ public class NotificationEntryManager implements if (!lifetimeExtended) { if (!lifetimeExtended) { // At this point, we are guaranteed the notification will be removed // At this point, we are guaranteed the notification will be removed abortExistingInflation(key, "removeNotification"); mAllNotifications.remove(entry); // Ensure any managers keeping the lifetime extended stop managing the entry // Ensure any managers keeping the lifetime extended stop managing the entry cancelLifetimeExtension(entry); cancelLifetimeExtension(entry); Loading @@ -477,13 +485,10 @@ public class NotificationEntryManager implements entry.removeRow(); entry.removeRow(); } } mAllNotifications.remove(entry); // Let's remove the children if this was a summary // Let's remove the children if this was a summary handleGroupSummaryRemoved(key); handleGroupSummaryRemoved(key); removeVisibleNotification(key); removeVisibleNotification(key); updateNotifications("removeNotificationInternal"); updateNotifications("removeNotificationInternal"); mLeakDetector.trackGarbage(entry); removedByUser |= entryDismissed; removedByUser |= entryDismissed; mLogger.logNotifRemoved(entry.getKey(), removedByUser); mLogger.logNotifRemoved(entry.getKey(), removedByUser); Loading @@ -497,6 +502,7 @@ public class NotificationEntryManager implements for (NotifCollectionListener listener : mNotifCollectionListeners) { for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryCleanUp(entry); listener.onEntryCleanUp(entry); } } mLeakDetector.trackGarbage(entry); } } } } } } Loading Loading @@ -556,21 +562,26 @@ public class NotificationEntryManager implements Ranking ranking = new Ranking(); Ranking ranking = new Ranking(); rankingMap.getRanking(key, ranking); rankingMap.getRanking(key, ranking); NotificationEntry entry = new NotificationEntry( NotificationEntry entry = mPendingNotifications.get(key); if (entry != null) { entry.setSbn(notification); } else { entry = new NotificationEntry( notification, notification, ranking, ranking, mFgsFeatureController.isForegroundServiceDismissalEnabled(), mFgsFeatureController.isForegroundServiceDismissalEnabled(), SystemClock.uptimeMillis()); SystemClock.uptimeMillis()); for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryBind(entry, notification); } mAllNotifications.add(entry); mAllNotifications.add(entry); mLeakDetector.trackInstance(entry); mLeakDetector.trackInstance(entry); for (NotifCollectionListener listener : mNotifCollectionListeners) { for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryInit(entry); listener.onEntryInit(entry); } } } for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryBind(entry, notification); } // Construct the expanded view. // Construct the expanded view. if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { Loading @@ -581,7 +592,6 @@ public class NotificationEntryManager implements mInflationCallback); mInflationCallback); } } abortExistingInflation(key, "addNotification"); mPendingNotifications.put(key, entry); mPendingNotifications.put(key, entry); mLogger.logNotifAdded(entry.getKey()); mLogger.logNotifAdded(entry.getKey()); for (NotificationEntryListener listener : mNotificationEntryListeners) { for (NotificationEntryListener listener : mNotificationEntryListeners) { Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -390,11 +390,11 @@ public class NotifCollection implements Dumpable { if (entry == null) { if (entry == null) { // A new notification! // A new notification! entry = new NotificationEntry(sbn, ranking, SystemClock.uptimeMillis()); entry = new NotificationEntry(sbn, ranking, SystemClock.uptimeMillis()); mEventQueue.add(new InitEntryEvent(entry)); mEventQueue.add(new BindEntryEvent(entry, sbn)); mEventQueue.add(new BindEntryEvent(entry, sbn)); mNotificationSet.put(sbn.getKey(), entry); mNotificationSet.put(sbn.getKey(), entry); mLogger.logNotifPosted(sbn.getKey()); mLogger.logNotifPosted(sbn.getKey()); mEventQueue.add(new InitEntryEvent(entry)); mEventQueue.add(new EntryAddedEvent(entry)); mEventQueue.add(new EntryAddedEvent(entry)); } else { } else { Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java +22 −0 Original line number Original line Diff line number Diff line Loading @@ -209,6 +209,28 @@ public class NotificationEntryManagerTest extends SysuiTestCase { setUserSentiment(mSbn.getKey(), Ranking.USER_SENTIMENT_NEUTRAL); setUserSentiment(mSbn.getKey(), Ranking.USER_SENTIMENT_NEUTRAL); } } @Test public void testAddNotification_noDuplicateEntriesCreated() { // GIVEN a notification has been added mEntryManager.addNotification(mSbn, mRankingMap); // WHEN the same notification is added multiple times before the previous entry (with // the same key) didn't finish inflating mEntryManager.addNotification(mSbn, mRankingMap); mEntryManager.addNotification(mSbn, mRankingMap); mEntryManager.addNotification(mSbn, mRankingMap); // THEN getAllNotifs() only contains exactly one notification with this key int count = 0; for (NotificationEntry entry : mEntryManager.getAllNotifs()) { if (entry.getKey().equals(mSbn.getKey())) { count++; } } assertEquals("Should only be one entry with key=" + mSbn.getKey() + " in mAllNotifs. " + "Instead there are " + count, 1, count); } @Test @Test public void testAddNotification_setsUserSentiment() { public void testAddNotification_setsUserSentiment() { mEntryManager.addNotification(mSbn, mRankingMap); mEntryManager.addNotification(mSbn, mRankingMap); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +34 −24 Original line number Original line Diff line number Diff line Loading @@ -151,6 +151,16 @@ public class NotificationEntryManager implements @Override @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("NotificationEntryManager state:"); pw.println("NotificationEntryManager state:"); pw.println(" mAllNotifications="); if (mAllNotifications.size() == 0) { pw.println("null"); } else { int i = 0; for (NotificationEntry entry : mAllNotifications) { dumpEntry(pw, " ", i, entry); i++; } } pw.print(" mPendingNotifications="); pw.print(" mPendingNotifications="); if (mPendingNotifications.size() == 0) { if (mPendingNotifications.size() == 0) { pw.println("null"); pw.println("null"); Loading Loading @@ -350,8 +360,8 @@ public class NotificationEntryManager implements private final NotificationHandler mNotifListener = new NotificationHandler() { private final NotificationHandler mNotifListener = new NotificationHandler() { @Override @Override public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { final boolean isUpdate = mActiveNotifications.containsKey(sbn.getKey()); final boolean isUpdateToInflatedNotif = mActiveNotifications.containsKey(sbn.getKey()); if (isUpdate) { if (isUpdateToInflatedNotif) { updateNotification(sbn, rankingMap); updateNotification(sbn, rankingMap); } else { } else { addNotification(sbn, rankingMap); addNotification(sbn, rankingMap); Loading Loading @@ -442,16 +452,12 @@ public class NotificationEntryManager implements } } if (!lifetimeExtended) { if (!lifetimeExtended) { // At this point, we are guaranteed the notification will be removed // At this point, we are guaranteed the notification will be removed abortExistingInflation(key, "removeNotification"); mAllNotifications.remove(pendingEntry); mAllNotifications.remove(pendingEntry); mLeakDetector.trackGarbage(pendingEntry); } } } } } } else { if (!lifetimeExtended) { abortExistingInflation(key, "removeNotification"); } if (entry != null) { // If a manager needs to keep the notification around for whatever reason, we // If a manager needs to keep the notification around for whatever reason, we // keep the notification // keep the notification boolean entryDismissed = entry.isRowDismissed(); boolean entryDismissed = entry.isRowDismissed(); Loading @@ -469,6 +475,8 @@ public class NotificationEntryManager implements if (!lifetimeExtended) { if (!lifetimeExtended) { // At this point, we are guaranteed the notification will be removed // At this point, we are guaranteed the notification will be removed abortExistingInflation(key, "removeNotification"); mAllNotifications.remove(entry); // Ensure any managers keeping the lifetime extended stop managing the entry // Ensure any managers keeping the lifetime extended stop managing the entry cancelLifetimeExtension(entry); cancelLifetimeExtension(entry); Loading @@ -477,13 +485,10 @@ public class NotificationEntryManager implements entry.removeRow(); entry.removeRow(); } } mAllNotifications.remove(entry); // Let's remove the children if this was a summary // Let's remove the children if this was a summary handleGroupSummaryRemoved(key); handleGroupSummaryRemoved(key); removeVisibleNotification(key); removeVisibleNotification(key); updateNotifications("removeNotificationInternal"); updateNotifications("removeNotificationInternal"); mLeakDetector.trackGarbage(entry); removedByUser |= entryDismissed; removedByUser |= entryDismissed; mLogger.logNotifRemoved(entry.getKey(), removedByUser); mLogger.logNotifRemoved(entry.getKey(), removedByUser); Loading @@ -497,6 +502,7 @@ public class NotificationEntryManager implements for (NotifCollectionListener listener : mNotifCollectionListeners) { for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryCleanUp(entry); listener.onEntryCleanUp(entry); } } mLeakDetector.trackGarbage(entry); } } } } } } Loading Loading @@ -556,21 +562,26 @@ public class NotificationEntryManager implements Ranking ranking = new Ranking(); Ranking ranking = new Ranking(); rankingMap.getRanking(key, ranking); rankingMap.getRanking(key, ranking); NotificationEntry entry = new NotificationEntry( NotificationEntry entry = mPendingNotifications.get(key); if (entry != null) { entry.setSbn(notification); } else { entry = new NotificationEntry( notification, notification, ranking, ranking, mFgsFeatureController.isForegroundServiceDismissalEnabled(), mFgsFeatureController.isForegroundServiceDismissalEnabled(), SystemClock.uptimeMillis()); SystemClock.uptimeMillis()); for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryBind(entry, notification); } mAllNotifications.add(entry); mAllNotifications.add(entry); mLeakDetector.trackInstance(entry); mLeakDetector.trackInstance(entry); for (NotifCollectionListener listener : mNotifCollectionListeners) { for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryInit(entry); listener.onEntryInit(entry); } } } for (NotifCollectionListener listener : mNotifCollectionListeners) { listener.onEntryBind(entry, notification); } // Construct the expanded view. // Construct the expanded view. if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { Loading @@ -581,7 +592,6 @@ public class NotificationEntryManager implements mInflationCallback); mInflationCallback); } } abortExistingInflation(key, "addNotification"); mPendingNotifications.put(key, entry); mPendingNotifications.put(key, entry); mLogger.logNotifAdded(entry.getKey()); mLogger.logNotifAdded(entry.getKey()); for (NotificationEntryListener listener : mNotificationEntryListeners) { for (NotificationEntryListener listener : mNotificationEntryListeners) { Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -390,11 +390,11 @@ public class NotifCollection implements Dumpable { if (entry == null) { if (entry == null) { // A new notification! // A new notification! entry = new NotificationEntry(sbn, ranking, SystemClock.uptimeMillis()); entry = new NotificationEntry(sbn, ranking, SystemClock.uptimeMillis()); mEventQueue.add(new InitEntryEvent(entry)); mEventQueue.add(new BindEntryEvent(entry, sbn)); mEventQueue.add(new BindEntryEvent(entry, sbn)); mNotificationSet.put(sbn.getKey(), entry); mNotificationSet.put(sbn.getKey(), entry); mLogger.logNotifPosted(sbn.getKey()); mLogger.logNotifPosted(sbn.getKey()); mEventQueue.add(new InitEntryEvent(entry)); mEventQueue.add(new EntryAddedEvent(entry)); mEventQueue.add(new EntryAddedEvent(entry)); } else { } else { Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java +22 −0 Original line number Original line Diff line number Diff line Loading @@ -209,6 +209,28 @@ public class NotificationEntryManagerTest extends SysuiTestCase { setUserSentiment(mSbn.getKey(), Ranking.USER_SENTIMENT_NEUTRAL); setUserSentiment(mSbn.getKey(), Ranking.USER_SENTIMENT_NEUTRAL); } } @Test public void testAddNotification_noDuplicateEntriesCreated() { // GIVEN a notification has been added mEntryManager.addNotification(mSbn, mRankingMap); // WHEN the same notification is added multiple times before the previous entry (with // the same key) didn't finish inflating mEntryManager.addNotification(mSbn, mRankingMap); mEntryManager.addNotification(mSbn, mRankingMap); mEntryManager.addNotification(mSbn, mRankingMap); // THEN getAllNotifs() only contains exactly one notification with this key int count = 0; for (NotificationEntry entry : mEntryManager.getAllNotifs()) { if (entry.getKey().equals(mSbn.getKey())) { count++; } } assertEquals("Should only be one entry with key=" + mSbn.getKey() + " in mAllNotifs. " + "Instead there are " + count, 1, count); } @Test @Test public void testAddNotification_setsUserSentiment() { public void testAddNotification_setsUserSentiment() { mEntryManager.addNotification(mSbn, mRankingMap); mEntryManager.addNotification(mSbn, mRankingMap); Loading