Merge "Move battery unplug command to the beginning of the test" am: 7691152162
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1769295 Change-Id: Idc76e3cc8268579f52ab98fbbc17aed34205ce99
This commit is contained in:
@@ -87,21 +87,36 @@ public class BatteryStatsManagerTest{
|
|||||||
@SkipPresubmit(reason = "Virtual hardware does not support wifi battery stats")
|
@SkipPresubmit(reason = "Virtual hardware does not support wifi battery stats")
|
||||||
public void testReportNetworkInterfaceForTransports() throws Exception {
|
public void testReportNetworkInterfaceForTransports() throws Exception {
|
||||||
try {
|
try {
|
||||||
final Network cellNetwork = mCtsNetUtils.connectToCell();
|
// Simulate the device being unplugged from charging.
|
||||||
final URL url = new URL(TEST_URL);
|
executeShellCommand("cmd battery unplug");
|
||||||
|
executeShellCommand("cmd battery set status " + BATTERY_STATUS_DISCHARGING);
|
||||||
|
// Reset all current stats before starting test.
|
||||||
|
executeShellCommand("dumpsys batterystats --reset");
|
||||||
|
// Do not automatically reset the stats when the devices are unplugging after the
|
||||||
|
// battery was last full or the level is 100, or have gone through a significant
|
||||||
|
// charge.
|
||||||
|
executeShellCommand("dumpsys batterystats enable no-auto-reset");
|
||||||
|
// Upon calling "cmd battery unplug" a task is scheduled on the battery
|
||||||
|
// stats worker thread. Because network battery stats are only recorded
|
||||||
|
// when the device is on battery, this test needs to wait until the
|
||||||
|
// battery status is recorded because causing traffic.
|
||||||
|
// Writing stats to disk is unnecessary, but --write waits for the worker
|
||||||
|
// thread to finish processing the enqueued tasks as a side effect. This
|
||||||
|
// side effect is the point of using --write here.
|
||||||
|
executeShellCommand("dumpsys batterystats --write");
|
||||||
|
|
||||||
// Make sure wifi is disabled.
|
// Make sure wifi is disabled.
|
||||||
mCtsNetUtils.ensureWifiDisconnected(null /* wifiNetworkToCheck */);
|
mCtsNetUtils.ensureWifiDisconnected(null /* wifiNetworkToCheck */);
|
||||||
// Simulate the device being unplugged from charging.
|
|
||||||
executeShellCommand("dumpsys battery unplug");
|
final Network cellNetwork = mCtsNetUtils.connectToCell();
|
||||||
executeShellCommand("dumpsys battery set status " + BATTERY_STATUS_DISCHARGING);
|
final URL url = new URL(TEST_URL);
|
||||||
executeShellCommand("dumpsys batterystats enable pretend-screen-off");
|
|
||||||
|
|
||||||
// Get cellular battery stats
|
// Get cellular battery stats
|
||||||
CellularBatteryStats cellularStatsBefore = runAsShell(UPDATE_DEVICE_STATS,
|
CellularBatteryStats cellularStatsBefore = runAsShell(UPDATE_DEVICE_STATS,
|
||||||
mBsm::getCellularBatteryStats);
|
mBsm::getCellularBatteryStats);
|
||||||
|
|
||||||
// Generate traffic on cellular network.
|
// Generate traffic on cellular network.
|
||||||
|
Log.d(TAG, "Generate traffic on cellular network.");
|
||||||
generateNetworkTraffic(cellNetwork, url);
|
generateNetworkTraffic(cellNetwork, url);
|
||||||
|
|
||||||
// The mobile battery stats are updated when a network stops being the default network.
|
// The mobile battery stats are updated when a network stops being the default network.
|
||||||
@@ -119,6 +134,7 @@ public class BatteryStatsManagerTest{
|
|||||||
mBsm::getWifiBatteryStats);
|
mBsm::getWifiBatteryStats);
|
||||||
|
|
||||||
// Generate traffic on wifi network.
|
// Generate traffic on wifi network.
|
||||||
|
Log.d(TAG, "Generate traffic on wifi network.");
|
||||||
generateNetworkTraffic(wifiNetwork, url);
|
generateNetworkTraffic(wifiNetwork, url);
|
||||||
// Wifi battery stats are updated when wifi on.
|
// Wifi battery stats are updated when wifi on.
|
||||||
mCtsNetUtils.toggleWifi();
|
mCtsNetUtils.toggleWifi();
|
||||||
@@ -130,8 +146,8 @@ public class BatteryStatsManagerTest{
|
|||||||
wifiStatsAfter)));
|
wifiStatsAfter)));
|
||||||
} finally {
|
} finally {
|
||||||
// Reset battery settings.
|
// Reset battery settings.
|
||||||
executeShellCommand("dumpsys battery reset");
|
executeShellCommand("dumpsys batterystats disable no-auto-reset");
|
||||||
executeShellCommand("dumpsys batterystats disable pretend-screen-off");
|
executeShellCommand("cmd battery reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user