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

Commit 8fee141f authored by jackqdyulei's avatar jackqdyulei
Browse files

Fix the update error in EarlyWarningTip

Fixes: 73331241
Test: RunSettingsRoboTests
Change-Id: I8b270d813c8c398d5ddd12f84d3e43426044b597
parent 49c8080a
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -62,13 +62,17 @@ public class EarlyWarningTip extends BatteryTip {

    @Override
    public void updateState(BatteryTip tip) {
        final EarlyWarningTip earlyHeadsUpTip = (EarlyWarningTip) tip;
        if (mPowerSaveModeOn != earlyHeadsUpTip.mPowerSaveModeOn) {
            mPowerSaveModeOn = earlyHeadsUpTip.mPowerSaveModeOn;
            mState = earlyHeadsUpTip.mPowerSaveModeOn ? StateType.HANDLED : StateType.NEW;
        } else if (mState != StateType.HANDLED) {
            mState = earlyHeadsUpTip.getState();
        final EarlyWarningTip earlyWarningTip = (EarlyWarningTip) tip;
        if (earlyWarningTip.mState == StateType.NEW) {
            // Display it if there is early warning
            mState = StateType.NEW;
        } else if (mState == StateType.NEW && earlyWarningTip.mState == StateType.INVISIBLE) {
            // If powerSaveMode is really on, show it as handled, otherwise just dismiss it.
            mState = earlyWarningTip.mPowerSaveModeOn ? StateType.HANDLED : StateType.INVISIBLE;
        } else {
            mState = earlyWarningTip.getState();
        }
        mPowerSaveModeOn = earlyWarningTip.mPowerSaveModeOn;
    }

    @Override
+34 −0
Original line number Diff line number Diff line
@@ -83,4 +83,38 @@ public class EarlyWarningTipTest {

        assertThat(mEarlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.HANDLED);
    }

    @Test
    public void testUpdate_devicePluggedIn_typeBecomeInvisible() {
        final EarlyWarningTip nextTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE,
                false /* powerModeOn */);

        mEarlyWarningTip.updateState(nextTip);

        assertThat(mEarlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE);
    }

    @Test
    public void testUpdate_turnOnLowPowerModeExplicitly_typeStillInvisible() {
        final EarlyWarningTip earlyWarningTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE,
                false /* powerModeOn */);
        final EarlyWarningTip nextTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE,
                true /* powerModeOn */);

        earlyWarningTip.updateState(nextTip);

        assertThat(earlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE);
    }

    @Test
    public void testUpdate_turnOffLowPowerModeExplicitly_typeBecomeInvisible() {
        final EarlyWarningTip earlyWarningTip = new EarlyWarningTip(BatteryTip.StateType.HANDLED,
                true /* powerModeOn */);
        final EarlyWarningTip nextTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE,
                false /* powerModeOn */);

        earlyWarningTip.updateState(nextTip);

        assertThat(earlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE);
    }
}