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

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

Ignore volume changed events from the non-active device

Bug: 78251684
Test: Run host native test net_test_avrcp
Change-Id: I164e9ded88c804da2ce8191c5f58cc053cfa6ecd
(cherry picked from commit 9697afe2)
parent 4dfdc25b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -282,6 +282,12 @@ void Device::HandleVolumeChanged(
    return;
  }

  if (!IsActive()) {
    DEVICE_VLOG(3) << __func__
                   << ": Ignoring volume changes from non active device";
    return;
  }

  volume_ = pkt->GetVolume();
  DEVICE_VLOG(1) << __func__ << ": Volume has changed to " << (uint32_t)volume_;
  volume_interface_->SetVolume(volume_);
+44 −0
Original line number Diff line number Diff line
@@ -724,6 +724,10 @@ TEST_F(AvrcpDeviceTest, volumeChangedTest) {

  test_device->RegisterInterfaces(&interface, &a2dp_interface, &vol_interface);

  // Pretend the device is active
  EXPECT_CALL(a2dp_interface, active_peer())
      .WillRepeatedly(Return(test_device->GetAddress()));

  auto reg_notif =
      RegisterNotificationRequestBuilder::MakeBuilder(Event::VOLUME_CHANGED, 0);
  EXPECT_CALL(response_cb, Call(_, false, matchPacket(std::move(reg_notif))))
@@ -751,6 +755,46 @@ TEST_F(AvrcpDeviceTest, volumeChangedTest) {
  SendMessage(1, response);
}

TEST_F(AvrcpDeviceTest, volumeChangedNonActiveTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;
  MockVolumeInterface vol_interface;

  test_device->RegisterInterfaces(&interface, &a2dp_interface, &vol_interface);

  // Pretend the device is active
  EXPECT_CALL(a2dp_interface, active_peer())
      .WillRepeatedly(Return(RawAddress::kEmpty));

  auto reg_notif =
      RegisterNotificationRequestBuilder::MakeBuilder(Event::VOLUME_CHANGED, 0);
  EXPECT_CALL(response_cb, Call(_, false, matchPacket(std::move(reg_notif))))
      .Times(1);
  test_device->RegisterVolumeChanged();

  EXPECT_CALL(vol_interface, DeviceConnected(test_device->GetAddress(), _))
      .Times(1)
      .WillOnce(InvokeCb<1>(0x30));
  auto set_vol = SetAbsoluteVolumeRequestBuilder::MakeBuilder(0x30);
  EXPECT_CALL(response_cb, Call(_, false, matchPacket(std::move(set_vol))))
      .Times(1);

  auto response = TestAvrcpPacket::Make(interim_volume_changed_notification);
  SendMessage(1, response);

  // Ensure that SetVolume is never called
  EXPECT_CALL(vol_interface, SetVolume(0x47)).Times(0);

  auto reg_notif2 =
      RegisterNotificationRequestBuilder::MakeBuilder(Event::VOLUME_CHANGED, 0);
  EXPECT_CALL(response_cb, Call(_, false, matchPacket(std::move(reg_notif2))))
      .Times(1);
  response = TestAvrcpPacket::Make(changed_volume_changed_notification);
  SendMessage(1, response);
  response = TestAvrcpPacket::Make(interim_volume_changed_notification);
  SendMessage(1, response);
}

TEST_F(AvrcpDeviceTest, volumeRejectedTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;