diff options
author | Roshan Pius <rpius@google.com> | 2016-06-08 09:59:08 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2016-06-08 14:30:58 -0700 |
commit | 06a2281303248446bacc87a00ab66ea1fdf0392d (patch) | |
tree | c98532e38c34e99fd925dd6173013b586ba8121b /service | |
parent | 9e3eb23ebd21b93625914e77ec86d4034d915160 (diff) |
WifiBackupRestore: Handle single WEP key configs
Handle backup/restore of partial WEP key configs. |XmlUtils| cannot
handle arrays with different types (string & null). So, need to convert
all null keys to empty strings while backing up and restore it
accordingly.
BUG: 28967335
Change-Id: I6133e3e5744f64c7b55a45462efe092d597e2f8b
TEST: Unit tests
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/util/XmlUtil.java | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java index b5d1007f8..4b8fec308 100644 --- a/service/java/com/android/server/wifi/util/XmlUtil.java +++ b/service/java/com/android/server/wifi/util/XmlUtil.java @@ -263,13 +263,25 @@ public class XmlUtil { /** * Write WepKeys to the XML stream. * WepKeys array is intialized in WifiConfiguration constructor, but all of the elements - * are null. XmlUtils serialization doesn't handle this array of nulls well . - * So, write null if the keys are not initialized. + * are set to null. User may chose to set any one of the key elements in WifiConfiguration. + * XmlUtils serialization doesn't handle this array of nulls well . + * So, write empty strings if some of the keys are not initialized and null if all of + * the elements are empty. */ private static void writeWepKeysToXml(XmlSerializer out, String[] wepKeys) throws XmlPullParserException, IOException { - if (wepKeys[0] != null) { - XmlUtil.writeNextValue(out, XML_TAG_WEP_KEYS, wepKeys); + String[] wepKeysToWrite = new String[wepKeys.length]; + boolean hasWepKey = false; + for (int i = 0; i < wepKeys.length; i++) { + if (wepKeys[i] == null) { + wepKeysToWrite[i] = new String(); + } else { + wepKeysToWrite[i] = wepKeys[i]; + hasWepKey = true; + } + } + if (hasWepKey) { + XmlUtil.writeNextValue(out, XML_TAG_WEP_KEYS, wepKeysToWrite); } else { XmlUtil.writeNextValue(out, XML_TAG_WEP_KEYS, null); } @@ -331,13 +343,23 @@ public class XmlUtil { } /** - * Populate wepKeys array only if they were non-null in the backup data. + * Populate wepKeys array elements only if they were non-empty in the backup data. + * @throws XmlPullParserException if parsing errors occur. */ private static void populateWepKeysFromXmlValue(Object value, String[] wepKeys) throws XmlPullParserException, IOException { String[] wepKeysInData = (String[]) value; - if (wepKeysInData != null) { - for (int i = 0; i < wepKeys.length; i++) { + if (wepKeysInData == null) { + return; + } + if (wepKeysInData.length != wepKeys.length) { + throw new XmlPullParserException( + "Invalid Wep Keys length: " + wepKeysInData.length); + } + for (int i = 0; i < wepKeys.length; i++) { + if (wepKeysInData[i].isEmpty()) { + wepKeys[i] = null; + } else { wepKeys[i] = wepKeysInData[i]; } } |