The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2006, The Android Open Source Project |
| 3 | ** |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 | ** |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 | ** |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 17 | #define DBUS_ADAPTER_IFACE BLUEZ_DBUS_BASE_IFC ".Adapter" |
| 18 | #define DBUS_DEVICE_IFACE BLUEZ_DBUS_BASE_IFC ".Device" |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 19 | #define DBUS_INPUT_IFACE BLUEZ_DBUS_BASE_IFC ".Input" |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 20 | #define DBUS_NETWORK_IFACE BLUEZ_DBUS_BASE_IFC ".Network" |
| 21 | #define DBUS_NETWORKSERVER_IFACE BLUEZ_DBUS_BASE_IFC ".NetworkServer" |
| 22 | |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 23 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 24 | #define LOG_TAG "BluetoothService.cpp" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | #include "android_bluetooth_common.h" |
| 27 | #include "android_runtime/AndroidRuntime.h" |
| 28 | #include "JNIHelp.h" |
| 29 | #include "jni.h" |
| 30 | #include "utils/Log.h" |
| 31 | #include "utils/misc.h" |
| 32 | |
| 33 | #include <ctype.h> |
| 34 | #include <stdio.h> |
| 35 | #include <string.h> |
| 36 | #include <stdlib.h> |
| 37 | #include <errno.h> |
| 38 | #include <unistd.h> |
| 39 | |
| 40 | #include <sys/socket.h> |
| 41 | #include <sys/ioctl.h> |
| 42 | #include <fcntl.h> |
| 43 | |
| 44 | #ifdef HAVE_BLUETOOTH |
| 45 | #include <dbus/dbus.h> |
| 46 | #include <bluedroid/bluetooth.h> |
| 47 | #endif |
| 48 | |
| 49 | #include <cutils/properties.h> |
| 50 | |
| 51 | namespace android { |
| 52 | |
Nick Pelly | 2b5be07 | 2009-03-31 14:42:33 -0700 | [diff] [blame] | 53 | #define BLUETOOTH_CLASS_ERROR 0xFF000000 |
Jaikumar Ganesh | 6d56b53 | 2009-08-24 17:11:11 -0700 | [diff] [blame] | 54 | #define PROPERTIES_NREFS 10 |
Nick Pelly | 2b5be07 | 2009-03-31 14:42:33 -0700 | [diff] [blame] | 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | #ifdef HAVE_BLUETOOTH |
| 57 | // We initialize these variables when we load class |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 58 | // android.server.BluetoothService |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | static jfieldID field_mNativeData; |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 60 | static jfieldID field_mEventLoop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | typedef struct { |
| 63 | JNIEnv *env; |
| 64 | DBusConnection *conn; |
| 65 | const char *adapter; // dbus object name of the local adapter |
| 66 | } native_data_t; |
| 67 | |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 68 | extern event_loop_native_data_t *get_EventLoop_native_data(JNIEnv *, |
| 69 | jobject); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 70 | extern DBusHandlerResult agent_event_filter(DBusConnection *conn, |
| 71 | DBusMessage *msg, |
| 72 | void *data); |
| 73 | void onCreatePairedDeviceResult(DBusMessage *msg, void *user, void *nat); |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 74 | void onDiscoverServicesResult(DBusMessage *msg, void *user, void *nat); |
| 75 | void onCreateDeviceResult(DBusMessage *msg, void *user, void *nat); |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 76 | void onInputDeviceConnectionResult(DBusMessage *msg, void *user, void *nat); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 77 | void onConnectPanResult(DBusMessage *msg, void *user, void *n); |
| 78 | void onPanDeviceConnectionResult(DBusMessage *msg, void *user, void *nat); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
| 81 | /** Get native data stored in the opaque (Java code maintained) pointer mNativeData |
| 82 | * Perform quick sanity check, if there are any problems return NULL |
| 83 | */ |
| 84 | static inline native_data_t * get_native_data(JNIEnv *env, jobject object) { |
| 85 | native_data_t *nat = |
| 86 | (native_data_t *)(env->GetIntField(object, field_mNativeData)); |
| 87 | if (nat == NULL || nat->conn == NULL) { |
| 88 | LOGE("Uninitialized native data\n"); |
| 89 | return NULL; |
| 90 | } |
| 91 | return nat; |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | static void classInitNative(JNIEnv* env, jclass clazz) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 96 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | #ifdef HAVE_BLUETOOTH |
| 98 | field_mNativeData = get_field(env, clazz, "mNativeData", "I"); |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 99 | field_mEventLoop = get_field(env, clazz, "mEventLoop", |
| 100 | "Landroid/server/BluetoothEventLoop;"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | #endif |
| 102 | } |
| 103 | |
| 104 | /* Returns true on success (even if adapter is present but disabled). |
| 105 | * Return false if dbus is down, or another serious error (out of memory) |
| 106 | */ |
| 107 | static bool initializeNativeDataNative(JNIEnv* env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 108 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | #ifdef HAVE_BLUETOOTH |
| 110 | native_data_t *nat = (native_data_t *)calloc(1, sizeof(native_data_t)); |
| 111 | if (NULL == nat) { |
| 112 | LOGE("%s: out of memory!", __FUNCTION__); |
| 113 | return false; |
| 114 | } |
| 115 | nat->env = env; |
| 116 | |
| 117 | env->SetIntField(object, field_mNativeData, (jint)nat); |
| 118 | DBusError err; |
| 119 | dbus_error_init(&err); |
| 120 | dbus_threads_init_default(); |
| 121 | nat->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); |
| 122 | if (dbus_error_is_set(&err)) { |
| 123 | LOGE("Could not get onto the system bus: %s", err.message); |
| 124 | dbus_error_free(&err); |
| 125 | return false; |
| 126 | } |
Nick Pelly | 9e0a195 | 2009-06-17 15:27:59 -0700 | [diff] [blame] | 127 | dbus_connection_set_exit_on_disconnect(nat->conn, FALSE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | #endif /*HAVE_BLUETOOTH*/ |
| 129 | return true; |
| 130 | } |
| 131 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 132 | static const char *get_adapter_path(JNIEnv* env, jobject object) { |
Jaikumar Ganesh | 82aea4a | 2009-06-09 23:23:20 -0700 | [diff] [blame] | 133 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 134 | event_loop_native_data_t *event_nat = |
| 135 | get_EventLoop_native_data(env, env->GetObjectField(object, |
| 136 | field_mEventLoop)); |
| 137 | if (event_nat == NULL) |
| 138 | return NULL; |
| 139 | return event_nat->adapter; |
Jaikumar Ganesh | 82aea4a | 2009-06-09 23:23:20 -0700 | [diff] [blame] | 140 | #else |
| 141 | return NULL; |
| 142 | #endif |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | // This function is called when the adapter is enabled. |
| 146 | static jboolean setupNativeDataNative(JNIEnv* env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 147 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 148 | #ifdef HAVE_BLUETOOTH |
| 149 | native_data_t *nat = |
| 150 | (native_data_t *)env->GetIntField(object, field_mNativeData); |
| 151 | event_loop_native_data_t *event_nat = |
| 152 | get_EventLoop_native_data(env, env->GetObjectField(object, |
| 153 | field_mEventLoop)); |
| 154 | // Register agent for remote devices. |
| 155 | const char *device_agent_path = "/android/bluetooth/remote_device_agent"; |
| 156 | static const DBusObjectPathVTable agent_vtable = { |
| 157 | NULL, agent_event_filter, NULL, NULL, NULL, NULL }; |
| 158 | |
| 159 | if (!dbus_connection_register_object_path(nat->conn, device_agent_path, |
| 160 | &agent_vtable, event_nat)) { |
| 161 | LOGE("%s: Can't register object path %s for remote device agent!", |
| 162 | __FUNCTION__, device_agent_path); |
| 163 | return JNI_FALSE; |
| 164 | } |
| 165 | #endif /*HAVE_BLUETOOTH*/ |
| 166 | return JNI_TRUE; |
| 167 | } |
| 168 | |
| 169 | static jboolean tearDownNativeDataNative(JNIEnv *env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 170 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 171 | #ifdef HAVE_BLUETOOTH |
| 172 | native_data_t *nat = |
| 173 | (native_data_t *)env->GetIntField(object, field_mNativeData); |
| 174 | if (nat != NULL) { |
| 175 | const char *device_agent_path = |
| 176 | "/android/bluetooth/remote_device_agent"; |
| 177 | dbus_connection_unregister_object_path (nat->conn, device_agent_path); |
| 178 | } |
| 179 | #endif /*HAVE_BLUETOOTH*/ |
| 180 | return JNI_TRUE; |
| 181 | } |
| 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | static void cleanupNativeDataNative(JNIEnv* env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 184 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | #ifdef HAVE_BLUETOOTH |
| 186 | native_data_t *nat = |
| 187 | (native_data_t *)env->GetIntField(object, field_mNativeData); |
| 188 | if (nat) { |
| 189 | free(nat); |
| 190 | nat = NULL; |
| 191 | } |
| 192 | #endif |
| 193 | } |
| 194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | static jstring getAdapterPathNative(JNIEnv *env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 196 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | #ifdef HAVE_BLUETOOTH |
| 198 | native_data_t *nat = get_native_data(env, object); |
| 199 | if (nat) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 200 | return (env->NewStringUTF(get_adapter_path(env, object))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
| 202 | #endif |
| 203 | return NULL; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | static jboolean startDiscoveryNative(JNIEnv *env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 208 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | #ifdef HAVE_BLUETOOTH |
| 210 | DBusMessage *msg = NULL; |
| 211 | DBusMessage *reply = NULL; |
| 212 | DBusError err; |
| 213 | const char *name; |
| 214 | jboolean ret = JNI_FALSE; |
| 215 | |
| 216 | native_data_t *nat = get_native_data(env, object); |
| 217 | if (nat == NULL) { |
| 218 | goto done; |
| 219 | } |
| 220 | |
| 221 | dbus_error_init(&err); |
| 222 | |
| 223 | /* Compose the command */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 224 | msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, |
| 225 | get_adapter_path(env, object), |
| 226 | DBUS_ADAPTER_IFACE, "StartDiscovery"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
| 228 | if (msg == NULL) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 229 | if (dbus_error_is_set(&err)) { |
| 230 | LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg); |
| 231 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | goto done; |
| 233 | } |
| 234 | |
| 235 | /* Send the command. */ |
| 236 | reply = dbus_connection_send_with_reply_and_block(nat->conn, msg, -1, &err); |
| 237 | if (dbus_error_is_set(&err)) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 238 | LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg); |
| 239 | ret = JNI_FALSE; |
| 240 | goto done; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | ret = JNI_TRUE; |
| 244 | done: |
| 245 | if (reply) dbus_message_unref(reply); |
| 246 | if (msg) dbus_message_unref(msg); |
| 247 | return ret; |
| 248 | #else |
| 249 | return JNI_FALSE; |
| 250 | #endif |
| 251 | } |
| 252 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 253 | static void stopDiscoveryNative(JNIEnv *env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 254 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | #ifdef HAVE_BLUETOOTH |
| 256 | DBusMessage *msg = NULL; |
| 257 | DBusMessage *reply = NULL; |
| 258 | DBusError err; |
| 259 | const char *name; |
| 260 | jstring ret; |
| 261 | native_data_t *nat; |
| 262 | |
| 263 | dbus_error_init(&err); |
| 264 | |
| 265 | nat = get_native_data(env, object); |
| 266 | if (nat == NULL) { |
| 267 | goto done; |
| 268 | } |
| 269 | |
| 270 | /* Compose the command */ |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 271 | msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, |
| 272 | get_adapter_path(env, object), |
| 273 | DBUS_ADAPTER_IFACE, "StopDiscovery"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | if (msg == NULL) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 275 | if (dbus_error_is_set(&err)) |
| 276 | LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | goto done; |
| 278 | } |
| 279 | |
| 280 | /* Send the command. */ |
| 281 | reply = dbus_connection_send_with_reply_and_block(nat->conn, msg, -1, &err); |
| 282 | if (dbus_error_is_set(&err)) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 283 | if(strncmp(err.name, BLUEZ_DBUS_BASE_IFC ".Error.NotAuthorized", |
| 284 | strlen(BLUEZ_DBUS_BASE_IFC ".Error.NotAuthorized")) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | // hcid sends this if there is no active discovery to cancel |
| 286 | LOGV("%s: There was no active discovery to cancel", __FUNCTION__); |
| 287 | dbus_error_free(&err); |
| 288 | } else { |
| 289 | LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | done: |
| 294 | if (msg) dbus_message_unref(msg); |
| 295 | if (reply) dbus_message_unref(reply); |
| 296 | #endif |
| 297 | } |
| 298 | |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 299 | static jbyteArray readAdapterOutOfBandDataNative(JNIEnv *env, jobject object) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 300 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 301 | #ifdef HAVE_BLUETOOTH |
| 302 | native_data_t *nat = get_native_data(env, object); |
| 303 | DBusError err; |
| 304 | jbyte *hash, *randomizer; |
| 305 | jbyteArray byteArray = NULL; |
| 306 | int hash_len, r_len; |
| 307 | if (nat) { |
| 308 | DBusMessage *reply = dbus_func_args(env, nat->conn, |
| 309 | get_adapter_path(env, object), |
| 310 | DBUS_ADAPTER_IFACE, "ReadLocalOutOfBandData", |
| 311 | DBUS_TYPE_INVALID); |
| 312 | if (!reply) return NULL; |
| 313 | |
| 314 | dbus_error_init(&err); |
| 315 | if (dbus_message_get_args(reply, &err, |
| 316 | DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &hash, &hash_len, |
| 317 | DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &randomizer, &r_len, |
| 318 | DBUS_TYPE_INVALID)) { |
| 319 | if (hash_len == 16 && r_len == 16) { |
| 320 | byteArray = env->NewByteArray(32); |
| 321 | if (byteArray) { |
| 322 | env->SetByteArrayRegion(byteArray, 0, 16, hash); |
| 323 | env->SetByteArrayRegion(byteArray, 16, 16, randomizer); |
| 324 | } |
| 325 | } else { |
| 326 | LOGE("readAdapterOutOfBandDataNative: Hash len = %d, R len = %d", |
| 327 | hash_len, r_len); |
| 328 | } |
| 329 | } else { |
| 330 | LOG_AND_FREE_DBUS_ERROR(&err); |
| 331 | } |
| 332 | dbus_message_unref(reply); |
| 333 | return byteArray; |
| 334 | } |
| 335 | #endif |
| 336 | return NULL; |
| 337 | } |
| 338 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 339 | static jboolean createPairedDeviceNative(JNIEnv *env, jobject object, |
| 340 | jstring address, jint timeout_ms) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 341 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | #ifdef HAVE_BLUETOOTH |
| 343 | native_data_t *nat = get_native_data(env, object); |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 344 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 345 | struct event_loop_native_data_t *eventLoopNat = |
| 346 | get_EventLoop_native_data(env, eventLoop); |
| 347 | |
| 348 | if (nat && eventLoopNat) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | const char *c_address = env->GetStringUTFChars(address, NULL); |
| 350 | LOGV("... address = %s", c_address); |
| 351 | char *context_address = (char *)calloc(BTADDR_SIZE, sizeof(char)); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 352 | const char *capabilities = "DisplayYesNo"; |
| 353 | const char *agent_path = "/android/bluetooth/remote_device_agent"; |
| 354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | strlcpy(context_address, c_address, BTADDR_SIZE); // for callback |
| 356 | bool ret = dbus_func_args_async(env, nat->conn, (int)timeout_ms, |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 357 | onCreatePairedDeviceResult, // callback |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 358 | context_address, |
| 359 | eventLoopNat, |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 360 | get_adapter_path(env, object), |
| 361 | DBUS_ADAPTER_IFACE, |
| 362 | "CreatePairedDevice", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | DBUS_TYPE_STRING, &c_address, |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 364 | DBUS_TYPE_OBJECT_PATH, &agent_path, |
| 365 | DBUS_TYPE_STRING, &capabilities, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | DBUS_TYPE_INVALID); |
| 367 | env->ReleaseStringUTFChars(address, c_address); |
| 368 | return ret ? JNI_TRUE : JNI_FALSE; |
| 369 | |
| 370 | } |
| 371 | #endif |
| 372 | return JNI_FALSE; |
| 373 | } |
| 374 | |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 375 | static jboolean createPairedDeviceOutOfBandNative(JNIEnv *env, jobject object, |
| 376 | jstring address, jint timeout_ms) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 377 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 378 | #ifdef HAVE_BLUETOOTH |
| 379 | native_data_t *nat = get_native_data(env, object); |
| 380 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 381 | struct event_loop_native_data_t *eventLoopNat = |
| 382 | get_EventLoop_native_data(env, eventLoop); |
| 383 | |
| 384 | if (nat && eventLoopNat) { |
| 385 | const char *c_address = env->GetStringUTFChars(address, NULL); |
| 386 | LOGV("... address = %s", c_address); |
| 387 | char *context_address = (char *)calloc(BTADDR_SIZE, sizeof(char)); |
| 388 | const char *capabilities = "DisplayYesNo"; |
| 389 | const char *agent_path = "/android/bluetooth/remote_device_agent"; |
| 390 | |
| 391 | strlcpy(context_address, c_address, BTADDR_SIZE); // for callback |
| 392 | bool ret = dbus_func_args_async(env, nat->conn, (int)timeout_ms, |
| 393 | onCreatePairedDeviceResult, // callback |
| 394 | context_address, |
| 395 | eventLoopNat, |
| 396 | get_adapter_path(env, object), |
| 397 | DBUS_ADAPTER_IFACE, |
| 398 | "CreatePairedDeviceOutOfBand", |
| 399 | DBUS_TYPE_STRING, &c_address, |
| 400 | DBUS_TYPE_OBJECT_PATH, &agent_path, |
| 401 | DBUS_TYPE_STRING, &capabilities, |
| 402 | DBUS_TYPE_INVALID); |
| 403 | env->ReleaseStringUTFChars(address, c_address); |
| 404 | return ret ? JNI_TRUE : JNI_FALSE; |
| 405 | } |
| 406 | #endif |
| 407 | return JNI_FALSE; |
| 408 | } |
| 409 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 410 | static jint getDeviceServiceChannelNative(JNIEnv *env, jobject object, |
| 411 | jstring path, |
| 412 | jstring pattern, jint attr_id) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 414 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | native_data_t *nat = get_native_data(env, object); |
Robert Greenwalt | 28d139f | 2009-04-02 22:41:08 -0700 | [diff] [blame] | 416 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 417 | struct event_loop_native_data_t *eventLoopNat = |
| 418 | get_EventLoop_native_data(env, eventLoop); |
| 419 | if (nat && eventLoopNat) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 420 | const char *c_pattern = env->GetStringUTFChars(pattern, NULL); |
| 421 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 422 | LOGV("... pattern = %s", c_pattern); |
| 423 | LOGV("... attr_id = %#X", attr_id); |
| 424 | DBusMessage *reply = |
| 425 | dbus_func_args(env, nat->conn, c_path, |
| 426 | DBUS_DEVICE_IFACE, "GetServiceAttributeValue", |
| 427 | DBUS_TYPE_STRING, &c_pattern, |
| 428 | DBUS_TYPE_UINT16, &attr_id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | DBUS_TYPE_INVALID); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 430 | env->ReleaseStringUTFChars(pattern, c_pattern); |
| 431 | env->ReleaseStringUTFChars(path, c_path); |
| 432 | return reply ? dbus_returns_int32(env, reply) : -1; |
| 433 | } |
| 434 | #endif |
| 435 | return -1; |
| 436 | } |
| 437 | |
| 438 | static jboolean cancelDeviceCreationNative(JNIEnv *env, jobject object, |
| 439 | jstring address) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 440 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 441 | jboolean result = JNI_FALSE; |
| 442 | #ifdef HAVE_BLUETOOTH |
| 443 | native_data_t *nat = get_native_data(env, object); |
| 444 | if (nat) { |
| 445 | const char *c_address = env->GetStringUTFChars(address, NULL); |
| 446 | DBusError err; |
| 447 | dbus_error_init(&err); |
| 448 | LOGV("... address = %s", c_address); |
| 449 | DBusMessage *reply = |
| 450 | dbus_func_args_timeout(env, nat->conn, -1, |
| 451 | get_adapter_path(env, object), |
| 452 | DBUS_ADAPTER_IFACE, "CancelDeviceCreation", |
| 453 | DBUS_TYPE_STRING, &c_address, |
| 454 | DBUS_TYPE_INVALID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | env->ReleaseStringUTFChars(address, c_address); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 456 | if (!reply) { |
| 457 | if (dbus_error_is_set(&err)) { |
| 458 | LOG_AND_FREE_DBUS_ERROR(&err); |
| 459 | } else |
| 460 | LOGE("DBus reply is NULL in function %s", __FUNCTION__); |
| 461 | return JNI_FALSE; |
| 462 | } else { |
| 463 | result = JNI_TRUE; |
| 464 | } |
| 465 | dbus_message_unref(reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | } |
| 467 | #endif |
| 468 | return JNI_FALSE; |
| 469 | } |
| 470 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 471 | static jboolean removeDeviceNative(JNIEnv *env, jobject object, jstring object_path) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 472 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 473 | #ifdef HAVE_BLUETOOTH |
| 474 | native_data_t *nat = get_native_data(env, object); |
| 475 | if (nat) { |
| 476 | const char *c_object_path = env->GetStringUTFChars(object_path, NULL); |
Jaikumar Ganesh | 995ae82 | 2009-09-20 11:25:09 -0700 | [diff] [blame] | 477 | bool ret = dbus_func_args_async(env, nat->conn, -1, |
| 478 | NULL, |
| 479 | NULL, |
| 480 | NULL, |
| 481 | get_adapter_path(env, object), |
| 482 | DBUS_ADAPTER_IFACE, |
| 483 | "RemoveDevice", |
| 484 | DBUS_TYPE_OBJECT_PATH, &c_object_path, |
| 485 | DBUS_TYPE_INVALID); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 486 | env->ReleaseStringUTFChars(object_path, c_object_path); |
Jaikumar Ganesh | 995ae82 | 2009-09-20 11:25:09 -0700 | [diff] [blame] | 487 | return ret ? JNI_TRUE : JNI_FALSE; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 488 | } |
| 489 | #endif |
Jaikumar Ganesh | 995ae82 | 2009-09-20 11:25:09 -0700 | [diff] [blame] | 490 | return JNI_FALSE; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 491 | } |
| 492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | static jint enableNative(JNIEnv *env, jobject object) { |
| 494 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 495 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | return bt_enable(); |
| 497 | #endif |
| 498 | return -1; |
| 499 | } |
| 500 | |
| 501 | static jint disableNative(JNIEnv *env, jobject object) { |
| 502 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 503 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | return bt_disable(); |
| 505 | #endif |
| 506 | return -1; |
| 507 | } |
| 508 | |
| 509 | static jint isEnabledNative(JNIEnv *env, jobject object) { |
| 510 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 511 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | return bt_is_enabled(); |
| 513 | #endif |
| 514 | return -1; |
| 515 | } |
| 516 | |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 517 | static jboolean setPairingConfirmationNative(JNIEnv *env, jobject object, |
| 518 | jstring address, bool confirm, |
| 519 | int nativeData) { |
| 520 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 521 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 522 | native_data_t *nat = get_native_data(env, object); |
| 523 | if (nat) { |
| 524 | DBusMessage *msg = (DBusMessage *)nativeData; |
| 525 | DBusMessage *reply; |
| 526 | if (confirm) { |
| 527 | reply = dbus_message_new_method_return(msg); |
| 528 | } else { |
| 529 | reply = dbus_message_new_error(msg, |
| 530 | "org.bluez.Error.Rejected", "User rejected confirmation"); |
| 531 | } |
| 532 | |
| 533 | if (!reply) { |
Jaikumar Ganesh | 32d8571 | 2009-09-10 22:00:05 -0700 | [diff] [blame] | 534 | LOGE("%s: Cannot create message reply to RequestPasskeyConfirmation or" |
| 535 | "RequestPairingConsent to D-Bus\n", __FUNCTION__); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 536 | dbus_message_unref(msg); |
| 537 | return JNI_FALSE; |
| 538 | } |
| 539 | |
| 540 | dbus_connection_send(nat->conn, reply, NULL); |
| 541 | dbus_message_unref(msg); |
| 542 | dbus_message_unref(reply); |
| 543 | return JNI_TRUE; |
| 544 | } |
| 545 | #endif |
| 546 | return JNI_FALSE; |
| 547 | } |
| 548 | |
| 549 | static jboolean setPasskeyNative(JNIEnv *env, jobject object, jstring address, |
| 550 | int passkey, int nativeData) { |
| 551 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 552 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 553 | native_data_t *nat = get_native_data(env, object); |
| 554 | if (nat) { |
| 555 | DBusMessage *msg = (DBusMessage *)nativeData; |
| 556 | DBusMessage *reply = dbus_message_new_method_return(msg); |
| 557 | if (!reply) { |
| 558 | LOGE("%s: Cannot create message reply to return Passkey code to " |
| 559 | "D-Bus\n", __FUNCTION__); |
| 560 | dbus_message_unref(msg); |
| 561 | return JNI_FALSE; |
| 562 | } |
| 563 | |
| 564 | dbus_message_append_args(reply, DBUS_TYPE_UINT32, (uint32_t *)&passkey, |
| 565 | DBUS_TYPE_INVALID); |
| 566 | |
| 567 | dbus_connection_send(nat->conn, reply, NULL); |
| 568 | dbus_message_unref(msg); |
| 569 | dbus_message_unref(reply); |
| 570 | return JNI_TRUE; |
| 571 | } |
| 572 | #endif |
| 573 | return JNI_FALSE; |
| 574 | } |
| 575 | |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 576 | static jboolean setRemoteOutOfBandDataNative(JNIEnv *env, jobject object, jstring address, |
| 577 | jbyteArray hash, jbyteArray randomizer, int nativeData) { |
| 578 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 579 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 580 | native_data_t *nat = get_native_data(env, object); |
| 581 | if (nat) { |
| 582 | DBusMessage *msg = (DBusMessage *)nativeData; |
| 583 | DBusMessage *reply = dbus_message_new_method_return(msg); |
| 584 | jbyte *h_ptr = env->GetByteArrayElements(hash, NULL); |
| 585 | jbyte *r_ptr = env->GetByteArrayElements(randomizer, NULL); |
| 586 | if (!reply) { |
| 587 | LOGE("%s: Cannot create message reply to return remote OOB data to " |
| 588 | "D-Bus\n", __FUNCTION__); |
| 589 | dbus_message_unref(msg); |
| 590 | return JNI_FALSE; |
| 591 | } |
| 592 | |
| 593 | dbus_message_append_args(reply, |
| 594 | DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &h_ptr, 16, |
| 595 | DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &r_ptr, 16, |
| 596 | DBUS_TYPE_INVALID); |
| 597 | |
| 598 | env->ReleaseByteArrayElements(hash, h_ptr, 0); |
| 599 | env->ReleaseByteArrayElements(randomizer, r_ptr, 0); |
| 600 | |
| 601 | dbus_connection_send(nat->conn, reply, NULL); |
| 602 | dbus_message_unref(msg); |
| 603 | dbus_message_unref(reply); |
| 604 | return JNI_TRUE; |
| 605 | } |
| 606 | #endif |
| 607 | return JNI_FALSE; |
| 608 | } |
| 609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | static jboolean setPinNative(JNIEnv *env, jobject object, jstring address, |
| 611 | jstring pin, int nativeData) { |
| 612 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 613 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | native_data_t *nat = get_native_data(env, object); |
| 615 | if (nat) { |
| 616 | DBusMessage *msg = (DBusMessage *)nativeData; |
| 617 | DBusMessage *reply = dbus_message_new_method_return(msg); |
| 618 | if (!reply) { |
| 619 | LOGE("%s: Cannot create message reply to return PIN code to " |
| 620 | "D-Bus\n", __FUNCTION__); |
| 621 | dbus_message_unref(msg); |
| 622 | return JNI_FALSE; |
| 623 | } |
| 624 | |
| 625 | const char *c_pin = env->GetStringUTFChars(pin, NULL); |
| 626 | |
| 627 | dbus_message_append_args(reply, DBUS_TYPE_STRING, &c_pin, |
| 628 | DBUS_TYPE_INVALID); |
| 629 | |
| 630 | dbus_connection_send(nat->conn, reply, NULL); |
| 631 | dbus_message_unref(msg); |
| 632 | dbus_message_unref(reply); |
| 633 | env->ReleaseStringUTFChars(pin, c_pin); |
| 634 | return JNI_TRUE; |
| 635 | } |
| 636 | #endif |
| 637 | return JNI_FALSE; |
| 638 | } |
| 639 | |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 640 | static jboolean cancelPairingUserInputNative(JNIEnv *env, jobject object, |
| 641 | jstring address, int nativeData) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 643 | LOGV("%s", __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | native_data_t *nat = get_native_data(env, object); |
| 645 | if (nat) { |
| 646 | DBusMessage *msg = (DBusMessage *)nativeData; |
| 647 | DBusMessage *reply = dbus_message_new_error(msg, |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 648 | "org.bluez.Error.Canceled", "Pairing User Input was canceled"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | if (!reply) { |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 650 | LOGE("%s: Cannot create message reply to return cancelUserInput to" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | "D-BUS\n", __FUNCTION__); |
| 652 | dbus_message_unref(msg); |
| 653 | return JNI_FALSE; |
| 654 | } |
| 655 | |
| 656 | dbus_connection_send(nat->conn, reply, NULL); |
| 657 | dbus_message_unref(msg); |
| 658 | dbus_message_unref(reply); |
| 659 | return JNI_TRUE; |
| 660 | } |
| 661 | #endif |
| 662 | return JNI_FALSE; |
| 663 | } |
| 664 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 665 | static jobjectArray getDevicePropertiesNative(JNIEnv *env, jobject object, |
| 666 | jstring path) |
| 667 | { |
| 668 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 669 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 670 | native_data_t *nat = get_native_data(env, object); |
| 671 | if (nat) { |
| 672 | DBusMessage *msg, *reply; |
| 673 | DBusError err; |
| 674 | dbus_error_init(&err); |
| 675 | |
| 676 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 677 | reply = dbus_func_args_timeout(env, |
| 678 | nat->conn, -1, c_path, |
| 679 | DBUS_DEVICE_IFACE, "GetProperties", |
| 680 | DBUS_TYPE_INVALID); |
| 681 | env->ReleaseStringUTFChars(path, c_path); |
| 682 | |
| 683 | if (!reply) { |
| 684 | if (dbus_error_is_set(&err)) { |
| 685 | LOG_AND_FREE_DBUS_ERROR(&err); |
| 686 | } else |
| 687 | LOGE("DBus reply is NULL in function %s", __FUNCTION__); |
| 688 | return NULL; |
| 689 | } |
Jaikumar Ganesh | 6d56b53 | 2009-08-24 17:11:11 -0700 | [diff] [blame] | 690 | env->PushLocalFrame(PROPERTIES_NREFS); |
| 691 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 692 | DBusMessageIter iter; |
| 693 | jobjectArray str_array = NULL; |
| 694 | if (dbus_message_iter_init(reply, &iter)) |
| 695 | str_array = parse_remote_device_properties(env, &iter); |
| 696 | dbus_message_unref(reply); |
Jaikumar Ganesh | 6d56b53 | 2009-08-24 17:11:11 -0700 | [diff] [blame] | 697 | |
| 698 | env->PopLocalFrame(NULL); |
| 699 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 700 | return str_array; |
| 701 | } |
| 702 | #endif |
| 703 | return NULL; |
| 704 | } |
| 705 | |
| 706 | static jobjectArray getAdapterPropertiesNative(JNIEnv *env, jobject object) { |
| 707 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 708 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 709 | native_data_t *nat = get_native_data(env, object); |
| 710 | if (nat) { |
| 711 | DBusMessage *msg, *reply; |
| 712 | DBusError err; |
| 713 | dbus_error_init(&err); |
| 714 | |
| 715 | reply = dbus_func_args_timeout(env, |
| 716 | nat->conn, -1, get_adapter_path(env, object), |
| 717 | DBUS_ADAPTER_IFACE, "GetProperties", |
| 718 | DBUS_TYPE_INVALID); |
| 719 | if (!reply) { |
| 720 | if (dbus_error_is_set(&err)) { |
| 721 | LOG_AND_FREE_DBUS_ERROR(&err); |
| 722 | } else |
| 723 | LOGE("DBus reply is NULL in function %s", __FUNCTION__); |
| 724 | return NULL; |
| 725 | } |
Jaikumar Ganesh | 6d56b53 | 2009-08-24 17:11:11 -0700 | [diff] [blame] | 726 | env->PushLocalFrame(PROPERTIES_NREFS); |
| 727 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 728 | DBusMessageIter iter; |
| 729 | jobjectArray str_array = NULL; |
| 730 | if (dbus_message_iter_init(reply, &iter)) |
| 731 | str_array = parse_adapter_properties(env, &iter); |
| 732 | dbus_message_unref(reply); |
Jaikumar Ganesh | 6d56b53 | 2009-08-24 17:11:11 -0700 | [diff] [blame] | 733 | |
| 734 | env->PopLocalFrame(NULL); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 735 | return str_array; |
| 736 | } |
| 737 | #endif |
| 738 | return NULL; |
| 739 | } |
| 740 | |
| 741 | static jboolean setAdapterPropertyNative(JNIEnv *env, jobject object, jstring key, |
| 742 | void *value, jint type) { |
| 743 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 744 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 745 | native_data_t *nat = get_native_data(env, object); |
| 746 | if (nat) { |
Jaikumar Ganesh | ff7db40 | 2010-10-25 16:25:52 -0700 | [diff] [blame] | 747 | DBusMessage *msg; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 748 | DBusMessageIter iter; |
Jaikumar Ganesh | ff7db40 | 2010-10-25 16:25:52 -0700 | [diff] [blame] | 749 | dbus_bool_t reply = JNI_FALSE; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 750 | const char *c_key = env->GetStringUTFChars(key, NULL); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 751 | |
| 752 | msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, |
| 753 | get_adapter_path(env, object), |
| 754 | DBUS_ADAPTER_IFACE, "SetProperty"); |
| 755 | if (!msg) { |
| 756 | LOGE("%s: Can't allocate new method call for GetProperties!", |
| 757 | __FUNCTION__); |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 758 | env->ReleaseStringUTFChars(key, c_key); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 759 | return JNI_FALSE; |
| 760 | } |
| 761 | |
| 762 | dbus_message_append_args(msg, DBUS_TYPE_STRING, &c_key, DBUS_TYPE_INVALID); |
| 763 | dbus_message_iter_init_append(msg, &iter); |
| 764 | append_variant(&iter, type, value); |
| 765 | |
Jaikumar Ganesh | ff7db40 | 2010-10-25 16:25:52 -0700 | [diff] [blame] | 766 | // Asynchronous call - the callbacks come via propertyChange |
| 767 | reply = dbus_connection_send_with_reply(nat->conn, msg, NULL, -1); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 768 | dbus_message_unref(msg); |
| 769 | |
| 770 | env->ReleaseStringUTFChars(key, c_key); |
Jaikumar Ganesh | ff7db40 | 2010-10-25 16:25:52 -0700 | [diff] [blame] | 771 | return reply ? JNI_TRUE : JNI_FALSE; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 772 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 773 | } |
| 774 | #endif |
| 775 | return JNI_FALSE; |
| 776 | } |
| 777 | |
| 778 | static jboolean setAdapterPropertyStringNative(JNIEnv *env, jobject object, jstring key, |
| 779 | jstring value) { |
Jaikumar Ganesh | d461349 | 2009-06-09 23:32:42 -0700 | [diff] [blame] | 780 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 781 | const char *c_value = env->GetStringUTFChars(value, NULL); |
| 782 | jboolean ret = setAdapterPropertyNative(env, object, key, (void *)&c_value, DBUS_TYPE_STRING); |
| 783 | env->ReleaseStringUTFChars(value, (char *)c_value); |
| 784 | return ret; |
Jaikumar Ganesh | d461349 | 2009-06-09 23:32:42 -0700 | [diff] [blame] | 785 | #else |
| 786 | return JNI_FALSE; |
| 787 | #endif |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | static jboolean setAdapterPropertyIntegerNative(JNIEnv *env, jobject object, jstring key, |
| 791 | jint value) { |
Jaikumar Ganesh | d461349 | 2009-06-09 23:32:42 -0700 | [diff] [blame] | 792 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 793 | return setAdapterPropertyNative(env, object, key, (void *)&value, DBUS_TYPE_UINT32); |
Jaikumar Ganesh | d461349 | 2009-06-09 23:32:42 -0700 | [diff] [blame] | 794 | #else |
| 795 | return JNI_FALSE; |
| 796 | #endif |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static jboolean setAdapterPropertyBooleanNative(JNIEnv *env, jobject object, jstring key, |
| 800 | jint value) { |
Jaikumar Ganesh | d461349 | 2009-06-09 23:32:42 -0700 | [diff] [blame] | 801 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 802 | return setAdapterPropertyNative(env, object, key, (void *)&value, DBUS_TYPE_BOOLEAN); |
Jaikumar Ganesh | d461349 | 2009-06-09 23:32:42 -0700 | [diff] [blame] | 803 | #else |
| 804 | return JNI_FALSE; |
| 805 | #endif |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 808 | static jboolean setDevicePropertyNative(JNIEnv *env, jobject object, jstring path, |
| 809 | jstring key, void *value, jint type) { |
| 810 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 811 | LOGV("%s", __FUNCTION__); |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 812 | native_data_t *nat = get_native_data(env, object); |
| 813 | if (nat) { |
| 814 | DBusMessage *reply, *msg; |
| 815 | DBusMessageIter iter; |
| 816 | DBusError err; |
| 817 | |
| 818 | const char *c_key = env->GetStringUTFChars(key, NULL); |
| 819 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 820 | |
| 821 | dbus_error_init(&err); |
| 822 | msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, |
| 823 | c_path, DBUS_DEVICE_IFACE, "SetProperty"); |
| 824 | if (!msg) { |
| 825 | LOGE("%s: Can't allocate new method call for device SetProperty!", __FUNCTION__); |
| 826 | env->ReleaseStringUTFChars(key, c_key); |
| 827 | env->ReleaseStringUTFChars(path, c_path); |
| 828 | return JNI_FALSE; |
| 829 | } |
| 830 | |
| 831 | dbus_message_append_args(msg, DBUS_TYPE_STRING, &c_key, DBUS_TYPE_INVALID); |
| 832 | dbus_message_iter_init_append(msg, &iter); |
| 833 | append_variant(&iter, type, value); |
| 834 | |
| 835 | reply = dbus_connection_send_with_reply_and_block(nat->conn, msg, -1, &err); |
| 836 | dbus_message_unref(msg); |
| 837 | |
| 838 | env->ReleaseStringUTFChars(key, c_key); |
| 839 | env->ReleaseStringUTFChars(path, c_path); |
| 840 | if (!reply) { |
| 841 | if (dbus_error_is_set(&err)) { |
| 842 | LOG_AND_FREE_DBUS_ERROR(&err); |
| 843 | } else |
| 844 | LOGE("DBus reply is NULL in function %s", __FUNCTION__); |
| 845 | return JNI_FALSE; |
| 846 | } |
| 847 | return JNI_TRUE; |
| 848 | } |
| 849 | #endif |
| 850 | return JNI_FALSE; |
| 851 | } |
| 852 | |
| 853 | static jboolean setDevicePropertyBooleanNative(JNIEnv *env, jobject object, |
| 854 | jstring path, jstring key, jint value) { |
| 855 | #ifdef HAVE_BLUETOOTH |
| 856 | return setDevicePropertyNative(env, object, path, key, |
| 857 | (void *)&value, DBUS_TYPE_BOOLEAN); |
| 858 | #else |
| 859 | return JNI_FALSE; |
| 860 | #endif |
| 861 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 862 | |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 863 | |
| 864 | static jboolean createDeviceNative(JNIEnv *env, jobject object, |
| 865 | jstring address) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 866 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 867 | #ifdef HAVE_BLUETOOTH |
| 868 | native_data_t *nat = get_native_data(env, object); |
| 869 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 870 | struct event_loop_native_data_t *eventLoopNat = |
| 871 | get_EventLoop_native_data(env, eventLoop); |
| 872 | |
| 873 | if (nat && eventLoopNat) { |
| 874 | const char *c_address = env->GetStringUTFChars(address, NULL); |
| 875 | LOGV("... address = %s", c_address); |
| 876 | char *context_address = (char *)calloc(BTADDR_SIZE, sizeof(char)); |
| 877 | strlcpy(context_address, c_address, BTADDR_SIZE); // for callback |
| 878 | |
| 879 | bool ret = dbus_func_args_async(env, nat->conn, -1, |
| 880 | onCreateDeviceResult, |
| 881 | context_address, |
| 882 | eventLoopNat, |
| 883 | get_adapter_path(env, object), |
| 884 | DBUS_ADAPTER_IFACE, |
| 885 | "CreateDevice", |
| 886 | DBUS_TYPE_STRING, &c_address, |
| 887 | DBUS_TYPE_INVALID); |
| 888 | env->ReleaseStringUTFChars(address, c_address); |
| 889 | return ret ? JNI_TRUE : JNI_FALSE; |
| 890 | } |
| 891 | #endif |
| 892 | return JNI_FALSE; |
| 893 | } |
| 894 | |
| 895 | static jboolean discoverServicesNative(JNIEnv *env, jobject object, |
| 896 | jstring path, jstring pattern) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 897 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 898 | #ifdef HAVE_BLUETOOTH |
| 899 | native_data_t *nat = get_native_data(env, object); |
| 900 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 901 | struct event_loop_native_data_t *eventLoopNat = |
| 902 | get_EventLoop_native_data(env, eventLoop); |
| 903 | |
| 904 | if (nat && eventLoopNat) { |
| 905 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 906 | const char *c_pattern = env->GetStringUTFChars(pattern, NULL); |
| 907 | int len = env->GetStringLength(path) + 1; |
| 908 | char *context_path = (char *)calloc(len, sizeof(char)); |
| 909 | strlcpy(context_path, c_path, len); // for callback |
| 910 | |
| 911 | LOGV("... Object Path = %s", c_path); |
| 912 | LOGV("... Pattern = %s, strlen = %d", c_pattern, strlen(c_pattern)); |
| 913 | |
| 914 | bool ret = dbus_func_args_async(env, nat->conn, -1, |
| 915 | onDiscoverServicesResult, |
| 916 | context_path, |
| 917 | eventLoopNat, |
| 918 | c_path, |
| 919 | DBUS_DEVICE_IFACE, |
| 920 | "DiscoverServices", |
| 921 | DBUS_TYPE_STRING, &c_pattern, |
| 922 | DBUS_TYPE_INVALID); |
| 923 | env->ReleaseStringUTFChars(path, c_path); |
| 924 | env->ReleaseStringUTFChars(pattern, c_pattern); |
| 925 | return ret ? JNI_TRUE : JNI_FALSE; |
| 926 | } |
| 927 | #endif |
| 928 | return JNI_FALSE; |
| 929 | } |
| 930 | |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 931 | #ifdef HAVE_BLUETOOTH |
Jaikumar Ganesh | aecb2c5 | 2010-12-13 14:04:45 -0800 | [diff] [blame] | 932 | static jintArray extract_handles(JNIEnv *env, DBusMessage *reply) { |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 933 | jint *handles; |
| 934 | jintArray handleArray = NULL; |
| 935 | int len; |
| 936 | |
| 937 | DBusError err; |
| 938 | dbus_error_init(&err); |
| 939 | |
| 940 | if (dbus_message_get_args(reply, &err, |
| 941 | DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &handles, &len, |
| 942 | DBUS_TYPE_INVALID)) { |
| 943 | handleArray = env->NewIntArray(len); |
| 944 | if (handleArray) { |
| 945 | env->SetIntArrayRegion(handleArray, 0, len, handles); |
| 946 | } else { |
| 947 | LOGE("Null array in extract_handles"); |
| 948 | } |
| 949 | } else { |
| 950 | LOG_AND_FREE_DBUS_ERROR(&err); |
| 951 | } |
| 952 | return handleArray; |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 953 | } |
Jaikumar Ganesh | aecb2c5 | 2010-12-13 14:04:45 -0800 | [diff] [blame] | 954 | #endif |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 955 | |
| 956 | static jintArray addReservedServiceRecordsNative(JNIEnv *env, jobject object, |
| 957 | jintArray uuids) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 958 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 959 | #ifdef HAVE_BLUETOOTH |
| 960 | DBusMessage *reply = NULL; |
| 961 | |
| 962 | native_data_t *nat = get_native_data(env, object); |
| 963 | |
| 964 | jint* svc_classes = env->GetIntArrayElements(uuids, NULL); |
| 965 | if (!svc_classes) return NULL; |
| 966 | |
| 967 | int len = env->GetArrayLength(uuids); |
| 968 | reply = dbus_func_args(env, nat->conn, |
| 969 | get_adapter_path(env, object), |
| 970 | DBUS_ADAPTER_IFACE, "AddReservedServiceRecords", |
| 971 | DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, |
| 972 | &svc_classes, len, DBUS_TYPE_INVALID); |
| 973 | env->ReleaseIntArrayElements(uuids, svc_classes, 0); |
| 974 | return reply ? extract_handles(env, reply) : NULL; |
| 975 | |
| 976 | #endif |
| 977 | return NULL; |
| 978 | } |
| 979 | |
| 980 | static jboolean removeReservedServiceRecordsNative(JNIEnv *env, jobject object, |
| 981 | jintArray handles) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 982 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 983 | #ifdef HAVE_BLUETOOTH |
| 984 | native_data_t *nat = get_native_data(env, object); |
| 985 | jint *values = env->GetIntArrayElements(handles, NULL); |
| 986 | DBusMessage *msg = NULL; |
| 987 | DBusMessage *reply = NULL; |
| 988 | if (values == NULL) return JNI_FALSE; |
| 989 | |
| 990 | jsize len = env->GetArrayLength(handles); |
| 991 | |
| 992 | reply = dbus_func_args(env, nat->conn, |
| 993 | get_adapter_path(env, object), |
| 994 | DBUS_ADAPTER_IFACE, "RemoveReservedServiceRecords", |
| 995 | DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, |
| 996 | &values, len, DBUS_TYPE_INVALID); |
| 997 | env->ReleaseIntArrayElements(handles, values, NULL); |
| 998 | return reply ? JNI_TRUE : JNI_FALSE; |
| 999 | #endif |
| 1000 | return JNI_FALSE; |
| 1001 | } |
| 1002 | |
Nick Pelly | 24bb9b8 | 2009-10-02 20:34:18 -0700 | [diff] [blame] | 1003 | static jint addRfcommServiceRecordNative(JNIEnv *env, jobject object, |
| 1004 | jstring name, jlong uuidMsb, jlong uuidLsb, jshort channel) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1005 | LOGV("%s", __FUNCTION__); |
Nick Pelly | 24bb9b8 | 2009-10-02 20:34:18 -0700 | [diff] [blame] | 1006 | #ifdef HAVE_BLUETOOTH |
| 1007 | native_data_t *nat = get_native_data(env, object); |
| 1008 | if (nat) { |
| 1009 | const char *c_name = env->GetStringUTFChars(name, NULL); |
| 1010 | LOGV("... name = %s", c_name); |
| 1011 | LOGV("... uuid1 = %llX", uuidMsb); |
| 1012 | LOGV("... uuid2 = %llX", uuidLsb); |
| 1013 | LOGV("... channel = %d", channel); |
| 1014 | DBusMessage *reply = dbus_func_args(env, nat->conn, |
| 1015 | get_adapter_path(env, object), |
| 1016 | DBUS_ADAPTER_IFACE, "AddRfcommServiceRecord", |
| 1017 | DBUS_TYPE_STRING, &c_name, |
| 1018 | DBUS_TYPE_UINT64, &uuidMsb, |
| 1019 | DBUS_TYPE_UINT64, &uuidLsb, |
| 1020 | DBUS_TYPE_UINT16, &channel, |
| 1021 | DBUS_TYPE_INVALID); |
| 1022 | env->ReleaseStringUTFChars(name, c_name); |
| 1023 | return reply ? dbus_returns_uint32(env, reply) : -1; |
| 1024 | } |
| 1025 | #endif |
| 1026 | return -1; |
| 1027 | } |
| 1028 | |
| 1029 | static jboolean removeServiceRecordNative(JNIEnv *env, jobject object, jint handle) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1030 | LOGV("%s", __FUNCTION__); |
Nick Pelly | 24bb9b8 | 2009-10-02 20:34:18 -0700 | [diff] [blame] | 1031 | #ifdef HAVE_BLUETOOTH |
| 1032 | native_data_t *nat = get_native_data(env, object); |
| 1033 | if (nat) { |
| 1034 | LOGV("... handle = %X", handle); |
| 1035 | DBusMessage *reply = dbus_func_args(env, nat->conn, |
| 1036 | get_adapter_path(env, object), |
| 1037 | DBUS_ADAPTER_IFACE, "RemoveServiceRecord", |
| 1038 | DBUS_TYPE_UINT32, &handle, |
| 1039 | DBUS_TYPE_INVALID); |
| 1040 | return reply ? JNI_TRUE : JNI_FALSE; |
| 1041 | } |
| 1042 | #endif |
| 1043 | return JNI_FALSE; |
| 1044 | } |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1045 | |
Jaikumar Ganesh | b7e029d | 2010-03-09 15:31:24 -0800 | [diff] [blame] | 1046 | static jboolean setLinkTimeoutNative(JNIEnv *env, jobject object, jstring object_path, |
| 1047 | jint num_slots) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1048 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | b7e029d | 2010-03-09 15:31:24 -0800 | [diff] [blame] | 1049 | #ifdef HAVE_BLUETOOTH |
| 1050 | native_data_t *nat = get_native_data(env, object); |
| 1051 | if (nat) { |
| 1052 | const char *c_object_path = env->GetStringUTFChars(object_path, NULL); |
| 1053 | DBusMessage *reply = dbus_func_args(env, nat->conn, |
| 1054 | get_adapter_path(env, object), |
| 1055 | DBUS_ADAPTER_IFACE, "SetLinkTimeout", |
| 1056 | DBUS_TYPE_OBJECT_PATH, &c_object_path, |
| 1057 | DBUS_TYPE_UINT32, &num_slots, |
| 1058 | DBUS_TYPE_INVALID); |
| 1059 | env->ReleaseStringUTFChars(object_path, c_object_path); |
| 1060 | return reply ? JNI_TRUE : JNI_FALSE; |
| 1061 | } |
| 1062 | #endif |
| 1063 | return JNI_FALSE; |
| 1064 | } |
| 1065 | |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1066 | static jboolean connectInputDeviceNative(JNIEnv *env, jobject object, jstring path) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1067 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1068 | #ifdef HAVE_BLUETOOTH |
| 1069 | native_data_t *nat = get_native_data(env, object); |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 1070 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 1071 | struct event_loop_native_data_t *eventLoopNat = |
| 1072 | get_EventLoop_native_data(env, eventLoop); |
| 1073 | |
| 1074 | if (nat && eventLoopNat) { |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1075 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 1076 | |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 1077 | int len = env->GetStringLength(path) + 1; |
| 1078 | char *context_path = (char *)calloc(len, sizeof(char)); |
| 1079 | strlcpy(context_path, c_path, len); // for callback |
| 1080 | |
| 1081 | bool ret = dbus_func_args_async(env, nat->conn, -1, onInputDeviceConnectionResult, |
| 1082 | context_path, eventLoopNat, c_path, DBUS_INPUT_IFACE, |
| 1083 | "Connect", |
| 1084 | DBUS_TYPE_INVALID); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1085 | |
| 1086 | env->ReleaseStringUTFChars(path, c_path); |
| 1087 | return ret ? JNI_TRUE : JNI_FALSE; |
| 1088 | } |
| 1089 | #endif |
| 1090 | return JNI_FALSE; |
| 1091 | } |
| 1092 | |
| 1093 | static jboolean disconnectInputDeviceNative(JNIEnv *env, jobject object, |
| 1094 | jstring path) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1095 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1096 | #ifdef HAVE_BLUETOOTH |
| 1097 | native_data_t *nat = get_native_data(env, object); |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 1098 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 1099 | struct event_loop_native_data_t *eventLoopNat = |
| 1100 | get_EventLoop_native_data(env, eventLoop); |
| 1101 | |
| 1102 | if (nat && eventLoopNat) { |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1103 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 1104 | |
Jaikumar Ganesh | de07503 | 2010-07-19 16:28:27 -0700 | [diff] [blame] | 1105 | int len = env->GetStringLength(path) + 1; |
| 1106 | char *context_path = (char *)calloc(len, sizeof(char)); |
| 1107 | strlcpy(context_path, c_path, len); // for callback |
| 1108 | |
| 1109 | bool ret = dbus_func_args_async(env, nat->conn, -1, onInputDeviceConnectionResult, |
| 1110 | context_path, eventLoopNat, c_path, DBUS_INPUT_IFACE, |
| 1111 | "Disconnect", |
| 1112 | DBUS_TYPE_INVALID); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1113 | |
| 1114 | env->ReleaseStringUTFChars(path, c_path); |
| 1115 | return ret ? JNI_TRUE : JNI_FALSE; |
| 1116 | } |
| 1117 | #endif |
| 1118 | return JNI_FALSE; |
| 1119 | } |
| 1120 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1121 | static jboolean setBluetoothTetheringNative(JNIEnv *env, jobject object, jboolean value, |
| 1122 | jstring src_role, jstring bridge) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1123 | LOGV("%s", __FUNCTION__); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1124 | #ifdef HAVE_BLUETOOTH |
| 1125 | native_data_t *nat = get_native_data(env, object); |
| 1126 | if (nat) { |
| 1127 | DBusMessage *reply; |
| 1128 | const char *c_role = env->GetStringUTFChars(src_role, NULL); |
| 1129 | const char *c_bridge = env->GetStringUTFChars(bridge, NULL); |
| 1130 | if (value) { |
| 1131 | LOGE("setBluetoothTetheringNative true"); |
| 1132 | reply = dbus_func_args(env, nat->conn, |
| 1133 | get_adapter_path(env, object), |
| 1134 | DBUS_NETWORKSERVER_IFACE, |
| 1135 | "Register", |
| 1136 | DBUS_TYPE_STRING, &c_role, |
| 1137 | DBUS_TYPE_STRING, &c_bridge, |
| 1138 | DBUS_TYPE_INVALID); |
| 1139 | } else { |
| 1140 | LOGE("setBluetoothTetheringNative false"); |
| 1141 | reply = dbus_func_args(env, nat->conn, |
| 1142 | get_adapter_path(env, object), |
| 1143 | DBUS_NETWORKSERVER_IFACE, |
| 1144 | "Unregister", |
| 1145 | DBUS_TYPE_STRING, &c_role, |
| 1146 | DBUS_TYPE_INVALID); |
| 1147 | } |
| 1148 | env->ReleaseStringUTFChars(src_role, c_role); |
| 1149 | env->ReleaseStringUTFChars(bridge, c_bridge); |
| 1150 | return reply ? JNI_TRUE : JNI_FALSE; |
| 1151 | } |
| 1152 | #endif |
| 1153 | return JNI_FALSE; |
| 1154 | } |
| 1155 | |
| 1156 | static jboolean connectPanDeviceNative(JNIEnv *env, jobject object, jstring path, |
Jaikumar Ganesh | b7ec3e1 | 2010-12-16 18:02:29 -0800 | [diff] [blame] | 1157 | jstring dstRole) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1158 | LOGV("%s", __FUNCTION__); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1159 | #ifdef HAVE_BLUETOOTH |
| 1160 | LOGE("connectPanDeviceNative"); |
| 1161 | native_data_t *nat = get_native_data(env, object); |
| 1162 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 1163 | struct event_loop_native_data_t *eventLoopNat = |
| 1164 | get_EventLoop_native_data(env, eventLoop); |
| 1165 | |
| 1166 | if (nat && eventLoopNat) { |
| 1167 | const char *c_path = env->GetStringUTFChars(path, NULL); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1168 | const char *dst = env->GetStringUTFChars(dstRole, NULL); |
| 1169 | |
| 1170 | int len = env->GetStringLength(path) + 1; |
| 1171 | char *context_path = (char *)calloc(len, sizeof(char)); |
| 1172 | strlcpy(context_path, c_path, len); // for callback |
| 1173 | |
| 1174 | bool ret = dbus_func_args_async(env, nat->conn, -1,onPanDeviceConnectionResult, |
| 1175 | context_path, eventLoopNat, c_path, |
| 1176 | DBUS_NETWORK_IFACE, "Connect", |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1177 | DBUS_TYPE_STRING, &dst, |
| 1178 | DBUS_TYPE_INVALID); |
| 1179 | |
| 1180 | env->ReleaseStringUTFChars(path, c_path); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1181 | env->ReleaseStringUTFChars(dstRole, dst); |
| 1182 | return ret ? JNI_TRUE : JNI_FALSE; |
| 1183 | } |
| 1184 | #endif |
| 1185 | return JNI_FALSE; |
| 1186 | } |
| 1187 | |
| 1188 | static jboolean disconnectPanDeviceNative(JNIEnv *env, jobject object, |
| 1189 | jstring path) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1190 | LOGV("%s", __FUNCTION__); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1191 | #ifdef HAVE_BLUETOOTH |
| 1192 | LOGE("disconnectPanDeviceNative"); |
| 1193 | native_data_t *nat = get_native_data(env, object); |
| 1194 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 1195 | struct event_loop_native_data_t *eventLoopNat = |
| 1196 | get_EventLoop_native_data(env, eventLoop); |
| 1197 | |
| 1198 | if (nat && eventLoopNat) { |
| 1199 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 1200 | |
| 1201 | int len = env->GetStringLength(path) + 1; |
| 1202 | char *context_path = (char *)calloc(len, sizeof(char)); |
| 1203 | strlcpy(context_path, c_path, len); // for callback |
| 1204 | |
| 1205 | bool ret = dbus_func_args_async(env, nat->conn, -1,onPanDeviceConnectionResult, |
| 1206 | context_path, eventLoopNat, c_path, |
| 1207 | DBUS_NETWORK_IFACE, "Disconnect", |
| 1208 | DBUS_TYPE_INVALID); |
| 1209 | |
| 1210 | env->ReleaseStringUTFChars(path, c_path); |
| 1211 | return ret ? JNI_TRUE : JNI_FALSE; |
| 1212 | } |
| 1213 | #endif |
| 1214 | return JNI_FALSE; |
| 1215 | } |
| 1216 | |
Jaikumar Ganesh | a44a1e7 | 2011-02-11 12:40:44 -0800 | [diff] [blame] | 1217 | static jboolean disconnectPanServerDeviceNative(JNIEnv *env, jobject object, |
| 1218 | jstring path, jstring address, |
| 1219 | jstring iface) { |
Jaikumar Ganesh | 2653a1e | 2011-02-22 10:53:29 -0800 | [diff] [blame] | 1220 | LOGV("%s", __FUNCTION__); |
Jaikumar Ganesh | a44a1e7 | 2011-02-11 12:40:44 -0800 | [diff] [blame] | 1221 | #ifdef HAVE_BLUETOOTH |
| 1222 | LOGE("disconnectPanServerDeviceNative"); |
| 1223 | native_data_t *nat = get_native_data(env, object); |
| 1224 | jobject eventLoop = env->GetObjectField(object, field_mEventLoop); |
| 1225 | struct event_loop_native_data_t *eventLoopNat = |
| 1226 | get_EventLoop_native_data(env, eventLoop); |
| 1227 | |
| 1228 | if (nat && eventLoopNat) { |
| 1229 | const char *c_address = env->GetStringUTFChars(address, NULL); |
| 1230 | const char *c_path = env->GetStringUTFChars(path, NULL); |
| 1231 | const char *c_iface = env->GetStringUTFChars(iface, NULL); |
| 1232 | |
| 1233 | int len = env->GetStringLength(path) + 1; |
| 1234 | char *context_path = (char *)calloc(len, sizeof(char)); |
| 1235 | strlcpy(context_path, c_path, len); // for callback |
| 1236 | |
| 1237 | bool ret = dbus_func_args_async(env, nat->conn, -1, |
| 1238 | onPanDeviceConnectionResult, |
| 1239 | context_path, eventLoopNat, |
| 1240 | get_adapter_path(env, object), |
| 1241 | DBUS_NETWORKSERVER_IFACE, |
| 1242 | "DisconnectDevice", |
| 1243 | DBUS_TYPE_STRING, &c_address, |
| 1244 | DBUS_TYPE_STRING, &c_iface, |
| 1245 | DBUS_TYPE_INVALID); |
| 1246 | |
| 1247 | env->ReleaseStringUTFChars(address, c_address); |
| 1248 | env->ReleaseStringUTFChars(iface, c_iface); |
| 1249 | env->ReleaseStringUTFChars(path, c_path); |
| 1250 | return ret ? JNI_TRUE : JNI_FALSE; |
| 1251 | } |
| 1252 | #endif |
| 1253 | return JNI_FALSE; |
| 1254 | } |
| 1255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | static JNINativeMethod sMethods[] = { |
| 1257 | /* name, signature, funcPtr */ |
| 1258 | {"classInitNative", "()V", (void*)classInitNative}, |
| 1259 | {"initializeNativeDataNative", "()V", (void *)initializeNativeDataNative}, |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1260 | {"setupNativeDataNative", "()Z", (void *)setupNativeDataNative}, |
| 1261 | {"tearDownNativeDataNative", "()Z", (void *)tearDownNativeDataNative}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | {"cleanupNativeDataNative", "()V", (void *)cleanupNativeDataNative}, |
| 1263 | {"getAdapterPathNative", "()Ljava/lang/String;", (void*)getAdapterPathNative}, |
| 1264 | |
| 1265 | {"isEnabledNative", "()I", (void *)isEnabledNative}, |
| 1266 | {"enableNative", "()I", (void *)enableNative}, |
| 1267 | {"disableNative", "()I", (void *)disableNative}, |
| 1268 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1269 | {"getAdapterPropertiesNative", "()[Ljava/lang/Object;", (void *)getAdapterPropertiesNative}, |
| 1270 | {"getDevicePropertiesNative", "(Ljava/lang/String;)[Ljava/lang/Object;", |
| 1271 | (void *)getDevicePropertiesNative}, |
| 1272 | {"setAdapterPropertyStringNative", "(Ljava/lang/String;Ljava/lang/String;)Z", |
| 1273 | (void *)setAdapterPropertyStringNative}, |
| 1274 | {"setAdapterPropertyBooleanNative", "(Ljava/lang/String;I)Z", |
| 1275 | (void *)setAdapterPropertyBooleanNative}, |
| 1276 | {"setAdapterPropertyIntegerNative", "(Ljava/lang/String;I)Z", |
| 1277 | (void *)setAdapterPropertyIntegerNative}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1279 | {"startDiscoveryNative", "()Z", (void*)startDiscoveryNative}, |
| 1280 | {"stopDiscoveryNative", "()Z", (void *)stopDiscoveryNative}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 1282 | {"readAdapterOutOfBandDataNative", "()[B", (void *)readAdapterOutOfBandDataNative}, |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1283 | {"createPairedDeviceNative", "(Ljava/lang/String;I)Z", (void *)createPairedDeviceNative}, |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 1284 | {"createPairedDeviceOutOfBandNative", "(Ljava/lang/String;I)Z", |
| 1285 | (void *)createPairedDeviceOutOfBandNative}, |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1286 | {"cancelDeviceCreationNative", "(Ljava/lang/String;)Z", (void *)cancelDeviceCreationNative}, |
| 1287 | {"removeDeviceNative", "(Ljava/lang/String;)Z", (void *)removeDeviceNative}, |
| 1288 | {"getDeviceServiceChannelNative", "(Ljava/lang/String;Ljava/lang/String;I)I", |
| 1289 | (void *)getDeviceServiceChannelNative}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1291 | {"setPairingConfirmationNative", "(Ljava/lang/String;ZI)Z", |
| 1292 | (void *)setPairingConfirmationNative}, |
| 1293 | {"setPasskeyNative", "(Ljava/lang/String;II)Z", (void *)setPasskeyNative}, |
Jaikumar Ganesh | cc5494c | 2010-09-09 15:37:57 -0700 | [diff] [blame] | 1294 | {"setRemoteOutOfBandDataNative", "(Ljava/lang/String;[B[BI)Z", (void *)setRemoteOutOfBandDataNative}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | {"setPinNative", "(Ljava/lang/String;Ljava/lang/String;I)Z", (void *)setPinNative}, |
Jaikumar Ganesh | b0eca41 | 2009-07-16 18:26:28 -0700 | [diff] [blame] | 1296 | {"cancelPairingUserInputNative", "(Ljava/lang/String;I)Z", |
| 1297 | (void *)cancelPairingUserInputNative}, |
Lixin Yue | efa1dd7 | 2009-08-31 15:55:13 +0800 | [diff] [blame] | 1298 | {"setDevicePropertyBooleanNative", "(Ljava/lang/String;Ljava/lang/String;I)Z", |
| 1299 | (void *)setDevicePropertyBooleanNative}, |
Jaikumar Ganesh | 1caa6d1 | 2009-09-18 11:32:54 -0700 | [diff] [blame] | 1300 | {"createDeviceNative", "(Ljava/lang/String;)Z", (void *)createDeviceNative}, |
| 1301 | {"discoverServicesNative", "(Ljava/lang/String;Ljava/lang/String;)Z", (void *)discoverServicesNative}, |
Nick Pelly | 24bb9b8 | 2009-10-02 20:34:18 -0700 | [diff] [blame] | 1302 | {"addRfcommServiceRecordNative", "(Ljava/lang/String;JJS)I", (void *)addRfcommServiceRecordNative}, |
| 1303 | {"removeServiceRecordNative", "(I)Z", (void *)removeServiceRecordNative}, |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 1304 | {"addReservedServiceRecordsNative", "([I)[I", (void *) addReservedServiceRecordsNative}, |
| 1305 | {"removeReservedServiceRecordsNative", "([I)Z", (void *) removeReservedServiceRecordsNative}, |
Jaikumar Ganesh | b7e029d | 2010-03-09 15:31:24 -0800 | [diff] [blame] | 1306 | {"setLinkTimeoutNative", "(Ljava/lang/String;I)Z", (void *)setLinkTimeoutNative}, |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 1307 | // HID functions |
| 1308 | {"connectInputDeviceNative", "(Ljava/lang/String;)Z", (void *)connectInputDeviceNative}, |
| 1309 | {"disconnectInputDeviceNative", "(Ljava/lang/String;)Z", (void *)disconnectInputDeviceNative}, |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1310 | |
| 1311 | {"setBluetoothTetheringNative", "(ZLjava/lang/String;Ljava/lang/String;)Z", |
| 1312 | (void *)setBluetoothTetheringNative}, |
Jaikumar Ganesh | b7ec3e1 | 2010-12-16 18:02:29 -0800 | [diff] [blame] | 1313 | {"connectPanDeviceNative", "(Ljava/lang/String;Ljava/lang/String;)Z", |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1314 | (void *)connectPanDeviceNative}, |
| 1315 | {"disconnectPanDeviceNative", "(Ljava/lang/String;)Z", (void *)disconnectPanDeviceNative}, |
Jaikumar Ganesh | a44a1e7 | 2011-02-11 12:40:44 -0800 | [diff] [blame] | 1316 | {"disconnectPanServerDeviceNative", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", |
| 1317 | (void *)disconnectPanServerDeviceNative}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | }; |
| 1319 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1320 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1321 | int register_android_server_BluetoothService(JNIEnv *env) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | return AndroidRuntime::registerNativeMethods(env, |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 1323 | "android/server/BluetoothService", sMethods, NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | } /* namespace android */ |