FileDocCategorySizeDatePackage
NotificationUsageStats.javaAPI DocAndroid 5.1 API29502Thu Mar 12 22:22:42 GMT 2015com.android.server.notification

NotificationUsageStats

public class NotificationUsageStats extends Object
Keeps track of notification activity, display, and user interaction.

This class receives signals from NoMan and keeps running stats of notification usage. Some metrics are updated as events occur. Others, namely those involving durations, are updated as the notification is canceled.

This class is thread-safe.

{@hide}

Fields Summary
private static final boolean
ENABLE_AGGREGATED_IN_MEMORY_STATS
private static final boolean
ENABLE_SQLITE_LOG
private static final AggregatedStats[]
EMPTY_AGGREGATED_STATS
private final Map
mStats
private final SQLiteLog
mSQLiteLog
Constructors Summary
public NotificationUsageStats(android.content.Context context)


       
        mSQLiteLog = ENABLE_SQLITE_LOG ? new SQLiteLog(context) : null;
    
Methods Summary
public synchronized voiddump(java.io.PrintWriter pw, java.lang.String indent, com.android.server.notification.NotificationManagerService.DumpFilter filter)

        if (ENABLE_AGGREGATED_IN_MEMORY_STATS) {
            for (AggregatedStats as : mStats.values()) {
                if (filter != null && !filter.matches(as.key))
                    continue;
                as.dump(pw, indent);
            }
        }
        if (ENABLE_SQLITE_LOG) {
            mSQLiteLog.dump(pw, indent, filter);
        }
    
private com.android.server.notification.NotificationUsageStats$AggregatedStats[]getAggregatedStatsLocked(NotificationRecord record)

        if (!ENABLE_AGGREGATED_IN_MEMORY_STATS) {
            return EMPTY_AGGREGATED_STATS;
        }

        StatusBarNotification n = record.sbn;

        String user = String.valueOf(n.getUserId());
        String userPackage = user + ":" + n.getPackageName();

        // TODO: Use pool of arrays.
        return new AggregatedStats[] {
                getOrCreateAggregatedStatsLocked(user),
                getOrCreateAggregatedStatsLocked(userPackage),
                getOrCreateAggregatedStatsLocked(n.getKey()),
        };
    
private com.android.server.notification.NotificationUsageStats$AggregatedStatsgetOrCreateAggregatedStatsLocked(java.lang.String key)

        AggregatedStats result = mStats.get(key);
        if (result == null) {
            result = new AggregatedStats(key);
            mStats.put(key, result);
        }
        return result;
    
public synchronized voidregisterCancelDueToClick(NotificationRecord notification)
Called when the notification is canceled because the user clicked it.

Called after {@link #registerClickedByUser(NotificationRecord)}.

        notification.stats.onCancel();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.collect(notification.stats);
        }
    
public synchronized voidregisterCancelUnknown(NotificationRecord notification)
Called when the notification is canceled due to unknown reasons.

Called for notifications of apps being uninstalled, for example.

        notification.stats.onCancel();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.collect(notification.stats);
        }
    
public synchronized voidregisterClickedByUser(NotificationRecord notification)
Called when the user clicked the notification in the UI.

        notification.stats.onClick();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numClickedByUser++;
        }
        if (ENABLE_SQLITE_LOG) {
            mSQLiteLog.logClicked(notification);
        }
    
public synchronized voidregisterDismissedByUser(NotificationRecord notification)
Called when the user dismissed the notification via the UI.

        notification.stats.onDismiss();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numDismissedByUser++;
            stats.collect(notification.stats);
        }
        if (ENABLE_SQLITE_LOG) {
            mSQLiteLog.logDismissed(notification);
        }
    
public synchronized voidregisterPostedByApp(NotificationRecord notification)
Called when a notification has been posted.

        notification.stats = new SingleNotificationStats();
        notification.stats.posttimeElapsedMs = SystemClock.elapsedRealtime();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numPostedByApp++;
        }
        if (ENABLE_SQLITE_LOG) {
            mSQLiteLog.logPosted(notification);
        }
    
public synchronized voidregisterRemovedByApp(NotificationRecord notification)
Called when the originating app removed the notification programmatically.

        notification.stats.onRemoved();
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numRemovedByApp++;
            stats.collect(notification.stats);
        }
        if (ENABLE_SQLITE_LOG) {
            mSQLiteLog.logRemoved(notification);
        }
    
public voidregisterUpdatedByApp(NotificationRecord notification, NotificationRecord old)
Called when a notification has been updated.

        notification.stats = old.stats;
        for (AggregatedStats stats : getAggregatedStatsLocked(notification)) {
            stats.numUpdatedByApp++;
        }