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

Commit 7576e359 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

LE audio: Pass METADATA_LE_AUDIO to native am: eb1f7cf3

parents 80ff1312 eb1f7cf3
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.
+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);

+14 −1
Original line number Diff line number Diff line
@@ -640,6 +640,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,
@@ -680,7 +692,8 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
    set_dynamic_audio_buffer_size,
    generate_local_oob_data,
    allow_low_latency_audio,
    clear_event_filter};
    clear_event_filter,
    metadata_changed};

// callback reporting helpers

+3 −0
Original line number Diff line number Diff line
@@ -3618,3 +3618,6 @@ void btif_dm_clear_event_filter() {
  LOG_VERBOSE("%s: called", __func__);
  bta_dm_clear_event_filter();
}

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