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

Commit fc444873 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

Merge "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."
parents b0e93d73 0ed07caf
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)