Merge "Add charging string V2 for settings" into main

This commit is contained in:
Pajace Chen
2024-04-11 10:38:40 +00:00
committed by Android (Google) Code Review
4 changed files with 504 additions and 46 deletions

View File

@@ -30,6 +30,7 @@ import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
import android.os.BatteryManager;
import android.os.PowerManager;
import android.os.SystemProperties;
import androidx.preference.PreferenceScreen;
@@ -42,6 +43,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;
@@ -105,6 +107,8 @@ public class BatteryHeaderPreferenceControllerTest {
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref;
mController.mBatteryStatusFeatureProvider = mBatteryStatusFeatureProvider;
BatteryUtils.setChargingStringV2Enabled(null);
}
@After
@@ -223,6 +227,67 @@ 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) {
SystemProperties.set(
BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY,
String.valueOf(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);

View File

@@ -17,6 +17,7 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -30,12 +31,14 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.AlarmManager;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.BatteryUsageStats;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.SparseIntArray;
@@ -56,6 +59,9 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.time.Duration;
import java.time.Instant;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@RunWith(RobolectricTestRunner.class)
@@ -80,11 +86,23 @@ public class BatteryInfoTest {
1000, /* estimateMillis */
false, /* isBasedOnUsage */
1000 /* averageDischargeTime */);
private static final Map<ChargingType, Integer> CHARGING_TYPE_MAP =
Map.of(
ChargingType.WIRED, BatteryManager.BATTERY_PLUGGED_AC,
ChargingType.WIRELESS, BatteryManager.BATTERY_PLUGGED_WIRELESS,
ChargingType.DOCKED, BatteryManager.BATTERY_PLUGGED_DOCK);
private static final Map<ChargingSpeed, Integer> CHARGING_SPEED_MAP =
Map.of(
ChargingSpeed.FAST, 1501000,
ChargingSpeed.REGULAR, 1500000,
ChargingSpeed.SLOW, 999999);
private static final long UNUSED_TIME_MS = -1L;
private Intent mDisChargingBatteryBroadcast;
private Intent mChargingBatteryBroadcast;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@Mock private BatteryUsageStats mBatteryUsageStats;
@Before
@@ -102,10 +120,13 @@ public class BatteryInfoTest {
mContext.getContentResolver(),
BatteryUtils.SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS,
0);
// Reset static cache for testing purpose.
com.android.settingslib.fuelgauge.BatteryUtils.setChargingStringV2Enabled(null);
}
@Test
public void testGetBatteryInfo_hasStatusLabel() {
public void getBatteryInfo_hasStatusLabel() {
doReturn(REMAINING_TIME_NULL).when(mBatteryUsageStats).getBatteryTimeRemainingMs();
BatteryInfo info =
BatteryInfo.getBatteryInfoOld(
@@ -119,7 +140,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_doNotShowChargingMethod_hasRemainingTime() {
public void getBatteryInfo_doNotShowChargingMethod_hasRemainingTime() {
doReturn(REMAINING_TIME).when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo info =
BatteryInfo.getBatteryInfoOld(
@@ -133,7 +154,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_doNotShowChargingMethod_noRemainingTime() {
public void getBatteryInfo_doNotShowChargingMethod_noRemainingTime() {
doReturn(REMAINING_TIME_NULL).when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo info =
BatteryInfo.getBatteryInfoOld(
@@ -147,7 +168,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_pluggedInUsingShortString_usesCorrectData() {
public void getBatteryInfo_pluggedInUsingShortString_usesCorrectData() {
doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
@@ -164,7 +185,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_basedOnUsageTrueMoreThanFifteenMinutes_usesCorrectString() {
public void getBatteryInfo_basedOnUsageTrueMoreThanFifteenMinutes_usesCorrectString() {
Estimate estimate =
new Estimate(
Duration.ofHours(4).toMillis(),
@@ -215,7 +236,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_basedOnUsageFalse_usesDefaultString() {
public void getBatteryInfo_basedOnUsageFalse_usesDefaultString() {
BatteryInfo info =
BatteryInfo.getBatteryInfo(
mContext,
@@ -238,7 +259,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_charging_usesChargeTime() {
public void getBatteryInfo_charging_usesChargeTime() {
doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
@@ -258,7 +279,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_pluggedInWithFullBattery_onlyShowBatteryLevel() {
public void getBatteryInfo_pluggedInWithFullBattery_onlyShowBatteryLevel() {
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 100);
BatteryInfo info =
@@ -274,7 +295,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_chargingWithDefender_updateChargeLabel() {
public void getBatteryInfo_chargingWithDefender_updateChargeLabel() {
doReturn(TEST_CHARGE_TIME_REMAINING).when(mBatteryUsageStats).getChargeTimeRemainingMs();
mChargingBatteryBroadcast.putExtra(
BatteryManager.EXTRA_CHARGING_STATUS,
@@ -294,7 +315,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_getChargeTimeRemaining_updateSettingsGlobal() {
public void getBatteryInfo_getChargeTimeRemaining_updateSettingsGlobal() {
doReturn(TEST_CHARGE_TIME_REMAINING).when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo.getBatteryInfo(
@@ -310,7 +331,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_differentChargeTimeRemaining_updateSettingsGlobal() {
public void getBatteryInfo_differentChargeTimeRemaining_updateSettingsGlobal() {
doReturn(TEST_CHARGE_TIME_REMAINING).when(mBatteryUsageStats).getChargeTimeRemainingMs();
final long newTimeToFull = 300L;
doReturn(newTimeToFull).when(mBatteryUsageStats).getChargeTimeRemainingMs();
@@ -327,16 +348,15 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_dockDefenderActive_updateChargeString() {
public void getBatteryInfo_dockDefenderActive_updateChargeString() {
doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
Intent intent =
BatteryTestUtils.getCustomBatteryIntent(
createBatteryIntent(
BatteryManager.BATTERY_PLUGGED_DOCK,
50 /* level */,
100 /* scale */,
/* level= */ 50,
BatteryManager.BATTERY_STATUS_CHARGING)
.putExtra(
BatteryManager.EXTRA_CHARGING_STATUS,
@@ -355,7 +375,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_dockDefenderTemporarilyBypassed_updateChargeLabel() {
public void getBatteryInfo_dockDefenderTemporarilyBypassed_updateChargeLabel() {
doReturn(REMAINING_TIME).when(mBatteryUsageStats).getChargeTimeRemainingMs();
mChargingBatteryBroadcast.putExtra(
BatteryManager.EXTRA_CHARGING_STATUS, BatteryManager.CHARGING_POLICY_DEFAULT);
@@ -367,10 +387,9 @@ public class BatteryInfoTest {
BatteryInfo info =
BatteryInfo.getBatteryInfo(
mContext,
BatteryTestUtils.getCustomBatteryIntent(
createBatteryIntent(
BatteryManager.BATTERY_PLUGGED_DOCK,
50 /* level */,
100 /* scale */,
/* level= */ 50,
BatteryManager.BATTERY_STATUS_CHARGING),
mBatteryUsageStats,
MOCK_ESTIMATE,
@@ -381,7 +400,7 @@ public class BatteryInfoTest {
}
@Test
public void testGetBatteryInfo_dockDefenderFutureBypass_updateChargeLabel() {
public void getBatteryInfo_dockDefenderFutureBypass_updateChargeLabel() {
doReturn(false).when(mFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
mChargingBatteryBroadcast.putExtra(
BatteryManager.EXTRA_CHARGING_STATUS, BatteryManager.CHARGING_POLICY_DEFAULT);
@@ -389,10 +408,9 @@ public class BatteryInfoTest {
BatteryInfo info =
BatteryInfo.getBatteryInfo(
mContext,
BatteryTestUtils.getCustomBatteryIntent(
createBatteryIntent(
BatteryManager.BATTERY_PLUGGED_DOCK,
50 /* level */,
100 /* scale */,
/* level= */ 50,
BatteryManager.BATTERY_STATUS_CHARGING),
mBatteryUsageStats,
MOCK_ESTIMATE,
@@ -402,6 +420,284 @@ public class BatteryInfoTest {
assertThat(info.chargeLabel.toString()).contains(STATUS_CHARGING_FUTURE_BYPASS);
}
@Test
public void getBatteryInfo_fastCharging_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(90).toMillis(),
/* chargingStringV2Enabled= */ false);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.FAST, /* batteryLevel= */ 61);
var expectedStatusLabel = "Charging rapidly";
var expectedRemainingLabel = "1 hr, 30 min left until full";
var expectedChargeLabel = "61% - " + expectedRemainingLabel;
assertGetBatteryInfo(
batteryIntent,
/* currentTimeMillis= */ UNUSED_TIME_MS,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_regularCharging_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(80).toMillis(),
/* chargingStringV2Enabled= */ false);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 33);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "1 hr, 20 min left until full";
var expectedChargeLabel = "33% - " + expectedRemainingLabel;
assertGetBatteryInfo(
batteryIntent,
/* currentTimeMillis= */ UNUSED_TIME_MS,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_slowCharging_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(100).toMillis(),
/* chargingStringV2Enabled= */ false);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.SLOW, /* batteryLevel= */ 53);
var expectedStatusLabel = "Charging slowly";
var expectedRemainingLabel = "1 hr, 40 min left until full";
var expectedChargeLabel = "53% - " + expectedRemainingLabel;
assertGetBatteryInfo(
batteryIntent,
/* currentTimeMillis= */ UNUSED_TIME_MS,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_wirelessCharging_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
/* chargingStringV2Enabled= */ false);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRELESS, ChargingSpeed.REGULAR, /* batteryLevel= */ 10);
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);
}
@Test
public void getBatteryInfo_dockedCharging_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(30).toMillis(),
/* chargingStringV2Enabled= */ false);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.DOCKED, ChargingSpeed.REGULAR, /* batteryLevel= */ 51);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "30 min left until full";
var expectedChargeLabel = "51% - " + expectedRemainingLabel;
assertGetBatteryInfo(
batteryIntent,
/* currentTimeMillis= */ UNUSED_TIME_MS,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_fastChargingV2_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofMinutes(30).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.FAST, /* batteryLevel= */ 56);
var expectedStatusLabel = "Fast charging";
var expectedRemainingLabel = "Full by 1:30PM";
var expectedChargeLabel = "56% - " + expectedStatusLabel + " - " + expectedRemainingLabel;
var currentTimeMillis = Instant.parse("2024-04-01T13:00:00Z").toEpochMilli();
assertGetBatteryInfo(
batteryIntent,
currentTimeMillis,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_regularChargingV2_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofHours(1).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 12);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "Fully charged by 2:00PM";
var expectedChargeLabel = "12% - " + expectedRemainingLabel;
var currentTimeMillis = Instant.parse("2024-04-01T13:00:00Z").toEpochMilli();
assertGetBatteryInfo(
batteryIntent,
currentTimeMillis,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_slowChargingV2_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofHours(2).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.SLOW, /* batteryLevel= */ 18);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "Fully charged by 3:00PM";
var expectedChargeLabel = "18% - " + expectedRemainingLabel;
var currentTimeMillis = Instant.parse("2024-04-01T13:00:00Z").toEpochMilli();
assertGetBatteryInfo(
batteryIntent,
currentTimeMillis,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_wirelessChargingV2_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofHours(1).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRELESS, ChargingSpeed.REGULAR, /* batteryLevel= */ 45);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "Fully charged by 4:00PM";
var expectedChargeLabel = "45% - " + expectedRemainingLabel;
var currentTimeMillis = Instant.parse("2024-04-01T15:00:00Z").toEpochMilli();
assertGetBatteryInfo(
batteryIntent,
currentTimeMillis,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
@Test
public void getBatteryInfo_dockedChargingV2_updateRemainingLabelAndStatusLabel() {
prepareTestGetBatteryInfoEnvironment(
/* remainingTimeMs= */ Duration.ofHours(1).toMillis(),
/* chargingStringV2Enabled= */ true);
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.DOCKED, ChargingSpeed.REGULAR, /* batteryLevel= */ 66);
var expectedStatusLabel = "Charging";
var expectedRemainingLabel = "Fully charged by 2:00PM";
var expectedChargeLabel = "66% - " + expectedRemainingLabel;
var currentTimeMillis = Instant.parse("2021-02-09T13:00:00.00Z").toEpochMilli();
assertGetBatteryInfo(
batteryIntent,
currentTimeMillis,
expectedStatusLabel,
expectedRemainingLabel,
expectedChargeLabel);
}
private enum ChargingSpeed {
FAST,
REGULAR,
SLOW
}
private enum ChargingType {
WIRED,
WIRELESS,
DOCKED
}
private Intent createIntentForGetBatteryInfoTest(
ChargingType chargingType, ChargingSpeed chargingSpeed, int batteryLevel) {
return createBatteryIntent(
CHARGING_TYPE_MAP.get(chargingType),
batteryLevel,
BatteryManager.BATTERY_STATUS_CHARGING)
.putExtra(
BatteryManager.EXTRA_MAX_CHARGING_CURRENT,
CHARGING_SPEED_MAP.get(chargingSpeed))
.putExtra(BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE, 5000000);
}
private void prepareTestGetBatteryInfoEnvironment(
long remainingTimeMs, boolean chargingStringV2Enabled) {
when(mBatteryUsageStats.getChargeTimeRemainingMs()).thenReturn(remainingTimeMs);
SystemProperties.set(
com.android.settingslib.fuelgauge.BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY,
String.valueOf(chargingStringV2Enabled));
Settings.Global.putInt(
mContext.getContentResolver(),
BatteryUtils.SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS,
1);
}
private void assertGetBatteryInfo(
Intent batteryIntent,
long currentTimeMillis,
String expectedStatusLabel,
String expectedRemainingLabel,
String expectedChargeLabel) {
mContext.getResources().getConfiguration().setLocale(Locale.US);
mContext.getSystemService(AlarmManager.class).setTimeZone("UTC");
var info =
BatteryInfo.getBatteryInfo(
mContext,
batteryIntent,
mBatteryUsageStats,
MOCK_ESTIMATE,
/* elapsedRealtimeUs= */ UNUSED_TIME_MS,
/* shortString= */ false,
/* currentTimeMillis= */ currentTimeMillis);
assertWithMessage("statusLabel is incorrect")
.that(info.statusLabel)
.isEqualTo(expectedStatusLabel);
assertWithMessage("remainingLabel is incorrect")
.that(info.remainingLabel.toString())
.isEqualTo(expectedRemainingLabel);
assertWithMessage("chargeLabel is incorrect")
.that(info.chargeLabel.toString())
.isEqualTo(expectedChargeLabel);
}
private static Intent createBatteryIntent(int plugged, int level, int status) {
return new Intent()
.putExtra(BatteryManager.EXTRA_PLUGGED, plugged)
.putExtra(BatteryManager.EXTRA_LEVEL, level)
.putExtra(BatteryManager.EXTRA_SCALE, 100)
.putExtra(BatteryManager.EXTRA_STATUS, status);
}
// Make our battery stats return a sequence of battery events.
private void mockBatteryStatsHistory() {
// Mock out new data every time iterateBatteryStatsHistory is called.