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

Commit 1c8e0a07 authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge "Fix Audio ramping code"

parents ca1f5966 24b082f8
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -623,23 +623,32 @@ public class AudioService extends IAudioService.Stub {
        ensureValidDirection(direction);
        int volume = Math.round(AudioSystem.getMasterVolume() * MAX_MASTER_VOLUME);
        int delta = 0;
        for (int i = 0; i < mMasterVolumeRamp.length; i += 2) {
            int testVolume = mMasterVolumeRamp[i];
            int testDelta =  mMasterVolumeRamp[i + 1];

        if (direction == AudioManager.ADJUST_RAISE) {
                if (volume >= testVolume) {
                    delta = testDelta;
                } else {
            // This is the default value if we make it to the end
            delta = mMasterVolumeRamp[1];
            // If we're raising the volume move down the ramp array until we
            // find the volume we're above and use that groups delta.
            for (int i = mMasterVolumeRamp.length - 1; i > 1; i -= 2) {
                if (volume >= mMasterVolumeRamp[i - 1]) {
                    delta = mMasterVolumeRamp[i];
                    break;
                }
            }
        } else if (direction == AudioManager.ADJUST_LOWER){
                if (volume - testDelta >= testVolume) {
                    delta = -testDelta;
                } else {
            int length = mMasterVolumeRamp.length;
            // This is the default value if we make it to the end
            delta = -mMasterVolumeRamp[length - 1];
            // If we're lowering the volume move up the ramp array until we
            // find the volume we're below and use the group below it's delta
            for (int i = 2; i < length; i += 2) {
                if (volume <= mMasterVolumeRamp[i]) {
                    delta = -mMasterVolumeRamp[i - 1];
                    break;
                }
            }
        }

//        Log.d(TAG, "adjustMasterVolume volume: " + volume + " delta: " + delta + " direction: " + direction);
        setMasterVolume(volume + delta, flags);
    }