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

Commit c62a4838 authored by Stanley Tng's avatar Stanley Tng Committed by Andre Eisenbach
Browse files

Allow the Bluetooth MAC address to be updated asynchronously (3/3)

There are intermittent issues where either the returned Bluetooth
MAC address to Java framework is uninitialized or this address update
arrives too late. This fix will do 2 things:
(1) Returns error when MAC address is unavailable in the native code.
(2) Updates the MAC address later by adding a new broadcast event.

Test: Check address for these cases: factory reset, system reboot, and
Bluetooth re-enable.
Bug: 36709382

Change-Id: I7b1c526ee227897c003ac921078f317f96b92604
parent 7968d0e1
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -591,7 +591,7 @@ bt_status_t btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) {

static bt_status_t btif_in_get_adapter_properties(void) {
  bt_property_t properties[6];
  uint32_t num_props;
  uint32_t num_props = 0;

  bt_bdaddr_t addr;
  bt_bdname_t name;
@@ -599,13 +599,17 @@ static bt_status_t btif_in_get_adapter_properties(void) {
  uint32_t disc_timeout;
  bt_bdaddr_t bonded_devices[BTM_SEC_MAX_DEVICE_RECORDS];
  bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
  num_props = 0;
  bt_status_t status;

  /* BD_ADDR */
  BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDADDR,
                             sizeof(addr), &addr);
  btif_storage_get_adapter_property(&properties[num_props]);
  status = btif_storage_get_adapter_property(&properties[num_props]);
  // Add BT_PROPERTY_BDADDR property into list only when successful.
  // Otherwise, skip this property entry.
  if (status == BT_STATUS_SUCCESS) {
    num_props++;
  }

  /* BD_NAME */
  BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDNAME,
+25 −14
Original line number Diff line number Diff line
@@ -83,14 +83,16 @@
/* This is a local property to add a device found */
#define BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP 0xFF

#define BTIF_STORAGE_GET_ADAPTER_PROP(t, v, l, p) \
// TODO: This macro should be converted to a function
#define BTIF_STORAGE_GET_ADAPTER_PROP(s, t, v, l, p) \
  do {                                               \
    (p).type = (t);                                  \
    (p).val = (v);                                   \
    (p).len = (l);                                   \
    btif_storage_get_adapter_property(&(p));      \
    s = btif_storage_get_adapter_property(&(p));     \
  } while (0)

// TODO: This macro should be converted to a function
#define BTIF_STORAGE_GET_REMOTE_PROP(b, t, v, l, p)     \
  do {                                                  \
    (p).type = (t);                                     \
@@ -548,7 +550,11 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) {
    /* Fetch the local BD ADDR */
    const controller_t* controller = controller_get_interface();
    if (controller->get_is_ready() == false) {
      LOG_ERROR(LOG_TAG, "%s: Controller not ready!", __func__);
      LOG_ERROR(LOG_TAG,
                "%s: Controller not ready! Unable to return Bluetooth Address",
                __func__);
      memset(bd_addr, 0, sizeof(bt_bdaddr_t));
      return BT_STATUS_FAIL;
    } else {
      LOG_ERROR(LOG_TAG, "%s: Controller ready!", __func__);
      memcpy(bd_addr, controller->get_address(), sizeof(bt_bdaddr_t));
@@ -794,6 +800,7 @@ bt_status_t btif_storage_load_bonded_devices(void) {
  uint32_t disc_timeout;
  bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
  bt_uuid_t remote_uuids[BT_MAX_NUM_UUIDS];
  bt_status_t status;

  btif_in_fetch_bonded_devices(&bonded_devices, 1);

@@ -802,13 +809,17 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    memset(adapter_props, 0, sizeof(adapter_props));

    /* BD_ADDR */
    BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDADDR, &addr, sizeof(addr),
                                  adapter_props[num_props]);
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_BDADDR, &addr,
                                  sizeof(addr), adapter_props[num_props]);
    // Add BT_PROPERTY_BDADDR property into list only when successful.
    // Otherwise, skip this property entry.
    if (status == BT_STATUS_SUCCESS) {
      num_props++;
    }

    /* BD_NAME */
    BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDNAME, &name, sizeof(name),
                                  adapter_props[num_props]);
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_BDNAME, &name,
                                  sizeof(name), adapter_props[num_props]);
    num_props++;

    /* SCAN_MODE */
@@ -823,7 +834,7 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    num_props++;

    /* DISC_TIMEOUT */
    BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
                                  &disc_timeout, sizeof(disc_timeout),
                                  adapter_props[num_props]);
    num_props++;
@@ -841,7 +852,7 @@ bt_status_t btif_storage_load_bonded_devices(void) {
    num_props++;

    /* LOCAL UUIDs */
    BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_UUIDS, local_uuids,
    BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_UUIDS, local_uuids,
                                  sizeof(local_uuids),
                                  adapter_props[num_props]);
    num_props++;