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

Unverified Commit 4235c3a2 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

SystemUI: Don't store pending ControlAction if the device is locked

Passing control action to activityStarter.dismissKeyguardThenExecute()
is enough to toggle it post device unlock.

Test: Use a control action from locked device, notice that it's no
      longer toggled twice.
Change-Id: I48cb9e0ad2425d35063fddefc738ab36c01690b8
parent 6da38c65
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -121,16 +121,6 @@ class ControlActionCoordinatorImplTest : SysuiTestCase() {
        verify(coordinator).bouncerOrRun(action)
        verify(activityStarter).dismissKeyguardThenExecute(any(), any(), anyBoolean())
        verify(action, never()).invoke()

        // Simulate a refresh call from a Publisher, which will trigger a call to runPendingAction
        reset(action)
        coordinator.runPendingAction(ID)
        verify(action, never()).invoke()

        `when`(keyguardStateController.isUnlocked()).thenReturn(true)
        reset(action)
        coordinator.runPendingAction(ID)
        verify(action).invoke()
    }

    @Test
+0 −6
Original line number Diff line number Diff line
@@ -68,12 +68,6 @@ interface ControlActionCoordinator {
     */
    fun setValue(cvh: ControlViewHolder, templateId: String, newValue: Float)

    /**
     * Actions may have been put on hold while the device is unlocked. Invoke this action if
     * present.
     */
    fun runPendingAction(controlId: String)

    /**
     * User interaction with a control may be blocked for a period of time while actions are being
     * executed by the application.  When the response returns, run this method to enable further
+1 −16
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ class ControlActionCoordinatorImpl @Inject constructor(
    private val controlsSettingsRepository: ControlsSettingsRepository,
) : ControlActionCoordinator {
    private var dialog: Dialog? = null
    private var pendingAction: Action? = null
    private var actionsInProgress = mutableSetOf<String>()
    private val isLocked: Boolean
        get() = !keyguardStateController.isUnlocked()
@@ -160,14 +159,6 @@ class ControlActionCoordinatorImpl @Inject constructor(
        )
    }

    override fun runPendingAction(controlId: String) {
        if (isLocked) return
        if (pendingAction?.controlId == controlId) {
            pendingAction?.invoke()
            pendingAction = null
        }
    }

    @MainThread
    override fun enableActionOnTouch(controlId: String) {
        actionsInProgress.remove(controlId)
@@ -189,17 +180,11 @@ class ControlActionCoordinatorImpl @Inject constructor(
        val authRequired = action.authIsRequired || !allowTrivialControls

        if (keyguardStateController.isShowing() && authRequired) {
            if (isLocked) {
                broadcastSender.closeSystemDialogs()

                // pending actions will only run after the control state has been refreshed
                pendingAction = action
            }
            activityStarter.dismissKeyguardThenExecute({
                Log.d(ControlsUiController.TAG, "Device unlocked, invoking controls action")
                action.invoke()
                true
            }, { pendingAction = null }, true /* afterKeyguardGone */)
            }, null, true /* afterKeyguardGone */)
        } else {
            action.invoke()
        }
+0 −2
Original line number Diff line number Diff line
@@ -181,8 +181,6 @@ class ControlViewHolder(
                    true
                }
            )

            controlActionCoordinator.runPendingAction(cws.ci.controlId)
        }

        val wasLoading = isLoading