1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wifi.hotspot2.omadm; 18 19 import android.util.Log; 20 21 import com.android.server.wifi.hotspot2.SystemInfo; 22 23 import org.w3c.dom.Document; 24 import org.w3c.dom.Element; 25 26 import javax.xml.parsers.ParserConfigurationException; 27 28 import android.annotation.NonNull; 29 30 /** 31 * Provides serialization API for DevInfo MO (Management Object). 32 * 33 * Devinfo---|- DevId 34 * |- Man 35 * |- Mod 36 * |- Dmv 37 * |- Lang 38 */ 39 public class DevInfoMo { 40 public static final String TAG = "DevInfoMo"; 41 public static final String URN = "urn:oma:mo:oma-dm-devinfo:1.0"; 42 43 private static final String MO_NAME = "DevInfo"; 44 private static final String TAG_DEVID = "DevID"; 45 private static final String TAG_MANUFACTURE = "Man"; 46 private static final String TAG_MODEL = "Mod"; 47 private static final String TAG_DM_VERSION = "DmV"; 48 private static final String TAG_LANGUAGE = "Lang"; 49 50 /** 51 * Make a format of XML based on the DDF(Data Definition Format) of DevInfo MO. 52 * 53 * @return the XML that has format of OMA DM DevInfo Management Object, <code>null</code> in 54 * case of any failure. 55 */ serializeToXml(@onNull SystemInfo systemInfo)56 public static String serializeToXml(@NonNull SystemInfo systemInfo) { 57 MoSerializer moSerializer; 58 try { 59 moSerializer = new MoSerializer(); 60 } catch (ParserConfigurationException e) { 61 Log.e(TAG, "failed to create the MoSerializer: " + e); 62 return null; 63 } 64 // Create the XML document for DevInfoMo 65 Document doc = moSerializer.createNewDocument(); 66 Element rootElement = moSerializer.createMgmtTree(doc); 67 rootElement.appendChild(moSerializer.writeVersion(doc)); 68 Element moNode = moSerializer.createNode(doc, MO_NAME); 69 moNode.appendChild(moSerializer.createNodeForUrn(doc, URN)); 70 rootElement.appendChild(moNode); 71 rootElement.appendChild( 72 moSerializer.createNodeForValue(doc, TAG_DEVID, systemInfo.getDeviceId())); 73 74 rootElement.appendChild(moSerializer.createNodeForValue(doc, TAG_MANUFACTURE, 75 systemInfo.getDeviceManufacturer())); 76 rootElement.appendChild( 77 moSerializer.createNodeForValue(doc, TAG_MODEL, systemInfo.getDeviceModel())); 78 rootElement.appendChild( 79 moSerializer.createNodeForValue(doc, TAG_DM_VERSION, MoSerializer.DM_VERSION)); 80 rootElement.appendChild( 81 moSerializer.createNodeForValue(doc, TAG_LANGUAGE, systemInfo.getLanguage())); 82 83 return moSerializer.serialize(doc); 84 } 85 }