diff --git a/system/btif/avrcp/avrcp_service.cc b/system/btif/avrcp/avrcp_service.cc index 0053a9d63e5be60352a04e04c49e42565cce7a94..d6750ce04d3a5a88d6fe2cc1a32d8e92defb192f 100644 --- a/system/btif/avrcp/avrcp_service.cc +++ b/system/btif/avrcp/avrcp_service.cc @@ -279,7 +279,7 @@ void AvrcpService::Init(MediaInterface* media_interface, ConnectionHandler::Initialize( base::Bind(&AvrcpService::DeviceCallback, base::Unretained(instance_)), - &avrcp_interface_, &sdp_interface_); + &avrcp_interface_, &sdp_interface_, volume_interface); instance_->connection_handler_ = ConnectionHandler::Get(); } diff --git a/system/profile/avrcp/connection_handler.cc b/system/profile/avrcp/connection_handler.cc index 3b6fec02dbf2ba86161e0e81e6086387334d052e..8cabe8ce13907188f69c8d3a873aca992360e3ae 100644 --- a/system/profile/avrcp/connection_handler.cc +++ b/system/profile/avrcp/connection_handler.cc @@ -42,7 +42,8 @@ ConnectionHandler* ConnectionHandler::Get() { } bool ConnectionHandler::Initialize(const ConnectionCallback& callback, - AvrcpInterface* avrcp, SdpInterface* sdp) { + AvrcpInterface* avrcp, SdpInterface* sdp, + VolumeInterface* vol) { CHECK(instance_ == nullptr); CHECK(avrcp != nullptr); CHECK(sdp != nullptr); @@ -53,6 +54,7 @@ bool ConnectionHandler::Initialize(const ConnectionCallback& callback, instance_->connection_cb_ = callback; instance_->avrc_ = avrcp; instance_->sdp_ = sdp; + instance_->vol_ = vol; // Set up the AVRCP acceptor connection if (!instance_->AvrcpConnect(false, RawAddress::kAny)) { @@ -232,7 +234,10 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event, if (feature_iter->second & BTA_AV_FEAT_ADV_CTRL) { newDevice->RegisterVolumeChanged(); + } else if (instance_->vol_ != nullptr) { + instance_->vol_->DeviceConnected(newDevice->GetAddress()); } + } break; case AVRC_CLOSE_IND_EVT: { @@ -308,6 +313,8 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event, // connected that doesn't support absolute volume. if (features & BTA_AV_FEAT_ADV_CTRL) { device->RegisterVolumeChanged(); + } else if (instance_->vol_ != nullptr) { + instance_->vol_->DeviceConnected(device->GetAddress()); } }; diff --git a/system/profile/avrcp/connection_handler.h b/system/profile/avrcp/connection_handler.h index 1737d60cf27192ece6355c187e8b62ffff603ad4..4db38b73006b556721514a1a1232576f76273c42 100644 --- a/system/profile/avrcp/connection_handler.h +++ b/system/profile/avrcp/connection_handler.h @@ -63,7 +63,8 @@ class ConnectionHandler { * TODO: Add message loop to determine which thread events are posted to */ static bool Initialize(const ConnectionCallback& callback, - AvrcpInterface* avrcp, SdpInterface* sdp); + AvrcpInterface* avrcp, SdpInterface* sdp, + VolumeInterface* vol); /** * Clears the singleton and tears down SDP @@ -120,6 +121,7 @@ class ConnectionHandler { private: AvrcpInterface* avrc_; SdpInterface* sdp_; + VolumeInterface* vol_; ConnectionCallback connection_cb_; diff --git a/system/profile/avrcp/tests/avrcp_connection_handler_test.cc b/system/profile/avrcp/tests/avrcp_connection_handler_test.cc index bd1e2d02a9b6c90c75544097937121f0bacd7be6..b820b6c6e92ba8334c8a040ce6d346a102f82d7a 100644 --- a/system/profile/avrcp/tests/avrcp_connection_handler_test.cc +++ b/system/profile/avrcp/tests/avrcp_connection_handler_test.cc @@ -31,6 +31,7 @@ using ::testing::SaveArgPointee; using ::testing::SetArgPointee; using ::testing::MockFunction; using ::testing::NiceMock; +using ::testing::StrictMock; namespace bluetooth { namespace avrcp { @@ -83,6 +84,7 @@ class AvrcpConnectionHandlerTest : public testing::Test { NiceMock<MockFunction<void(device_ptr)>> device_cb; NiceMock<MockAvrcpInterface> mock_avrcp_; NiceMock<MockSdpInterface> mock_sdp_; + NiceMock<MockVolumeInterface> mock_volume_; }; TEST_F(AvrcpConnectionHandlerTest, initializeTest) { @@ -96,8 +98,8 @@ TEST_F(AvrcpConnectionHandlerTest, initializeTest) { auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Check that the callback was sent with us as the acceptor @@ -123,8 +125,8 @@ TEST_F(AvrcpConnectionHandlerTest, remoteDeviceConnectionTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Check that the callback was sent with us as the acceptor @@ -151,6 +153,79 @@ TEST_F(AvrcpConnectionHandlerTest, remoteDeviceConnectionTest) { ConnectionHandler::CleanUp(); } +// Check that when a device does not support absolute volume, that the +// handler reports that via the volume interface. +TEST_F(AvrcpConnectionHandlerTest, noAbsoluteVolumeTest) { + // Set an Expectation that Open will be called twice as an acceptor and save + // the connection callback once it is called. + tAVRC_CONN_CB conn_cb; + EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny)) + .Times(2) + .WillOnce( + DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0))) + .WillOnce( + DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0))); + + // Initialize the interface + auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, + base::Unretained(&device_cb)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); + connection_handler_ = ConnectionHandler::Get(); + + // Set an Expectations that SDP will be performed + tAVRC_FIND_CBACK sdp_cb; + SetUpSdp(&sdp_cb, false, false); + + EXPECT_CALL(mock_volume_, DeviceConnected(RawAddress::kAny)).Times(1); + + // Call the callback with a message saying that a remote device has connected + conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny); + + // Run the SDP callback with status success + sdp_cb.Run(0); + + connection_handler_ = nullptr; + ConnectionHandler::CleanUp(); +} + +// Check that when a device does support absolute volume, that the handler +// doesn't report it. Instead that will be left up to the device. +TEST_F(AvrcpConnectionHandlerTest, absoluteVolumeTest) { + // Set an Expectation that Open will be called twice as an acceptor and save + // the connection callback once it is called. + tAVRC_CONN_CB conn_cb; + EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny)) + .Times(2) + .WillOnce( + DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0))) + .WillOnce( + DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0))); + + // Initialize the interface + auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, + base::Unretained(&device_cb)); + + StrictMock<MockVolumeInterface> strict_volume; + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &strict_volume)); + connection_handler_ = ConnectionHandler::Get(); + + // Set an Expectations that SDP will be performed with absolute volume + // supported + tAVRC_FIND_CBACK sdp_cb; + SetUpSdp(&sdp_cb, false, true); + + // Call the callback with a message saying that a remote device has connected + conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny); + + // Run the SDP callback with status success + sdp_cb.Run(0); + + connection_handler_ = nullptr; + ConnectionHandler::CleanUp(); +} + TEST_F(AvrcpConnectionHandlerTest, disconnectTest) { // Set an Expectation that Open will be called twice as an acceptor and save // the connection callback once it is called. @@ -164,8 +239,8 @@ TEST_F(AvrcpConnectionHandlerTest, disconnectTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Call the callback with a message saying that a remote device has connected @@ -200,8 +275,8 @@ TEST_F(AvrcpConnectionHandlerTest, multipleRemoteDeviceConnectionTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Check that the callback was sent with us as the acceptor @@ -259,8 +334,8 @@ TEST_F(AvrcpConnectionHandlerTest, cleanupTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Call the callback twice with a message saying that a remote device has @@ -281,8 +356,8 @@ TEST_F(AvrcpConnectionHandlerTest, connectToRemoteDeviceTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Set an Expectation that SDP will be performed @@ -326,8 +401,8 @@ TEST_F(AvrcpConnectionHandlerTest, connectToBrowsableRemoteDeviceTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Set an Expectation that SDP will be performed @@ -380,8 +455,8 @@ TEST_F(AvrcpConnectionHandlerTest, disconnectWhileDoingSdpTest) { // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); - ASSERT_TRUE( - ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); + ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, + &mock_sdp_, &mock_volume_)); connection_handler_ = ConnectionHandler::Get(); // Set an Expectation that SDP will be performed