diff options
5 files changed, 30 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/power/BatteryStateSnapshot.kt b/packages/SystemUI/src/com/android/systemui/power/BatteryStateSnapshot.kt index d7a2d9acf3b5..02ad0f1766bd 100644 --- a/packages/SystemUI/src/com/android/systemui/power/BatteryStateSnapshot.kt +++ b/packages/SystemUI/src/com/android/systemui/power/BatteryStateSnapshot.kt @@ -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 } diff --git a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java index bd130f4b40f3..a87922792616 100644 --- a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java +++ b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimates.java @@ -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(); } diff --git a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java index 3f2417638f1a..bfb809ecbf34 100644 --- a/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/power/EnhancedEstimatesImpl.java @@ -21,4 +21,9 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates { public long getSevereWarningThreshold() { return 0; } + + @Override + public boolean getLowWarningEnabled() { + return true; + } } diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java index 18638606a251..4e41108f6496 100644 --- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java +++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java @@ -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 diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java index f51e4731a390..5928a07487d9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java @@ -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); |