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

Commit 70990c94 authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Automerger Merge Worker
Browse files

Merge "Unify volume conversion method and add force vol update" into main am:...

Merge "Unify volume conversion method and add force vol update" into main am: a5c49f61 am: 30c24bfe

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2770767



Change-Id: I6a7f528c2036d5b6594a936079f431ee5ff3b3ac
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 089eab74 30c24bfe
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -63,12 +63,12 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
    boolean mAbsoluteVolumeSupported = false;

    static int avrcpToSystemVolume(int avrcpVolume) {
        return (int) Math.floor((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL);
        return (int) Math.round((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL);
    }

    static int systemToAvrcpVolume(int deviceVolume) {
        int avrcpVolume = (int) Math.ceil((double) deviceVolume
                * AVRCP_MAX_VOL / sDeviceMaxVolume);
        int avrcpVolume =
                (int) Math.round((double) deviceVolume * AVRCP_MAX_VOL / sDeviceMaxVolume);
        if (avrcpVolume > 127) avrcpVolume = 127;
        return avrcpVolume;
    }
@@ -178,8 +178,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
    }

    void setVolume(@NonNull BluetoothDevice device, int avrcpVolume) {
        int deviceVolume =
                (int) Math.round((double) avrcpVolume * sDeviceMaxVolume / AVRCP_MAX_VOL);
        int deviceVolume = avrcpToSystemVolume(avrcpVolume);
        mVolumeEventLogger.logd(DEBUG, TAG, "setVolume:"
                        + " device=" + device
                        + " avrcpVolume=" + avrcpVolume
@@ -196,9 +195,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
            d("sendVolumeChanged: Skipping update volume to same as current.");
            return;
        }
        int avrcpVolume =
                (int) Math.round((double) deviceVolume * AVRCP_MAX_VOL / sDeviceMaxVolume);
        if (avrcpVolume > 127) avrcpVolume = 127;
        int avrcpVolume = systemToAvrcpVolume(deviceVolume);
        mVolumeEventLogger.logd(DEBUG, TAG, "sendVolumeChanged:"
                        + " device=" + device
                        + " avrcpVolume=" + avrcpVolume
+5 −1
Original line number Diff line number Diff line
@@ -75,10 +75,14 @@ public class AvrcpVolumeManagerTest {
    }

    @Test
    public void avrcpToSystemVolume() {
    public void avrcpVolumeConversion() {
        assertThat(AvrcpVolumeManager.avrcpToSystemVolume(0)).isEqualTo(0);
        assertThat(AvrcpVolumeManager.avrcpToSystemVolume(AVRCP_MAX_VOL))
                .isEqualTo(TEST_DEVICE_MAX_VOUME);

        assertThat(AvrcpVolumeManager.systemToAvrcpVolume(0)).isEqualTo(0);
        assertThat(AvrcpVolumeManager.systemToAvrcpVolume(TEST_DEVICE_MAX_VOUME))
                .isEqualTo(AVRCP_MAX_VOL);
    }

    @Test
+5 −0
Original line number Diff line number Diff line
@@ -1862,6 +1862,11 @@ void Device::DeviceDisconnected() {
  // remove these conditionals.
  if (volume_interface_ != nullptr)
    volume_interface_->DeviceDisconnected(GetAddress());
  // The volume at connection is set by the remote device when indicating
  // that it supports absolute volume, in case it's not, we need
  // to reset the local volume var to be sure we send the correct value
  // to the remote device on the next connection.
  volume_ = VOL_NOT_SUPPORTED;
}

static std::string volumeToStr(int8_t volume) {
+15 −0
Original line number Diff line number Diff line
@@ -1469,6 +1469,21 @@ TEST_F(AvrcpDeviceTest, setVolumeOnceTest) {
  test_device->SetVolume(vol);
}

TEST_F(AvrcpDeviceTest, setVolumeAfterReconnectionTest) {
  int vol = 0x48;

  auto set_abs_vol = SetAbsoluteVolumeRequestBuilder::MakeBuilder(vol);

  // Ensure that SetVolume is called twice as DeviceDisconnected will
  // reset the previous stored volume.
  EXPECT_CALL(response_cb, Call(_, false, matchPacket(std::move(set_abs_vol))))
      .Times(2);

  test_device->SetVolume(vol);
  test_device->DeviceDisconnected();
  test_device->SetVolume(vol);
}

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