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

Commit 0ed07caf authored by Will Brockman's avatar Will Brockman
Browse files

To avoid stale data in logs, and avoid risk of race conditions, have

StatusBarNotification create a new LogMaker each time it is requested,
instead of trying to keep and reuse one.

Bug: 124924850
Test: atest frameworks/base/services/tests/uiservicestests/src/com/android/server/notification frameworks/base/core/tests/coretests/src/android/service/notification SystemUITests

Change-Id: I0fe3c17b5c9534fd486575b6a3c20fdd43cc28f5
parent 49c1069c
Loading
Loading
Loading
Loading
+7 −19
Original line number Diff line number Diff line
@@ -63,9 +63,6 @@ public class StatusBarNotification implements Parcelable {

    private Context mContext; // used for inflation & icon expansion

    // Contains the basic logging data of the notification.
    private LogMaker mLogMaker;

    /** @hide */
    public StatusBarNotification(String pkg, String opPkg, int id,
            String tag, int uid, int initialPid, Notification notification, UserHandle user,
@@ -404,19 +401,10 @@ public class StatusBarNotification implements Parcelable {
     * @hide
     */
    public LogMaker getLogMaker() {
        if (mLogMaker == null) {
            // Initialize fields that only change on update (so a new record).
            mLogMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN)
                .setPackageName(getPackageName())
        return new LogMaker(MetricsEvent.VIEW_UNKNOWN).setPackageName(getPackageName())
                .addTaggedData(MetricsEvent.NOTIFICATION_ID, getId())
                .addTaggedData(MetricsEvent.NOTIFICATION_TAG, getTag())
                .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID, getChannelIdLogTag());
        }
        // Reset fields that can change between updates, or are used by multiple logs.
        return mLogMaker
            .clearCategory()
            .clearType()
            .clearSubtype()
                .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID, getChannelIdLogTag())
                .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID, getGroupLogTag())
                .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY,
                        getNotification().isGroupSummary() ? 1 : 0)
+11 −0
Original line number Diff line number Diff line
@@ -89,6 +89,17 @@ public class StatusBarNotificationTest {
        assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CATEGORY));
    }

    /** Verify that modifying the returned logMaker won't leave stale data behind for
     * the next caller.*/
    @Test
    public void testLogMakerNoStaleData() {
        StatusBarNotification sbn = getNotification(PKG, GROUP_ID_1, CHANNEL_ID);
        final LogMaker logMaker = sbn.getLogMaker();
        int extraTag = MetricsEvent.FIELD_NOTIFICATION_CHANNEL_GROUP_ID;  // An arbitrary new tag
        logMaker.addTaggedData(extraTag, 1);
        assertNull(sbn.getLogMaker().getTaggedData(extraTag));
    }

    @Test
    public void testLogMakerWithCategory() {
        Notification.Builder builder = getNotificationBuilder(GROUP_ID_1, CHANNEL_ID)