Loading android/app/src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +5 −8 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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 Loading @@ -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 Loading android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java +5 −1 Original line number Diff line number Diff line Loading @@ -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 Loading system/profile/avrcp/device.cc +5 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading system/profile/avrcp/tests/avrcp_device_test.cc +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +5 −8 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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 Loading @@ -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 Loading
android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java +5 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
system/profile/avrcp/device.cc +5 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
system/profile/avrcp/tests/avrcp_device_test.cc +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading