Loading src/com/android/settings/fuelgauge/BatteryInfo.java +4 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ public class BatteryInfo { public int batteryStatus; public int pluggedStatus; public boolean discharging = true; public boolean isBatteryDefender; public boolean isBatteryDefender = false; public boolean isLongLife = false; public boolean isFastCharging; public long remainingTimeUs = 0; public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN; Loading Loading @@ -306,7 +307,7 @@ public class BatteryInfo { info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); info.mCharging = info.pluggedStatus != 0; info.averageTimeToDischarge = estimate.getAverageDischargeTime(); info.isBatteryDefender = info.isLongLife = batteryBroadcast.getIntExtra( BatteryManager.EXTRA_CHARGING_STATUS, BatteryManager.CHARGING_POLICY_DEFAULT) Loading @@ -319,7 +320,7 @@ public class BatteryInfo { info.isFastCharging = BatteryStatus.getChargingSpeed(context, batteryBroadcast) == BatteryStatus.CHARGING_FAST; if (info.isBatteryDefender) { if (info.isLongLife) { info.isBatteryDefender = FeatureFactory.getFeatureFactory() .getPowerUsageFeatureProvider() Loading src/com/android/settings/fuelgauge/BatteryUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -600,12 +600,12 @@ public class BatteryUtils { context.getContentResolver(), SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0) == 1) { return DockDefenderMode.TEMPORARILY_BYPASSED; } else if (batteryInfo.isBatteryDefender } else if (batteryInfo.isLongLife && FeatureFactory.getFeatureFactory() .getPowerUsageFeatureProvider() .isExtraDefend()) { return DockDefenderMode.ACTIVE; } else if (!batteryInfo.isBatteryDefender) { } else if (!batteryInfo.isLongLife) { return DockDefenderMode.FUTURE_BYPASS; } } Loading src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider @Override public boolean isBatteryDefend(BatteryInfo info) { return info.isBatteryDefender && !isExtraDefend(); return info.isLongLife && !isExtraDefend(); } @Override Loading src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java +3 −6 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.Context; import com.android.settings.fuelgauge.BatteryInfo; import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.overlay.FeatureFactory; /** Detect whether the battery is overheated */ public class BatteryDefenderDetector implements BatteryTipDetector { Loading @@ -35,12 +34,10 @@ public class BatteryDefenderDetector implements BatteryTipDetector { @Override public BatteryTip detect() { final boolean isBasicBatteryDefend = FeatureFactory.getFeatureFactory() .getPowerUsageFeatureProvider() .isBatteryDefend(mBatteryInfo); final int state = isBasicBatteryDefend ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE; mBatteryInfo.isBatteryDefender ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE; final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0; return new BatteryDefenderTip(state, isPluggedIn); } Loading tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java +43 −0 Original line number Diff line number Diff line Loading @@ -789,6 +789,40 @@ public class BatteryInfoTest { expectedChargeLabel); } @Test public void getBatteryInfo_longlife_shouldSetLonglife() { var batteryIntent = createIntentForLongLifeTest(/* hasLongLife= */ true); var batteryInfo = BatteryInfo.getBatteryInfo( mContext, batteryIntent, mBatteryUsageStats, /* estimate= */ MOCK_ESTIMATE, /* elapsedRealtimeUs= */ 0L, /* shortString= */ false, /* currentTimeMs= */ 0L); assertThat(batteryInfo.isLongLife).isTrue(); } @Test public void getBatteryInfo_noLonglife_shouldNotLonglife() { var batteryIntent = createIntentForLongLifeTest(/* hasLongLife= */ false); var batteryInfo = BatteryInfo.getBatteryInfo( mContext, batteryIntent, mBatteryUsageStats, /* estimate= */ MOCK_ESTIMATE, /* elapsedRealtimeUs= */ 0L, /* shortString= */ false, /* currentTimeMs= */ 0L); assertThat(batteryInfo.isLongLife).isFalse(); } private enum ChargingSpeed { FAST, REGULAR, Loading @@ -801,6 +835,15 @@ public class BatteryInfoTest { DOCKED } private Intent createIntentForLongLifeTest(Boolean hasLongLife) { return new Intent(Intent.ACTION_BATTERY_CHANGED) .putExtra( BatteryManager.EXTRA_CHARGING_STATUS, hasLongLife ? BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE : BatteryManager.CHARGING_POLICY_DEFAULT); } private Intent createIntentForGetBatteryInfoTest( ChargingType chargingType, ChargingSpeed chargingSpeed, int batteryLevel) { return createBatteryIntent( Loading Loading
src/com/android/settings/fuelgauge/BatteryInfo.java +4 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,8 @@ public class BatteryInfo { public int batteryStatus; public int pluggedStatus; public boolean discharging = true; public boolean isBatteryDefender; public boolean isBatteryDefender = false; public boolean isLongLife = false; public boolean isFastCharging; public long remainingTimeUs = 0; public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN; Loading Loading @@ -306,7 +307,7 @@ public class BatteryInfo { info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); info.mCharging = info.pluggedStatus != 0; info.averageTimeToDischarge = estimate.getAverageDischargeTime(); info.isBatteryDefender = info.isLongLife = batteryBroadcast.getIntExtra( BatteryManager.EXTRA_CHARGING_STATUS, BatteryManager.CHARGING_POLICY_DEFAULT) Loading @@ -319,7 +320,7 @@ public class BatteryInfo { info.isFastCharging = BatteryStatus.getChargingSpeed(context, batteryBroadcast) == BatteryStatus.CHARGING_FAST; if (info.isBatteryDefender) { if (info.isLongLife) { info.isBatteryDefender = FeatureFactory.getFeatureFactory() .getPowerUsageFeatureProvider() Loading
src/com/android/settings/fuelgauge/BatteryUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -600,12 +600,12 @@ public class BatteryUtils { context.getContentResolver(), SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0) == 1) { return DockDefenderMode.TEMPORARILY_BYPASSED; } else if (batteryInfo.isBatteryDefender } else if (batteryInfo.isLongLife && FeatureFactory.getFeatureFactory() .getPowerUsageFeatureProvider() .isExtraDefend()) { return DockDefenderMode.ACTIVE; } else if (!batteryInfo.isBatteryDefender) { } else if (!batteryInfo.isLongLife) { return DockDefenderMode.FUTURE_BYPASS; } } Loading
src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider @Override public boolean isBatteryDefend(BatteryInfo info) { return info.isBatteryDefender && !isExtraDefend(); return info.isLongLife && !isExtraDefend(); } @Override Loading
src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java +3 −6 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.Context; import com.android.settings.fuelgauge.BatteryInfo; import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.overlay.FeatureFactory; /** Detect whether the battery is overheated */ public class BatteryDefenderDetector implements BatteryTipDetector { Loading @@ -35,12 +34,10 @@ public class BatteryDefenderDetector implements BatteryTipDetector { @Override public BatteryTip detect() { final boolean isBasicBatteryDefend = FeatureFactory.getFeatureFactory() .getPowerUsageFeatureProvider() .isBatteryDefend(mBatteryInfo); final int state = isBasicBatteryDefend ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE; mBatteryInfo.isBatteryDefender ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE; final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0; return new BatteryDefenderTip(state, isPluggedIn); } Loading
tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java +43 −0 Original line number Diff line number Diff line Loading @@ -789,6 +789,40 @@ public class BatteryInfoTest { expectedChargeLabel); } @Test public void getBatteryInfo_longlife_shouldSetLonglife() { var batteryIntent = createIntentForLongLifeTest(/* hasLongLife= */ true); var batteryInfo = BatteryInfo.getBatteryInfo( mContext, batteryIntent, mBatteryUsageStats, /* estimate= */ MOCK_ESTIMATE, /* elapsedRealtimeUs= */ 0L, /* shortString= */ false, /* currentTimeMs= */ 0L); assertThat(batteryInfo.isLongLife).isTrue(); } @Test public void getBatteryInfo_noLonglife_shouldNotLonglife() { var batteryIntent = createIntentForLongLifeTest(/* hasLongLife= */ false); var batteryInfo = BatteryInfo.getBatteryInfo( mContext, batteryIntent, mBatteryUsageStats, /* estimate= */ MOCK_ESTIMATE, /* elapsedRealtimeUs= */ 0L, /* shortString= */ false, /* currentTimeMs= */ 0L); assertThat(batteryInfo.isLongLife).isFalse(); } private enum ChargingSpeed { FAST, REGULAR, Loading @@ -801,6 +835,15 @@ public class BatteryInfoTest { DOCKED } private Intent createIntentForLongLifeTest(Boolean hasLongLife) { return new Intent(Intent.ACTION_BATTERY_CHANGED) .putExtra( BatteryManager.EXTRA_CHARGING_STATUS, hasLongLife ? BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE : BatteryManager.CHARGING_POLICY_DEFAULT); } private Intent createIntentForGetBatteryInfoTest( ChargingType chargingType, ChargingSpeed chargingSpeed, int batteryLevel) { return createBatteryIntent( Loading