OSDN Git Service

Don't show low battery tip when estimation is zero
authorjackqdyulei <jackqdyulei@google.com>
Thu, 14 Jun 2018 21:53:59 +0000 (14:53 -0700)
committerjackqdyulei <jackqdyulei@google.com>
Thu, 14 Jun 2018 21:53:59 +0000 (14:53 -0700)
It means invalid when estimation is zero. We should catch this case
int LowBatteryDetector and don't show it.

Change-Id: I01dd50616f54162a6688257f4bdb329dfa351bc5
Fixes: 110226028
Test: RunSettingsRoboTests

src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java
tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetectorTest.java

index c3f9b07..21cc28a 100644 (file)
@@ -47,7 +47,7 @@ public class LowBatteryDetector implements BatteryTipDetector {
     public BatteryTip detect() {
         final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
         final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel
-                || (mBatteryInfo.discharging
+                || (mBatteryInfo.discharging && mBatteryInfo.remainingTimeUs != 0
                 && mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour));
 
         int state = BatteryTip.StateType.INVISIBLE;
index 9764559..657a5e3 100644 (file)
@@ -106,6 +106,13 @@ public class LowBatteryDetectorTest {
     }
 
     @Test
+    public void testDetect_timeEstimationZero_tipInvisible() {
+        mBatteryInfo.batteryLevel = 50;
+        mBatteryInfo.remainingTimeUs = 0;
+        assertThat(mLowBatteryDetector.detect().isVisible()).isFalse();
+    }
+
+    @Test
     public void testDetect_noEarlyWarning_tipInvisible() {
         mBatteryInfo.remainingTimeUs = TimeUnit.DAYS.toMicros(1);
         mBatteryInfo.batteryLevel = 100;