summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMitchell Wills <mwills@google.com>2016-02-11 18:00:02 +0000
committerAndroid Partner Code Review <android-gerrit-partner@google.com>2016-02-11 18:00:03 +0000
commit4086badffeb97f4c87b2bed3fcaa49b731a6670e (patch)
treea99d9c1a9fbb7eb17e01ffeb5d6b42cfff533e99 /tests
parent6eb121431c67b98d8b14242a34c28b205a42b119 (diff)
parent9f8586ea6d640e86560efd9a2d9c1909b08a3ef4 (diff)
Merge "Revert "Allow managed profile to modify networks"" into mm-wireless-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/BinderUtil.java32
-rw-r--r--tests/wifitests/src/com/android/server/wifi/BinderUtilTest.java95
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java74
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java77
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtil.java (renamed from tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java)27
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java66
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectionTest.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java223
8 files changed, 50 insertions, 552 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/BinderUtil.java b/tests/wifitests/src/com/android/server/wifi/BinderUtil.java
deleted file mode 100644
index 107de7c8d..000000000
--- a/tests/wifitests/src/com/android/server/wifi/BinderUtil.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import android.os.Binder;
-
-/**
- * Utilities for faking the calling uid in Binder.
- */
-public class BinderUtil {
- /**
- * Fake the calling uid in Binder.
- * @param uid the calling uid that Binder should return from now on
- */
- public static void setUid(int uid) {
- Binder.restoreCallingIdentity((((long) uid) << 32) | Binder.getCallingPid());
- }
-}
diff --git a/tests/wifitests/src/com/android/server/wifi/BinderUtilTest.java b/tests/wifitests/src/com/android/server/wifi/BinderUtilTest.java
deleted file mode 100644
index 925bdc0c2..000000000
--- a/tests/wifitests/src/com/android/server/wifi/BinderUtilTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import android.os.Binder;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link com.android.server.wifi.BinderUtil}.
- */
-@SmallTest
-public class BinderUtilTest {
- static final int FAKE_UID = 30000000;
-
- private long mToken;
-
- /**
- * Sets up the test harness before running a test.
- */
- @Before
- public void setUp() {
- mToken = Binder.clearCallingIdentity();
- }
-
- /**
- * Cleans up the test harness after running a test.
- */
- @After
- public void cleanUp() {
- Binder.restoreCallingIdentity(mToken);
- }
-
- /**
- * Test using {@link BinderUtil.setUid} to set and restore the Binder uid.
- */
- @Test
- public void setUid() {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- assertFalse(uid == FAKE_UID);
-
- // Verify that setUid() can be used to fake the Binder uid without affecting the pid.
- BinderUtil.setUid(FAKE_UID);
- assertEquals(pid, Binder.getCallingPid());
- assertEquals(FAKE_UID, Binder.getCallingUid());
-
- // Verify that setUid() can be used to restore the original Binder uid without affecting the
- // pid.
- BinderUtil.setUid(uid);
- assertEquals(pid, Binder.getCallingPid());
- assertEquals(uid, Binder.getCallingUid());
- }
-
- /**
- * Test using {@link BinderUtil.setUid} to set the Binder uid and
- * {@link Binder.restoreCallingIdentity} to restore it.
- */
- @Test
- public void setUidAndRestoreCallingIdentity() {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- assertFalse(uid == FAKE_UID);
-
- // Verify that setUid() can be used to fake the Binder uid without affecting the pid.
- BinderUtil.setUid(FAKE_UID);
- assertEquals(pid, Binder.getCallingPid());
- assertEquals(FAKE_UID, Binder.getCallingUid());
-
- // Verify that the setUid() calls above did not break Binder.restoreCallingIdentity().
- Binder.restoreCallingIdentity(mToken);
- assertEquals(pid, Binder.getCallingPid());
- assertEquals(uid, Binder.getCallingUid());
- }
-}
diff --git a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
index d8075c349..917fd77a7 100644
--- a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
@@ -18,23 +18,12 @@ package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.anyInt;
-import static org.mockito.Mockito.when;
-import android.content.Context;
-import android.content.pm.UserInfo;
import android.net.wifi.WifiConfiguration;
import android.os.UserHandle;
-import android.os.UserManager;
import android.test.suitebuilder.annotation.SmallTest;
-import android.util.SparseArray;
-import com.android.server.wifi.MockAnswerUtil.AnswerWithArguments;
-
-import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.Arrays;
@@ -48,59 +37,25 @@ import java.util.Set;
@SmallTest
public class ConfigurationMapTest {
private static final List<WifiConfiguration> CONFIGS = Arrays.asList(
- WifiConfigurationTestUtil.generateWifiConfig(
- 0, 1000000, "\"red\"", true, true, null, null),
- WifiConfigurationTestUtil.generateWifiConfig(
- 1, 1000001, "\"green\"", true, false, "example.com", "Green"),
- WifiConfigurationTestUtil.generateWifiConfig(
- 2, 1200000, "\"blue\"", false, true, null, null),
- WifiConfigurationTestUtil.generateWifiConfig(
+ WifiConfigurationUtil.generateWifiConfig(0, 1000000, "\"red\"", true, true, null, null),
+ WifiConfigurationUtil.generateWifiConfig(
+ 1, 1000001, "\"green\"", false, true, null, null),
+ WifiConfigurationUtil.generateWifiConfig(
+ 2, 1000002, "\"blue\"", true, false, "example.com", "Blue"),
+ WifiConfigurationUtil.generateWifiConfig(
3, 1100000, "\"cyan\"", true, true, null, null),
- WifiConfigurationTestUtil.generateWifiConfig(
- 4, 1100001, "\"yellow\"", true, true, "example.org", "Yellow"),
- WifiConfigurationTestUtil.generateWifiConfig(
- 5, 1100002, "\"magenta\"", false, false, null, null));
-
- private static final SparseArray<List<UserInfo>> USER_PROFILES = new SparseArray<>();
- static {
- USER_PROFILES.put(UserHandle.USER_SYSTEM, Arrays.asList(
- new UserInfo(UserHandle.USER_SYSTEM, "Owner", 0),
- new UserInfo(12, "Managed Profile", 0)));
- USER_PROFILES.put(10, Arrays.asList(new UserInfo(10, "Alice", 0)));
- USER_PROFILES.put(11, Arrays.asList(new UserInfo(11, "Bob", 0)));
- }
-
- @Mock UserManager mUserManager;
- @Mock Context mContext;
+ WifiConfigurationUtil.generateWifiConfig(
+ 4, 1100001, "\"yellow\"", false, false, null, null),
+ WifiConfigurationUtil.generateWifiConfig(
+ 5, 1100002, "\"magenta\"", true, true, "example.org", "Magenta"));
private int mCurrentUserId = UserHandle.USER_SYSTEM;
- private ConfigurationMap mConfigs;
-
- /**
- * Sets up the test harness before running a test.
- */
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- when(mUserManager.getProfiles(anyInt()))
- .then(new AnswerWithArguments() {
- public List<UserInfo> answer(int userId) {
- return USER_PROFILES.get(userId);
- }
- });
- when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
-
- mConfigs = new ConfigurationMap(mContext);
- }
+ private final ConfigurationMap mConfigs = new ConfigurationMap();
public void switchUser(int newUserId) {
Set<WifiConfiguration> hiddenConfigurations = new HashSet<>();
for (WifiConfiguration config : mConfigs.valuesForAllUsers()) {
- if (WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(mCurrentUserId))
- && !WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(newUserId))) {
+ if (config.isVisibleToUser(mCurrentUserId) && !config.isVisibleToUser(newUserId)) {
hiddenConfigurations.add(config);
}
}
@@ -118,8 +73,7 @@ public class ConfigurationMapTest {
// user. Also, check that *ForAllUsers() methods can be used to access all network
// configurations, irrespective of their visibility to the current user.
for (WifiConfiguration config : configs) {
- if (WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(mCurrentUserId))) {
+ if (config.isVisibleToUser(mCurrentUserId)) {
configsForCurrentUser.add(config);
if (config.status != WifiConfiguration.Status.DISABLED) {
enabledConfigsForCurrentUser.add(config);
@@ -222,7 +176,7 @@ public class ConfigurationMapTest {
configs.add(config2);
verifyGetters(configs);
- // Add |config3|, which belongs to a managed profile of the current user.
+ // Add |config3|.
final WifiConfiguration config3 = CONFIGS.get(2);
assertNull(mConfigs.put(config3));
// Verify that the getters return |config2| and |config3|.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
index 83d6e2a27..592280335 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
@@ -31,7 +31,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.content.pm.UserInfo;
import android.net.wifi.FakeKeys;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
@@ -44,7 +43,6 @@ import android.security.Credentials;
import android.test.AndroidTestCase;
import android.text.TextUtils;
import android.util.Log;
-import android.util.SparseArray;
import com.android.server.net.DelayedDiskWrite;
import com.android.server.wifi.MockAnswerUtil.AnswerWithArguments;
@@ -87,33 +85,20 @@ import java.util.TreeMap;
*/
public class WifiConfigStoreTest extends AndroidTestCase {
private static final List<WifiConfiguration> CONFIGS = Arrays.asList(
- WifiConfigurationTestUtil.generateWifiConfig(
+ WifiConfigurationUtil.generateWifiConfig(
0, 1000000, "\"red\"", true, true, null, null),
- WifiConfigurationTestUtil.generateWifiConfig(
+ WifiConfigurationUtil.generateWifiConfig(
1, 1000001, "\"green\"", true, true, "example.com", "Green"),
- WifiConfigurationTestUtil.generateWifiConfig(
- 2, 1100000, "\"blue\"", false, true, "example.org", "Blue"),
- WifiConfigurationTestUtil.generateWifiConfig(
- 3, 1200000, "\"cyan\"", false, true, null, null));
+ WifiConfigurationUtil.generateWifiConfig(
+ 2, 1100000, "\"blue\"", false, true, "example.org", "Blue"));
private static final int[] USER_IDS = {0, 10, 11};
- private static final int MANAGED_PROFILE_USER_ID = 12;
- private static final int MANAGED_PROFILE_PARENT_USER_ID = 0;
- private static final SparseArray<List<UserInfo>> USER_PROFILES = new SparseArray<>();
- static {
- USER_PROFILES.put(0, Arrays.asList(new UserInfo(0, "Owner", 0),
- new UserInfo(12, "Managed Profile", 0)));
- USER_PROFILES.put(10, Arrays.asList(new UserInfo(10, "Alice", 0)));
- USER_PROFILES.put(11, Arrays.asList(new UserInfo(11, "Bob", 0)));
- }
-
private static final Map<Integer, List<WifiConfiguration>> VISIBLE_CONFIGS = new HashMap<>();
static {
for (int userId : USER_IDS) {
List<WifiConfiguration> configs = new ArrayList<>();
for (int i = 0; i < CONFIGS.size(); ++i) {
- if (WifiConfigurationUtil.isVisibleToAnyProfile(CONFIGS.get(i),
- USER_PROFILES.get(userId))) {
+ if (CONFIGS.get(i).isVisibleToUser(userId)) {
configs.add(CONFIGS.get(i));
}
}
@@ -141,9 +126,8 @@ public class WifiConfigStoreTest extends AndroidTestCase {
when(mContext.getPackageName()).thenReturn(realContext.getPackageName());
when(mContext.getResources()).thenReturn(realContext.getResources());
when(mContext.getPackageManager()).thenReturn(realContext.getPackageManager());
+
when(mWifiStateMachine.getCurrentUserId()).thenReturn(UserHandle.USER_SYSTEM);
- when(mWifiStateMachine.getCurrentUserProfiles())
- .thenReturn(USER_PROFILES.get(UserHandle.USER_SYSTEM));
mConfigStore = new WifiConfigStore(mContext, mWifiStateMachine, mWifiNative,
mFrameworkFacade);
@@ -179,18 +163,11 @@ public class WifiConfigStoreTest extends AndroidTestCase {
private void switchUser(int newUserId) {
when(mWifiStateMachine.getCurrentUserId()).thenReturn(newUserId);
- when(mWifiStateMachine.getCurrentUserProfiles())
- .thenReturn(USER_PROFILES.get(newUserId));
mConfigStore.handleUserSwitch();
}
- private void switchUserToCreatorOrParentOf(WifiConfiguration config) {
- final int creatorUserId = UserHandle.getUserId(config.creatorUid);
- if (creatorUserId == MANAGED_PROFILE_USER_ID) {
- switchUser(MANAGED_PROFILE_PARENT_USER_ID);
- } else {
- switchUser(creatorUserId);
- }
+ private void switchUserToCreatorOf(WifiConfiguration config) {
+ switchUser(UserHandle.getUserId(config.creatorUid));
}
private void addNetworks() throws Exception {
@@ -201,7 +178,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
.thenReturn(true);
for (int i = 0; i < CONFIGS.size(); ++i) {
assertEquals(i, CONFIGS.get(i).networkId);
- switchUserToCreatorOrParentOf(CONFIGS.get(i));
+ switchUserToCreatorOf(CONFIGS.get(i));
final WifiConfiguration config = new WifiConfiguration(CONFIGS.get(i));
config.networkId = -1;
when(mWifiNative.addNetwork()).thenReturn(i);
@@ -303,8 +280,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
for (WifiConfiguration expectedConfig: CONFIGS) {
final WifiConfiguration actualConfig =
mConfigStore.getWifiConfiguration(expectedConfig.networkId);
- if (WifiConfigurationUtil.isVisibleToAnyProfile(expectedConfig,
- USER_PROFILES.get(userId))) {
+ if (expectedConfig.isVisibleToUser(userId)) {
verifyNetworkConfig(expectedConfig, actualConfig);
} else {
assertNull(actualConfig);
@@ -325,8 +301,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
for (WifiConfiguration expectedConfig: CONFIGS) {
final WifiConfiguration actualConfig =
mConfigStore.getWifiConfiguration(expectedConfig.configKey());
- if (WifiConfigurationUtil.isVisibleToAnyProfile(expectedConfig,
- USER_PROFILES.get(userId))) {
+ if (expectedConfig.isVisibleToUser(userId)) {
verifyNetworkConfig(expectedConfig, actualConfig);
} else {
assertNull(actualConfig);
@@ -359,8 +334,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
mConfigStore.enableAllNetworks();
for (WifiConfiguration config : mConfiguredNetworks.valuesForAllUsers()) {
- assertEquals(WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(userId)),
+ assertEquals(config.isVisibleToUser(userId),
config.getNetworkSelectionStatus().isNetworkEnabled());
}
}
@@ -387,8 +361,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
final WifiNative wifiNative = createNewWifiNativeMock();
final boolean success =
mConfigStore.selectNetwork(config, false, config.creatorUid);
- if (!WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(userId))) {
+ if (!config.isVisibleToUser(userId)) {
// If the network configuration is not visible to the current user, verify that
// nothing changed.
assertFalse(success);
@@ -409,8 +382,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
verify(wifiNative, never()).enableNetwork(intThat(not(config.networkId)),
anyBoolean());
for (WifiConfiguration config2 : mConfiguredNetworks.valuesForAllUsers()) {
- if (WifiConfigurationUtil.isVisibleToAnyProfile(config2,
- USER_PROFILES.get(userId))
+ if (config2.isVisibleToUser(userId)
&& config2.networkId != config.networkId) {
assertEquals(WifiConfiguration.Status.DISABLED, config2.status);
} else {
@@ -431,7 +403,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
*/
private void verifySaveNetwork(int network) throws Exception {
// Switch to the correct user.
- switchUserToCreatorOrParentOf(CONFIGS.get(network));
+ switchUserToCreatorOf(CONFIGS.get(network));
// Set up wpa_supplicant.
when(mWifiNative.addNetwork()).thenReturn(0);
@@ -558,21 +530,14 @@ public class WifiConfigStoreTest extends AndroidTestCase {
.thenReturn(null);
when(mWifiNative.getNetworkVariable(1, WifiConfigStore.ID_STRING_VAR_NAME))
.thenReturn('"' + CONFIGS.get(1).FQDN + '"');
- // Up-to-date Hotspot 2.0 network configuration: Metadata in "id_str".
- Map<String, String> metadata = new HashMap<String, String>();
+ // Up-to-date configuration: Metadata in "id_str".
+ final Map<String, String> metadata = new HashMap<String, String>();
metadata.put(WifiConfigStore.ID_STRING_KEY_CONFIG_KEY, CONFIGS.get(2).configKey());
metadata.put(WifiConfigStore.ID_STRING_KEY_CREATOR_UID,
Integer.toString(CONFIGS.get(2).creatorUid));
metadata.put(WifiConfigStore.ID_STRING_KEY_FQDN, CONFIGS.get(2).FQDN);
when(mWifiNative.getNetworkExtra(2, WifiConfigStore.ID_STRING_VAR_NAME))
.thenReturn(metadata);
- // Up-to-date regular network configuration: Metadata in "id_str".
- metadata = new HashMap<String, String>();
- metadata.put(WifiConfigStore.ID_STRING_KEY_CONFIG_KEY, CONFIGS.get(3).configKey());
- metadata.put(WifiConfigStore.ID_STRING_KEY_CREATOR_UID,
- Integer.toString(CONFIGS.get(3).creatorUid));
- when(mWifiNative.getNetworkExtra(3, WifiConfigStore.ID_STRING_VAR_NAME))
- .thenReturn(metadata);
// Set up networkHistory.txt file.
final File file = File.createTempFile("networkHistory.txt", null);
@@ -669,10 +634,9 @@ public class WifiConfigStoreTest extends AndroidTestCase {
final Collection<WifiConfiguration> oldConfigs = mConfiguredNetworks.valuesForAllUsers();
int expectedNumberOfConfigs = oldConfigs.size();
for (WifiConfiguration config : oldConfigs) {
- if (WifiConfigurationUtil.isVisibleToAnyProfile(config, USER_PROFILES.get(oldUserId))) {
+ if (config.isVisibleToUser(oldUserId)) {
config.status = WifiConfiguration.Status.ENABLED;
- if (WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(newUserId))) {
+ if (config.isVisibleToUser(newUserId)) {
if (makeOneConfigEphemeral && removedEphemeralConfig == null) {
config.ephemeral = true;
lastSelectedConfigurationField.set(mConfigStore, config.configKey());
@@ -683,8 +647,7 @@ public class WifiConfigStoreTest extends AndroidTestCase {
}
} else {
config.status = WifiConfiguration.Status.DISABLED;
- if (WifiConfigurationUtil.isVisibleToAnyProfile(config,
- USER_PROFILES.get(newUserId))) {
+ if (config.isVisibleToUser(newUserId)) {
newUserOnlyConfigs.add(config);
} else {
neitherUserConfigs.add(config);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtil.java
index 7117c2a61..1368fc1c2 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtil.java
@@ -11,7 +11,7 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License.
+ * limitations under the License
*/
package com.android.server.wifi;
@@ -22,7 +22,7 @@ import android.net.wifi.WifiEnterpriseConfig;
/**
* Helper for creating and populating WifiConfigurations in unit tests.
*/
-public class WifiConfigurationTestUtil {
+public class WifiConfigurationUtil {
/**
* These values are used to describe AP's security setting. One AP can support multiple of them,
* only if there is no conflict.
@@ -32,17 +32,6 @@ public class WifiConfigurationTestUtil {
public static final int SECURITY_PSK = 1 << 1;
public static final int SECURITY_EAP = 1 << 2;
- /**
- * Construct a {@link android.net.wifi.WifiConfiguration}.
- * @param networkId the configuration's networkId
- * @param uid the configuration's creator uid
- * @param ssid the configuration's ssid
- * @param shared whether the configuration is shared with other users on the device
- * @param enabled whether the configuration is enabled
- * @param fqdn the configuration's FQDN (Hotspot 2.0 only)
- * @param providerFriendlyName the configuration's provider's friendly name (Hotspot 2.0 only)
- * @return the constructed {@link android.net.wifi.WifiConfiguration}
- */
public static WifiConfiguration generateWifiConfig(int networkId, int uid, String ssid,
boolean shared, boolean enabled, String fqdn, String providerFriendlyName) {
final WifiConfiguration config = new WifiConfiguration();
@@ -60,18 +49,6 @@ public class WifiConfigurationTestUtil {
return config;
}
- /**
- * Construct a {@link android.net.wifi.WifiConfiguration}.
- * @param networkId the configuration's networkId
- * @param uid the configuration's creator uid
- * @param ssid the configuration's ssid
- * @param shared whether the configuration is shared with other users on the device
- * @param enabled whether the configuration is enabled
- * @param fqdn the configuration's FQDN (Hotspot 2.0 only)
- * @param providerFriendlyName the configuration's provider's friendly name (Hotspot 2.0 only)
- * @param security the configuration's security type
- * @return the constructed {@link android.net.wifi.WifiConfiguration}
- */
public static WifiConfiguration generateWifiConfig(int networkId, int uid, String ssid,
boolean shared, boolean enabled, String fqdn, String providerFriendlyName,
int security) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java
deleted file mode 100644
index c5b50300e..000000000
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import android.content.pm.UserInfo;
-import android.net.wifi.WifiConfiguration;
-import android.os.UserHandle;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Unit tests for {@link com.android.server.wifi.WifiConfigurationUtil}.
- */
-@SmallTest
-public class WifiConfigurationUtilTest {
- static final int CURRENT_USER_ID = 0;
- static final int CURRENT_USER_MANAGED_PROFILE_USER_ID = 10;
- static final int OTHER_USER_ID = 11;
- static final List<UserInfo> PROFILES = Arrays.asList(
- new UserInfo(CURRENT_USER_ID, "owner", 0),
- new UserInfo(CURRENT_USER_MANAGED_PROFILE_USER_ID, "managed profile", 0));
-
- /**
- * Test for {@link WifiConfigurationUtil.isVisibleToAnyProfile}.
- */
- @Test
- public void isVisibleToAnyProfile() {
- // Shared network configuration created by another user.
- final WifiConfiguration configuration = new WifiConfiguration();
- configuration.creatorUid = UserHandle.getUid(OTHER_USER_ID, 0);
- assertTrue(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
-
- // Private network configuration created by another user.
- configuration.shared = false;
- assertFalse(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
-
- // Private network configuration created by the current user.
- configuration.creatorUid = UserHandle.getUid(CURRENT_USER_ID, 0);
- assertTrue(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
-
- // Private network configuration created by the current user's managed profile.
- configuration.creatorUid = UserHandle.getUid(CURRENT_USER_MANAGED_PROFILE_USER_ID, 0);
- assertTrue(WifiConfigurationUtil.isVisibleToAnyProfile(configuration, PROFILES));
- }
-}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectionTest.java b/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectionTest.java
index f6967aa74..0d35f5fcb 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectionTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectionTest.java
@@ -16,10 +16,10 @@
package com.android.server.wifi;
-import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_EAP;
-import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_NONE;
-import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_PSK;
-import static com.android.server.wifi.WifiConfigurationTestUtil.generateWifiConfig;
+import static com.android.server.wifi.WifiConfigurationUtil.SECURITY_EAP;
+import static com.android.server.wifi.WifiConfigurationUtil.SECURITY_NONE;
+import static com.android.server.wifi.WifiConfigurationUtil.SECURITY_PSK;
+import static com.android.server.wifi.WifiConfigurationUtil.generateWifiConfig;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyInt;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index d7614753a..43e5da06a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -17,16 +17,13 @@
package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyObject;
import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
@@ -34,12 +31,11 @@ import static org.mockito.Mockito.withSettings;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
-import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.DhcpResults;
-import android.net.LinkProperties;
import android.net.ip.IpManager;
+import android.net.LinkProperties;
import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration;
@@ -47,7 +43,6 @@ import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
import android.net.wifi.p2p.IWifiP2pManager;
import android.os.BatteryStats;
-import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
@@ -59,7 +54,6 @@ import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.UserHandle;
-import android.os.UserManager;
import android.provider.Settings;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
@@ -87,7 +81,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -99,11 +92,6 @@ import java.util.Map;
public class WifiStateMachineTest {
public static final String TAG = "WifiStateMachineTest";
- private static final int MANAGED_PROFILE_UID = 1100000;
- private static final int OTHER_USER_UID = 1200000;
-
- private long mBinderToken;
-
private static <T> T mockWithInterfaces(Class<T> class1, Class<?>... interfaces) {
return mock(class1, withSettings().extraInterfaces(interfaces));
}
@@ -147,7 +135,7 @@ public class WifiStateMachineTest {
}
}
- private FrameworkFacade getFrameworkFacade() throws Exception {
+ private FrameworkFacade getFrameworkFacade() throws InterruptedException {
FrameworkFacade facade = mock(FrameworkFacade.class);
when(facade.makeBaseLogger()).thenReturn(mock(BaseWifiLogger.class));
@@ -190,9 +178,6 @@ public class WifiStateMachineTest {
}
});
- when(facade.checkUidPermission(eq(android.Manifest.permission.OVERRIDE_WIFI_CONFIG),
- anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED);
-
return facade;
}
@@ -314,7 +299,6 @@ public class WifiStateMachineTest {
@Mock WifiNative mWifiNative;
@Mock SupplicantStateTracker mSupplicantStateTracker;
@Mock WifiMetrics mWifiMetrics;
- @Mock UserManager mUserManager;
public WifiStateMachineTest() throws Exception {
}
@@ -352,13 +336,7 @@ public class WifiStateMachineTest {
any(Context.class), any(WifiStateMachine.class), any(WifiConfigStore.class),
any(Handler.class))).thenReturn(mSupplicantStateTracker);
- when(mUserManager.getProfileParent(11))
- .thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "owner", 0));
- when(mUserManager.getProfiles(UserHandle.USER_SYSTEM)).thenReturn(Arrays.asList(
- new UserInfo(UserHandle.USER_SYSTEM, "owner", 0),
- new UserInfo(11, "managed profile", 0)));
-
- mWsm = new WifiStateMachine(context, null, factory, mWifiMetrics, mUserManager);
+ mWsm = new WifiStateMachine(context, null, factory, mWifiMetrics);
mWsmThread = getWsmHandlerThread(mWsm);
final Object sync = new Object();
@@ -393,13 +371,10 @@ public class WifiStateMachineTest {
}
/* Now channel is supposed to be connected */
-
- mBinderToken = Binder.clearCallingIdentity();
}
@After
public void cleanUp() throws Exception {
- Binder.restoreCallingIdentity(mBinderToken);
if (mSyncThread != null) stopLooper(mSyncThread.getLooper());
if (mWsmThread != null) stopLooper(mWsmThread.getLooper());
@@ -471,7 +446,8 @@ public class WifiStateMachineTest {
assertEquals("InitialState", getCurrentState().getName());
}
- private void addNetworkAndVerifySuccess() throws Exception {
+ @Test
+ public void addNetwork() throws Exception {
loadComponents();
@@ -539,189 +515,10 @@ public class WifiStateMachineTest {
assertTrue(config2.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE));
}
- private void addNetworkAndVerifyFailure() throws Exception {
- loadComponents();
-
- final WifiConfiguration config = new WifiConfiguration();
- config.SSID = sSSID;
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
-
- mWsm.syncAddOrUpdateNetwork(mWsmAsyncChannel, config);
- wait(200);
-
- verify(mWifiNative, never()).addNetwork();
- verify(mWifiNative, never()).setNetworkVariable(anyInt(), anyString(), anyString());
-
- assertTrue(mWsm.syncGetConfiguredNetworks(-1, mWsmAsyncChannel).isEmpty());
- }
-
- /**
- * Verifies that the current foreground user is allowed to add a network.
- */
- @Test
- public void addNetworkAsCurrentUser() throws Exception {
- addNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a managed profile of the current foreground user is allowed to add a network.
- */
- @Test
- public void addNetworkAsCurrentUsersManagedProfile() throws Exception {
- BinderUtil.setUid(MANAGED_PROFILE_UID);
- addNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a background user is not allowed to add a network.
- */
- @Test
- public void addNetworkAsOtherUser() throws Exception {
- BinderUtil.setUid(OTHER_USER_UID);
- addNetworkAndVerifyFailure();
- }
-
- private void removeNetworkAndVerifySuccess() throws Exception {
- when(mWifiNative.removeNetwork(0)).thenReturn(true);
- assertTrue(mWsm.syncRemoveNetwork(mWsmAsyncChannel, 0));
- wait(200);
- assertTrue(mWsm.syncGetConfiguredNetworks(-1, mWsmAsyncChannel).isEmpty());
- }
-
- private void removeNetworkAndVerifyFailure() throws Exception {
- assertFalse(mWsm.syncRemoveNetwork(mWsmAsyncChannel, 0));
- wait(200);
- assertEquals(1, mWsm.syncGetConfiguredNetworks(-1, mWsmAsyncChannel).size());
- verify(mWifiNative, never()).removeNetwork(anyInt());
- }
-
- /**
- * Verifies that the current foreground user is allowed to remove a network.
- */
- @Test
- public void removeNetworkAsCurrentUser() throws Exception {
- addNetworkAndVerifySuccess();
- removeNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a managed profile of the current foreground user is allowed to remove a
- * network.
- */
- @Test
- public void removeNetworkAsCurrentUsersManagedProfile() throws Exception {
- addNetworkAndVerifySuccess();
- BinderUtil.setUid(MANAGED_PROFILE_UID);
- removeNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a background user is not allowed to remove a network.
- */
- @Test
- public void removeNetworkAsOtherUser() throws Exception {
- addNetworkAndVerifySuccess();
- BinderUtil.setUid(OTHER_USER_UID);
- removeNetworkAndVerifyFailure();
- }
-
- private void enableNetworkAndVerifySuccess() throws Exception {
- when(mWifiNative.enableNetwork(0, true)).thenReturn(true);
- assertTrue(mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true));
- wait(200);
- verify(mWifiNative).enableNetwork(0, true);
- }
-
- private void enableNetworkAndVerifyFailure() throws Exception {
- assertFalse(mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true));
- wait(200);
- verify(mWifiNative, never()).enableNetwork(anyInt(), anyBoolean());
- }
-
- /**
- * Verifies that the current foreground user is allowed to enable a network.
- */
- @Test
- public void enableNetworkAsCurrentUser() throws Exception {
- addNetworkAndVerifySuccess();
- enableNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a managed profile of the current foreground user is allowed to enable a
- * network.
- */
- @Test
- public void enableNetworkAsCurrentUsersManagedProfile() throws Exception {
- addNetworkAndVerifySuccess();
- BinderUtil.setUid(MANAGED_PROFILE_UID);
- enableNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a background user is not allowed to enable a network.
- */
- @Test
- public void enableNetworkAsOtherUser() throws Exception {
- addNetworkAndVerifySuccess();
- BinderUtil.setUid(OTHER_USER_UID);
- enableNetworkAndVerifyFailure();
- }
-
- private void forgetNetworkAndVerifySuccess() throws Exception {
- when(mWifiNative.removeNetwork(0)).thenReturn(true);
- final Message result =
- mWsmAsyncChannel.sendMessageSynchronously(WifiManager.FORGET_NETWORK, 0);
- assertEquals(WifiManager.FORGET_NETWORK_SUCCEEDED, result.what);
- result.recycle();
- wait(200);
- assertTrue(mWsm.syncGetConfiguredNetworks(-1, mWsmAsyncChannel).isEmpty());
- }
-
- private void forgetNetworkAndVerifyFailure() throws Exception {
- final Message result =
- mWsmAsyncChannel.sendMessageSynchronously(WifiManager.FORGET_NETWORK, 0);
- assertEquals(WifiManager.FORGET_NETWORK_FAILED, result.what);
- result.recycle();
- wait(200);
- assertEquals(1, mWsm.syncGetConfiguredNetworks(-1, mWsmAsyncChannel).size());
- verify(mWifiNative, never()).removeNetwork(anyInt());
- }
-
- /**
- * Verifies that the current foreground user is allowed to forget a network.
- */
- @Test
- public void forgetNetworkAsCurrentUser() throws Exception {
- addNetworkAndVerifySuccess();
- forgetNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a managed profile of the current foreground user is allowed to forget a
- * network.
- */
- @Test
- public void forgetNetworkAsCurrentUsersManagedProfile() throws Exception {
- addNetworkAndVerifySuccess();
- BinderUtil.setUid(MANAGED_PROFILE_UID);
- forgetNetworkAndVerifySuccess();
- }
-
- /**
- * Verifies that a background user is not allowed to forget a network.
- */
- @Test
- public void forgetNetworkAsOtherUser() throws Exception {
- addNetworkAndVerifySuccess();
- BinderUtil.setUid(OTHER_USER_UID);
- forgetNetworkAndVerifyFailure();
- }
-
@Test
public void scan() throws Exception {
- addNetworkAndVerifySuccess();
+ addNetwork();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
@@ -741,7 +538,7 @@ public class WifiStateMachineTest {
@Test
public void connect() throws Exception {
- addNetworkAndVerifySuccess();
+ addNetwork();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true);
@@ -770,7 +567,7 @@ public class WifiStateMachineTest {
@Test
public void testDhcpFailure() throws Exception {
- addNetworkAndVerifySuccess();
+ addNetwork();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true);
@@ -794,7 +591,7 @@ public class WifiStateMachineTest {
@Test
public void testBadNetworkEvent() throws Exception {
- addNetworkAndVerifySuccess();
+ addNetwork();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true);
@@ -837,7 +634,7 @@ public class WifiStateMachineTest {
@Test
public void iconQueryTest() throws Exception {
/* enable wi-fi */
- addNetworkAndVerifySuccess();
+ addNetwork();
long bssid = 0x1234567800FFL;
String filename = "iconFileName.png";