Merge "Disable battery saver notification based on predicted time left" into tm-dev

This commit is contained in:
Wesley Wang
2022-05-03 12:27:37 +00:00
committed by Android (Google) Code Review
2 changed files with 6 additions and 9 deletions

View File

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

View File

@@ -498,8 +498,8 @@ public class PowerUITest extends SysuiTestCase {
// We should dismiss if the device is plugged in // We should dismiss if the device is plugged in
state.mPlugged = true; state.mPlugged = true;
state.mTimeRemainingMillis = Duration.ofHours(1).toMillis(); state.mBatteryLevel = 19;
state.mLowThresholdMillis = Duration.ofHours(2).toMillis(); state.mLowLevelThreshold = 20;
boolean shouldDismiss = mPowerUI.shouldDismissHybridWarning(state.get()); boolean shouldDismiss = mPowerUI.shouldDismissHybridWarning(state.get());
assertThat(shouldDismiss).isTrue(); assertThat(shouldDismiss).isTrue();
@@ -509,7 +509,7 @@ public class PowerUITest extends SysuiTestCase {
assertThat(shouldDismiss).isFalse(); assertThat(shouldDismiss).isFalse();
// If we go over the low warning threshold we should dismiss // 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()); shouldDismiss = mPowerUI.shouldDismissHybridWarning(state.get());
assertThat(shouldDismiss).isTrue(); assertThat(shouldDismiss).isTrue();
} }