diff options
| -rw-r--r-- | core/java/android/service/notification/StatusBarNotification.java | 26 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java | 11 |
2 files changed, 18 insertions, 19 deletions
diff --git a/core/java/android/service/notification/StatusBarNotification.java b/core/java/android/service/notification/StatusBarNotification.java index 43151005f673..cc74e1a329ed 100644 --- a/core/java/android/service/notification/StatusBarNotification.java +++ b/core/java/android/service/notification/StatusBarNotification.java @@ -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,24 +401,15 @@ 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_GROUP_ID, getGroupLogTag()) - .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY, - getNotification().isGroupSummary() ? 1 : 0) - .addTaggedData(MetricsProto.MetricsEvent.FIELD_NOTIFICATION_CATEGORY, - getNotification().category); + .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID, getChannelIdLogTag()) + .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID, getGroupLogTag()) + .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY, + getNotification().isGroupSummary() ? 1 : 0) + .addTaggedData(MetricsProto.MetricsEvent.FIELD_NOTIFICATION_CATEGORY, + getNotification().category); } private String getGroupLogTag() { diff --git a/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java b/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java index c99777b160f0..0f32a827377e 100644 --- a/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java +++ b/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java @@ -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) |