Customize the remaining time label during wireless charging.

Bug: 336204618
Test: robotests
Change-Id: Ic7025f219ee09fba0922ac183daa891e7b63b673
This commit is contained in:
Yiling Chuang
2024-04-22 10:04:57 +00:00
parent 660986353e
commit 901a46c93e
5 changed files with 115 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertWithMessage;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
@@ -634,6 +635,81 @@ public class BatteryInfoTest {
expectedChargeLabel);
}
@Test
public void
getBatteryInfo_customizedWirelessChargingLabel_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofHours(1).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRELESS, ChargingSpeed.REGULAR, /* batteryLevel= */ 45);
CharSequence expectedLabel = "Full by 8:00 AM";
when(mFeatureFactory.batterySettingsFeatureProvider.getWirelessChargingRemainingLabel(
eq(mContext), anyLong(), anyLong()))
.thenReturn(expectedLabel);
var currentTimeMillis = Instant.parse("2021-02-09T13:00:00.00Z").toEpochMilli();
var info =
BatteryInfo.getBatteryInfo(
mContext,
batteryIntent,
mBatteryUsageStats,
MOCK_ESTIMATE,
/* elapsedRealtimeUs= */ UNUSED_TIME_MS,
/* shortString= */ false,
/* currentTimeMillis= */ currentTimeMillis);
assertThat(info.remainingLabel).isEqualTo(expectedLabel);
}
@Test
public void
getBatteryInfo_noCustomizedWirelessChargingLabel_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofHours(1).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRELESS, ChargingSpeed.REGULAR, /* batteryLevel= */ 45);
when(mFeatureFactory.batterySettingsFeatureProvider.getWirelessChargingRemainingLabel(
eq(mContext), anyLong(), anyLong()))
.thenReturn(null);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "Fully charged by";
var expectedChargeLabel = "45% - " + expectedRemainingLabel;
var currentTimeMillis = Instant.parse("2024-04-01T15:00:00Z").toEpochMilli();
assertGetBatteryInfo(
batteryIntent,
currentTimeMillis,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_noCustomWirelessChargingLabelWithV1_updateRemainingAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
/* chargingStringV2Enabled= */ false);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRELESS, ChargingSpeed.REGULAR, /* batteryLevel= */ 10);
when(mFeatureFactory.batterySettingsFeatureProvider.getWirelessChargingRemainingLabel(
eq(mContext), anyLong(), anyLong()))
.thenReturn(null);
var expectedStatusLabel = "Charging wirelessly";
var expectedRemainingLabel = "2 hr, 10 min left until full";
var expectedChargeLabel = "10% - " + expectedRemainingLabel;
assertGetBatteryInfo(
batteryIntent,
/* currentTimeMillis= */ UNUSED_TIME_MS,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
private enum ChargingSpeed {
FAST,
REGULAR,