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

Commit 89a12d30 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Add a way to pass CCID from Java to Native code

CCID is used as a metadata in the Enable command.
It is going to be provided by LeAudioService

Bug: 230551601
Test: atest --host bluetooth_le_audio_client_test
bluetooth_le_audio_test

Change-Id: I22d19a1af758631435266b91ea455f171ab9335c
(cherry picked from commit 0862897ce423cae8c64ce285d68bc78c853ea0ea)
parent d5f5499e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -512,6 +512,17 @@ static void setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
      group_id, input_codec_config, output_codec_config);
}

static void setCcidInformationNative(JNIEnv* env, jobject object, jint ccid,
                                     jint contextType) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sLeAudioClientInterface) {
    LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
    return;
  }

  sLeAudioClientInterface->SetCcidInformation(ccid, contextType);
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "([Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
@@ -526,6 +537,7 @@ static JNINativeMethod sMethods[] = {
     "(ILandroid/bluetooth/BluetoothLeAudioCodecConfig;Landroid/bluetooth/"
     "BluetoothLeAudioCodecConfig;)V",
     (void*)setCodecConfigPreferenceNative},
    {"setCcidInformationNative", "(II)V", (void*)setCcidInformationNative},
};

/* Le Audio Broadcaster */
+13 −0
Original line number Diff line number Diff line
@@ -265,6 +265,18 @@ public class LeAudioNativeInterface {
        setCodecConfigPreferenceNative(groupId, inputCodecConfig, outputCodecConfig);
    }

    /**
     * Set content control id (Ccid) along with context type.
     * @param ccid content control id
     * @param contextType assigned contextType
     */
    public void setCcidInformation(int ccid, int contextType) {
        if (DBG) {
            Log.d(TAG, "setCcidInformation ccid: " + ccid + " context type: " + contextType);
        }
        setCcidInformationNative(ccid, contextType);
    }

    // Native methods that call into the JNI interface
    private static native void classInitNative();
    private native void initNative(BluetoothLeAudioCodecConfig[] codecConfigOffloading);
@@ -277,4 +289,5 @@ public class LeAudioNativeInterface {
    private native void setCodecConfigPreferenceNative(int groupId,
            BluetoothLeAudioCodecConfig inputCodecConfig,
            BluetoothLeAudioCodecConfig outputCodecConfig);
    private native void setCcidInformationNative(int ccid, int contextType);
}
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ class LeAudioClient {
      int group_id,
      bluetooth::le_audio::btle_audio_codec_config_t input_codec_config,
      bluetooth::le_audio::btle_audio_codec_config_t output_codec_config) = 0;
  virtual void SetCcidInformation(int ccid, int context_type) = 0;
  virtual std::vector<RawAddress> GetGroupDevices(const int group_id) = 0;
  static void AddFromStorage(const RawAddress& addr, bool autoconnect);
  static bool IsLeAudioClientRunning();
+32 −3
Original line number Diff line number Diff line
@@ -307,6 +307,14 @@ class LeAudioClientImpl : public LeAudioClient {
    group_remove_node(group, address);
  }

  int GetCcid(le_audio::types::LeAudioContextType context_type) {
    if (ccids_.count(context_type) == 0) {
      return -1;
    }

    return ccids_[context_type];
  }

  /* This callback happens if kLeAudioDeviceSetStateTimeoutMs timeout happens
   * during transition from origin to target state
   */
@@ -612,7 +620,8 @@ class LeAudioClientImpl : public LeAudioClient {
    }

    bool result = groupStateMachine_->StartStream(
        group, static_cast<LeAudioContextType>(final_context_type));
        group, static_cast<LeAudioContextType>(final_context_type),
        GetCcid(static_cast<LeAudioContextType>(final_context_type)));
    if (result)
      stream_setup_start_timestamp_ =
          bluetooth::common::time_get_os_boottime_us();
@@ -701,6 +710,21 @@ class LeAudioClientImpl : public LeAudioClient {
    // TODO Implement
  }

  void SetCcidInformation(int ccid, int context_type) override {
    LOG_DEBUG("Ccid: %d, context type %d", ccid, context_type);

    std::bitset<16> test{static_cast<uint16_t>(context_type)};
    auto ctx_type =
        static_cast<le_audio::types::LeAudioContextType>(context_type);
    if (test.count() > 1 ||
        ctx_type >= le_audio::types::LeAudioContextType::RFU) {
      LOG_ERROR("Unknownd context type %d", context_type);
      return;
    }

    ccids_[ctx_type] = ccid;
  }

  void StartAudioSession(LeAudioDeviceGroup* group,
                          LeAudioCodecConfiguration* source_config,
                          LeAudioCodecConfiguration* sink_config) {
@@ -3446,8 +3470,9 @@ class LeAudioClientImpl : public LeAudioClient {
        stream_setup_start_timestamp_ = 0;
        if (group && group->IsPendingConfiguration()) {
          SuspendedForReconfiguration();
          if (groupStateMachine_->ConfigureStream(group,
                                                  current_context_type_)) {
          if (groupStateMachine_->ConfigureStream(
                  group, current_context_type_,
                  GetCcid(current_context_type_))) {
            /* If configuration succeed wait for new status. */
            return;
          }
@@ -3489,6 +3514,10 @@ class LeAudioClientImpl : public LeAudioClient {
  /* Speaker(s) */
  AudioState audio_sender_state_;

  /* Ccid informations */
  std::map<le_audio::types::LeAudioContextType /* context */, int /*ccid */>
      ccids_;

  /* Current stream configuration */
  LeAudioCodecConfiguration current_source_codec_config;
  LeAudioCodecConfiguration current_sink_codec_config;
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class LeAudioClientImpl : public LeAudioClient {
      bluetooth::le_audio::btle_audio_codec_config_t input_codec_config,
      bluetooth::le_audio::btle_audio_codec_config_t output_codec_config)
      override {}
  void SetCcidInformation(int ccid, int context_type) override {}
  std::vector<RawAddress> GetGroupDevices(const int group_id) override {
    return {};
  }
Loading