summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/hotspot2/omadm
diff options
context:
space:
mode:
authorEcco Park <eccopark@google.com>2018-04-16 17:58:11 -0700
committerEcco Park <eccopark@google.com>2018-05-21 15:15:44 -0700
commit33370ca96ee94dd38c8102c8f128a972a4919657 (patch)
tree4e1275d6b6615feb167f61ad50b235cd5a82d922 /service/java/com/android/server/wifi/hotspot2/omadm
parentac0ef7e9e588142904807deea75946fada4192b1 (diff)
downloadandroid_frameworks_opt_net_wifi-33370ca96ee94dd38c8102c8f128a972a4919657.tar.gz
android_frameworks_opt_net_wifi-33370ca96ee94dd38c8102c8f128a972a4919657.tar.bz2
android_frameworks_opt_net_wifi-33370ca96ee94dd38c8102c8f128a972a4919657.zip
passpoint-r2: added the OMA-DM MO and XML lib for the serialization
Bug: 78141901 Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I0ddbfaf29c4ff6e3d3803cb33a15cae69fe4ba08 Signed-off-by: Ecco Park <eccopark@google.com>
Diffstat (limited to 'service/java/com/android/server/wifi/hotspot2/omadm')
-rw-r--r--service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java89
-rw-r--r--service/java/com/android/server/wifi/hotspot2/omadm/MoSerializer.java173
2 files changed, 262 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java b/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java
new file mode 100644
index 000000000..4bae5c908
--- /dev/null
+++ b/service/java/com/android/server/wifi/hotspot2/omadm/DevInfoMo.java
@@ -0,0 +1,89 @@
+/*
+ * 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.util.Log;
+
+import com.android.server.wifi.hotspot2.SystemInfo;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * Provides serialization API for DevInfo MO (Management Object).
+ *
+ * Devinfo---|- DevId
+ * |- Man
+ * |- Mod
+ * |- Dmv
+ * |- Lang
+ */
+public class DevInfoMo {
+ public static final String TAG = "DevInfoMo";
+ public static final String URN = "urn:oma:mo:oma-dm-devinfo:1.0";
+
+ private static final String MO_NAME = "DevInfo";
+ private static final String TAG_DEVID = "DevID";
+ private static final String TAG_MANUFACTURE = "Man";
+ private static final String TAG_MODEL = "Mod";
+ 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() {
+ MoSerializer moSerializer;
+ try {
+ moSerializer = new MoSerializer();
+ } catch (ParserConfigurationException e) {
+ Log.e(TAG, "failed to create the MoSerializer: " + e);
+ return null;
+ }
+ // Create the XML document for DevInfoMo
+ Document doc = moSerializer.createNewDocument();
+ Element rootElement = moSerializer.createMgmtTree(doc);
+ rootElement.appendChild(moSerializer.writeVersion(doc));
+ Element moNode = moSerializer.createNode(doc, MO_NAME);
+ moNode.appendChild(moSerializer.createNodeForUrn(doc, URN));
+ rootElement.appendChild(moNode);
+ rootElement.appendChild(
+ moSerializer.createNodeForValue(doc, TAG_DEVID, mSystemInfo.getDeviceId()));
+
+ rootElement.appendChild(moSerializer.createNodeForValue(doc, TAG_MANUFACTURE,
+ mSystemInfo.getDeviceManufacturer()));
+ rootElement.appendChild(
+ moSerializer.createNodeForValue(doc, TAG_MODEL, mSystemInfo.getDeviceModel()));
+ rootElement.appendChild(
+ moSerializer.createNodeForValue(doc, TAG_DM_VERSION, MoSerializer.DM_VERSION));
+ rootElement.appendChild(
+ moSerializer.createNodeForValue(doc, TAG_LANGUAGE, mSystemInfo.getLanguage()));
+
+ return moSerializer.serialize(doc);
+ }
+} \ No newline at end of file
diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/MoSerializer.java b/service/java/com/android/server/wifi/hotspot2/omadm/MoSerializer.java
new file mode 100644
index 000000000..f804fdeb9
--- /dev/null
+++ b/service/java/com/android/server/wifi/hotspot2/omadm/MoSerializer.java
@@ -0,0 +1,173 @@
+/*
+ * 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.util.Log;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+/**
+ * Provides serialization API for OMA DM Management Object.
+ */
+class MoSerializer {
+ static final String TAG = "MoSerializable";
+ static final String DM_VERSION = "1.2";
+ static final String TAG_MGMT_TREE = "MgmtTree";
+ static final String TAG_VERSION = "VerDTD";
+ static final String TAG_NODE = "Node";
+ static final String TAG_NODENAME = "NodeName";
+ static final String TAG_PATH = "Path";
+ static final String TAG_VALUE = "Value";
+ static final String TAG_RTPROPERTIES = "RTProperties";
+ static final String TAG_TYPE = "Type";
+ static final String TAG_DDF_NAME = "DDFName";
+ private DocumentBuilder mDbBuilder;
+
+ public MoSerializer() throws ParserConfigurationException {
+ mDbBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ }
+
+ /**
+ * Serializes the Management Object into a XML format.
+ *
+ * @return {@link String) that indicates the entire xml of {@link MoSerializer}},
+ * <code>null<code/> in case of failure.
+ */
+ String serialize(@NonNull Document doc) {
+ StringWriter writer = new StringWriter();
+ try {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.transform(new DOMSource(doc), new StreamResult(writer));
+ } catch (TransformerException e) {
+ e.printStackTrace();
+ return null;
+ }
+ return writer.toString();
+ }
+
+ /**
+ * Create new Document to make a XML document of OMA DM Management Object.
+ *
+ * @return new {@link Document}
+ */
+ Document createNewDocument() {
+ return mDbBuilder.newDocument();
+ }
+
+ /**
+ * Generates root Node starting a "MgmtTree".
+ *
+ * Expected output: <MgmtTree></MgmtTree>
+ * @param doc {@link Document} that indicates an entire xml document.
+ * @return {@link Element} for Root
+ */
+ Element createMgmtTree(@NonNull Document doc) {
+ // root element
+ Element rootElement = doc.createElement(TAG_MGMT_TREE);
+ doc.appendChild(rootElement);
+ return rootElement;
+ }
+
+ /**
+ * Generates DTD version Node.
+ *
+ * Expected output: <VerDTD>[value]</VerDTD>
+ * @param doc {@link Document} that indicates an entire xml document.
+ * @return {@link Element} for new Node
+ */
+ Element writeVersion(@NonNull Document doc) {
+ Element dtdElement = doc.createElement(TAG_VERSION);
+ dtdElement.appendChild(doc.createTextNode(DM_VERSION));
+ return dtdElement;
+ }
+
+ /**
+ * Generates Node having {@param nodeName}
+ *
+ * Expected output: <Node><NodeName>[nodeName]</NodeName></Node>
+ * @param doc {@link Document} that indicates an entire xml document.
+ * @param nodeName node name for new node.
+ * @return {@link Element} for new Node
+ */
+ Element createNode(@NonNull Document doc, @NonNull String nodeName) {
+ Element node = doc.createElement(TAG_NODE);
+ Element nameNode = doc.createElement(TAG_NODENAME);
+ nameNode.appendChild(doc.createTextNode(nodeName));
+ node.appendChild(nameNode);
+ return node;
+ }
+
+ /** Generates Node with the Unique Resource Name (URN).
+ *
+ * URN is encapsulated inside RTProperties node.
+ *
+ * Expected output: <RTProperties><Type><DDFName>[urn]</DDFName></Type></RTProperites>
+ * @param doc {@link Document} that indicates an entire xml document.
+ * @param urn The unique resource name
+ *
+ * @return {@link Element} for new Node
+ */
+ Element createNodeForUrn(@NonNull Document doc, @NonNull String urn) {
+ Element node = doc.createElement(TAG_RTPROPERTIES);
+ Element type = doc.createElement(TAG_TYPE);
+ Element ddfName = doc.createElement(TAG_DDF_NAME);
+ ddfName.appendChild(doc.createTextNode(urn));
+ type.appendChild(ddfName);
+ node.appendChild(type);
+ return node;
+ }
+
+ /**
+ * Generates for a node with a value.
+ *
+ * Expected output:
+ * <Node><NodeName>[name]</NodeName><Value>[value]</Value></Node>
+ * @param doc {@link Document} that indicates an entire xml document.
+ * @param name name of the node.
+ * @param value value of the node
+ *
+ * @return {@link Element} for new Node
+ */
+ Element createNodeForValue(@NonNull Document doc, @NonNull String name, @NonNull String value) {
+ Element node = doc.createElement(TAG_NODE);
+ Element nameNode = doc.createElement(TAG_NODENAME);
+ nameNode.appendChild(doc.createTextNode(name));
+ node.appendChild(nameNode);
+
+ Element valueNode = doc.createElement(TAG_VALUE);
+ valueNode.appendChild(doc.createTextNode(value));
+
+ node.appendChild(valueNode);
+ return node;
+ }
+} \ No newline at end of file