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

Commit 94442315 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Bluetooth: Fine tune audio gain for Absolute Volume case" into nyc-dev

parents 34510eb2 39fb5670
Loading
Loading
Loading
Loading
+32 −24
Original line number Original line Diff line number Diff line
@@ -3940,33 +3940,40 @@ public class AudioService extends IAudioService.Stub {
            }
            }
        }
        }


        // must be called while synchronized VolumeStreamState.class
        private int getAbsoluteVolumeIndex(int index) {
        public void applyDeviceVolume_syncVSS(int device) {
            int index;
            if (mIsMuted) {
                index = 0;
            } else if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) {
            /* Special handling for Bluetooth Absolute Volume scenario
            /* Special handling for Bluetooth Absolute Volume scenario
             * If we send full audio gain, some accessories are too loud even at its lowest
             * 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
             * volume. We are not able to enumerate all such accessories, so here is the
             * workaround from phone side.
             * workaround from phone side.
                 * For the lowest volume steps 1 and 2, restrict audio gain to 50% and 75%.
             * Pre-scale volume at lowest volume steps 1 2 and 3.
             * For volume step 0, set audio gain to 0 as some accessories won't mute on their end.
             * 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 (index == 0) {
                if (i == 0) {
                // 0% for volume 0
                // 0% for volume 0
                index = 0;
                index = 0;
                } else if (i == 1) {
            } else if (index == 1) {
                // 50% for volume 1
                // 50% for volume 1
                index = (int)(mIndexMax * 0.5) /10;
                index = (int)(mIndexMax * 0.5) /10;
                } else if (i == 2) {
            } else if (index == 2) {
                    // 75% for volume 2
                // 70% for volume 2
                    index = (int)(mIndexMax * 0.75) /10;
                index = (int)(mIndexMax * 0.70) /10;
            } else if (index == 3) {
                // 85% for volume 3
                index = (int)(mIndexMax * 0.85) /10;
            } else {
            } else {
                // otherwise, full gain
                // otherwise, full gain
                index = (mIndexMax + 5)/10;
                index = (mIndexMax + 5)/10;
            }
            }
            return index;
        }

        // must be called while synchronized VolumeStreamState.class
        public void applyDeviceVolume_syncVSS(int device) {
            int index;
            if (mIsMuted) {
                index = 0;
            } else if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) {
                index = getAbsoluteVolumeIndex((getIndex(device) + 5)/10);
            } else if ((device & mFullVolumeDevices) != 0) {
            } else if ((device & mFullVolumeDevices) != 0) {
                index = (mIndexMax + 5)/10;
                index = (mIndexMax + 5)/10;
            } else {
            } else {
@@ -3984,9 +3991,10 @@ public class AudioService extends IAudioService.Stub {
                    if (device != AudioSystem.DEVICE_OUT_DEFAULT) {
                    if (device != AudioSystem.DEVICE_OUT_DEFAULT) {
                        if (mIsMuted) {
                        if (mIsMuted) {
                            index = 0;
                            index = 0;
                        } else if (((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
                        } else if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
                                mAvrcpAbsVolSupported)
                                mAvrcpAbsVolSupported) {
                                    || ((device & mFullVolumeDevices) != 0)) {
                            index = getAbsoluteVolumeIndex((getIndex(device) + 5)/10);
                        } else if ((device & mFullVolumeDevices) != 0) {
                            index = (mIndexMax + 5)/10;
                            index = (mIndexMax + 5)/10;
                        } else {
                        } else {
                            index = (mIndexMap.valueAt(i) + 5)/10;
                            index = (mIndexMap.valueAt(i) + 5)/10;