Merge "Fix "Dock defend string and tips in settings are incorrectly" issue" into main

This commit is contained in:
YK Hung
2024-06-26 11:11:11 +00:00
committed by Android (Google) Code Review
3 changed files with 48 additions and 4 deletions

View File

@@ -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,
@@ -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(