diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2010-06-04 10:23:03 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2010-06-17 13:49:25 -0700 |
commit | 545e6708adda6859932b55fd824794b1401f5318 (patch) | |
tree | ce35056656b208a19aca1edc98864f35935d4edf /core/jni | |
parent | 4e74ae3d5b27d917ea26d0929015f9fdc64af412 (diff) | |
download | frameworks_base-545e6708adda6859932b55fd824794b1401f5318.zip frameworks_base-545e6708adda6859932b55fd824794b1401f5318.tar.gz frameworks_base-545e6708adda6859932b55fd824794b1401f5318.tar.bz2 |
HID profile.
Change-Id: I52e965a6537bce02c751ba26fe7b44dd03832510
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_bluetooth_common.cpp | 14 | ||||
-rw-r--r-- | core/jni/android_bluetooth_common.h | 2 | ||||
-rw-r--r-- | core/jni/android_server_BluetoothEventLoop.cpp | 21 | ||||
-rw-r--r-- | core/jni/android_server_BluetoothService.cpp | 42 |
4 files changed, 79 insertions, 0 deletions
diff --git a/core/jni/android_bluetooth_common.cpp b/core/jni/android_bluetooth_common.cpp index 9a8f1b8..53ac625 100644 --- a/core/jni/android_bluetooth_common.cpp +++ b/core/jni/android_bluetooth_common.cpp @@ -68,6 +68,10 @@ static Properties adapter_properties[] = { {"UUIDs", DBUS_TYPE_ARRAY}, }; +static Properties input_properties[] = { + {"Connected", DBUS_TYPE_BOOLEAN}, +}; + typedef union { char *str_val; int int_val; @@ -698,6 +702,11 @@ jobjectArray parse_remote_device_property_change(JNIEnv *env, DBusMessage *msg) sizeof(remote_device_properties) / sizeof(Properties)); } +jobjectArray parse_input_property_change(JNIEnv *env, DBusMessage *msg) { + return parse_property_change(env, msg, (Properties *) &input_properties, + sizeof(input_properties) / sizeof(Properties)); +} + jobjectArray parse_adapter_properties(JNIEnv *env, DBusMessageIter *iter) { return parse_properties(env, iter, (Properties *) &adapter_properties, sizeof(adapter_properties) / sizeof(Properties)); @@ -708,6 +717,11 @@ jobjectArray parse_remote_device_properties(JNIEnv *env, DBusMessageIter *iter) sizeof(remote_device_properties) / sizeof(Properties)); } +jobjectArray parse_input_properties(JNIEnv *env, DBusMessageIter *iter) { + return parse_properties(env, iter, (Properties *) &input_properties, + sizeof(input_properties) / sizeof(Properties)); +} + int get_bdaddr(const char *str, bdaddr_t *ba) { char *d = ((char *)ba) + 5, *endp; int i; diff --git a/core/jni/android_bluetooth_common.h b/core/jni/android_bluetooth_common.h index 378bb6f..27a00ae 100644 --- a/core/jni/android_bluetooth_common.h +++ b/core/jni/android_bluetooth_common.h @@ -162,6 +162,8 @@ jobjectArray parse_adapter_properties(JNIEnv *env, DBusMessageIter *iter); jobjectArray parse_remote_device_properties(JNIEnv *env, DBusMessageIter *iter); jobjectArray parse_remote_device_property_change(JNIEnv *env, DBusMessage *msg); jobjectArray parse_adapter_property_change(JNIEnv *env, DBusMessage *msg); +jobjectArray parse_input_properties(JNIEnv *env, DBusMessageIter *iter); +jobjectArray parse_input_property_change(JNIEnv *env, DBusMessage *msg); void append_variant(DBusMessageIter *iter, int type, void *val); int get_bdaddr(const char *str, bdaddr_t *ba); void get_bdaddr_as_string(const bdaddr_t *ba, char *str); diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp index 01b6711..3c88158 100644 --- a/core/jni/android_server_BluetoothEventLoop.cpp +++ b/core/jni/android_server_BluetoothEventLoop.cpp @@ -64,6 +64,8 @@ static jmethodID method_onDisplayPasskey; static jmethodID method_onAgentAuthorize; static jmethodID method_onAgentCancel; +static jmethodID method_onInputDevicePropertyChanged; + typedef event_loop_native_data_t native_data_t; #define EVENT_LOOP_REFS 10 @@ -116,6 +118,9 @@ static void classInitNative(JNIEnv* env, jclass clazz) { "(Ljava/lang/String;I)V"); method_onDisplayPasskey = env->GetMethodID(clazz, "onDisplayPasskey", "(Ljava/lang/String;II)V"); + method_onInputDevicePropertyChanged = env->GetMethodID(clazz, "onInputDevicePropertyChanged", + "(Ljava/lang/String;[Ljava/lang/String;)V"); + field_mNativeData = env->GetFieldID(clazz, "mNativeData", "I"); #endif @@ -853,6 +858,22 @@ static DBusHandlerResult event_filter(DBusConnection *conn, DBusMessage *msg, method_onDeviceDisconnectRequested, env->NewStringUTF(remote_device_path)); goto success; + } else if (dbus_message_is_signal(msg, + "org.bluez.Input", + "PropertyChanged")) { + + jobjectArray str_array = + parse_input_property_change(env, msg); + if (str_array != NULL) { + const char *c_path = dbus_message_get_path(msg); + env->CallVoidMethod(nat->me, + method_onInputDevicePropertyChanged, + env->NewStringUTF(c_path), + str_array); + } else { + LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg); + } + goto success; } ret = a2dp_event_filter(msg, env); diff --git a/core/jni/android_server_BluetoothService.cpp b/core/jni/android_server_BluetoothService.cpp index 4420aca..a52a74c 100644 --- a/core/jni/android_server_BluetoothService.cpp +++ b/core/jni/android_server_BluetoothService.cpp @@ -16,6 +16,8 @@ #define DBUS_ADAPTER_IFACE BLUEZ_DBUS_BASE_IFC ".Adapter" #define DBUS_DEVICE_IFACE BLUEZ_DBUS_BASE_IFC ".Device" +#define DBUS_INPUT_IFACE BLUEZ_DBUS_BASE_IFC ".Input" + #define LOG_TAG "BluetoothService.cpp" #include "android_bluetooth_common.h" @@ -881,6 +883,43 @@ static jboolean setLinkTimeoutNative(JNIEnv *env, jobject object, jstring object return JNI_FALSE; } +static jboolean connectInputDeviceNative(JNIEnv *env, jobject object, jstring path) { + LOGV(__FUNCTION__); +#ifdef HAVE_BLUETOOTH + native_data_t *nat = get_native_data(env, object); + if (nat) { + const char *c_path = env->GetStringUTFChars(path, NULL); + + bool ret = dbus_func_args_async(env, nat->conn, -1, NULL, NULL, nat, + c_path, DBUS_INPUT_IFACE, "Connect", + DBUS_TYPE_INVALID); + + env->ReleaseStringUTFChars(path, c_path); + return ret ? JNI_TRUE : JNI_FALSE; + } +#endif + return JNI_FALSE; +} + +static jboolean disconnectInputDeviceNative(JNIEnv *env, jobject object, + jstring path) { + LOGV(__FUNCTION__); +#ifdef HAVE_BLUETOOTH + native_data_t *nat = get_native_data(env, object); + if (nat) { + const char *c_path = env->GetStringUTFChars(path, NULL); + + bool ret = dbus_func_args_async(env, nat->conn, -1, NULL, NULL, nat, + c_path, DBUS_INPUT_IFACE, "Disconnect", + DBUS_TYPE_INVALID); + + env->ReleaseStringUTFChars(path, c_path); + return ret ? JNI_TRUE : JNI_FALSE; + } +#endif + return JNI_FALSE; +} + static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ {"classInitNative", "()V", (void*)classInitNative}, @@ -926,6 +965,9 @@ static JNINativeMethod sMethods[] = { {"addRfcommServiceRecordNative", "(Ljava/lang/String;JJS)I", (void *)addRfcommServiceRecordNative}, {"removeServiceRecordNative", "(I)Z", (void *)removeServiceRecordNative}, {"setLinkTimeoutNative", "(Ljava/lang/String;I)Z", (void *)setLinkTimeoutNative}, + // HID functions + {"connectInputDeviceNative", "(Ljava/lang/String;)Z", (void *)connectInputDeviceNative}, + {"disconnectInputDeviceNative", "(Ljava/lang/String;)Z", (void *)disconnectInputDeviceNative}, }; int register_android_server_BluetoothService(JNIEnv *env) { |