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

Commit 10c8b566 authored by Josh Tsuji's avatar Josh Tsuji Committed by Automerger Merge Worker
Browse files

Merge "Don't short-circuit setting StatusBarState if the upcoming state...

Merge "Don't short-circuit setting StatusBarState if the upcoming state differs." into tm-dev am: 95afc78e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17451109



Change-Id: I049981fc032e5db930dd0d5cf7c678bfa6babb9f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 85e1e058 95afc78e
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -174,10 +174,21 @@ public class StatusBarStateControllerImpl implements
        if (state > MAX_STATE || state < MIN_STATE) {
            throw new IllegalArgumentException("Invalid state " + state);
        }
        if (!force && state == mState) {

        // Unless we're explicitly asked to force the state change, don't apply the new state if
        // it's identical to both the current and upcoming states, since that should not be
        // necessary.
        if (!force && state == mState && state == mUpcomingState) {
            return false;
        }

        if (state != mUpcomingState) {
            Log.d(TAG, "setState: requested state " + StatusBarState.toString(state)
                    + "!= upcomingState: " + StatusBarState.toString(mUpcomingState) + ". "
                    + "This usually means the status bar state transition was interrupted before "
                    + "the upcoming state could be applied.");
        }

        // Record the to-be mState and mLastState
        recordHistoricalState(state /* newState */, mState /* lastState */, false);

+40 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
import com.android.systemui.plugins.statusbar.StatusBarStateController
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -87,4 +89,42 @@ class StatusBarStateControllerImplTest : SysuiTestCase() {
        controller.setDozeAmount(0.5f, false /* animated */)
        verify(listener).onDozeAmountChanged(eq(0.5f), anyFloat())
    }

    @Test
    fun testSetState_appliesState_sameStateButDifferentUpcomingState() {
        controller.state = StatusBarState.SHADE
        controller.setUpcomingState(StatusBarState.KEYGUARD)

        assertEquals(controller.state, StatusBarState.SHADE)

        // We should return true (state change was applied) despite going from SHADE to SHADE, since
        // the upcoming state was set to KEYGUARD.
        assertTrue(controller.setState(StatusBarState.SHADE))
    }

    @Test
    fun testSetState_appliesState_differentStateEqualToUpcomingState() {
        controller.state = StatusBarState.SHADE
        controller.setUpcomingState(StatusBarState.KEYGUARD)

        assertEquals(controller.state, StatusBarState.SHADE)

        // Make sure we apply a SHADE -> KEYGUARD state change when the upcoming state is KEYGUARD.
        assertTrue(controller.setState(StatusBarState.KEYGUARD))
    }

    @Test
    fun testSetState_doesNotApplyState_currentAndUpcomingStatesSame() {
        controller.state = StatusBarState.SHADE
        controller.setUpcomingState(StatusBarState.SHADE)

        assertEquals(controller.state, StatusBarState.SHADE)

        // We're going from SHADE -> SHADE, and the upcoming state is also SHADE, this should not do
        // anything.
        assertFalse(controller.setState(StatusBarState.SHADE))

        // Double check that we can still force it to happen.
        assertTrue(controller.setState(StatusBarState.SHADE, true /* force */))
    }
}