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

Commit c876e5ea authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Delay showing the controls ui after dialog" into tm-qpr-dev am: fe532fc2 am: 8e3b8b0e

parents b2616e1a 8e3b8b0e
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -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?) {
+31 −0
Original line number Diff line number Diff line
@@ -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`
@@ -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)