Loading packages/SettingsLib/src/com/android/settingslib/wifi/WifiEnterpriseRestrictionUtils.java +17 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ public class WifiEnterpriseRestrictionUtils { private static final String TAG = "WifiEntResUtils"; /** * Confirm Wi-Fi tethering is available according to whether user restriction is set * Confirm Wi-Fi tethering is allowed according to whether user restriction is set * * @param context A context * @return whether the device is permitted to use Wi-Fi Tethering Loading @@ -44,6 +44,22 @@ public class WifiEnterpriseRestrictionUtils { return true; } /** * Confirm Wi-Fi Direct is allowed according to whether user restriction is set * * @param context A context * @return whether the device is permitted to use Wi-Fi Direct */ public static boolean isWifiDirectAllowed(Context context) { final UserManager userManager = context.getSystemService(UserManager.class); final Bundle restrictions = userManager.getUserRestrictions(); if (isAtLeastT() && restrictions.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)) { Log.i(TAG, "Wi-Fi Direct 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 @@ -77,4 +77,30 @@ public class WifiEnterpriseRestrictionUtilsTest { assertThat(WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(mContext)).isTrue(); } @Test public void isWifiDirectAllowed_setSDKForS_shouldReturnTrue() { ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.S); when(mBundle.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isTrue(); } @Test public void isWifiDirectAllowed_setSDKForTAndDisallowForRestriction_shouldReturnFalse() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isFalse(); } @Test public void isWifiDirectAllowed_setSDKForTAndAllowForRestriction_shouldReturnTrue() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)).thenReturn(false); assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isTrue(); } } Loading
packages/SettingsLib/src/com/android/settingslib/wifi/WifiEnterpriseRestrictionUtils.java +17 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ public class WifiEnterpriseRestrictionUtils { private static final String TAG = "WifiEntResUtils"; /** * Confirm Wi-Fi tethering is available according to whether user restriction is set * Confirm Wi-Fi tethering is allowed according to whether user restriction is set * * @param context A context * @return whether the device is permitted to use Wi-Fi Tethering Loading @@ -44,6 +44,22 @@ public class WifiEnterpriseRestrictionUtils { return true; } /** * Confirm Wi-Fi Direct is allowed according to whether user restriction is set * * @param context A context * @return whether the device is permitted to use Wi-Fi Direct */ public static boolean isWifiDirectAllowed(Context context) { final UserManager userManager = context.getSystemService(UserManager.class); final Bundle restrictions = userManager.getUserRestrictions(); if (isAtLeastT() && restrictions.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)) { Log.i(TAG, "Wi-Fi Direct 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 @@ -77,4 +77,30 @@ public class WifiEnterpriseRestrictionUtilsTest { assertThat(WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(mContext)).isTrue(); } @Test public void isWifiDirectAllowed_setSDKForS_shouldReturnTrue() { ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.S); when(mBundle.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isTrue(); } @Test public void isWifiDirectAllowed_setSDKForTAndDisallowForRestriction_shouldReturnFalse() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)).thenReturn(true); assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isFalse(); } @Test public void isWifiDirectAllowed_setSDKForTAndAllowForRestriction_shouldReturnTrue() { ReflectionHelpers.setStaticField( Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.TIRAMISU); when(mBundle.getBoolean(UserManager.DISALLOW_WIFI_DIRECT)).thenReturn(false); assertThat(WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(mContext)).isTrue(); } }