Merge "Don't show low battery tip when estimation is zero"

This commit is contained in:
TreeHugger Robot
2018-06-19 18:42:43 +00:00
committed by Android (Google) Code Review
2 changed files with 8 additions and 1 deletions

View File

@@ -47,7 +47,7 @@ public class LowBatteryDetector implements BatteryTipDetector {
public BatteryTip detect() { public BatteryTip detect() {
final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode(); final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel
|| (mBatteryInfo.discharging || (mBatteryInfo.discharging && mBatteryInfo.remainingTimeUs != 0
&& mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour)); && mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour));
int state = BatteryTip.StateType.INVISIBLE; int state = BatteryTip.StateType.INVISIBLE;

View File

@@ -105,6 +105,13 @@ public class LowBatteryDetectorTest {
assertThat(mLowBatteryDetector.detect().isVisible()).isFalse(); assertThat(mLowBatteryDetector.detect().isVisible()).isFalse();
} }
@Test
public void testDetect_timeEstimationZero_tipInvisible() {
mBatteryInfo.batteryLevel = 50;
mBatteryInfo.remainingTimeUs = 0;
assertThat(mLowBatteryDetector.detect().isVisible()).isFalse();
}
@Test @Test
public void testDetect_noEarlyWarning_tipInvisible() { public void testDetect_noEarlyWarning_tipInvisible() {
mBatteryInfo.remainingTimeUs = TimeUnit.DAYS.toMicros(1); mBatteryInfo.remainingTimeUs = TimeUnit.DAYS.toMicros(1);