summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-09-29 22:13:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-09-29 22:13:42 +0000
commit9d7cf1434fc63dec2d63d5a9c7330c2fa37aefc5 (patch)
tree235d8a92ee4185576a2d4d46eeb4e5e76dc19d1b /tests
parentdbaf29e09adbf2e44a598438fa8ad38f70c47b5b (diff)
parent7cede48303b0faabb3b6861a1ac7229f76fca006 (diff)
Merge changes I38c31645,Ib6f61b81 into oc-mr1-dev
* changes: WifiStateMachine: Handle WifiManager.save() when wifi is off NetworkListStoreData: Set creatorUid for all networks on load
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java119
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java137
3 files changed, 241 insertions, 32 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java
index cbad3bbec..19a92b8e4 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkListStoreDataTest.java
@@ -16,9 +16,13 @@
package com.android.server.wifi;
+import static android.os.Process.SYSTEM_UID;
+
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import android.content.Context;
+import android.content.pm.PackageManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.test.suitebuilder.annotation.SmallTest;
@@ -29,6 +33,8 @@ import com.android.server.wifi.util.XmlUtilTest;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
@@ -49,6 +55,7 @@ public class NetworkListStoreDataTest {
private static final String TEST_SSID = "WifiConfigStoreDataSSID_";
private static final String TEST_CONNECT_CHOICE = "XmlUtilConnectChoice";
private static final long TEST_CONNECT_CHOICE_TIMESTAMP = 0x4566;
+ private static final String TEST_CREATOR_NAME = "CreatorName";
private static final String SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT =
"<Network>\n"
+ "<WifiConfiguration>\n"
@@ -79,7 +86,7 @@ public class NetworkListStoreDataTest {
+ "<boolean name=\"UseExternalScores\" value=\"false\" />\n"
+ "<int name=\"NumAssociation\" value=\"0\" />\n"
+ "<int name=\"CreatorUid\" value=\"%d\" />\n"
- + "<null name=\"CreatorName\" />\n"
+ + "<string name=\"CreatorName\">%s</string>\n"
+ "<null name=\"CreationTime\" />\n"
+ "<int name=\"LastUpdateUid\" value=\"-1\" />\n"
+ "<null name=\"LastUpdateName\" />\n"
@@ -130,7 +137,7 @@ public class NetworkListStoreDataTest {
+ "<boolean name=\"UseExternalScores\" value=\"false\" />\n"
+ "<int name=\"NumAssociation\" value=\"0\" />\n"
+ "<int name=\"CreatorUid\" value=\"%d\" />\n"
- + "<null name=\"CreatorName\" />\n"
+ + "<string name=\"CreatorName\">%s</string>\n"
+ "<null name=\"CreationTime\" />\n"
+ "<int name=\"LastUpdateUid\" value=\"-1\" />\n"
+ "<null name=\"LastUpdateName\" />\n"
@@ -170,10 +177,15 @@ public class NetworkListStoreDataTest {
+ "</Network>\n";
private NetworkListStoreData mNetworkListStoreData;
+ @Mock private Context mContext;
+ @Mock private PackageManager mPackageManager;
@Before
public void setUp() throws Exception {
- mNetworkListStoreData = new NetworkListStoreData();
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.getNameForUid(anyInt())).thenReturn(TEST_CREATOR_NAME);
+ mNetworkListStoreData = new NetworkListStoreData(mContext);
}
/**
@@ -221,11 +233,13 @@ public class NetworkListStoreDataTest {
*/
private List<WifiConfiguration> getTestNetworksConfig(boolean shared) {
WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorName = TEST_CREATOR_NAME;
openNetwork.shared = shared;
openNetwork.setIpConfiguration(
WifiConfigurationTestUtil.createDHCPIpConfigurationWithNoProxy());
WifiConfiguration eapNetwork = WifiConfigurationTestUtil.createEapNetwork();
eapNetwork.shared = shared;
+ eapNetwork.creatorName = TEST_CREATOR_NAME;
eapNetwork.setIpConfiguration(
WifiConfigurationTestUtil.createDHCPIpConfigurationWithNoProxy());
List<WifiConfiguration> networkList = new ArrayList<>();
@@ -247,11 +261,11 @@ public class NetworkListStoreDataTest {
String openNetworkXml = String.format(SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT,
openNetwork.configKey().replaceAll("\"", "&quot;"),
openNetwork.SSID.replaceAll("\"", "&quot;"),
- openNetwork.shared, openNetwork.creatorUid);
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName);
String eapNetworkXml = String.format(SINGLE_EAP_NETWORK_DATA_XML_STRING_FORMAT,
eapNetwork.configKey().replaceAll("\"", "&quot;"),
eapNetwork.SSID.replaceAll("\"", "&quot;"),
- eapNetwork.shared, eapNetwork.creatorUid);
+ eapNetwork.shared, eapNetwork.creatorUid, openNetwork.creatorName);
return (openNetworkXml + eapNetworkXml).getBytes(StandardCharsets.UTF_8);
}
@@ -420,7 +434,8 @@ public class NetworkListStoreDataTest {
byte[] xmlData = String.format(SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT,
"InvalidConfigKey",
openNetwork.SSID.replaceAll("\"", "&quot;"),
- openNetwork.shared, openNetwork.creatorUid).getBytes(StandardCharsets.UTF_8);
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName)
+ .getBytes(StandardCharsets.UTF_8);
deserializeData(xmlData, true);
}
@@ -448,4 +463,96 @@ public class NetworkListStoreDataTest {
assertNotEquals(eapNetwork.SSID, network.SSID);
}
}
+
+ /**
+ * Verify that a saved network config with invalid creatorUid resets it to
+ * {@link android.os.Process#SYSTEM_UID}.
+ */
+ public void parseNetworkWithInvalidCreatorUidResetsToSystem() throws Exception {
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorUid = -1;
+ // Return null for invalid uid.
+ when(mPackageManager.getNameForUid(eq(openNetwork.creatorUid))).thenReturn(null);
+
+ byte[] xmlData = String.format(SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT,
+ openNetwork.configKey().replaceAll("\"", "&quot;"),
+ openNetwork.SSID.replaceAll("\"", "&quot;"),
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName)
+ .getBytes(StandardCharsets.UTF_8);
+ List<WifiConfiguration> deserializedNetworks = deserializeData(xmlData, true);
+ assertEquals(1, deserializedNetworks.size());
+ assertEquals(openNetwork.configKey(), deserializedNetworks.get(0).configKey());
+ assertEquals(SYSTEM_UID, deserializedNetworks.get(0).creatorUid);
+ assertEquals(TEST_CREATOR_NAME, deserializedNetworks.get(0).creatorName);
+ }
+
+ /**
+ * Verify that a saved network config with invalid creatorName resets it to the package name
+ * provided {@link PackageManager} for the creatorUid.
+ */
+ public void parseNetworkWithInvalidCreatorNameResetsToPackageNameForCreatorUid()
+ throws Exception {
+ String badCreatorName = "bad";
+ String correctCreatorName = "correct";
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorUid = 1324422;
+ openNetwork.creatorName = badCreatorName;
+ when(mPackageManager.getNameForUid(eq(openNetwork.creatorUid)))
+ .thenReturn(correctCreatorName);
+
+ byte[] xmlData = String.format(SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT,
+ openNetwork.configKey().replaceAll("\"", "&quot;"),
+ openNetwork.SSID.replaceAll("\"", "&quot;"),
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName)
+ .getBytes(StandardCharsets.UTF_8);
+ List<WifiConfiguration> deserializedNetworks = deserializeData(xmlData, true);
+ assertEquals(1, deserializedNetworks.size());
+ assertEquals(openNetwork.configKey(), deserializedNetworks.get(0).configKey());
+ assertEquals(openNetwork.creatorUid, deserializedNetworks.get(0).creatorUid);
+ assertEquals(correctCreatorName, deserializedNetworks.get(0).creatorName);
+ }
+
+ /**
+ * Verify that a saved network config with invalid creatorName resets it to the package name
+ * provided {@link PackageManager} for the creatorUid.
+ */
+ public void parseNetworkWithNullCreatorNameResetsToPackageNameForCreatorUid()
+ throws Exception {
+ String correctCreatorName = "correct";
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorUid = 1324422;
+ openNetwork.creatorName = null;
+ when(mPackageManager.getNameForUid(eq(openNetwork.creatorUid)))
+ .thenReturn(correctCreatorName);
+
+ byte[] xmlData = String.format(SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT,
+ openNetwork.configKey().replaceAll("\"", "&quot;"),
+ openNetwork.SSID.replaceAll("\"", "&quot;"),
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName)
+ .getBytes(StandardCharsets.UTF_8);
+ List<WifiConfiguration> deserializedNetworks = deserializeData(xmlData, true);
+ assertEquals(1, deserializedNetworks.size());
+ assertEquals(openNetwork.configKey(), deserializedNetworks.get(0).configKey());
+ assertEquals(openNetwork.creatorUid, deserializedNetworks.get(0).creatorUid);
+ assertEquals(correctCreatorName, deserializedNetworks.get(0).creatorName);
+ }
+
+ /**
+ * Verify that a saved network config with valid creatorUid is preserved.
+ */
+ public void parseNetworkWithValidCreatorUid() throws Exception {
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorUid = 1324422;
+
+ byte[] xmlData = String.format(SINGLE_OPEN_NETWORK_DATA_XML_STRING_FORMAT,
+ openNetwork.configKey().replaceAll("\"", "&quot;"),
+ openNetwork.SSID.replaceAll("\"", "&quot;"),
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName)
+ .getBytes(StandardCharsets.UTF_8);
+ List<WifiConfiguration> deserializedNetworks = deserializeData(xmlData, true);
+ assertEquals(1, deserializedNetworks.size());
+ assertEquals(openNetwork.configKey(), deserializedNetworks.get(0).configKey());
+ assertEquals(openNetwork.creatorUid, deserializedNetworks.get(0).creatorUid);
+ assertEquals(TEST_CREATOR_NAME, deserializedNetworks.get(0).creatorName);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
index 86d6e11e7..0958fea61 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.*;
import android.app.test.TestAlarmManager;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.net.wifi.WifiConfiguration;
import android.os.test.TestLooper;
import android.test.suitebuilder.annotation.SmallTest;
@@ -60,6 +61,7 @@ public class WifiConfigStoreTest {
private static final String TEST_USER_DATA = "UserData";
private static final String TEST_SHARE_DATA = "ShareData";
+ private static final String TEST_CREATOR_NAME = "CreatorName";
private static final String TEST_DATA_XML_STRING_FORMAT =
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n"
@@ -95,7 +97,7 @@ public class WifiConfigStoreTest {
+ "<boolean name=\"UseExternalScores\" value=\"false\" />\n"
+ "<int name=\"NumAssociation\" value=\"0\" />\n"
+ "<int name=\"CreatorUid\" value=\"%d\" />\n"
- + "<null name=\"CreatorName\" />\n"
+ + "<string name=\"CreatorName\">%s</string>\n"
+ "<null name=\"CreationTime\" />\n"
+ "<int name=\"LastUpdateUid\" value=\"-1\" />\n"
+ "<null name=\"LastUpdateName\" />\n"
@@ -125,6 +127,7 @@ public class WifiConfigStoreTest {
// Test mocks
@Mock private Context mContext;
+ @Mock private PackageManager mPackageManager;
private TestAlarmManager mAlarmManager;
private TestLooper mLooper;
@Mock private Clock mClock;
@@ -146,6 +149,8 @@ public class WifiConfigStoreTest {
mLooper = new TestLooper();
when(mContext.getSystemService(Context.ALARM_SERVICE))
.thenReturn(mAlarmManager.getAlarmManager());
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.getNameForUid(anyInt())).thenReturn(TEST_CREATOR_NAME);
mUserStore = new MockStoreFile();
mSharedStore = new MockStoreFile();
mStoreData = new MockStoreData();
@@ -364,9 +369,10 @@ public class WifiConfigStoreTest {
@Test
public void testReadWifiConfigStoreData() throws Exception {
// Setup network list.
- NetworkListStoreData networkList = new NetworkListStoreData();
+ NetworkListStoreData networkList = new NetworkListStoreData(mContext);
mWifiConfigStore.registerStoreData(networkList);
WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorName = TEST_CREATOR_NAME;
openNetwork.setIpConfiguration(
WifiConfigurationTestUtil.createDHCPIpConfigurationWithNoProxy());
List<WifiConfiguration> userConfigs = new ArrayList<>();
@@ -384,7 +390,7 @@ public class WifiConfigStoreTest {
String xmlString = String.format(TEST_DATA_XML_STRING_FORMAT,
openNetwork.configKey().replaceAll("\"", "&quot;"),
openNetwork.SSID.replaceAll("\"", "&quot;"),
- openNetwork.shared, openNetwork.creatorUid, testSsid);
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName, testSsid);
byte[] xmlBytes = xmlString.getBytes(StandardCharsets.UTF_8);
mUserStore.storeRawDataToWrite(xmlBytes);
@@ -406,9 +412,10 @@ public class WifiConfigStoreTest {
mWifiConfigStore.switchUserStoreAndRead(mUserStore);
// Setup network list store data.
- NetworkListStoreData networkList = new NetworkListStoreData();
+ NetworkListStoreData networkList = new NetworkListStoreData(mContext);
mWifiConfigStore.registerStoreData(networkList);
WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ openNetwork.creatorName = TEST_CREATOR_NAME;
openNetwork.setIpConfiguration(
WifiConfigurationTestUtil.createDHCPIpConfigurationWithNoProxy());
List<WifiConfiguration> userConfigs = new ArrayList<>();
@@ -428,7 +435,7 @@ public class WifiConfigStoreTest {
String xmlString = String.format(TEST_DATA_XML_STRING_FORMAT,
openNetwork.configKey().replaceAll("\"", "&quot;"),
openNetwork.SSID.replaceAll("\"", "&quot;"),
- openNetwork.shared, openNetwork.creatorUid, testSsid);
+ openNetwork.shared, openNetwork.creatorUid, openNetwork.creatorName, testSsid);
byte[] xmlBytes = xmlString.getBytes(StandardCharsets.UTF_8);
mWifiConfigStore.write(true);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 177261632..5b0f59685 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -139,6 +139,7 @@ public class WifiStateMachineTest {
: WifiStateMachine.NUM_LOG_RECS_VERBOSE);
private static final int FRAMEWORK_NETWORK_ID = 7;
private static final int TEST_RSSI = -54;
+ private static final int TEST_NETWORK_ID = 54;
private static final int WPS_SUPPLICANT_NETWORK_ID = 5;
private static final int WPS_FRAMEWORK_NETWORK_ID = 10;
private static final String DEFAULT_TEST_SSID = "\"GoogleGuest\"";
@@ -750,18 +751,15 @@ public class WifiStateMachineTest {
(Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
- /**
- * Verifies that configs can be removed when in client mode.
- */
- @Test
- public void canRemoveNetworkConfigInClientMode() throws Exception {
+ private void canRemoveNetwork() {
boolean result;
when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
- initializeAndAddNetworkAndVerifySuccess();
mLooper.startAutoDispatch();
result = mWsm.syncRemoveNetwork(mWsmAsyncChannel, 0);
mLooper.stopAutoDispatch();
+
assertTrue(result);
+ verify(mWifiConfigManager).removeNetwork(anyInt(), anyInt());
}
/**
@@ -769,23 +767,21 @@ public class WifiStateMachineTest {
*/
@Test
public void canRemoveNetworkConfigWhenWifiDisabled() {
- boolean result;
- when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
- mLooper.startAutoDispatch();
- result = mWsm.syncRemoveNetwork(mWsmAsyncChannel, 0);
- mLooper.stopAutoDispatch();
-
- assertTrue(result);
- verify(mWifiConfigManager).removeNetwork(anyInt(), anyInt());
+ canRemoveNetwork();
}
+
/**
- * Verifies that configs can be forgotten when in client mode.
+ * Verifies that configs can be removed when in client mode.
*/
@Test
- public void canForgetNetworkConfigInClientMode() throws Exception {
- when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
+ public void canRemoveNetworkConfigInClientMode() throws Exception {
initializeAndAddNetworkAndVerifySuccess();
+ canRemoveNetwork();
+ }
+
+ private void canForgetNetwork() {
+ when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
mWsm.sendMessage(WifiManager.FORGET_NETWORK, 0, MANAGED_PROFILE_UID);
mLooper.dispatchAll();
verify(mWifiConfigManager).removeNetwork(anyInt(), anyInt());
@@ -796,10 +792,109 @@ public class WifiStateMachineTest {
*/
@Test
public void canForgetNetworkConfigWhenWifiDisabled() throws Exception {
- when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
- mWsm.sendMessage(WifiManager.FORGET_NETWORK, 0, MANAGED_PROFILE_UID);
- mLooper.dispatchAll();
- verify(mWifiConfigManager).removeNetwork(anyInt(), anyInt());
+ canForgetNetwork();
+ }
+
+ /**
+ * Verifies that configs can be forgotten when in client mode.
+ */
+ @Test
+ public void canForgetNetworkConfigInClientMode() throws Exception {
+ initializeAndAddNetworkAndVerifySuccess();
+ canForgetNetwork();
+ }
+
+ private void canSaveNetworkConfig() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+
+ int networkId = TEST_NETWORK_ID;
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(networkId));
+ when(mWifiConfigManager.enableNetwork(eq(networkId), eq(false), anyInt()))
+ .thenReturn(true);
+
+ mLooper.startAutoDispatch();
+ Message reply = mWsmAsyncChannel.sendMessageSynchronously(WifiManager.SAVE_NETWORK, config);
+ mLooper.stopAutoDispatch();
+ assertEquals(WifiManager.SAVE_NETWORK_SUCCEEDED, reply.what);
+
+ verify(mWifiConfigManager).addOrUpdateNetwork(any(WifiConfiguration.class), anyInt());
+ verify(mWifiConfigManager).enableNetwork(eq(networkId), eq(false), anyInt());
+ }
+
+ /**
+ * Verifies that configs can be saved when not in client mode.
+ */
+ @Test
+ public void canSaveNetworkConfigWhenWifiDisabled() throws Exception {
+ canSaveNetworkConfig();
+ }
+
+ /**
+ * Verifies that configs can be saved when in client mode.
+ */
+ @Test
+ public void canSaveNetworkConfigInClientMode() throws Exception {
+ loadComponentsInStaMode();
+ canSaveNetworkConfig();
+ }
+
+ /**
+ * Verifies that null configs are rejected in SAVE_NETWORK message.
+ */
+ @Test
+ public void saveNetworkConfigFailsWithNullConfig() throws Exception {
+ mLooper.startAutoDispatch();
+ Message reply = mWsmAsyncChannel.sendMessageSynchronously(WifiManager.SAVE_NETWORK, null);
+ mLooper.stopAutoDispatch();
+ assertEquals(WifiManager.SAVE_NETWORK_FAILED, reply.what);
+
+ verify(mWifiConfigManager, never())
+ .addOrUpdateNetwork(any(WifiConfiguration.class), anyInt());
+ verify(mWifiConfigManager, never())
+ .enableNetwork(anyInt(), anyBoolean(), anyInt());
+ }
+
+ /**
+ * Verifies that configs save fails when the addition of network fails.
+ */
+ @Test
+ public void saveNetworkConfigFailsWithConfigAddFailure() throws Exception {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID));
+
+ mLooper.startAutoDispatch();
+ Message reply = mWsmAsyncChannel.sendMessageSynchronously(WifiManager.SAVE_NETWORK, config);
+ mLooper.stopAutoDispatch();
+ assertEquals(WifiManager.SAVE_NETWORK_FAILED, reply.what);
+
+ verify(mWifiConfigManager).addOrUpdateNetwork(any(WifiConfiguration.class), anyInt());
+ verify(mWifiConfigManager, never())
+ .enableNetwork(anyInt(), anyBoolean(), anyInt());
+ }
+
+ /**
+ * Verifies that configs save fails when the enable of network fails.
+ */
+ @Test
+ public void saveNetworkConfigFailsWithConfigEnableFailure() throws Exception {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+
+ int networkId = 5;
+ when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt()))
+ .thenReturn(new NetworkUpdateResult(networkId));
+ when(mWifiConfigManager.enableNetwork(eq(networkId), eq(false), anyInt()))
+ .thenReturn(false);
+
+ mLooper.startAutoDispatch();
+ Message reply = mWsmAsyncChannel.sendMessageSynchronously(WifiManager.SAVE_NETWORK, config);
+ mLooper.stopAutoDispatch();
+ assertEquals(WifiManager.SAVE_NETWORK_FAILED, reply.what);
+
+ verify(mWifiConfigManager).addOrUpdateNetwork(any(WifiConfiguration.class), anyInt());
+ verify(mWifiConfigManager).enableNetwork(eq(networkId), eq(false), anyInt());
}
/**