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

Commit cc18eab2 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7066627 from bdc710f1 to sc-release

Change-Id: I86e3aeca961d650a920886fd81a3b826a944f28c
parents 80bd4f7f bdc710f1
Loading
Loading
Loading
Loading
+57 −42
Original line number Diff line number Diff line
@@ -999,8 +999,6 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
  uint16_t service = 0xFFFF;
  tSDP_PROTOCOL_ELEM pe;

  tBTA_DM_SEARCH result;

  std::vector<Uuid> uuid_list;

  if ((p_data->sdp_event.sdp_result == SDP_SUCCESS) ||
@@ -1025,6 +1023,9 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
       * service UUID */
      if (bta_dm_search_cb.service_index == BTA_MAX_SERVICE_ID) {
        /* all GATT based services */

        std::vector<Uuid> gatt_uuids;

        do {
          /* find a service record, report it */
          p_sdp_rec =
@@ -1032,16 +1033,23 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
          if (p_sdp_rec) {
            Uuid service_uuid;
            if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid)) {
              /* send result back to app now, one by one */
              gatt_uuids.push_back(service_uuid);
            }
          }
        } while (p_sdp_rec);

        if (!gatt_uuids.empty()) {
          LOG_INFO("GATT services discovered using SDP");

          // send all result back to app
          tBTA_DM_SEARCH result;
          result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
          strlcpy((char*)result.disc_ble_res.bd_name, bta_dm_get_remname(),
                  BD_NAME_LEN + 1);

              result.disc_ble_res.service = service_uuid;
          result.disc_ble_res.services = &gatt_uuids;
          bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result);
        }
          }
        } while (p_sdp_rec);
      } else {
        /* SDP_DB_FULL means some records with the
           required attributes were received */
@@ -1194,7 +1202,46 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
 ******************************************************************************/
void bta_dm_search_cmpl() {
  bta_dm_search_set_state(BTA_DM_SEARCH_IDLE);
  bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, NULL);

  uint16_t conn_id = bta_dm_search_cb.conn_id;

  /* no BLE connection, i.e. Classic service discovery end */
  if (conn_id == GATT_INVALID_CONN_ID) {
    bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);
    return;
  }

  btgatt_db_element_t* db = NULL;
  int count = 0;
  BTA_GATTC_GetGattDb(conn_id, 0x0000, 0xFFFF, &db, &count);

  if (count == 0) {
    LOG_INFO("Empty GATT database - no BLE services discovered");
    bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);
    return;
  }

  std::vector<Uuid> gatt_services;

  for (int i = 0; i < count; i++) {
    // we process service entries only
    if (db[i].type == BTGATT_DB_PRIMARY_SERVICE) {
      gatt_services.push_back(db[i].uuid);
    }
  }
  osi_free(db);

  tBTA_DM_SEARCH result;
  result.disc_ble_res.services = &gatt_services;
  result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
  strlcpy((char*)result.disc_ble_res.bd_name, (char*)bta_dm_search_cb.peer_name,
          BD_NAME_LEN + 1);

  LOG_INFO("GATT services discovered using LE Transport");
  // send all result back to app
  bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result);

  bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);
}

/*******************************************************************************
@@ -3588,37 +3635,6 @@ static void bta_dm_gattc_register(void) {
  }
}

/*******************************************************************************
 *
 * Function         bta_dm_gatt_disc_result
 *
 * Description      This function process the GATT service search result.
 *
 * Parameters:
 *
 ******************************************************************************/
static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id) {
  tBTA_DM_SEARCH result;

  /*
   * This logic will not work for gatt case.  We are checking against the
   * bluetooth profiles here
   * just copy the GATTID in raw data field and send it across.
   */

  LOG_INFO("%s service_id_uuid_len=%zu", __func__,
           service_id.uuid.GetShortestRepresentationSize());
  if (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) {
    /* send result back to app now, one by one */
    result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
    strlcpy((char*)result.disc_ble_res.bd_name, bta_dm_get_remname(),
            BD_NAME_LEN + 1);
    result.disc_ble_res.service = service_id.uuid;

    bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result);
  }
}

/*******************************************************************************
 *
 * Function         bta_dm_gatt_disc_complete
@@ -3768,7 +3784,6 @@ static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
      break;

    case BTA_GATTC_SEARCH_RES_EVT:
      bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid);
      break;

    case BTA_GATTC_SEARCH_CMPL_EVT:
+2 −1
Original line number Diff line number Diff line
@@ -419,7 +419,8 @@ typedef struct {
typedef struct {
  RawAddress bd_addr; /* BD address peer device. */
  BD_NAME bd_name;  /* Name of peer device. */
  bluetooth::Uuid service; /* GATT based Services UUID found on peer device. */
  std::vector<bluetooth::Uuid>*
      services; /* GATT based Services UUID found on peer device. */
} tBTA_DM_DISC_BLE_RES;

/* Union of all search callback structures */
+6 −1
Original line number Diff line number Diff line
@@ -206,7 +206,8 @@ void bta_cback(tBTA_GATTC_EVT, tBTA_GATTC*) {}
class BleScannerInterfaceImpl : public BleScannerInterface {
  ~BleScannerInterfaceImpl() override{};

  void RegisterScanner(RegisterCallback cb) override {
  void RegisterScanner(const bluetooth::Uuid& app_uuid,
                       RegisterCallback cb) override {
    do_in_main_thread(FROM_HERE,
                      Bind(
                          [](RegisterCallback cb) {
@@ -333,6 +334,10 @@ class BleScannerInterfaceImpl : public BleScannerInterface {
                 SyncLostCb lost_cb) override {}

  void StopSync(uint16_t handle) override {}

  void RegisterCallbacks(ScanningCallbacks* callbacks) {
    // For GD only
  }
};

BleScannerInterface* btLeScannerInstance = nullptr;
+45 −33
Original line number Diff line number Diff line
@@ -1236,6 +1236,11 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
  }
}

/* Returns true if |uuid| should be passed as device property */
static bool btif_is_interesting_le_service(bluetooth::Uuid uuid) {
  return uuid.As16Bit() == UUID_SERVCLASS_LE_HID || uuid == UUID_HEARING_AID;
}

/*******************************************************************************
 *
 * Function         btif_dm_search_services_evt
@@ -1334,34 +1339,42 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
      break;

    case BTA_DM_DISC_BLE_RES_EVT: {
      LOG_VERBOSE("service %s",
                  p_data->disc_ble_res.service.ToString().c_str());
      int num_properties = 0;
      if (p_data->disc_ble_res.service.As16Bit() == UUID_SERVCLASS_LE_HID ||
          p_data->disc_ble_res.service == UUID_HEARING_AID) {
        LOG_INFO("Found HOGP or HEARING AID UUID");
      bt_property_t prop[2];
        bt_status_t ret;
      std::vector<uint8_t> property_value;
      int num_uuids = 0;

        const auto& arr = p_data->disc_ble_res.service.To128BitBE();
      for (Uuid uuid : *p_data->disc_ble_res.services) {
        LOG_VERBOSE("service %s", uuid.ToString().c_str());
        if (btif_is_interesting_le_service(uuid)) {
          num_uuids++;
          auto valAsBe = uuid.To128BitBE();
          property_value.insert(property_value.end(), valAsBe.begin(),
                                valAsBe.end());
        }
      }

      if (num_uuids == 0) {
        LOG_INFO("No well known BLE services discovered");
        return;
      }

      RawAddress& bd_addr = p_data->disc_ble_res.bd_addr;
      prop[0].type = BT_PROPERTY_UUIDS;
        prop[0].val = (void*)arr.data();
        prop[0].len = Uuid::kNumBytes128;
      prop[0].val = (void*)property_value.data();
      prop[0].len = Uuid::kNumBytes128 * num_uuids;

      /* Also write this to the NVRAM */
        ret = btif_storage_set_remote_device_property(&bd_addr, &prop[0]);
        ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed",
                ret);
      bt_status_t ret =
          btif_storage_set_remote_device_property(&bd_addr, &prop[0]);
      ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
      num_properties++;

      /* Remote name update */
      if (strnlen((const char*)p_data->disc_ble_res.bd_name, BD_NAME_LEN)) {
        prop[1].type = BT_PROPERTY_BDNAME;
        prop[1].val = p_data->disc_ble_res.bd_name;
          prop[1].len =
              strnlen((char*)p_data->disc_ble_res.bd_name, BD_NAME_LEN);
        prop[1].len = strnlen((char*)p_data->disc_ble_res.bd_name, BD_NAME_LEN);

        ret = btif_storage_set_remote_device_property(&bd_addr, &prop[1]);
        ASSERTC(ret == BT_STATUS_SUCCESS,
@@ -1372,7 +1385,6 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
      /* Send the event to the BTIF */
      invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr,
                                         num_properties, prop);
      }
    } break;

    default: { ASSERTC(0, "unhandled search services event", event); } break;
+65 −0
Original line number Diff line number Diff line
@@ -41,6 +41,11 @@ enum class ScanApiType {
  EXTENDED = 3,
};

struct Scanner {
  Uuid app_uuid;
  bool in_use;
};

struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback {
  impl(Module* module) : module_(module), le_scanning_interface_(nullptr) {}

@@ -65,6 +70,11 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
    } else {
      api_type_ = ScanApiType::LEGACY;
    }
    scanners_ = std::vector<Scanner>(kMaxAppNum + 1);
    for (size_t i = 0; i < scanners_.size(); i++) {
      scanners_[i].app_uuid = Uuid::kEmpty;
      scanners_[i].in_use = false;
    }
    configure_scan();
  }

@@ -149,6 +159,43 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
    }
  }

  void register_scanner(const Uuid app_uuid) {
    for (uint8_t i = 1; i <= kMaxAppNum; i++) {
      if (scanners_[i].in_use && scanners_[i].app_uuid == app_uuid) {
        LOG_ERROR("Application already registered %s", app_uuid.ToString().c_str());
        scanning_callbacks_->OnScannerRegistered(app_uuid, 0x00, ScanningCallback::ScanningStatus::INTERNAL_ERROR);
        return;
      }
    }

    // valid value of scanner id : 1 ~ kMaxAppNum
    for (uint8_t i = 1; i <= kMaxAppNum; i++) {
      if (!scanners_[i].in_use) {
        scanners_[i].app_uuid = app_uuid;
        scanners_[i].in_use = true;
        scanning_callbacks_->OnScannerRegistered(app_uuid, i, ScanningCallback::ScanningStatus::SUCCESS);
        return;
      }
    }

    LOG_ERROR("Unable to register scanner, max client reached:%d", kMaxAppNum);
    scanning_callbacks_->OnScannerRegistered(app_uuid, 0x00, ScanningCallback::ScanningStatus::NO_RESOURCES);
  }

  void unregister_scanner(ScannerId scanner_id) {
    if (scanner_id <= 0 || scanner_id > kMaxAppNum) {
      LOG_WARN("Invalid scanner id");
      return;
    }

    if (scanners_[scanner_id].in_use) {
      scanners_[scanner_id].in_use = false;
      scanners_[scanner_id].app_uuid = Uuid::kEmpty;
    } else {
      LOG_WARN("Unregister scanner with unused scanner id");
    }
  }

  void start_scan(LeScanningManagerCallbacks* le_scanning_manager_callbacks) {
    registered_callback_ = le_scanning_manager_callbacks;

@@ -207,6 +254,10 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
    }
  }

  void register_scanning_callback(ScanningCallback* scanning_callbacks) {
    scanning_callbacks_ = scanning_callbacks;
  }

  void OnPause() override {
    cached_registered_callback_ = registered_callback_;
    stop_scan(common::Bind(&impl::ack_pause, common::Unretained(this)), true);
@@ -236,6 +287,8 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
  hci::LeScanningInterface* le_scanning_interface_;
  hci::LeAddressManager* le_address_manager_;
  bool address_manager_registered = false;
  ScanningCallback* scanning_callbacks_ = nullptr;
  std::vector<Scanner> scanners_;

  uint32_t interval_ms_{1000};
  uint16_t window_ms_{1000};
@@ -298,6 +351,14 @@ std::string LeScanningManager::ToString() const {
  return "Le Scanning Manager";
}

void LeScanningManager::RegisterScanner(Uuid app_uuid) {
  CallOn(pimpl_.get(), &impl::register_scanner, app_uuid);
}

void LeScanningManager::Unregister(ScannerId scanner_id) {
  CallOn(pimpl_.get(), &impl::unregister_scanner, scanner_id);
}

void LeScanningManager::StartScan(LeScanningManagerCallbacks* callbacks) {
  GetHandler()->Post(common::Bind(&impl::start_scan, common::Unretained(pimpl_.get()), callbacks));
}
@@ -306,5 +367,9 @@ void LeScanningManager::StopScan(common::Callback<void()> on_stopped) {
  GetHandler()->Post(common::Bind(&impl::stop_scan, common::Unretained(pimpl_.get()), on_stopped, false));
}

void LeScanningManager::RegisterScanningCallback(ScanningCallback* scanning_callback) {
  CallOn(pimpl_.get(), &impl::register_scanning_callback, scanning_callback);
}

}  // namespace hci
}  // namespace bluetooth
Loading