Added tests for network restrictions while the screen is off.
BUG: 30785671 Change-Id: I1b211e545ff234272ff6acadfda9ce97765695a9 (cherry picked from commit b80a93061aa7d0a19b47a7dbb82f0dc06e3afb7e)
This commit is contained in:
@@ -85,16 +85,24 @@ abstract class AbstractBatterySaverModeTestCase extends AbstractRestrictBackgrou
|
|||||||
assertsForegroundAlwaysHasNetworkAccess();
|
assertsForegroundAlwaysHasNetworkAccess();
|
||||||
assertBackgroundNetworkAccess(false);
|
assertBackgroundNetworkAccess(false);
|
||||||
|
|
||||||
// Make sure foreground app doesn't lose access upon enabling it.
|
// Make sure foreground app doesn't lose access upon Battery Saver.
|
||||||
setBatterySaverMode(false);
|
setBatterySaverMode(false);
|
||||||
launchActivity();
|
launchActivity();
|
||||||
assertForegroundNetworkAccess();
|
assertForegroundNetworkAccess();
|
||||||
setBatterySaverMode(true);
|
setBatterySaverMode(true);
|
||||||
assertForegroundNetworkAccess();
|
assertForegroundNetworkAccess();
|
||||||
|
|
||||||
|
// Although it should not have access while the screen is off.
|
||||||
|
turnScreenOff();
|
||||||
|
assertBackgroundNetworkAccess(false);
|
||||||
|
turnScreenOn();
|
||||||
|
assertForegroundNetworkAccess();
|
||||||
|
|
||||||
|
// Goes back to background state.
|
||||||
finishActivity();
|
finishActivity();
|
||||||
assertBackgroundNetworkAccess(false);
|
assertBackgroundNetworkAccess(false);
|
||||||
|
|
||||||
// Same for foreground service.
|
// Make sure foreground service doesn't lose access upon enabling Battery Saver.
|
||||||
setBatterySaverMode(false);
|
setBatterySaverMode(false);
|
||||||
startForegroundService();
|
startForegroundService();
|
||||||
assertForegroundNetworkAccess();
|
assertForegroundNetworkAccess();
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
|
|||||||
if (isBackground(state.state)) {
|
if (isBackground(state.state)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d(TAG, "App not on background state on attempt #" + i
|
Log.d(TAG, "App not on background state (" + state + ") on attempt #" + i
|
||||||
+ "; sleeping 1s before trying again");
|
+ "; sleeping 1s before trying again");
|
||||||
SystemClock.sleep(SECOND_IN_MS);
|
SystemClock.sleep(SECOND_IN_MS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,16 +98,24 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase
|
|||||||
assertsForegroundAlwaysHasNetworkAccess();
|
assertsForegroundAlwaysHasNetworkAccess();
|
||||||
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
|
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
|
||||||
|
|
||||||
// Make sure foreground app doesn't lose access upon enabling it.
|
// Make sure foreground app doesn't lose access upon enabling Data Saver.
|
||||||
setRestrictBackground(false);
|
setRestrictBackground(false);
|
||||||
launchActivity();
|
launchActivity();
|
||||||
assertForegroundNetworkAccess();
|
assertForegroundNetworkAccess();
|
||||||
setRestrictBackground(true);
|
setRestrictBackground(true);
|
||||||
assertForegroundNetworkAccess();
|
assertForegroundNetworkAccess();
|
||||||
|
|
||||||
|
// Although it should not have access while the screen is off.
|
||||||
|
turnScreenOff();
|
||||||
|
assertBackgroundNetworkAccess(false);
|
||||||
|
turnScreenOn();
|
||||||
|
assertForegroundNetworkAccess();
|
||||||
|
|
||||||
|
// Goes back to background state.
|
||||||
finishActivity();
|
finishActivity();
|
||||||
assertBackgroundNetworkAccess(false);
|
assertBackgroundNetworkAccess(false);
|
||||||
|
|
||||||
// Same for foreground service.
|
// Make sure foreground service doesn't lose access upon enabling Data Saver.
|
||||||
setRestrictBackground(false);
|
setRestrictBackground(false);
|
||||||
startForegroundService();
|
startForegroundService();
|
||||||
assertForegroundNetworkAccess();
|
assertForegroundNetworkAccess();
|
||||||
|
|||||||
Reference in New Issue
Block a user