diff options
| -rw-r--r-- | proto/src/metrics_constants.proto | 14 | ||||
| -rw-r--r-- | services/core/java/com/android/server/notification/NotificationRecord.java | 28 |
2 files changed, 40 insertions, 2 deletions
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto index 4328d94275e9..143fa8634333 100644 --- a/proto/src/metrics_constants.proto +++ b/proto/src/metrics_constants.proto @@ -6116,7 +6116,21 @@ message MetricsEvent { // OS: P FIELD_AUTOFILL_SESSION_ID = 1456; + // NOTIFICATION_SINCE_INTERRUPTION_MILLIS added to P + // NOTIFICATION_INTERRUPTION added to P + // ---- End P Constants, all P constants go above this line ---- + + // Time since this notification last interrupted (visibly or audible) the user + NOTIFICATION_SINCE_INTERRUPTION_MILLIS = 1500; + + // OPEN: Notification interrupted the user, either audibly or visually. + // Tagged data: NOTIFICATION_SINCE_INTERRUPTION_MILLIS + // CATEGORY: NOTIFICATION + NOTIFICATION_INTERRUPTION = 1501; + + // ---- End Q Constants, all Q constants go above this line ---- + // Add new aosp constants above this line. // END OF AOSP CONSTANTS } diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index 39d0bf58c3b1..75b9f1311b75 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -128,6 +128,11 @@ public final class NotificationRecord { // The most recent update time, or the creation time if no updates. private long mUpdateTimeMs; + // The most recent interruption time, or the creation time if no updates. Differs from the + // above value because updates are filtered based on whether they actually interrupted the + // user + private long mInterruptionTimeMs; + // Is this record an update of an old record? public boolean isUpdate; private int mPackagePriority; @@ -180,6 +185,7 @@ public final class NotificationRecord { mRankingTimeMs = calculateRankingTimeMs(0L); mCreationTimeMs = sbn.getPostTime(); mUpdateTimeMs = mCreationTimeMs; + mInterruptionTimeMs = mCreationTimeMs; mContext = context; stats = new NotificationUsageStats.SingleNotificationStats(); mChannel = channel; @@ -525,6 +531,7 @@ public final class NotificationRecord { pw.println(prefix + "mCreationTimeMs=" + mCreationTimeMs); pw.println(prefix + "mVisibleSinceMs=" + mVisibleSinceMs); pw.println(prefix + "mUpdateTimeMs=" + mUpdateTimeMs); + pw.println(prefix + "mInterruptionTimeMs=" + mInterruptionTimeMs); pw.println(prefix + "mSuppressedVisualEffects= " + mSuppressedVisualEffects); if (mPreChannelsNotification) { pw.println(prefix + String.format("defaults=0x%08x flags=0x%08x", @@ -786,6 +793,10 @@ public final class NotificationRecord { return mVisibleSinceMs == 0 ? 0 : (int) (now - mVisibleSinceMs); } + public int getInterruptionMs(long now) { + return (int) (now - mInterruptionTimeMs); + } + /** * Set the visibility of the notification. */ @@ -844,7 +855,7 @@ public final class NotificationRecord { public void setSeen() { mStats.setSeen(); if (mTextChanged) { - mIsInterruptive = true; + setInterruptive(true); } } @@ -940,6 +951,17 @@ public final class NotificationRecord { public void setInterruptive(boolean interruptive) { mIsInterruptive = interruptive; + final long now = System.currentTimeMillis(); + mInterruptionTimeMs = interruptive ? now : mInterruptionTimeMs; + + if (interruptive) { + MetricsLogger.action(getLogMaker() + .setCategory(MetricsEvent.NOTIFICATION_INTERRUPTION) + .setType(MetricsEvent.TYPE_OPEN) + .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_INTERRUPTION_MILLIS, + getInterruptionMs(now))); + MetricsLogger.histogram(mContext, "note_interruptive", getInterruptionMs(now)); + } } public void setTextChanged(boolean textChanged) { @@ -1116,7 +1138,9 @@ public final class NotificationRecord { sbn.getNotification().isGroupSummary() ? 1 : 0) .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_CREATE_MILLIS, getLifespanMs(now)) .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_UPDATE_MILLIS, getFreshnessMs(now)) - .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_VISIBLE_MILLIS, getExposureMs(now)); + .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_VISIBLE_MILLIS, getExposureMs(now)) + .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_INTERRUPTION_MILLIS, + getInterruptionMs(now)); } public LogMaker getLogMaker() { |