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

Commit 6bce3e83 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge changes I942ee991,I3decc84a,I33a5d93b into main am: fea93458 am: 7e443e2a

parents 4f05d3ac 7e443e2a
Loading
Loading
Loading
Loading
+12 −10
Original line number Original line Diff line number Diff line
@@ -202,11 +202,11 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArr
}
}


static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */, jint focus_state) {
static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */, jint focus_state) {
  btif_av_sink_set_audio_focus_state((uint8_t)focus_state);
  btif_av_sink_set_audio_focus_state(static_cast<uint8_t>(focus_state));
}
}


static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */, jfloat gain) {
static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */, jfloat gain) {
  btif_av_sink_set_audio_track_gain((float)gain);
  btif_av_sink_set_audio_track_gain(static_cast<float>(gain));
}
}


static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
@@ -217,7 +217,7 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteAr
  }
  }


  RawAddress rawAddress;
  RawAddress rawAddress;
  rawAddress.FromOctets((uint8_t*)addr);
  rawAddress.FromOctets(reinterpret_cast<uint8_t*>(addr));


  log::info("{}", rawAddress);
  log::info("{}", rawAddress);
  bt_status_t status = btif_av_sink_set_active_device(rawAddress);
  bt_status_t status = btif_av_sink_set_active_device(rawAddress);
@@ -231,13 +231,15 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteAr


int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
  const JNINativeMethod methods[] = {
  const JNINativeMethod methods[] = {
          {"initNative", "(I)V", (void*)initNative},
          {"initNative", "(I)V", reinterpret_cast<void*>(initNative)},
          {"cleanupNative", "()V", (void*)cleanupNative},
          {"cleanupNative", "()V", reinterpret_cast<void*>(cleanupNative)},
          {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
          {"connectA2dpNative", "([B)Z", reinterpret_cast<void*>(connectA2dpNative)},
          {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
          {"disconnectA2dpNative", "([B)Z", reinterpret_cast<void*>(disconnectA2dpNative)},
          {"informAudioFocusStateNative", "(I)V", (void*)informAudioFocusStateNative},
          {"informAudioFocusStateNative", "(I)V",
          {"informAudioTrackGainNative", "(F)V", (void*)informAudioTrackGainNative},
           reinterpret_cast<void*>(informAudioFocusStateNative)},
          {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
          {"informAudioTrackGainNative", "(F)V",
           reinterpret_cast<void*>(informAudioTrackGainNative)},
          {"setActiveDeviceNative", "([B)Z", reinterpret_cast<void*>(setActiveDeviceNative)},
  };
  };
  const int result = REGISTER_NATIVE_METHODS(
  const int result = REGISTER_NATIVE_METHODS(
          env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", methods);
          env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", methods);
+28 −12
Original line number Original line Diff line number Diff line
@@ -23,12 +23,15 @@


#include <mutex>
#include <mutex>
#include <sstream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>


#include "bta/sys/bta_sys.h"
#include "bta/sys/bta_sys.h"
#include "btif_av.h"
#include "btif/include/btif_av.h"
#include "btif_common.h"
#include "btif/include/btif_common.h"
#include "device.h"
#include "osi/include/osi.h"
#include "osi/include/osi.h"
#include "profile/avrcp/device.h"
#include "stack/include/a2dp_api.h"
#include "stack/include/a2dp_api.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/bt_uuid16.h"
@@ -37,7 +40,7 @@
#include "types/bluetooth/uuid.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
#include "types/raw_address.h"


using namespace bluetooth::legacy::stack::sdp;
using bluetooth::legacy::stack::sdp::get_legacy_stack_sdp_api;


namespace bluetooth {
namespace bluetooth {
namespace avrcp {
namespace avrcp {
@@ -69,7 +72,6 @@ class A2dpInterfaceImpl : public A2dpInterface {


    return A2DP_FindService(UUID_SERVCLASS_AUDIO_SINK, peer_address, &db_params, p_cback);
    return A2DP_FindService(UUID_SERVCLASS_AUDIO_SINK, peer_address, &db_params, p_cback);
  }
  }

} a2dp_interface_;
} a2dp_interface_;


class AvrcpInterfaceImpl : public AvrcpInterface {
class AvrcpInterfaceImpl : public AvrcpInterface {
@@ -115,7 +117,6 @@ public:
  void SaveControllerVersion(const RawAddress& bdaddr, uint16_t version) override {
  void SaveControllerVersion(const RawAddress& bdaddr, uint16_t version) override {
    AVRC_SaveControllerVersion(bdaddr, version);
    AVRC_SaveControllerVersion(bdaddr, version);
  }
  }

} avrcp_interface_;
} avrcp_interface_;


class SdpInterfaceImpl : public SdpInterface {
class SdpInterfaceImpl : public SdpInterface {
@@ -147,7 +148,7 @@ public:
// switching/synchronization so the devices don't have to worry about it.
// switching/synchronization so the devices don't have to worry about it.
class MediaInterfaceWrapper : public MediaInterface {
class MediaInterfaceWrapper : public MediaInterface {
public:
public:
  MediaInterfaceWrapper(MediaInterface* cb) : wrapped_(cb) {}
  explicit MediaInterfaceWrapper(MediaInterface* cb) : wrapped_(cb) {}


  void SendKeyEvent(uint8_t key, KeyState state) override {
  void SendKeyEvent(uint8_t key, KeyState state) override {
    do_in_jni_thread(
    do_in_jni_thread(
@@ -250,7 +251,7 @@ private:
// switching/synchronization so the devices don't have to worry about it.
// switching/synchronization so the devices don't have to worry about it.
class VolumeInterfaceWrapper : public VolumeInterface {
class VolumeInterfaceWrapper : public VolumeInterface {
public:
public:
  VolumeInterfaceWrapper(VolumeInterface* interface) : wrapped_(interface) {}
  explicit VolumeInterfaceWrapper(VolumeInterface* interface) : wrapped_(interface) {}


  void DeviceConnected(const RawAddress& bdaddr) override {
  void DeviceConnected(const RawAddress& bdaddr) override {
    do_in_jni_thread(base::Bind(static_cast<void (VolumeInterface::*)(const RawAddress&)>(
    do_in_jni_thread(base::Bind(static_cast<void (VolumeInterface::*)(const RawAddress&)>(
@@ -288,7 +289,8 @@ private:
// switching/synchronization so the devices don't have to worry about it.
// switching/synchronization so the devices don't have to worry about it.
class PlayerSettingsInterfaceWrapper : public PlayerSettingsInterface {
class PlayerSettingsInterfaceWrapper : public PlayerSettingsInterface {
public:
public:
  PlayerSettingsInterfaceWrapper(PlayerSettingsInterface* interface) : wrapped_(interface) {}
  explicit PlayerSettingsInterfaceWrapper(PlayerSettingsInterface* interface)
      : wrapped_(interface) {}


  void ListPlayerSettings(ListPlayerSettingsCallback cb) override {
  void ListPlayerSettings(ListPlayerSettingsCallback cb) override {
    auto cb_lambda = [](const ListPlayerSettingsCallback& cb,
    auto cb_lambda = [](const ListPlayerSettingsCallback& cb,
@@ -458,23 +460,34 @@ ServiceInterface* AvrcpService::GetServiceInterface() {


void AvrcpService::ConnectDevice(const RawAddress& bdaddr) {
void AvrcpService::ConnectDevice(const RawAddress& bdaddr) {
  log::info("address={}", bdaddr);
  log::info("address={}", bdaddr);

  if (connection_handler_ == nullptr) {
    return;
  }
  connection_handler_->ConnectDevice(bdaddr);
  connection_handler_->ConnectDevice(bdaddr);
}
}


void AvrcpService::DisconnectDevice(const RawAddress& bdaddr) {
void AvrcpService::DisconnectDevice(const RawAddress& bdaddr) {
  log::info("address={}", bdaddr);
  log::info("address={}", bdaddr);
  if (connection_handler_ == nullptr) {
    return;
  }
  connection_handler_->DisconnectDevice(bdaddr);
  connection_handler_->DisconnectDevice(bdaddr);
}
}


void AvrcpService::SetBipClientStatus(const RawAddress& bdaddr, bool connected) {
void AvrcpService::SetBipClientStatus(const RawAddress& bdaddr, bool connected) {
  log::info("address={}, connected={}", bdaddr, connected);
  log::info("address={}, connected={}", bdaddr, connected);
  if (connection_handler_ == nullptr) {
    return;
  }
  connection_handler_->SetBipClientStatus(bdaddr, connected);
  connection_handler_->SetBipClientStatus(bdaddr, connected);
}
}


void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state, bool queue) {
void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state, bool queue) {
  log::info("track_changed={} :  play_state={} :  queue={}", track_changed, play_state, queue);
  log::info("track_changed={} :  play_state={} :  queue={}", track_changed, play_state, queue);


  if (instance_ == nullptr || instance_->connection_handler_ == nullptr) {
    return;
  }
  // This function may be called on any thread, we need to make sure that the
  // This function may be called on any thread, we need to make sure that the
  // device update happens on the main thread.
  // device update happens on the main thread.
  for (const auto& device : instance_->connection_handler_->GetListOfDevices()) {
  for (const auto& device : instance_->connection_handler_->GetListOfDevices()) {
@@ -487,6 +500,9 @@ void AvrcpService::SendFolderUpdate(bool available_players, bool addressed_playe
  log::info("available_players={} :  addressed_players={} :  uids={}", available_players,
  log::info("available_players={} :  addressed_players={} :  uids={}", available_players,
            addressed_players, uids);
            addressed_players, uids);


  if (instance_ == nullptr || instance_->connection_handler_ == nullptr) {
    return;
  }
  // Ensure that the update is posted to the correct thread
  // Ensure that the update is posted to the correct thread
  for (const auto& device : instance_->connection_handler_->GetListOfDevices()) {
  for (const auto& device : instance_->connection_handler_->GetListOfDevices()) {
    do_in_main_thread(base::BindOnce(&Device::SendFolderUpdate, device.get()->Get(),
    do_in_main_thread(base::BindOnce(&Device::SendFolderUpdate, device.get()->Get(),
@@ -544,7 +560,7 @@ void AvrcpService::ServiceInterfaceImpl::Init(MediaInterface* media_interface,
                                              PlayerSettingsInterface* player_settings_interface) {
                                              PlayerSettingsInterface* player_settings_interface) {
  std::lock_guard<std::mutex> lock(service_interface_lock_);
  std::lock_guard<std::mutex> lock(service_interface_lock_);


  // TODO: This function should block until the service is completely up so
  // TODO(apanicke): This function should block until the service is completely up so
  // that its possible to call Get() on the service immediately after calling
  // that its possible to call Get() on the service immediately after calling
  // init without issues.
  // init without issues.