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

Commit 8fb64ca9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Invoke address consolidate callback when BT ON"

parents 97063b96 eb182189
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -612,6 +612,7 @@ class AdapterProperties {
            if (prop == null) {
                prop = mRemoteDevices.addDeviceProperties(addrByte);
            }
            device = prop.getDevice();
            prop.setBondState(state);

            if (state == BluetoothDevice.BOND_BONDED) {
+8 −1
Original line number Diff line number Diff line
@@ -198,7 +198,14 @@ final class RemoteDevices {

    DeviceProperties getDeviceProperties(BluetoothDevice device) {
        synchronized (mDevices) {
            return mDevices.get(device.getAddress());
            DeviceProperties prop = mDevices.get(device.getAddress());
            if (prop == null) {
                String mainAddress = mDualDevicesMap.get(device.getAddress());
                if (mainAddress != null && mDevices.get(mainAddress) != null) {
                    prop = mDevices.get(mainAddress);
                }
            }
            return prop;
        }
    }

+19 −4
Original line number Diff line number Diff line
@@ -171,12 +171,27 @@ bt_status_t btif_storage_remove_bonded_device(const RawAddress* remote_bd_addr);

/*******************************************************************************
 *
 * Function         btif_storage_remove_bonded_device
 * Function         btif_storage_load_consolidate_devices
 *
 * Description      BTIF storage API - Deletes the bonded device from NVRAM
 * Description      BTIF storage API - Load the consolidate devices from NVRAM
 *                  Additionally, this API also invokes the adaper_properties_cb
 *                  and invoke_address_consolidate_cb for each of the
 *                  consolidate devices.
 *
 * Returns          BT_STATUS_SUCCESS if the deletion was successful,
 *                  BT_STATUS_FAIL otherwise
 ******************************************************************************/
void btif_storage_load_consolidate_devices(void);

/*******************************************************************************
 *
 * Function         btif_storage_load_bonded_devices
 *
 * Description      BTIF storage API - Loads all the bonded devices from NVRAM
 *                  and adds to the BTA.
 *                  Additionally, this API also invokes the adaper_properties_cb
 *                  and remote_device_properties_cb for each of the bonded
 *                  devices.
 *
 * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
 *
 ******************************************************************************/
bt_status_t btif_storage_load_bonded_devices(void);
+5 −1
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ const Uuid UUID_VC = Uuid::FromString("1844");
const Uuid UUID_CSIS = Uuid::FromString("1846");
const Uuid UUID_LE_AUDIO = Uuid::FromString("184E");
const Uuid UUID_LE_MIDI = Uuid::FromString("03B80E5A-EDE8-4B33-A751-6CE34EC4C700");
const bool enable_address_consolidate = false;  // TODO remove

#define COD_MASK 0x07FF

@@ -945,7 +946,6 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
  bt_status_t status = BT_STATUS_FAIL;
  bt_bond_state_t state = BT_BOND_STATE_NONE;
  bool skip_sdp = false;
  bool enable_address_consolidate = false;  // TODO remove

  BTIF_TRACE_DEBUG("%s: bond state=%d, success=%d, key_present=%d", __func__,
                   pairing_cb.state, p_auth_cmpl->success,
@@ -1541,6 +1541,10 @@ void BTIF_dm_enable() {
  /* clear control blocks */
  memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
  pairing_cb.bond_type = tBTM_SEC_DEV_REC::BOND_TYPE_PERSISTENT;
  if (enable_address_consolidate) {
    LOG_INFO("enable address consolidate");
    btif_storage_load_consolidate_devices();
  }

  /* This function will also trigger the adapter_properties_cb
  ** and bonded_devices_info_cb
+54 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@
#include <string.h>
#include <time.h>

#include <vector>

#include "bta_csis_api.h"
#include "bta_groups.h"
#include "bta_hd_api.h"
@@ -924,6 +926,58 @@ static void remove_devices_with_sample_ltk() {
  }
}

/*******************************************************************************
 *
 * Function         btif_storage_load_consolidate_devices
 *
 * Description      BTIF storage API - Load the consolidate devices from NVRAM
 *                  Additionally, this API also invokes the adaper_properties_cb
 *                  and invoke_address_consolidate_cb for each of the
 *                  consolidate devices.
 *
 ******************************************************************************/
void btif_storage_load_consolidate_devices(void) {
  btif_bonded_devices_t bonded_devices;
  btif_in_fetch_bonded_devices(&bonded_devices, 1);

  std::vector<std::pair<RawAddress, RawAddress>> consolidated_devices;
  for (uint16_t i = 0; i < bonded_devices.num_devices; i++) {
    // RawAddress* p_remote_addr;
    tBTA_LE_KEY_VALUE key = {};
    if (btif_storage_get_ble_bonding_key(
            bonded_devices.devices[i], BTM_LE_KEY_PID, (uint8_t*)&key,
            sizeof(tBTM_LE_PID_KEYS)) == BT_STATUS_SUCCESS) {
      if (bonded_devices.devices[i] != key.pid_key.identity_addr) {
        LOG_INFO("found consolidated device %s %s",
                 bonded_devices.devices[i].ToString().c_str(),
                 key.pid_key.identity_addr.ToString().c_str());
        consolidated_devices.emplace_back(bonded_devices.devices[i],
                                          key.pid_key.identity_addr);
      }
    }
  }

  bt_property_t adapter_prop = {};
  /* Send the adapter_properties_cb with bonded consolidated device */
  {
    /* BONDED_DEVICES */
    auto devices_list =
        std::make_unique<RawAddress[]>(consolidated_devices.size());
    adapter_prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES;
    adapter_prop.len = consolidated_devices.size() * sizeof(RawAddress);
    adapter_prop.val = devices_list.get();
    for (uint16_t i = 0; i < consolidated_devices.size(); i++) {
      devices_list[i] = consolidated_devices[i].first;
    }
    btif_adapter_properties_evt(BT_STATUS_SUCCESS, /* num_props */ 1,
                                &adapter_prop);
  }

  for (const auto& device : consolidated_devices) {
    invoke_address_consolidate_cb(device.first, device.second);
  }
}

/*******************************************************************************
 *
 * Function         btif_storage_load_bonded_devices