From efb185744313b3baf4b579a9eb6f8640cd603c78 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Mon, 4 May 2020 13:34:29 -0700 Subject: [PATCH] Test that idle apps get network when device charges. This is a partial revert of the change that removed the parole (Icd7b6eff8777f9b53a10eca521b73988f58f2d84). Bug: 151802309 Test: atest --rerun-until-failure 10 com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: I65f5ff20cdd342905e1afd1f4897017aa60682d3 --- .../net/hostside/AbstractAppIdleTestCase.java | 6 +++--- .../cts/net/NetworkPolicyTestsPreparer.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java index 51bdf8e502..5fe4573847 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java @@ -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); diff --git a/tests/cts/hostside/src/com/android/cts/net/NetworkPolicyTestsPreparer.java b/tests/cts/hostside/src/com/android/cts/net/NetworkPolicyTestsPreparer.java index dfce7da467..b0facec119 100644 --- a/tests/cts/hostside/src/com/android/cts/net/NetworkPolicyTestsPreparer.java +++ b/tests/cts/hostside/src/com/android/cts/net/NetworkPolicyTestsPreparer.java @@ -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);