Force the app idle state again after whitelisting it.

Whitelisting the app resets forced idle state of an app, so
forcing idle state again.

Bug: 161477606
Test: atest ./hostsidetests/net/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Change-Id: Ib57202a68071cc02d6071e0dc2c4780f026ad90b
This commit is contained in:
Sudheer Shanka
2020-07-16 14:00:27 -07:00
parent 79b592dd26
commit 7c4bb75e1b
2 changed files with 10 additions and 0 deletions

View File

@@ -89,14 +89,19 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
assertAppIdle(false); // Sanity check - not idle anymore, since whitelisted
assertBackgroundNetworkAccess(true);
setAppIdleNoAssert(true);
assertAppIdle(false); // app is still whitelisted
removePowerSaveModeWhitelist(TEST_APP2_PKG);
assertAppIdle(true); // Sanity check - idle again, once whitelisted was removed
assertBackgroundNetworkAccess(false);
setAppIdle(true);
addPowerSaveModeExceptIdleWhitelist(TEST_APP2_PKG);
assertAppIdle(false); // Sanity check - not idle anymore, since whitelisted
assertBackgroundNetworkAccess(true);
setAppIdleNoAssert(true);
assertAppIdle(false); // app is still whitelisted
removePowerSaveModeExceptIdleWhitelist(TEST_APP2_PKG);
assertAppIdle(true); // Sanity check - idle again, once whitelisted was removed
assertBackgroundNetworkAccess(false);

View File

@@ -662,6 +662,11 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
assertAppIdle(enabled); // Sanity check
}
protected void setAppIdleNoAssert(boolean enabled) throws Exception {
Log.i(TAG, "Setting app idle to " + enabled);
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
}
protected void assertAppIdle(boolean enabled) throws Exception {
try {
assertDelayedShellCommand("am get-inactive " + TEST_APP2_PKG, 15, 2, "Idle=" + enabled);