Loading packages/SettingsLib/src/com/android/settingslib/wifi/WifiEnterpriseRestrictionUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,22 @@ public class WifiEnterpriseRestrictionUtils { return true; } /** * Confirm Wi-Fi Config is allowed to add according to whether user restriction is set * * @param context A context * @return whether the device is permitted to add new Wi-Fi config */ public static boolean isAddWifiConfigAllowed(Context context) { final UserManager userManager = context.getSystemService(UserManager.class); final Bundle restrictions = userManager.getUserRestrictions(); if (isAtLeastT() && restrictions.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)) { Log.i(TAG, "Wi-Fi Add network isn't available due to user restriction."); return false; } return true; } @ChecksSdkIntAtLeast(api=Build.VERSION_CODES.TIRAMISU) private static boolean isAtLeastT() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU; Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiEnterpriseRestrictionUtilsTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -103,4 +103,30 @@ public class WifiEnterpriseRestrictionUtilsTest { assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isTrue(); } @Test public void isAddWifiConfigAllowed_setSDKForS_shouldReturnTrue() { ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.S); when(mBundle.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isAddWifiConfigAllowed(mContext)).isTrue(); } @Test public void isAddWifiConfigAllowed_setSDKForTAndDisallowForRestriction_shouldReturnFalse() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isAddWifiConfigAllowed(mContext)).isFalse(); } @Test public void isAddWifiConfigAllowed_setSDKForTAndAllowForRestriction_shouldReturnTrue() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)).thenReturn(false); assertThat(WifiEnterpriseRestrictionUtils.isAddWifiConfigAllowed(mContext)).isTrue(); } } Loading
packages/SettingsLib/src/com/android/settingslib/wifi/WifiEnterpriseRestrictionUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,22 @@ public class WifiEnterpriseRestrictionUtils { return true; } /** * Confirm Wi-Fi Config is allowed to add according to whether user restriction is set * * @param context A context * @return whether the device is permitted to add new Wi-Fi config */ public static boolean isAddWifiConfigAllowed(Context context) { final UserManager userManager = context.getSystemService(UserManager.class); final Bundle restrictions = userManager.getUserRestrictions(); if (isAtLeastT() && restrictions.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)) { Log.i(TAG, "Wi-Fi Add network isn't available due to user restriction."); return false; } return true; } @ChecksSdkIntAtLeast(api=Build.VERSION_CODES.TIRAMISU) private static boolean isAtLeastT() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU; Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiEnterpriseRestrictionUtilsTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -103,4 +103,30 @@ public class WifiEnterpriseRestrictionUtilsTest { assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isTrue(); } @Test public void isAddWifiConfigAllowed_setSDKForS_shouldReturnTrue() { ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.S); when(mBundle.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isAddWifiConfigAllowed(mContext)).isTrue(); } @Test public void isAddWifiConfigAllowed_setSDKForTAndDisallowForRestriction_shouldReturnFalse() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isAddWifiConfigAllowed(mContext)).isFalse(); } @Test public void isAddWifiConfigAllowed_setSDKForTAndAllowForRestriction_shouldReturnTrue() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_ADD_WIFI_CONFIG)).thenReturn(false); assertThat(WifiEnterpriseRestrictionUtils.isAddWifiConfigAllowed(mContext)).isTrue(); } }