Add CTS for setProfileNetworkPreference

Test: atest android.net.cts.ConnectivityManagerTest
Bug: 190797743
Change-Id: Ifffdf55addbb7ec4466d4adec61e5812b7f94320
This commit is contained in:
Junyu Lai
2021-06-11 09:36:01 +00:00
parent 99e50a0fc9
commit 75b109586a

View File

@@ -28,6 +28,7 @@ import static android.content.pm.PackageManager.FEATURE_WIFI;
import static android.content.pm.PackageManager.FEATURE_WIFI_DIRECT;
import static android.content.pm.PackageManager.GET_PERMISSIONS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE;
import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_MOBILE_CBS;
@@ -2053,6 +2054,20 @@ public class ConnectivityManagerTest {
}
}
/**
* Verify that {@link ConnectivityManager#setProfileNetworkPreference} cannot be called
* without required NETWORK_STACK permissions.
*/
@Test
public void testSetProfileNetworkPreference_NoPermission() {
// Cannot use @IgnoreUpTo(Build.VERSION_CODES.R) because this test also requires API 31
// shims, and @IgnoreUpTo does not check that.
assumeTrue(TestUtils.shouldTestSApis());
assertThrows(SecurityException.class, () -> mCm.setProfileNetworkPreference(
UserHandle.of(0), PROFILE_NETWORK_PREFERENCE_ENTERPRISE, null /* executor */,
null /* listener */));
}
private void verifySettings(int expectedAirplaneMode, int expectedPrivateDnsMode,
int expectedAvoidBadWifi) throws Exception {
assertEquals(expectedAirplaneMode, Settings.Global.getInt(