AVRCP: Narrow the scope of the lock in Init and Cleanup
Bug: 80227904
Test: Disable Bluetooth while connected to a device
Change-Id: I6c77e38ebaa84e4a075ef4636d6b519d4ccfb8c5
(cherry picked from commit 11f043e81fe45dfb6e90a53cd1e3e9e5393203c7)
diff --git a/system/btif/avrcp/avrcp_service.cc b/system/btif/avrcp/avrcp_service.cc
index 14f098f..26b826c 100644
--- a/system/btif/avrcp/avrcp_service.cc
+++ b/system/btif/avrcp/avrcp_service.cc
@@ -282,12 +282,14 @@
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();
}
- jni_message_loop_ = get_jni_message_loop();
+ {
+ 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::Cleanup() {
LOG(INFO) << "AVRCP Target Service stopped";
- std::lock_guard<std::mutex> lock(jni_mutex_);
-
- task_tracker_.TryCancelAll();
- jni_message_loop_ = nullptr;
+ {
+ std::lock_guard<std::mutex> lock(jni_mutex_);
+ task_tracker_.TryCancelAll();
+ jni_message_loop_ = nullptr;
+ }
instance_->connection_handler_->CleanUp();
instance_->connection_handler_ = nullptr;