summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-06-23 04:26:45 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-06-23 04:26:52 +0000
commitdb11f55cb731ee9c66a8906febe34c49c9563688 (patch)
treed8d7b0981719c88729cbd1544b92931ea95a68a2
parent824d75e0e13b916155623a83be8115f3d526db7c (diff)
parent1e11d006276c5663fa9028e415afbcfb754ad9a0 (diff)
downloadbase-db11f55cb731ee9c66a8906febe34c49c9563688.tar.gz
Merge "WifiEnterpriseConfig: New copy method to ignore masked password" into oc-dev
-rw-r--r--wifi/java/android/net/wifi/WifiEnterpriseConfig.java38
-rw-r--r--wifi/tests/src/android/net/wifi/WifiEnterpriseConfigTest.java25
2 files changed, 60 insertions, 3 deletions
diff --git a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java
index 18f30f834bc1..bb3af3cd1687 100644
--- a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java
+++ b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java
@@ -156,9 +156,20 @@ public class WifiEnterpriseConfig implements Parcelable {
}
- /** Copy constructor */
- public WifiEnterpriseConfig(WifiEnterpriseConfig source) {
+ /**
+ * Copy over the contents of the source WifiEnterpriseConfig object over to this object.
+ *
+ * @param source Source WifiEnterpriseConfig object.
+ * @param ignoreMaskedPassword Set to true to ignore masked password field, false otherwise.
+ * @param mask if |ignoreMaskedPassword| is set, check if the incoming password field is set
+ * to this value.
+ */
+ private void copyFrom(WifiEnterpriseConfig source, boolean ignoreMaskedPassword, String mask) {
for (String key : source.mFields.keySet()) {
+ if (ignoreMaskedPassword && key.equals(PASSWORD_KEY)
+ && TextUtils.equals(source.mFields.get(key), mask)) {
+ continue;
+ }
mFields.put(key, source.mFields.get(key));
}
if (source.mCaCerts != null) {
@@ -178,6 +189,29 @@ public class WifiEnterpriseConfig implements Parcelable {
mPhase2Method = source.mPhase2Method;
}
+ /**
+ * Copy constructor.
+ * This copies over all the fields verbatim (does not ignore masked password fields).
+ *
+ * @param source Source WifiEnterpriseConfig object.
+ */
+ public WifiEnterpriseConfig(WifiEnterpriseConfig source) {
+ copyFrom(source, false, "");
+ }
+
+ /**
+ * Copy fields from the provided external WifiEnterpriseConfig.
+ * This is needed to handle the WifiEnterpriseConfig objects which were sent by apps with the
+ * password field masked.
+ *
+ * @param externalConfig External WifiEnterpriseConfig object.
+ * @param mask String mask to compare against.
+ * @hide
+ */
+ public void copyFromExternal(WifiEnterpriseConfig externalConfig, String mask) {
+ copyFrom(externalConfig, true, convertToQuotedString(mask));
+ }
+
@Override
public int describeContents() {
return 0;
diff --git a/wifi/tests/src/android/net/wifi/WifiEnterpriseConfigTest.java b/wifi/tests/src/android/net/wifi/WifiEnterpriseConfigTest.java
index d0aedbad03b5..1a7dd132389e 100644
--- a/wifi/tests/src/android/net/wifi/WifiEnterpriseConfigTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiEnterpriseConfigTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -316,15 +317,37 @@ public class WifiEnterpriseConfigTest {
assertEquals("\"auth=AKA'\"", getSupplicantPhase2Method());
}
- /** Verfies that the copy constructor preseves the inner method information. */
+ /**
+ * Verifies that the copy constructor preseves both the masked password and inner method
+ * information.
+ */
@Test
public void copyConstructor() {
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
+ enterpriseConfig.setPassword("*");
enterpriseConfig.setEapMethod(Eap.TTLS);
enterpriseConfig.setPhase2Method(Phase2.GTC);
mEnterpriseConfig = new WifiEnterpriseConfig(enterpriseConfig);
assertEquals("TTLS", getSupplicantEapMethod());
assertEquals("\"autheap=GTC\"", getSupplicantPhase2Method());
+ assertEquals("*", mEnterpriseConfig.getPassword());
+ }
+
+ /**
+ * Verifies that the copy from external ignores masked passwords and preserves the
+ * inner method information.
+ */
+ @Test
+ public void copyFromExternal() {
+ WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
+ enterpriseConfig.setPassword("*");
+ enterpriseConfig.setEapMethod(Eap.TTLS);
+ enterpriseConfig.setPhase2Method(Phase2.GTC);
+ mEnterpriseConfig = new WifiEnterpriseConfig();
+ mEnterpriseConfig.copyFromExternal(enterpriseConfig, "*");
+ assertEquals("TTLS", getSupplicantEapMethod());
+ assertEquals("\"autheap=GTC\"", getSupplicantPhase2Method());
+ assertNotEquals("*", mEnterpriseConfig.getPassword());
}
/** Verfies that parceling a WifiEnterpriseConfig preseves method information. */