Sync the charge time with battery info on settings

Test: atest SettingsTests

Bug: 296793655
Change-Id: I407de30589e77ba09916f54f06f4f9c345adf330
This commit is contained in:
Trina
2023-08-09 09:38:31 +00:00
parent a9a819a5d7
commit c17809f03b
2 changed files with 46 additions and 0 deletions

View File

@@ -229,6 +229,37 @@ public class BatteryInfoTest {
assertThat(info.chargeLabel.toString()).contains(STATUS_CHARGING_PAUSED);
}
@Test
public void testGetBatteryInfo_getChargeTimeRemaining_updateSettingsGlobal() {
doReturn(TEST_CHARGE_TIME_REMAINING)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(BatteryInfo.getSettingsChargeTimeRemaining(mContext)).isEqualTo(
TEST_CHARGE_TIME_REMAINING);
}
@Test
public void testGetBatteryInfo_differentChargeTimeRemaining_updateSettingsGlobal() {
doReturn(TEST_CHARGE_TIME_REMAINING)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
final long newTimeToFull = 300L;
doReturn(newTimeToFull)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(BatteryInfo.getSettingsChargeTimeRemaining(mContext)).isEqualTo(newTimeToFull);
}
@Test
public void testGetBatteryInfo_dockDefenderActive_updateChargeString() {
doReturn(TEST_CHARGE_TIME_REMAINING / 1000)