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

Commit 5e5871fd authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Android (Google) Code Review
Browse files

Merge changes Idef1fe5e,I79233c7a,Idfcc87ce,I32394168,I1e91469f, ... into tm-qpr-dev

* changes:
  Fix pairing multiple devices in a row
  LE Audio: metadata parsing in native
  LE audio: Pass METADATA_LE_AUDIO to native
  LE Audio: force GATT over LE finish before returning services
  Remember what stage of service discovery are we during bonding
  Don't call BTA_DM_DISC_RES_EVT for GATT over LE services
  Don't return GATT services discovered over SDP separately
  BTA_DM_DISC_BLE_RES_EVT -> BTA_DM_GATT_OVER_LE_RES_EVT and BTA_DM_GATT_OVER_SDP_RES_EVT
parents b63a5308 95832728
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -1810,6 +1810,35 @@ static jboolean allowLowLatencyAudioNative(JNIEnv* env, jobject obj,
  return true;
}

static void metadataChangedNative(JNIEnv* env, jobject obj, jbyteArray address,
                                  jint key, jbyteArray value) {
  ALOGV("%s", __func__);
  if (!sBluetoothInterface) return;
  jbyte* addr = env->GetByteArrayElements(address, nullptr);
  if (addr == nullptr) {
    jniThrowIOException(env, EINVAL);
    return;
  }
  RawAddress addr_obj = {};
  addr_obj.FromOctets((uint8_t*)addr);

  if (value == NULL) {
    ALOGE("metadataChangedNative() ignoring NULL array");
    return;
  }

  uint16_t len = (uint16_t)env->GetArrayLength(value);
  jbyte* p_value = env->GetByteArrayElements(value, NULL);
  if (p_value == NULL) return;

  std::vector<uint8_t> val_vec(reinterpret_cast<uint8_t*>(p_value),
                               reinterpret_cast<uint8_t*>(p_value + len));
  env->ReleaseByteArrayElements(value, p_value, 0);

  sBluetoothInterface->metadata_changed(addr_obj, key, std::move(val_vec));
  return;
}

static JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    {"classInitNative", "()V", (void*)classInitNative},
@@ -1852,6 +1881,7 @@ static JNINativeMethod sMethods[] = {
    {"requestMaximumTxDataLengthNative", "([B)V",
     (void*)requestMaximumTxDataLengthNative},
    {"allowLowLatencyAudioNative", "(Z[B)Z", (void*)allowLowLatencyAudioNative},
    {"metadataChangedNative", "([BI[B)V", (void*)metadataChangedNative},
};

int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
+8 −0
Original line number Diff line number Diff line
@@ -4979,6 +4979,12 @@ public class AdapterService extends Service {
    @VisibleForTesting
    public void metadataChanged(String address, int key, byte[] value) {
        BluetoothDevice device = mRemoteDevices.getDevice(Utils.getBytesFromAddress(address));

        // pass just interesting metadata to native, to reduce spam
        if (key == BluetoothDevice.METADATA_LE_AUDIO) {
            metadataChangedNative(Utils.getBytesFromAddress(address), key, value);
        }

        if (mMetadataListeners.containsKey(device)) {
            ArrayList<IBluetoothMetadataListener> list = mMetadataListeners.get(device);
            for (IBluetoothMetadataListener listener : list) {
@@ -5624,6 +5630,8 @@ public class AdapterService extends Service {

    private native boolean allowLowLatencyAudioNative(boolean allowed, byte[] address);

    private native void metadataChangedNative(byte[] address, int key, byte[] value);

    // Returns if this is a mock object. This is currently used in testing so that we may not call
    // System.exit() while finalizing the object. Otherwise GC of mock objects unfortunately ends up
    // calling finalize() which in turn calls System.exit() and the process crashes.
+11 −5
Original line number Diff line number Diff line
@@ -1143,7 +1143,8 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
                  BD_NAME_LEN + 1);

          result.disc_ble_res.services = &gatt_uuids;
          bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result);
          bta_dm_search_cb.p_search_cback(BTA_DM_GATT_OVER_SDP_RES_EVT,
                                          &result);
        }
      } else {
        /* SDP_DB_FULL means some records with the
@@ -1336,7 +1337,7 @@ void bta_dm_search_cmpl() {

  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_GATT_OVER_LE_RES_EVT, &result);

  bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);

@@ -1356,8 +1357,13 @@ void bta_dm_search_cmpl() {
void bta_dm_disc_result(tBTA_DM_MSG* p_data) {
  APPL_TRACE_EVENT("%s", __func__);

  /* disc_res.device_type is set only when GATT discovery is finished in
   * bta_dm_gatt_disc_complete */
  bool is_gatt_over_ble = ((p_data->disc_result.result.disc_res.device_type &
                            BT_DEVICE_TYPE_BLE) != 0);

  /* if any BR/EDR service discovery has been done, report the event */
  if ((bta_dm_search_cb.services &
  if (!is_gatt_over_ble && (bta_dm_search_cb.services &
                            ((BTA_ALL_SERVICE_MASK | BTA_USER_SERVICE_MASK) &
                             ~BTA_BLE_SERVICE_MASK)))
    bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT,
+4 −2
Original line number Diff line number Diff line
@@ -419,10 +419,12 @@ typedef void(tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data);
#define BTA_DM_INQ_RES_EVT 0  /* Inquiry result for a peer device. */
#define BTA_DM_INQ_CMPL_EVT 1 /* Inquiry complete. */
#define BTA_DM_DISC_RES_EVT 2 /* Discovery result for a peer device. */
#define BTA_DM_DISC_BLE_RES_EVT \
  3 /* Discovery result for BLE GATT based servoce on a peer device. */
#define BTA_DM_GATT_OVER_LE_RES_EVT \
  3 /* GATT services over LE transport discovered */
#define BTA_DM_DISC_CMPL_EVT 4          /* Discovery complete. */
#define BTA_DM_SEARCH_CANCEL_CMPL_EVT 6 /* Search cancelled */
#define BTA_DM_DID_RES_EVT 7            /* Vendor/Product ID search result */
#define BTA_DM_GATT_OVER_SDP_RES_EVT 8  /* GATT services over SDP discovered */

typedef uint8_t tBTA_DM_SEARCH_EVT;

+3 −0
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport);

void btif_dm_clear_event_filter();

void btif_dm_metadata_changed(const RawAddress& remote_bd_addr, int key,
                              std::vector<uint8_t> value);

/*callout for reading SMP properties from Text file*/
bool btif_dm_get_smp_config(tBTE_APPL_CFG* p_cfg);

Loading