Loading jni/Android.bp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ cc_library_shared { ], ], include_dirs: [ include_dirs: [ "libnativehelper/include/nativehelper", "libnativehelper/include/nativehelper", "system/bt/types", ], ], shared_libs: [ shared_libs: [ "libandroid_runtime", "libandroid_runtime", Loading @@ -27,6 +28,9 @@ cc_library_shared { "liblog", "liblog", "libhardware", "libhardware", ], ], static_libs: [ "libbluetooth-types", ], cflags: [ cflags: [ "-Wall", "-Wall", "-Wextra", "-Wextra", Loading jni/com_android_bluetooth_gatt.cpp +9 −44 Original line number Original line Diff line number Diff line Loading @@ -71,44 +71,15 @@ static uint64_t uuid_msb(const bt_uuid_t& uuid) { return msb; return msb; } } static void bd_addr_str_to_addr(const char* str, uint8_t* bd_addr) { int i; char c; c = *str++; for (i = 0; i < BD_ADDR_LEN; i++) { if (c >= '0' && c <= '9') bd_addr[i] = c - '0'; else if (c >= 'a' && c <= 'z') bd_addr[i] = c - 'a' + 10; else // (c >= 'A' && c <= 'Z') bd_addr[i] = c - 'A' + 10; c = *str++; if (c != ':') { bd_addr[i] <<= 4; if (c >= '0' && c <= '9') bd_addr[i] |= c - '0'; else if (c >= 'a' && c <= 'z') bd_addr[i] |= c - 'a' + 10; else // (c >= 'A' && c <= 'Z') bd_addr[i] |= c - 'A' + 10; c = *str++; } c = *str++; } } static RawAddress str2addr(JNIEnv* env, jstring address) { static RawAddress str2addr(JNIEnv* env, jstring address) { RawAddress bda; RawAddress bd_addr; const char* c_bda = env->GetStringUTFChars(address, NULL); const char* c_address = env->GetStringUTFChars(address, NULL); if (!c_bda || strlen(c_bda) != 17) return bda; if (!c_address) return bd_addr; RawAddress::FromString(std::string(c_address), bd_addr); env->ReleaseStringUTFChars(address, c_address); bd_addr_str_to_addr(c_bda, bda.address); return bd_addr; env->ReleaseStringUTFChars(address, c_bda); return bda; } } static jstring bdaddr2newjstr(JNIEnv* env, const RawAddress* bda) { static jstring bdaddr2newjstr(JNIEnv* env, const RawAddress* bda) { Loading Loading @@ -1173,10 +1144,7 @@ static void gattClientRegisterForNotificationsNative( jboolean enable) { jboolean enable) { if (!sGattIf) return; if (!sGattIf) return; RawAddress bd_addr; RawAddress bd_addr = str2addr(env, address); const char* c_address = env->GetStringUTFChars(address, NULL); bd_addr_str_to_addr(c_address, bd_addr.address); if (enable) if (enable) sGattIf->client->register_for_notification(clientIf, bd_addr, handle); sGattIf->client->register_for_notification(clientIf, bd_addr, handle); else else Loading Loading @@ -1517,10 +1485,7 @@ static void gattServerConnectNative(JNIEnv* env, jobject object, jint server_if, jint transport) { jint transport) { if (!sGattIf) return; if (!sGattIf) return; RawAddress bd_addr; RawAddress bd_addr = str2addr(env, address); const char* c_address = env->GetStringUTFChars(address, NULL); bd_addr_str_to_addr(c_address, bd_addr.address); sGattIf->server->connect(server_if, bd_addr, is_direct, transport); sGattIf->server->connect(server_if, bd_addr, is_direct, transport); } } Loading Loading
jni/Android.bp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ cc_library_shared { ], ], include_dirs: [ include_dirs: [ "libnativehelper/include/nativehelper", "libnativehelper/include/nativehelper", "system/bt/types", ], ], shared_libs: [ shared_libs: [ "libandroid_runtime", "libandroid_runtime", Loading @@ -27,6 +28,9 @@ cc_library_shared { "liblog", "liblog", "libhardware", "libhardware", ], ], static_libs: [ "libbluetooth-types", ], cflags: [ cflags: [ "-Wall", "-Wall", "-Wextra", "-Wextra", Loading
jni/com_android_bluetooth_gatt.cpp +9 −44 Original line number Original line Diff line number Diff line Loading @@ -71,44 +71,15 @@ static uint64_t uuid_msb(const bt_uuid_t& uuid) { return msb; return msb; } } static void bd_addr_str_to_addr(const char* str, uint8_t* bd_addr) { int i; char c; c = *str++; for (i = 0; i < BD_ADDR_LEN; i++) { if (c >= '0' && c <= '9') bd_addr[i] = c - '0'; else if (c >= 'a' && c <= 'z') bd_addr[i] = c - 'a' + 10; else // (c >= 'A' && c <= 'Z') bd_addr[i] = c - 'A' + 10; c = *str++; if (c != ':') { bd_addr[i] <<= 4; if (c >= '0' && c <= '9') bd_addr[i] |= c - '0'; else if (c >= 'a' && c <= 'z') bd_addr[i] |= c - 'a' + 10; else // (c >= 'A' && c <= 'Z') bd_addr[i] |= c - 'A' + 10; c = *str++; } c = *str++; } } static RawAddress str2addr(JNIEnv* env, jstring address) { static RawAddress str2addr(JNIEnv* env, jstring address) { RawAddress bda; RawAddress bd_addr; const char* c_bda = env->GetStringUTFChars(address, NULL); const char* c_address = env->GetStringUTFChars(address, NULL); if (!c_bda || strlen(c_bda) != 17) return bda; if (!c_address) return bd_addr; RawAddress::FromString(std::string(c_address), bd_addr); env->ReleaseStringUTFChars(address, c_address); bd_addr_str_to_addr(c_bda, bda.address); return bd_addr; env->ReleaseStringUTFChars(address, c_bda); return bda; } } static jstring bdaddr2newjstr(JNIEnv* env, const RawAddress* bda) { static jstring bdaddr2newjstr(JNIEnv* env, const RawAddress* bda) { Loading Loading @@ -1173,10 +1144,7 @@ static void gattClientRegisterForNotificationsNative( jboolean enable) { jboolean enable) { if (!sGattIf) return; if (!sGattIf) return; RawAddress bd_addr; RawAddress bd_addr = str2addr(env, address); const char* c_address = env->GetStringUTFChars(address, NULL); bd_addr_str_to_addr(c_address, bd_addr.address); if (enable) if (enable) sGattIf->client->register_for_notification(clientIf, bd_addr, handle); sGattIf->client->register_for_notification(clientIf, bd_addr, handle); else else Loading Loading @@ -1517,10 +1485,7 @@ static void gattServerConnectNative(JNIEnv* env, jobject object, jint server_if, jint transport) { jint transport) { if (!sGattIf) return; if (!sGattIf) return; RawAddress bd_addr; RawAddress bd_addr = str2addr(env, address); const char* c_address = env->GetStringUTFChars(address, NULL); bd_addr_str_to_addr(c_address, bd_addr.address); sGattIf->server->connect(server_if, bd_addr, is_direct, transport); sGattIf->server->connect(server_if, bd_addr, is_direct, transport); } } Loading