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

Commit c1792bf4 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Add missing AVRCP Set Addressed Player Response

Bug: 77237301
Test: run host native tests net-test-btpackets and net-test-avrcp
Change-Id: Ic9a2c8d8cf5dd4c5be02a83975caa92e335ca2b9
(cherry picked from commit c3ad060f)
Merged-In: Ic9a2c8d8cf5dd4c5be02a83975caa92e335ca2b9
parent 72b7540c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ cc_test {
        "tests/avrcp/play_item_packet_test.cc",
        "tests/avrcp/register_notification_packet_test.cc",
        "tests/avrcp/set_absolute_volume_packet_test.cc",
        "tests/avrcp/set_addressed_player_packet_test.cc",
        "tests/avrcp/set_browsed_player_packet_test.cc",
        "tests/avrcp/vendor_packet_test.cc",
        "tests/base/iterator_test.cc",
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ cc_library_static {
        "play_item.cc",
        "register_notification_packet.cc",
        "set_absolute_volume.cc",
        "set_addressed_player.cc",
        "set_browsed_player.cc",
        "vendor_packet.cc",
    ],
+2 −3
Original line number Diff line number Diff line
@@ -20,13 +20,12 @@
#include <base/macros.h>
#include <iostream>

#include "avrcp_common.h"
#include "avrcp_logging_helper.h"
#include "iterator.h"
#include "packet.h"
#include "packet_builder.h"

#include "avrcp_common.h"
#include "avrcp_logging_helper.h"

namespace bluetooth {
namespace avrcp {

+77 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "set_addressed_player.h"

namespace bluetooth {
namespace avrcp {

std::unique_ptr<SetAddressedPlayerResponseBuilder>
SetAddressedPlayerResponseBuilder::MakeBuilder(Status status) {
  std::unique_ptr<SetAddressedPlayerResponseBuilder> builder(
      new SetAddressedPlayerResponseBuilder(status));

  return builder;
}

size_t SetAddressedPlayerResponseBuilder::size() const {
  size_t len = VendorPacket::kMinSize();
  len += 1;  // Status
  return len;
}

bool SetAddressedPlayerResponseBuilder::Serialize(
    const std::shared_ptr<::bluetooth::Packet>& pkt) {
  ReserveSpace(pkt, size());

  PacketBuilder::PushHeader(pkt);

  VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize());

  AddPayloadOctets1(pkt, (uint8_t)status_);

  return true;
}

uint16_t SetAddressedPlayerRequest::GetPlayerId() const {
  auto it = begin() + VendorPacket::kMinSize();
  return base::ByteSwap(it.extract<uint16_t>());
}

bool SetAddressedPlayerRequest::IsValid() const {
  if (!VendorPacket::IsValid()) return false;
  return size() == kMinSize();
}

std::string SetAddressedPlayerRequest::ToString() const {
  std::stringstream ss;
  ss << "SetAddressedPlayerRequest: " << std::endl;
  ss << "  └ cType = " << GetCType() << std::endl;
  ss << "  └ Subunit Type = " << loghex(GetSubunitType()) << std::endl;
  ss << "  └ Subunit ID = " << loghex(GetSubunitId()) << std::endl;
  ss << "  └ OpCode = " << GetOpcode() << std::endl;
  ss << "  └ Company ID = " << loghex(GetCompanyId()) << std::endl;
  ss << "  └ Command PDU = " << GetCommandPdu() << std::endl;
  ss << "  └ PacketType = " << GetPacketType() << std::endl;
  ss << "  └ Parameter Length = " << loghex(GetParameterLength()) << std::endl;
  ss << "  └ Player ID = " << loghex(GetPlayerId()) << std::endl;
  ss << std::endl;

  return ss.str();
}

}  // namespace avrcp
}  // namespace bluetooth
 No newline at end of file
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "vendor_packet.h"

namespace bluetooth {
namespace avrcp {

class SetAddressedPlayerResponseBuilder : public VendorPacketBuilder {
 public:
  virtual ~SetAddressedPlayerResponseBuilder() = default;

  static std::unique_ptr<SetAddressedPlayerResponseBuilder> MakeBuilder(
      Status status);

  virtual size_t size() const override;
  virtual bool Serialize(
      const std::shared_ptr<::bluetooth::Packet>& pkt) override;

 protected:
  Status status_;

  SetAddressedPlayerResponseBuilder(Status status)
      : VendorPacketBuilder(CType::ACCEPTED, CommandPdu::SET_ADDRESSED_PLAYER,
                            PacketType::SINGLE),
        status_(status){};
};

class SetAddressedPlayerRequest : public VendorPacket {
 public:
  virtual ~SetAddressedPlayerRequest() = default;

  /**
   *  Register Notificaiton Request Packet Layout
   *   AvrcpPacket:
   *     CType c_type_;
   *     uint8_t subunit_type_ : 5;
   *     uint8_t subunit_id_ : 3;
   *     Opcode opcode_;
   *   VendorPacket:
   *     uint8_t company_id[3];
   *     uint8_t command_pdu;
   *     uint8_t packet_type;
   *     uint16_t param_length;
   *   SetAddressedPlayerRequest:
   *     uint16_t player_id;
   */
  static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 2; }

  uint16_t GetPlayerId() const;

  virtual bool IsValid() const override;
  virtual std::string ToString() const override;

 protected:
  using VendorPacket::VendorPacket;
};

}  // namespace avrcp
}  // namespace bluetooth
 No newline at end of file
Loading