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

Commit d3bb7468 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

LE audio: Pass METADATA_LE_AUDIO to native

Bug: 258651822
Test: manual, pair with FP capable LE Audio device
Change-Id: Idfcc87ceb707a526fbfb008ec69dc6440db7c880
parent d508cc93
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -1816,6 +1816,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},
@@ -1858,6 +1887,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
@@ -5139,6 +5139,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) {
@@ -5706,6 +5712,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.
+2 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ void btif_dm_allow_wake_by_hid();
void btif_dm_restore_filter_accept_list();
void btif_dm_set_default_event_mask_except(uint64_t mask, uint64_t le_mask);
void btif_dm_set_event_filter_inquiry_result_all_devices();
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);
+14 −1
Original line number Diff line number Diff line
@@ -961,6 +961,18 @@ static bool allow_low_latency_audio(bool allowed, const RawAddress& address) {
  return true;
}

static void metadata_changed(const RawAddress& remote_bd_addr, int key,
                             std::vector<uint8_t> value) {
  if (!interface_ready()) {
    LOG_ERROR("Interface not ready!");
    return;
  }

  do_in_main_thread(
      FROM_HERE, base::BindOnce(btif_dm_metadata_changed, remote_bd_addr, key,
                                std::move(value)));
}

EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
    sizeof(bluetoothInterface),
    .init = init,
@@ -1013,7 +1025,8 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
    .allow_wake_by_hid = allow_wake_by_hid,
    .set_event_filter_connection_setup_all_devices =
        set_event_filter_connection_setup_all_devices,
    .get_wbs_supported = get_wbs_supported};
    .get_wbs_supported = get_wbs_supported,
    .metadata_changed = metadata_changed};

// callback reporting helpers

+3 −0
Original line number Diff line number Diff line
@@ -3700,3 +3700,6 @@ void btif_dm_set_event_filter_inquiry_result_all_devices() {
  // Autoplumbed
  BTA_DmSetEventFilterInquiryResultAllDevices();
}

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