diff options
4 files changed, 541 insertions, 13 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java b/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java new file mode 100644 index 000000000..9799c2ea5 --- /dev/null +++ b/service/java/com/android/server/wifi/hotspot2/omadm/DevDetailMo.java @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi.hotspot2.omadm; + +import android.annotation.NonNull; +import android.content.Context; +import android.net.wifi.EAPConstants; +import android.telephony.TelephonyManager; +import android.text.TextUtils; +import android.util.Log; +import android.util.Pair; + +import com.android.internal.annotations.VisibleForTesting; +import com.android.server.wifi.hotspot2.SystemInfo; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.ParserConfigurationException; + +/** + * Provides serialization API for DevDetail MO (Management Object). + */ +public class DevDetailMo { + private static final String TAG = "DevDetailMo"; + // Refer to 9.2 DevDetail MO vendor specific extensions + // in the Hotspot2.0 R2 Technical Specification document in detail + @VisibleForTesting + public static final String URN = "urn:oma:mo:oma-dm-devdetail:1.0"; + @VisibleForTesting + public static final String HS20_URN = "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0"; + + private static final String MO_NAME = "DevDetail"; + + private static final String TAG_EXT = "ext"; + private static final String TAG_ORG_WIFI = "org.wi-fi"; + private static final String TAG_WIFI = "Wi-Fi"; + private static final String TAG_EAP_METHOD_LIST = "EAPMethodList"; //Required field + private static final String TAG_EAP_METHOD = "EAPMethod"; //Required field + private static final String TAG_EAP_TYPE = "EAPType"; //Required field + private static final String TAG_VENDOR_ID = "VendorId"; + private static final String TAG_VENDOR_TYPE = "VendorType"; + private static final String TAG_INNER_EAP_TYPE = "InnerEAPType"; + private static final String TAG_INNER_VENDOR_ID = "InnerVendorID"; + private static final String TAG_INNER_VENDOR_TYPE = "InnerVendorType"; + private static final String TAG_INNER_METHOD = "InnerMethod"; //Required field + + // Mobile device information related to certificates provisioned by SPs + private static final String TAG_SP_CERTIFICATE = "SPCertificate"; + private static final String TAG_CERTIFICATE_ISSUER_NAME = "CertificateIssuerName"; + + // Required if the mobile device is in possession of an IEEE 802.1ar-compliant + // manufacturing certificate and is authorized to use that certificate for + // mobile device AAA authentication + private static final String TAG_MANUFACTURING_CERT = "ManufacturingCertificate"; + // Required for a device having a SIM, but will not provide the IMSI to an SP that + // did not issue the IMSI. + private static final String TAG_IMSI = "IMSI"; + // Required for the device having a SIM. + private static final String TAG_IMEI_MEID = "IMEI_MEID"; + + private static final String TAG_WIFI_MAC_ADDR = "Wi-FiMACAddress"; // Required field + + // Required field + private static final String TAG_CLIENT_TRIGGER_REDIRECT_URI = "ClientTriggerRedirectURI"; + + private static final String TAG_OPS = "Ops"; + private static final String TAG_LAUNCH_BROWSER_TO_URI = "launchBrowserToURI"; + private static final String TAG_NEGOTIATE_CLIENT_CERT_TLS = "negotiateClientCertTLS"; + private static final String TAG_GET_CERTIFICATE = "getCertificate"; + + private static final List<String> sSupportedOps = new ArrayList<>(); + private static final String TAG_URI = "URI"; + private static final String TAG_MAX_DEPTH = "MaxDepth"; + private static final String TAG_MAX_TOT_LEN = "MaxTotLen"; + private static final String TAG_MAX_SEG_LEN = "MaxSegLen"; + private static final String TAG_DEV_TYPE = "DevType"; + private static final String TAG_OEM = "OEM"; + private static final String TAG_FW_VER = "FwV"; + private static final String TAG_SW_VER = "SwV"; + private static final String TAG_HW_VER = "HwV"; + private static final String TAG_LRG_ORJ = "LrgOrj"; + + private static final String INNER_METHOD_PAP = "PAP"; + private static final String INNER_METHOD_MS_CHAP = "MS-CHAP"; + private static final String INNER_METHOD_MS_CHAP_V2 = "MS-CHAP-V2"; + + private static final String IFNAME = "wlan0"; + private static final String DEVICE_TYPE = "Smartphone"; + + private static final List<Pair<Integer, String>> sEapMethods = new ArrayList<>(); + static { + sEapMethods.add(Pair.create(EAPConstants.EAP_TTLS, INNER_METHOD_MS_CHAP_V2)); + sEapMethods.add(Pair.create(EAPConstants.EAP_TTLS, INNER_METHOD_MS_CHAP)); + sEapMethods.add(Pair.create(EAPConstants.EAP_TTLS, INNER_METHOD_PAP)); + + sEapMethods.add(Pair.create(EAPConstants.EAP_TLS, null)); + sEapMethods.add(Pair.create(EAPConstants.EAP_SIM, null)); + sEapMethods.add(Pair.create(EAPConstants.EAP_AKA, null)); + sEapMethods.add(Pair.create(EAPConstants.EAP_AKA_PRIME, null)); + + sSupportedOps.add(TAG_LAUNCH_BROWSER_TO_URI); + } + + /** + * Make a format of XML based on the DDF(Data Definition Format) of DevDetail MO. + * + * expected_output : refer to Figure 73: example sppPostDevData SOAP message in Hotspot 2.0 + * Rel 2.0 Specification document. + * @param context {@link Context} + * @param info {@link SystemInfo} + * @param redirectUri redirect uri that server uses as completion of subscription. + * @param isHomeCarrier {@code true} if the network is the home carrier network. + * @return the XML that has format of OMA DM DevDetail Management Object, <code>null</code> in + * case of any failure. + */ + public static String serializeToXml(@NonNull Context context, @NonNull SystemInfo info, + @NonNull String redirectUri, boolean isHomeCarrier) { + String macAddress = info.getMacAddress(IFNAME); + if (macAddress != null) { + macAddress = macAddress.replace(":", ""); + } + if (TextUtils.isEmpty(macAddress)) { + Log.e(TAG, "mac address is empty"); + return null; + } + MoSerializer moSerializer; + try { + moSerializer = new MoSerializer(); + } catch (ParserConfigurationException e) { + Log.e(TAG, "failed to create the MoSerializer: " + e); + return null; + } + + TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService( + Context.TELEPHONY_SERVICE); + // Create the XML document for DevInfoMo + Document doc = moSerializer.createNewDocument(); + Element rootElement = moSerializer.createMgmtTree(doc); + rootElement.appendChild(moSerializer.writeVersion(doc)); + // <Node><NodeName>DevDetail</NodeName> + Element moNode = moSerializer.createNode(doc, MO_NAME); + + + moNode.appendChild(moSerializer.createNodeForUrn(doc, URN)); + // <Node><NodeName>Ext</NodeName> + Element extNode = moSerializer.createNode(doc, TAG_EXT); + // <Node><NodeName>org.wi-fi</NodeName> + Element orgNode = moSerializer.createNode(doc, TAG_ORG_WIFI); + orgNode.appendChild(moSerializer.createNodeForUrn(doc, HS20_URN)); + // <Node><NodeName>Wi-Fi</NodeName> + Element wifiNode = moSerializer.createNode(doc, TAG_WIFI); + // <Node><NodeName>EAPMethodList</NodeName> + Element eapMethodListNode = moSerializer.createNode(doc, TAG_EAP_METHOD_LIST); + + String tagName; + Element eapMethodNode; + + int i = 0; + for (Pair<Integer, String> entry : sEapMethods) { + tagName = String.format("%s%02d", TAG_EAP_METHOD, ++i); + eapMethodNode = moSerializer.createNode(doc, tagName); + eapMethodNode.appendChild( + moSerializer.createNodeForValue(doc, TAG_EAP_TYPE, entry.first.toString())); + if (entry.second != null) { + eapMethodNode.appendChild( + moSerializer.createNodeForValue(doc, TAG_INNER_METHOD, entry.second)); + } + eapMethodListNode.appendChild(eapMethodNode); + + } + wifiNode.appendChild(eapMethodListNode); // TAG_EAP_METHOD_LIST + + wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_MANUFACTURING_CERT, "FALSE")); + wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_CLIENT_TRIGGER_REDIRECT_URI, + redirectUri)); + wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_WIFI_MAC_ADDR, macAddress)); + + String imsi = telephonyManager.getSubscriberId(); + if (imsi != null) { + if (isHomeCarrier) { + // Don't provide the IMSI to an SP that did not issue the IMSI + wifiNode.appendChild(moSerializer.createNodeForValue(doc, TAG_IMSI, imsi)); + } + // Mandatory for mobile devices possessing a SIM card. + wifiNode.appendChild( + moSerializer.createNodeForValue(doc, TAG_IMEI_MEID, info.getDeviceId())); + } + + // <Node><NodeName>Ops</NodeName> + Element opsNode = moSerializer.createNode(doc, TAG_OPS); + for (String op: sSupportedOps) { + opsNode.appendChild(moSerializer.createNodeForValue(doc, op, "")); + } + wifiNode.appendChild(opsNode); // TAG_OPS + orgNode.appendChild(wifiNode); // TAG_WIFI + extNode.appendChild(orgNode); // TAG_ORG_WIFI + moNode.appendChild(extNode); // TAG_EXT + // <Node><NodeName>URI</NodeName> + Element uriNode = moSerializer.createNode(doc, TAG_URI); + + uriNode.appendChild(moSerializer.createNodeForValue(doc, TAG_MAX_DEPTH, "32")); + uriNode.appendChild(moSerializer.createNodeForValue(doc, TAG_MAX_TOT_LEN, "2048")); + uriNode.appendChild(moSerializer.createNodeForValue(doc, TAG_MAX_SEG_LEN, "64")); + moNode.appendChild(uriNode); // TAG_URI + + moNode.appendChild(moSerializer.createNodeForValue(doc, TAG_DEV_TYPE, DEVICE_TYPE)); + moNode.appendChild( + moSerializer.createNodeForValue(doc, TAG_OEM, info.getDeviceManufacturer())); + moNode.appendChild( + moSerializer.createNodeForValue(doc, TAG_FW_VER, info.getFirmwareVersion())); + moNode.appendChild( + moSerializer.createNodeForValue(doc, TAG_SW_VER, info.getSoftwareVersion())); + moNode.appendChild(moSerializer.createNodeForValue(doc, TAG_HW_VER, info.getHwVersion())); + moNode.appendChild(moSerializer.createNodeForValue(doc, TAG_LRG_ORJ, "TRUE")); + rootElement.appendChild(moNode); // TAG_DEVDETAIL + + return moSerializer.serialize(doc); + } +} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java b/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java index 4bae5c908..28ebf7e56 100644 --- a/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java +++ b/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java @@ -25,6 +25,8 @@ import org.w3c.dom.Element; import javax.xml.parsers.ParserConfigurationException; +import android.annotation.NonNull; + /** * Provides serialization API for DevInfo MO (Management Object). * @@ -45,19 +47,13 @@ public class DevInfoMo { private static final String TAG_DM_VERSION = "DmV"; private static final String TAG_LANGUAGE = "Lang"; - private final SystemInfo mSystemInfo; - - public DevInfoMo(SystemInfo systemInfo) { - mSystemInfo = systemInfo; - } - /** * Make a format of XML based on the DDF(Data Definition Format) of DevInfo MO. * * @return the XML that has format of OMA DM DevInfo Management Object, <code>null</code> in * case of any failure. */ - public String serializeToXml() { + public static String serializeToXml(@NonNull SystemInfo systemInfo) { MoSerializer moSerializer; try { moSerializer = new MoSerializer(); @@ -73,16 +69,16 @@ public class DevInfoMo { moNode.appendChild(moSerializer.createNodeForUrn(doc, URN)); rootElement.appendChild(moNode); rootElement.appendChild( - moSerializer.createNodeForValue(doc, TAG_DEVID, mSystemInfo.getDeviceId())); + moSerializer.createNodeForValue(doc, TAG_DEVID, systemInfo.getDeviceId())); rootElement.appendChild(moSerializer.createNodeForValue(doc, TAG_MANUFACTURE, - mSystemInfo.getDeviceManufacturer())); + systemInfo.getDeviceManufacturer())); rootElement.appendChild( - moSerializer.createNodeForValue(doc, TAG_MODEL, mSystemInfo.getDeviceModel())); + moSerializer.createNodeForValue(doc, TAG_MODEL, systemInfo.getDeviceModel())); rootElement.appendChild( moSerializer.createNodeForValue(doc, TAG_DM_VERSION, MoSerializer.DM_VERSION)); rootElement.appendChild( - moSerializer.createNodeForValue(doc, TAG_LANGUAGE, mSystemInfo.getLanguage())); + moSerializer.createNodeForValue(doc, TAG_LANGUAGE, systemInfo.getLanguage())); return moSerializer.serialize(doc); } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java new file mode 100644 index 000000000..ff3d86ff5 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevDetailMoTest.java @@ -0,0 +1,295 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi.hotspot2.omadm; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import android.content.Context; +import android.os.Build; +import android.support.test.filters.SmallTest; +import android.telephony.TelephonyManager; + +import com.android.server.wifi.hotspot2.SystemInfo; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; + +/** + * Unit tests for {@link DevDetailMo}. + * TODO(b/80300806): change the test to verify the XML in terms of the structure of XML. + */ +@SmallTest +public class DevDetailMoTest { + private static final String TEST_DEV_ID = "12312341"; + private static final String TEST_MANUFACTURER = Build.MANUFACTURER; + private static final String TEST_HW_VERSION = "Test HW 1.0"; + private static final String TEST_MAC_ADDR = "11:22:33:44:55:66"; + private static final String TEST_IMSI = "310150123456789"; + private static final String TEST_SW_VERSION = "Android Test 1.0"; + private static final String TEST_FW_VERSION = "Test FW 1.0"; + private static final String TEST_REDIRECT_URL = "http://127.0.0.1:12345/index.htm"; + + @Mock + private SystemInfo mSystemInfo; + @Mock + private Context mContext; + @Mock + private TelephonyManager mTelephonyManager; + /** + * Sets up test. + */ + @Before + public void setUp() throws Exception { + initMocks(this); + when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mSystemInfo.getDeviceId()).thenReturn(TEST_DEV_ID); + when(mSystemInfo.getDeviceManufacturer()).thenReturn(TEST_MANUFACTURER); + when(mSystemInfo.getHwVersion()).thenReturn(TEST_HW_VERSION); + when(mSystemInfo.getMacAddress(any(String.class))).thenReturn(TEST_MAC_ADDR); + when(mSystemInfo.getSoftwareVersion()).thenReturn(TEST_SW_VERSION); + when(mSystemInfo.getFirmwareVersion()).thenReturn(TEST_FW_VERSION); + when(mTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI); + } + + /** + * Verify the serialization will return null if wifi mac address was missed. + */ + @Test + public void serializeDevDetailMoWithoutMacaddress() { + when(mSystemInfo.getMacAddress(any(String.class))).thenReturn(null); + assertNull(DevDetailMo.serializeToXml(mContext, mSystemInfo, TEST_REDIRECT_URL, false)); + } + + /** + * Verify the serialization will include IMSI if the HS2.0 network is a home carrier network. + */ + @Test + public void serializeDevDetailMoForHomeNetworkCarrier() { + String expected = String.format("<MgmtTree>" + + "<VerDTD>%s</VerDTD>" + + "<Node><NodeName>DevDetail</NodeName>" + + "<RTProperties>" + + "<Type><DDFName>%s</DDFName></Type>" + + "</RTProperties>" + + "<Node><NodeName>ext</NodeName>" + + "<Node><NodeName>org.wi-fi</NodeName>" + + "<RTProperties>" + + "<Type><DDFName>%s</DDFName></Type>" + + "</RTProperties>" + + "<Node><NodeName>Wi-Fi</NodeName>" + + "<Node><NodeName>EAPMethodList</NodeName>" + + "<Node><NodeName>EAPMethod01</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>MS-CHAP-V2</Value></Node>" + + "</Node>" + + "<Node><NodeName>EAPMethod02</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>MS-CHAP</Value></Node>" + + "</Node>" + + "<Node><NodeName>EAPMethod03</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>PAP</Value></Node></Node>" + + "<Node><NodeName>EAPMethod04</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>13</Value></Node></Node>" + + "<Node><NodeName>EAPMethod05</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>18</Value></Node></Node>" + + "<Node><NodeName>EAPMethod06</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>23</Value></Node></Node>" + + "<Node><NodeName>EAPMethod07</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>50</Value></Node></Node>" + + "</Node>" + + "<Node><NodeName>ManufacturingCertificate</NodeName><Value>FALSE</Value>" + + "</Node>" + + "<Node><NodeName>ClientTriggerRedirectURI</NodeName>" + + "<Value>%s</Value></Node>" + + "<Node><NodeName>Wi-FiMACAddress</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>IMSI</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>IMEI_MEID</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>Ops</NodeName>" + + "<Node><NodeName>launchBrowserToURI</NodeName><Value/></Node>" + + "</Node>" + + "</Node>" + + "</Node>" + + "</Node>" + + "<Node><NodeName>URI</NodeName>" + + "<Node><NodeName>MaxDepth</NodeName><Value>32</Value></Node>" + + "<Node><NodeName>MaxTotLen</NodeName><Value>2048</Value></Node>" + + "<Node><NodeName>MaxSegLen</NodeName><Value>64</Value></Node>" + + "</Node>" + + "<Node><NodeName>DevType</NodeName><Value>Smartphone</Value></Node>" + + "<Node><NodeName>OEM</NodeName><Value>%s</Value></Node><Node>" + + "<NodeName>FwV</NodeName><Value>%s</Value></Node><Node>" + + "<NodeName>SwV</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>HwV</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>LrgOrj</NodeName><Value>TRUE</Value></Node>" + + "</Node>" + + "</MgmtTree>", + MoSerializer.DM_VERSION, DevDetailMo.URN, DevDetailMo.HS20_URN, + TEST_REDIRECT_URL, TEST_MAC_ADDR.replace(":", ""), TEST_IMSI, TEST_DEV_ID, + TEST_MANUFACTURER, TEST_FW_VERSION, TEST_SW_VERSION, TEST_HW_VERSION); + assertEquals(expected, + DevDetailMo.serializeToXml(mContext, mSystemInfo, TEST_REDIRECT_URL, true)); + } + + /** + * Verify the serialization will not include IMSI if the HS2.0 network is not a home carrier + * network. + */ + @Test + public void serializeDevDetailMoForOtherCarrier() { + + String expected = String.format("<MgmtTree>" + + "<VerDTD>%s</VerDTD>" + + "<Node><NodeName>DevDetail</NodeName>" + + "<RTProperties>" + + "<Type><DDFName>%s</DDFName></Type>" + + "</RTProperties>" + + "<Node><NodeName>ext</NodeName>" + + "<Node><NodeName>org.wi-fi</NodeName>" + + "<RTProperties>" + + "<Type><DDFName>%s</DDFName></Type>" + + "</RTProperties>" + + "<Node><NodeName>Wi-Fi</NodeName>" + + "<Node><NodeName>EAPMethodList</NodeName>" + + "<Node><NodeName>EAPMethod01</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>MS-CHAP-V2</Value></Node>" + + "</Node>" + + "<Node><NodeName>EAPMethod02</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>MS-CHAP</Value>" + + "</Node></Node>" + + "<Node><NodeName>EAPMethod03</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>PAP</Value></Node></Node>" + + "<Node><NodeName>EAPMethod04</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>13</Value></Node></Node>" + + "<Node><NodeName>EAPMethod05</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>18</Value></Node></Node>" + + "<Node><NodeName>EAPMethod06</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>23</Value></Node></Node>" + + "<Node><NodeName>EAPMethod07</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>50</Value></Node></Node>" + + "</Node>" + + "<Node><NodeName>ManufacturingCertificate</NodeName><Value>FALSE</Value>" + + "</Node>" + + "<Node><NodeName>ClientTriggerRedirectURI</NodeName>" + + "<Value>%s</Value></Node>" + + "<Node><NodeName>Wi-FiMACAddress</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>IMEI_MEID</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>Ops</NodeName>" + + "<Node><NodeName>launchBrowserToURI</NodeName><Value/></Node>" + + "</Node>" + + "</Node>" + + "</Node>" + + "</Node>" + + "<Node><NodeName>URI</NodeName>" + + "<Node><NodeName>MaxDepth</NodeName><Value>32</Value></Node>" + + "<Node><NodeName>MaxTotLen</NodeName><Value>2048</Value></Node>" + + "<Node><NodeName>MaxSegLen</NodeName><Value>64</Value></Node>" + + "</Node>" + + "<Node><NodeName>DevType</NodeName><Value>Smartphone</Value></Node>" + + "<Node><NodeName>OEM</NodeName><Value>%s</Value></Node><Node>" + + "<NodeName>FwV</NodeName><Value>%s</Value></Node><Node>" + + "<NodeName>SwV</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>HwV</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>LrgOrj</NodeName><Value>TRUE</Value></Node>" + + "</Node>" + + "</MgmtTree>", + MoSerializer.DM_VERSION, DevDetailMo.URN, DevDetailMo.HS20_URN, + TEST_REDIRECT_URL, TEST_MAC_ADDR.replace(":", ""), TEST_DEV_ID, TEST_MANUFACTURER, + TEST_FW_VERSION, TEST_SW_VERSION, TEST_HW_VERSION); + assertEquals(expected, + DevDetailMo.serializeToXml(mContext, mSystemInfo, TEST_REDIRECT_URL, false)); + } + + /** + * Verify the serialization will not include IMSI and IMEI if the device has no SIM. + */ + @Test + public void serializeDevDetailMoWithoutSim() { + when(mTelephonyManager.getSubscriberId()).thenReturn(null); + String expected = String.format("<MgmtTree>" + + "<VerDTD>%s</VerDTD>" + + "<Node><NodeName>DevDetail</NodeName>" + + "<RTProperties>" + + "<Type><DDFName>%s</DDFName></Type>" + + "</RTProperties>" + + "<Node><NodeName>ext</NodeName>" + + "<Node><NodeName>org.wi-fi</NodeName>" + + "<RTProperties>" + + "<Type><DDFName>%s</DDFName></Type>" + + "</RTProperties>" + + "<Node><NodeName>Wi-Fi</NodeName>" + + "<Node><NodeName>EAPMethodList</NodeName>" + + "<Node><NodeName>EAPMethod01</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>MS-CHAP-V2</Value></Node>" + + "</Node>" + + "<Node><NodeName>EAPMethod02</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>MS-CHAP</Value>" + + "</Node></Node>" + + "<Node><NodeName>EAPMethod03</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>21</Value></Node>" + + "<Node><NodeName>InnerMethod</NodeName><Value>PAP</Value></Node></Node>" + + "<Node><NodeName>EAPMethod04</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>13</Value></Node></Node>" + + "<Node><NodeName>EAPMethod05</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>18</Value></Node></Node>" + + "<Node><NodeName>EAPMethod06</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>23</Value></Node></Node>" + + "<Node><NodeName>EAPMethod07</NodeName>" + + "<Node><NodeName>EAPType</NodeName><Value>50</Value></Node></Node>" + + "</Node>" + + "<Node><NodeName>ManufacturingCertificate</NodeName><Value>FALSE</Value>" + + "</Node>" + + "<Node><NodeName>ClientTriggerRedirectURI</NodeName>" + + "<Value>%s</Value></Node>" + + "<Node><NodeName>Wi-FiMACAddress</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>Ops</NodeName>" + + "<Node><NodeName>launchBrowserToURI</NodeName><Value/></Node>" + + "</Node>" + + "</Node>" + + "</Node>" + + "</Node>" + + "<Node><NodeName>URI</NodeName>" + + "<Node><NodeName>MaxDepth</NodeName><Value>32</Value></Node>" + + "<Node><NodeName>MaxTotLen</NodeName><Value>2048</Value></Node>" + + "<Node><NodeName>MaxSegLen</NodeName><Value>64</Value></Node>" + + "</Node>" + + "<Node><NodeName>DevType</NodeName><Value>Smartphone</Value></Node>" + + "<Node><NodeName>OEM</NodeName><Value>%s</Value></Node><Node>" + + "<NodeName>FwV</NodeName><Value>%s</Value></Node><Node>" + + "<NodeName>SwV</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>HwV</NodeName><Value>%s</Value></Node>" + + "<Node><NodeName>LrgOrj</NodeName><Value>TRUE</Value></Node>" + + "</Node>" + + "</MgmtTree>", + MoSerializer.DM_VERSION, DevDetailMo.URN, DevDetailMo.HS20_URN, TEST_REDIRECT_URL, + TEST_MAC_ADDR.replace(":", ""), TEST_MANUFACTURER, + TEST_FW_VERSION, TEST_SW_VERSION, TEST_HW_VERSION); + assertEquals(expected, + DevDetailMo.serializeToXml(mContext, mSystemInfo, TEST_REDIRECT_URL, false)); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java index d0b93b941..065159587 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java @@ -29,6 +29,7 @@ import org.junit.Test; /** * Unit tests for {@link DevInfoMo}. + * TODO(b/80300806): change the test to verify the XML in terms of the structure of XML. */ @SmallTest public class DevInfoMoTest { @@ -57,7 +58,6 @@ public class DevInfoMoTest { + "</MgmtTree>", MoSerializer.DM_VERSION, DevInfoMo.URN, TEST_DEV_ID, TEST_MANUFACTURER, TEST_MODEL, MoSerializer.DM_VERSION, TEST_LANGUAGE); - DevInfoMo mo = new DevInfoMo(systemInfo); - assertEquals(expected, mo.serializeToXml()); + assertEquals(expected, DevInfoMo.serializeToXml(systemInfo)); } }
\ No newline at end of file |