Tests for idle parole when charging

Make sure that when switching between idle, paroled
and battery saver, the network availability of the app
is correctly updated.

Bug: 31399882
Test: cts-tradefed run commandAndExit cts -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testAppIdleNonMetered_whenCharging
Test: cts-tradefed run commandAndExit cts -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testAppIdleMetered_whenCharging
Change-Id: I060a0d5f9c3297430b5b623b389c1afdf6abde87
This commit is contained in:
Amith Yamasani
2016-09-19 09:27:06 -07:00
parent 987c7c6bc9
commit 2855028c8e
2 changed files with 34 additions and 0 deletions

View File

@@ -138,4 +138,28 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
assertsForegroundAlwaysHasNetworkAccess();
assertBackgroundNetworkAccess(true);
}
public void testAppIdleNetworkAccess_whenCharging() throws Exception {
if (!isSupported()) return;
// Check that app is paroled when charging
setAppIdle(true);
assertBackgroundNetworkAccess(false);
turnBatteryOn();
assertBackgroundNetworkAccess(true);
turnBatteryOff();
assertBackgroundNetworkAccess(false);
// Check that app is restricted when not idle but power-save is on
setAppIdle(false);
assertBackgroundNetworkAccess(true);
setBatterySaverMode(true);
assertBackgroundNetworkAccess(false);
turnBatteryOn();
assertBackgroundNetworkAccess(true);
// And when no longer charging, it still has network access, since it's not idle
turnBatteryOff();
assertBackgroundNetworkAccess(true);
}
}

View File

@@ -171,6 +171,16 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
"testBackgroundNetworkAccess_enabled");
}
public void testAppIdleNonMetered_whenCharging() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleNonMeteredTest",
"testAppIdleNetworkAccess_whenCharging");
}
public void testAppIdleMetered_whenCharging() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleMeteredTest",
"testAppIdleNetworkAccess_whenCharging");
}
/********************
* Doze Mode tests. *
********************/