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

Commit 723aa768 authored by Chris Wren's avatar Chris Wren
Browse files

Support ad hoc counters in the framework

with some examples in NotificationManagerService.

New counters in this CL:
  note_with_people
  note_dismiss_longevity
  note_click_longevity

Bug: 20137009
Change-Id: I10b769ff4872d50f4c1c3828ea519f9712be7bc2
parent f6b9fe55
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5,3 +5,5 @@ option java_package com.android.internal.logging;
# interaction logs
524287 sysui_view_visibility (category|1|5),(visible|1|6)
524288 sysui_action (category|1|5)
524290 sysui_count (name|3),(increment|1)
524291 sysui_histogram (name|3),(bucket|1)
+10 −0
Original line number Diff line number Diff line
@@ -48,4 +48,14 @@ public class MetricsLogger implements MetricsConstants {
        }
        EventLogTags.writeSysuiAction(category);
    }

    /** Add an integer value to the monotonically increasing counter with the given name. */
    public static void count(Context context, String name, int value) {
        EventLogTags.writeSysuiCount(name, value);
    }

    /** Increment the bucket with the integer label on the histogram with the given name. */
    public static void histogram(Context context, String name, int bucket) {
        EventLogTags.writeSysuiHistogram(name, bucket);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.SystemClock;
import android.service.notification.StatusBarNotification;
import android.util.Log;

import com.android.internal.logging.MetricsLogger;
import com.android.server.notification.NotificationManagerService.DumpFilter;

import java.io.PrintWriter;
@@ -56,8 +57,10 @@ public class NotificationUsageStats {
    // Guarded by synchronized(this).
    private final Map<String, AggregatedStats> mStats = new HashMap<String, AggregatedStats>();
    private final SQLiteLog mSQLiteLog;
    private final Context mContext;

    public NotificationUsageStats(Context context) {
        mContext = context;
        mSQLiteLog = ENABLE_SQLITE_LOG ? new SQLiteLog(context) : null;
    }

@@ -103,6 +106,8 @@ public class NotificationUsageStats {
     * Called when the user dismissed the notification via the UI.
     */
    public synchronized void registerDismissedByUser(NotificationRecord notification) {
        MetricsLogger.histogram(mContext, "note_dismiss_longevity",
                (int) (System.currentTimeMillis() - notification.getRankingTimeMs()) / (60 * 1000));
        notification.stats.onDismiss();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numDismissedByUser++;
@@ -117,6 +122,8 @@ public class NotificationUsageStats {
     * Called when the user clicked the notification in the UI.
     */
    public synchronized void registerClickedByUser(NotificationRecord notification) {
        MetricsLogger.histogram(mContext, "note_click_longevity",
                (int) (System.currentTimeMillis() - notification.getRankingTimeMs()) / (60 * 1000));
        notification.stats.onClick();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numClickedByUser++;
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.LruCache;
import android.util.Slog;
import com.android.internal.logging.MetricsLogger;

import java.util.ArrayList;
import java.util.LinkedList;
@@ -244,6 +245,7 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {

        if (pendingLookups.isEmpty()) {
            if (INFO) Slog.i(TAG, "final affinity: " + affinity);
            if (affinity != NONE) MetricsLogger.count(mBaseContext, "note_with_people", 1);
            return null;
        }

@@ -453,6 +455,8 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {
                Slog.d(TAG, "Validation finished in " + (System.currentTimeMillis() - timeStartMs) +
                        "ms");
            }

            if (mContactAffinity != NONE) MetricsLogger.count(mBaseContext, "note_with_people", 1);
        }

        @Override