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

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

Merge "audioservice: fix media volume reset at boot" into oc-dr1-dev

parents d8fdb26e b378a13a
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -692,7 +692,6 @@ public class AudioService extends IAudioService.Stub
        // the mcc is read by onConfigureSafeVolume()
        mSafeMediaVolumeIndex = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_safe_media_volume_index) * 10;
        mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();

        mUseFixedVolume = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_useFixedVolume);
@@ -705,6 +704,10 @@ public class AudioService extends IAudioService.Stub
        mSettingsObserver = new SettingsObserver();
        createStreamStates();

        // mSafeUsbMediaVolumeIndex must be initialized after createStreamStates() because it
        // relies on audio policy having correct ranges for volume indexes.
        mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();

        mMediaFocusControl = new MediaFocusControl(mContext, mPlaybackMonitor);

        readAndSetLowRamDevice();
@@ -3465,13 +3468,13 @@ public class AudioService extends IAudioService.Stub
            int index = (max + min) / 2;
            float gainDB = AudioSystem.getStreamVolumeDB(
                    AudioSystem.STREAM_MUSIC, index, AudioSystem.DEVICE_OUT_USB_HEADSET);
            if (gainDB == Float.NaN) {
            if (Float.isNaN(gainDB)) {
                //keep last min in case of read error
                break;
            } else if (gainDB == SAVE_VOLUME_GAIN_DBFS) {
            } else if (gainDB == SAFE_VOLUME_GAIN_DBFS) {
                min = index;
                break;
            } else if (gainDB < SAVE_VOLUME_GAIN_DBFS) {
            } else if (gainDB < SAFE_VOLUME_GAIN_DBFS) {
                min = index;
            } else {
                max = index;
@@ -5996,11 +5999,14 @@ public class AudioService extends IAudioService.Stub
    private int mMcc = 0;
    // mSafeMediaVolumeIndex is the cached value of config_safe_media_volume_index property
    private int mSafeMediaVolumeIndex;
    // mSafeUsbMediaVolumeIndex is used for USB Headsets and is to the music volume
    // UI index corresponding to a gain of -15 dBFS. This corresponds to a loudness of 85 dB SPL
    // if the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
    // mSafeUsbMediaVolumeIndex is used for USB Headsets and is the music volume UI index
    // corresponding to a gain of -30 dBFS in audio flinger mixer.
    // We remove -15 dBs from the theoretical -15dB to account for the EQ boost when bands are set
    // to max gain.
    // This level corresponds to a loudness of 85 dB SPL for the warning to be displayed when
    // the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
    private int mSafeUsbMediaVolumeIndex;
    private static final float SAVE_VOLUME_GAIN_DBFS = -15;
    private static final float SAFE_VOLUME_GAIN_DBFS = -30.0f;
    // mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced,
    private final int mSafeMediaVolumeDevices = AudioSystem.DEVICE_OUT_WIRED_HEADSET |
                                                AudioSystem.DEVICE_OUT_WIRED_HEADPHONE |