Loading system/packet/tests/avrcp/avrcp_test_packets.h +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,14 @@ namespace { std::vector<uint8_t> get_capabilities_request = { 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x03}; // AVRCP Get Capabilities Request packet with Company ID std::vector<uint8_t> get_capabilities_request_company_id = { 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x02}; // AVRCP Get Capabilities Request packet with Unknown std::vector<uint8_t> get_capabilities_request_unknown = { 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x7f}; // AVRCP Get Capabilities Response to Company ID request std::vector<uint8_t> get_capabilities_response_company_id = { 0x0c, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, Loading system/profile/avrcp/device.cc +42 −24 Original line number Diff line number Diff line Loading @@ -91,30 +91,8 @@ void Device::VendorPacketHandler(uint8_t label, switch (pkt->GetCommandPdu()) { case CommandPdu::GET_CAPABILITIES: { auto capability_request_pkt = Packet::Specialize<GetCapabilitiesRequest>(pkt); if (capability_request_pkt->GetCapabilityRequested() == Capability::COMPANY_ID) { auto response = GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958); response->AddCompanyId(0x002345); send_message_cb_.Run(label, false, std::move(response)); } else { auto response = GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder( Event::PLAYBACK_STATUS_CHANGED); response->AddEvent(Event::TRACK_CHANGED); response->AddEvent(Event::PLAYBACK_POS_CHANGED); if (!avrcp13_compatibility_) { response->AddEvent(Event::AVAILABLE_PLAYERS_CHANGED); response->AddEvent(Event::ADDRESSED_PLAYER_CHANGED); response->AddEvent(Event::UIDS_CHANGED); response->AddEvent(Event::NOW_PLAYING_CONTENT_CHANGED); } send_message(label, false, std::move(response)); } HandleGetCapabilities(label, Packet::Specialize<GetCapabilitiesRequest>(pkt)); } break; case CommandPdu::REGISTER_NOTIFICATION: { Loading Loading @@ -157,6 +135,46 @@ void Device::VendorPacketHandler(uint8_t label, } } void Device::HandleGetCapabilities( uint8_t label, const std::shared_ptr<GetCapabilitiesRequest>& pkt) { DEVICE_VLOG(4) << __func__ << ": capability=" << pkt->GetCapabilityRequested(); switch (pkt->GetCapabilityRequested()) { case Capability::COMPANY_ID: { auto response = GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958); response->AddCompanyId(0x002345); send_message_cb_.Run(label, false, std::move(response)); } break; case Capability::EVENTS_SUPPORTED: { auto response = GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder( Event::PLAYBACK_STATUS_CHANGED); response->AddEvent(Event::TRACK_CHANGED); response->AddEvent(Event::PLAYBACK_POS_CHANGED); if (!avrcp13_compatibility_) { response->AddEvent(Event::AVAILABLE_PLAYERS_CHANGED); response->AddEvent(Event::ADDRESSED_PLAYER_CHANGED); response->AddEvent(Event::UIDS_CHANGED); response->AddEvent(Event::NOW_PLAYING_CONTENT_CHANGED); } send_message(label, false, std::move(response)); } break; default: { DEVICE_LOG(WARNING) << "Unhandled Capability: " << pkt->GetCapabilityRequested(); auto response = RejectBuilder::MakeBuilder(CommandPdu::GET_CAPABILITIES, Status::INVALID_PARAMETER); send_message(label, false, std::move(response)); } break; } } void Device::HandleNotification( uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt) { DEVICE_VLOG(4) << __func__ << ": event=" << pkt->GetEventRegistered(); Loading system/profile/avrcp/device.h +4 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,10 @@ class Device { uint8_t label, bool interim, std::string curr_song_id, std::vector<SongInfo> song_list); // GET CAPABILITY virtual void HandleGetCapabilities( uint8_t label, const std::shared_ptr<GetCapabilitiesRequest>& pkt); // REGISTER NOTIFICATION virtual void HandleNotification( uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt); Loading system/profile/avrcp/tests/avrcp_device_test.cc +49 −1 Original line number Diff line number Diff line Loading @@ -938,5 +938,53 @@ TEST_F(AvrcpDeviceTest, mediaKeyInactiveDeviceTest) { SendMessage(1, play_released_pkt); } TEST_F(AvrcpDeviceTest, getCapabilitiesTest) { MockMediaInterface interface; NiceMock<MockA2dpInterface> a2dp_interface; test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr); // GetCapabilities with CapabilityID COMPANY_ID auto request_company_id_response = GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958); request_company_id_response->AddCompanyId(0x002345); EXPECT_CALL( response_cb, Call(1, false, matchPacket(std::move(request_company_id_response)))) .Times(1); auto request_company_id = TestAvrcpPacket::Make(get_capabilities_request_company_id); SendMessage(1, request_company_id); // GetCapabilities with CapabilityID EVENTS_SUPPORTED auto request_events_supported_response = GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder( Event::PLAYBACK_STATUS_CHANGED); request_events_supported_response->AddEvent(Event::TRACK_CHANGED); request_events_supported_response->AddEvent(Event::PLAYBACK_POS_CHANGED); EXPECT_CALL( response_cb, Call(2, false, matchPacket(std::move(request_events_supported_response)))) .Times(1); auto request_events_supported = TestAvrcpPacket::Make(get_capabilities_request); SendMessage(2, request_events_supported); // GetCapabilities with CapabilityID UNKNOWN auto request_unknown_response = RejectBuilder::MakeBuilder( CommandPdu::GET_CAPABILITIES, Status::INVALID_PARAMETER); EXPECT_CALL(response_cb, Call(3, false, matchPacket(std::move(request_unknown_response)))) .Times(1); auto request_unknown = TestAvrcpPacket::Make(get_capabilities_request_unknown); SendMessage(3, request_unknown); } } // namespace avrcp } // namespace bluetooth Loading
system/packet/tests/avrcp/avrcp_test_packets.h +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,14 @@ namespace { std::vector<uint8_t> get_capabilities_request = { 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x03}; // AVRCP Get Capabilities Request packet with Company ID std::vector<uint8_t> get_capabilities_request_company_id = { 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x02}; // AVRCP Get Capabilities Request packet with Unknown std::vector<uint8_t> get_capabilities_request_unknown = { 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, 0x01, 0x7f}; // AVRCP Get Capabilities Response to Company ID request std::vector<uint8_t> get_capabilities_response_company_id = { 0x0c, 0x48, 0x00, 0x00, 0x19, 0x58, 0x10, 0x00, 0x00, Loading
system/profile/avrcp/device.cc +42 −24 Original line number Diff line number Diff line Loading @@ -91,30 +91,8 @@ void Device::VendorPacketHandler(uint8_t label, switch (pkt->GetCommandPdu()) { case CommandPdu::GET_CAPABILITIES: { auto capability_request_pkt = Packet::Specialize<GetCapabilitiesRequest>(pkt); if (capability_request_pkt->GetCapabilityRequested() == Capability::COMPANY_ID) { auto response = GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958); response->AddCompanyId(0x002345); send_message_cb_.Run(label, false, std::move(response)); } else { auto response = GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder( Event::PLAYBACK_STATUS_CHANGED); response->AddEvent(Event::TRACK_CHANGED); response->AddEvent(Event::PLAYBACK_POS_CHANGED); if (!avrcp13_compatibility_) { response->AddEvent(Event::AVAILABLE_PLAYERS_CHANGED); response->AddEvent(Event::ADDRESSED_PLAYER_CHANGED); response->AddEvent(Event::UIDS_CHANGED); response->AddEvent(Event::NOW_PLAYING_CONTENT_CHANGED); } send_message(label, false, std::move(response)); } HandleGetCapabilities(label, Packet::Specialize<GetCapabilitiesRequest>(pkt)); } break; case CommandPdu::REGISTER_NOTIFICATION: { Loading Loading @@ -157,6 +135,46 @@ void Device::VendorPacketHandler(uint8_t label, } } void Device::HandleGetCapabilities( uint8_t label, const std::shared_ptr<GetCapabilitiesRequest>& pkt) { DEVICE_VLOG(4) << __func__ << ": capability=" << pkt->GetCapabilityRequested(); switch (pkt->GetCapabilityRequested()) { case Capability::COMPANY_ID: { auto response = GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958); response->AddCompanyId(0x002345); send_message_cb_.Run(label, false, std::move(response)); } break; case Capability::EVENTS_SUPPORTED: { auto response = GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder( Event::PLAYBACK_STATUS_CHANGED); response->AddEvent(Event::TRACK_CHANGED); response->AddEvent(Event::PLAYBACK_POS_CHANGED); if (!avrcp13_compatibility_) { response->AddEvent(Event::AVAILABLE_PLAYERS_CHANGED); response->AddEvent(Event::ADDRESSED_PLAYER_CHANGED); response->AddEvent(Event::UIDS_CHANGED); response->AddEvent(Event::NOW_PLAYING_CONTENT_CHANGED); } send_message(label, false, std::move(response)); } break; default: { DEVICE_LOG(WARNING) << "Unhandled Capability: " << pkt->GetCapabilityRequested(); auto response = RejectBuilder::MakeBuilder(CommandPdu::GET_CAPABILITIES, Status::INVALID_PARAMETER); send_message(label, false, std::move(response)); } break; } } void Device::HandleNotification( uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt) { DEVICE_VLOG(4) << __func__ << ": event=" << pkt->GetEventRegistered(); Loading
system/profile/avrcp/device.h +4 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,10 @@ class Device { uint8_t label, bool interim, std::string curr_song_id, std::vector<SongInfo> song_list); // GET CAPABILITY virtual void HandleGetCapabilities( uint8_t label, const std::shared_ptr<GetCapabilitiesRequest>& pkt); // REGISTER NOTIFICATION virtual void HandleNotification( uint8_t label, const std::shared_ptr<RegisterNotificationRequest>& pkt); Loading
system/profile/avrcp/tests/avrcp_device_test.cc +49 −1 Original line number Diff line number Diff line Loading @@ -938,5 +938,53 @@ TEST_F(AvrcpDeviceTest, mediaKeyInactiveDeviceTest) { SendMessage(1, play_released_pkt); } TEST_F(AvrcpDeviceTest, getCapabilitiesTest) { MockMediaInterface interface; NiceMock<MockA2dpInterface> a2dp_interface; test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr); // GetCapabilities with CapabilityID COMPANY_ID auto request_company_id_response = GetCapabilitiesResponseBuilder::MakeCompanyIdBuilder(0x001958); request_company_id_response->AddCompanyId(0x002345); EXPECT_CALL( response_cb, Call(1, false, matchPacket(std::move(request_company_id_response)))) .Times(1); auto request_company_id = TestAvrcpPacket::Make(get_capabilities_request_company_id); SendMessage(1, request_company_id); // GetCapabilities with CapabilityID EVENTS_SUPPORTED auto request_events_supported_response = GetCapabilitiesResponseBuilder::MakeEventsSupportedBuilder( Event::PLAYBACK_STATUS_CHANGED); request_events_supported_response->AddEvent(Event::TRACK_CHANGED); request_events_supported_response->AddEvent(Event::PLAYBACK_POS_CHANGED); EXPECT_CALL( response_cb, Call(2, false, matchPacket(std::move(request_events_supported_response)))) .Times(1); auto request_events_supported = TestAvrcpPacket::Make(get_capabilities_request); SendMessage(2, request_events_supported); // GetCapabilities with CapabilityID UNKNOWN auto request_unknown_response = RejectBuilder::MakeBuilder( CommandPdu::GET_CAPABILITIES, Status::INVALID_PARAMETER); EXPECT_CALL(response_cb, Call(3, false, matchPacket(std::move(request_unknown_response)))) .Times(1); auto request_unknown = TestAvrcpPacket::Make(get_capabilities_request_unknown); SendMessage(3, request_unknown); } } // namespace avrcp } // namespace bluetooth