Merge "Add CTS for setProfileNetworkPreference" am: 5d4f701244 am: 106a4752f7

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1733784

Change-Id: Ib5b529b38eb05c33d2b85ca9a8da3f6a4915125b
This commit is contained in:
Treehugger Robot 2021-06-21 10:34:59 +00:00 • committed by Automerger Merge Worker
commit 9bb6c1958d

View file

@ -29,6 +29,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;
@ -2140,6 +2141,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(