Merge "Fix "Dock defend string and tips in settings are incorrectly" issue" into main
This commit is contained in:
@@ -53,7 +53,8 @@ public class BatteryInfo {
|
|||||||
public int batteryStatus;
|
public int batteryStatus;
|
||||||
public int pluggedStatus;
|
public int pluggedStatus;
|
||||||
public boolean discharging = true;
|
public boolean discharging = true;
|
||||||
public boolean isBatteryDefender;
|
public boolean isBatteryDefender = false;
|
||||||
|
public boolean isLongLife = false;
|
||||||
public boolean isFastCharging;
|
public boolean isFastCharging;
|
||||||
public long remainingTimeUs = 0;
|
public long remainingTimeUs = 0;
|
||||||
public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
|
public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
|
||||||
@@ -306,7 +307,7 @@ public class BatteryInfo {
|
|||||||
info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
||||||
info.mCharging = info.pluggedStatus != 0;
|
info.mCharging = info.pluggedStatus != 0;
|
||||||
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
|
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
|
||||||
info.isBatteryDefender =
|
info.isLongLife =
|
||||||
batteryBroadcast.getIntExtra(
|
batteryBroadcast.getIntExtra(
|
||||||
BatteryManager.EXTRA_CHARGING_STATUS,
|
BatteryManager.EXTRA_CHARGING_STATUS,
|
||||||
BatteryManager.CHARGING_POLICY_DEFAULT)
|
BatteryManager.CHARGING_POLICY_DEFAULT)
|
||||||
@@ -319,7 +320,7 @@ public class BatteryInfo {
|
|||||||
info.isFastCharging =
|
info.isFastCharging =
|
||||||
BatteryStatus.getChargingSpeed(context, batteryBroadcast)
|
BatteryStatus.getChargingSpeed(context, batteryBroadcast)
|
||||||
== BatteryStatus.CHARGING_FAST;
|
== BatteryStatus.CHARGING_FAST;
|
||||||
if (info.isBatteryDefender) {
|
if (info.isLongLife) {
|
||||||
info.isBatteryDefender =
|
info.isBatteryDefender =
|
||||||
FeatureFactory.getFeatureFactory()
|
FeatureFactory.getFeatureFactory()
|
||||||
.getPowerUsageFeatureProvider()
|
.getPowerUsageFeatureProvider()
|
||||||
|
@@ -600,7 +600,7 @@ public class BatteryUtils {
|
|||||||
context.getContentResolver(), SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0)
|
context.getContentResolver(), SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0)
|
||||||
== 1) {
|
== 1) {
|
||||||
return DockDefenderMode.TEMPORARILY_BYPASSED;
|
return DockDefenderMode.TEMPORARILY_BYPASSED;
|
||||||
} else if (batteryInfo.isBatteryDefender
|
} else if (batteryInfo.isLongLife
|
||||||
&& FeatureFactory.getFeatureFactory()
|
&& FeatureFactory.getFeatureFactory()
|
||||||
.getPowerUsageFeatureProvider()
|
.getPowerUsageFeatureProvider()
|
||||||
.isExtraDefend()) {
|
.isExtraDefend()) {
|
||||||
|
@@ -789,6 +789,40 @@ public class BatteryInfoTest {
|
|||||||
expectedChargeLabel);
|
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 {
|
private enum ChargingSpeed {
|
||||||
FAST,
|
FAST,
|
||||||
REGULAR,
|
REGULAR,
|
||||||
@@ -801,6 +835,15 @@ public class BatteryInfoTest {
|
|||||||
DOCKED
|
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(
|
private Intent createIntentForGetBatteryInfoTest(
|
||||||
ChargingType chargingType, ChargingSpeed chargingSpeed, int batteryLevel) {
|
ChargingType chargingType, ChargingSpeed chargingSpeed, int batteryLevel) {
|
||||||
return createBatteryIntent(
|
return createBatteryIntent(
|
||||||
|
Reference in New Issue
Block a user