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

Commit ab45924f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE: Use a weak pointer to deliver updates to AVRCP devices." into pi-dev

parents ea638eee aa5490d4
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -346,9 +346,10 @@ void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state,

  // This function may be called on any thread, we need to make sure that the
  // device update happens on the main thread.
  for (auto device : instance_->connection_handler_->GetListOfDevices()) {
    do_in_bta_thread(FROM_HERE, base::Bind(&Device::SendMediaUpdate,
                                           base::Unretained(device.get()),
  for (const auto& device :
       instance_->connection_handler_->GetListOfDevices()) {
    do_in_bta_thread(FROM_HERE,
                     base::Bind(&Device::SendMediaUpdate, device.get()->Get(),
                                track_changed, play_state, queue));
  }
}
@@ -361,10 +362,10 @@ void AvrcpService::SendFolderUpdate(bool available_players,
            << " uids=" << uids;

  // Ensure that the update is posted to the correct thread
  for (auto device : instance_->connection_handler_->GetListOfDevices()) {
    do_in_bta_thread(
        FROM_HERE,
        base::Bind(&Device::SendFolderUpdate, base::Unretained(device.get()),
  for (const auto& device :
       instance_->connection_handler_->GetListOfDevices()) {
    do_in_bta_thread(FROM_HERE,
                     base::Bind(&Device::SendFolderUpdate, device.get()->Get(),
                                available_players, addressed_players, uids));
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ void Device::RegisterInterfaces(MediaInterface* media_interface,
  volume_interface_ = volume_interface;
}

base::WeakPtr<Device> Device::Get() { return weak_ptr_factory_.GetWeakPtr(); }

bool Device::IsActive() const {
  return address_ == a2dp_interface_->active_peer();
}
+6 −0
Original line number Diff line number Diff line
@@ -55,6 +55,12 @@ class Device {
      uint16_t ctrl_mtu, uint16_t browse_mtu);
  virtual ~Device() = default;

  /**
   * Gets a weak pointer to this device that is invalidated when the device is
   * disconnected.
   */
  base::WeakPtr<Device> Get();

  const RawAddress& GetAddress() const { return address_; };

  /**