Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68950951 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by android-build-merger
Browse files

Merge "Make RawAddress into a class (3/3)"

am: 81e9716c

Change-Id: I6a3d271ba7d2901360a299a2ed967d7060a51801
parents 9bb3c43c 81e9716c
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -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",
@@ -27,6 +28,9 @@ cc_library_shared {
        "liblog",
        "liblog",
        "libhardware",
        "libhardware",
    ],
    ],
    static_libs: [
        "libbluetooth-types",
    ],
    cflags: [
    cflags: [
        "-Wall",
        "-Wall",
        "-Wextra",
        "-Wextra",
+9 −44
Original line number Original line Diff line number Diff line
@@ -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) {
@@ -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
@@ -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);
}
}