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

Commit b47baa79 authored by Rahul Sabnis's avatar Rahul Sabnis Committed by Android (Google) Code Review
Browse files

Merge "Sets up callback to associate an LE-only device with its identity...

Merge "Sets up callback to associate an LE-only device with its identity address in the Java layer." into tm-d1-dev
parents 9601241a 7391423f
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ static jmethodID method_pinRequestCallback;
static jmethodID method_sspRequestCallback;
static jmethodID method_bondStateChangeCallback;
static jmethodID method_addressConsolidateCallback;
static jmethodID method_leAddressAssociateCallback;
static jmethodID method_aclStateChangeCallback;
static jmethodID method_discoveryStateChangeCallback;
static jmethodID method_linkQualityReportCallback;
@@ -336,6 +337,34 @@ static void address_consolidate_callback(RawAddress* main_bd_addr,
                               main_addr.get(), secondary_addr.get());
}

static void le_address_associate_callback(RawAddress* main_bd_addr,
                                          RawAddress* secondary_bd_addr) {
  CallbackEnv sCallbackEnv(__func__);

  ScopedLocalRef<jbyteArray> main_addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!main_addr.get()) {
    ALOGE("Address allocation failed in %s", __func__);
    return;
  }
  sCallbackEnv->SetByteArrayRegion(main_addr.get(), 0, sizeof(RawAddress),
                                   (jbyte*)main_bd_addr);

  ScopedLocalRef<jbyteArray> secondary_addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!secondary_addr.get()) {
    ALOGE("Address allocation failed in %s", __func__);
    return;
  }

  sCallbackEnv->SetByteArrayRegion(secondary_addr.get(), 0, sizeof(RawAddress),
                                   (jbyte*)secondary_bd_addr);

  sCallbackEnv->CallVoidMethod(sJniCallbacksObj,
                               method_leAddressAssociateCallback,
                               main_addr.get(), secondary_addr.get());
}

static void acl_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
                                       bt_acl_state_t state,
                                       int transport_link_type,
@@ -696,6 +725,7 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks),
                                             ssp_request_callback,
                                             bond_state_changed_callback,
                                             address_consolidate_callback,
                                             le_address_associate_callback,
                                             acl_state_changed_callback,
                                             callback_thread_event,
                                             dut_mode_recv_callback,
@@ -922,6 +952,9 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_addressConsolidateCallback = env->GetMethodID(
      jniCallbackClass, "addressConsolidateCallback", "([B[B)V");

  method_leAddressAssociateCallback = env->GetMethodID(
      jniCallbackClass, "leAddressAssociateCallback", "([B[B)V");

  method_aclStateChangeCallback =
      env->GetMethodID(jniCallbackClass, "aclStateChangeCallback", "(I[BIII)V");

+2 −2
Original line number Diff line number Diff line
@@ -3860,7 +3860,7 @@ public class AdapterService extends Service {

    public byte[] getByteIdentityAddress(BluetoothDevice device) {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp != null && deviceProp.isConsolidated()) {
        if (deviceProp != null && deviceProp.getIdentityAddress() != null) {
            return Utils.getBytesFromAddress(deviceProp.getIdentityAddress());
        } else {
            return Utils.getByteAddress(device);
@@ -3878,7 +3878,7 @@ public class AdapterService extends Service {
    public String getIdentityAddress(String address) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address.toUpperCase());
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp != null && deviceProp.isConsolidated()) {
        if (deviceProp != null && deviceProp.getIdentityAddress() != null) {
            return deviceProp.getIdentityAddress();
        } else {
            return address;
+4 −0
Original line number Diff line number Diff line
@@ -71,6 +71,10 @@ final class JniCallbacks {
        mRemoteDevices.addressConsolidateCallback(mainAddress, secondaryAddress);
    }

    void leAddressAssociateCallback(byte[] mainAddress, byte[] secondaryAddress) {
        mRemoteDevices.leAddressAssociateCallback(mainAddress, secondaryAddress);
    }

    void aclStateChangeCallback(int status, byte[] address, int newState,
            int transportLinkType, int hciReason) {
        mRemoteDevices.aclStateChangeCallback(status, address, newState,
+21 −0
Original line number Diff line number Diff line
@@ -805,6 +805,27 @@ final class RemoteDevices {
        mDualDevicesMap.put(deviceProperties.getIdentityAddress(), Utils.getAddressStringFromByte(mainAddress));
    }

    /**
     * Callback to associate an LE-only device's RPA with its identity address
     *
     * @param mainAddress the device's RPA
     * @param secondaryAddress the device's identity address
     */
    void leAddressAssociateCallback(byte[] mainAddress, byte[] secondaryAddress) {
        BluetoothDevice device = getDevice(mainAddress);
        if (device == null) {
            errorLog("leAddressAssociateCallback: device is NULL, address="
                    + Utils.getAddressStringFromByte(mainAddress) + ", secondaryAddress="
                    + Utils.getAddressStringFromByte(secondaryAddress));
            return;
        }
        Log.d(TAG, "leAddressAssociateCallback device: " + device + ", secondaryAddress:"
                + Utils.getAddressStringFromByte(secondaryAddress));

        DeviceProperties deviceProperties = getDeviceProperties(device);
        deviceProperties.mIdentityAddress = Utils.getAddressStringFromByte(secondaryAddress);
    }

    void aclStateChangeCallback(int status, byte[] address, int newState,
                                int transportLinkType, int hciReason) {
        BluetoothDevice device = getDevice(address);
+6 −0
Original line number Diff line number Diff line
@@ -3636,6 +3636,12 @@ static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda,
      }
      break;

    case BTM_LE_ADDR_ASSOC_EVT:
      sec_event.proc_id_addr.pairing_bda = bda;
      sec_event.proc_id_addr.id_addr = p_data->id_addr;
      bta_dm_cb.p_sec_cback(BTA_DM_LE_ADDR_ASSOC_EVT, &sec_event);
      break;

    default:
      status = BTM_NOT_AUTHORIZED;
      break;
Loading