Merge "Delay showing the controls ui after dialog" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fe532fc2cb
@@ -155,17 +155,18 @@ internal constructor(
|
|||||||
d.show()
|
d.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun turnOnSettingSecurely(settings: List<String>) {
|
private fun turnOnSettingSecurely(settings: List<String>, onComplete: () -> Unit) {
|
||||||
val action =
|
val action =
|
||||||
ActivityStarter.OnDismissAction {
|
ActivityStarter.OnDismissAction {
|
||||||
settings.forEach { setting ->
|
settings.forEach { setting ->
|
||||||
secureSettings.putIntForUser(setting, 1, userTracker.userId)
|
secureSettings.putIntForUser(setting, 1, userTracker.userId)
|
||||||
}
|
}
|
||||||
|
onComplete()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
activityStarter.dismissKeyguardThenExecute(
|
activityStarter.dismissKeyguardThenExecute(
|
||||||
action,
|
action,
|
||||||
/* cancel */ null,
|
/* cancel */ onComplete,
|
||||||
/* afterKeyguardGone */ true
|
/* afterKeyguardGone */ true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,11 @@ internal constructor(
|
|||||||
if (!showDeviceControlsInLockscreen) {
|
if (!showDeviceControlsInLockscreen) {
|
||||||
settings.add(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS)
|
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) {
|
if (attempts != MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
|
||||||
prefs
|
prefs
|
||||||
@@ -194,7 +199,6 @@ internal constructor(
|
|||||||
.putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
|
.putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
onComplete()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCancel(dialog: DialogInterface?) {
|
override fun onCancel(dialog: DialogInterface?) {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import org.junit.runner.RunWith
|
|||||||
import org.mockito.ArgumentMatchers.anyBoolean
|
import org.mockito.ArgumentMatchers.anyBoolean
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.anyInt
|
import org.mockito.Mockito.anyInt
|
||||||
|
import org.mockito.Mockito.doAnswer
|
||||||
import org.mockito.Mockito.never
|
import org.mockito.Mockito.never
|
||||||
import org.mockito.Mockito.verify
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
@@ -233,6 +234,36 @@ class ControlsSettingsDialogManagerImplTest : SysuiTestCase() {
|
|||||||
verify(completedRunnable).invoke()
|
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
|
@Test
|
||||||
fun dialogCancelDoesntChangeSetting() {
|
fun dialogCancelDoesntChangeSetting() {
|
||||||
sharedPreferences.putAttempts(0)
|
sharedPreferences.putAttempts(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user