diff options
author | Roshan Pius <rpius@google.com> | 2016-06-08 10:55:56 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2016-06-08 14:31:01 -0700 |
commit | 2622233bd264f9bfbde164b6c62bd9d785da935b (patch) | |
tree | 8a6502492ac8192146dee1b60f59b83b3185978a /service | |
parent | 06a2281303248446bacc87a00ab66ea1fdf0392d (diff) |
WifiBackupRestore: Handle backups with no ipconfig data
Handle restore of old backups with no corresponding ipconfig data.
According to ctate@, this is a possibility on certain older devices.
Also, add unit-tests to validate the restore behavior.
BUG: 28967335
Change-Id: Id9d7be22132b3da560a7ec72aa5509392177bafe
TEST: Unit tests.
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiBackupRestore.java | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiBackupRestore.java b/service/java/com/android/server/wifi/WifiBackupRestore.java index f4a99e4d1..d17b777d0 100644 --- a/service/java/com/android/server/wifi/WifiBackupRestore.java +++ b/service/java/com/android/server/wifi/WifiBackupRestore.java @@ -327,7 +327,7 @@ public class WifiBackupRestore { line = line.replaceAll( WEP_KEYS_MASK_SEARCH_PATTERN, WEP_KEYS_MASK_REPLACE_PATTERN); } - sb.append(line + "\n"); + sb.append(line).append("\n"); } } catch (UnsupportedEncodingException e) { return ""; @@ -345,8 +345,7 @@ public class WifiBackupRestore { */ public List<WifiConfiguration> retrieveConfigurationsFromSupplicantBackupData( byte[] supplicantData, byte[] ipConfigData) { - if (supplicantData == null || ipConfigData == null - || supplicantData.length == 0 || ipConfigData.length == 0) { + if (supplicantData == null || supplicantData.length == 0) { Log.e(TAG, "Invalid supplicant backup data received"); return null; } @@ -370,21 +369,26 @@ public class WifiBackupRestore { List<WifiConfiguration> configurations = supplicantNetworks.retrieveWifiConfigurations(); // Now retrieve all the IpConfiguration objects and set in the corresponding - // WifiConfiguration objects. - SparseArray<IpConfiguration> networks = - IpConfigStore.readIpAndProxyConfigurations(new ByteArrayInputStream(ipConfigData)); - if (networks != null) { - for (int i = 0; i < networks.size(); i++) { - int id = networks.keyAt(i); - for (WifiConfiguration configuration : configurations) { - // This is a dangerous lookup, but that's how it is currently written. - if (configuration.configKey().hashCode() == id) { - configuration.setIpConfiguration(networks.valueAt(i)); + // WifiConfiguration objects if ipconfig data is present. + if (ipConfigData != null && ipConfigData.length != 0) { + SparseArray<IpConfiguration> networks = + IpConfigStore.readIpAndProxyConfigurations( + new ByteArrayInputStream(ipConfigData)); + if (networks != null) { + for (int i = 0; i < networks.size(); i++) { + int id = networks.keyAt(i); + for (WifiConfiguration configuration : configurations) { + // This is a dangerous lookup, but that's how it is currently written. + if (configuration.configKey().hashCode() == id) { + configuration.setIpConfiguration(networks.valueAt(i)); + } } } + } else { + Log.e(TAG, "Failed to parse ipconfig data"); } } else { - Log.e(TAG, "Invalid Ip config data"); + Log.e(TAG, "Invalid ipconfig backup data received"); } return configurations; } @@ -494,7 +498,7 @@ public class WifiBackupRestore { line = line.replaceAll( WEP_KEYS_MASK_SEARCH_PATTERN, WEP_KEYS_MASK_REPLACE_PATTERN); } - sb.append(line + "\n"); + sb.append(line).append("\n"); } } catch (UnsupportedEncodingException e) { return ""; |