Merge "Add notification category information to notification logging."
diff --git a/core/java/android/service/notification/StatusBarNotification.java b/core/java/android/service/notification/StatusBarNotification.java
index 3a644d4..551bb8a 100644
--- a/core/java/android/service/notification/StatusBarNotification.java
+++ b/core/java/android/service/notification/StatusBarNotification.java
@@ -28,6 +28,7 @@
import android.os.Parcelable;
import android.os.UserHandle;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
/**
@@ -410,7 +411,9 @@
.clearSubtype()
.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID, getGroupLogTag())
.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY,
- getNotification().isGroupSummary() ? 1 : 0);
+ 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 4aa1000..c99777b 100644
--- a/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java
+++ b/core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java
@@ -77,7 +77,6 @@
@Test
public void testLogMaker() {
final LogMaker logMaker = getNotification(PKG, GROUP_ID_1, CHANNEL_ID).getLogMaker();
-
assertEquals(CHANNEL_ID,
(String) logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID));
assertEquals(PKG, logMaker.getPackageName());
@@ -85,6 +84,18 @@
assertEquals(TAG, logMaker.getTaggedData(MetricsEvent.NOTIFICATION_TAG));
assertEquals(GROUP_ID_1,
logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID));
+ assertEquals(0,
+ logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY));
+ assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CATEGORY));
+ }
+
+ @Test
+ public void testLogMakerWithCategory() {
+ Notification.Builder builder = getNotificationBuilder(GROUP_ID_1, CHANNEL_ID)
+ .setCategory(Notification.CATEGORY_MESSAGE);
+ final LogMaker logMaker = getNotification(PKG, builder).getLogMaker();
+ assertEquals(Notification.CATEGORY_MESSAGE,
+ logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CATEGORY));
}
@Test
@@ -138,6 +149,10 @@
}
private StatusBarNotification getNotification(String pkg, String group, String channelId) {
+ return getNotification(pkg, getNotificationBuilder(group, channelId));
+ }
+
+ private Notification.Builder getNotificationBuilder(String group, String channelId) {
final Notification.Builder builder = new Notification.Builder(mMockContext, channelId)
.setContentTitle("foo")
.setSmallIcon(android.R.drawable.sym_def_app_icon);
@@ -145,10 +160,13 @@
if (group != null) {
builder.setGroup(group);
}
+ return builder;
+ }
- Notification n = builder.build();
+ private StatusBarNotification getNotification(String pkg, Notification.Builder builder) {
+
return new StatusBarNotification(
- pkg, pkg, ID, TAG, UID, UID, n, USER, null, UID);
+ pkg, pkg, ID, TAG, UID, UID, builder.build(), USER, null, UID);
}
}
diff --git a/proto/src/metrics_constants/metrics_constants.proto b/proto/src/metrics_constants/metrics_constants.proto
index 73fcb01..43e9435 100644
--- a/proto/src/metrics_constants/metrics_constants.proto
+++ b/proto/src/metrics_constants/metrics_constants.proto
@@ -6904,6 +6904,12 @@
// OS: Q
FIELD_TEXT_CLASSIFIER_WIDGET_VERSION = 1640;
+ // Tagged data for NOTIFICATION_ITEM. One of the CATEGORY String constants from
+ // https://developer.android.com/reference/android/app/Notification .
+ // OS: Q
+ // CATEGORY: NOTIFICATION
+ FIELD_NOTIFICATION_CATEGORY = 1641;
+
// ---- End Q Constants, all Q constants go above this line ----
// Add new aosp constants above this line.
// END OF AOSP CONSTANTS