Merge "Add CTS test for Restricted Networking Mode" am: 99f6c312ef
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1545724 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Iee0461ea66a212db9cef6d2676742c707e567a95
This commit is contained in:
@@ -234,12 +234,16 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void assertForegroundNetworkAccess() throws Exception {
|
protected void assertForegroundNetworkAccess() throws Exception {
|
||||||
|
assertForegroundNetworkAccess(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertForegroundNetworkAccess(boolean expectAllowed) throws Exception {
|
||||||
assertForegroundState();
|
assertForegroundState();
|
||||||
// We verified that app is in foreground state but if the screen turns-off while
|
// 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
|
// 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
|
// foreground status was due to top activity). So, turn the screen on when verifying
|
||||||
// network connectivity.
|
// network connectivity.
|
||||||
assertNetworkAccess(true /* expectAvailable */, true /* needScreenOn */);
|
assertNetworkAccess(expectAllowed /* expectAvailable */, true /* needScreenOn */);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertForegroundServiceNetworkAccess() throws Exception {
|
protected void assertForegroundServiceNetworkAccess() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.cts.net.hostside;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public final class RestrictedModeTest extends AbstractRestrictBackgroundNetworkTestCase {
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
setRestrictedMode(false);
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRestrictedMode(boolean enabled) throws Exception {
|
||||||
|
executeSilentShellCommand(
|
||||||
|
"settings put global restricted_networking_mode " + (enabled ? 1 : 0));
|
||||||
|
assertRestrictedModeState(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertRestrictedModeState(boolean enabled) throws Exception {
|
||||||
|
assertDelayedShellCommand("cmd netpolicy get restricted-mode",
|
||||||
|
"Restricted mode status: " + (enabled ? "enabled" : "disabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNetworkAccess() throws Exception {
|
||||||
|
setRestrictedMode(false);
|
||||||
|
|
||||||
|
// go to foreground state and enable restricted mode
|
||||||
|
launchComponentAndAssertNetworkAccess(TYPE_COMPONENT_ACTIVTIY);
|
||||||
|
setRestrictedMode(true);
|
||||||
|
assertForegroundNetworkAccess(false);
|
||||||
|
|
||||||
|
// go to background state
|
||||||
|
finishActivity();
|
||||||
|
assertBackgroundNetworkAccess(false);
|
||||||
|
|
||||||
|
// disable restricted mode and assert network access in foreground and background states
|
||||||
|
setRestrictedMode(false);
|
||||||
|
launchComponentAndAssertNetworkAccess(TYPE_COMPONENT_ACTIVTIY);
|
||||||
|
assertForegroundNetworkAccess(true);
|
||||||
|
|
||||||
|
// go to background state
|
||||||
|
finishActivity();
|
||||||
|
assertBackgroundNetworkAccess(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -311,6 +311,14 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
|
|||||||
"testAppIdleAndBatterySaver_tempPowerSaveAndAppIdleWhitelists");
|
"testAppIdleAndBatterySaver_tempPowerSaveAndAppIdleWhitelists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************
|
||||||
|
* Restricted mode tests. *
|
||||||
|
**************************/
|
||||||
|
public void testRestrictedMode_networkAccess() throws Exception {
|
||||||
|
runDeviceTests(TEST_PKG, TEST_PKG + ".RestrictedModeTest",
|
||||||
|
"testNetworkAccess");
|
||||||
|
}
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
* Helper methods. *
|
* Helper methods. *
|
||||||
*******************/
|
*******************/
|
||||||
|
|||||||
Reference in New Issue
Block a user