1 /* 2 * Copyright (C) 2014 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.omadm.service; 18 19 import android.util.Log; 20 21 final class NativeDM { 22 private static final String TAG = "NativeDM"; 23 24 private NativeDM() {} 25 26 static { 27 try { 28 logd("loading libdmengine.so"); 29 System.loadLibrary("dmengine"); 30 logd("loaded libdmengine.so"); 31 } catch (UnsatisfiedLinkError ule) { 32 loge("error: Could not load libdmengine.so", ule); 33 throw ule; 34 } 35 } 36 37 /** 38 * Initialize the native DM library. 39 * @return either {@link DMResult#SYNCML_DM_SUCCESS} or {@link DMResult#SYNCML_DM_FAIL} 40 */ 41 public static native int initialize(); 42 43 /** 44 * Initialize the native DM library. 45 * @return either {@link DMResult#SYNCML_DM_SUCCESS} or {@link DMResult#SYNCML_DM_FAIL} 46 */ 47 public static native int destroy(); 48 49 /** 50 * Start a DM client session. 51 * @param serverID the server ID to use 52 * @param sessionAgent the {@link DMSession} object to use 53 * @return either {@link DMResult#SYNCML_DM_SUCCESS} or a {@link DMResult} error code 54 */ 55 public static native int startClientSession(String serverID, DMSession sessionAgent); 56 57 /** 58 * Start a FOTA client session. The alert URI is {@code "./DevDetail/Ext/SystemUpdate"}. 59 * @param serverID the server ID to use 60 * @param alertStr the alert string to use 61 * @param sessionAgent the {@link DMSession} object to use 62 * @return either {@link DMResult#SYNCML_DM_SUCCESS} or a {@link DMResult} error code 63 */ 64 public static native int startFotaClientSession(String serverID, String alertStr, 65 DMSession sessionAgent); 66 67 /** 68 * Start a FOTA server session. 69 * @param serverID the server ID to use 70 * @param sessionID the session ID to use 71 * @param sessionAgent the {@link DMSession} object to use 72 * @return either {@link DMResult#SYNCML_DM_SUCCESS} or a {@link DMResult} error code 73 */ 74 public static native int startFotaServerSession(String serverID, int sessionID, 75 DMSession sessionAgent); 76 77 /** 78 * Start a FOTA notification session. 79 * @param result 80 * @param pkgURI 81 * @param alertType 82 * @param serverID 83 * @param correlator 84 * @param sessionAgent 85 * @return either {@link DMResult#SYNCML_DM_SUCCESS} or a {@link DMResult} error code 86 */ 87 public static native int startFotaNotifySession(String result, String pkgURI, 88 String alertType, String serverID, String correlator, DMSession sessionAgent); 89 90 /** 91 * 92 * @return 93 */ 94 public static native int cancelSession(); 95 96 /** 97 * 98 * @param pkg0 99 * @param dmtNotification 100 * @return 101 */ 102 public static native int parsePkg0(byte[] pkg0, DMPkg0Notification dmtNotification); 103 104 /** 105 * 106 * @param node 107 * @return 108 */ 109 public static native int createInterior(String node); 110 111 /** 112 * 113 * @param node 114 * @param value 115 * @return 116 */ 117 public static native int createLeaf(String node, String value); 118 119 /** 120 * 121 * @param node 122 * @param value 123 * @return 124 */ 125 public static native int createLeaf(String node, byte[] value); 126 127 /** 128 * 129 * @param node 130 * @return 131 */ 132 public static native int deleteNode(String node); 133 134 /** 135 * 136 * @param node 137 * @param value 138 * @return 139 */ 140 public static native String setStringNode(String node, String value); 141 142 /** 143 * 144 * @param node 145 * @param value 146 * @return 147 */ 148 public static native String createLeafInteger(String node, String value); 149 150 /** 151 * 152 * @param node 153 * @return 154 */ 155 public static native String getNodeInfo(String node); 156 157 /** 158 * 159 * @param node 160 * @param data 161 * @return 162 */ 163 public static native String executePlugin(String node, String data); 164 165 /** 166 * 167 * @param node 168 * @return 169 */ 170 public static native String dumpTree(String node); 171 172 /** 173 * 174 * @param wbxmlBuf 175 * @return 176 */ 177 public static native byte[] nativeWbxmlToXml(byte[] wbxmlBuf); 178 179 /** 180 * 181 * @param serverId 182 * @param fileName 183 * @param bBinary 184 * @param retCode 185 * @param session 186 * @return 187 */ 188 public static native byte[] processScript(String serverId, String fileName, boolean bBinary, 189 int retCode, DMSession session); 190 191 /** 192 * 193 * @param msgData 194 * @param bIsWbxml 195 * @param serverId 196 * @return 197 */ 198 public static native int processBootstrapScript(byte[] msgData, boolean bIsWbxml, 199 String serverId); 200 201 /** 202 * 203 * @param msgData 204 * @param bIsWbxml 205 * @return 206 */ 207 public static native String parseBootstrapServerId(byte[] msgData, boolean bIsWbxml); 208 209 /** 210 * Get the node type for a DM node. 211 * @param path the OMA DM path to use 212 * @return the DM node type 213 */ 214 public static native int getNodeType(String path); 215 216 /** 217 * Get the node value for a DM node. 218 * @param path the OMA DM path to use 219 * @return the DM node value, as a String 220 */ 221 public static native String getNodeValue(String path); 222 223 private static void logd(String msg) { 224 Log.d(TAG, msg); 225 } 226 227 private static void loge(String msg, Throwable tr) { 228 Log.e(TAG, msg, tr); 229 } 230 } 231