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

Commit 81e7a587 authored by Eric Laurent's avatar Eric Laurent Committed by Gerrit Code Review
Browse files

Merge "Bluetooth: Restrict gain for Absolute volume case"

parents 60cbd0b0 4565a47d
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -3737,8 +3737,29 @@ public class AudioService extends IAudioService.Stub {
            int index;
            if (mIsMuted) {
                index = 0;
            } else if (((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported)
                    || ((device & mFullVolumeDevices) != 0)) {
            } else if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) {
                /* Special handling for Bluetooth Absolute Volume scenario
                 * If we send full audio gain, some accessories are too loud even at its lowest
                 * volume. We are not able to enumerate all such accessories, so here is the
                 * workaround from phone side.
                 * For the lowest volume steps 1 and 2, restrict audio gain to 50% and 75%.
                 * For volume step 0, set audio gain to 0 as some accessories won't mute on their end.
                 */
                int i = (getIndex(device) + 5)/10;
                if (i == 0) {
                    // 0% for volume 0
                    index = 0;
                } else if (i == 1) {
                    // 50% for volume 1
                    index = (int)(mIndexMax * 0.5) /10;
                } else if (i == 2) {
                    // 75% for volume 2
                    index = (int)(mIndexMax * 0.75) /10;
                } else {
                    // otherwise, full gain
                    index = (mIndexMax + 5)/10;
                }
            } else if ((device & mFullVolumeDevices) != 0) {
                index = (mIndexMax + 5)/10;
            } else {
                index = (getIndex(device) + 5)/10;