Merge "Test that idle apps get network when device charges." into rvc-dev
This commit is contained in:
@@ -50,7 +50,7 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
|
||||
public final void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
|
||||
turnBatteryOff();
|
||||
executeSilentShellCommand("cmd battery reset");
|
||||
setAppIdle(false);
|
||||
}
|
||||
|
||||
@@ -131,11 +131,11 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
|
||||
@RequiredProperties({BATTERY_SAVER_MODE})
|
||||
@Test
|
||||
public void testAppIdleNetworkAccess_whenCharging() throws Exception {
|
||||
// Check that idle app doesn't get network when charging
|
||||
// Check that app is paroled when charging
|
||||
setAppIdle(true);
|
||||
assertBackgroundNetworkAccess(false);
|
||||
turnBatteryOff();
|
||||
assertBackgroundNetworkAccess(false);
|
||||
assertBackgroundNetworkAccess(true);
|
||||
turnBatteryOn();
|
||||
assertBackgroundNetworkAccess(false);
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ import com.android.tradefed.targetprep.ITargetPreparer;
|
||||
public class NetworkPolicyTestsPreparer implements ITargetPreparer {
|
||||
private ITestDevice mDevice;
|
||||
private String mOriginalAppStandbyEnabled;
|
||||
private String mOriginalBatteryStatsConstants;
|
||||
private final static String KEY_STABLE_CHARGING_DELAY_MS = "battery_charged_delay_ms";
|
||||
private final static int DESIRED_STABLE_CHARGING_DELAY_MS = 0;
|
||||
|
||||
@Override
|
||||
public void setUp(TestInformation testInformation) throws DeviceNotAvailableException {
|
||||
@@ -31,12 +34,18 @@ public class NetworkPolicyTestsPreparer implements ITargetPreparer {
|
||||
mOriginalAppStandbyEnabled = getAppStandbyEnabled();
|
||||
setAppStandbyEnabled("1");
|
||||
LogUtil.CLog.d("Original app_standby_enabled: " + mOriginalAppStandbyEnabled);
|
||||
|
||||
mOriginalBatteryStatsConstants = getBatteryStatsConstants();
|
||||
setBatteryStatsConstants(
|
||||
KEY_STABLE_CHARGING_DELAY_MS + "=" + DESIRED_STABLE_CHARGING_DELAY_MS);
|
||||
LogUtil.CLog.d("Original battery_saver_constants: " + mOriginalBatteryStatsConstants);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown(TestInformation testInformation, Throwable e)
|
||||
throws DeviceNotAvailableException {
|
||||
setAppStandbyEnabled(mOriginalAppStandbyEnabled);
|
||||
setBatteryStatsConstants(mOriginalBatteryStatsConstants);
|
||||
}
|
||||
|
||||
private void setAppStandbyEnabled(String appStandbyEnabled) throws DeviceNotAvailableException {
|
||||
@@ -51,6 +60,15 @@ public class NetworkPolicyTestsPreparer implements ITargetPreparer {
|
||||
return executeCmd("settings get global app_standby_enabled").trim();
|
||||
}
|
||||
|
||||
private void setBatteryStatsConstants(String batteryStatsConstants)
|
||||
throws DeviceNotAvailableException {
|
||||
executeCmd("settings put global battery_stats_constants \"" + batteryStatsConstants + "\"");
|
||||
}
|
||||
|
||||
private String getBatteryStatsConstants() throws DeviceNotAvailableException {
|
||||
return executeCmd("settings get global battery_stats_constants");
|
||||
}
|
||||
|
||||
private String executeCmd(String cmd) throws DeviceNotAvailableException {
|
||||
final String output = mDevice.executeShellCommand(cmd).trim();
|
||||
LogUtil.CLog.d("Output for '%s': %s", cmd, output);
|
||||
|
||||
Reference in New Issue
Block a user