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

Commit 901f3ca2 authored by Wesley Wang's avatar Wesley Wang
Browse files

Disable battery saver notification based on predicted time left

 - Adjust the condition to not rely on the remaining time, this will
   makes the battery saver notification only be trigger by the fixed
   battery level

Bug: 229198413
Test: atest SystemUITests
Change-Id: I1f27c4b37fb7c80f451bd4339640ef8dcfbe456b
parent f69119a1
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -397,16 +397,12 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {

        final boolean playSound = currentSnapshot.getBucket() != lastSnapshot.getBucket()
                || lastSnapshot.getPlugged();
        final long timeRemainingMillis = currentSnapshot.getTimeRemainingMillis();

        if (shouldShowHybridWarning(currentSnapshot)) {
            mWarnings.showLowBatteryWarning(playSound);
            // 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
            if ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
                    && timeRemainingMillis <= currentSnapshot.getSevereThresholdMillis())
                    || currentSnapshot.getBatteryLevel()
                    <= currentSnapshot.getSevereLevelThreshold()) {
            if (currentSnapshot.getBatteryLevel() <= currentSnapshot.getSevereLevelThreshold()) {
                mSevereWarningShownThisChargeCycle = true;
                mLowWarningShownThisChargeCycle = true;
                if (DEBUG) {
@@ -461,7 +457,8 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {
    @VisibleForTesting
    boolean shouldDismissHybridWarning(BatteryStateSnapshot snapshot) {
        return snapshot.getPlugged()
                || snapshot.getTimeRemainingMillis() > snapshot.getLowThresholdMillis();
                || snapshot.getBatteryLevel()
                > snapshot.getLowLevelThreshold();
    }

    protected void maybeShowBatteryWarning(
+3 −3
Original line number Diff line number Diff line
@@ -498,8 +498,8 @@ public class PowerUITest extends SysuiTestCase {

        // We should dismiss if the device is plugged in
        state.mPlugged = true;
        state.mTimeRemainingMillis = Duration.ofHours(1).toMillis();
        state.mLowThresholdMillis = Duration.ofHours(2).toMillis();
        state.mBatteryLevel = 19;
        state.mLowLevelThreshold = 20;
        boolean shouldDismiss = mPowerUI.shouldDismissHybridWarning(state.get());
        assertThat(shouldDismiss).isTrue();

@@ -509,7 +509,7 @@ public class PowerUITest extends SysuiTestCase {
        assertThat(shouldDismiss).isFalse();

        // If we go over the low warning threshold we should dismiss
        state.mTimeRemainingMillis = Duration.ofHours(3).toMillis();
        state.mBatteryLevel = 21;
        shouldDismiss = mPowerUI.shouldDismissHybridWarning(state.get());
        assertThat(shouldDismiss).isTrue();
    }