Merge "Only query for estimate on battery level change" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
729bfdf9a8
@@ -77,6 +77,7 @@ public class PowerUI extends SystemUI {
|
||||
private int mPlugType = 0;
|
||||
private int mInvalidCharger = 0;
|
||||
private EnhancedEstimates mEnhancedEstimates;
|
||||
private Estimate mLastEstimate;
|
||||
private boolean mLowWarningShownThisChargeCycle;
|
||||
private boolean mSevereWarningShownThisChargeCycle;
|
||||
|
||||
@@ -247,7 +248,8 @@ public class PowerUI extends SystemUI {
|
||||
|
||||
// Show the correct version of low battery warning if needed
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
maybeShowBatteryWarning(plugged, oldPlugged, oldBucket, bucket);
|
||||
maybeShowBatteryWarning(
|
||||
oldBatteryLevel, plugged, oldPlugged, oldBucket, bucket);
|
||||
});
|
||||
|
||||
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
|
||||
@@ -262,14 +264,18 @@ public class PowerUI extends SystemUI {
|
||||
}
|
||||
}
|
||||
|
||||
protected void maybeShowBatteryWarning(boolean plugged, boolean oldPlugged, int oldBucket,
|
||||
int bucket) {
|
||||
protected void maybeShowBatteryWarning(int oldBatteryLevel, boolean plugged, boolean oldPlugged,
|
||||
int oldBucket, int bucket) {
|
||||
boolean isPowerSaver = mPowerManager.isPowerSaveMode();
|
||||
// only play SFX when the dialog comes up or the bucket changes
|
||||
final boolean playSound = bucket != oldBucket || oldPlugged;
|
||||
final boolean hybridEnabled = mEnhancedEstimates.isHybridNotificationEnabled();
|
||||
if (hybridEnabled) {
|
||||
final Estimate estimate = mEnhancedEstimates.getEstimate();
|
||||
Estimate estimate = mLastEstimate;
|
||||
if (estimate == null || mBatteryLevel != oldBatteryLevel) {
|
||||
estimate = mEnhancedEstimates.getEstimate();
|
||||
mLastEstimate = estimate;
|
||||
}
|
||||
// Turbo is not always booted once SysUI is running so we have ot make sure we actually
|
||||
// get data back
|
||||
if (estimate != null) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -66,6 +67,8 @@ public class PowerUITest extends SysuiTestCase {
|
||||
public static final long BELOW_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(2);
|
||||
public static final long ABOVE_HYBRID_THRESHOLD = TimeUnit.HOURS.toMillis(4);
|
||||
private static final long ABOVE_CHARGE_CYCLE_THRESHOLD = Duration.ofHours(8).toMillis();
|
||||
private static final int OLD_BATTERY_LEVEL_NINE = 9;
|
||||
private static final int OLD_BATTERY_LEVEL_10 = 10;
|
||||
private HardwarePropertiesManager mHardProps;
|
||||
private WarningsUI mMockWarnings;
|
||||
private PowerUI mPowerUI;
|
||||
@@ -307,8 +310,8 @@ public class PowerUITest extends SysuiTestCase {
|
||||
.thenReturn(new Estimate(BELOW_HYBRID_THRESHOLD, true));
|
||||
mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD;
|
||||
|
||||
mPowerUI.maybeShowBatteryWarning(UNPLUGGED, UNPLUGGED, ABOVE_WARNING_BUCKET,
|
||||
ABOVE_WARNING_BUCKET);
|
||||
mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED,
|
||||
ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET);
|
||||
|
||||
// reduce battery level to handle time based trigger -> level trigger interactions
|
||||
mPowerUI.mBatteryLevel = 10;
|
||||
@@ -449,6 +452,33 @@ public class PowerUITest extends SysuiTestCase {
|
||||
verify(mMockWarnings, never()).dismissLowBatteryWarning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaybeShowBatteryWarning_onlyQueriesEstimateOnBatteryLevelChangeOrNull() {
|
||||
mPowerUI.start();
|
||||
Estimate estimate = new Estimate(BELOW_HYBRID_THRESHOLD, true);
|
||||
when(mEnhancedEstimates.isHybridNotificationEnabled()).thenReturn(true);
|
||||
when(mEnhancedEstimates.getLowWarningThreshold()).thenReturn(PowerUI.THREE_HOURS_IN_MILLIS);
|
||||
when(mEnhancedEstimates.getSevereWarningThreshold()).thenReturn(ONE_HOUR_MILLIS);
|
||||
when(mEnhancedEstimates.getEstimate()).thenReturn(estimate);
|
||||
mPowerUI.mBatteryStatus = BatteryManager.BATTERY_HEALTH_GOOD;
|
||||
|
||||
// we expect that the first time it will query even if the level is the same
|
||||
mPowerUI.mBatteryLevel = 9;
|
||||
mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED,
|
||||
ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET);
|
||||
verify(mEnhancedEstimates, times(1)).getEstimate();
|
||||
|
||||
// We should NOT query again if the battery level hasn't changed
|
||||
mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_NINE, UNPLUGGED, UNPLUGGED,
|
||||
ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET);
|
||||
verify(mEnhancedEstimates, times(1)).getEstimate();
|
||||
|
||||
// Battery level has changed, so we should query again
|
||||
mPowerUI.maybeShowBatteryWarning(OLD_BATTERY_LEVEL_10, UNPLUGGED, UNPLUGGED,
|
||||
ABOVE_WARNING_BUCKET, ABOVE_WARNING_BUCKET);
|
||||
verify(mEnhancedEstimates, times(2)).getEstimate();
|
||||
}
|
||||
|
||||
private void setCurrentTemp(float temp) {
|
||||
when(mHardProps.getDeviceTemperatures(DEVICE_TEMPERATURE_SKIN, TEMPERATURE_CURRENT))
|
||||
.thenReturn(new float[] { temp });
|
||||
|
||||
Reference in New Issue
Block a user