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

Commit d076cd7b authored by Yuri Lin's avatar Yuri Lin
Browse files

Initialize instance_id at enqueue rather than post.

Because assistant adjustments were potentially happening at enqueue time but we weren't instantiating instance IDs until postNotification, all of the notification classification atoms were getting logged with instance ID 0.

Fixes: 417536505
Test: atom tester, NotificationManagerServiceTest
Flag: EXEMPT bugfix
Change-Id: I75f8c635d01eea4fe39764592478d525c30cad3c
parent 9cc5bfd8
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -9859,9 +9859,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());
@@ -9870,6 +9867,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();
@@ -10024,13 +10043,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";