diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/EnableZenModeDialog.java b/packages/SettingsLib/src/com/android/settingslib/notification/EnableZenModeDialog.java index dee68948a16eb..6a1cee3146a26 100644 --- a/packages/SettingsLib/src/com/android/settingslib/notification/EnableZenModeDialog.java +++ b/packages/SettingsLib/src/com/android/settingslib/notification/EnableZenModeDialog.java @@ -16,6 +16,7 @@ package com.android.settingslib.notification; +import android.annotation.Nullable; import android.app.ActivityManager; import android.app.AlarmManager; import android.app.AlertDialog; @@ -42,8 +43,6 @@ import android.widget.ScrollView; import android.widget.TextView; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.logging.MetricsLogger; -import com.android.internal.logging.nano.MetricsProto; import com.android.internal.policy.PhoneWindow; import com.android.settingslib.R; @@ -72,6 +71,9 @@ public class EnableZenModeDialog { private static final int SECONDS_MS = 1000; private static final int MINUTES_MS = 60 * SECONDS_MS; + @Nullable + private final ZenModeDialogMetricsLogger mMetricsLogger; + @VisibleForTesting protected Uri mForeverId; private int mBucketIndex = -1; @@ -102,13 +104,16 @@ public class EnableZenModeDialog { } public EnableZenModeDialog(Context context, int themeResId) { - this(context, themeResId, false /* cancelIsNeutral */); + this(context, themeResId, false /* cancelIsNeutral */, + new ZenModeDialogMetricsLogger(context)); } - public EnableZenModeDialog(Context context, int themeResId, boolean cancelIsNeutral) { + public EnableZenModeDialog(Context context, int themeResId, boolean cancelIsNeutral, + ZenModeDialogMetricsLogger metricsLogger) { mContext = context; mThemeResId = themeResId; mCancelIsNeutral = cancelIsNeutral; + mMetricsLogger = metricsLogger; } public AlertDialog createDialog() { @@ -129,17 +134,11 @@ public class EnableZenModeDialog { ConditionTag tag = getConditionTagAt(checkedId); if (isForever(tag.condition)) { - MetricsLogger.action(mContext, - MetricsProto.MetricsEvent. - NOTIFICATION_ZEN_MODE_TOGGLE_ON_FOREVER); + mMetricsLogger.logOnEnableZenModeForever(); } else if (isAlarm(tag.condition)) { - MetricsLogger.action(mContext, - MetricsProto.MetricsEvent. - NOTIFICATION_ZEN_MODE_TOGGLE_ON_ALARM); + mMetricsLogger.logOnEnableZenModeUntilAlarm(); } else if (isCountdown(tag.condition)) { - MetricsLogger.action(mContext, - MetricsProto.MetricsEvent. - NOTIFICATION_ZEN_MODE_TOGGLE_ON_COUNTDOWN); + mMetricsLogger.logOnEnableZenModeUntilCountdown(); } else { Slog.d(TAG, "Invalid manual condition: " + tag.condition); } @@ -222,8 +221,7 @@ public class EnableZenModeDialog { if (isChecked) { tag.rb.setChecked(true); if (DEBUG) Log.d(TAG, "onCheckedChanged " + conditionId); - MetricsLogger.action(mContext, - MetricsProto.MetricsEvent.QS_DND_CONDITION_SELECT); + mMetricsLogger.logOnConditionSelected(); updateAlarmWarningText(tag.condition); } } @@ -435,7 +433,7 @@ public class EnableZenModeDialog { } private void onClickTimeButton(View row, ConditionTag tag, boolean up, int rowId) { - MetricsLogger.action(mContext, MetricsProto.MetricsEvent.QS_DND_TIME, up); + mMetricsLogger.logOnClickTimeButton(up); Condition newCondition = null; final int N = MINUTE_BUCKETS.length; if (mBucketIndex == -1) { diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/ZenModeDialogMetricsLogger.java b/packages/SettingsLib/src/com/android/settingslib/notification/ZenModeDialogMetricsLogger.java new file mode 100644 index 0000000000000..088a37d995ed3 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/notification/ZenModeDialogMetricsLogger.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settingslib.notification; + +import android.content.Context; + +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto; + +/** + * Logs ui events for {@link EnableZenModeDialog}. + */ +public class ZenModeDialogMetricsLogger { + private final Context mContext; + + public ZenModeDialogMetricsLogger(Context context) { + mContext = context; + } + + /** + * User enabled DND from the QS DND dialog to last until manually turned off + */ + public void logOnEnableZenModeForever() { + MetricsLogger.action( + mContext, + MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_TOGGLE_ON_FOREVER); + } + + /** + * User enabled DND from the QS DND dialog to last until the next alarm goes off + */ + public void logOnEnableZenModeUntilAlarm() { + MetricsLogger.action( + mContext, + MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_TOGGLE_ON_ALARM); + } + + /** + * User enabled DND from the QS DND dialog to last until countdown is done + */ + public void logOnEnableZenModeUntilCountdown() { + MetricsLogger.action( + mContext, + MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_TOGGLE_ON_COUNTDOWN); + } + + /** + * User selected an option on the DND dialog + */ + public void logOnConditionSelected() { + MetricsLogger.action( + mContext, + MetricsProto.MetricsEvent.QS_DND_CONDITION_SELECT); + } + + /** + * User increased or decreased countdown duration of DND from the DND dialog + */ + public void logOnClickTimeButton(boolean up) { + MetricsLogger.action(mContext, MetricsProto.MetricsEvent.QS_DND_TIME, up); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSEvents.kt b/packages/SystemUI/src/com/android/systemui/qs/QSEvents.kt index cc5a771f78c14..26adf464195cd 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSEvents.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/QSEvents.kt @@ -94,15 +94,28 @@ enum class QSEditEvent(private val _id: Int) : UiEventLogger.UiEventEnum { override fun getId() = _id } +/** + * Events from the QS DND tile dialog. {@see QSZenModeDialogMetricsLogger} + * Other names for DND (Do Not Disturb) include "Zen" and "Priority mode". + */ enum class QSDndEvent(private val _id: Int) : UiEventLogger.UiEventEnum { - @UiEvent(doc = "TODO(beverlyt)") + @UiEvent(doc = "User selected an option on the DND dialog") QS_DND_CONDITION_SELECT(420), - @UiEvent(doc = "TODO(beverlyt)") + @UiEvent(doc = "User increased countdown duration of DND from the DND dialog") QS_DND_TIME_UP(422), - @UiEvent(doc = "TODO(beverlyt)") - QS_DND_TIME_DOWN(423); + @UiEvent(doc = "User decreased countdown duration of DND from the DND dialog") + QS_DND_TIME_DOWN(423), + + @UiEvent(doc = "User enabled DND from the QS DND dialog to last until manually turned off") + QS_DND_DIALOG_ENABLE_FOREVER(946), + + @UiEvent(doc = "User enabled DND from the QS DND dialog to last until the next alarm goes off") + QS_DND_DIALOG_ENABLE_UNTIL_ALARM(947), + + @UiEvent(doc = "User enabled DND from the QS DND dialog to last until countdown is done") + QS_DND_DIALOG_ENABLE_UNTIL_COUNTDOWN(948); override fun getId() = _id } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java index a06dc8b2c19a9..a33650cd3d3f2 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java @@ -65,6 +65,7 @@ import com.android.systemui.qs.QSHost; import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.tileimpl.QSTileImpl; +import com.android.systemui.qs.tiles.dialog.QSZenModeDialogMetricsLogger; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.systemui.util.settings.SecureSettings; @@ -86,6 +87,7 @@ public class DndTile extends QSTileImpl { private final SharedPreferences mSharedPreferences; private final SettingObserver mSettingZenDuration; private final DialogLaunchAnimator mDialogLaunchAnimator; + private final QSZenModeDialogMetricsLogger mQSZenDialogMetricsLogger; private boolean mListening; private boolean mShowingDetail; @@ -119,6 +121,7 @@ public class DndTile extends QSTileImpl { refreshState(); } }; + mQSZenDialogMetricsLogger = new QSZenModeDialogMetricsLogger(mContext); } public static void setVisible(Context context, boolean visible) { @@ -211,7 +214,8 @@ public class DndTile extends QSTileImpl { private Dialog makeZenModeDialog() { AlertDialog dialog = new EnableZenModeDialog(mContext, R.style.Theme_SystemUI_Dialog, - true /* cancelIsNeutral */).createDialog(); + true /* cancelIsNeutral */, + mQSZenDialogMetricsLogger).createDialog(); SystemUIDialog.applyFlags(dialog); SystemUIDialog.setShowForAllUsers(dialog, true); SystemUIDialog.registerDismissListener(dialog); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/QSZenModeDialogMetricsLogger.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/QSZenModeDialogMetricsLogger.java new file mode 100644 index 0000000000000..1b81a9947ee37 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/QSZenModeDialogMetricsLogger.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.qs.tiles.dialog; + +import android.content.Context; + +import com.android.internal.logging.UiEventLogger; +import com.android.settingslib.notification.ZenModeDialogMetricsLogger; +import com.android.systemui.qs.QSDndEvent; +import com.android.systemui.qs.QSEvents; + +/** + * Logs ui events for the DND dialog that may appear from tapping the QS DND tile. + * To see the dialog from QS: + * Settings > Notifications > Do Not Disturb > Duration for Quick Settings > Ask every time + * + * Other names for DND (Do Not Disturb) include "Zen" and "Priority only". + */ +public class QSZenModeDialogMetricsLogger extends ZenModeDialogMetricsLogger { + private final UiEventLogger mUiEventLogger = QSEvents.INSTANCE.getQsUiEventsLogger(); + + public QSZenModeDialogMetricsLogger(Context context) { + super(context); + } + + @Override + public void logOnEnableZenModeForever() { + super.logOnEnableZenModeForever(); + mUiEventLogger.log(QSDndEvent.QS_DND_DIALOG_ENABLE_FOREVER); + } + + @Override + public void logOnEnableZenModeUntilAlarm() { + super.logOnEnableZenModeUntilAlarm(); + mUiEventLogger.log(QSDndEvent.QS_DND_DIALOG_ENABLE_UNTIL_ALARM); + } + + @Override + public void logOnEnableZenModeUntilCountdown() { + super.logOnEnableZenModeUntilCountdown(); + mUiEventLogger.log(QSDndEvent.QS_DND_DIALOG_ENABLE_UNTIL_COUNTDOWN); + } + + @Override + public void logOnConditionSelected() { + super.logOnConditionSelected(); + mUiEventLogger.log(QSDndEvent.QS_DND_CONDITION_SELECT); + } + + @Override + public void logOnClickTimeButton(boolean up) { + super.logOnClickTimeButton(up); + mUiEventLogger.log(up + ? QSDndEvent.QS_DND_TIME_UP : QSDndEvent.QS_DND_TIME_DOWN); + } +} + diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index 0cd4fb9578ff8..7bb987ca7cf01 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -56,12 +56,9 @@ import android.widget.TextView; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; -import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.systemui.Prefs; import com.android.systemui.R; -import com.android.systemui.qs.QSDndEvent; -import com.android.systemui.qs.QSEvents; import com.android.systemui.statusbar.policy.ZenModeController; import java.io.FileDescriptor; @@ -106,7 +103,6 @@ public class ZenModePanel extends FrameLayout { private final TransitionHelper mTransitionHelper = new TransitionHelper(); private final Uri mForeverId; private final ConfigurableTexts mConfigurableTexts; - private final UiEventLogger mUiEventLogger = QSEvents.INSTANCE.getQsUiEventsLogger(); private String mTag = TAG + "/" + Integer.toHexString(System.identityHashCode(this)); @@ -666,7 +662,6 @@ public class ZenModePanel extends FrameLayout { tag.rb.setChecked(true); if (DEBUG) Log.d(mTag, "onCheckedChanged " + conditionId); MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT); - mUiEventLogger.log(QSDndEvent.QS_DND_CONDITION_SELECT); select(tag.condition); announceConditionSelection(tag); } @@ -772,7 +767,6 @@ public class ZenModePanel extends FrameLayout { private void onClickTimeButton(View row, ConditionTag tag, boolean up, int rowId) { MetricsLogger.action(mContext, MetricsEvent.QS_DND_TIME, up); - mUiEventLogger.log(up ? QSDndEvent.QS_DND_TIME_UP : QSDndEvent.QS_DND_TIME_DOWN); Condition newCondition = null; final int N = MINUTE_BUCKETS.length; if (mBucketIndex == -1) {