Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b72ac84 authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Update QSDndEvents

* EnableZenModeDialog lives in SettingsLib, so add an
  interface to allow the SystemUI version to log ui events
* Add UIEvents that weren't ported over from MetricsLogger =>
  UiEventLogger

Test: atest DndTileTest EnableZenModeDialogTest
Test: check unbuffered log with
  adb shell cmd stats print-logs && adb logcat -s statsd:I | grep --line-buffered ' (90)'
Fixes: 206792037

Change-Id: I25c4f1b08a1793dcb24aabc6b31324f93b117240
parent d7c5ca76
Loading
Loading
Loading
Loading
+14 −16
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.settingslib.notification;
package com.android.settingslib.notification;


import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.AlertDialog;
@@ -42,8 +43,6 @@ import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.TextView;


import com.android.internal.annotations.VisibleForTesting;
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.internal.policy.PhoneWindow;
import com.android.settingslib.R;
import com.android.settingslib.R;


@@ -72,6 +71,9 @@ public class EnableZenModeDialog {
    private static final int SECONDS_MS = 1000;
    private static final int SECONDS_MS = 1000;
    private static final int MINUTES_MS = 60 * SECONDS_MS;
    private static final int MINUTES_MS = 60 * SECONDS_MS;


    @Nullable
    private final ZenModeDialogMetricsLogger mMetricsLogger;

    @VisibleForTesting
    @VisibleForTesting
    protected Uri mForeverId;
    protected Uri mForeverId;
    private int mBucketIndex = -1;
    private int mBucketIndex = -1;
@@ -102,13 +104,16 @@ public class EnableZenModeDialog {
    }
    }


    public EnableZenModeDialog(Context context, int themeResId) {
    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;
        mContext = context;
        mThemeResId = themeResId;
        mThemeResId = themeResId;
        mCancelIsNeutral = cancelIsNeutral;
        mCancelIsNeutral = cancelIsNeutral;
        mMetricsLogger = metricsLogger;
    }
    }


    public AlertDialog createDialog() {
    public AlertDialog createDialog() {
@@ -129,17 +134,11 @@ public class EnableZenModeDialog {
                                ConditionTag tag = getConditionTagAt(checkedId);
                                ConditionTag tag = getConditionTagAt(checkedId);


                                if (isForever(tag.condition)) {
                                if (isForever(tag.condition)) {
                                    MetricsLogger.action(mContext,
                                    mMetricsLogger.logOnEnableZenModeForever();
                                            MetricsProto.MetricsEvent.
                                                    NOTIFICATION_ZEN_MODE_TOGGLE_ON_FOREVER);
                                } else if (isAlarm(tag.condition)) {
                                } else if (isAlarm(tag.condition)) {
                                    MetricsLogger.action(mContext,
                                    mMetricsLogger.logOnEnableZenModeUntilAlarm();
                                            MetricsProto.MetricsEvent.
                                                    NOTIFICATION_ZEN_MODE_TOGGLE_ON_ALARM);
                                } else if (isCountdown(tag.condition)) {
                                } else if (isCountdown(tag.condition)) {
                                    MetricsLogger.action(mContext,
                                    mMetricsLogger.logOnEnableZenModeUntilCountdown();
                                            MetricsProto.MetricsEvent.
                                                    NOTIFICATION_ZEN_MODE_TOGGLE_ON_COUNTDOWN);
                                } else {
                                } else {
                                    Slog.d(TAG, "Invalid manual condition: " + tag.condition);
                                    Slog.d(TAG, "Invalid manual condition: " + tag.condition);
                                }
                                }
@@ -222,8 +221,7 @@ public class EnableZenModeDialog {
                if (isChecked) {
                if (isChecked) {
                    tag.rb.setChecked(true);
                    tag.rb.setChecked(true);
                    if (DEBUG) Log.d(TAG, "onCheckedChanged " + conditionId);
                    if (DEBUG) Log.d(TAG, "onCheckedChanged " + conditionId);
                    MetricsLogger.action(mContext,
                    mMetricsLogger.logOnConditionSelected();
                            MetricsProto.MetricsEvent.QS_DND_CONDITION_SELECT);
                    updateAlarmWarningText(tag.condition);
                    updateAlarmWarningText(tag.condition);
                }
                }
            }
            }
@@ -435,7 +433,7 @@ public class EnableZenModeDialog {
    }
    }


    private void onClickTimeButton(View row, ConditionTag tag, boolean up, int rowId) {
    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;
        Condition newCondition = null;
        final int N = MINUTE_BUCKETS.length;
        final int N = MINUTE_BUCKETS.length;
        if (mBucketIndex == -1) {
        if (mBucketIndex == -1) {
+76 −0
Original line number Original line Diff line number Diff line
/*
 * 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);
    }
}
+17 −4
Original line number Original line Diff line number Diff line
@@ -94,15 +94,28 @@ enum class QSEditEvent(private val _id: Int) : UiEventLogger.UiEventEnum {
    override fun getId() = _id
    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 {
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),
    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),
    QS_DND_TIME_UP(422),


    @UiEvent(doc = "TODO(beverlyt)")
    @UiEvent(doc = "User decreased countdown duration of DND from the DND dialog")
    QS_DND_TIME_DOWN(423);
    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
    override fun getId() = _id
}
}
+5 −1
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.SettingObserver;
import com.android.systemui.qs.SettingObserver;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl;
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.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.util.settings.SecureSettings;
@@ -86,6 +87,7 @@ public class DndTile extends QSTileImpl<BooleanState> {
    private final SharedPreferences mSharedPreferences;
    private final SharedPreferences mSharedPreferences;
    private final SettingObserver mSettingZenDuration;
    private final SettingObserver mSettingZenDuration;
    private final DialogLaunchAnimator mDialogLaunchAnimator;
    private final DialogLaunchAnimator mDialogLaunchAnimator;
    private final QSZenModeDialogMetricsLogger mQSZenDialogMetricsLogger;


    private boolean mListening;
    private boolean mListening;
    private boolean mShowingDetail;
    private boolean mShowingDetail;
@@ -119,6 +121,7 @@ public class DndTile extends QSTileImpl<BooleanState> {
                refreshState();
                refreshState();
            }
            }
        };
        };
        mQSZenDialogMetricsLogger = new QSZenModeDialogMetricsLogger(mContext);
    }
    }


    public static void setVisible(Context context, boolean visible) {
    public static void setVisible(Context context, boolean visible) {
@@ -211,7 +214,8 @@ public class DndTile extends QSTileImpl<BooleanState> {


    private Dialog makeZenModeDialog() {
    private Dialog makeZenModeDialog() {
        AlertDialog dialog = new EnableZenModeDialog(mContext, R.style.Theme_SystemUI_Dialog,
        AlertDialog dialog = new EnableZenModeDialog(mContext, R.style.Theme_SystemUI_Dialog,
                true /* cancelIsNeutral */).createDialog();
                true /* cancelIsNeutral */,
                mQSZenDialogMetricsLogger).createDialog();
        SystemUIDialog.applyFlags(dialog);
        SystemUIDialog.applyFlags(dialog);
        SystemUIDialog.setShowForAllUsers(dialog, true);
        SystemUIDialog.setShowForAllUsers(dialog, true);
        SystemUIDialog.registerDismissListener(dialog);
        SystemUIDialog.registerDismissListener(dialog);
+71 −0
Original line number Original line Diff line number Diff line
/*
 * 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);
    }
}
Loading