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

Commit 2bd40b9a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix NullPointerException on estimate object" into rvc-dev

parents 627b49ad 5a558b99
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
package com.android.systemui.power;

import com.android.settingslib.fuelgauge.Estimate;
import com.android.settingslib.fuelgauge.EstimateKt;

import javax.inject.Inject;
import javax.inject.Singleton;
@@ -19,7 +20,10 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates {

    @Override
    public Estimate getEstimate() {
        return null;
        // Returns an unknown estimate.
        return new Estimate(EstimateKt.ESTIMATE_MILLIS_UNKNOWN,
                false /* isBasedOnUsage */,
                EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
    }

    @Override
+10 −5
Original line number Diff line number Diff line
@@ -374,8 +374,10 @@ public class PowerUI extends SystemUI implements CommandQueue.Callbacks {
            BatteryStateSnapshot lastSnapshot) {
        // if we are now over 45% battery & 6 hours remaining so we can trigger hybrid
        // notification again
        final long timeRemainingMillis = currentSnapshot.getTimeRemainingMillis();
        if (currentSnapshot.getBatteryLevel() >= CHARGE_CYCLE_PERCENT_RESET
                && currentSnapshot.getTimeRemainingMillis() > SIX_HOURS_MILLIS) {
                && (timeRemainingMillis > SIX_HOURS_MILLIS
                || timeRemainingMillis == NO_ESTIMATE_AVAILABLE)) {
            mLowWarningShownThisChargeCycle = false;
            mSevereWarningShownThisChargeCycle = false;
            if (DEBUG) {
@@ -390,8 +392,8 @@ public class PowerUI extends SystemUI implements CommandQueue.Callbacks {
            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 (currentSnapshot.getTimeRemainingMillis()
                    <= currentSnapshot.getSevereThresholdMillis()
            if ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
                    && timeRemainingMillis <= currentSnapshot.getSevereThresholdMillis())
                    || currentSnapshot.getBatteryLevel()
                    <= currentSnapshot.getSevereLevelThreshold()) {
                mSevereWarningShownThisChargeCycle = true;
@@ -426,15 +428,18 @@ public class PowerUI extends SystemUI implements CommandQueue.Callbacks {
            return false;
        }

        final long timeRemainingMillis = snapshot.getTimeRemainingMillis();
        // 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()
                && ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
                && timeRemainingMillis < snapshot.getLowThresholdMillis())
                || snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold());

        // Only show the severe warning once per charge cycle
        final boolean canShowSevereWarning = !mSevereWarningShownThisChargeCycle
                && (snapshot.getTimeRemainingMillis() < snapshot.getSevereThresholdMillis()
                && ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
                && timeRemainingMillis < snapshot.getSevereThresholdMillis())
                || snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold());

        final boolean canShow = canShowWarning || canShowSevereWarning;