WifiConfigurationTestUtil.java revision 1fe1065da82165183fa057ddbbd2e33bc5708c1b
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server.wifi; 18 19import static org.junit.Assert.*; 20 21import android.net.IpConfiguration; 22import android.net.LinkAddress; 23import android.net.NetworkUtils; 24import android.net.ProxyInfo; 25import android.net.StaticIpConfiguration; 26import android.net.wifi.WifiConfiguration; 27import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; 28import android.net.wifi.WifiEnterpriseConfig; 29import android.text.TextUtils; 30 31import java.net.InetAddress; 32import java.security.cert.X509Certificate; 33import java.util.List; 34 35/** 36 * Helper for creating and populating WifiConfigurations in unit tests. 37 */ 38public class WifiConfigurationTestUtil { 39 /** 40 * These values are used to describe AP's security setting. One AP can support multiple of them, 41 * only if there is no conflict. 42 */ 43 public static final int SECURITY_NONE = 0; 44 public static final int SECURITY_WEP = 1 << 0; 45 public static final int SECURITY_PSK = 1 << 1; 46 public static final int SECURITY_EAP = 1 << 2; 47 48 /** 49 * These values are used to describe ip configuration parameters for a network. 50 */ 51 public static final int STATIC_IP_ASSIGNMENT = 0; 52 public static final int DHCP_IP_ASSIGNMENT = 1; 53 public static final int STATIC_PROXY_SETTING = 0; 54 public static final int PAC_PROXY_SETTING = 1; 55 public static final int NONE_PROXY_SETTING = 2; 56 57 /** 58 * These are constants used to generate predefined WifiConfiguration objects. 59 */ 60 public static final int TEST_NETWORK_ID = -1; 61 public static final int TEST_UID = 5; 62 public static final String TEST_SSID = "WifiConfigurationTestUtilSSID"; 63 public static final String TEST_PSK = "WifiConfigurationTestUtilPsk"; 64 public static final String[] TEST_WEP_KEYS = 65 {"WifiConfigurationTestUtilWep1", "WifiConfigurationTestUtilWep2", 66 "WifiConfigurationTestUtilWep3", "WifiConfigurationTestUtilWep3"}; 67 public static final int TEST_WEP_TX_KEY_INDEX = 1; 68 public static final String TEST_FQDN = "WifiConfigurationTestUtilFQDN"; 69 public static final String TEST_PROVIDER_FRIENDLY_NAME = 70 "WifiConfigurationTestUtilFriendlyName"; 71 public static final String TEST_STATIC_IP_LINK_ADDRESS = "192.168.48.2"; 72 public static final int TEST_STATIC_IP_LINK_PREFIX_LENGTH = 8; 73 public static final String TEST_STATIC_IP_GATEWAY_ADDRESS = "192.168.48.1"; 74 public static final String[] TEST_STATIC_IP_DNS_SERVER_ADDRESSES = 75 new String[]{"192.168.48.1", "192.168.48.10"}; 76 public static final String TEST_STATIC_PROXY_HOST = "192.168.48.1"; 77 public static final int TEST_STATIC_PROXY_PORT = 8000; 78 public static final String TEST_STATIC_PROXY_EXCLUSION_LIST = ""; 79 public static final String TEST_PAC_PROXY_LOCATION = "http://"; 80 public static final String TEST_CA_CERT_ALIAS = "WifiConfigurationTestUtilCaCertAlias"; 81 82 private static final int MAX_SSID_LENGTH = 32; 83 /** 84 * Index used to assign unique SSIDs for the generation of predefined WifiConfiguration objects. 85 */ 86 private static int sNetworkIndex = 0; 87 88 /** 89 * Construct a {@link android.net.wifi.WifiConfiguration}. 90 * @param networkId the configuration's networkId 91 * @param uid the configuration's creator uid 92 * @param ssid the configuration's ssid 93 * @param shared whether the configuration is shared with other users on the device 94 * @param enabled whether the configuration is enabled 95 * @param fqdn the configuration's FQDN (Hotspot 2.0 only) 96 * @param providerFriendlyName the configuration's provider's friendly name (Hotspot 2.0 only) 97 * @return the constructed {@link android.net.wifi.WifiConfiguration} 98 */ 99 public static WifiConfiguration generateWifiConfig(int networkId, int uid, String ssid, 100 boolean shared, boolean enabled, String fqdn, String providerFriendlyName) { 101 final WifiConfiguration config = new WifiConfiguration(); 102 config.SSID = ssid; 103 config.networkId = networkId; 104 config.creatorUid = uid; 105 config.shared = shared; 106 config.status = enabled ? WifiConfiguration.Status.ENABLED 107 : WifiConfiguration.Status.DISABLED; 108 if (fqdn != null) { 109 config.FQDN = fqdn; 110 config.providerFriendlyName = providerFriendlyName; 111 config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM); 112 } 113 return config; 114 } 115 116 /** 117 * Construct a {@link android.net.wifi.WifiConfiguration}. 118 * @param networkId the configuration's networkId 119 * @param uid the configuration's creator uid 120 * @param ssid the configuration's ssid 121 * @param shared whether the configuration is shared with other users on the device 122 * @param enabled whether the configuration is enabled 123 * @param fqdn the configuration's FQDN (Hotspot 2.0 only) 124 * @param providerFriendlyName the configuration's provider's friendly name (Hotspot 2.0 only) 125 * @param security the configuration's security type 126 * @return the constructed {@link android.net.wifi.WifiConfiguration} 127 */ 128 public static WifiConfiguration generateWifiConfig(int networkId, int uid, String ssid, 129 boolean shared, boolean enabled, String fqdn, String providerFriendlyName, 130 int security) { 131 WifiConfiguration config = generateWifiConfig(networkId, uid, ssid, shared, enabled, fqdn, 132 providerFriendlyName); 133 134 if ((security == SECURITY_NONE) || ((security & SECURITY_WEP) != 0)) { 135 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 136 } else { 137 if ((security & SECURITY_PSK) != 0) { 138 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); 139 } 140 141 if ((security & SECURITY_EAP) != 0) { 142 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); 143 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X); 144 } 145 } 146 return config; 147 } 148 149 /** 150 * Construct a {@link android.net.IpConfiguration }. 151 * @param ipAssignmentType One of {@link #STATIC_IP_ASSIGNMENT} or {@link #DHCP_IP_ASSIGNMENT}. 152 * @param proxySettingType One of {@link #STATIC_PROXY_SETTING} or {@link #PAC_PROXY_SETTING} or 153 * {@link #NONE_PROXY_SETTING}. 154 * @param linkAddress static ip address string. 155 * @param linkPrefixLength static ip address prefix length. 156 * @param gatewayAddress static gateway address. 157 * @param dnsServerAddresses list of dns servers for static ip configuration. 158 * @param proxyHost Static proxy server address. 159 * @param proxyPort Static proxy server port. 160 * @param proxyExclusionList Static proxy exclusion list. 161 * @param pacProxyPath Pac proxy server path. 162 * @return the constructed {@link android.net.IpConfiguration} 163 */ 164 public static IpConfiguration generateIpConfig( 165 int ipAssignmentType, int proxySettingType, String linkAddress, int linkPrefixLength, 166 String gatewayAddress, String[] dnsServerAddresses, String proxyHost, 167 int proxyPort, String proxyExclusionList, String pacProxyPath) { 168 StaticIpConfiguration staticIpConfiguration = null; 169 ProxyInfo proxyInfo = null; 170 IpConfiguration.IpAssignment ipAssignment = IpConfiguration.IpAssignment.UNASSIGNED; 171 IpConfiguration.ProxySettings proxySettings = IpConfiguration.ProxySettings.UNASSIGNED; 172 173 if (ipAssignmentType == STATIC_IP_ASSIGNMENT) { 174 staticIpConfiguration = new StaticIpConfiguration(); 175 if (!TextUtils.isEmpty(linkAddress)) { 176 LinkAddress linkAddr = 177 new LinkAddress( 178 NetworkUtils.numericToInetAddress(linkAddress), linkPrefixLength); 179 staticIpConfiguration.ipAddress = linkAddr; 180 } 181 182 if (!TextUtils.isEmpty(gatewayAddress)) { 183 InetAddress gatewayAddr = 184 NetworkUtils.numericToInetAddress(gatewayAddress); 185 staticIpConfiguration.gateway = gatewayAddr; 186 } 187 if (dnsServerAddresses != null) { 188 for (String dnsServerAddress : dnsServerAddresses) { 189 if (!TextUtils.isEmpty(dnsServerAddress)) { 190 staticIpConfiguration.dnsServers.add( 191 NetworkUtils.numericToInetAddress(dnsServerAddress)); 192 } 193 194 } 195 } 196 ipAssignment = IpConfiguration.IpAssignment.STATIC; 197 } else if (ipAssignmentType == DHCP_IP_ASSIGNMENT) { 198 ipAssignment = IpConfiguration.IpAssignment.DHCP; 199 } 200 201 if (proxySettingType == STATIC_PROXY_SETTING) { 202 proxyInfo = new ProxyInfo(proxyHost, proxyPort, proxyExclusionList); 203 proxySettings = IpConfiguration.ProxySettings.STATIC; 204 } else if (proxySettingType == PAC_PROXY_SETTING) { 205 proxyInfo = new ProxyInfo(pacProxyPath); 206 proxySettings = IpConfiguration.ProxySettings.PAC; 207 } else if (proxySettingType == NONE_PROXY_SETTING) { 208 proxySettings = IpConfiguration.ProxySettings.NONE; 209 } 210 return new IpConfiguration(ipAssignment, proxySettings, staticIpConfiguration, proxyInfo); 211 } 212 213 /** 214 * Create a new SSID for the the network being created. 215 */ 216 private static String createNewSSID() { 217 String ssid = TEST_SSID + sNetworkIndex++; 218 assertTrue(ssid.length() <= MAX_SSID_LENGTH); 219 return "\"" + ssid + "\""; 220 } 221 222 /** 223 * Helper methods to generate predefined WifiConfiguration objects of the required type. These 224 * use a static index to avoid duplicate configurations. 225 */ 226 public static WifiConfiguration createOpenNetwork() { 227 return generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 228 null, SECURITY_NONE); 229 } 230 231 public static WifiConfiguration createOpenHiddenNetwork() { 232 WifiConfiguration configuration = createOpenNetwork(); 233 configuration.hiddenSSID = true; 234 return configuration; 235 } 236 237 public static WifiConfiguration createPskNetwork() { 238 WifiConfiguration configuration = 239 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 240 null, SECURITY_PSK); 241 configuration.preSharedKey = TEST_PSK; 242 return configuration; 243 } 244 245 public static WifiConfiguration createPskHiddenNetwork() { 246 WifiConfiguration configuration = createPskNetwork(); 247 configuration.hiddenSSID = true; 248 return configuration; 249 } 250 251 public static WifiConfiguration createWepNetwork() { 252 WifiConfiguration configuration = 253 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 254 null, SECURITY_WEP); 255 configuration.wepKeys = TEST_WEP_KEYS; 256 configuration.wepTxKeyIndex = TEST_WEP_TX_KEY_INDEX; 257 return configuration; 258 } 259 260 public static WifiConfiguration createWepHiddenNetwork() { 261 WifiConfiguration configuration = createWepNetwork(); 262 configuration.hiddenSSID = true; 263 return configuration; 264 } 265 266 267 public static WifiConfiguration createWepNetworkWithSingleKey() { 268 WifiConfiguration configuration = 269 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 270 null, SECURITY_WEP); 271 configuration.wepKeys[0] = TEST_WEP_KEYS[0]; 272 configuration.wepTxKeyIndex = 0; 273 return configuration; 274 } 275 276 277 public static WifiConfiguration createEapNetwork() { 278 WifiConfiguration configuration = 279 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, 280 TEST_FQDN, TEST_PROVIDER_FRIENDLY_NAME, SECURITY_EAP); 281 return configuration; 282 } 283 284 public static IpConfiguration createStaticIpConfigurationWithPacProxy() { 285 return generateIpConfig( 286 STATIC_IP_ASSIGNMENT, PAC_PROXY_SETTING, 287 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 288 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 289 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 290 TEST_PAC_PROXY_LOCATION); 291 } 292 293 public static IpConfiguration createStaticIpConfigurationWithStaticProxy() { 294 return generateIpConfig( 295 STATIC_IP_ASSIGNMENT, STATIC_PROXY_SETTING, 296 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 297 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 298 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 299 TEST_PAC_PROXY_LOCATION); 300 } 301 302 public static IpConfiguration createPartialStaticIpConfigurationWithPacProxy() { 303 return generateIpConfig( 304 STATIC_IP_ASSIGNMENT, PAC_PROXY_SETTING, 305 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 306 null, null, 307 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 308 TEST_PAC_PROXY_LOCATION); 309 } 310 311 public static IpConfiguration createDHCPIpConfigurationWithPacProxy() { 312 return generateIpConfig( 313 DHCP_IP_ASSIGNMENT, PAC_PROXY_SETTING, 314 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 315 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 316 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 317 TEST_PAC_PROXY_LOCATION); 318 } 319 320 public static IpConfiguration createDHCPIpConfigurationWithStaticProxy() { 321 return generateIpConfig( 322 DHCP_IP_ASSIGNMENT, STATIC_PROXY_SETTING, 323 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 324 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 325 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 326 TEST_PAC_PROXY_LOCATION); 327 } 328 329 public static IpConfiguration createDHCPIpConfigurationWithNoProxy() { 330 return generateIpConfig( 331 DHCP_IP_ASSIGNMENT, NONE_PROXY_SETTING, 332 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 333 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 334 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 335 TEST_PAC_PROXY_LOCATION); 336 } 337 338 // TODO: These enterprise configurations may need more parameters set. 339 public static WifiEnterpriseConfig createPEAPWifiEnterpriseConfigWithGTCPhase2() { 340 WifiEnterpriseConfig config = new WifiEnterpriseConfig(); 341 config.setEapMethod(WifiEnterpriseConfig.Eap.PEAP); 342 config.setPhase2Method(WifiEnterpriseConfig.Phase2.GTC); 343 config.setCaCertificateAliases(new String[] {TEST_CA_CERT_ALIAS + "PEAP"}); 344 config.setCaCertificates(new X509Certificate[] {FakeKeys.CA_CERT0, FakeKeys.CA_CERT1}); 345 return config; 346 } 347 348 public static WifiEnterpriseConfig createTLSWifiEnterpriseConfigWithNonePhase2() { 349 WifiEnterpriseConfig config = new WifiEnterpriseConfig(); 350 config.setEapMethod(WifiEnterpriseConfig.Eap.TLS); 351 config.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE); 352 config.setCaCertificateAliases(new String[] {TEST_CA_CERT_ALIAS + "TLS"}); 353 config.setCaCertificates(new X509Certificate[] {FakeKeys.CA_CERT0, FakeKeys.CA_CERT1}); 354 return config; 355 } 356 357 /** 358 * Asserts that the 2 WifiConfigurations are equal in the elements saved for both backup/restore 359 * and config store. 360 */ 361 private static void assertCommonConfigurationElementsEqual( 362 WifiConfiguration expected, WifiConfiguration actual) { 363 assertNotNull(expected); 364 assertNotNull(actual); 365 assertEquals(expected.SSID, actual.SSID); 366 assertEquals(expected.BSSID, actual.BSSID); 367 assertEquals(expected.preSharedKey, actual.preSharedKey); 368 assertEquals(expected.wepKeys, actual.wepKeys); 369 assertEquals(expected.wepTxKeyIndex, actual.wepTxKeyIndex); 370 assertEquals(expected.hiddenSSID, actual.hiddenSSID); 371 assertEquals(expected.requirePMF, actual.requirePMF); 372 assertEquals(expected.allowedKeyManagement, actual.allowedKeyManagement); 373 assertEquals(expected.allowedProtocols, actual.allowedProtocols); 374 assertEquals(expected.allowedAuthAlgorithms, actual.allowedAuthAlgorithms); 375 assertEquals(expected.allowedGroupCiphers, actual.allowedGroupCiphers); 376 assertEquals(expected.allowedPairwiseCiphers, actual.allowedPairwiseCiphers); 377 assertEquals(expected.shared, actual.shared); 378 assertEquals(expected.getIpConfiguration(), actual.getIpConfiguration()); 379 } 380 381 /** 382 * Asserts that the 2 WifiConfigurations are equal. This only compares the elements saved 383 * fpr backup/restore. 384 */ 385 public static void assertConfigurationEqualForBackup( 386 WifiConfiguration expected, WifiConfiguration actual) { 387 assertCommonConfigurationElementsEqual(expected, actual); 388 } 389 390 /** 391 * Asserts that the 2 WifiConfigurations are equal. This compares all the elements saved for 392 * config store. 393 */ 394 public static void assertConfigurationEqualForConfigStore( 395 WifiConfiguration expected, WifiConfiguration actual) { 396 assertCommonConfigurationElementsEqual(expected, actual); 397 assertEquals(expected.FQDN, actual.FQDN); 398 assertEquals(expected.providerFriendlyName, actual.providerFriendlyName); 399 assertEquals(expected.linkedConfigurations, actual.linkedConfigurations); 400 assertEquals(expected.defaultGwMacAddress, actual.defaultGwMacAddress); 401 assertEquals(expected.validatedInternetAccess, actual.validatedInternetAccess); 402 assertEquals(expected.noInternetAccessExpected, actual.noInternetAccessExpected); 403 assertEquals(expected.userApproved, actual.userApproved); 404 assertEquals(expected.meteredHint, actual.meteredHint); 405 assertEquals(expected.useExternalScores, actual.useExternalScores); 406 assertEquals(expected.numAssociation, actual.numAssociation); 407 assertEquals(expected.creatorUid, actual.creatorUid); 408 assertEquals(expected.creatorName, actual.creatorName); 409 assertEquals(expected.creationTime, actual.creationTime); 410 assertEquals(expected.lastUpdateUid, actual.lastUpdateUid); 411 assertEquals(expected.lastUpdateName, actual.lastUpdateName); 412 assertEquals(expected.lastConnectUid, actual.lastConnectUid); 413 assertEquals(expected.updateTime, actual.updateTime); 414 assertNetworkSelectionStatusEqualForConfigStore( 415 expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus()); 416 assertWifiEnterpriseConfigEqualForConfigStore( 417 expected.enterpriseConfig, actual.enterpriseConfig); 418 } 419 420 /** 421 * Asserts that the 2 WifiConfigurations are equal. This compares all the elements that are 422 * saved into internal database by WifiConfigurationManager for network additions/updates. 423 */ 424 public static void assertConfigurationEqualForConfigManagerAddOrUpdate( 425 WifiConfiguration expected, WifiConfiguration actual) { 426 assertCommonConfigurationElementsEqual(expected, actual); 427 assertEquals(expected.FQDN, actual.FQDN); 428 assertEquals(expected.providerFriendlyName, actual.providerFriendlyName); 429 assertEquals(expected.noInternetAccessExpected, actual.noInternetAccessExpected); 430 assertEquals(expected.meteredHint, actual.meteredHint); 431 assertEquals(expected.useExternalScores, actual.useExternalScores); 432 assertEquals(expected.ephemeral, actual.ephemeral); 433 assertEquals(expected.creatorUid, actual.creatorUid); 434 assertEquals(expected.creatorName, actual.creatorName); 435 assertEquals(expected.creationTime, actual.creationTime); 436 assertEquals(expected.lastUpdateUid, actual.lastUpdateUid); 437 assertEquals(expected.lastUpdateName, actual.lastUpdateName); 438 assertEquals(expected.updateTime, actual.updateTime); 439 assertNetworkSelectionStatusEqualForConfigStore( 440 expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus()); 441 assertWifiEnterpriseConfigEqualForConfigStore( 442 expected.enterpriseConfig, actual.enterpriseConfig); 443 } 444 445 /** 446 * Asserts that the 2 WifiConfigurations are equal. This is a generic version of the comparator 447 * which is used in QNS tests for comparing the network selections. 448 * This importantly checks that the networkId's of the 2 configs are equal. 449 */ 450 public static void assertConfigurationEqual( 451 WifiConfiguration expected, WifiConfiguration actual) { 452 assertCommonConfigurationElementsEqual(expected, actual); 453 assertEquals(expected.networkId, actual.networkId); 454 } 455 456 /** 457 * Assert that the 2 NetworkSelectionStatus's are equal. This compares all the elements saved 458 * for config store. 459 */ 460 public static void assertNetworkSelectionStatusEqualForConfigStore( 461 NetworkSelectionStatus expected, NetworkSelectionStatus actual) { 462 if (expected.isNetworkTemporaryDisabled()) { 463 // Temporarily disabled networks are enabled when persisted. 464 assertEquals( 465 NetworkSelectionStatus.NETWORK_SELECTION_ENABLED, 466 actual.getNetworkSelectionStatus()); 467 assertEquals( 468 NetworkSelectionStatus.NETWORK_SELECTION_ENABLE, 469 actual.getNetworkSelectionDisableReason()); 470 } else { 471 assertEquals(expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus()); 472 assertEquals( 473 expected.getNetworkSelectionDisableReason(), 474 actual.getNetworkSelectionDisableReason()); 475 } 476 assertEquals(expected.getConnectChoice(), actual.getConnectChoice()); 477 assertEquals(expected.getConnectChoiceTimestamp(), actual.getConnectChoiceTimestamp()); 478 assertEquals(expected.getHasEverConnected(), actual.getHasEverConnected()); 479 } 480 481 /** 482 * Assert that the 2 WifiEnterpriseConfig's are equal. This compares all the elements saved 483 * for config store. 484 */ 485 public static void assertWifiEnterpriseConfigEqualForConfigStore( 486 WifiEnterpriseConfig expected, WifiEnterpriseConfig actual) { 487 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY), 488 actual.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY)); 489 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ANON_IDENTITY_KEY), 490 actual.getFieldValue(WifiEnterpriseConfig.ANON_IDENTITY_KEY)); 491 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.PASSWORD_KEY), 492 actual.getFieldValue(WifiEnterpriseConfig.PASSWORD_KEY)); 493 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.CLIENT_CERT_KEY), 494 actual.getFieldValue(WifiEnterpriseConfig.CLIENT_CERT_KEY)); 495 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.CA_CERT_KEY), 496 actual.getFieldValue(WifiEnterpriseConfig.CA_CERT_KEY)); 497 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.SUBJECT_MATCH_KEY), 498 actual.getFieldValue(WifiEnterpriseConfig.SUBJECT_MATCH_KEY)); 499 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ENGINE_KEY), 500 actual.getFieldValue(WifiEnterpriseConfig.ENGINE_KEY)); 501 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ENGINE_ID_KEY), 502 actual.getFieldValue(WifiEnterpriseConfig.ENGINE_ID_KEY)); 503 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY), 504 actual.getFieldValue(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY)); 505 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY), 506 actual.getFieldValue(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY)); 507 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.DOM_SUFFIX_MATCH_KEY), 508 actual.getFieldValue(WifiEnterpriseConfig.DOM_SUFFIX_MATCH_KEY)); 509 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.CA_PATH_KEY), 510 actual.getFieldValue(WifiEnterpriseConfig.CA_PATH_KEY)); 511 assertEquals(expected.getEapMethod(), actual.getEapMethod()); 512 assertEquals(expected.getPhase2Method(), actual.getPhase2Method()); 513 } 514 515 /** 516 * Asserts that the 2 lists of WifiConfigurations are equal. This compares all the elements 517 * saved for backup/restore. 518 */ 519 public static void assertConfigurationsEqualForBackup( 520 List<WifiConfiguration> expected, List<WifiConfiguration> actual) { 521 assertEquals(expected.size(), actual.size()); 522 for (WifiConfiguration expectedConfiguration : expected) { 523 String expectedConfigKey = expectedConfiguration.configKey(); 524 boolean didCompare = false; 525 for (WifiConfiguration actualConfiguration : actual) { 526 String actualConfigKey = actualConfiguration.configKey(); 527 if (actualConfigKey.equals(expectedConfigKey)) { 528 assertConfigurationEqualForBackup( 529 expectedConfiguration, actualConfiguration); 530 didCompare = true; 531 } 532 } 533 assertTrue(didCompare); 534 } 535 } 536 537 /** 538 * Asserts that the 2 lists of WifiConfigurations are equal. This compares all the elements 539 * that are saved into internal database by WifiConfigurationManager for network 540 * additions/updates. 541 */ 542 public static void assertConfigurationsEqualForConfigManagerAddOrUpdate( 543 List<WifiConfiguration> expected, List<WifiConfiguration> actual) { 544 assertEquals(expected.size(), actual.size()); 545 for (WifiConfiguration expectedConfiguration : expected) { 546 String expectedConfigKey = expectedConfiguration.configKey(); 547 boolean didCompare = false; 548 for (WifiConfiguration actualConfiguration : actual) { 549 String actualConfigKey = actualConfiguration.configKey(); 550 if (actualConfigKey.equals(expectedConfigKey)) { 551 assertConfigurationEqualForConfigManagerAddOrUpdate( 552 expectedConfiguration, actualConfiguration); 553 didCompare = true; 554 } 555 } 556 assertTrue(didCompare); 557 } 558 } 559 560 /** 561 * Asserts that the 2 lists of WifiConfigurations are equal. This compares all the elements 562 * saved for config store. 563 */ 564 public static void assertConfigurationsEqualForConfigStore( 565 List<WifiConfiguration> expected, List<WifiConfiguration> actual) { 566 assertEquals(expected.size(), actual.size()); 567 for (WifiConfiguration expectedConfiguration : expected) { 568 String expectedConfigKey = expectedConfiguration.configKey(); 569 boolean didCompare = false; 570 for (WifiConfiguration actualConfiguration : actual) { 571 String actualConfigKey = actualConfiguration.configKey(); 572 if (actualConfigKey.equals(expectedConfigKey)) { 573 assertConfigurationEqualForConfigStore( 574 expectedConfiguration, actualConfiguration); 575 didCompare = true; 576 } 577 } 578 assertTrue(didCompare); 579 } 580 } 581} 582