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

Commit 9918db93 authored by Will Brockman's avatar Will Brockman
Browse files

Statsd log remaining notification events.

This CL maps the remaining Tron logging in NotificationManagerService
that I think should be ported to statsd.

Also refactors NotificationRecordLogger slightly to improve testing.

Bug: 146488473
Test: atest NotificationManagerServiceTest
Test: statsd_testdrive 90
Test: adb shell cmd stats print-logs && adb logcat -s statsd:I | grep ' (90)'
Change-Id: I826cd5669fcca10b88e324616b9d3c16afac00eb
parent c9611acb
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -926,6 +926,8 @@ public class NotificationManagerService extends SystemService {
                        .setType(MetricsEvent.TYPE_ACTION)
                        .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_INDEX, nv.rank)
                        .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_COUNT, nv.count));
                mNotificationRecordLogger.log(
                        NotificationRecordLogger.NotificationEvent.NOTIFICATION_CLICKED, r);
                EventLogTags.writeNotificationClicked(key,
                        r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now),
                        nv.rank, nv.count);
@@ -965,7 +967,8 @@ public class NotificationManagerService extends SystemService {
                                generatedByAssistant ? 1 : 0)
                        .addTaggedData(MetricsEvent.NOTIFICATION_LOCATION,
                                nv.location.toMetricsEventEnum()));

                mNotificationRecordLogger.log(
                        NotificationRecordLogger.NotificationEvent.NOTIFICATION_ACTION_CLICKED, r);
                EventLogTags.writeNotificationActionClicked(key, actionIndex,
                        r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now),
                        nv.rank, nv.count);
@@ -999,6 +1002,8 @@ public class NotificationManagerService extends SystemService {
        public void onPanelRevealed(boolean clearEffects, int items) {
            MetricsLogger.visible(getContext(), MetricsEvent.NOTIFICATION_PANEL);
            MetricsLogger.histogram(getContext(), "note_load", items);
            mNotificationRecordLogger.log(
                    NotificationRecordLogger.NotificationPanelEvent.NOTIFICATION_PANEL_OPEN);
            EventLogTags.writeNotificationPanelRevealed(items);
            if (clearEffects) {
                clearEffects();
@@ -1009,6 +1014,8 @@ public class NotificationManagerService extends SystemService {
        @Override
        public void onPanelHidden() {
            MetricsLogger.hidden(getContext(), MetricsEvent.NOTIFICATION_PANEL);
            mNotificationRecordLogger.log(
                    NotificationRecordLogger.NotificationPanelEvent.NOTIFICATION_PANEL_CLOSE);
            EventLogTags.writeNotificationPanelHidden();
            mAssistants.onPanelHidden();
        }
@@ -1098,6 +1105,10 @@ public class NotificationManagerService extends SystemService {
                        MetricsLogger.action(r.getItemLogMaker()
                                .setType(expanded ? MetricsEvent.TYPE_DETAIL
                                        : MetricsEvent.TYPE_COLLAPSE));
                        mNotificationRecordLogger.log(
                                NotificationRecordLogger.NotificationEvent.fromExpanded(expanded,
                                        userAction),
                                r);
                    }
                    if (expanded && userAction) {
                        r.recordExpanded();
@@ -1119,6 +1130,9 @@ public class NotificationManagerService extends SystemService {
                    mMetricsLogger.write(r.getLogMaker()
                            .setCategory(MetricsEvent.NOTIFICATION_DIRECT_REPLY_ACTION)
                            .setType(MetricsEvent.TYPE_ACTION));
                    mNotificationRecordLogger.log(
                            NotificationRecordLogger.NotificationEvent.NOTIFICATION_DIRECT_REPLIED,
                            r);
                    reportUserInteraction(r);
                    mAssistants.notifyAssistantNotificationDirectReplyLocked(r.getSbn());
                }
@@ -1161,6 +1175,9 @@ public class NotificationManagerService extends SystemService {
                                    MetricsEvent.NOTIFICATION_SMART_REPLY_MODIFIED_BEFORE_SENDING,
                                    modifiedBeforeSending ? 1 : 0);
                    mMetricsLogger.write(logMaker);
                    mNotificationRecordLogger.log(
                            NotificationRecordLogger.NotificationEvent.NOTIFICATION_SMART_REPLIED,
                            r);
                    // Treat clicking on a smart reply as a user interaction.
                    reportUserInteraction(r);
                    mAssistants.notifyAssistantSuggestedReplySent(
@@ -1305,6 +1322,9 @@ public class NotificationManagerService extends SystemService {
                            MetricsEvent.NOTIFICATION_SMART_REPLY_EDIT_BEFORE_SENDING,
                            r.getEditChoicesBeforeSending() ? 1 : 0);
            mMetricsLogger.write(logMaker);
            mNotificationRecordLogger.log(
                    NotificationRecordLogger.NotificationEvent.NOTIFICATION_SMART_REPLY_VISIBLE,
                    r);
        }
    }

@@ -6143,6 +6163,9 @@ public class NotificationManagerService extends SystemService {
                MetricsLogger.action(r.getLogMaker()
                        .setType(MetricsProto.MetricsEvent.TYPE_UPDATE)
                        .setCategory(MetricsProto.MetricsEvent.NOTIFICATION_SNOOZED));
                mNotificationRecordLogger.log(
                        NotificationRecordLogger.NotificationEvent.NOTIFICATION_NOT_POSTED_SNOOZED,
                        r);
                if (DBG) {
                    Slog.d(TAG, "Ignored enqueue for snoozed notification " + r.getKey());
                }
@@ -6272,6 +6295,8 @@ public class NotificationManagerService extends SystemService {
                            mDuration)
                    .addTaggedData(MetricsEvent.NOTIFICATION_SNOOZED_CRITERIA,
                            mSnoozeCriterionId == null ? 0 : 1));
            mNotificationRecordLogger.log(
                    NotificationRecordLogger.NotificationEvent.NOTIFICATION_SNOOZED, r);
            reportUserInteraction(r);
            boolean wasPosted = removeFromNotificationListsLocked(r);
            cancelNotificationLocked(r, false, REASON_SNOOZED, wasPosted, null);
+65 −5
Original line number Diff line number Diff line
@@ -35,11 +35,14 @@ import java.util.ArrayList;
import java.util.Objects;

/**
 * Interface for writing NotificationReported atoms to statsd log.
 * Interface for writing NotificationReported atoms to statsd log. Use NotificationRecordLoggerImpl
 * in production.  Use NotificationRecordLoggerFake for testing.
 * @hide
 */
public interface NotificationRecordLogger {

    // The high-level interface used by clients.

    /**
     * May log a NotificationReported atom reflecting the posting or update of a notification.
     * @param r The new NotificationRecord. If null, no action is taken.
@@ -58,9 +61,11 @@ public interface NotificationRecordLogger {
     * @param reason The reason the notification was canceled.
     * @param dismissalSurface The surface the notification was dismissed from.
     */
    void logNotificationCancelled(@Nullable NotificationRecord r,
    default void logNotificationCancelled(@Nullable NotificationRecord r,
            @NotificationListenerService.NotificationCancelReason int reason,
            @NotificationStats.DismissalSurface int dismissalSurface);
            @NotificationStats.DismissalSurface int dismissalSurface) {
        log(NotificationCancelledEvent.fromCancelReason(reason, dismissalSurface), r);
    }

    /**
     * Logs a notification visibility change event using UiEventReported (event ids from the
@@ -68,7 +73,17 @@ public interface NotificationRecordLogger {
     * @param r The NotificationRecord. If null, no action is taken.
     * @param visible True if the notification became visible.
     */
    void logNotificationVisibility(@Nullable NotificationRecord r, boolean visible);
    default void logNotificationVisibility(@Nullable NotificationRecord r, boolean visible) {
        log(NotificationEvent.fromVisibility(visible), r);
    }

    // The UiEventReported logging methods are implemented in terms of this lower-level interface.

    /** Logs a UiEventReported event for the given notification. */
    void log(UiEventLogger.UiEventEnum event, NotificationRecord r);

    /** Logs a UiEventReported event that is not associated with any notification. */
    void log(UiEventLogger.UiEventEnum event);

    /**
     * The UiEvent enums that this class can log.
@@ -205,7 +220,30 @@ public interface NotificationRecordLogger {
        @UiEvent(doc = "Notification became visible.")
        NOTIFICATION_OPEN(197),
        @UiEvent(doc = "Notification stopped being visible.")
        NOTIFICATION_CLOSE(198);
        NOTIFICATION_CLOSE(198),
        @UiEvent(doc = "Notification was snoozed.")
        NOTIFICATION_SNOOZED(317),
        @UiEvent(doc = "Notification was not posted because its app is snoozed.")
        NOTIFICATION_NOT_POSTED_SNOOZED(319),
        @UiEvent(doc = "Notification was clicked.")
        NOTIFICATION_CLICKED(320),
        @UiEvent(doc = "Notification action was clicked.")
        NOTIFICATION_ACTION_CLICKED(321),
        @UiEvent(doc = "Notification detail was expanded due to non-user action.")
        NOTIFICATION_DETAIL_OPEN_SYSTEM(327),
        @UiEvent(doc = "Notification detail was collapsed due to non-user action.")
        NOTIFICATION_DETAIL_CLOSE_SYSTEM(328),
        @UiEvent(doc = "Notification detail was expanded due to user action.")
        NOTIFICATION_DETAIL_OPEN_USER(329),
        @UiEvent(doc = "Notification detail was collapsed due to user action.")
        NOTIFICATION_DETAIL_CLOSE_USER(330),
        @UiEvent(doc = "Notification direct reply action was used.")
        NOTIFICATION_DIRECT_REPLIED(331),
        @UiEvent(doc = "Notification smart reply action was used.")
        NOTIFICATION_SMART_REPLIED(332),
        @UiEvent(doc = "Notification smart reply action was visible.")
        NOTIFICATION_SMART_REPLY_VISIBLE(333),
        ;

        private final int mId;
        NotificationEvent(int id) {
@@ -218,7 +256,29 @@ public interface NotificationRecordLogger {
        public static NotificationEvent fromVisibility(boolean visible) {
            return visible ? NOTIFICATION_OPEN : NOTIFICATION_CLOSE;
        }
        public static NotificationEvent fromExpanded(boolean expanded, boolean userAction) {
            if (userAction) {
                return expanded ? NOTIFICATION_DETAIL_OPEN_USER : NOTIFICATION_DETAIL_CLOSE_USER;
            }
            return expanded ? NOTIFICATION_DETAIL_OPEN_SYSTEM : NOTIFICATION_DETAIL_CLOSE_SYSTEM;
        }
    }

    enum NotificationPanelEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "Notification panel became visible.")
        NOTIFICATION_PANEL_OPEN(325),
        @UiEvent(doc = "Notification panel stopped being visible.")
        NOTIFICATION_PANEL_CLOSE(326);

        private final int mId;
        NotificationPanelEvent(int id) {
            mId = id;
        }
        @Override public int getId() {
            return mId;
        }
    }

    /**
     * A helper for extracting logging information from one or two NotificationRecords.
     */
+6 −10
Original line number Diff line number Diff line
@@ -65,20 +65,16 @@ public class NotificationRecordLoggerImpl implements NotificationRecordLogger {
    }

    @Override
    public void logNotificationCancelled(NotificationRecord r, int reason, int dismissalSurface) {
        log(NotificationCancelledEvent.fromCancelReason(reason, dismissalSurface), r);
    }

    @Override
    public void logNotificationVisibility(NotificationRecord r, boolean visible) {
        log(NotificationEvent.fromVisibility(visible), r);
    }

    void log(UiEventLogger.UiEventEnum event, NotificationRecord r) {
    public void log(UiEventLogger.UiEventEnum event, NotificationRecord r) {
        if (r == null) {
            return;
        }
        mUiEventLogger.logWithInstanceId(event, r.getUid(), r.getSbn().getPackageName(),
                r.getSbn().getInstanceId());
    }

    @Override
    public void log(UiEventLogger.UiEventEnum event) {
        mUiEventLogger.log(event);
    }
}
+112 −30

File changed.

Preview size limit exceeded, changes collapsed.

+15 −9
Original line number Diff line number Diff line
@@ -31,25 +31,29 @@ class NotificationRecordLoggerFake implements NotificationRecordLogger {
        // The following fields are only relevant to maybeLogNotificationPosted() calls.
        static final int INVALID = -1;
        public int position = INVALID, buzzBeepBlink = INVALID;
        public boolean shouldLogReported;
        public boolean wasLogged;

        CallRecord(NotificationRecord r, NotificationRecord old, int position,
                int buzzBeepBlink) {
            super(r, old);
            this.position = position;
            this.buzzBeepBlink = buzzBeepBlink;
            shouldLogReported = shouldLogReported(buzzBeepBlink);
            event = shouldLogReported ? NotificationReportedEvent.fromRecordPair(this) : null;
            wasLogged = shouldLogReported(buzzBeepBlink);
            event = wasLogged ? NotificationReportedEvent.fromRecordPair(this) : null;
        }

        CallRecord(NotificationRecord r, UiEventLogger.UiEventEnum event) {
            super(r, null);
            shouldLogReported = false;
            wasLogged = true;
            this.event = event;
        }
    }
    private List<CallRecord> mCalls = new ArrayList<>();

    public int numCalls() {
        return mCalls.size();
    }

    List<CallRecord> getCalls() {
        return mCalls;
    }
@@ -57,6 +61,9 @@ class NotificationRecordLoggerFake implements NotificationRecordLogger {
    CallRecord get(int index) {
        return mCalls.get(index);
    }
    UiEventLogger.UiEventEnum event(int index) {
        return mCalls.get(index).event;
    }

    @Override
    public void maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old,
@@ -65,13 +72,12 @@ class NotificationRecordLoggerFake implements NotificationRecordLogger {
    }

    @Override
    public void logNotificationCancelled(NotificationRecord r, int reason, int dismissalSurface) {
        mCalls.add(new CallRecord(r,
                NotificationCancelledEvent.fromCancelReason(reason, dismissalSurface)));
    public void log(UiEventLogger.UiEventEnum event, NotificationRecord r) {
        mCalls.add(new CallRecord(r, event));
    }

    @Override
    public void logNotificationVisibility(NotificationRecord r, boolean visible) {
        mCalls.add(new CallRecord(r, NotificationEvent.fromVisibility(visible)));
    public void log(UiEventLogger.UiEventEnum event) {
        mCalls.add(new CallRecord(null, event));
    }
}