summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-21 20:23:54 -0700
committerRoshan Pius <rpius@google.com>2019-10-30 20:01:34 -0700
commite564ad666f3e5f2aab07d1e158ace5a9179bcf43 (patch)
tree5799f0392dbcfdae76e47626000c290488582b38 /tests
parent9cc29b34b202db69c255e6d035646d791dc925cb (diff)
WifiStack: Use new hasUserRestrictionForUser @SystemApi
Wifi stack needs a multi-user version of UserManager.hasUserRestriction(). Bug: 142888959 Test: atest com.android.server.wifi Change-Id: I0d9668194fa45b48235ee819b01e17fa8cbeda34
Diffstat (limited to 'tests')
-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
3 files changed, 39 insertions, 24 deletions
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);