From 10864275fb3655dc88fa7f98a430fca6f84fd25b Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Sun, 11 Feb 2018 00:11:42 -0800 Subject: [PATCH] Turn screen-on if needed, on every iteration network access is verified. In some cases, we verify network connection is available to an app while in foreground. If the app's foreground status is due to top activity, it will lose the foreground status in case the screen goes off. So, turn the screen-on while verifying for network connectivity. Fixes: 71694434 Test: cts-tradefed run singleCommand cts-dev -m CtsHostsideNetworkTests -t \ com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: Id1a49cedc2501859f73deead372afb7f6a41baac --- ...bstractRestrictBackgroundNetworkTestCase.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java index 2f36b936f2..db7904e775 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java @@ -260,17 +260,21 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation protected void assertBackgroundNetworkAccess(boolean expectAllowed) throws Exception { assertBackgroundState(); // Sanity check. - assertNetworkAccess(expectAllowed); + assertNetworkAccess(expectAllowed /* expectAvailable */, false /* needScreenOn */); } protected void assertForegroundNetworkAccess() throws Exception { assertForegroundState(); // Sanity check. - assertNetworkAccess(true); + // We verified that app is in foreground state but if the screen turns-off while + // verifying for network access, the app will go into background state (in case app's + // foreground status was due to top activity). So, turn the screen on when verifying + // network connectivity. + assertNetworkAccess(true /* expectAvailable */, true /* needScreenOn */); } protected void assertForegroundServiceNetworkAccess() throws Exception { assertForegroundServiceState(); // Sanity check. - assertNetworkAccess(true); + assertNetworkAccess(true /* expectAvailable */, false /* needScreenOn */); } /** @@ -369,7 +373,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation /** * Asserts whether the active network is available or not. */ - private void assertNetworkAccess(boolean expectAvailable) throws Exception { + private void assertNetworkAccess(boolean expectAvailable, boolean needScreenOn) + throws Exception { final int maxTries = 5; String error = null; int timeoutMs = 500; @@ -387,6 +392,9 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation Log.w(TAG, "Network status didn't match for expectAvailable=" + expectAvailable + " on attempt #" + i + ": " + error + "\n" + "Sleeping " + timeoutMs + "ms before trying again"); + if (needScreenOn) { + turnScreenOn(); + } // No sleep after the last turn if (i < maxTries) { SystemClock.sleep(timeoutMs);