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

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

Merge "AudioService: fix deadlock"

parents f19f5057 085346ac
Loading
Loading
Loading
Loading
+53 −49
Original line number Diff line number Diff line
@@ -1028,6 +1028,7 @@ public class AudioService extends IAudioService.Stub
    }

    private void checkAllAliasStreamVolumes() {
        synchronized (mSettingsLock) {
            synchronized (VolumeStreamState.class) {
                int numStreamTypes = AudioSystem.getNumStreamTypes();
                for (int streamType = 0; streamType < numStreamTypes; streamType++) {
@@ -1040,6 +1041,7 @@ public class AudioService extends IAudioService.Stub
                }
            }
        }
    }

    private void checkAllFixedVolumeDevices()
    {
@@ -1141,13 +1143,16 @@ public class AudioService extends IAudioService.Stub
        if (updateVolumes && mStreamStates != null) {
            updateDefaultVolumes();

            mStreamStates[AudioSystem.STREAM_DTMF].setAllIndexes(mStreamStates[dtmfStreamAlias],
                    caller);

            synchronized (mSettingsLock) {
                synchronized (VolumeStreamState.class) {
                    mStreamStates[AudioSystem.STREAM_DTMF]
                            .setAllIndexes(mStreamStates[dtmfStreamAlias], caller);
                    mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].mVolumeIndexSettingName =
                            System.VOLUME_SETTINGS_INT[a11yStreamAlias];
                    mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].setAllIndexes(
                            mStreamStates[a11yStreamAlias], caller);
                }
            }
            if (sIndependentA11yVolume) {
                // restore the a11y values from the settings
                mStreamStates[AudioSystem.STREAM_ACCESSIBILITY].readSettings();
@@ -4590,12 +4595,12 @@ public class AudioService extends IAudioService.Stub
         * @param srcStream
         * @param caller
         */
        // must be sync'd on mSettingsLock before VolumeStreamState.class
        @GuardedBy("VolumeStreamState.class")
        public void setAllIndexes(VolumeStreamState srcStream, String caller) {
            if (mStreamType == srcStream.mStreamType) {
                return;
            }
            synchronized (mSettingsLock) {
                synchronized (VolumeStreamState.class) {
            int srcStreamType = srcStream.getStreamType();
            // apply default device volume from source stream to all devices first in case
            // some devices are present in this stream state but not in source stream state
@@ -4614,17 +4619,14 @@ public class AudioService extends IAudioService.Stub
                setIndex(index, device, caller);
            }
        }
            }
        }

        @GuardedBy("mSettingsLock")
        // must be sync'd on mSettingsLock before VolumeStreamState.class
        @GuardedBy("VolumeStreamState.class")
        public void setAllIndexesToMax() {
            synchronized (VolumeStreamState.class) {
            for (int i = 0; i < mIndexMap.size(); i++) {
                mIndexMap.put(mIndexMap.keyAt(i), mIndexMax);
            }
        }
        }

        public void mute(boolean state) {
            boolean changed = false;
@@ -6201,6 +6203,7 @@ public class AudioService extends IAudioService.Stub
                mCameraSoundForced = cameraSoundForced;
                if (cameraSoundForcedChanged) {
                    if (!mIsSingleVolume) {
                        synchronized (VolumeStreamState.class) {
                            VolumeStreamState s = mStreamStates[AudioSystem.STREAM_SYSTEM_ENFORCED];
                            if (cameraSoundForced) {
                                s.setAllIndexesToMax();
@@ -6211,6 +6214,7 @@ public class AudioService extends IAudioService.Stub
                                mRingerModeAffectedStreams |=
                                        (1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
                            }
                        }
                        // take new state into account for streams muted by ringer mode
                        setRingerModeInt(getRingerModeInternal(), false);
                    }