From e6ddb8a1348d2ea53bc3033be43c4dae922b653a Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Wed, 27 May 2015 15:21:00 -0400 Subject: [PATCH] add event timers to all notification logs. previously, some logs had only some times, and not others. Bug: 21394955 Change-Id: I0d7af163be23f5a989c35aba6e6f6879672543fc --- .../com/android/server/EventLogTags.logtags | 8 +++---- .../NotificationManagerService.java | 20 ++++++++++------ .../notification/NotificationRecord.java | 23 +++++++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags index 4b65dec93ee25..c01d816807504 100644 --- a/services/core/java/com/android/server/EventLogTags.logtags +++ b/services/core/java/com/android/server/EventLogTags.logtags @@ -66,13 +66,13 @@ option java_package com.android.server # when notifications are newly displayed on screen, or disappear from screen 27510 notification_visibility_changed (newlyVisibleKeys|3),(noLongerVisibleKeys|3) # when notifications are expanded, or contracted -27511 notification_expansion (key|3),(user_action|1),(expanded|1) +27511 notification_expansion (key|3),(user_action|1),(expanded|1),(lifespan|1),(freshness|1),(exposure|1) # when a notification has been clicked -27520 notification_clicked (key|3) +27520 notification_clicked (key|3),(lifespan|1),(freshness|1),(exposure|1) # when a notification action button has been clicked -27521 notification_action_clicked (key|3),(action_index|1) +27521 notification_action_clicked (key|3),(action_index|1),(lifespan|1),(freshness|1),(exposure|1) # when a notification has been canceled -27530 notification_canceled (key|3),(reason|1),(lifespan|1),(exposure|1) +27530 notification_canceled (key|3),(reason|1),(lifespan|1),(freshness|1),(exposure|1) # replaces 27510 with a row per notification 27531 notification_visibility (key|3),(visibile|1),(lifespan|1),(freshness|1) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index ef4da02e78165..d942a5492fd09 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -555,12 +555,15 @@ public class NotificationManagerService extends SystemService { @Override public void onNotificationClick(int callingUid, int callingPid, String key) { synchronized (mNotificationList) { - EventLogTags.writeNotificationClicked(key); NotificationRecord r = mNotificationsByKey.get(key); if (r == null) { Log.w(TAG, "No notification with key: " + key); return; } + final long now = System.currentTimeMillis(); + EventLogTags.writeNotificationClicked(key, + r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now)); + StatusBarNotification sbn = r.sbn; cancelNotification(callingUid, callingPid, sbn.getPackageName(), sbn.getTag(), sbn.getId(), Notification.FLAG_AUTO_CANCEL, @@ -573,12 +576,14 @@ public class NotificationManagerService extends SystemService { public void onNotificationActionClick(int callingUid, int callingPid, String key, int actionIndex) { synchronized (mNotificationList) { - EventLogTags.writeNotificationActionClicked(key, actionIndex); NotificationRecord r = mNotificationsByKey.get(key); if (r == null) { Log.w(TAG, "No notification with key: " + key); return; } + final long now = System.currentTimeMillis(); + EventLogTags.writeNotificationActionClicked(key, actionIndex, + r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now)); // TODO: Log action click via UsageStats. } } @@ -685,11 +690,14 @@ public class NotificationManagerService extends SystemService { @Override public void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded) { - EventLogTags.writeNotificationExpansion(key, userAction ? 1 : 0, expanded ? 1 : 0); synchronized (mNotificationList) { NotificationRecord r = mNotificationsByKey.get(key); if (r != null) { r.stats.onExpansionChanged(userAction, expanded); + final long now = System.currentTimeMillis(); + EventLogTags.writeNotificationExpansion(key, + userAction ? 1 : 0, expanded ? 1 : 0, + r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now)); } } } @@ -2786,10 +2794,8 @@ public class NotificationManagerService extends SystemService { mArchive.record(r.sbn); final long now = System.currentTimeMillis(); - final int lifespan = (int) (now - r.getCreationTimeMs()); - final long visibleSinceMs = r.getVisibleSinceMs(); - final int exposure = visibleSinceMs == 0L ? 0 : (int) (now - visibleSinceMs); - EventLogTags.writeNotificationCanceled(canceledKey, reason, lifespan, exposure); + EventLogTags.writeNotificationCanceled(canceledKey, reason, + r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now)); } /** diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index b8478c1d2f4c1..c4773cacf1ca9 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -288,24 +288,27 @@ public final class NotificationRecord { } /** - * Returns the timestamp of the most recent updates, or the post time if none. + * @param now this current time in milliseconds. + * @returns the number of milliseconds since the most recent update, or the post time if none. */ - public long getUpdateTimeMs() { - return mUpdateTimeMs; + public int getFreshnessMs(long now) { + return (int) (now - mUpdateTimeMs); } /** - * Returns the timestamp of the first post, ignoring updates. + * @param now this current time in milliseconds. + * @returns the number of milliseconds since the the first post, ignoring updates. */ - public long getCreationTimeMs() { - return mCreationTimeMs; + public int getLifespanMs(long now) { + return (int) (now - mCreationTimeMs); } /** - * Returns the timestamp of the most recent visibility event, or 0L if hidden. + * @param now this current time in milliseconds. + * @returns the number of milliseconds since the most recent visibility event, or 0 if never. */ - public long getVisibleSinceMs() { - return mVisibleSinceMs; + public int getExposureMs(long now) { + return mVisibleSinceMs == 0 ? 0 : (int) (now - mVisibleSinceMs); } /** @@ -313,7 +316,7 @@ public final class NotificationRecord { */ public void setVisibility(boolean visible) { final long now = System.currentTimeMillis(); - mVisibleSinceMs = visible ? now : 0L; + mVisibleSinceMs = visible ? now : mVisibleSinceMs; stats.onVisibilityChanged(visible); EventLogTags.writeNotificationVisibility(getKey(), visible ? 1 : 0, (int) (now - mCreationTimeMs),