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

Commit 25041bce authored by Salvador Martinez's avatar Salvador Martinez Committed by Android (Google) Code Review
Browse files

Merge "Update triggering to not double trigger at severe threshold"

parents d538e6b8 88b0d501
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -301,9 +301,10 @@ public class PowerUI extends SystemUI {
            // mark if we've already shown a warning this cycle. This will prevent the notification
            // mark if we've already shown a warning this cycle. This will prevent the notification
            // trigger from spamming users by only showing low/critical warnings once per cycle
            // trigger from spamming users by only showing low/critical warnings once per cycle
            if (hybridEnabled) {
            if (hybridEnabled) {
                if (mTimeRemaining < mEnhancedEstimates.getSevereWarningThreshold()
                if (mTimeRemaining <= mEnhancedEstimates.getSevereWarningThreshold()
                        || mBatteryLevel < mLowBatteryReminderLevels[1]) {
                        || mBatteryLevel <= mLowBatteryReminderLevels[1]) {
                    mSevereWarningShownThisChargeCycle = true;
                    mSevereWarningShownThisChargeCycle = true;
                    mLowWarningShownThisChargeCycle = true;
                } else {
                } else {
                    mLowWarningShownThisChargeCycle = true;
                    mLowWarningShownThisChargeCycle = true;
                }
                }
+31 −0
Original line number Original line Diff line number Diff line
@@ -65,10 +65,12 @@ public class PowerUITest extends SysuiTestCase {
    private static final long ONE_HOUR_MILLIS = Duration.ofHours(1).toMillis();
    private static final long ONE_HOUR_MILLIS = Duration.ofHours(1).toMillis();
    public static final int BELOW_WARNING_BUCKET = -1;
    public static final int BELOW_WARNING_BUCKET = -1;
    public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2);
    public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2);
    public static final long BELOW_SEVERE_HYBRID_THRESHOLD = TimeUnit.MINUTES.toMillis(30);
    public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4);
    public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4);
    private static final long ABOVE_CHARGE_CYCLE_THRESHOLD = Duration.ofHours(8).toMillis();
    private static final long ABOVE_CHARGE_CYCLE_THRESHOLD = Duration.ofHours(8).toMillis();
    private static final int OLD_BATTERY_LEVEL_NINE = 9;
    private static final int OLD_BATTERY_LEVEL_NINE = 9;
    private static final int OLD_BATTERY_LEVEL_10 = 10;
    private static final int OLD_BATTERY_LEVEL_10 = 10;
    private static final long VERY_BELOW_SEVERE_HYBRID_THRESHOLD = TimeUnit.MINUTES.toMillis(15);
    private HardwarePropertiesManager mHardProps;
    private HardwarePropertiesManager mHardProps;
    private WarningsUI mMockWarnings;
    private WarningsUI mMockWarnings;
    private PowerUI mPowerUI;
    private PowerUI mPowerUI;
@@ -466,6 +468,35 @@ public class PowerUITest extends SysuiTestCase {
        verify(mMockWarnings, never()).dismissLowBatteryWarning();
        verify(mMockWarnings, never()).dismissLowBatteryWarning();
    }
    }


    @Test
    public void testSevereWarning_countsAsLowAndSevere_WarningOnlyShownOnce() {
        mPowerUI.start();
        when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
        when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
        when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
        when(mEnhancedEstimates.getEstimate())
                .thenReturn(new Estimate(BELOW_SEVERE_HYBRID_THRESHOLD, true));
        mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD;

        // reduce battery level to handle time based trigger -> level trigger interactions
        mPowerUI.mBatteryLevel = 5;
        boolean shouldShow =
                mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
                        ABOVE_WARNING_BUCKET, BELOW_SEVERE_HYBRID_THRESHOLD,
                        POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
        assertTrue(shouldShow);

        // actually run the end to end since it handles changing the internal state.
        mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_10, UNPLUGGED, UNPLUGGED,
                ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET);

        shouldShow =
                mPowerUI.shouldShowLowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
                        ABOVE_WARNING_BUCKET, VERY_BELOW_SEVERE_HYBRID_THRESHOLD,
                        POWER_SAVER_OFF, BatteryManager.BATTERY_HEALTH_GOOD);
        assertFalse(shouldShow);
    }

    @Test
    @Test
    public void testMaybeShowBatteryWarning_onlyQueriesEstimateOnBatteryLevelChangeOrNull() {
    public void testMaybeShowBatteryWarning_onlyQueriesEstimateOnBatteryLevelChangeOrNull() {
        mPowerUI.start();
        mPowerUI.start();