summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2016-07-28 10:10:00 -0700
committerRoshan Pius <rpius@google.com>2016-07-28 10:17:13 -0700
commit0e2540a1c1ba3c541a229b039a90789f93c41ee7 (patch)
tree037cbf10a630648456f9bf6fc625d63f28c99868 /tests
parentc47c15bf9a4cebb5160400bcd6265385b256278b (diff)
XmlUtil: Store NetworkSelectionStatus strings
Storing direct enum values in the XML file makes it difficult to deprecate these enums later. So, instead store the string associated with these status/disable reason in the XML file. If any of the status/disable reason is deprecated, the reverse lookup of the index from the corresponding string array will fail. Such networks are restored as enabled (along with any temp disabled networks). Also, moved the existing logic to re-enable temporarily disabled networks to the |parseFromXml| method since we anyway need to perform the above checks there. BUG: 30448209 Change-Id: Ib8b8b1ab2b730853dddb7a1d716a2150b1a0f491 TEST: Unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigStoreDataTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/XmlUtilTest.java120
3 files changed, 122 insertions, 11 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreDataTest.java
index 7bed17a52..217d4aa87 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreDataTest.java
@@ -82,8 +82,8 @@ public class WifiConfigStoreDataTest {
+ "<int name=\"LastConnectUid\" value=\"0\" />\n"
+ "</WifiConfiguration>\n"
+ "<NetworkStatus>\n"
- + "<int name=\"SelectionStatus\" value=\"0\" />\n"
- + "<int name=\"DisableReason\" value=\"0\" />\n"
+ + "<string name=\"SelectionStatus\">NETWORK_SELECTION_ENABLED</string>\n"
+ + "<string name=\"DisableReason\">NETWORK_SELECTION_ENABLE</string>\n"
+ "<null name=\"ConnectChoice\" />\n"
+ "<long name=\"ConnectChoiceTimeStamp\" value=\"-1\" />\n"
+ "<boolean name=\"HasEverConnected\" value=\"false\" />\n"
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
index 39bfd1653..e45ddefa8 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
@@ -446,12 +446,15 @@ public class WifiConfigurationTestUtil {
assertEquals(
NetworkSelectionStatus.NETWORK_SELECTION_ENABLED,
actual.getNetworkSelectionStatus());
+ assertEquals(
+ NetworkSelectionStatus.NETWORK_SELECTION_ENABLE,
+ actual.getNetworkSelectionDisableReason());
} else {
assertEquals(expected.getNetworkSelectionStatus(), actual.getNetworkSelectionStatus());
+ assertEquals(
+ expected.getNetworkSelectionDisableReason(),
+ actual.getNetworkSelectionDisableReason());
}
- assertEquals(
- expected.getNetworkSelectionDisableReason(),
- actual.getNetworkSelectionDisableReason());
assertEquals(expected.getConnectChoice(), actual.getConnectChoice());
assertEquals(expected.getConnectChoiceTimestamp(), actual.getConnectChoiceTimestamp());
assertEquals(expected.getHasEverConnected(), actual.getHasEverConnected());
diff --git a/tests/wifitests/src/com/android/server/wifi/util/XmlUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/XmlUtilTest.java
index 7b0616411..89fa4a48b 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/XmlUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/XmlUtilTest.java
@@ -16,7 +16,7 @@
package com.android.server.wifi.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import android.net.IpConfiguration;
@@ -235,6 +235,103 @@ public class XmlUtilTest {
}
/**
+ * Verify that a network selection status deprecation is handled correctly during restore
+ * of data after upgrade.
+ * This test tries to simulate the scenario where we have a
+ * {@link NetworkSelectionStatus#getNetworkStatusString()} string stored
+ * in the XML file from a previous release which has now been deprecated. The network should
+ * be restored as enabled.
+ */
+ @Test
+ public void testDeprecatedNetworkSelectionStatusDeserialize()
+ throws IOException, XmlPullParserException {
+ // Create a dummy network selection status.
+ NetworkSelectionStatus status = new NetworkSelectionStatus();
+ status.setNetworkSelectionStatus(
+ NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
+ status.setNetworkSelectionDisableReason(
+ NetworkSelectionStatus.DISABLED_DHCP_FAILURE);
+ status.setConnectChoice(TEST_DUMMY_CONFIG_KEY);
+ status.setConnectChoiceTimestamp(867889);
+ status.setHasEverConnected(true);
+
+ // Serialize this to XML string.
+ byte[] xmlData = serializeNetworkSelectionStatus(status);
+
+ // Now modify the status string with some invalid string in XML data..
+ String xmlString = new String(xmlData);
+ String deprecatedXmlString =
+ xmlString.replaceAll(
+ status.getNetworkStatusString(), "NETWORK_SELECTION_DEPRECATED");
+ // Ensure that the modification did take effect.
+ assertFalse(xmlString.equals(deprecatedXmlString));
+
+ // Now Deserialize the modified XML data.
+ byte[] deprecatedXmlData = xmlString.getBytes();
+ NetworkSelectionStatus retrievedStatus =
+ deserializeNetworkSelectionStatus(deprecatedXmlData);
+
+ // The status retrieved should have reset both the |Status| & |DisableReason| fields after
+ // deserialization, but should have restored all the other fields correctly.
+ NetworkSelectionStatus expectedStatus = new NetworkSelectionStatus();
+ expectedStatus.copy(status);
+ expectedStatus.setNetworkSelectionStatus(NetworkSelectionStatus.NETWORK_SELECTION_ENABLED);
+ expectedStatus.setNetworkSelectionDisableReason(
+ NetworkSelectionStatus.NETWORK_SELECTION_ENABLE);
+
+ WifiConfigurationTestUtil.assertNetworkSelectionStatusEqualForConfigStore(
+ expectedStatus, retrievedStatus);
+ }
+
+ /**
+ * Verify that a network selection disable reason deprecation is handled correctly during
+ * restore of data after upgrade.
+ * This test tries to simulate the scenario where we have a
+ * {@link NetworkSelectionStatus#getNetworkDisableReasonString()} ()} string stored
+ * in the XML file from a previous release which has now been deprecated. The network should
+ * be restored as enabled.
+ */
+ @Test
+ public void testDeprecatedNetworkSelectionDisableReasonDeserialize()
+ throws IOException, XmlPullParserException {
+ // Create a dummy network selection status.
+ NetworkSelectionStatus status = new NetworkSelectionStatus();
+ status.setNetworkSelectionStatus(
+ NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
+ status.setNetworkSelectionDisableReason(
+ NetworkSelectionStatus.DISABLED_DHCP_FAILURE);
+ status.setConnectChoice(TEST_DUMMY_CONFIG_KEY);
+ status.setConnectChoiceTimestamp(867889);
+ status.setHasEverConnected(true);
+
+ // Serialize this to XML string.
+ byte[] xmlData = serializeNetworkSelectionStatus(status);
+
+ // Now modify the disable reason string with some invalid string in XML data.
+ String xmlString = new String(xmlData);
+ String deprecatedXmlString =
+ xmlString.replaceAll(status.getNetworkDisableReasonString(), "DISABLED_DEPRECATED");
+ // Ensure that the modification did take effect.
+ assertFalse(xmlString.equals(deprecatedXmlString));
+
+ // Now Deserialize the modified XML data.
+ byte[] deprecatedXmlData = xmlString.getBytes();
+ NetworkSelectionStatus retrievedStatus =
+ deserializeNetworkSelectionStatus(deprecatedXmlData);
+
+ // The status retrieved should have reset both the |Status| & |DisableReason| fields after
+ // deserialization, but should have restored all the other fields correctly.
+ NetworkSelectionStatus expectedStatus = new NetworkSelectionStatus();
+ expectedStatus.copy(status);
+ expectedStatus.setNetworkSelectionStatus(NetworkSelectionStatus.NETWORK_SELECTION_ENABLED);
+ expectedStatus.setNetworkSelectionDisableReason(
+ NetworkSelectionStatus.NETWORK_SELECTION_ENABLE);
+
+ WifiConfigurationTestUtil.assertNetworkSelectionStatusEqualForConfigStore(
+ expectedStatus, retrievedStatus);
+ }
+
+ /**
* Verify that a WifiEnterpriseConfig object is serialized & deserialized correctly.
*/
@Test
@@ -358,7 +455,7 @@ public class XmlUtilTest {
assertEquals(configuration, retrievedConfiguration);
}
- private void serializeDeserializeNetworkSelectionStatus(NetworkSelectionStatus status)
+ private byte[] serializeNetworkSelectionStatus(NetworkSelectionStatus status)
throws IOException, XmlPullParserException {
// Serialize the configuration object.
final XmlSerializer out = new FastXmlSerializer();
@@ -367,14 +464,25 @@ public class XmlUtilTest {
XmlUtil.writeDocumentStart(out, mXmlDocHeader);
NetworkSelectionStatusXmlUtil.writeToXml(out, status);
XmlUtil.writeDocumentEnd(out, mXmlDocHeader);
+ return outputStream.toByteArray();
+ }
- // Deserialize the configuration object.
+ private NetworkSelectionStatus deserializeNetworkSelectionStatus(byte[] data)
+ throws IOException, XmlPullParserException {
final XmlPullParser in = Xml.newPullParser();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
in.setInput(inputStream, StandardCharsets.UTF_8.name());
XmlUtil.gotoDocumentStart(in, mXmlDocHeader);
- NetworkSelectionStatus retrievedStatus =
- NetworkSelectionStatusXmlUtil.parseFromXml(in, in.getDepth());
+ return NetworkSelectionStatusXmlUtil.parseFromXml(in, in.getDepth());
+ }
+
+ private void serializeDeserializeNetworkSelectionStatus(NetworkSelectionStatus status)
+ throws IOException, XmlPullParserException {
+ // Serialize the status object.
+ byte[] data = serializeNetworkSelectionStatus(status);
+ // Deserialize the status object.
+ NetworkSelectionStatus retrievedStatus = deserializeNetworkSelectionStatus(data);
+
WifiConfigurationTestUtil.assertNetworkSelectionStatusEqualForConfigStore(
status, retrievedStatus);
}