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

Commit 3bd7ea9c authored by Chris Manton's avatar Chris Manton
Browse files

btif::gatt Clean up transport selection

Bug: 354325012
Test: m .
Flag: EXEMPT, Mechanical Refactor

Change-Id: I3167a18b44ac6777d2f06eadf1c0f42b9e0e5c59
parent 94bca219
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@
#include "stack/include/pan_api.h"
#include "stack/include/sdp_api.h"
#include "storage/config_keys.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"

using bluetooth::csis::CsisClientInterface;
+30 −21
Original line number Diff line number Diff line
@@ -37,14 +37,13 @@
#include <cstdlib>
#include <string>

#include "bta/include/bta_api.h"
#include "bta/include/bta_gatt_api.h"
#include "bta/include/bta_sec_api.h"
#include "bta_api.h"
#include "bta_gatt_api.h"
#include "btif_common.h"
#include "btif_config.h"
#include "btif_gatt.h"
#include "btif_gatt_util.h"
#include "gatt_api.h"
#include "btif/include/btif_common.h"
#include "btif/include/btif_config.h"
#include "btif/include/btif_gatt.h"
#include "btif/include/btif_gatt_util.h"
#include "hci/controller_interface.h"
#include "internal_include/bte_appl.h"
#include "main/shim/entry.h"
@@ -53,6 +52,7 @@
#include "stack/include/acl_api_types.h"
#include "stack/include/btm_ble_sec_api.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/gatt_api.h"
#include "stack/include/main_thread.h"
#include "storage/config_keys.h"
#include "types/ble_address_with_type.h"
@@ -119,6 +119,21 @@ static btif_test_cb_t test_cb;

namespace {

tBT_TRANSPORT to_bt_transport(int val) {
  switch (val) {
    case 0:
      return BT_TRANSPORT_AUTO;
    case 1:
      return BT_TRANSPORT_BR_EDR;
    case 2:
      return BT_TRANSPORT_LE;
    default:
      break;
  }
  log::warn("Passed unexpected transport value:{}", val);
  return BT_TRANSPORT_AUTO;
}

uint8_t rssi_request_client_if;

static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) {
@@ -278,10 +293,9 @@ static bt_status_t btif_gattc_unregister_app(int client_if) {
}

void btif_gattc_open_impl(int client_if, RawAddress address, tBLE_ADDR_TYPE addr_type,
                          bool is_direct, int transport_p, bool opportunistic,
                          bool is_direct, tBT_TRANSPORT transport, bool opportunistic,
                          int initiating_phys) {
  int device_type = BT_DEVICE_TYPE_UNKNOWN;
  tBT_TRANSPORT transport = (tBT_TRANSPORT)BT_TRANSPORT_LE;

  if (addr_type == BLE_ADDR_RANDOM) {
    device_type = BT_DEVICE_TYPE_BLE;
@@ -312,9 +326,7 @@ void btif_gattc_open_impl(int client_if, RawAddress address, tBLE_ADDR_TYPE addr
  }

  // Determine transport
  if (transport_p != BT_TRANSPORT_AUTO) {
    transport = transport_p;
  } else {
  if (transport == BT_TRANSPORT_AUTO) {
    switch (device_type) {
      case BT_DEVICE_TYPE_BREDR:
        transport = BT_TRANSPORT_BR_EDR;
@@ -325,21 +337,18 @@ void btif_gattc_open_impl(int client_if, RawAddress address, tBLE_ADDR_TYPE addr
        break;

      case BT_DEVICE_TYPE_DUMO:
        if (addr_type == BLE_ADDR_RANDOM) {
          transport = BT_TRANSPORT_LE;
        } else {
          transport = BT_TRANSPORT_BR_EDR;
        }
        transport = (addr_type == BLE_ADDR_RANDOM) ? BT_TRANSPORT_LE : BT_TRANSPORT_BR_EDR;
        break;

      default:
        log::error("Unknown device type {}", device_type);
        log::error("Unknown device type {}", DeviceTypeText(device_type));
        break;
    }
  }

  // Connect!
  log::info("Transport={}, device type={}, address type ={}, phy={}", transport, device_type,
            addr_type, initiating_phys);
  log::info("Transport={}, device type={}, address type ={}, phy={}", bt_transport_text(transport),
            DeviceTypeText(device_type), addr_type, initiating_phys);
  tBTM_BLE_CONN_TYPE type = is_direct ? BTM_BLE_DIRECT_CONNECTION : BTM_BLE_BKG_CONNECT_ALLOW_LIST;
  BTA_GATTC_Open(client_if, address, addr_type, type, transport, opportunistic, initiating_phys);
}
@@ -350,7 +359,7 @@ static bt_status_t btif_gattc_open(int client_if, const RawAddress& bd_addr, uin
  CHECK_BTGATT_INIT();
  // Closure will own this value and free it.
  return do_in_jni_thread(Bind(&btif_gattc_open_impl, client_if, bd_addr, addr_type, is_direct,
                               transport, opportunistic, initiating_phys));
                               to_bt_transport(transport), opportunistic, initiating_phys));
}

void btif_gattc_close_impl(int client_if, RawAddress address, int conn_id) {
+48 −19
Original line number Diff line number Diff line
@@ -35,11 +35,11 @@
#include <stdlib.h>
#include <string.h>

#include "bta/include/bta_gatt_api.h"
#include "bta/include/bta_sec_api.h"
#include "bta_gatt_api.h"
#include "btif_common.h"
#include "btif_gatt.h"
#include "btif_gatt_util.h"
#include "btif/include/btif_common.h"
#include "btif/include/btif_gatt.h"
#include "btif/include/btif_gatt_util.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/btm_client_interface.h"
@@ -57,6 +57,23 @@ using bluetooth::Uuid;
using std::vector;
using namespace bluetooth;

namespace {
tBT_TRANSPORT to_bt_transport(int val) {
  switch (val) {
    case 0:
      return BT_TRANSPORT_AUTO;
    case 1:
      return BT_TRANSPORT_BR_EDR;
    case 2:
      return BT_TRANSPORT_LE;
    default:
      break;
  }
  log::warn("Passed unexpected transport value:{}", val);
  return BT_TRANSPORT_AUTO;
}
}  // namespace

/*******************************************************************************
 *  Constants & Macros
 ******************************************************************************/
@@ -273,11 +290,10 @@ static bt_status_t btif_gatts_unregister_app(int server_if) {
}

static void btif_gatts_open_impl(int server_if, const RawAddress& address, bool is_direct,
                                 int transport_param) {
                                 tBT_TRANSPORT transport) {
  // Ensure device is in inquiry database
  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
  int device_type = 0;
  tBT_TRANSPORT transport = BT_TRANSPORT_LE;

  if (btif_get_address_type(address, &addr_type) && btif_get_device_type(address, &device_type) &&
      device_type != BT_DEVICE_TYPE_BREDR) {
@@ -285,9 +301,7 @@ static void btif_gatts_open_impl(int server_if, const RawAddress& address, bool
  }

  // Determine transport
  if (transport_param != BT_TRANSPORT_AUTO) {
    transport = transport_param;
  } else {
  if (transport == BT_TRANSPORT_AUTO) {
    switch (device_type) {
      case BT_DEVICE_TYPE_BREDR:
        transport = BT_TRANSPORT_BR_EDR;
@@ -300,6 +314,10 @@ static void btif_gatts_open_impl(int server_if, const RawAddress& address, bool
      case BT_DEVICE_TYPE_DUMO:
        transport = BT_TRANSPORT_BR_EDR;
        break;

      default:
        log::error("Unknown device type {}", DeviceTypeText(device_type));
        break;
    }
  }

@@ -311,22 +329,32 @@ static void btif_gatts_open_impl(int server_if, const RawAddress& address, bool
// ble_gatt_server_use_address_type_in_connection is enabled.
static void btif_gatts_open_impl_use_address_type(int server_if, const RawAddress& address,
                                                  tBLE_ADDR_TYPE addr_type, bool is_direct,
                                                  int transport_param) {
                                                  tBT_TRANSPORT transport) {
  int device_type = BT_DEVICE_TYPE_UNKNOWN;
  if (btif_get_address_type(address, &addr_type) && btif_get_device_type(address, &device_type) &&
      device_type != BT_DEVICE_TYPE_BREDR) {
    BTA_DmAddBleDevice(address, addr_type, device_type);
  }

  if (transport_param != BT_TRANSPORT_AUTO) {
    log::info("addr_type:{}, transport_param:{}", addr_type, transport_param);
    BTA_GATTS_Open(server_if, address, addr_type, is_direct, transport_param);
    return;
  // Determine transport
  if (transport == BT_TRANSPORT_AUTO) {
    switch (device_type) {
      case BT_DEVICE_TYPE_BREDR:
        transport = BT_TRANSPORT_BR_EDR;
        break;

      case BT_DEVICE_TYPE_BLE:
      case BT_DEVICE_TYPE_DUMO:
        transport = BT_TRANSPORT_LE;
        break;

      default:
        log::error("Unknown device type {}", DeviceTypeText(device_type));
        break;
    }
  }

  tBT_TRANSPORT transport =
          (device_type == BT_DEVICE_TYPE_BREDR) ? BT_TRANSPORT_BR_EDR : BT_TRANSPORT_LE;
  log::info("addr_type:{}, transport:{}", addr_type, transport);
  log::info("addr_type:{}, transport:{}", addr_type, bt_transport_text(transport));
  BTA_GATTS_Open(server_if, address, addr_type, is_direct, transport);
}

@@ -336,9 +364,10 @@ static bt_status_t btif_gatts_open(int server_if, const RawAddress& bd_addr, uin

  if (com::android::bluetooth::flags::ble_gatt_server_use_address_type_in_connection()) {
    return do_in_jni_thread(Bind(&btif_gatts_open_impl_use_address_type, server_if, bd_addr,
                                 addr_type, is_direct, transport));
                                 addr_type, is_direct, to_bt_transport(transport)));
  } else {
    return do_in_jni_thread(Bind(&btif_gatts_open_impl, server_if, bd_addr, is_direct, transport));
    return do_in_jni_thread(
            Bind(&btif_gatts_open_impl, server_if, bd_addr, is_direct, to_bt_transport(transport)));
  }
}