diff options
2 files changed, 39 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt index 06d4a0888197..ce0f2e93f26d 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt @@ -155,17 +155,18 @@ internal constructor( d.show() } - private fun turnOnSettingSecurely(settings: List<String>) { + private fun turnOnSettingSecurely(settings: List<String>, onComplete: () -> Unit) { val action = ActivityStarter.OnDismissAction { settings.forEach { setting -> secureSettings.putIntForUser(setting, 1, userTracker.userId) } + onComplete() true } activityStarter.dismissKeyguardThenExecute( action, - /* cancel */ null, + /* cancel */ onComplete, /* afterKeyguardGone */ true ) } @@ -186,7 +187,11 @@ internal constructor( if (!showDeviceControlsInLockscreen) { settings.add(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS) } - turnOnSettingSecurely(settings) + // If we are toggling the flag, we want to call onComplete after the keyguard is + // dismissed (and the setting is turned on), to pass the correct value. + turnOnSettingSecurely(settings, onComplete) + } else { + onComplete() } if (attempts != MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) { prefs @@ -194,7 +199,6 @@ internal constructor( .putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) .apply() } - onComplete() } override fun onCancel(dialog: DialogInterface?) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt index 5a613aa9225e..590989d3a987 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt @@ -45,6 +45,7 @@ import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.Mock import org.mockito.Mockito.anyInt +import org.mockito.Mockito.doAnswer import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` @@ -234,6 +235,36 @@ class ControlsSettingsDialogManagerImplTest : SysuiTestCase() { } @Test + fun dialogPositiveButtonWhenCalledOnCompleteSettingIsTrue() { + sharedPreferences.putAttempts(0) + secureSettings.putBool(SETTING_SHOW, true) + secureSettings.putBool(SETTING_ACTION, false) + + doAnswer { assertThat(secureSettings.getBool(SETTING_ACTION, false)).isTrue() } + .`when`(completedRunnable) + .invoke() + + underTest.maybeShowDialog(context, completedRunnable) + clickButton(DialogInterface.BUTTON_POSITIVE) + + verify(completedRunnable).invoke() + } + + @Test + fun dialogPositiveCancelKeyguardStillCallsOnComplete() { + `when`(activityStarter.dismissKeyguardThenExecute(any(), nullable(), anyBoolean())) + .thenAnswer { (it.arguments[1] as Runnable).run() } + sharedPreferences.putAttempts(0) + secureSettings.putBool(SETTING_SHOW, true) + secureSettings.putBool(SETTING_ACTION, false) + + underTest.maybeShowDialog(context, completedRunnable) + clickButton(DialogInterface.BUTTON_POSITIVE) + + verify(completedRunnable).invoke() + } + + @Test fun dialogCancelDoesntChangeSetting() { sharedPreferences.putAttempts(0) secureSettings.putBool(SETTING_SHOW, true) |