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

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

Merge "Remove the 3 hour warning"

parents dcb8edfc d73c5aa8
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -17,7 +17,8 @@ data class BatteryStateSnapshot(
    val timeRemainingMillis: Long,
    val severeThresholdMillis: Long,
    val lowThresholdMillis: Long,
    val isBasedOnUsage: Boolean
    val isBasedOnUsage: Boolean,
    val isLowWarningEnabled: Boolean
) {
    /**
     * Returns whether hybrid warning logic/copy should be used for this snapshot
@@ -48,7 +49,8 @@ data class BatteryStateSnapshot(
        NO_ESTIMATE_AVAILABLE.toLong(),
        NO_ESTIMATE_AVAILABLE.toLong(),
        NO_ESTIMATE_AVAILABLE.toLong(),
        false
        false,
        true
    ) {
        this.isHybrid = false
    }
+5 −0
Original line number Diff line number Diff line
@@ -23,4 +23,9 @@ public interface EnhancedEstimates {
     * show a severe warning to the user.
     */
    long getSevereWarningThreshold();

    /**
     * Returns a boolean indicating if the low warning should be shown at all or not.
     */
    boolean getLowWarningEnabled();
}
+5 −0
Original line number Diff line number Diff line
@@ -21,4 +21,9 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates {
    public long getSevereWarningThreshold() {
        return 0;
    }

    @Override
    public boolean getLowWarningEnabled() {
        return true;
    }
}
+6 −4
Original line number Diff line number Diff line
@@ -284,7 +284,8 @@ public class PowerUI extends SystemUI {
                    plugged, bucket, mBatteryStatus, mLowBatteryReminderLevels[1],
                    mLowBatteryReminderLevels[0], estimate.getEstimateMillis(),
                    mEnhancedEstimates.getSevereWarningThreshold(),
                    mEnhancedEstimates.getLowWarningThreshold(), estimate.isBasedOnUsage());
                    mEnhancedEstimates.getLowWarningThreshold(), estimate.isBasedOnUsage(),
                    mEnhancedEstimates.getLowWarningEnabled());
        } else {
            if (DEBUG) {
                Slog.d(TAG, "using standard");
@@ -351,7 +352,6 @@ public class PowerUI extends SystemUI {
                Slog.d(TAG, "Low warning marked as shown this cycle");
                mLowWarningShownThisChargeCycle = true;
            }

        } else if (shouldDismissHybridWarning(currentSnapshot)) {
            if (DEBUG) {
                Slog.d(TAG, "Dismissing warning");
@@ -375,8 +375,9 @@ public class PowerUI extends SystemUI {
            return false;
        }

        // Only show the low warning once per charge cycle & no battery saver
        final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver()
        // Only show the low warning if enabled once per charge cycle & no battery saver
        final boolean canShowWarning = snapshot.isLowWarningEnabled()
                && !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver()
                && (snapshot.getTimeRemainingMillis() < snapshot.getLowThresholdMillis()
                || snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold());

@@ -386,6 +387,7 @@ public class PowerUI extends SystemUI {
                || snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold());

        final boolean canShow = canShowWarning || canShowSevereWarning;

        if (DEBUG) {
            Slog.d(TAG, "Enhanced trigger is: " + canShow + "\nwith battery snapshot:"
                    + " mLowWarningShownThisChargeCycle: " + mLowWarningShownThisChargeCycle
+10 −3
Original line number Diff line number Diff line
@@ -265,6 +265,12 @@ public class PowerUITest extends SysuiTestCase {
        state.mIsPowerSaver = true;
        shouldShow = mPowerUI.shouldShowHybridWarning(state.get());
        assertThat(shouldShow).isFalse();

        state.mIsPowerSaver = false;
        // if disabled we should not show the low warning.
        state.mIsLowLevelWarningEnabled = false;
        shouldShow = mPowerUI.shouldShowHybridWarning(state.get());
        assertThat(shouldShow).isFalse();
    }

    @Test
@@ -365,7 +371,7 @@ public class PowerUITest extends SysuiTestCase {
        assertThat(refreshedEstimate.getEstimateMillis()).isEqualTo(BELOW_HYBRID_THRESHOLD);
        BatteryStateSnapshot snapshot = new BatteryStateSnapshot(
                BATTERY_LEVEL_10, false, false, 0, BatteryManager.BATTERY_HEALTH_GOOD,
                0, 0, -1, 0, 0, false);
                0, 0, -1, 0, 0, false, true);
        mPowerUI.mLastBatteryStateSnapshot = snapshot;

        // query again since the estimate was -1
@@ -375,7 +381,7 @@ public class PowerUITest extends SysuiTestCase {
        assertThat(refreshedEstimate.getEstimateMillis()).isEqualTo(BELOW_SEVERE_HYBRID_THRESHOLD);
        snapshot = new BatteryStateSnapshot(
                BATTERY_LEVEL_10, false, false, 0, BatteryManager.BATTERY_HEALTH_GOOD, 0,
                0, BELOW_SEVERE_HYBRID_THRESHOLD, 0, 0, false);
                0, BELOW_SEVERE_HYBRID_THRESHOLD, 0, 0, false, true);
        mPowerUI.mLastBatteryStateSnapshot = snapshot;

        // Battery level hasn't changed, so we don't query again
@@ -536,13 +542,14 @@ public class PowerUITest extends SysuiTestCase {
        public long mTimeRemainingMillis = Duration.ofHours(24).toMillis();
        public boolean mIsBasedOnUsage = true;
        public boolean mIsHybrid = true;
        public boolean mIsLowLevelWarningEnabled = true;

        public BatteryStateSnapshot get() {
            if (mIsHybrid) {
                return new BatteryStateSnapshot(mBatteryLevel, mIsPowerSaver, mPlugged, mBucket,
                        mBatteryStatus, mSevereLevelThreshold, mLowLevelThreshold,
                        mTimeRemainingMillis, mSevereThresholdMillis, mLowThresholdMillis,
                        mIsBasedOnUsage);
                        mIsBasedOnUsage, mIsLowLevelWarningEnabled);
            } else {
                return new BatteryStateSnapshot(mBatteryLevel, mIsPowerSaver, mPlugged, mBucket,
                        mBatteryStatus, mSevereLevelThreshold, mLowLevelThreshold);