Add charging string V2 for settings

Apply charging string V2 for settings

Bug: 328546483
Test: Manual test
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6f3c97f60a966a8ec357ba4d15b19d9d7a04b34d)
Merged-In: Ic68bf4231da81d865faa285bca97a929abe26a42
Change-Id: Ic68bf4231da81d865faa285bca97a929abe26a42
This commit is contained in:
Pajace Chen
2024-04-06 09:17:59 +08:00
parent e499724357
commit d9b44a8b9c
4 changed files with 501 additions and 46 deletions

View File

@@ -44,6 +44,7 @@ import com.android.settings.testutils.BatteryTestUtils;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.fuelgauge.BatteryUtils;
import com.android.settingslib.widget.UsageProgressBarPreference;
import org.junit.After;
@@ -107,6 +108,8 @@ public class BatteryHeaderPreferenceControllerTest {
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref;
mController.mBatteryStatusFeatureProvider = mBatteryStatusFeatureProvider;
BatteryUtils.setChargingStringV2Enabled(null);
}
@After
@@ -225,6 +228,65 @@ public class BatteryHeaderPreferenceControllerTest {
verify(mBatteryUsageProgressBarPref).setBottomSummary(label);
}
@Test
public void updateBatteryStatus_chargingString_statusWithRemainingLabel() {
var batteryInfo =
arrangeUpdateBatteryStatusTestWithRemainingLabel(
/* remainingLabel= */ "1 hr, 40 min left until full",
/* statusLabel= */ "Charging rapidly",
/* isFastCharging= */ true,
/* isChargingStringV2= */ false);
var expectedChargingString = batteryInfo.statusLabel + "" + batteryInfo.remainingLabel;
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
}
@Test
public void updateBatteryStatus_chargingStringV2FastCharging_statusWithRemainingLabel() {
var batteryInfo =
arrangeUpdateBatteryStatusTestWithRemainingLabel(
/* remainingLabel= */ "Full by 1:30 PM",
/* statusLabel= */ "Fast Charging",
/* isFastCharging= */ true,
/* isChargingStringV2= */ true);
var expectedChargingString = batteryInfo.statusLabel + "" + batteryInfo.remainingLabel;
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
}
@Test
public void updateBatteryStatus_chargingStringV2NonFastCharging_remainingLabel() {
var batteryInfo =
arrangeUpdateBatteryStatusTestWithRemainingLabel(
/* remainingLabel= */ "Fully charged by 11:10 PM",
/* statusLabel= */ "Charging",
/* isFastCharging= */ false,
/* isChargingStringV2= */ true);
var expectedChargingString = batteryInfo.remainingLabel;
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
}
private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel(
String remainingLabel,
String statusLabel,
boolean isFastCharging,
boolean isChargingStringV2) {
BatteryUtils.setChargingStringV2Enabled(isChargingStringV2);
mBatteryInfo.isBatteryDefender = false;
mBatteryInfo.remainingLabel = remainingLabel;
mBatteryInfo.statusLabel = statusLabel;
mBatteryInfo.discharging = false;
mBatteryInfo.isFastCharging = isFastCharging;
return mBatteryInfo;
}
@Test
public void updateHeaderByBatteryTips_lowBatteryTip_showLowBattery() {
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);