summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-06-26 11:07:21 -0700
committerEtan Cohen <etancohen@google.com>2019-06-27 21:21:40 +0000
commita171b41e2c47a93408c1f867e8570330cbcf5091 (patch)
tree2b981083cbdae247f04ed02fb143d465d1c3d5e0
parent5571ad34461466bc053c85628920957daa35d1db (diff)
downloadandroid_frameworks_opt_net_wifi-a171b41e2c47a93408c1f867e8570330cbcf5091.tar.gz
android_frameworks_opt_net_wifi-a171b41e2c47a93408c1f867e8570330cbcf5091.tar.bz2
android_frameworks_opt_net_wifi-a171b41e2c47a93408c1f867e8570330cbcf5091.zip
WifiNetworkSuggestionsManager: Persist enterprise credentials
Enterprise credentials for suggestions were not being persisted to disk. This would prevent the device from auto-connecting to networks suggested by apps (via the new network suggestion API surface) after a reboot. Bug: 136088495 Test: atest com.android.server.wifi Test: ACTS test: NetworkSuggestionTest Test: Verified scenario mentioned in the bug (carrier wifi app suggested EAP networks not connecting). Merged-In: Ife2cff3daf84a5986cb2b63207eccf1b6faee5ae Change-Id: Ife2cff3daf84a5986cb2b63207eccf1b6faee5ae
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionStoreData.java54
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java25
2 files changed, 66 insertions, 13 deletions
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
index 088092df4..9627a9daa 100644
--- a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
+++ b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
@@ -17,9 +17,9 @@
package com.android.server.wifi;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiNetworkSuggestion;
import android.os.Process;
-import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -53,6 +53,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
"NetworkSuggestionPerApp";
private static final String XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION = "NetworkSuggestion";
private static final String XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION = "WifiConfiguration";
+ private static final String XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION =
+ "WifiEnterpriseConfiguration";
private static final String XML_TAG_IS_APP_INTERACTION_REQUIRED = "IsAppInteractionRequired";
private static final String XML_TAG_IS_USER_INTERACTION_REQUIRED = "IsUserInteractionRequired";
private static final String XML_TAG_SUGGESTOR_UID = "SuggestorUid";
@@ -187,6 +189,16 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
WifiConfigurationXmlUtil.writeToXmlForConfigStore(out, suggestion.wifiConfiguration);
XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
+ // Serialize enterprise configuration for enterprise networks.
+ if (suggestion.wifiConfiguration.enterpriseConfig != null
+ && suggestion.wifiConfiguration.enterpriseConfig.getEapMethod()
+ != WifiEnterpriseConfig.Eap.NONE) {
+ XmlUtil.writeNextSectionStart(
+ out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
+ XmlUtil.WifiEnterpriseConfigXmlUtil.writeToXml(
+ out, suggestion.wifiConfiguration.enterpriseConfig);
+ XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
+ }
// Serialize other fields
XmlUtil.writeNextValue(out, XML_TAG_IS_APP_INTERACTION_REQUIRED,
@@ -269,7 +281,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private WifiNetworkSuggestion parseNetworkSuggestion(XmlPullParser in, int outerTagDepth)
throws XmlPullParserException, IOException {
- WifiConfiguration wifiConfiguration = null;
+ Pair<String, WifiConfiguration> parsedConfig = null;
+ WifiEnterpriseConfig enterpriseConfig = null;
boolean isAppInteractionRequired = false;
boolean isUserInteractionRequired = false;
int suggestorUid = Process.INVALID_UID;
@@ -299,16 +312,35 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
"Unknown value name found: " + valueName[0]);
}
} else {
- if (!TextUtils.equals(in.getName(), XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION)) {
- throw new XmlPullParserException("Unexpected section under configuration: "
- + in.getName());
+ String tagName = in.getName();
+ if (tagName == null) {
+ throw new XmlPullParserException("Unexpected null under "
+ + XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION);
+ }
+ switch (tagName) {
+ case XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION:
+ if (parsedConfig != null) {
+ throw new XmlPullParserException("Detected duplicate tag for: "
+ + XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
+ }
+ parsedConfig = WifiConfigurationXmlUtil.parseFromXml(
+ in, outerTagDepth + 1);
+ break;
+ case XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION:
+ if (enterpriseConfig != null) {
+ throw new XmlPullParserException("Detected duplicate tag for: "
+ + XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
+ }
+ enterpriseConfig = XmlUtil.WifiEnterpriseConfigXmlUtil.parseFromXml(
+ in, outerTagDepth + 1);
+ break;
+ default:
+ throw new XmlPullParserException("Unknown tag under "
+ + XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION + ": " + in.getName());
}
- Pair<String, WifiConfiguration> parsedConfigWithConfigKey =
- WifiConfigurationXmlUtil.parseFromXml(in, outerTagDepth + 1);
- wifiConfiguration = parsedConfigWithConfigKey.second;
}
}
- if (wifiConfiguration == null) {
+ if (parsedConfig == null || parsedConfig.second == null) {
throw new XmlPullParserException("XML parsing of wifi configuration failed");
}
if (suggestorUid == -1) {
@@ -317,6 +349,10 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
if (suggestorPackageName == null) {
throw new XmlPullParserException("XML parsing of suggestor package name failed");
}
+ WifiConfiguration wifiConfiguration = parsedConfig.second;
+ if (enterpriseConfig != null) {
+ wifiConfiguration.enterpriseConfig = enterpriseConfig;
+ }
return new WifiNetworkSuggestion(
wifiConfiguration, isAppInteractionRequired, isUserInteractionRequired,
suggestorUid, suggestorPackageName);
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java
index eeaf5cd00..5c1dcb459 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java
@@ -19,6 +19,7 @@ package com.android.server.wifi;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiNetworkSuggestion;
import android.util.Xml;
@@ -150,15 +151,30 @@ public class NetworkSuggestionStoreDataTest {
Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>();
PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_NAME_1);
- WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
- WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1,
+
+ WifiConfiguration configuration = WifiConfigurationTestUtil.createEapNetwork();
+ configuration.enterpriseConfig =
+ WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2();
+ WifiNetworkSuggestion networkSuggestion =
+ new WifiNetworkSuggestion(configuration, false, false, TEST_UID_1,
TEST_PACKAGE_NAME_1);
appInfo.hasUserApproved = false;
appInfo.extNetworkSuggestions.add(
ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion, appInfo));
networkSuggestionsMap.put(TEST_PACKAGE_NAME_1, appInfo);
- assertSerializeDeserialize(networkSuggestionsMap);
+ Map<String, PerAppInfo> deserializedPerAppInfoMap =
+ assertSerializeDeserialize(networkSuggestionsMap);
+ ExtendedWifiNetworkSuggestion deserializedSuggestion =
+ deserializedPerAppInfoMap.get(TEST_PACKAGE_NAME_1).extNetworkSuggestions.stream()
+ .findAny()
+ .orElse(null);
+
+ WifiConfigurationTestUtil.assertConfigurationEqual(
+ configuration, deserializedSuggestion.wns.wifiConfiguration);
+ WifiConfigurationTestUtil.assertWifiEnterpriseConfigEqualForConfigStore(
+ configuration.enterpriseConfig,
+ deserializedSuggestion.wns.wifiConfiguration.enterpriseConfig);
}
/**
@@ -237,7 +253,7 @@ public class NetworkSuggestionStoreDataTest {
deserializeData(TEST_CORRUPT_DATA_INVALID_SSID.getBytes());
}
- private void assertSerializeDeserialize(
+ private Map<String, PerAppInfo> assertSerializeDeserialize(
Map<String, PerAppInfo> networkSuggestionsMap) throws Exception {
// Setup the data to serialize.
when(mDataSource.toSerialize()).thenReturn(networkSuggestionsMap);
@@ -250,5 +266,6 @@ public class NetworkSuggestionStoreDataTest {
ArgumentCaptor.forClass(HashMap.class);
verify(mDataSource).fromDeserialized(deserializedNetworkSuggestionsMap.capture());
assertEquals(networkSuggestionsMap, deserializedNetworkSuggestionsMap.getValue());
+ return deserializedNetworkSuggestionsMap.getValue();
}
}