Add CTS for setProfileNetworkPreference am: bd595f739c
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/15044618 Change-Id: Ifb59930da0feb99477f5e4b8112248c19aa8f64a
This commit is contained in:
@@ -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;
|
||||
@@ -2104,6 +2105,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(
|
||||
|
||||
Reference in New Issue
Block a user