Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2137b07c authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "Initialize instance_id at enqueue rather than post." into main

parents 8f4ef4a7 d076cd7b
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -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());
@@ -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();
@@ -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);
+32 −0
Original line number Diff line number Diff line
@@ -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";