Loading src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java +1 −5 Original line number Diff line number Diff line Loading @@ -23,8 +23,6 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; import java.util.concurrent.TimeUnit; /** * Detect whether the battery is too low */ Loading @@ -46,9 +44,7 @@ public class LowBatteryDetector implements BatteryTipDetector { @Override public BatteryTip detect() { final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel || (mBatteryInfo.discharging && mBatteryInfo.remainingTimeUs != 0 && mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour)); final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel; final boolean lowBatteryEnabled = mPolicy.lowBatteryEnabled && !mIsPowerSaveMode; final boolean dischargingLowBatteryState = mPolicy.testLowBatteryTip || (mBatteryInfo.discharging && lowBattery); Loading src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java +10 −4 Original line number Diff line number Diff line Loading @@ -116,8 +116,16 @@ public final class BatteryUsageDataLoader { final Handler handler = new Handler(Looper.getMainLooper()); final BatteryLevelData batteryLevelData = DataProcessManager.getBatteryLevelData( context, handler, /*isFromPeriodJob=*/ true, batteryDiffDataMap -> DatabaseUtils.sendBatteryUsageSlotData(context, ConvertUtils.convertToBatteryUsageSlotList(batteryDiffDataMap))); batteryDiffDataMap -> { DatabaseUtils.sendBatteryUsageSlotData(context, ConvertUtils.convertToBatteryUsageSlotList(batteryDiffDataMap)); if (batteryDiffDataMap.values().stream().anyMatch(data -> (!data.getAppDiffEntryList().isEmpty() || !data.getSystemDiffEntryList().isEmpty()))) { FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context) .detectSettingsAnomaly(context, /* displayDrain= */ 0); } }); if (batteryLevelData == null) { Log.d(TAG, "preprocessBatteryUsageSlots() no new battery usage data."); return; Loading @@ -139,8 +147,6 @@ public final class BatteryUsageDataLoader { // No app usage data or battery diff data at this time. loadAppUsageData(context); preprocessBatteryUsageSlots(context); FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context) .detectSettingsAnomaly(context, /* displayDrain= */ 0); } Log.d(TAG, String.format( "loadUsageDataSafely() in %d/ms", System.currentTimeMillis() - start)); Loading tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetectorTest.java +3 −8 Original line number Diff line number Diff line Loading @@ -53,7 +53,6 @@ public class LowBatteryDetectorTest { mPolicy = spy(new BatteryTipPolicy(RuntimeEnvironment.application)); mContext = RuntimeEnvironment.application; ReflectionHelpers.setField(mPolicy, "lowBatteryEnabled", true); ReflectionHelpers.setField(mPolicy, "lowBatteryHour", 3); mBatteryInfo.discharging = true; mLowBatteryDetector = new LowBatteryDetector(mContext, mPolicy, mBatteryInfo, Loading @@ -78,13 +77,9 @@ public class LowBatteryDetectorTest { @Test public void testDetect_lowBattery_tipNew() { mBatteryInfo.batteryLevel = 3; mBatteryInfo.batteryLevel = 20; mBatteryInfo.remainingTimeUs = TimeUnit.DAYS.toMillis(1); assertThat(mLowBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW); mBatteryInfo.batteryLevel = 50; mBatteryInfo.remainingTimeUs = TimeUnit.MINUTES.toMillis(1); assertThat(mLowBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW); } @Test Loading @@ -104,9 +99,9 @@ public class LowBatteryDetectorTest { } @Test public void testDetect_timeEstimationZero_tipInvisible() { public void testDetect_lowTimeEstimation_tipInvisible() { mBatteryInfo.batteryLevel = 50; mBatteryInfo.remainingTimeUs = 0; mBatteryInfo.remainingTimeUs = TimeUnit.MINUTES.toMillis(1); assertThat(mLowBatteryDetector.detect().isVisible()).isFalse(); } Loading Loading
src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java +1 −5 Original line number Diff line number Diff line Loading @@ -23,8 +23,6 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; import java.util.concurrent.TimeUnit; /** * Detect whether the battery is too low */ Loading @@ -46,9 +44,7 @@ public class LowBatteryDetector implements BatteryTipDetector { @Override public BatteryTip detect() { final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel || (mBatteryInfo.discharging && mBatteryInfo.remainingTimeUs != 0 && mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour)); final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel; final boolean lowBatteryEnabled = mPolicy.lowBatteryEnabled && !mIsPowerSaveMode; final boolean dischargingLowBatteryState = mPolicy.testLowBatteryTip || (mBatteryInfo.discharging && lowBattery); Loading
src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java +10 −4 Original line number Diff line number Diff line Loading @@ -116,8 +116,16 @@ public final class BatteryUsageDataLoader { final Handler handler = new Handler(Looper.getMainLooper()); final BatteryLevelData batteryLevelData = DataProcessManager.getBatteryLevelData( context, handler, /*isFromPeriodJob=*/ true, batteryDiffDataMap -> DatabaseUtils.sendBatteryUsageSlotData(context, ConvertUtils.convertToBatteryUsageSlotList(batteryDiffDataMap))); batteryDiffDataMap -> { DatabaseUtils.sendBatteryUsageSlotData(context, ConvertUtils.convertToBatteryUsageSlotList(batteryDiffDataMap)); if (batteryDiffDataMap.values().stream().anyMatch(data -> (!data.getAppDiffEntryList().isEmpty() || !data.getSystemDiffEntryList().isEmpty()))) { FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context) .detectSettingsAnomaly(context, /* displayDrain= */ 0); } }); if (batteryLevelData == null) { Log.d(TAG, "preprocessBatteryUsageSlots() no new battery usage data."); return; Loading @@ -139,8 +147,6 @@ public final class BatteryUsageDataLoader { // No app usage data or battery diff data at this time. loadAppUsageData(context); preprocessBatteryUsageSlots(context); FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context) .detectSettingsAnomaly(context, /* displayDrain= */ 0); } Log.d(TAG, String.format( "loadUsageDataSafely() in %d/ms", System.currentTimeMillis() - start)); Loading
tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetectorTest.java +3 −8 Original line number Diff line number Diff line Loading @@ -53,7 +53,6 @@ public class LowBatteryDetectorTest { mPolicy = spy(new BatteryTipPolicy(RuntimeEnvironment.application)); mContext = RuntimeEnvironment.application; ReflectionHelpers.setField(mPolicy, "lowBatteryEnabled", true); ReflectionHelpers.setField(mPolicy, "lowBatteryHour", 3); mBatteryInfo.discharging = true; mLowBatteryDetector = new LowBatteryDetector(mContext, mPolicy, mBatteryInfo, Loading @@ -78,13 +77,9 @@ public class LowBatteryDetectorTest { @Test public void testDetect_lowBattery_tipNew() { mBatteryInfo.batteryLevel = 3; mBatteryInfo.batteryLevel = 20; mBatteryInfo.remainingTimeUs = TimeUnit.DAYS.toMillis(1); assertThat(mLowBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW); mBatteryInfo.batteryLevel = 50; mBatteryInfo.remainingTimeUs = TimeUnit.MINUTES.toMillis(1); assertThat(mLowBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW); } @Test Loading @@ -104,9 +99,9 @@ public class LowBatteryDetectorTest { } @Test public void testDetect_timeEstimationZero_tipInvisible() { public void testDetect_lowTimeEstimation_tipInvisible() { mBatteryInfo.batteryLevel = 50; mBatteryInfo.remainingTimeUs = 0; mBatteryInfo.remainingTimeUs = TimeUnit.MINUTES.toMillis(1); assertThat(mLowBatteryDetector.detect().isVisible()).isFalse(); } Loading