diff options
author | Jan Nordqvist <jannq@google.com> | 2015-04-17 12:22:44 -0700 |
---|---|---|
committer | Vinit Deshpande <vinitd@google.com> | 2015-04-17 21:18:28 +0000 |
commit | 05d2f4e6f26834a94b53187e6121379a16749088 (patch) | |
tree | e9cb58c51b7261d0a57bc6d9b6f1ec5d3d984c2f /service/java/com/android/server/wifi/hotspot2/omadm | |
parent | baa9bdfd34a95aef26c0099282a7d437739ef8c1 (diff) | |
download | android_frameworks_opt_net_wifi-05d2f4e6f26834a94b53187e6121379a16749088.tar.gz android_frameworks_opt_net_wifi-05d2f4e6f26834a94b53187e6121379a16749088.tar.bz2 android_frameworks_opt_net_wifi-05d2f4e6f26834a94b53187e6121379a16749088.zip |
Various Passpoint Fixes
- Changed lifecycle of MOManager and confined all PPS access to it.
- Fixed topology issues in the MO.
- Added all HomeSP fields to MO.
- A number of tidy ups: Changed to Java7 diamonds, added curlies, "m_" fixes and dropped a few more PARSE-LOG
- Added anonynmous@realm as anonymous identity to HS2.0 configs.
- Implemented domain_suffix_match for AAA server cert matching.
Change-Id: I79c7a545b396ba3cd409d923c4ee339a1d6fea27
Diffstat (limited to 'service/java/com/android/server/wifi/hotspot2/omadm')
5 files changed, 287 insertions, 214 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/MOManager.java b/service/java/com/android/server/wifi/hotspot2/omadm/MOManager.java index b49a6225c..24254bac9 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/MOManager.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/MOManager.java @@ -25,6 +25,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -37,10 +38,83 @@ import java.util.TimeZone; * Handles provisioning of PerProviderSubscription data. */ public class MOManager { + + public static final String TAG_AAAServerTrustRoot = "AAAServerTrustRoot"; + public static final String TAG_AbleToShare = "AbleToShare"; + public static final String TAG_CertificateType = "CertificateType"; + public static final String TAG_CertSHA256Fingerprint = "CertSHA256Fingerprint"; + public static final String TAG_CertURL = "CertURL"; + public static final String TAG_CheckAAAServerCertStatus = "CheckAAAServerCertStatus"; + public static final String TAG_Country = "Country"; + public static final String TAG_CreationDate = "CreationDate"; + public static final String TAG_Credential = "Credential"; + public static final String TAG_CredentialPriority = "CredentialPriority"; + public static final String TAG_DataLimit = "DataLimit"; + public static final String TAG_DigitalCertificate = "DigitalCertificate"; + public static final String TAG_DLBandwidth = "DLBandwidth"; + public static final String TAG_EAPMethod = "EAPMethod"; + public static final String TAG_EAPType = "EAPType"; + public static final String TAG_ExpirationDate = "ExpirationDate"; + public static final String TAG_Extension = "Extension"; + public static final String TAG_FQDN = "FQDN"; + public static final String TAG_FQDN_Match = "FQDN_Match"; + public static final String TAG_FriendlyName = "FriendlyName"; + public static final String TAG_HESSID = "HESSID"; + public static final String TAG_HomeOI = "HomeOI"; + public static final String TAG_HomeOIList = "HomeOIList"; + public static final String TAG_HomeOIRequired = "HomeOIRequired"; + public static final String TAG_HomeSP = "HomeSP"; + public static final String TAG_IconURL = "IconURL"; + public static final String TAG_IMSI = "IMSI"; + public static final String TAG_InnerEAPType = "InnerEAPType"; + public static final String TAG_InnerMethod = "InnerMethod"; + public static final String TAG_InnerVendorID = "InnerVendorID"; + public static final String TAG_InnerVendorType = "InnerVendorType"; + public static final String TAG_IPProtocol = "IPProtocol"; + public static final String TAG_MachineManaged = "MachineManaged"; + public static final String TAG_MaximumBSSLoadValue = "MaximumBSSLoadValue"; + public static final String TAG_MinBackhaulThreshold = "MinBackhaulThreshold"; + public static final String TAG_NetworkID = "NetworkID"; + public static final String TAG_NetworkType = "NetworkType"; + public static final String TAG_Other = "Other"; + public static final String TAG_OtherHomePartners = "OtherHomePartners"; + public static final String TAG_Password = "Password"; + public static final String TAG_PerProviderSubscription = "PerProviderSubscription"; + public static final String TAG_Policy = "Policy"; + public static final String TAG_PolicyUpdate = "PolicyUpdate"; + public static final String TAG_PortNumber = "PortNumber"; + public static final String TAG_PreferredRoamingPartnerList = "PreferredRoamingPartnerList"; + public static final String TAG_Priority = "Priority"; + public static final String TAG_Realm = "Realm"; + public static final String TAG_RequiredProtoPortTuple = "RequiredProtoPortTuple"; + public static final String TAG_Restriction = "Restriction"; + public static final String TAG_RoamingConsortiumOI = "RoamingConsortiumOI"; + public static final String TAG_SIM = "SIM"; + public static final String TAG_SoftTokenApp = "SoftTokenApp"; + public static final String TAG_SPExclusionList = "SPExclusionList"; + public static final String TAG_SSID = "SSID"; + public static final String TAG_StartDate = "StartDate"; + public static final String TAG_SubscriptionParameters = "SubscriptionParameters"; + public static final String TAG_SubscriptionUpdate = "SubscriptionUpdate"; + public static final String TAG_TimeLimit = "TimeLimit"; + public static final String TAG_TrustRoot = "TrustRoot"; + public static final String TAG_TypeOfSubscription = "TypeOfSubscription"; + public static final String TAG_ULBandwidth = "ULBandwidth"; + public static final String TAG_UpdateIdentifier = "UpdateIdentifier"; + public static final String TAG_UpdateInterval = "UpdateInterval"; + public static final String TAG_UpdateMethod = "UpdateMethod"; + public static final String TAG_URI = "URI"; + public static final String TAG_UsageLimits = "UsageLimits"; + public static final String TAG_UsageTimePeriod = "UsageTimePeriod"; + public static final String TAG_Username = "Username"; + public static final String TAG_UsernamePassword = "UsernamePassword"; + public static final String TAG_VendorId = "VendorId"; + public static final String TAG_VendorType = "VendorType"; + private final File mPpsFile; private final Map<String, HomeSP> mSPs; - public MOManager(File ppsFile) throws IOException { + public MOManager(File ppsFile) { mPpsFile = ppsFile; mSPs = new HashMap<>(); } @@ -54,53 +128,34 @@ public class MOManager { } public List<HomeSP> loadAllSPs() throws IOException { - List<MOTree> trees = new ArrayList<MOTree>(); - List<HomeSP> sps = new ArrayList<HomeSP>(); if (!mPpsFile.exists()) { - return sps; + return Collections.emptyList(); } - BufferedInputStream in = null; - try { - in = new BufferedInputStream(new FileInputStream(mPpsFile)); - while (in.available() > 0) { - MOTree tree = MOTree.unmarshal(in); - if (tree != null) { - trees.add(tree); - } else { - break; - } - } - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException ioe) { - /**/ - } + try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) { + MOTree moTree = MOTree.unmarshal(in); + Log.d("HS2J", "MO Tree: " + moTree); + mSPs.clear(); + if (moTree == null) { + return Collections.emptyList(); // Empty file } - } - for (MOTree moTree : trees) { - List<HomeSP> sp = buildSPs(moTree); - if (sp != null) { - sps.addAll(sp); - } else { - Log.d("PARSE-LOG", "failed to build HomeSP"); - } - } + List<HomeSP> sps = buildSPs(moTree); + if (sps != null) { + for (HomeSP sp : sps) { + if (mSPs.put(sp.getFQDN(), sp) != null) { + throw new OMAException("Multiple SPs for FQDN '" + sp.getFQDN() + "'"); + } else { + Log.d("PARSE-LOG", "retrieved " + sp.getFQDN() + " from PPS"); + } + } + return sps; - for (HomeSP sp : sps) { - if (mSPs.put(sp.getFQDN(), sp) != null) { - throw new OMAException("Multiple SPs for FQDN '" + sp.getFQDN() + "'"); } else { - Log.d("PARSE-LOG", "added " + sp.getFQDN() + " to list"); + throw new OMAException("Failed to build HomeSP"); } } - - Log.d("PARSE-LOG", "found " + mSPs.size() + " configurations"); - return sps; } public static HomeSP buildSP(String xml) throws IOException, SAXException { @@ -145,84 +200,172 @@ public class MOManager { } public void saveAllSps(Collection<HomeSP> homeSPs) throws IOException { + boolean dirty = homeSPs.size() != mSPs.size(); + + if (!dirty) { + Map<String, HomeSP> spClone = new HashMap<>(mSPs); + for (HomeSP homeSP : homeSPs) { + HomeSP existing = spClone.remove(homeSP.getFQDN()); + if (!homeSP.deepEquals(existing)) { + dirty = true; + break; + } + } + + if (!dirty) { + dirty = !spClone.isEmpty(); + } + } - OMAConstructed root = new OMAConstructed(null, "MgmtTree", ""); + Log.d("HS2J", "Save all SPs: dirty: " + dirty + + ", update from " + mSPs.size() + " to " + homeSPs); + if (homeSPs.size() < mSPs.size()) { + return; + } - for (HomeSP homeSP : homeSPs) { - OMANode providerNode = root.addChild(TAG_PerProviderSubscription, null, null, null); - OMANode providerSubNode = providerNode.addChild("Node", null, null, null); + if (dirty) { + mSPs.clear(); - if (mSPs.put(homeSP.getFQDN(), homeSP) != null) { - throw new OMAException("SP " + homeSP.getFQDN() + " already exists"); + OMAConstructed ppsNode = new OMAConstructed(null, TAG_PerProviderSubscription, null); + int instance = 0; + for (HomeSP homeSP : homeSPs) { + buildHomeSPTree(homeSP, ppsNode, instance++); + mSPs.put(homeSP.getFQDN(), homeSP); } - OMANode homeSpNode = providerSubNode.addChild(TAG_HomeSP, null, null, null); - homeSpNode.addChild(TAG_FQDN, null, homeSP.getFQDN(), null); - homeSpNode.addChild(TAG_FriendlyName, null, homeSP.getFriendlyName(), null); - - OMANode credentialNode = providerSubNode.addChild(TAG_Credential, null, null, null); - Credential cred = homeSP.getCredential(); - EAPMethod method = cred.getEAPMethod(); - if (method == null) { - throw new OMAException("SP " + homeSP.getFQDN() + " already exists"); + MOTree tree = new MOTree(OMAConstants.LOC_PPS + ":1.0", "1.2", ppsNode); + try (BufferedOutputStream out = + new BufferedOutputStream(new FileOutputStream(mPpsFile, true))) { + tree.marshal(out); + out.flush(); } + } + } - if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_SIM - || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKA - || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKAPrim) { + private static void buildHomeSPTree(HomeSP homeSP, OMAConstructed root, int spInstance) + throws IOException { + OMANode providerSubNode = root.addChild(getInstanceString(spInstance), null, null, null); + + // The HomeSP: + OMANode homeSpNode = providerSubNode.addChild(TAG_HomeSP, null, null, null); + if (!homeSP.getSSIDs().isEmpty()) { + OMAConstructed nwkIDNode = + (OMAConstructed) homeSpNode.addChild(TAG_NetworkID, null, null, null); + int instance = 0; + for (Map.Entry<String, Long> entry : homeSP.getSSIDs().entrySet()) { + OMAConstructed inode = + (OMAConstructed) nwkIDNode.addChild(getInstanceString(instance++), null, null, null); + inode.addChild(TAG_SSID, null, entry.getKey(), null); + if (entry.getValue() != null) { + inode.addChild(TAG_HESSID, null, String.format("%012x", entry.getValue()), null); + } + } + } - OMANode simNode = credentialNode.addChild(TAG_SIM, null, null, null); - simNode.addChild(TAG_IMSI, null, cred.getImsi(), null); - simNode.addChild(TAG_EAPType, null, - Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null); + homeSpNode.addChild(TAG_FriendlyName, null, homeSP.getFriendlyName(), null); - } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TTLS) { + if (homeSP.getIconURL() != null) { + homeSpNode.addChild(TAG_IconURL, null, homeSP.getIconURL(), null); + } - OMANode unpNode = credentialNode.addChild(TAG_UsernamePassword, null, null, null); - unpNode.addChild(TAG_Username, null, cred.getUserName(), null); - unpNode.addChild(TAG_Password, null, cred.getPassword(), null); - OMANode eapNode = unpNode.addChild(TAG_EAPMethod, null, null, null); - eapNode.addChild(TAG_EAPType, null, - Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null); - eapNode.addChild(TAG_InnerMethod, null, - ((NonEAPInnerAuth) method.getAuthParam()).getOMAtype(), null); + homeSpNode.addChild(TAG_FQDN, null, homeSP.getFQDN(), null); - } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TLS) { + if (!homeSP.getMatchAllOIs().isEmpty() || !homeSP.getMatchAnyOIs().isEmpty()) { + OMAConstructed homeOIList = + (OMAConstructed) homeSpNode.addChild(TAG_HomeOIList, null, null, null); - OMANode certNode = credentialNode.addChild(TAG_DigitalCertificate, null, null, null); - certNode.addChild(TAG_CertificateType, null, Credential.CertTypeX509, null); - certNode.addChild(TAG_CertSHA256Fingerprint, null, - Utils.toHex(cred.getFingerPrint()), null); + int instance = 0; + for (Long oi : homeSP.getMatchAllOIs()) { + OMAConstructed inode = + (OMAConstructed) homeOIList.addChild(getInstanceString(instance++), + null, null, null); + inode.addChild(TAG_HomeOI, null, String.format("%x", oi), null); + inode.addChild(TAG_HomeOIRequired, null, "TRUE", null); + } + for (Long oi : homeSP.getMatchAnyOIs()) { + OMAConstructed inode = + (OMAConstructed) homeOIList.addChild(getInstanceString(instance++), + null, null, null); + inode.addChild(TAG_HomeOI, null, String.format("%x", oi), null); + inode.addChild(TAG_HomeOIRequired, null, "FALSE", null); + } + } - } else { - throw new OMAException("Invalid credential on " + homeSP.getFQDN()); + if (!homeSP.getOtherHomePartners().isEmpty()) { + OMAConstructed otherPartners = + (OMAConstructed) homeSpNode.addChild(TAG_OtherHomePartners, null, null, null); + int instance = 0; + for (String fqdn : homeSP.getOtherHomePartners()) { + OMAConstructed inode = + (OMAConstructed) otherPartners.addChild(getInstanceString(instance++), + null, null, null); + inode.addChild(TAG_FQDN, null, fqdn, null); } + } - credentialNode.addChild(TAG_Realm, null, homeSP.getCredential().getRealm(), null); - // !!! Note: This node defines CRL checking through OSCP, I suspect we won't be able - // to do that so it is commented out: - //credentialNode.addChild(TAG_CheckAAAServerCertStatus, null, "TRUE", null); + if (!homeSP.getRoamingConsortiums().isEmpty()) { + homeSpNode.addChild(TAG_RoamingConsortiumOI, null, getRCList(homeSP.getRoamingConsortiums()), null); + } - StringBuilder builder = new StringBuilder(); - boolean first = true; - for (Long roamingConsortium : homeSP.getRoamingConsortiums()) { - if (first) { - first = false; - } - else { - builder.append(','); - } - builder.append(String.format("%x", roamingConsortium)); - } - credentialNode.addChild(TAG_RoamingConsortiumOI, null, builder.toString(), null); + // The Credential: + OMANode credentialNode = providerSubNode.addChild(TAG_Credential, null, null, null); + Credential cred = homeSP.getCredential(); + EAPMethod method = cred.getEAPMethod(); + + if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_SIM + || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKA + || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKAPrim) { + + OMANode simNode = credentialNode.addChild(TAG_SIM, null, null, null); + simNode.addChild(TAG_IMSI, null, cred.getImsi(), null); + simNode.addChild(TAG_EAPType, null, + Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null); + + } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TTLS) { + + OMANode unpNode = credentialNode.addChild(TAG_UsernamePassword, null, null, null); + unpNode.addChild(TAG_Username, null, cred.getUserName(), null); + unpNode.addChild(TAG_Password, null, cred.getPassword(), null); + OMANode eapNode = unpNode.addChild(TAG_EAPMethod, null, null, null); + eapNode.addChild(TAG_EAPType, null, + Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null); + eapNode.addChild(TAG_InnerMethod, null, + ((NonEAPInnerAuth) method.getAuthParam()).getOMAtype(), null); + + } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TLS) { + + OMANode certNode = credentialNode.addChild(TAG_DigitalCertificate, null, null, null); + certNode.addChild(TAG_CertificateType, null, Credential.CertTypeX509, null); + certNode.addChild(TAG_CertSHA256Fingerprint, null, + Utils.toHex(cred.getFingerPrint()), null); + + } else { + throw new OMAException("Invalid credential on " + homeSP.getFQDN()); } - MOTree tree = new MOTree(OMAConstants.LOC_PPS + ":1.0", "1.2", root); - try (BufferedOutputStream out = - new BufferedOutputStream(new FileOutputStream(mPpsFile, true))) { - tree.marshal(out); - out.flush(); + credentialNode.addChild(TAG_Realm, null, homeSP.getCredential().getRealm(), null); + // !!! Note: This node defines CRL checking through OSCP, I suspect we won't be able + // to do that so it is commented out: + //credentialNode.addChild(TAG_CheckAAAServerCertStatus, null, "TRUE", null); + } + + private static String getInstanceString(int instance) { + return "i" + instance; + } + + private static String getRCList(Collection<Long> rcs) { + StringBuilder builder = new StringBuilder(); + boolean first = true; + for (Long roamingConsortium : rcs) { + if (first) { + first = false; + } + else { + builder.append(','); + } + builder.append(String.format("%x", roamingConsortium)); } + return builder.toString(); } private static final DateFormat DTFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); @@ -231,81 +374,17 @@ public class MOManager { DTFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } - public static final String TAG_AAAServerTrustRoot = "AAAServerTrustRoot"; - public static final String TAG_AbleToShare = "AbleToShare"; - public static final String TAG_CertificateType = "CertificateType"; - public static final String TAG_CertSHA256Fingerprint = "CertSHA256Fingerprint"; - public static final String TAG_CertURL = "CertURL"; - public static final String TAG_CheckAAAServerCertStatus = "CheckAAAServerCertStatus"; - public static final String TAG_Country = "Country"; - public static final String TAG_CreationDate = "CreationDate"; - public static final String TAG_Credential = "Credential"; - public static final String TAG_CredentialPriority = "CredentialPriority"; - public static final String TAG_DataLimit = "DataLimit"; - public static final String TAG_DigitalCertificate = "DigitalCertificate"; - public static final String TAG_DLBandwidth = "DLBandwidth"; - public static final String TAG_EAPMethod = "EAPMethod"; - public static final String TAG_EAPType = "EAPType"; - public static final String TAG_ExpirationDate = "ExpirationDate"; - public static final String TAG_Extension = "Extension"; - public static final String TAG_FQDN = "FQDN"; - public static final String TAG_FQDN_Match = "FQDN_Match"; - public static final String TAG_FriendlyName = "FriendlyName"; - public static final String TAG_HESSID = "HESSID"; - public static final String TAG_HomeOI = "HomeOI"; - public static final String TAG_HomeOIList = "HomeOIList"; - public static final String TAG_HomeOIRequired = "HomeOIRequired"; - public static final String TAG_HomeSP = "HomeSP"; - public static final String TAG_IconURL = "IconURL"; - public static final String TAG_IMSI = "IMSI"; - public static final String TAG_InnerEAPType = "InnerEAPType"; - public static final String TAG_InnerMethod = "InnerMethod"; - public static final String TAG_InnerVendorID = "InnerVendorID"; - public static final String TAG_InnerVendorType = "InnerVendorType"; - public static final String TAG_IPProtocol = "IPProtocol"; - public static final String TAG_MachineManaged = "MachineManaged"; - public static final String TAG_MaximumBSSLoadValue = "MaximumBSSLoadValue"; - public static final String TAG_MinBackhaulThreshold = "MinBackhaulThreshold"; - public static final String TAG_NetworkID = "NetworkID"; - public static final String TAG_NetworkType = "NetworkType"; - public static final String TAG_Other = "Other"; - public static final String TAG_OtherHomePartners = "OtherHomePartners"; - public static final String TAG_Password = "Password"; - public static final String TAG_PerProviderSubscription = "PerProviderSubscription"; - public static final String TAG_Policy = "Policy"; - public static final String TAG_PolicyUpdate = "PolicyUpdate"; - public static final String TAG_PortNumber = "PortNumber"; - public static final String TAG_PreferredRoamingPartnerList = "PreferredRoamingPartnerList"; - public static final String TAG_Priority = "Priority"; - public static final String TAG_Realm = "Realm"; - public static final String TAG_RequiredProtoPortTuple = "RequiredProtoPortTuple"; - public static final String TAG_Restriction = "Restriction"; - public static final String TAG_RoamingConsortiumOI = "RoamingConsortiumOI"; - public static final String TAG_SIM = "SIM"; - public static final String TAG_SoftTokenApp = "SoftTokenApp"; - public static final String TAG_SPExclusionList = "SPExclusionList"; - public static final String TAG_SSID = "SSID"; - public static final String TAG_StartDate = "StartDate"; - public static final String TAG_SubscriptionParameters = "SubscriptionParameters"; - public static final String TAG_SubscriptionUpdate = "SubscriptionUpdate"; - public static final String TAG_TimeLimit = "TimeLimit"; - public static final String TAG_TrustRoot = "TrustRoot"; - public static final String TAG_TypeOfSubscription = "TypeOfSubscription"; - public static final String TAG_ULBandwidth = "ULBandwidth"; - public static final String TAG_UpdateIdentifier = "UpdateIdentifier"; - public static final String TAG_UpdateInterval = "UpdateInterval"; - public static final String TAG_UpdateMethod = "UpdateMethod"; - public static final String TAG_URI = "URI"; - public static final String TAG_UsageLimits = "UsageLimits"; - public static final String TAG_UsageTimePeriod = "UsageTimePeriod"; - public static final String TAG_Username = "Username"; - public static final String TAG_UsernamePassword = "UsernamePassword"; - public static final String TAG_VendorId = "VendorId"; - public static final String TAG_VendorType = "VendorType"; - private static List<HomeSP> buildSPs(MOTree moTree) throws OMAException { - List<String> spPath = Arrays.asList(TAG_PerProviderSubscription); - OMAConstructed spList = moTree.getRoot().getListValue(spPath.iterator()); + Log.d("HS2J", "MO root: " + moTree.getRoot().getName()); + OMAConstructed spList; + if (moTree.getRoot().getName().equals(TAG_PerProviderSubscription)) { + // The PPS file is rooted at PPS instead of MgmtTree to conserve space + spList = moTree.getRoot(); + } + else { + List<String> spPath = Arrays.asList(TAG_PerProviderSubscription); + spList = moTree.getRoot().getListValue(spPath.iterator()); + } List<HomeSP> homeSPs = new ArrayList<>(); @@ -326,7 +405,7 @@ public class MOManager { String friendlyName = spRoot.getScalarValue(Arrays.asList(TAG_FriendlyName).iterator()); String iconURL = spRoot.getScalarValue(Arrays.asList(TAG_IconURL).iterator()); - HashSet<Long> roamingConsortiums = new HashSet<Long>(); + HashSet<Long> roamingConsortiums = new HashSet<>(); String oiString = spRoot.getScalarValue(Arrays.asList(TAG_RoamingConsortiumOI).iterator()); if (oiString != null) { for (String oi : oiString.split(",")) { @@ -334,7 +413,7 @@ public class MOManager { } } - Map<String, Long> ssids = new HashMap<String, Long>(); + Map<String, Long> ssids = new HashMap<>(); OMANode ssidListNode = spRoot.getListValue(Arrays.asList(TAG_NetworkID).iterator()); if (ssidListNode != null) { @@ -344,8 +423,8 @@ public class MOManager { } } - Set<Long> matchAnyOIs = new HashSet<Long>(); - List<Long> matchAllOIs = new ArrayList<Long>(); + Set<Long> matchAnyOIs = new HashSet<>(); + List<Long> matchAllOIs = new ArrayList<>(); OMANode homeOIListNode = spRoot.getListValue(Arrays.asList(TAG_HomeOIList).iterator()); if (homeOIListNode != null) { for (OMANode homeOIRoot : homeOIListNode.getChildren()) { @@ -358,7 +437,7 @@ public class MOManager { } } - Set<String> otherHomePartners = new HashSet<String>(); + Set<String> otherHomePartners = new HashSet<>(); OMANode otherListNode = spRoot.getListValue(Arrays.asList(TAG_OtherHomePartners).iterator()); if (otherListNode != null) { diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java b/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java index 3d9bb99a5..96df05f59 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java @@ -11,6 +11,8 @@ import java.nio.charset.StandardCharsets; import java.util.*; public class MOTree { + public static final String MgmtTreeTag = "MgmtTree"; + private static final String NodeTag = "Node"; private static final String NodeNameTag = "NodeName"; private static final String PathTag = "Path"; @@ -40,7 +42,7 @@ public class MOTree { mUrn = urn; mDtdRev = dtdRev; - mRoot = new OMAConstructed(null, ".", null); + mRoot = new OMAConstructed(null, MgmtTreeTag, null); for (XMLNode child : node.getChildren()) { buildNode(mRoot, child); @@ -199,9 +201,7 @@ public class MOTree { StringBuilder tree = new StringBuilder(); for (; ; ) { int octet = in.read(); - Log.d("PARSE-LOG", "octet = " + octet); if (octet < 0) { - Log.d("PARSE-LOG", "returning because octet < 0"); return null; } else if (octet > ' ') { tree.append((char) octet); @@ -210,16 +210,15 @@ public class MOTree { break; } } - if (!tree.toString().equals("tree")) + if (!tree.toString().equals("tree")) { throw new IOException("Not a tree: " + tree); + } String version = OMAConstants.deserializeString(in); String urn = OMAConstants.readURN(in); - Log.d("PARSE-LOG", "version = " + version + ", urn = " + urn); OMAConstructed root = OMANode.unmarshal(in); - Log.d("PARSE-LOG", "return new MOTree"); return new MOTree(urn, version, root); } } diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java index 9d926cf86..34db91d6b 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java @@ -1,18 +1,20 @@ package com.android.server.wifi.hotspot2.omadm; -import android.util.Log; - import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; public class OMAConstructed extends OMANode { - private final Map<String, OMANode> m_children; + private final Map<String, OMANode> mChildren; public OMAConstructed(OMANode parent, String name, String context) { super(parent, name, context); - m_children = new HashMap<>(); + mChildren = new HashMap<>(); } @Override @@ -21,7 +23,7 @@ public class OMAConstructed extends OMANode { OMANode child = value != null ? new OMAScalar(this, name, context, value) : new OMAConstructed(this, name, context); - m_children.put(name, child); + mChildren.put(name, child); return child; } else { OMANode target = this; @@ -44,7 +46,7 @@ public class OMAConstructed extends OMANode { throw new OMAException("Path too short for " + getPathString()); } String tag = path.next(); - OMANode child = m_children.get(tag); + OMANode child = mChildren.get(tag); if (child != null) { return child.getScalarValue(path); } else { @@ -58,7 +60,7 @@ public class OMAConstructed extends OMANode { return this; } String tag = path.next(); - OMANode child = m_children.get(tag); + OMANode child = mChildren.get(tag); if (child != null) { return child.getListValue(path); } else { @@ -73,11 +75,11 @@ public class OMAConstructed extends OMANode { @Override public Collection<OMANode> getChildren() { - return Collections.unmodifiableCollection(m_children.values()); + return Collections.unmodifiableCollection(mChildren.values()); } public OMANode getChild(String name) { - return m_children.get(name); + return mChildren.get(name); } @Override @@ -87,12 +89,15 @@ public class OMAConstructed extends OMANode { @Override public void toString(StringBuilder sb, int level) { + sb.append(getPathString()); if (getContext() != null) { - sb.append(getPathString()).append(" (").append(getContext()).append(')').append('\n'); + sb.append(" (").append(getContext()).append(')'); } + sb.append('\n'); - for (OMANode node : m_children.values()) + for (OMANode node : mChildren.values()) { node.toString(sb, level + 1); + } } @Override @@ -104,9 +109,7 @@ public class OMAConstructed extends OMANode { } out.write(new byte[] { '+', '\n' }); - Log.d("PARSE-LOG", "Node " + getName() + " has " + m_children.size() + " children"); - for (OMANode child : m_children.values()) { - Log.d("PARSE-LOG", "marshalling " + child.getName()); + for (OMANode child : mChildren.values()) { child.marshal(out, level + 1); } OMAConstants.indent(level, out); diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java index 97121e279..5eab73d9f 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java @@ -1,7 +1,5 @@ package com.android.server.wifi.hotspot2.omadm; -import android.util.Log; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -34,9 +32,10 @@ public abstract class OMANode { } public List<String> getPath() { - LinkedList<String> path = new LinkedList<String>(); - for (OMANode node = this; node.getParent() != null; node = node.getParent()) + LinkedList<String> path = new LinkedList<>(); + for (OMANode node = this; node != null; node = node.getParent()) { path.addFirst(node.getName()); + } return path; } @@ -76,8 +75,9 @@ public abstract class OMANode { public static OMAConstructed unmarshal(InputStream in) throws IOException { OMANode node = buildNode(in, null); - if (node == null || node.isLeaf()) + if (node == null || node.isLeaf()) { throw new IOException("Bad OMA tree"); + } unmarshal(in, (OMAConstructed) node); return (OMAConstructed) node; } @@ -85,45 +85,39 @@ public abstract class OMANode { private static void unmarshal(InputStream in, OMAConstructed parent) throws IOException { for (; ; ) { OMANode node = buildNode(in, parent); - if (node == null) + if (node == null) { return; - else if (!node.isLeaf()) + } + else if (!node.isLeaf()) { unmarshal(in, (OMAConstructed) node); + } } } private static OMANode buildNode(InputStream in, OMAConstructed parent) throws IOException { String name = OMAConstants.deserializeString(in); if (name == null) { - Log.d("PARSE-LOG", "Could not read node name"); return null; } - Log.d("PARSE-LOG", "name = " + name); - String urn = null; int next = in.read(); if (next == '(') { urn = OMAConstants.readURN(in); - Log.d("PARSE-LOG", "Urn = " + urn); next = in.read(); } if (next == '=') { String value = OMAConstants.deserializeString(in); - Log.d("PARSE-LOG", "value = " + value); return parent.addChild(name, urn, value, null); } else if (next == '+') { if (parent != null) { - Log.d("PARSE-LOG", "added child node " + name); return parent.addChild(name, urn, null, null); } else { - Log.d("PARSE-LOG", "created new node " + name); return new OMAConstructed(null, name, urn); } } else { - Log.d("PARSE-LOG", "parsing error"); throw new IOException("Parse error: expected = or + after node name"); } } diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java index 7802a435a..fa93478af 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java @@ -61,8 +61,6 @@ public class OMAScalar extends OMANode { @Override public void marshal(OutputStream out, int level) throws IOException { - Log.d("PARSE-LOG", "Node " + getName() + " has value " + getValue()); - OMAConstants.indent(level, out); OMAConstants.serializeString(getName(), out); out.write((byte) '='); |