Loading packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateControllerImpl.java +12 −1 Original line number Original line Diff line number Diff line Loading @@ -174,10 +174,21 @@ public class StatusBarStateControllerImpl implements if (state > MAX_STATE || state < MIN_STATE) { if (state > MAX_STATE || state < MIN_STATE) { throw new IllegalArgumentException("Invalid state " + 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; 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 // Record the to-be mState and mLastState recordHistoricalState(state /* newState */, mState /* lastState */, false); recordHistoricalState(state /* newState */, mState /* lastState */, false); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarStateControllerImplTest.kt +40 −0 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,8 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager import com.android.systemui.dump.DumpManager import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.plugins.statusbar.StatusBarStateController import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith Loading Loading @@ -87,4 +89,42 @@ class StatusBarStateControllerImplTest : SysuiTestCase() { controller.setDozeAmount(0.5f, false /* animated */) controller.setDozeAmount(0.5f, false /* animated */) verify(listener).onDozeAmountChanged(eq(0.5f), anyFloat()) 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 */)) } } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateControllerImpl.java +12 −1 Original line number Original line Diff line number Diff line Loading @@ -174,10 +174,21 @@ public class StatusBarStateControllerImpl implements if (state > MAX_STATE || state < MIN_STATE) { if (state > MAX_STATE || state < MIN_STATE) { throw new IllegalArgumentException("Invalid state " + 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; 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 // Record the to-be mState and mLastState recordHistoricalState(state /* newState */, mState /* lastState */, false); recordHistoricalState(state /* newState */, mState /* lastState */, false); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarStateControllerImplTest.kt +40 −0 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,8 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager import com.android.systemui.dump.DumpManager import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.plugins.statusbar.StatusBarStateController import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test import org.junit.runner.RunWith import org.junit.runner.RunWith Loading Loading @@ -87,4 +89,42 @@ class StatusBarStateControllerImplTest : SysuiTestCase() { controller.setDozeAmount(0.5f, false /* animated */) controller.setDozeAmount(0.5f, false /* animated */) verify(listener).onDozeAmountChanged(eq(0.5f), anyFloat()) 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 */)) } } }