Loading packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt +8 −4 Original line number Diff line number Diff line Loading @@ -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 ) } Loading @@ -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 Loading @@ -194,7 +199,6 @@ internal constructor( .putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) .apply() } onComplete() } override fun onCancel(dialog: DialogInterface?) { Loading packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt +31 −0 Original line number Diff line number Diff line Loading @@ -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` Loading Loading @@ -233,6 +234,36 @@ class ControlsSettingsDialogManagerImplTest : SysuiTestCase() { verify(completedRunnable).invoke() } @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) Loading Loading
packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt +8 −4 Original line number Diff line number Diff line Loading @@ -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 ) } Loading @@ -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 Loading @@ -194,7 +199,6 @@ internal constructor( .putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) .apply() } onComplete() } override fun onCancel(dialog: DialogInterface?) { Loading
packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt +31 −0 Original line number Diff line number Diff line Loading @@ -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` Loading Loading @@ -233,6 +234,36 @@ class ControlsSettingsDialogManagerImplTest : SysuiTestCase() { verify(completedRunnable).invoke() } @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) Loading