From 21a2e72655a1ef62c07986bd25a3ef635cd9a49d Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Mon, 2 Oct 2017 17:44:53 -0400 Subject: [PATCH] measure snooze UI use more precisely Bug: 67003813 Test: runtest systemui Change-Id: Id7ba68c8308e911cd506943f84c034ade21d1514 --- .../systemui/statusbar/NotificationSnooze.java | 47 +++++++++++++++++++--- proto/src/metrics_constants.proto | 24 +++++++++++ .../notification/NotificationManagerService.java | 2 + 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationSnooze.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationSnooze.java index 54e9ed9e3b76..492ab44d499b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationSnooze.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationSnooze.java @@ -18,8 +18,11 @@ package com.android.systemui.statusbar; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption; @@ -30,6 +33,7 @@ import android.animation.ObjectAnimator; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; +import android.metrics.LogMaker; import android.os.Bundle; import android.provider.Settings; import android.service.notification.SnoozeCriterion; @@ -63,6 +67,15 @@ public class NotificationSnooze extends LinearLayout private static final int MAX_ASSISTANT_SUGGESTIONS = 1; private static final String KEY_DEFAULT_SNOOZE = "default"; private static final String KEY_OPTIONS = "options_array"; + private static final LogMaker OPTIONS_OPEN_LOG = + new LogMaker(MetricsEvent.NOTIFICATION_SNOOZE_OPTIONS) + .setType(MetricsEvent.TYPE_OPEN); + private static final LogMaker OPTIONS_CLOSE_LOG = + new LogMaker(MetricsEvent.NOTIFICATION_SNOOZE_OPTIONS) + .setType(MetricsEvent.TYPE_CLOSE); + private static final LogMaker UNDO_LOG = + new LogMaker(MetricsEvent.NOTIFICATION_UNDO_SNOOZE) + .setType(MetricsEvent.TYPE_ACTION); private NotificationGuts mGutsContainer; private NotificationSwipeActionHelper mSnoozeListener; private StatusBarNotification mSbn; @@ -88,6 +101,8 @@ public class NotificationSnooze extends LinearLayout R.id.action_snooze_longer, }; + private MetricsLogger mMetricsLogger = new MetricsLogger(); + public NotificationSnooze(Context context, AttributeSet attrs) { super(context, attrs); mParser = new KeyValueListParser(','); @@ -123,7 +138,13 @@ public class NotificationSnooze extends LinearLayout mSnoozeOptions = getDefaultSnoozeOptions(); createOptionViews(); - setSelected(mDefaultOption); + setSelected(mDefaultOption, false); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + logOptionSelection(MetricsEvent.NOTIFICATION_SNOOZE_CLICKED, mDefaultOption); } @Override @@ -163,7 +184,7 @@ public class NotificationSnooze extends LinearLayout SnoozeOption so = mSnoozeOptions.get(i); if (so.getAccessibilityAction() != null && so.getAccessibilityAction().getId() == action) { - setSelected(so); + setSelected(so, true); return true; } } @@ -327,12 +348,24 @@ public class NotificationSnooze extends LinearLayout mExpandAnimation.start(); } - private void setSelected(SnoozeOption option) { + private void setSelected(SnoozeOption option, boolean userAction) { mSelectedOption = option; mSelectedOptionText.setText(option.getConfirmation()); showSnoozeOptions(false); hideSelectedOption(); sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); + if (userAction) { + logOptionSelection(MetricsEvent.NOTIFICATION_SELECT_SNOOZE, option); + } + } + + private void logOptionSelection(int category, SnoozeOption option) { + int index = mSnoozeOptions.indexOf(option); + long duration = TimeUnit.MINUTES.toMillis(option.getMinutesToSnoozeFor()); + mMetricsLogger.write(new LogMaker(category) + .setType(MetricsEvent.TYPE_ACTION) + .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_SNOOZE_INDEX, index) + .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_SNOOZE_DURATION_MS, duration)); } @Override @@ -343,13 +376,15 @@ public class NotificationSnooze extends LinearLayout final int id = v.getId(); final SnoozeOption tag = (SnoozeOption) v.getTag(); if (tag != null) { - setSelected(tag); + setSelected(tag, true); } else if (id == R.id.notification_snooze) { // Toggle snooze options showSnoozeOptions(!mExpanded); + mMetricsLogger.write(!mExpanded ? OPTIONS_OPEN_LOG : OPTIONS_CLOSE_LOG); } else { // Undo snooze was selected undoSnooze(v); + mMetricsLogger.write(UNDO_LOG); } } @@ -380,7 +415,7 @@ public class NotificationSnooze extends LinearLayout @Override public View getContentView() { // Reset the view before use - setSelected(mDefaultOption); + setSelected(mDefaultOption, false); return this; } @@ -402,7 +437,7 @@ public class NotificationSnooze extends LinearLayout return true; } else { // The view should actually be closed - setSelected(mSnoozeOptions.get(0)); + setSelected(mSnoozeOptions.get(0), false); return false; // Return false here so that guts handles closing the view } } diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto index 54c9ec51a6d8..6ec60e2e590f 100644 --- a/proto/src/metrics_constants.proto +++ b/proto/src/metrics_constants.proto @@ -4538,6 +4538,30 @@ message MetricsEvent { // OS: O MR AUTOFILL_UI_LATENCY = 1136; + // Action: the snooze leave-behind was shown after the user clicked the snooze icon + // OS: O MR + NOTIFICATION_SNOOZE_CLICKED = 1137; + + // Action: user selected a notification snooze duration from the drop down + // OS: O MR + NOTIFICATION_SELECT_SNOOZE = 1138; + + // attached to NOTIFICATION_SNOOZED and NOTIFICATION_SELECT_SNOOZE events + // OS: O MR + FIELD_NOTIFICATION_SNOOZE_DURATION_MS = 1139; + + // attached to NOTIFICATION_SELECT_SNOOZE events to indicate the option selected + // OS: O MR + FIELD_NOTIFICATION_SNOOZE_INDEX = 1140; + + // Action: user tapped undo on the notification snooze leave-behind + // OS: O MR + NOTIFICATION_UNDO_SNOOZE = 1141; + + // Action: user togged the visibility of the notification snooze options drop down + // OS: O MR + NOTIFICATION_SNOOZE_OPTIONS = 1142; + // ---- End O-MR1 Constants, all O-MR1 constants go above this line ---- // Add new aosp constants above this line. diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c6f2e8a4f512..9a07baa5f4af 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3741,6 +3741,8 @@ public class NotificationManagerService extends SystemService { MetricsLogger.action(r.getLogMaker() .setCategory(MetricsEvent.NOTIFICATION_SNOOZED) .setType(MetricsEvent.TYPE_CLOSE) + .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_SNOOZE_DURATION_MS, + mDuration) .addTaggedData(MetricsEvent.NOTIFICATION_SNOOZED_CRITERIA, mSnoozeCriterionId == null ? 0 : 1)); boolean wasPosted = removeFromNotificationListsLocked(r); -- 2.11.0