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

Commit 11f043e8 authored by Ajay Panicker's avatar Ajay Panicker Committed by Myles Watson
Browse files

AVRCP: Narrow the scope of the lock in Init and Cleanup

Bug: 80227904
Test: Disable Bluetooth while connected to a device
Change-Id: I6c77e38ebaa84e4a075ef4636d6b519d4ccfb8c5
parent 39835601
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -282,12 +282,14 @@ class VolumeInterfaceWrapper : public VolumeInterface {
void AvrcpService::Init(MediaInterface* media_interface,
                        VolumeInterface* volume_interface) {
  LOG(INFO) << "AVRCP Target Service started";
  std::lock_guard<std::mutex> lock(jni_mutex_);
  if (instance_ == nullptr) {
    instance_ = new AvrcpService();
  }

  {
    std::lock_guard<std::mutex> lock(jni_mutex_);
    jni_message_loop_ = get_jni_message_loop();
  }

  // TODO (apanicke): Add a function that sets up the SDP records once we
  // remove the AVRCP SDP setup in AVDTP (bta_av_main.cc)
@@ -310,10 +312,11 @@ void AvrcpService::Init(MediaInterface* media_interface,

void AvrcpService::Cleanup() {
  LOG(INFO) << "AVRCP Target Service stopped";
  {
    std::lock_guard<std::mutex> lock(jni_mutex_);

    task_tracker_.TryCancelAll();
    jni_message_loop_ = nullptr;
  }

  instance_->connection_handler_->CleanUp();
  instance_->connection_handler_ = nullptr;