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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user