WifiConfigurationTestUtil.java revision 1fa858ae90e82658e2d5332f66c62c671e736bfb
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.FakeKeys; 27import android.net.wifi.WifiConfiguration; 28import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; 29import android.net.wifi.WifiEnterpriseConfig; 30import android.text.TextUtils; 31 32import java.net.InetAddress; 33import java.security.cert.X509Certificate; 34import java.util.List; 35 36/** 37 * Helper for creating and populating WifiConfigurations in unit tests. 38 */ 39public class WifiConfigurationTestUtil { 40 /** 41 * These values are used to describe AP's security setting. One AP can support multiple of them, 42 * only if there is no conflict. 43 */ 44 public static final int SECURITY_NONE = 0; 45 public static final int SECURITY_WEP = 1 << 0; 46 public static final int SECURITY_PSK = 1 << 1; 47 public static final int SECURITY_EAP = 1 << 2; 48 49 /** 50 * These values are used to describe ip configuration parameters for a network. 51 */ 52 public static final int STATIC_IP_ASSIGNMENT = 0; 53 public static final int DHCP_IP_ASSIGNMENT = 1; 54 public static final int STATIC_PROXY_SETTING = 0; 55 public static final int PAC_PROXY_SETTING = 1; 56 public static final int NONE_PROXY_SETTING = 2; 57 58 /** 59 * These are constants used to generate predefined WifiConfiguration objects. 60 */ 61 public static final int TEST_NETWORK_ID = -1; 62 public static final int TEST_UID = 1; 63 public static final String TEST_SSID = "WifiConfigurationTestUtilSSID_"; 64 public static final String TEST_PSK = "WifiConfigurationTestUtilPsk"; 65 public static final String[] TEST_WEP_KEYS = 66 {"WifiConfigurationTestUtilWep1", "WifiConfigurationTestUtilWep2", 67 "WifiConfigurationTestUtilWep3", "WifiConfigurationTestUtilWep3"}; 68 public static final int TEST_WEP_TX_KEY_INDEX = 1; 69 public static final String TEST_FQDN = "WifiConfigurationTestUtilFQDN"; 70 public static final String TEST_PROVIDER_FRIENDLY_NAME = 71 "WifiConfigurationTestUtilFriendlyName"; 72 public static final String TEST_STATIC_IP_LINK_ADDRESS = "192.168.48.2"; 73 public static final int TEST_STATIC_IP_LINK_PREFIX_LENGTH = 8; 74 public static final String TEST_STATIC_IP_GATEWAY_ADDRESS = "192.168.48.1"; 75 public static final String[] TEST_STATIC_IP_DNS_SERVER_ADDRESSES = 76 new String[]{"192.168.48.1", "192.168.48.10"}; 77 public static final String TEST_STATIC_PROXY_HOST = "192.168.48.1"; 78 public static final int TEST_STATIC_PROXY_PORT = 8000; 79 public static final String TEST_STATIC_PROXY_EXCLUSION_LIST = ""; 80 public static final String TEST_PAC_PROXY_LOCATION = "http://"; 81 public static final String TEST_CA_CERT_ALIAS = "WifiConfigurationTestUtilCaCertAlias"; 82 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) { 135 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 136 } else { 137 if (((security & SECURITY_WEP) != 0) || ((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 return "\"" + TEST_SSID + sNetworkIndex++ + "\""; 218 } 219 220 /** 221 * Helper methods to generate predefined WifiConfiguration objects of the required type. These 222 * use a static index to avoid duplicate configurations. 223 */ 224 public static WifiConfiguration createOpenNetwork() { 225 return generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 226 null, SECURITY_NONE); 227 } 228 229 public static WifiConfiguration createOpenHiddenNetwork() { 230 WifiConfiguration configuration = createOpenNetwork(); 231 configuration.hiddenSSID = true; 232 return configuration; 233 } 234 235 public static WifiConfiguration createPskNetwork() { 236 WifiConfiguration configuration = 237 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 238 null, SECURITY_PSK); 239 configuration.preSharedKey = TEST_PSK; 240 return configuration; 241 } 242 243 public static WifiConfiguration createPskHiddenNetwork() { 244 WifiConfiguration configuration = createPskNetwork(); 245 configuration.hiddenSSID = true; 246 return configuration; 247 } 248 249 public static WifiConfiguration createWepNetwork() { 250 WifiConfiguration configuration = 251 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 252 null, SECURITY_WEP); 253 configuration.wepKeys = TEST_WEP_KEYS; 254 configuration.wepTxKeyIndex = TEST_WEP_TX_KEY_INDEX; 255 return configuration; 256 } 257 258 public static WifiConfiguration createWepHiddenNetwork() { 259 WifiConfiguration configuration = createWepNetwork(); 260 configuration.hiddenSSID = true; 261 return configuration; 262 } 263 264 265 public static WifiConfiguration createWepNetworkWithSingleKey() { 266 WifiConfiguration configuration = 267 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, 268 null, SECURITY_WEP); 269 configuration.wepKeys[0] = TEST_WEP_KEYS[0]; 270 configuration.wepTxKeyIndex = 0; 271 return configuration; 272 } 273 274 275 public static WifiConfiguration createEapNetwork() { 276 WifiConfiguration configuration = 277 generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, 278 TEST_FQDN, TEST_PROVIDER_FRIENDLY_NAME, SECURITY_EAP); 279 return configuration; 280 } 281 282 public static IpConfiguration createStaticIpConfigurationWithPacProxy() { 283 return generateIpConfig( 284 STATIC_IP_ASSIGNMENT, PAC_PROXY_SETTING, 285 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 286 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 287 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 288 TEST_PAC_PROXY_LOCATION); 289 } 290 291 public static IpConfiguration createStaticIpConfigurationWithStaticProxy() { 292 return generateIpConfig( 293 STATIC_IP_ASSIGNMENT, STATIC_PROXY_SETTING, 294 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 295 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 296 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 297 TEST_PAC_PROXY_LOCATION); 298 } 299 300 public static IpConfiguration createPartialStaticIpConfigurationWithPacProxy() { 301 return generateIpConfig( 302 STATIC_IP_ASSIGNMENT, PAC_PROXY_SETTING, 303 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 304 null, null, 305 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 306 TEST_PAC_PROXY_LOCATION); 307 } 308 309 public static IpConfiguration createDHCPIpConfigurationWithPacProxy() { 310 return generateIpConfig( 311 DHCP_IP_ASSIGNMENT, PAC_PROXY_SETTING, 312 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 313 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 314 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 315 TEST_PAC_PROXY_LOCATION); 316 } 317 318 public static IpConfiguration createDHCPIpConfigurationWithStaticProxy() { 319 return generateIpConfig( 320 DHCP_IP_ASSIGNMENT, STATIC_PROXY_SETTING, 321 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 322 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 323 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 324 TEST_PAC_PROXY_LOCATION); 325 } 326 327 public static IpConfiguration createDHCPIpConfigurationWithNoProxy() { 328 return generateIpConfig( 329 DHCP_IP_ASSIGNMENT, NONE_PROXY_SETTING, 330 TEST_STATIC_IP_LINK_ADDRESS, TEST_STATIC_IP_LINK_PREFIX_LENGTH, 331 TEST_STATIC_IP_GATEWAY_ADDRESS, TEST_STATIC_IP_DNS_SERVER_ADDRESSES, 332 TEST_STATIC_PROXY_HOST, TEST_STATIC_PROXY_PORT, TEST_STATIC_PROXY_EXCLUSION_LIST, 333 TEST_PAC_PROXY_LOCATION); 334 } 335 336 // TODO: These enterprise configurations may need more parameters set. 337 public static WifiEnterpriseConfig createPEAPWifiEnterpriseConfigWithGTCPhase2() { 338 WifiEnterpriseConfig config = new WifiEnterpriseConfig(); 339 config.setEapMethod(WifiEnterpriseConfig.Eap.PEAP); 340 config.setPhase2Method(WifiEnterpriseConfig.Phase2.GTC); 341 config.setCaCertificateAliases(new String[] {TEST_CA_CERT_ALIAS + "PEAP"}); 342 config.setCaCertificates(new X509Certificate[] {FakeKeys.CA_CERT0, FakeKeys.CA_CERT1}); 343 return config; 344 } 345 346 public static WifiEnterpriseConfig createTLSWifiEnterpriseConfigWithNonePhase2() { 347 WifiEnterpriseConfig config = new WifiEnterpriseConfig(); 348 config.setEapMethod(WifiEnterpriseConfig.Eap.TLS); 349 config.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE); 350 config.setCaCertificateAliases(new String[] {TEST_CA_CERT_ALIAS + "TLS"}); 351 config.setCaCertificates(new X509Certificate[] {FakeKeys.CA_CERT0, FakeKeys.CA_CERT1}); 352 return config; 353 } 354 355 /** 356 * Asserts that the 2 WifiConfigurations are equal in the elements saved for both backup/restore 357 * and config store. 358 */ 359 private static void assertCommonConfigurationElementsEqual( 360 WifiConfiguration expected, WifiConfiguration actual) { 361 assertEquals(expected.SSID, actual.SSID); 362 assertEquals(expected.BSSID, actual.BSSID); 363 assertEquals(expected.preSharedKey, actual.preSharedKey); 364 assertEquals(expected.wepKeys, actual.wepKeys); 365 assertEquals(expected.wepTxKeyIndex, actual.wepTxKeyIndex); 366 assertEquals(expected.hiddenSSID, actual.hiddenSSID); 367 assertEquals(expected.allowedKeyManagement, actual.allowedKeyManagement); 368 assertEquals(expected.allowedProtocols, actual.allowedProtocols); 369 assertEquals(expected.allowedAuthAlgorithms, actual.allowedAuthAlgorithms); 370 assertEquals(expected.shared, actual.shared); 371 assertEquals(expected.getIpConfiguration(), actual.getIpConfiguration()); 372 } 373 374 /** 375 * Asserts that the 2 WifiConfigurations are equal. This only compares the elements saved 376 * fpr backup/restore. 377 */ 378 public static void assertConfigurationEqualForBackup( 379 WifiConfiguration expected, WifiConfiguration actual) { 380 assertCommonConfigurationElementsEqual(expected, actual); 381 } 382 383 /** 384 * Asserts that the 2 WifiConfigurations are equal. This compares all the elements saved for 385 * config store. 386 */ 387 public static void assertConfigurationEqualForConfigStore( 388 WifiConfiguration expected, WifiConfiguration actual) { 389 assertCommonConfigurationElementsEqual(expected, actual); 390 assertEquals(expected.FQDN, actual.FQDN); 391 assertEquals(expected.providerFriendlyName, actual.providerFriendlyName); 392 assertEquals(expected.linkedConfigurations, actual.linkedConfigurations); 393 assertEquals(expected.defaultGwMacAddress, actual.defaultGwMacAddress); 394 assertEquals(expected.validatedInternetAccess, actual.validatedInternetAccess); 395 assertEquals(expected.noInternetAccessExpected, actual.noInternetAccessExpected); 396 assertEquals(expected.userApproved, actual.userApproved); 397 assertEquals(expected.meteredHint, actual.meteredHint); 398 assertEquals(expected.useExternalScores, actual.useExternalScores); 399 assertEquals(expected.numAssociation, actual.numAssociation); 400 assertEquals(expected.creatorUid, actual.creatorUid); 401 assertEquals(expected.creatorName, actual.creatorName); 402 assertEquals(expected.creationTime, actual.creationTime); 403 assertEquals(expected.lastUpdateUid, actual.lastUpdateUid); 404 assertEquals(expected.lastUpdateName, actual.lastUpdateName); 405 assertEquals(expected.lastConnectUid, actual.lastConnectUid); 406 assertEquals(expected.updateTime, actual.updateTime); 407 assertNetworkSelectionStatusEqualForConfigStore( 408 expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus()); 409 assertWifiEnterpriseConfigEqualForConfigStore( 410 expected.enterpriseConfig, actual.enterpriseConfig); 411 } 412 413 /** 414 * Asserts that the 2 WifiConfigurations are equal. This compares all the elements that are 415 * saved into internal database by WifiConfigurationManager for network additions/updates. 416 */ 417 public static void assertConfigurationEqualForConfigManagerAddOrUpdate( 418 WifiConfiguration expected, WifiConfiguration actual) { 419 assertCommonConfigurationElementsEqual(expected, actual); 420 assertEquals(expected.FQDN, actual.FQDN); 421 assertEquals(expected.providerFriendlyName, actual.providerFriendlyName); 422 assertEquals(expected.noInternetAccessExpected, actual.noInternetAccessExpected); 423 assertEquals(expected.meteredHint, actual.meteredHint); 424 assertEquals(expected.useExternalScores, actual.useExternalScores); 425 assertEquals(expected.ephemeral, actual.ephemeral); 426 assertEquals(expected.creatorUid, actual.creatorUid); 427 assertEquals(expected.creatorName, actual.creatorName); 428 assertEquals(expected.creationTime, actual.creationTime); 429 assertEquals(expected.lastUpdateUid, actual.lastUpdateUid); 430 assertEquals(expected.lastUpdateName, actual.lastUpdateName); 431 assertEquals(expected.updateTime, actual.updateTime); 432 assertNetworkSelectionStatusEqualForConfigStore( 433 expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus()); 434 assertWifiEnterpriseConfigEqualForConfigStore( 435 expected.enterpriseConfig, actual.enterpriseConfig); 436 } 437 438 /** 439 * Assert that the 2 NetworkSelectionStatus's are equal. This compares all the elements saved 440 * for config store. 441 */ 442 public static void assertNetworkSelectionStatusEqualForConfigStore( 443 NetworkSelectionStatus expected, NetworkSelectionStatus actual) { 444 if (expected.isNetworkTemporaryDisabled()) { 445 // Temporarily disabled networks are enabled when persisted. 446 assertEquals( 447 NetworkSelectionStatus.NETWORK_SELECTION_ENABLED, 448 actual.getNetworkSelectionStatus()); 449 } else { 450 assertEquals(expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus()); 451 } 452 assertEquals( 453 expected.getNetworkSelectionDisableReason(), 454 actual.getNetworkSelectionDisableReason()); 455 assertEquals(expected.getConnectChoice(), actual.getConnectChoice()); 456 assertEquals(expected.getConnectChoiceTimestamp(), actual.getConnectChoiceTimestamp()); 457 assertEquals(expected.getHasEverConnected(), actual.getHasEverConnected()); 458 } 459 460 /** 461 * Assert that the 2 WifiEnterpriseConfig's are equal. This compares all the elements saved 462 * for config store. 463 */ 464 public static void assertWifiEnterpriseConfigEqualForConfigStore( 465 WifiEnterpriseConfig expected, WifiEnterpriseConfig actual) { 466 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY, ""), 467 actual.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY, "")); 468 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ANON_IDENTITY_KEY, ""), 469 actual.getFieldValue(WifiEnterpriseConfig.ANON_IDENTITY_KEY, "")); 470 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.PASSWORD_KEY, ""), 471 actual.getFieldValue(WifiEnterpriseConfig.PASSWORD_KEY, "")); 472 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.CLIENT_CERT_KEY, ""), 473 actual.getFieldValue(WifiEnterpriseConfig.CLIENT_CERT_KEY, "")); 474 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.CA_CERT_KEY, ""), 475 actual.getFieldValue(WifiEnterpriseConfig.CA_CERT_KEY, "")); 476 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.SUBJECT_MATCH_KEY, ""), 477 actual.getFieldValue(WifiEnterpriseConfig.SUBJECT_MATCH_KEY, "")); 478 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ENGINE_KEY, ""), 479 actual.getFieldValue(WifiEnterpriseConfig.ENGINE_KEY, "")); 480 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ENGINE_ID_KEY, ""), 481 actual.getFieldValue(WifiEnterpriseConfig.ENGINE_ID_KEY, "")); 482 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY, ""), 483 actual.getFieldValue(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY, "")); 484 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY, ""), 485 actual.getFieldValue(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY, "")); 486 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.DOM_SUFFIX_MATCH_KEY, ""), 487 actual.getFieldValue(WifiEnterpriseConfig.DOM_SUFFIX_MATCH_KEY, "")); 488 assertEquals(expected.getFieldValue(WifiEnterpriseConfig.CA_PATH_KEY, ""), 489 actual.getFieldValue(WifiEnterpriseConfig.CA_PATH_KEY, "")); 490 assertEquals(expected.getEapMethod(), actual.getEapMethod()); 491 assertEquals(expected.getPhase2Method(), actual.getPhase2Method()); 492 } 493 494 /** 495 * Asserts that the 2 lists of WifiConfigurations are equal. This compares all the elements 496 * saved for backup/restore. 497 */ 498 public static void assertConfigurationsEqualForBackup( 499 List<WifiConfiguration> expected, List<WifiConfiguration> actual) { 500 assertEquals(expected.size(), actual.size()); 501 for (WifiConfiguration expectedConfiguration : expected) { 502 String expectedConfigKey = expectedConfiguration.configKey(); 503 boolean didCompare = false; 504 for (WifiConfiguration actualConfiguration : actual) { 505 String actualConfigKey = actualConfiguration.configKey(); 506 if (actualConfigKey.equals(expectedConfigKey)) { 507 assertConfigurationEqualForBackup( 508 expectedConfiguration, actualConfiguration); 509 didCompare = true; 510 } 511 } 512 assertTrue(didCompare); 513 } 514 } 515 516 /** 517 * Asserts that the 2 lists of WifiConfigurations are equal. This compares all the elements 518 * that are saved into internal database by WifiConfigurationManager for network 519 * additions/updates. 520 */ 521 public static void assertConfigurationsEqualForConfigManagerAddOrUpdate( 522 List<WifiConfiguration> expected, List<WifiConfiguration> actual) { 523 assertEquals(expected.size(), actual.size()); 524 for (WifiConfiguration expectedConfiguration : expected) { 525 String expectedConfigKey = expectedConfiguration.configKey(); 526 boolean didCompare = false; 527 for (WifiConfiguration actualConfiguration : actual) { 528 String actualConfigKey = actualConfiguration.configKey(); 529 if (actualConfigKey.equals(expectedConfigKey)) { 530 assertConfigurationEqualForConfigManagerAddOrUpdate( 531 expectedConfiguration, actualConfiguration); 532 didCompare = true; 533 } 534 } 535 assertTrue(didCompare); 536 } 537 } 538 539 /** 540 * Asserts that the 2 lists of WifiConfigurations are equal. This compares all the elements 541 * saved for config store. 542 */ 543 public static void assertConfigurationsEqualForConfigStore( 544 List<WifiConfiguration> expected, List<WifiConfiguration> actual) { 545 assertEquals(expected.size(), actual.size()); 546 for (WifiConfiguration expectedConfiguration : expected) { 547 String expectedConfigKey = expectedConfiguration.configKey(); 548 boolean didCompare = false; 549 for (WifiConfiguration actualConfiguration : actual) { 550 String actualConfigKey = actualConfiguration.configKey(); 551 if (actualConfigKey.equals(expectedConfigKey)) { 552 assertConfigurationEqualForConfigStore( 553 expectedConfiguration, actualConfiguration); 554 didCompare = true; 555 } 556 } 557 assertTrue(didCompare); 558 } 559 } 560} 561