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

Commit 54edfd68 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add `identity_address_type` to `leAddressAssociateCallback`" into main

parents 54f1dc09 bc4c5706
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -403,7 +403,8 @@ static void address_consolidate_callback(RawAddress* main_bd_addr, RawAddress* s
                               secondary_addr.get());
}

static void le_address_associate_callback(RawAddress* main_bd_addr, RawAddress* secondary_bd_addr) {
static void le_address_associate_callback(RawAddress* main_bd_addr, RawAddress* secondary_bd_addr,
                                          uint8_t identity_address_type) {
  std::shared_lock<std::shared_timed_mutex> lock(jniObjMutex);
  if (!sJniCallbacksObj) {
    log::error("JNI obj is null. Failed to call JNI callback");
@@ -432,7 +433,7 @@ static void le_address_associate_callback(RawAddress* main_bd_addr, RawAddress*
                                   reinterpret_cast<jbyte*>(secondary_bd_addr));

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

static void acl_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
@@ -2301,7 +2302,6 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
          {"allowWakeByHidNative", "()Z", reinterpret_cast<void*>(allowWakeByHidNative)},
          {"restoreFilterAcceptListNative", "()Z",
           reinterpret_cast<void*>(restoreFilterAcceptListNative)},

  };
  const int result = REGISTER_NATIVE_METHODS(
          env, "com/android/bluetooth/btservice/AdapterNativeInterface", methods);
@@ -2327,7 +2327,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
          {"sspRequestCallback", "([BII)V", &method_sspRequestCallback},
          {"bondStateChangeCallback", "(I[BII)V", &method_bondStateChangeCallback},
          {"addressConsolidateCallback", "([B[B)V", &method_addressConsolidateCallback},
          {"leAddressAssociateCallback", "([B[B)V", &method_leAddressAssociateCallback},
          {"leAddressAssociateCallback", "([B[BI)V", &method_leAddressAssociateCallback},
          {"aclStateChangeCallback", "(I[BIIII)V", &method_aclStateChangeCallback},
          {"linkQualityReportCallback", "(JIIIIII)V", &method_linkQualityReportCallback},
          {"switchBufferSizeCallback", "(Z)V", &method_switchBufferSizeCallback},
+4 −2
Original line number Diff line number Diff line
@@ -71,8 +71,10 @@ class JniCallbacks {
        mRemoteDevices.addressConsolidateCallback(mainAddress, secondaryAddress);
    }

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

    void aclStateChangeCallback(
+63 −4
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice.AddressType;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
@@ -327,6 +328,7 @@ public class RemoteDevices {
        private String mName;
        private byte[] mAddress;
        private String mIdentityAddress;
        @AddressType private int mIdentityAddressType = BluetoothDevice.ADDRESS_TYPE_UNKNOWN;
        private boolean mIsConsolidated = false;
        private int mBluetoothClass = BluetoothClass.Device.Major.UNCATEGORIZED;
        private int mBredrConnectionHandle = BluetoothDevice.ERROR;
@@ -386,6 +388,55 @@ public class RemoteDevices {
            }
        }

        /**
         * @return the mIdentityAddressType
         */
        @AddressType
        int getIdentityAddressType() {
            synchronized (mObject) {
                return mIdentityAddressType;
            }
        }

        /**
         * @param identityAddressType the mIdentityAddressType to set
         */
        void setIdentityAddressType(int identityAddressType) {
            synchronized (mObject) {
                this.mIdentityAddressType = identityAddressType;
            }
        }

        /**
         * @param identityAddressTypeFromNative the mIdentityAddressType to set after mapping to
         *     Java layer.
         */
        void setIdentityAddressTypeFromNative(int identityAddressTypeFromNative) {
            /*
             * from system/types/ble_address_with_type.h
             *
             * #define BLE_ADDR_PUBLIC 0x00
             * #define BLE_ADDR_RANDOM 0x01
             */
            int identityAddressType = BluetoothDevice.ADDRESS_TYPE_UNKNOWN;
            switch (identityAddressTypeFromNative) {
                case 0x00:
                    identityAddressType = BluetoothDevice.ADDRESS_TYPE_PUBLIC;
                    break;
                case 0x01:
                    identityAddressType = BluetoothDevice.ADDRESS_TYPE_RANDOM;
                    break;
                default:
                    errorLog(
                            "Unexpected identity address type received from native: "
                                    + identityAddressTypeFromNative);
                    break;
            }
            synchronized (mObject) {
                this.mIdentityAddressType = identityAddressType;
            }
        }

        /**
         * @return mIsConsolidated
         */
@@ -1157,19 +1208,24 @@ public class RemoteDevices {
    }

    /**
     * Callback to associate an LE-only device's RPA with its identity address
     * Callback to associate an LE-only device's RPA with its identity address and identity address
     * type
     *
     * @param mainAddress the device's RPA
     * @param secondaryAddress the device's identity address
     * @param identityAddressTypeFromNative the device's identity address type from native
     */
    void leAddressAssociateCallback(byte[] mainAddress, byte[] secondaryAddress) {
    void leAddressAssociateCallback(
            byte[] mainAddress, byte[] secondaryAddress, int identityAddressTypeFromNative) {
        BluetoothDevice device = getDevice(mainAddress);
        if (device == null) {
            errorLog(
                    "leAddressAssociateCallback: device is NULL, address="
                            + Utils.getRedactedAddressStringFromByte(mainAddress)
                            + ", secondaryAddress="
                            + Utils.getRedactedAddressStringFromByte(secondaryAddress));
                            + Utils.getRedactedAddressStringFromByte(secondaryAddress)
                            + ", identityAddressTypeFromNative="
                            + identityAddressTypeFromNative);
            return;
        }
        Log.d(
@@ -1177,10 +1233,13 @@ public class RemoteDevices {
                "leAddressAssociateCallback device: "
                        + device
                        + ", secondaryAddress:"
                        + Utils.getRedactedAddressStringFromByte(secondaryAddress));
                        + Utils.getRedactedAddressStringFromByte(secondaryAddress)
                        + ", identityAddressTypeFromNative="
                        + identityAddressTypeFromNative);

        DeviceProperties deviceProperties = getDeviceProperties(device);
        deviceProperties.setIdentityAddress(Utils.getAddressStringFromByte(secondaryAddress));
        deviceProperties.setIdentityAddressTypeFromNative(identityAddressTypeFromNative);
    }

    void aclStateChangeCallback(
+2 −1
Original line number Diff line number Diff line
@@ -798,7 +798,8 @@ static tBTM_STATUS bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda

    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;
      sec_event.proc_id_addr.id_addr = p_data->id_addr_with_type.bda;
      sec_event.proc_id_addr.id_addr_type = p_data->id_addr_with_type.type;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_LE_ADDR_ASSOC_EVT, &sec_event);
      break;

+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <string>

#include "macros.h"
#include "types/ble_address_with_type.h"
#include "types/raw_address.h"

/*****************************************************************************
@@ -57,6 +58,7 @@ inline std::string bta_status_text(const tBTA_STATUS& status) {
typedef struct {
  RawAddress pairing_bda;
  RawAddress id_addr;
  tBLE_ADDR_TYPE id_addr_type;
} tBTA_DM_PROC_ID_ADDR;

typedef struct {
Loading