Loading packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenDurationDialog.java→packages/SettingsLib/src/com/android/settingslib/notification/modes/DndDurationDialogFactory.java +7 −2 Original line number Diff line number Diff line Loading @@ -44,7 +44,12 @@ import com.android.settingslib.R; import java.util.Arrays; public class ZenDurationDialog { /** * This dialog configures the default behavior that the user prefers when enabling DND. * Not to be confused with {@link EnableDndDialogFactory}, which is the dialog that will be shown * when the user enables DND if the "Ask every time" option was selected in this dialog. */ public class DndDurationDialogFactory { private static final int[] MINUTE_BUCKETS = ZenModeConfig.MINUTE_BUCKETS; @VisibleForTesting protected static final int MIN_BUCKET_MINUTES = MINUTE_BUCKETS[0]; Loading Loading @@ -72,7 +77,7 @@ public class ZenDurationDialog { @VisibleForTesting protected LayoutInflater mLayoutInflater; public ZenDurationDialog(Context context) { public DndDurationDialogFactory(Context context) { mContext = context; } Loading packages/SettingsLib/src/com/android/settingslib/notification/modes/EnableZenModeDialog.java→packages/SettingsLib/src/com/android/settingslib/notification/modes/EnableDndDialogFactory.java +15 −8 Original line number Diff line number Diff line Loading @@ -54,8 +54,15 @@ import java.util.GregorianCalendar; import java.util.Locale; import java.util.Objects; public class EnableZenModeDialog { private static final String TAG = "EnableZenModeDialog"; /** * When enabling DND, if the user has the setting to "Ask every time" for the duration, we show * this dialog to allow the user to select for how long they want DND to be enabled this time. * Not to be confused with {@link DndDurationDialogFactory}, which is the dialog that allows the * user to configure the default behavior for enabling DND (and in turn may lead to this dialog * being shown, since it contains the said "Ask every time" option). */ public class EnableDndDialogFactory { private static final String TAG = "EnableDndDialogFactory"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final int[] MINUTE_BUCKETS = ZenModeConfig.MINUTE_BUCKETS; Loading @@ -74,7 +81,7 @@ public class EnableZenModeDialog { private static final int MINUTES_MS = 60 * SECONDS_MS; @Nullable private final ZenModeDialogMetricsLogger mMetricsLogger; private final EnableDndDialogMetricsLogger mMetricsLogger; @VisibleForTesting protected Uri mForeverId; Loading @@ -101,17 +108,17 @@ public class EnableZenModeDialog { @VisibleForTesting protected LayoutInflater mLayoutInflater; public EnableZenModeDialog(Context context) { public EnableDndDialogFactory(Context context) { this(context, 0); } public EnableZenModeDialog(Context context, int themeResId) { public EnableDndDialogFactory(Context context, int themeResId) { this(context, themeResId, false /* cancelIsNeutral */, new ZenModeDialogMetricsLogger(context)); new EnableDndDialogMetricsLogger(context)); } public EnableZenModeDialog(Context context, int themeResId, boolean cancelIsNeutral, ZenModeDialogMetricsLogger metricsLogger) { public EnableDndDialogFactory(Context context, int themeResId, boolean cancelIsNeutral, EnableDndDialogMetricsLogger metricsLogger) { mContext = context; mThemeResId = themeResId; mCancelIsNeutral = cancelIsNeutral; Loading packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenModeDialogMetricsLogger.java→packages/SettingsLib/src/com/android/settingslib/notification/modes/EnableDndDialogMetricsLogger.java +3 −3 Original line number Diff line number Diff line Loading @@ -22,12 +22,12 @@ import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto; /** * Logs ui events for {@link EnableZenModeDialog}. * Logs ui events for {@link EnableDndDialogFactory}. */ public class ZenModeDialogMetricsLogger { public class EnableDndDialogMetricsLogger { private final Context mContext; public ZenModeDialogMetricsLogger(Context context) { public EnableDndDialogMetricsLogger(Context context) { mContext = context; } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenDurationDialogTest.java→packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/DndDurationDialogFactoryTest.java +38 −54 Original line number Diff line number Diff line Loading @@ -16,6 +16,12 @@ package com.android.settingslib.notification.modes; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.ALWAYS_ASK_CONDITION_INDEX; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.COUNTDOWN_CONDITION_INDEX; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.FOREVER_CONDITION_INDEX; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.MAX_BUCKET_MINUTES; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.MIN_BUCKET_MINUTES; import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; Loading @@ -32,6 +38,8 @@ import android.view.View; import androidx.appcompat.app.AlertDialog; import com.android.settingslib.notification.modes.DndDurationDialogFactory.ConditionTag; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -39,8 +47,8 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class ZenDurationDialogTest { private ZenDurationDialog mController; public class DndDurationDialogFactoryTest { private DndDurationDialogFactory mController; private Context mContext; private LayoutInflater mLayoutInflater; Loading @@ -53,7 +61,7 @@ public class ZenDurationDialogTest { mContentResolver = RuntimeEnvironment.application.getContentResolver(); mLayoutInflater = LayoutInflater.from(mContext); mController = spy(new ZenDurationDialog(mContext)); mController = spy(new DndDurationDialogFactory(mContext)); mController.mLayoutInflater = mLayoutInflater; mController.getContentView(); mBuilder = new AlertDialog.Builder(mContext); Loading @@ -65,12 +73,9 @@ public class ZenDurationDialogTest { Settings.Global.ZEN_DURATION_PROMPT); mController.setupDialog(mBuilder); assertFalse(mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -79,12 +84,9 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_FOREVER); mController.setupDialog(mBuilder); assertTrue(mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -92,12 +94,9 @@ public class ZenDurationDialogTest { Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, 45); mController.setupDialog(mBuilder); assertFalse(mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -106,8 +105,7 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_FOREVER); mController.setupDialog(mBuilder); mController.getConditionTagAt(ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.setChecked( true); mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.setChecked(true); mController.updateZenDuration(Settings.Secure.ZEN_DURATION_FOREVER); assertEquals(Settings.Secure.ZEN_DURATION_PROMPT, Settings.Secure.getInt(mContentResolver, Loading @@ -120,8 +118,7 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_PROMPT); mController.setupDialog(mBuilder); mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb.setChecked( true); mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.setChecked(true); mController.updateZenDuration(Settings.Secure.ZEN_DURATION_PROMPT); assertEquals(Settings.Secure.ZEN_DURATION_FOREVER, Settings.Secure.getInt(mContentResolver, Loading @@ -134,8 +131,7 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_PROMPT); mController.setupDialog(mBuilder); mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb.setChecked( true); mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.setChecked(true); mController.updateZenDuration(Settings.Secure.ZEN_DURATION_PROMPT); // countdown defaults to 60 minutes: Loading @@ -152,59 +148,50 @@ public class ZenDurationDialogTest { // click time button starts at 60 minutes // - 1 hour to MAX_BUCKET_MINUTES (12 hours), increments by 1 hour // - 0-60 minutes increments by 15 minutes View view = mController.mZenRadioGroupContent.getChildAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); ZenDurationDialog.ConditionTag tag = mController.getConditionTagAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); View view = mController.mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX); ConditionTag tag = mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX); // test incrementing up: mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); assertEquals(120, tag.countdownZenDuration); // goes from 1 hour to 2 hours // try clicking up 50 times - should max out at ZenDurationDialog.MAX_BUCKET_MINUTES for (int i = 0; i < 50; i++) { mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); } assertEquals(ZenDurationDialog.MAX_BUCKET_MINUTES, tag.countdownZenDuration); assertEquals(MAX_BUCKET_MINUTES, tag.countdownZenDuration); // reset, test incrementing down: mController.mBucketIndex = -1; // reset current bucket index to reset countdownZenDuration tag.countdownZenDuration = 60; // back to default mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); assertEquals(45, tag.countdownZenDuration); // goes from 60 minutes to 45 minutes // try clicking down 50 times - should stop at MIN_BUCKET_MINUTES for (int i = 0; i < 50; i++) { mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); } assertEquals(ZenDurationDialog.MIN_BUCKET_MINUTES, tag.countdownZenDuration); assertEquals(MIN_BUCKET_MINUTES, tag.countdownZenDuration); // reset countdownZenDuration to unbucketed number, should round change to nearest bucket mController.mBucketIndex = -1; tag.countdownZenDuration = 50; mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); assertEquals(45, tag.countdownZenDuration); mController.mBucketIndex = -1; tag.countdownZenDuration = 50; mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); assertEquals(60, tag.countdownZenDuration); mController.mBucketIndex = -1; tag.countdownZenDuration = 75; mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); assertEquals(60, tag.countdownZenDuration); mController.mBucketIndex = -1; tag.countdownZenDuration = 75; mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); assertEquals(120, tag.countdownZenDuration); } Loading @@ -213,12 +200,9 @@ public class ZenDurationDialogTest { Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, Settings.Secure.ZEN_DURATION_FOREVER); mController.setupDialog(mBuilder); ZenDurationDialog.ConditionTag forever = mController.getConditionTagAt( ZenDurationDialog.FOREVER_CONDITION_INDEX); ZenDurationDialog.ConditionTag countdown = mController.getConditionTagAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); ZenDurationDialog.ConditionTag alwaysAsk = mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX); ConditionTag forever = mController.getConditionTagAt(FOREVER_CONDITION_INDEX); ConditionTag countdown = mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX); ConditionTag alwaysAsk = mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX); forever.rb.setChecked(true); assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected"); Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/EnableZenModeDialogTest.java→packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/EnableDndDialogFactoryTest.java +31 −38 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package com.android.settingslib.notification.modes; import static com.android.settingslib.notification.modes.EnableDndDialogFactory.COUNTDOWN_ALARM_CONDITION_INDEX; import static com.android.settingslib.notification.modes.EnableDndDialogFactory.COUNTDOWN_CONDITION_INDEX; import static com.android.settingslib.notification.modes.EnableDndDialogFactory.FOREVER_CONDITION_INDEX; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertFalse; Loading @@ -39,6 +43,8 @@ import android.net.Uri; import android.service.notification.Condition; import android.view.LayoutInflater; import com.android.settingslib.notification.modes.EnableDndDialogFactory.ConditionTag; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -48,8 +54,8 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class EnableZenModeDialogTest { private EnableZenModeDialog mController; public class EnableDndDialogFactoryTest { private EnableDndDialogFactory mController; @Mock private Context mContext; Loading @@ -74,7 +80,7 @@ public class EnableZenModeDialogTest { when(mFragment.getContext()).thenReturn(mShadowContext); mLayoutInflater = LayoutInflater.from(mShadowContext); mController = spy(new EnableZenModeDialog(mContext)); mController = spy(new EnableDndDialogFactory(mContext)); mController.mContext = mContext; mController.mLayoutInflater = mLayoutInflater; mController.mForeverId = Condition.newId(mContext).appendPath("forever").build(); Loading @@ -101,36 +107,29 @@ public class EnableZenModeDialogTest { Uri countdown = Condition.newId(mContext).appendPath("countdown").build(); mCountdownCondition = new Condition(countdown, "countdown", "", "", 0, 0, 0); mController.bind(mCountdownCondition, mController.mZenRadioGroupContent.getChildAt( EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX), EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX); mController.mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX), COUNTDOWN_CONDITION_INDEX); mController.bind(mAlarmCondition, mController.mZenRadioGroupContent.getChildAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX), EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX); COUNTDOWN_ALARM_CONDITION_INDEX), COUNTDOWN_ALARM_CONDITION_INDEX); } @Test public void testForeverChecked() { mController.bindConditions(mController.forever()); assertTrue(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test public void testNoneChecked() { mController.bindConditions(null); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -139,12 +138,9 @@ public class EnableZenModeDialogTest { doReturn(true).when(mController).isAlarm(mAlarmCondition); mController.bindConditions(mAlarmCondition); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -153,12 +149,9 @@ public class EnableZenModeDialogTest { doReturn(true).when(mController).isCountdown(mCountdownCondition); mController.bindConditions(mCountdownCondition); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test Loading Loading @@ -198,12 +191,12 @@ public class EnableZenModeDialogTest { @Test public void testAccessibility() { mController.bindConditions(null); EnableZenModeDialog.ConditionTag forever = mController.getConditionTagAt( ZenDurationDialog.FOREVER_CONDITION_INDEX); EnableZenModeDialog.ConditionTag countdown = mController.getConditionTagAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); EnableZenModeDialog.ConditionTag alwaysAsk = mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX); ConditionTag forever = mController.getConditionTagAt( DndDurationDialogFactory.FOREVER_CONDITION_INDEX); ConditionTag countdown = mController.getConditionTagAt( DndDurationDialogFactory.COUNTDOWN_CONDITION_INDEX); ConditionTag alwaysAsk = mController.getConditionTagAt( DndDurationDialogFactory.ALWAYS_ASK_CONDITION_INDEX); forever.rb.setChecked(true); assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected"); Loading Loading
packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenDurationDialog.java→packages/SettingsLib/src/com/android/settingslib/notification/modes/DndDurationDialogFactory.java +7 −2 Original line number Diff line number Diff line Loading @@ -44,7 +44,12 @@ import com.android.settingslib.R; import java.util.Arrays; public class ZenDurationDialog { /** * This dialog configures the default behavior that the user prefers when enabling DND. * Not to be confused with {@link EnableDndDialogFactory}, which is the dialog that will be shown * when the user enables DND if the "Ask every time" option was selected in this dialog. */ public class DndDurationDialogFactory { private static final int[] MINUTE_BUCKETS = ZenModeConfig.MINUTE_BUCKETS; @VisibleForTesting protected static final int MIN_BUCKET_MINUTES = MINUTE_BUCKETS[0]; Loading Loading @@ -72,7 +77,7 @@ public class ZenDurationDialog { @VisibleForTesting protected LayoutInflater mLayoutInflater; public ZenDurationDialog(Context context) { public DndDurationDialogFactory(Context context) { mContext = context; } Loading
packages/SettingsLib/src/com/android/settingslib/notification/modes/EnableZenModeDialog.java→packages/SettingsLib/src/com/android/settingslib/notification/modes/EnableDndDialogFactory.java +15 −8 Original line number Diff line number Diff line Loading @@ -54,8 +54,15 @@ import java.util.GregorianCalendar; import java.util.Locale; import java.util.Objects; public class EnableZenModeDialog { private static final String TAG = "EnableZenModeDialog"; /** * When enabling DND, if the user has the setting to "Ask every time" for the duration, we show * this dialog to allow the user to select for how long they want DND to be enabled this time. * Not to be confused with {@link DndDurationDialogFactory}, which is the dialog that allows the * user to configure the default behavior for enabling DND (and in turn may lead to this dialog * being shown, since it contains the said "Ask every time" option). */ public class EnableDndDialogFactory { private static final String TAG = "EnableDndDialogFactory"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final int[] MINUTE_BUCKETS = ZenModeConfig.MINUTE_BUCKETS; Loading @@ -74,7 +81,7 @@ public class EnableZenModeDialog { private static final int MINUTES_MS = 60 * SECONDS_MS; @Nullable private final ZenModeDialogMetricsLogger mMetricsLogger; private final EnableDndDialogMetricsLogger mMetricsLogger; @VisibleForTesting protected Uri mForeverId; Loading @@ -101,17 +108,17 @@ public class EnableZenModeDialog { @VisibleForTesting protected LayoutInflater mLayoutInflater; public EnableZenModeDialog(Context context) { public EnableDndDialogFactory(Context context) { this(context, 0); } public EnableZenModeDialog(Context context, int themeResId) { public EnableDndDialogFactory(Context context, int themeResId) { this(context, themeResId, false /* cancelIsNeutral */, new ZenModeDialogMetricsLogger(context)); new EnableDndDialogMetricsLogger(context)); } public EnableZenModeDialog(Context context, int themeResId, boolean cancelIsNeutral, ZenModeDialogMetricsLogger metricsLogger) { public EnableDndDialogFactory(Context context, int themeResId, boolean cancelIsNeutral, EnableDndDialogMetricsLogger metricsLogger) { mContext = context; mThemeResId = themeResId; mCancelIsNeutral = cancelIsNeutral; Loading
packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenModeDialogMetricsLogger.java→packages/SettingsLib/src/com/android/settingslib/notification/modes/EnableDndDialogMetricsLogger.java +3 −3 Original line number Diff line number Diff line Loading @@ -22,12 +22,12 @@ import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto; /** * Logs ui events for {@link EnableZenModeDialog}. * Logs ui events for {@link EnableDndDialogFactory}. */ public class ZenModeDialogMetricsLogger { public class EnableDndDialogMetricsLogger { private final Context mContext; public ZenModeDialogMetricsLogger(Context context) { public EnableDndDialogMetricsLogger(Context context) { mContext = context; } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenDurationDialogTest.java→packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/DndDurationDialogFactoryTest.java +38 −54 Original line number Diff line number Diff line Loading @@ -16,6 +16,12 @@ package com.android.settingslib.notification.modes; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.ALWAYS_ASK_CONDITION_INDEX; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.COUNTDOWN_CONDITION_INDEX; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.FOREVER_CONDITION_INDEX; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.MAX_BUCKET_MINUTES; import static com.android.settingslib.notification.modes.DndDurationDialogFactory.MIN_BUCKET_MINUTES; import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; Loading @@ -32,6 +38,8 @@ import android.view.View; import androidx.appcompat.app.AlertDialog; import com.android.settingslib.notification.modes.DndDurationDialogFactory.ConditionTag; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -39,8 +47,8 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class ZenDurationDialogTest { private ZenDurationDialog mController; public class DndDurationDialogFactoryTest { private DndDurationDialogFactory mController; private Context mContext; private LayoutInflater mLayoutInflater; Loading @@ -53,7 +61,7 @@ public class ZenDurationDialogTest { mContentResolver = RuntimeEnvironment.application.getContentResolver(); mLayoutInflater = LayoutInflater.from(mContext); mController = spy(new ZenDurationDialog(mContext)); mController = spy(new DndDurationDialogFactory(mContext)); mController.mLayoutInflater = mLayoutInflater; mController.getContentView(); mBuilder = new AlertDialog.Builder(mContext); Loading @@ -65,12 +73,9 @@ public class ZenDurationDialogTest { Settings.Global.ZEN_DURATION_PROMPT); mController.setupDialog(mBuilder); assertFalse(mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -79,12 +84,9 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_FOREVER); mController.setupDialog(mBuilder); assertTrue(mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -92,12 +94,9 @@ public class ZenDurationDialogTest { Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, 45); mController.setupDialog(mBuilder); assertFalse(mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -106,8 +105,7 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_FOREVER); mController.setupDialog(mBuilder); mController.getConditionTagAt(ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX).rb.setChecked( true); mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX).rb.setChecked(true); mController.updateZenDuration(Settings.Secure.ZEN_DURATION_FOREVER); assertEquals(Settings.Secure.ZEN_DURATION_PROMPT, Settings.Secure.getInt(mContentResolver, Loading @@ -120,8 +118,7 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_PROMPT); mController.setupDialog(mBuilder); mController.getConditionTagAt(ZenDurationDialog.FOREVER_CONDITION_INDEX).rb.setChecked( true); mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.setChecked(true); mController.updateZenDuration(Settings.Secure.ZEN_DURATION_PROMPT); assertEquals(Settings.Secure.ZEN_DURATION_FOREVER, Settings.Secure.getInt(mContentResolver, Loading @@ -134,8 +131,7 @@ public class ZenDurationDialogTest { Settings.Secure.ZEN_DURATION_PROMPT); mController.setupDialog(mBuilder); mController.getConditionTagAt(ZenDurationDialog.COUNTDOWN_CONDITION_INDEX).rb.setChecked( true); mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.setChecked(true); mController.updateZenDuration(Settings.Secure.ZEN_DURATION_PROMPT); // countdown defaults to 60 minutes: Loading @@ -152,59 +148,50 @@ public class ZenDurationDialogTest { // click time button starts at 60 minutes // - 1 hour to MAX_BUCKET_MINUTES (12 hours), increments by 1 hour // - 0-60 minutes increments by 15 minutes View view = mController.mZenRadioGroupContent.getChildAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); ZenDurationDialog.ConditionTag tag = mController.getConditionTagAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); View view = mController.mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX); ConditionTag tag = mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX); // test incrementing up: mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); assertEquals(120, tag.countdownZenDuration); // goes from 1 hour to 2 hours // try clicking up 50 times - should max out at ZenDurationDialog.MAX_BUCKET_MINUTES for (int i = 0; i < 50; i++) { mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); } assertEquals(ZenDurationDialog.MAX_BUCKET_MINUTES, tag.countdownZenDuration); assertEquals(MAX_BUCKET_MINUTES, tag.countdownZenDuration); // reset, test incrementing down: mController.mBucketIndex = -1; // reset current bucket index to reset countdownZenDuration tag.countdownZenDuration = 60; // back to default mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); assertEquals(45, tag.countdownZenDuration); // goes from 60 minutes to 45 minutes // try clicking down 50 times - should stop at MIN_BUCKET_MINUTES for (int i = 0; i < 50; i++) { mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); } assertEquals(ZenDurationDialog.MIN_BUCKET_MINUTES, tag.countdownZenDuration); assertEquals(MIN_BUCKET_MINUTES, tag.countdownZenDuration); // reset countdownZenDuration to unbucketed number, should round change to nearest bucket mController.mBucketIndex = -1; tag.countdownZenDuration = 50; mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); assertEquals(45, tag.countdownZenDuration); mController.mBucketIndex = -1; tag.countdownZenDuration = 50; mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); assertEquals(60, tag.countdownZenDuration); mController.mBucketIndex = -1; tag.countdownZenDuration = 75; mController.onClickTimeButton(view, tag, false, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, false, COUNTDOWN_CONDITION_INDEX); assertEquals(60, tag.countdownZenDuration); mController.mBucketIndex = -1; tag.countdownZenDuration = 75; mController.onClickTimeButton(view, tag, true, ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); mController.onClickTimeButton(view, tag, true, COUNTDOWN_CONDITION_INDEX); assertEquals(120, tag.countdownZenDuration); } Loading @@ -213,12 +200,9 @@ public class ZenDurationDialogTest { Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, Settings.Secure.ZEN_DURATION_FOREVER); mController.setupDialog(mBuilder); ZenDurationDialog.ConditionTag forever = mController.getConditionTagAt( ZenDurationDialog.FOREVER_CONDITION_INDEX); ZenDurationDialog.ConditionTag countdown = mController.getConditionTagAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); ZenDurationDialog.ConditionTag alwaysAsk = mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX); ConditionTag forever = mController.getConditionTagAt(FOREVER_CONDITION_INDEX); ConditionTag countdown = mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX); ConditionTag alwaysAsk = mController.getConditionTagAt(ALWAYS_ASK_CONDITION_INDEX); forever.rb.setChecked(true); assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected"); Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/EnableZenModeDialogTest.java→packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/EnableDndDialogFactoryTest.java +31 −38 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package com.android.settingslib.notification.modes; import static com.android.settingslib.notification.modes.EnableDndDialogFactory.COUNTDOWN_ALARM_CONDITION_INDEX; import static com.android.settingslib.notification.modes.EnableDndDialogFactory.COUNTDOWN_CONDITION_INDEX; import static com.android.settingslib.notification.modes.EnableDndDialogFactory.FOREVER_CONDITION_INDEX; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertFalse; Loading @@ -39,6 +43,8 @@ import android.net.Uri; import android.service.notification.Condition; import android.view.LayoutInflater; import com.android.settingslib.notification.modes.EnableDndDialogFactory.ConditionTag; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -48,8 +54,8 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class EnableZenModeDialogTest { private EnableZenModeDialog mController; public class EnableDndDialogFactoryTest { private EnableDndDialogFactory mController; @Mock private Context mContext; Loading @@ -74,7 +80,7 @@ public class EnableZenModeDialogTest { when(mFragment.getContext()).thenReturn(mShadowContext); mLayoutInflater = LayoutInflater.from(mShadowContext); mController = spy(new EnableZenModeDialog(mContext)); mController = spy(new EnableDndDialogFactory(mContext)); mController.mContext = mContext; mController.mLayoutInflater = mLayoutInflater; mController.mForeverId = Condition.newId(mContext).appendPath("forever").build(); Loading @@ -101,36 +107,29 @@ public class EnableZenModeDialogTest { Uri countdown = Condition.newId(mContext).appendPath("countdown").build(); mCountdownCondition = new Condition(countdown, "countdown", "", "", 0, 0, 0); mController.bind(mCountdownCondition, mController.mZenRadioGroupContent.getChildAt( EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX), EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX); mController.mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX), COUNTDOWN_CONDITION_INDEX); mController.bind(mAlarmCondition, mController.mZenRadioGroupContent.getChildAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX), EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX); COUNTDOWN_ALARM_CONDITION_INDEX), COUNTDOWN_ALARM_CONDITION_INDEX); } @Test public void testForeverChecked() { mController.bindConditions(mController.forever()); assertTrue(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test public void testNoneChecked() { mController.bindConditions(null); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -139,12 +138,9 @@ public class EnableZenModeDialogTest { doReturn(true).when(mController).isAlarm(mAlarmCondition); mController.bindConditions(mAlarmCondition); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test Loading @@ -153,12 +149,9 @@ public class EnableZenModeDialogTest { doReturn(true).when(mController).isCountdown(mCountdownCondition); mController.bindConditions(mCountdownCondition); assertFalse(mController.getConditionTagAt(EnableZenModeDialog.FOREVER_CONDITION_INDEX).rb .isChecked()); assertTrue(mController.getConditionTagAt(EnableZenModeDialog.COUNTDOWN_CONDITION_INDEX).rb .isChecked()); assertFalse(mController.getConditionTagAt( EnableZenModeDialog.COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(FOREVER_CONDITION_INDEX).rb.isChecked()); assertTrue(mController.getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.isChecked()); assertFalse(mController.getConditionTagAt(COUNTDOWN_ALARM_CONDITION_INDEX).rb.isChecked()); } @Test Loading Loading @@ -198,12 +191,12 @@ public class EnableZenModeDialogTest { @Test public void testAccessibility() { mController.bindConditions(null); EnableZenModeDialog.ConditionTag forever = mController.getConditionTagAt( ZenDurationDialog.FOREVER_CONDITION_INDEX); EnableZenModeDialog.ConditionTag countdown = mController.getConditionTagAt( ZenDurationDialog.COUNTDOWN_CONDITION_INDEX); EnableZenModeDialog.ConditionTag alwaysAsk = mController.getConditionTagAt( ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX); ConditionTag forever = mController.getConditionTagAt( DndDurationDialogFactory.FOREVER_CONDITION_INDEX); ConditionTag countdown = mController.getConditionTagAt( DndDurationDialogFactory.COUNTDOWN_CONDITION_INDEX); ConditionTag alwaysAsk = mController.getConditionTagAt( DndDurationDialogFactory.ALWAYS_ASK_CONDITION_INDEX); forever.rb.setChecked(true); assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected"); Loading