Loading services/core/java/com/android/server/notification/NotificationManagerService.java +22 −10 Original line number Diff line number Diff line Loading @@ -9862,9 +9862,6 @@ public class NotificationManagerService extends SystemService { return false; } mEnqueuedNotifications.add(r); mTtlHelper.scheduleTimeoutLocked(r, SystemClock.elapsedRealtime()); final StatusBarNotification n = r.getSbn(); if (DBG) Slog.d(TAG, "EnqueueNotificationRunnable.run for: " + n.getKey()); NotificationRecord old = mNotificationsByKey.get(n.getKey()); Loading @@ -9873,6 +9870,28 @@ public class NotificationManagerService extends SystemService { r.copyRankingInformation(old); } // If we don't have a previous record, before adding this record to enqueued list, // see if we have a previously enqueued version of this notification so we can share // instance ID if necessary. NotificationRecord previouslyEnqueued = null; if (old == null) { previouslyEnqueued = findNotificationByListLocked(mEnqueuedNotifications, n.getKey()); } mEnqueuedNotifications.add(r); mTtlHelper.scheduleTimeoutLocked(r, SystemClock.elapsedRealtime()); // Either initialize instance ID for statsd logging, or carry over from old SBN. if (old != null && old.getSbn().getInstanceId() != null) { n.setInstanceId(old.getSbn().getInstanceId()); } else if (previouslyEnqueued != null && previouslyEnqueued.getSbn().getInstanceId() != null) { n.setInstanceId(previouslyEnqueued.getSbn().getInstanceId()); } else { n.setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); } final int callingUid = n.getUid(); final int callingPid = n.getInitialPid(); final Notification notification = n.getNotification(); Loading Loading @@ -10027,13 +10046,6 @@ public class NotificationManagerService extends SystemService { } NotificationRecord old = mNotificationsByKey.get(key); // Make sure the SBN has an instance ID for statsd logging. if (old == null || old.getSbn().getInstanceId() == null) { n.setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); } else { n.setInstanceId(old.getSbn().getInstanceId()); } int index = indexOfNotificationLocked(n.getKey()); if (index < 0) { mNotificationList.add(r); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +32 −0 Original line number Diff line number Diff line Loading @@ -2065,6 +2065,38 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(mNotificationRecordLogger.get(1).postDurationMillisLogged).isGreaterThan(0); } @Test public void testEnqueueNotificationWithTag_inheritsPostedInstanceId() throws Exception { final String tag = "testEnqueueNotificationWithTag_inheritsPostedInstanceId"; Notification original = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, original, mUserId); // wait for the notification to get fully posted first rather than updating while still // enqueued waitForIdle(); // then update Notification update = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon) .setCategory(Notification.CATEGORY_ALARM).build(); mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, update, mUserId); waitForIdle(); assertEquals(2, mNotificationRecordLogger.numCalls()); assertTrue(mNotificationRecordLogger.get(0).wasLogged); assertEquals(NOTIFICATION_POSTED, mNotificationRecordLogger.event(0)); assertEquals(1, mNotificationRecordLogger.get(0).getInstanceId()); assertThat(mNotificationRecordLogger.get(0).postDurationMillisLogged).isGreaterThan(0); assertTrue(mNotificationRecordLogger.get(1).wasLogged); assertEquals(NOTIFICATION_UPDATED, mNotificationRecordLogger.event(1)); // Instance ID doesn't change on update of an active notification assertEquals(1, mNotificationRecordLogger.get(1).getInstanceId()); assertThat(mNotificationRecordLogger.get(1).postDurationMillisLogged).isGreaterThan(0); } @Test public void testEnqueueNotificationWithTag_DoesNotLogOnMinorUpdate() throws Exception { final String tag = "testEnqueueNotificationWithTag_DoesNotLogOnMinorUpdate"; Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +22 −10 Original line number Diff line number Diff line Loading @@ -9862,9 +9862,6 @@ public class NotificationManagerService extends SystemService { return false; } mEnqueuedNotifications.add(r); mTtlHelper.scheduleTimeoutLocked(r, SystemClock.elapsedRealtime()); final StatusBarNotification n = r.getSbn(); if (DBG) Slog.d(TAG, "EnqueueNotificationRunnable.run for: " + n.getKey()); NotificationRecord old = mNotificationsByKey.get(n.getKey()); Loading @@ -9873,6 +9870,28 @@ public class NotificationManagerService extends SystemService { r.copyRankingInformation(old); } // If we don't have a previous record, before adding this record to enqueued list, // see if we have a previously enqueued version of this notification so we can share // instance ID if necessary. NotificationRecord previouslyEnqueued = null; if (old == null) { previouslyEnqueued = findNotificationByListLocked(mEnqueuedNotifications, n.getKey()); } mEnqueuedNotifications.add(r); mTtlHelper.scheduleTimeoutLocked(r, SystemClock.elapsedRealtime()); // Either initialize instance ID for statsd logging, or carry over from old SBN. if (old != null && old.getSbn().getInstanceId() != null) { n.setInstanceId(old.getSbn().getInstanceId()); } else if (previouslyEnqueued != null && previouslyEnqueued.getSbn().getInstanceId() != null) { n.setInstanceId(previouslyEnqueued.getSbn().getInstanceId()); } else { n.setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); } final int callingUid = n.getUid(); final int callingPid = n.getInitialPid(); final Notification notification = n.getNotification(); Loading Loading @@ -10027,13 +10046,6 @@ public class NotificationManagerService extends SystemService { } NotificationRecord old = mNotificationsByKey.get(key); // Make sure the SBN has an instance ID for statsd logging. if (old == null || old.getSbn().getInstanceId() == null) { n.setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); } else { n.setInstanceId(old.getSbn().getInstanceId()); } int index = indexOfNotificationLocked(n.getKey()); if (index < 0) { mNotificationList.add(r); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +32 −0 Original line number Diff line number Diff line Loading @@ -2065,6 +2065,38 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(mNotificationRecordLogger.get(1).postDurationMillisLogged).isGreaterThan(0); } @Test public void testEnqueueNotificationWithTag_inheritsPostedInstanceId() throws Exception { final String tag = "testEnqueueNotificationWithTag_inheritsPostedInstanceId"; Notification original = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, original, mUserId); // wait for the notification to get fully posted first rather than updating while still // enqueued waitForIdle(); // then update Notification update = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon) .setCategory(Notification.CATEGORY_ALARM).build(); mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, update, mUserId); waitForIdle(); assertEquals(2, mNotificationRecordLogger.numCalls()); assertTrue(mNotificationRecordLogger.get(0).wasLogged); assertEquals(NOTIFICATION_POSTED, mNotificationRecordLogger.event(0)); assertEquals(1, mNotificationRecordLogger.get(0).getInstanceId()); assertThat(mNotificationRecordLogger.get(0).postDurationMillisLogged).isGreaterThan(0); assertTrue(mNotificationRecordLogger.get(1).wasLogged); assertEquals(NOTIFICATION_UPDATED, mNotificationRecordLogger.event(1)); // Instance ID doesn't change on update of an active notification assertEquals(1, mNotificationRecordLogger.get(1).getInstanceId()); assertThat(mNotificationRecordLogger.get(1).postDurationMillisLogged).isGreaterThan(0); } @Test public void testEnqueueNotificationWithTag_DoesNotLogOnMinorUpdate() throws Exception { final String tag = "testEnqueueNotificationWithTag_DoesNotLogOnMinorUpdate"; Loading