Merge "add event timers to all notification logs." into mnc-dev
diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags
index 4b65dec..c01d8168 100644
--- a/services/core/java/com/android/server/EventLogTags.logtags
+++ b/services/core/java/com/android/server/EventLogTags.logtags
@@ -66,13 +66,13 @@
# 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 2be409a..c8ab10a 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 @@
@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 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 @@
@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));
}
}
}
@@ -2787,10 +2795,8 @@
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 b8478c1..c4773ca 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 @@
}
/**
- * 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 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),