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

Commit 4dfe3293 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove rolled out flag abs_volume_index_fix" into main

parents dba18551 f9aac4cd
Loading
Loading
Loading
Loading
+41 −84
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
import static com.android.media.audio.Flags.absVolumeIndexFix;
import static com.android.media.audio.Flags.alarmMinVolumeZero;
import static com.android.media.audio.Flags.asDeviceConnectionFailure;
import static com.android.media.audio.Flags.audioserverPermissions;
@@ -4126,10 +4125,8 @@ public class AudioService extends IAudioService.Stub
            int newIndex = getVssForStreamOrDefault(streamType).getIndex(device);
            int streamToDriveAbsVol = absVolumeIndexFix() ? getBluetoothContextualVolumeStream() :
                    AudioSystem.STREAM_MUSIC;
            // Check if volume update should be send to AVRCP
            if (streamTypeAlias == streamToDriveAbsVol
            if (streamTypeAlias == getBluetoothContextualVolumeStream()
                    && AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(device)
                    && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
                if (DEBUG_VOL) {
@@ -4992,8 +4989,7 @@ public class AudioService extends IAudioService.Stub
                + scoManagedByAudio());
        pw.println("\tcom.android.media.audio.vgsVssSyncMuteOrder:"
                + vgsVssSyncMuteOrder());
        pw.println("\tcom.android.media.audio.absVolumeIndexFix:"
                + absVolumeIndexFix());
        pw.println("\tcom.android.media.audio.absVolumeIndexFix - EOL");
        pw.println("\tcom.android.media.audio.replaceStreamBtSco:"
                + replaceStreamBtSco());
        pw.println("\tcom.android.media.audio.equalScoLeaVcIndexRange:"
@@ -5202,9 +5198,7 @@ public class AudioService extends IAudioService.Stub
            }
        }
        int streamToDriveAbsVol = absVolumeIndexFix() ? getBluetoothContextualVolumeStream() :
                AudioSystem.STREAM_MUSIC;
        if (streamTypeAlias == streamToDriveAbsVol
        if (streamTypeAlias == getBluetoothContextualVolumeStream()
                && AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(device)
                && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
            if (DEBUG_VOL) {
@@ -9594,33 +9588,6 @@ public class AudioService extends IAudioService.Stub
            }
        }
        private int getAbsoluteVolumeIndex(int index) {
            if (absVolumeIndexFix()) {
                // The attenuation is applied in the APM. No need to manipulate the index here
                return index;
            } else {
                /* 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.
                 * 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.
                 */
                if (index == 0) {
                    // 0% for volume 0
                    index = 0;
                } else if (!disablePrescaleAbsoluteVolume() && index > 0 && index <= 3) {
                    // Pre-scale for volume steps 1 2 and 3
                    index = (int) (mIndexMax * mPrescaleAbsoluteVolume[index - 1]) / 10;
                } else {
                    // otherwise, full gain
                    index = (mIndexMax + 5) / 10;
                }
                return index;
            }
        }
        /**
         * Sends the new volume index on the given device to native.
         *
@@ -9660,19 +9627,15 @@ public class AudioService extends IAudioService.Stub
                    || isA2dpAbsoluteVolumeDevice(device)
                    || AudioSystem.isLeAudioDeviceType(device)) {
                // do not change the volume logic for dynamic abs behavior devices like HDMI
                if (absVolumeIndexFix() && isAbsoluteVolumeDevice(device)) {
                    index = getAbsoluteVolumeIndex((mIndexMax + 5) / 10);
                if (isAbsoluteVolumeDevice(device)) {
                    index = (mIndexMax + 5) / 10;
                } else {
                    index = getAbsoluteVolumeIndex((getIndex(device) + 5) / 10);
                    index = (getIndex(device) + 5) / 10;
                }
            } else if (isFullVolumeDevice(device)) {
                index = (mIndexMax + 5)/10;
            } else if (device == AudioSystem.DEVICE_OUT_HEARING_AID) {
                if (absVolumeIndexFix()) {
                    index = getAbsoluteVolumeIndex((getIndex(device) + 5) / 10);
                } else {
                    index = (mIndexMax + 5) / 10;
                }
                index = (getIndex(device) + 5) / 10;
            } else {
                index = (getIndex(device) + 5)/10;
            }
@@ -9696,20 +9659,16 @@ public class AudioService extends IAudioService.Stub
                            isAbsoluteVolume = true;
                            // do not change the volume logic for dynamic abs behavior devices
                            // like HDMI
                            if (absVolumeIndexFix() && isAbsoluteVolumeDevice(device)) {
                                index = getAbsoluteVolumeIndex((mIndexMax + 5) / 10);
                            if (isAbsoluteVolumeDevice(device)) {
                                index = (mIndexMax + 5) / 10;
                            } else {
                                index = getAbsoluteVolumeIndex((getIndex(device) + 5) / 10);
                                index = (getIndex(device) + 5) / 10;
                            }
                        } else if (isFullVolumeDevice(device)) {
                            index = (mIndexMax + 5)/10;
                        } else if (device == AudioSystem.DEVICE_OUT_HEARING_AID) {
                            if (absVolumeIndexFix()) {
                            isAbsoluteVolume = true;
                                index = getAbsoluteVolumeIndex((getIndex(device) + 5) / 10);
                            } else {
                                index = (mIndexMax + 5) / 10;
                            }
                            index = (getIndex(device) + 5) / 10;
                        } else {
                            index = (mIndexMap.valueAt(i) + 5)/10;
                        }
@@ -10779,7 +10738,6 @@ public class AudioService extends IAudioService.Stub
        Log.i(TAG, "setAvrcpAbsoluteVolumeSupported support " + support);
        synchronized (mCachedAbsVolDrivingStreamsLock) {
            mAvrcpAbsVolSupported = support;
            if (absVolumeIndexFix()) {
            int a2dpDev = AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
            mCachedAbsVolDrivingStreams.compute(a2dpDev, (dev, stream) -> {
                if (!mAvrcpAbsVolSupported) {
@@ -10812,7 +10770,6 @@ public class AudioService extends IAudioService.Stub
                return streamToDriveAbs;
            });
        }
        }
        sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
                    AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0,
                    getVssForStreamOrDefault(AudioSystem.STREAM_MUSIC), 0);
+2 −61
Original line number Diff line number Diff line
@@ -16,9 +16,7 @@

package com.android.server.audio;

import static com.android.media.audio.Flags.FLAG_ABS_VOLUME_INDEX_FIX;
import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME;
import static com.android.media.audio.Flags.absVolumeIndexFix;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
@@ -37,7 +35,6 @@ import android.media.VolumeInfo;
import android.os.IpcDataCache;
import android.os.PermissionEnforcer;
import android.os.test.TestLooper;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
@@ -123,55 +120,6 @@ public class AudioDeviceVolumeManagerTest {
                AudioManager.STREAM_MUSIC, midIndex, false, AudioSystem.DEVICE_OUT_USB_DEVICE);
    }

    @Test
    @RequiresFlagsDisabled({FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME, FLAG_ABS_VOLUME_INDEX_FIX})
    public void configurablePreScaleAbsoluteVolume_checkIndex() throws Exception {
        AudioManager am = mContext.getSystemService(AudioManager.class);
        final int minIndex = am.getStreamMinVolume(AudioManager.STREAM_MUSIC);
        final int maxIndex = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        final VolumeInfo volMedia = new VolumeInfo.Builder(AudioManager.STREAM_MUSIC)
                .setMinVolumeIndex(minIndex)
                .setMaxVolumeIndex(maxIndex)
                .build();
        final AudioDeviceAttributes bleDevice = new AudioDeviceAttributes(
                /*native type*/ AudioSystem.DEVICE_OUT_BLE_HEADSET, /*address*/ "fake_ble");
        final int maxPreScaleIndex = 3;
        final float[] preScale = new float[3];
        preScale[0] = mContext.getResources().getFraction(
                com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index1,
                1, 1);
        preScale[1] = mContext.getResources().getFraction(
                com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index2,
                1, 1);
        preScale[2] = mContext.getResources().getFraction(
                com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index3,
                1, 1);

        for (int i = 0; i < maxPreScaleIndex; i++) {
            final int targetIndex = (int) (preScale[i] * maxIndex);
            final VolumeInfo volCur = new VolumeInfo.Builder(volMedia)
                    .setVolumeIndex(i + 1).build();
            // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:1~3)
            mAudioService.setDeviceVolume(volCur, bleDevice, mPackageName);
            mTestLooper.dispatchAll();

            // Stream volume changes
            verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                            AudioManager.STREAM_MUSIC, targetIndex, false,
                            AudioSystem.DEVICE_OUT_BLE_HEADSET);
        }

        // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:4)
        final VolumeInfo volIndex4 = new VolumeInfo.Builder(volMedia)
                .setVolumeIndex(4).build();
        mAudioService.setDeviceVolume(volIndex4, bleDevice, mPackageName);
        mTestLooper.dispatchAll();

        verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                        AudioManager.STREAM_MUSIC, maxIndex, false,
                        AudioSystem.DEVICE_OUT_BLE_HEADSET);
    }

    @Test
    @RequiresFlagsEnabled(FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME)
    public void disablePreScaleAbsoluteVolume_checkIndex() throws Exception {
@@ -185,7 +133,6 @@ public class AudioDeviceVolumeManagerTest {
        final AudioDeviceAttributes bleDevice = new AudioDeviceAttributes(
                /*native type*/ AudioSystem.DEVICE_OUT_BLE_HEADSET, /*address*/ "bla");
        final int maxPreScaleIndex = 3;
        int passedIndex = maxIndex;

        for (int i = 0; i < maxPreScaleIndex; i++) {
            final VolumeInfo volCur = new VolumeInfo.Builder(volMedia)
@@ -194,12 +141,9 @@ public class AudioDeviceVolumeManagerTest {
            mAudioService.setDeviceVolume(volCur, bleDevice, mPackageName);
            mTestLooper.dispatchAll();

            if (absVolumeIndexFix()) {
                passedIndex = i + 1;
            }
            // Stream volume changes
            verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                    AudioManager.STREAM_MUSIC, passedIndex, false,
                    AudioManager.STREAM_MUSIC, /*index=*/i + 1, false,
                    AudioSystem.DEVICE_OUT_BLE_HEADSET);
        }

@@ -209,11 +153,8 @@ public class AudioDeviceVolumeManagerTest {
        mAudioService.setDeviceVolume(volIndex4, bleDevice, mPackageName);
        mTestLooper.dispatchAll();

        if (absVolumeIndexFix()) {
            passedIndex = 4;
        }
        verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                AudioManager.STREAM_MUSIC, passedIndex, false,
                AudioManager.STREAM_MUSIC, /*index=*/4, false,
                AudioSystem.DEVICE_OUT_BLE_HEADSET);
    }
}
+2 −62
Original line number Diff line number Diff line
@@ -40,10 +40,8 @@ import static android.media.audio.Flags.autoPublicVolumeApiHardening;
import static android.view.KeyEvent.ACTION_DOWN;
import static android.view.KeyEvent.KEYCODE_VOLUME_UP;

import static com.android.media.audio.Flags.FLAG_ABS_VOLUME_INDEX_FIX;
import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME;
import static com.android.media.audio.Flags.FLAG_RING_MY_CAR;
import static com.android.media.audio.Flags.absVolumeIndexFix;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
@@ -85,7 +83,6 @@ import android.os.Looper;
import android.os.PermissionEnforcer;
import android.os.test.TestLooper;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
@@ -674,56 +671,6 @@ public class VolumeHelperTest {
                eq(STREAM_MUSIC), anyInt(), anyBoolean(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE));
    }

    @Test
    @RequiresFlagsDisabled({FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME, FLAG_ABS_VOLUME_INDEX_FIX})
    public void configurablePreScaleAbsoluteVolume_checkIndex() throws Exception {
        final int minIndex = mAm.getStreamMinVolume(STREAM_MUSIC);
        final int maxIndex = mAm.getStreamMaxVolume(STREAM_MUSIC);
        final VolumeInfo volMedia = new VolumeInfo.Builder(STREAM_MUSIC)
                .setMinVolumeIndex(minIndex)
                .setMaxVolumeIndex(maxIndex)
                .build();
        final AudioDeviceAttributes bleDevice = new AudioDeviceAttributes(
                /*native type*/ AudioSystem.DEVICE_OUT_BLE_HEADSET, /*address*/ "fake_ble");
        final int maxPreScaleIndex = 3;
        final float[] preScale = new float[maxPreScaleIndex];
        preScale[0] = mContext.getResources().getFraction(
                com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index1,
                1, 1);
        preScale[1] = mContext.getResources().getFraction(
                com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index2,
                1, 1);
        preScale[2] = mContext.getResources().getFraction(
                com.android.internal.R.fraction.config_prescaleAbsoluteVolume_index3,
                1, 1);

        for (int i = 0; i < maxPreScaleIndex; i++) {
            final int targetIndex = (int) (preScale[i] * maxIndex);
            final VolumeInfo volCur = new VolumeInfo.Builder(volMedia)
                    .setVolumeIndex(i + 1).build();
            // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:1~3)
            mAudioService.setDeviceVolume(volCur, bleDevice, mContext.getOpPackageName());
            mTestLooper.dispatchAll();

            assertEquals(volCur,
                    mAudioService.getDeviceVolume(volCur, bleDevice, mContext.getOpPackageName()));
            // Stream volume changes
            verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                    STREAM_MUSIC, targetIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET);
        }

        // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:4)
        final VolumeInfo volIndex4 = new VolumeInfo.Builder(volMedia)
                .setVolumeIndex(4).build();
        mAudioService.setDeviceVolume(volIndex4, bleDevice, mContext.getOpPackageName());
        mTestLooper.dispatchAll();

        assertEquals(volIndex4,
                mAudioService.getDeviceVolume(volIndex4, bleDevice, mContext.getOpPackageName()));
        verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                STREAM_MUSIC, maxIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET);
    }

    @Test
    @RequiresFlagsEnabled(FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME)
    public void disablePreScaleAbsoluteVolume_checkIndex() throws Exception {
@@ -736,7 +683,6 @@ public class VolumeHelperTest {
        final AudioDeviceAttributes bleDevice = new AudioDeviceAttributes(
                /*native type*/ AudioSystem.DEVICE_OUT_BLE_HEADSET, /*address*/ "bla");
        final int maxPreScaleIndex = 3;
        int passedIndex = maxIndex;

        for (int i = 0; i < maxPreScaleIndex; i++) {
            final VolumeInfo volCur = new VolumeInfo.Builder(volMedia)
@@ -745,12 +691,9 @@ public class VolumeHelperTest {
            mAudioService.setDeviceVolume(volCur, bleDevice, mContext.getOpPackageName());
            mTestLooper.dispatchAll();

            if (absVolumeIndexFix()) {
                passedIndex = i + 1;
            }
            // Stream volume changes
            verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                    STREAM_MUSIC, passedIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET);
                    STREAM_MUSIC, /*index=*/i + 1, false, AudioSystem.DEVICE_OUT_BLE_HEADSET);
        }

        // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:4)
@@ -759,11 +702,8 @@ public class VolumeHelperTest {
        mAudioService.setDeviceVolume(volIndex4, bleDevice, mContext.getOpPackageName());
        mTestLooper.dispatchAll();

        if (absVolumeIndexFix()) {
            passedIndex = 4;
        }
        verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                STREAM_MUSIC, passedIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET);
                STREAM_MUSIC, /*index=*/4, false, AudioSystem.DEVICE_OUT_BLE_HEADSET);
    }

    // ---------------- DeviceVolumeBehaviorTest ----------------