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

Commit 828427ef authored by Will Brockman's avatar Will Brockman
Browse files

Add notification category information to notification logging.

Capturing the app-declared notification category:
https://developer.android.com/training/notify-user/build-notification#system-category

Adding to StatusBarNotification.getLogMaker() means that it will be
put on many categories of notification logging automatically.  No
extra data usage for notifications where the category was not
declared.

Bug: 123071368
Test: atest SystemUITests and manual test
Change-Id: I8f59fea1a8e7c98366fe888cf5a28cf252859fdf
parent 170725ab
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.Parcel;
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 @@ public class StatusBarNotification implements Parcelable {
            .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() {
+21 −3
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ public class StatusBarNotificationTest {
    @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 @@ public class StatusBarNotificationTest {
        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 @@ public class StatusBarNotificationTest {
    }

    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 @@ public class StatusBarNotificationTest {
        if (group != null) {
            builder.setGroup(group);
        }
        return builder;
    }

    private StatusBarNotification getNotification(String pkg, Notification.Builder builder) {

        Notification n = builder.build();
        return new StatusBarNotification(
                pkg, pkg, ID, TAG, UID, UID, n, USER, null, UID);
                pkg, pkg, ID, TAG, UID, UID, builder.build(), USER, null, UID);
    }

}
+6 −0
Original line number Diff line number Diff line
@@ -6904,6 +6904,12 @@ message MetricsEvent {
    // 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