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

Commit dedbea20 authored by Sal Savage's avatar Sal Savage
Browse files

Pass BIP client status down and use it to decide to send image handles

The new avrcp architecture has the design such that all requests to Java
are agnostic of which device is asking for them. However, image handles
are not meant to be sent if there is no BIP connection with that device.

Rather than invalidate the previous design assumption, this patch sends
that status down to the connection handler and device objects to use
when building response packets. The image handles, if included, will be
automatically removed if there is no client connection. If no image
handles are sent, none will be included.

Tag: #feature
Bug: 153076316
Test: Build, flash, make sure existing metadata isn't impacted and is
still sent when requested. Make sure imge handles are sent, when they
exist, if and only if we've connected a client on the Java side BIP OBEX
server.

Change-Id: If252abe120188df2bcdabed22382fba070d17f32
parent bafad799
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -401,6 +401,13 @@ void AvrcpService::DisconnectDevice(const RawAddress& bdaddr) {
  connection_handler_->DisconnectDevice(bdaddr);
  connection_handler_->DisconnectDevice(bdaddr);
}
}


void AvrcpService::SetBipClientStatus(const RawAddress& bdaddr,
                                      bool connected) {
  LOG(INFO) << __PRETTY_FUNCTION__ << ": address=" << bdaddr.ToString()
            << ", connected=" << connected;
  connection_handler_->SetBipClientStatus(bdaddr, connected);
}

void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state,
void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state,
                                   bool queue) {
                                   bool queue) {
  LOG(INFO) << __PRETTY_FUNCTION__ << " track_changed=" << track_changed
  LOG(INFO) << __PRETTY_FUNCTION__ << " track_changed=" << track_changed
@@ -500,6 +507,15 @@ bool AvrcpService::ServiceInterfaceImpl::DisconnectDevice(
  return true;
  return true;
}
}


void AvrcpService::ServiceInterfaceImpl::SetBipClientStatus(
    const RawAddress& bdaddr, bool connected) {
  std::lock_guard<std::mutex> lock(service_interface_lock_);
  CHECK(instance_ != nullptr);
  do_in_main_thread(FROM_HERE, base::Bind(&AvrcpService::SetBipClientStatus,
                                          base::Unretained(instance_), bdaddr,
                                          connected));
}

bool AvrcpService::ServiceInterfaceImpl::Cleanup() {
bool AvrcpService::ServiceInterfaceImpl::Cleanup() {
  std::lock_guard<std::mutex> lock(service_interface_lock_);
  std::lock_guard<std::mutex> lock(service_interface_lock_);


+3 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,8 @@ class AvrcpService : public MediaCallbacks {
  void ConnectDevice(const RawAddress& bdaddr);
  void ConnectDevice(const RawAddress& bdaddr);
  void DisconnectDevice(const RawAddress& bdaddr);
  void DisconnectDevice(const RawAddress& bdaddr);


  void SetBipClientStatus(const RawAddress& bdaddr, bool connected);

  // Functions inherited from MediaCallbacks in order to receive updates
  // Functions inherited from MediaCallbacks in order to receive updates
  void SendMediaUpdate(bool track_changed, bool play_state,
  void SendMediaUpdate(bool track_changed, bool play_state,
                       bool queue) override;
                       bool queue) override;
@@ -77,6 +79,7 @@ class AvrcpService : public MediaCallbacks {
    void UnregisterBipServer() override;
    void UnregisterBipServer() override;
    bool ConnectDevice(const RawAddress& bdaddr) override;
    bool ConnectDevice(const RawAddress& bdaddr) override;
    bool DisconnectDevice(const RawAddress& bdaddr) override;
    bool DisconnectDevice(const RawAddress& bdaddr) override;
    void SetBipClientStatus(const RawAddress& bdaddr, bool connected) override;
    bool Cleanup() override;
    bool Cleanup() override;


   private:
   private:
+1 −0
Original line number Original line Diff line number Diff line
@@ -180,6 +180,7 @@ class ServiceInterface {
  virtual void UnregisterBipServer() = 0;
  virtual void UnregisterBipServer() = 0;
  virtual bool ConnectDevice(const RawAddress& bdaddr) = 0;
  virtual bool ConnectDevice(const RawAddress& bdaddr) = 0;
  virtual bool DisconnectDevice(const RawAddress& bdaddr) = 0;
  virtual bool DisconnectDevice(const RawAddress& bdaddr) = 0;
  virtual void SetBipClientStatus(const RawAddress& bdaddr, bool connected) = 0;
  virtual bool Cleanup() = 0;
  virtual bool Cleanup() = 0;


 protected:
 protected:
+10 −0
Original line number Original line Diff line number Diff line
@@ -149,6 +149,16 @@ bool ConnectionHandler::DisconnectDevice(const RawAddress& bdaddr) {
  return false;
  return false;
}
}


void ConnectionHandler::SetBipClientStatus(const RawAddress& bdaddr,
                                           bool connected) {
  for (auto it = device_map_.begin(); it != device_map_.end(); it++) {
    if (bdaddr == it->second->GetAddress()) {
      it->second->SetBipClientStatus(connected);
      return;
    }
  }
}

std::vector<std::shared_ptr<Device>> ConnectionHandler::GetListOfDevices()
std::vector<std::shared_ptr<Device>> ConnectionHandler::GetListOfDevices()
    const {
    const {
  std::vector<std::shared_ptr<Device>> list;
  std::vector<std::shared_ptr<Device>> list;
+8 −0
Original line number Original line Diff line number Diff line
@@ -110,6 +110,14 @@ class ConnectionHandler {
   */
   */
  virtual bool DisconnectDevice(const RawAddress& bdaddr);
  virtual bool DisconnectDevice(const RawAddress& bdaddr);


  /**
   * Indicates the connection status of a device on the BIP OBEX server.
   *
   * This status is used to determine whether we should include image handles
   * when building responses for media item metadata queries.
   */
  virtual void SetBipClientStatus(const RawAddress& bdaddr, bool connected);

  virtual std::vector<std::shared_ptr<Device>> GetListOfDevices() const;
  virtual std::vector<std::shared_ptr<Device>> GetListOfDevices() const;


  /**
  /**
Loading