summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/AvailableNetworkNotifier.java3
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java15
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java53
6 files changed, 58 insertions, 32 deletions
diff --git a/service/java/com/android/server/wifi/AvailableNetworkNotifier.java b/service/java/com/android/server/wifi/AvailableNetworkNotifier.java
index 7af22934f..bbfedaf91 100644
--- a/service/java/com/android/server/wifi/AvailableNetworkNotifier.java
+++ b/service/java/com/android/server/wifi/AvailableNetworkNotifier.java
@@ -261,7 +261,8 @@ public class AvailableNetworkNotifier {
private boolean isControllerEnabled() {
return mSettingEnabled && !mContext.getSystemService(UserManager.class)
// TODO (b/142234604): This will not work on multi-user device scenarios.
- .hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, UserHandle.CURRENT_OR_SELF);
+ .hasUserRestrictionForUser(UserManager.DISALLOW_CONFIG_WIFI,
+ UserHandle.CURRENT_OR_SELF);
}
/**
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index d2a4678ad..b459bb2f6 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -1373,7 +1373,8 @@ public class WifiServiceImpl extends BaseWifiService {
}
// verify that tethering is not disabled
- if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
+ if (mUserManager.hasUserRestrictionForUser(
+ UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.getUserHandleForUid(uid))) {
return LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED;
}
@@ -2747,15 +2748,21 @@ public class WifiServiceImpl extends BaseWifiService {
return;
}
mLog.info("factoryReset uid=%").c(Binder.getCallingUid()).flush();
- if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
+ if (mUserManager.hasUserRestrictionForUser(
+ UserManager.DISALLOW_NETWORK_RESET,
+ UserHandle.getUserHandleForUid(Binder.getCallingUid()))) {
return;
}
- if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
+ if (!mUserManager.hasUserRestrictionForUser(
+ UserManager.DISALLOW_CONFIG_TETHERING,
+ UserHandle.getUserHandleForUid(Binder.getCallingUid()))) {
// Turn mobile hotspot off
stopSoftApInternal(WifiManager.IFACE_IP_MODE_UNSPECIFIED);
}
- if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) {
+ if (mUserManager.hasUserRestrictionForUser(
+ UserManager.DISALLOW_CONFIG_WIFI,
+ UserHandle.getUserHandleForUid(Binder.getCallingUid()))) {
return;
}
// Delete all Wifi SSIDs
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
index dfbc45f8a..783dac970 100644
--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -4121,9 +4121,12 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
if (!mWifiPermissionsUtil.checkNetworkSettingsPermission(uid)) return false;
- if (userManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) return false;
-
- if (userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) return false;
+ if (userManager.hasUserRestrictionForUser(
+ UserManager.DISALLOW_NETWORK_RESET, UserHandle.getUserHandleForUid(uid))
+ || userManager.hasUserRestrictionForUser(
+ UserManager.DISALLOW_CONFIG_WIFI, UserHandle.getUserHandleForUid(uid))) {
+ return false;
+ }
Log.i(TAG, "factoryReset uid=" + uid + " pkg=" + pkgName);
diff --git a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java
index e47a18269..bdb82b20a 100644
--- a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java
@@ -459,7 +459,7 @@ public class OpenNetworkNotifierTest extends WifiBaseTest {
@Test
public void userHasDisallowConfigWifiRestriction_notificationNotDisplayed() {
// TODO (b/142234604): This will not work on multi-user device scenarios.
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI,
+ when(mUserManager.hasUserRestrictionForUser(UserManager.DISALLOW_CONFIG_WIFI,
UserHandle.CURRENT_OR_SELF))
.thenReturn(true);
@@ -480,7 +480,7 @@ public class OpenNetworkNotifierTest extends WifiBaseTest {
verify(mNotificationManager).notify(anyInt(), any());
// TODO (b/142234604): This will not work on multi-user device scenarios.
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI,
+ when(mUserManager.hasUserRestrictionForUser(UserManager.DISALLOW_CONFIG_WIFI,
UserHandle.CURRENT_OR_SELF))
.thenReturn(true);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 0c85dc132..318acc102 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -1442,7 +1442,8 @@ public class WifiServiceImplTest extends WifiBaseTest {
private void setupLohsPermissions() {
when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true);
when(mFrameworkFacade.isAppForeground(any(), anyInt())).thenReturn(true);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
+ when(mUserManager.hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_CONFIG_TETHERING), any()))
.thenReturn(false);
}
@@ -1553,7 +1554,8 @@ public class WifiServiceImplTest extends WifiBaseTest {
public void testHotspotDoesNotStartWhenTetheringDisallowed() throws Exception {
when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true);
when(mFrameworkFacade.isAppForeground(any(), anyInt())).thenReturn(true);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
+ when(mUserManager.hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_CONFIG_TETHERING), any()))
.thenReturn(true);
int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME);
assertEquals(ERROR_TETHERING_DISALLOWED, returnCode);
diff --git a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
index 8127ffe47..52439e42e 100644
--- a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
@@ -1736,9 +1736,9 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
// permissions for factory reset
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt()))
.thenReturn(true);
- when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET)))
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_NETWORK_RESET), any()))
.thenReturn(false);
- when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_WIFI)))
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any()))
.thenReturn(false);
ArgumentCaptor<WifiP2pGroupList> groupsCaptor =
@@ -1904,9 +1904,9 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
// permissions for factory reset
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt()))
.thenReturn(true);
- when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET)))
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_NETWORK_RESET), any()))
.thenReturn(false);
- when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_WIFI)))
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any()))
.thenReturn(false);
// There is one group hosted by this device in mGroups.
@@ -3104,16 +3104,19 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
when(mWifiInjector.getUserManager()).thenReturn(mUserManager);
when(mPackageManager.getNameForUid(anyInt())).thenReturn("testPkg");
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)).thenReturn(false);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)).thenReturn(false);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_NETWORK_RESET), any()))
+ .thenReturn(false);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any()))
+ .thenReturn(false);
when(mWifiNative.p2pListNetworks(any())).thenReturn(true);
sendSimpleMsg(mClientMessenger, WifiP2pManager.FACTORY_RESET);
checkSendP2pPersistentGroupsChangedBroadcast();
verify(mWifiInjector).getUserManager();
verify(mPackageManager).getNameForUid(anyInt());
verify(mWifiPermissionsUtil).checkNetworkSettingsPermission(anyInt());
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET));
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_WIFI));
+ verify(mUserManager).hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_NETWORK_RESET), any());
+ verify(mUserManager).hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any());
verify(mWifiNative, atLeastOnce()).p2pListNetworks(any());
verify(mFrameworkFacade).setIntegerSetting(eq(mContext),
eq(Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET), eq(0));
@@ -3131,15 +3134,18 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
when(mWifiInjector.getUserManager()).thenReturn(mUserManager);
when(mPackageManager.getNameForUid(anyInt())).thenReturn("testPkg");
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)).thenReturn(false);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)).thenReturn(false);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_NETWORK_RESET), any()))
+ .thenReturn(false);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any()))
+ .thenReturn(false);
when(mWifiNative.p2pListNetworks(any())).thenReturn(true);
sendSimpleMsg(mClientMessenger, WifiP2pManager.FACTORY_RESET);
verify(mWifiInjector).getUserManager();
verify(mPackageManager).getNameForUid(anyInt());
verify(mWifiPermissionsUtil).checkNetworkSettingsPermission(anyInt());
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET));
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_WIFI));
+ verify(mUserManager).hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_NETWORK_RESET), any());
+ verify(mUserManager).hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any());
verify(mWifiNative, never()).p2pListNetworks(any());
verify(mFrameworkFacade).setIntegerSetting(eq(mContext),
eq(Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET), eq(1));
@@ -3154,8 +3160,10 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
verify(mWifiInjector, times(2)).getUserManager();
verify(mPackageManager, times(2)).getNameForUid(anyInt());
verify(mWifiPermissionsUtil, times(2)).checkNetworkSettingsPermission(anyInt());
- verify(mUserManager, times(2)).hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET));
- verify(mUserManager, times(2)).hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_WIFI));
+ verify(mUserManager, times(2)).hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_NETWORK_RESET), any());
+ verify(mUserManager, times(2)).hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_CONFIG_WIFI), any());
verify(mWifiNative, atLeastOnce()).p2pListNetworks(any());
verify(mFrameworkFacade).getIntegerSetting(eq(mContext),
eq(Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET), eq(0));
@@ -3196,12 +3204,14 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
when(mWifiInjector.getUserManager()).thenReturn(mUserManager);
when(mPackageManager.getNameForUid(anyInt())).thenReturn("testPkg");
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)).thenReturn(true);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_NETWORK_RESET), any()))
+ .thenReturn(true);
sendSimpleMsg(mClientMessenger, WifiP2pManager.FACTORY_RESET);
verify(mWifiInjector).getUserManager();
verify(mPackageManager).getNameForUid(anyInt());
verify(mWifiPermissionsUtil).checkNetworkSettingsPermission(anyInt());
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET));
+ verify(mUserManager).hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_NETWORK_RESET), any());
verify(mClientHandler).sendMessage(mMessageCaptor.capture());
Message message = mMessageCaptor.getValue();
assertEquals(WifiP2pManager.FACTORY_RESET_FAILED, message.what);
@@ -3219,14 +3229,17 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
when(mWifiInjector.getUserManager()).thenReturn(mUserManager);
when(mPackageManager.getNameForUid(anyInt())).thenReturn("testPkg");
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)).thenReturn(false);
- when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)).thenReturn(true);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_NETWORK_RESET), any()))
+ .thenReturn(false);
+ when(mUserManager.hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any()))
+ .thenReturn(true);
sendSimpleMsg(mClientMessenger, WifiP2pManager.FACTORY_RESET);
verify(mWifiInjector).getUserManager();
verify(mPackageManager).getNameForUid(anyInt());
verify(mWifiPermissionsUtil).checkNetworkSettingsPermission(anyInt());
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_NETWORK_RESET));
- verify(mUserManager).hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_WIFI));
+ verify(mUserManager).hasUserRestrictionForUser(
+ eq(UserManager.DISALLOW_NETWORK_RESET), any());
+ verify(mUserManager).hasUserRestrictionForUser(eq(UserManager.DISALLOW_CONFIG_WIFI), any());
verify(mClientHandler).sendMessage(mMessageCaptor.capture());
Message message = mMessageCaptor.getValue();
assertEquals(WifiP2pManager.FACTORY_RESET_FAILED, message.what);