summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2016-06-23 11:23:16 -0700
committerRoshan Pius <rpius@google.com>2016-06-27 13:09:15 -0700
commit6e2780943dc04aae2e6b0fc7890d660f25e7e5fc (patch)
tree80fa9c25b1d74a49ce3ec4c70516ead0b19a272e
parent50eed92fe9556fdd9934683690181fea77ce4eac (diff)
downloadandroid_frameworks_opt_net_wifi-6e2780943dc04aae2e6b0fc7890d660f25e7e5fc.tar.gz
android_frameworks_opt_net_wifi-6e2780943dc04aae2e6b0fc7890d660f25e7e5fc.tar.bz2
android_frameworks_opt_net_wifi-6e2780943dc04aae2e6b0fc7890d660f25e7e5fc.zip
WifiConfigManagerNew: Send broadcasts & write store
Send the expected WifiManager broadcasts on network addition/updation/removal. Also trigger config store writes for these network modifications. Resturctured the unit tests to verify the broadcast sending and store writes. While there, Cleaned up the existing log style. All local logs will be prefixed by the method name in which they're in. All logcat logs will not have the method names prefixed. BUG: 29606878 Change-Id: I55f1ac4f8b061d3ce1c8eb7d518ee1f91db90a6b TEST: Unit tests
-rw-r--r--service/java/com/android/server/wifi/NetworkUpdateResult.java5
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManagerNew.java79
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java275
3 files changed, 283 insertions, 76 deletions
diff --git a/service/java/com/android/server/wifi/NetworkUpdateResult.java b/service/java/com/android/server/wifi/NetworkUpdateResult.java
index 63cc33f7b..22c8e223f 100644
--- a/service/java/com/android/server/wifi/NetworkUpdateResult.java
+++ b/service/java/com/android/server/wifi/NetworkUpdateResult.java
@@ -67,4 +67,9 @@ class NetworkUpdateResult {
public void setIsNewNetwork(boolean isNew) {
isNewNetwork = isNew;
}
+
+ public boolean isSuccess() {
+ return netId != INVALID_NETWORK_ID;
+ }
+
}
diff --git a/service/java/com/android/server/wifi/WifiConfigManagerNew.java b/service/java/com/android/server/wifi/WifiConfigManagerNew.java
index a4d0b3e5c..e231eabfa 100644
--- a/service/java/com/android/server/wifi/WifiConfigManagerNew.java
+++ b/service/java/com/android/server/wifi/WifiConfigManagerNew.java
@@ -21,6 +21,7 @@ import android.app.admin.DeviceAdminInfo;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.IpConfiguration;
import android.net.ProxyInfo;
@@ -345,6 +346,38 @@ public class WifiConfigManagerNew {
}
/**
+ * Method to send out the configured networks change broadcast when a single network
+ * configuration is changed.
+ *
+ * @param network WifiConfiguration corresponding to the network that was changed.
+ * @param reason The reason for the change, should be one of WifiManager.CHANGE_REASON_ADDED,
+ * WifiManager.CHANGE_REASON_REMOVED, or WifiManager.CHANGE_REASON_CHANGE.
+ */
+ private void sendConfiguredNetworkChangedBroadcast(
+ WifiConfiguration network, int reason) {
+ Intent intent = new Intent(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ intent.putExtra(WifiManager.EXTRA_MULTIPLE_NETWORKS_CHANGED, false);
+ // Create a new WifiConfiguration with passwords masked before we send it out.
+ WifiConfiguration broadcastNetwork = new WifiConfiguration(network);
+ maskPasswordsInWifiConfiguration(broadcastNetwork);
+ intent.putExtra(WifiManager.EXTRA_WIFI_CONFIGURATION, broadcastNetwork);
+ intent.putExtra(WifiManager.EXTRA_CHANGE_REASON, reason);
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+ }
+
+ /**
+ * Method to send out the configured networks change broadcast when multiple network
+ * configurations are changed.
+ */
+ private void sendConfiguredNetworksChangedBroadcast() {
+ Intent intent = new Intent(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ intent.putExtra(WifiManager.EXTRA_MULTIPLE_NETWORKS_CHANGED, true);
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+ }
+
+ /**
* Checks if the app has the permission to override Wi-Fi network configuration or not.
*
* @param uid uid of the app.
@@ -648,7 +681,7 @@ public class WifiConfigManagerNew {
*/
private NetworkUpdateResult addOrUpdateNetworkInternal(WifiConfiguration config, int uid) {
if (mVerboseLoggingEnabled) {
- Log.v(TAG, "addOrUpdateNetworkInternal: " + config.getPrintableSsid());
+ Log.v(TAG, "Adding/Updating network " + config.getPrintableSsid());
}
boolean newNetwork;
WifiConfiguration existingInternalConfig;
@@ -716,8 +749,20 @@ public class WifiConfigManagerNew {
Log.e(TAG, "Cannot add/update network with null config");
return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
}
- return addOrUpdateNetworkInternal(config, uid);
- // TODO: More stuff to be done here.
+ NetworkUpdateResult result = addOrUpdateNetworkInternal(config, uid);
+ if (!result.isSuccess()) {
+ Log.e(TAG, "Failed to add/update network " + config.getPrintableSsid());
+ return result;
+ }
+ WifiConfiguration newConfig = getInternalConfiguredNetwork(result.getNetworkId());
+ sendConfiguredNetworkChangedBroadcast(
+ newConfig,
+ result.isNewNetwork()
+ ? WifiManager.CHANGE_REASON_ADDED
+ : WifiManager.CHANGE_REASON_CONFIG_CHANGE);
+ // External modification, persist it immediately.
+ saveToStore(true);
+ return result;
}
/**
@@ -728,7 +773,7 @@ public class WifiConfigManagerNew {
*/
private boolean removeNetworkInternal(WifiConfiguration config) {
if (mVerboseLoggingEnabled) {
- Log.v(TAG, "removeNetworkInternal: " + config.getPrintableSsid());
+ Log.v(TAG, "Removing network " + config.getPrintableSsid());
}
// Remove any associated enterprise keys.
if (config.enterpriseConfig != null
@@ -754,13 +799,19 @@ public class WifiConfigManagerNew {
* @return true if successful, false otherwise.
*/
public boolean removeNetwork(int networkId) {
- WifiConfiguration configuration = getInternalConfiguredNetwork(networkId);
- if (configuration == null) {
+ WifiConfiguration config = getInternalConfiguredNetwork(networkId);
+ if (config == null) {
Log.e(TAG, "Cannot find network with networkId " + networkId);
return false;
}
- return removeNetworkInternal(configuration);
- // TODO: More stuff to be done here.
+ if (!removeNetworkInternal(config)) {
+ Log.e(TAG, "Failed to remove network " + config.getPrintableSsid());
+ return false;
+ }
+ sendConfiguredNetworkChangedBroadcast(config, WifiManager.CHANGE_REASON_REMOVED);
+ // External modification, persist it immediately.
+ saveToStore(true);
+ return true;
}
/**
@@ -777,12 +828,11 @@ public class WifiConfigManagerNew {
try {
storeData = mWifiConfigStore.read();
} catch (Exception e) {
- // TODO: Handle this exception properly?
- Log.wtf(TAG, "Reading from new store failed: " + e + ". All saved networks are lost!");
+ Log.wtf(TAG, "Reading from new store failed " + e + ". All saved networks are lost!");
return;
}
long readTime = mClock.getElapsedSinceBootMillis() - readStartTime;
- Log.d(TAG, "loadFromStore: Read time: " + readTime + " ms");
+ Log.d(TAG, "Loading from store completed in " + readTime + " ms.");
// Clear out all the existing in-memory lists and load the lists from what was retrieved
// from the config store.
@@ -791,7 +841,7 @@ public class WifiConfigManagerNew {
for (WifiConfiguration configuration : storeData.configurations) {
configuration.networkId = mLastNetworkId++;
if (mVerboseLoggingEnabled) {
- Log.v(TAG, "Adding network from store: " + configuration.configKey());
+ Log.v(TAG, "Adding network from store " + configuration.configKey());
}
mConfiguredNetworks.put(configuration);
}
@@ -824,12 +874,11 @@ public class WifiConfigManagerNew {
try {
mWifiConfigStore.write(forceWrite, storeData);
} catch (Exception e) {
- // TODO: Handle this exception properly?
- Log.wtf(TAG, "Writing to store failed: " + e + ". Saved networks maybe lost!");
+ Log.wtf(TAG, "Writing to store failed " + e + ". Saved networks maybe lost!");
return false;
}
long writeTime = mClock.getElapsedSinceBootMillis() - writeStartTime;
- Log.d(TAG, "saveToStore: Write time: " + writeTime + " ms");
+ Log.d(TAG, "Writing to store completed in " + writeTime + " ms.");
return true;
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java
index 467a94ad4..726439bea 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java
@@ -21,14 +21,20 @@ import static org.mockito.Mockito.*;
import android.app.test.MockAnswerUtil.AnswerWithArguments;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.IpConfiguration;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.UserHandle;
import android.os.UserManager;
import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -57,6 +63,8 @@ public class WifiConfigManagerNewTest {
@Mock private WifiConfigStoreNew mWifiConfigStore;
@Mock private PackageManager mPackageManager;
+ private InOrder mContextConfigStoreMockOrder;
+
private WifiConfigManagerNew mWifiConfigManager;
/**
@@ -66,6 +74,10 @@ public class WifiConfigManagerNewTest {
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ // Set up the inorder for verifications. This is needed to verify that the broadcasts,
+ // store writes for network updates followed by network additions are in the expected order.
+ mContextConfigStoreMockOrder = inOrder(mContext, mWifiConfigStore);
+
// Set up the package name stuff & permission override.
when(mContext.getPackageManager()).thenReturn(mPackageManager);
doAnswer(new AnswerWithArguments() {
@@ -108,9 +120,7 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(openNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddNetworkToWifiConfigManager(openNetwork);
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -128,18 +138,11 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(openNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddNetworkToWifiConfigManager(openNetwork);
- // Now set the obtained network id in the configuration and change BSSID.
- openNetwork.networkId = result.getNetworkId();
+ // Now change BSSID for the network.
assertAndSetNetworkBSSID(openNetwork, TEST_BSSID);
-
- // Update the same configuration and compare.
- result = updateNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertFalse(result.isNewNetwork());
+ verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(openNetwork);
// Now verify that the modification has been effective.
List<WifiConfiguration> retrievedNetworks =
@@ -160,9 +163,7 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(openNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddEphemeralNetworkToWifiConfigManager(openNetwork);
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -184,12 +185,9 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(openNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddNetworkToWifiConfigManager(openNetwork);
- // Now set the obtained network id in the configuration and change BSSID.
- openNetwork.networkId = result.getNetworkId();
+ // Now change BSSID of the network.
assertAndSetNetworkBSSID(openNetwork, TEST_BSSID);
// Deny permission for |UPDATE_UID|.
@@ -203,7 +201,7 @@ public class WifiConfigManagerNewTest {
}).when(mFrameworkFacade).checkUidPermission(anyString(), anyInt());
// Update the same configuration and ensure that the operation failed.
- result = updateNetworkToWifiConfigManager(openNetwork);
+ NetworkUpdateResult result = updateNetworkToWifiConfigManager(openNetwork);
assertTrue(result.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID);
}
@@ -218,12 +216,9 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(openNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddNetworkToWifiConfigManager(openNetwork);
- // Now set the obtained network id in the configuration and change BSSID.
- openNetwork.networkId = result.getNetworkId();
+ // Now change BSSID of the network.
assertAndSetNetworkBSSID(openNetwork, TEST_BSSID);
// Deny permission for all UIDs.
@@ -234,7 +229,8 @@ public class WifiConfigManagerNewTest {
}).when(mFrameworkFacade).checkUidPermission(anyString(), anyInt());
// Update the same configuration using the creator UID.
- result = mWifiConfigManager.addOrUpdateNetwork(openNetwork, TEST_CREATOR_UID);
+ NetworkUpdateResult result =
+ mWifiConfigManager.addOrUpdateNetwork(openNetwork, TEST_CREATOR_UID);
assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
// Now verify that the modification has been effective.
@@ -255,9 +251,7 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(pskNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(pskNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddNetworkToWifiConfigManager(pskNetwork);
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -267,8 +261,7 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> retrievedSavedNetworks = mWifiConfigManager.getSavedNetworks();
assertEquals(retrievedSavedNetworks.size(), 1);
assertEquals(retrievedSavedNetworks.get(0).configKey(), pskNetwork.configKey());
- assertEquals(
- WifiConfigManagerNew.PASSWORD_MASK, retrievedSavedNetworks.get(0).preSharedKey);
+ assertPasswordsMaskedInWifiConfiguration(retrievedSavedNetworks.get(0));
}
/**
@@ -282,9 +275,7 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(wepNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(wepNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
+ verifyAddNetworkToWifiConfigManager(wepNetwork);
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -294,14 +285,7 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> retrievedSavedNetworks = mWifiConfigManager.getSavedNetworks();
assertEquals(retrievedSavedNetworks.size(), 1);
assertEquals(retrievedSavedNetworks.get(0).configKey(), wepNetwork.configKey());
- assertEquals(
- WifiConfigManagerNew.PASSWORD_MASK, retrievedSavedNetworks.get(0).wepKeys[0]);
- assertEquals(
- WifiConfigManagerNew.PASSWORD_MASK, retrievedSavedNetworks.get(0).wepKeys[1]);
- assertEquals(
- WifiConfigManagerNew.PASSWORD_MASK, retrievedSavedNetworks.get(0).wepKeys[2]);
- assertEquals(
- WifiConfigManagerNew.PASSWORD_MASK, retrievedSavedNetworks.get(0).wepKeys[3]);
+ assertPasswordsMaskedInWifiConfiguration(retrievedSavedNetworks.get(0));
}
/**
@@ -314,33 +298,20 @@ public class WifiConfigManagerNewTest {
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(openNetwork);
- NetworkUpdateResult result = addNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertTrue(result.isNewNetwork());
- assertTrue(result.hasIpChanged());
- assertTrue(result.hasProxyChanged());
+ verifyAddNetworkToWifiConfigManager(openNetwork);
- // Now set the obtained network id in the configuration and change BSSID.
- openNetwork.networkId = result.getNetworkId();
+ // Now change BSSID of the network.
assertAndSetNetworkBSSID(openNetwork, TEST_BSSID);
// Update the same configuration and ensure that the IP configuration change flags
// are not set.
- result = updateNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertFalse(result.isNewNetwork());
- assertFalse(result.hasIpChanged());
- assertFalse(result.hasProxyChanged());
+ verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(openNetwork);
// Change the IpConfiguration now and ensure that the IP configuration flags are set now.
assertAndSetNetworkIpConfiguration(
openNetwork,
WifiConfigurationTestUtil.createStaticIpConfigurationWithStaticProxy());
- result = updateNetworkToWifiConfigManager(openNetwork);
- assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
- assertFalse(result.isNewNetwork());
- assertTrue(result.hasIpChanged());
- assertTrue(result.hasProxyChanged());
+ verifyUpdateNetworkToWifiConfigManagerWithIpChange(openNetwork);
// Now verify that all the modifications have been effective.
List<WifiConfiguration> retrievedNetworks =
@@ -438,6 +409,114 @@ public class WifiConfigManagerNewTest {
}
/**
+ * Returns whether the provided network was in the store data or not.
+ */
+ private boolean isNetworkInConfigStoreData(WifiConfiguration configuration) {
+ try {
+ ArgumentCaptor<WifiConfigStoreData> storeDataCaptor =
+ ArgumentCaptor.forClass(WifiConfigStoreData.class);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore)
+ .write(anyBoolean(), storeDataCaptor.capture());
+
+ WifiConfigStoreData storeData = storeDataCaptor.getValue();
+
+ boolean foundNetworkInStoreData = false;
+ for (WifiConfiguration retrievedConfig: storeData.configurations) {
+ if (retrievedConfig.configKey().equals(configuration.configKey())) {
+ foundNetworkInStoreData = true;
+ }
+ }
+ return foundNetworkInStoreData;
+ } catch (Exception e) {
+ fail("Exception encountered during write " + e);
+ }
+ return false;
+ }
+
+ /**
+ * Verifies that the provided network was not present in the last config store write.
+ */
+ private void verifyNetworkNotInConfigStoreData(WifiConfiguration configuration) {
+ assertFalse(isNetworkInConfigStoreData(configuration));
+ }
+
+ /**
+ * Verifies that the provided network was present in the last config store write.
+ */
+ private void verifyNetworkInConfigStoreData(WifiConfiguration configuration) {
+ assertTrue(isNetworkInConfigStoreData(configuration));
+ }
+
+ private void assertPasswordsMaskedInWifiConfiguration(WifiConfiguration configuration) {
+ if(!TextUtils.isEmpty(configuration.preSharedKey)) {
+ assertEquals(WifiConfigManagerNew.PASSWORD_MASK, configuration.preSharedKey);
+ }
+ if (configuration.wepKeys != null) {
+ for (int i = 0; i < configuration.wepKeys.length; i++) {
+ if (!TextUtils.isEmpty(configuration.wepKeys[i])) {
+ assertEquals(WifiConfigManagerNew.PASSWORD_MASK, configuration.wepKeys[i]);
+ }
+ }
+ }
+ if(!TextUtils.isEmpty(configuration.enterpriseConfig.getPassword())) {
+ assertEquals(
+ WifiConfigManagerNew.PASSWORD_MASK,
+ configuration.enterpriseConfig.getPassword());
+ }
+ }
+
+ /**
+ * Verifies that the network was present in the network change broadcast and returns the
+ * change reason.
+ */
+ private int verifyNetworkInBroadcastAndReturnReason(WifiConfiguration configuration) {
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ ArgumentCaptor<UserHandle> userHandleCaptor = ArgumentCaptor.forClass(UserHandle.class);
+ mContextConfigStoreMockOrder.verify(mContext)
+ .sendBroadcastAsUser(intentCaptor.capture(), userHandleCaptor.capture());
+
+ assertEquals(userHandleCaptor.getValue(), UserHandle.ALL);
+ Intent intent = intentCaptor.getValue();
+
+ int changeReason = intent.getIntExtra(WifiManager.EXTRA_CHANGE_REASON, -1);
+ WifiConfiguration retrievedConfig =
+ (WifiConfiguration) intent.getExtra(WifiManager.EXTRA_WIFI_CONFIGURATION);
+ assertEquals(retrievedConfig.configKey(), configuration.configKey());
+
+ // Verify that all the passwords are masked in the broadcast configuration.
+ assertPasswordsMaskedInWifiConfiguration(retrievedConfig);
+
+ return changeReason;
+ }
+
+ /**
+ * Verifies that we sent out an add broadcast with the provided network.
+ */
+ private void verifyNetworkAddBroadcast(WifiConfiguration configuration) {
+ assertEquals(
+ verifyNetworkInBroadcastAndReturnReason(configuration),
+ WifiManager.CHANGE_REASON_ADDED);
+ }
+
+ /**
+ * Verifies that we sent out an update broadcast with the provided network.
+ */
+ private void verifyNetworkUpdateBroadcast(WifiConfiguration configuration) {
+ assertEquals(
+ verifyNetworkInBroadcastAndReturnReason(configuration),
+ WifiManager.CHANGE_REASON_CONFIG_CHANGE);
+ }
+
+ /**
+ * Verifies that we sent out a remove broadcast with the provided network.
+ */
+ private void verifyNetworkRemoveBroadcast(WifiConfiguration configuration) {
+ assertEquals(
+ verifyNetworkInBroadcastAndReturnReason(configuration),
+ WifiManager.CHANGE_REASON_REMOVED);
+ }
+
+ /**
* Adds the provided configuration to WifiConfigManager and modifies the provided configuration
* with creator/update uid, package name and time. This also sets defaults for fields not
* populated.
@@ -450,6 +529,41 @@ public class WifiConfigManagerNewTest {
mWifiConfigManager.addOrUpdateNetwork(configuration, TEST_CREATOR_UID);
setDefaults(configuration);
setCreationDebugParams(configuration);
+ configuration.networkId = result.getNetworkId();
+ return result;
+ }
+
+ /**
+ * Add network to WifiConfigManager and ensure that it was successful.
+ */
+ private NetworkUpdateResult verifyAddNetworkToWifiConfigManager(
+ WifiConfiguration configuration) {
+ NetworkUpdateResult result = addNetworkToWifiConfigManager(configuration);
+ assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
+ assertTrue(result.isNewNetwork());
+ assertTrue(result.hasIpChanged());
+ assertTrue(result.hasProxyChanged());
+
+ verifyNetworkAddBroadcast(configuration);
+ // Verify that the config store write was triggered with this new configuration.
+ verifyNetworkInConfigStoreData(configuration);
+ return result;
+ }
+
+ /**
+ * Add ephemeral network to WifiConfigManager and ensure that it was successful.
+ */
+ private NetworkUpdateResult verifyAddEphemeralNetworkToWifiConfigManager(
+ WifiConfiguration configuration) {
+ NetworkUpdateResult result = addNetworkToWifiConfigManager(configuration);
+ assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
+ assertTrue(result.isNewNetwork());
+ assertTrue(result.hasIpChanged());
+ assertTrue(result.hasProxyChanged());
+
+ verifyNetworkAddBroadcast(configuration);
+ // Ephemeral networks should not be persisted.
+ verifyNetworkNotInConfigStoreData(configuration);
return result;
}
@@ -466,4 +580,43 @@ public class WifiConfigManagerNewTest {
setUpdateDebugParams(configuration);
return result;
}
+
+ /**
+ * Update network to WifiConfigManager config change and ensure that it was successful.
+ */
+ private NetworkUpdateResult verifyUpdateNetworkToWifiConfigManager(
+ WifiConfiguration configuration) {
+ NetworkUpdateResult result = updateNetworkToWifiConfigManager(configuration);
+ assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
+ assertFalse(result.isNewNetwork());
+
+ verifyNetworkUpdateBroadcast(configuration);
+ // Verify that the config store write was triggered with this new configuration.
+ verifyNetworkInConfigStoreData(configuration);
+ return result;
+ }
+
+ /**
+ * Update network to WifiConfigManager without IP config change and ensure that it was
+ * successful.
+ */
+ private NetworkUpdateResult verifyUpdateNetworkToWifiConfigManagerWithoutIpChange(
+ WifiConfiguration configuration) {
+ NetworkUpdateResult result = verifyUpdateNetworkToWifiConfigManager(configuration);
+ assertFalse(result.hasIpChanged());
+ assertFalse(result.hasProxyChanged());
+ return result;
+ }
+
+ /**
+ * Update network to WifiConfigManager with IP config change and ensure that it was
+ * successful.
+ */
+ private NetworkUpdateResult verifyUpdateNetworkToWifiConfigManagerWithIpChange(
+ WifiConfiguration configuration) {
+ NetworkUpdateResult result = verifyUpdateNetworkToWifiConfigManager(configuration);
+ assertTrue(result.hasIpChanged());
+ assertTrue(result.hasProxyChanged());
+ return result;
+ }
}