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

Commit 3d4b7065 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 4047 into donut

* changes:
  Fix issue #899198	MODE_RINGER_STREAMS_AFFECTED does not restore volumes correctly
parents d670b8c6 9bcf401d
Loading
Loading
Loading
Loading
+35 −18
Original line number Original line Diff line number Diff line
@@ -163,6 +163,9 @@ public class AudioService extends IAudioService.Stub {
     */
     */
    private int mRingerMode;
    private int mRingerMode;


    /** @see System#MODE_RINGER_STREAMS_AFFECTED */
    private int mRingerModeAffectedStreams;

    /** @see System#MUTE_STREAMS_AFFECTED */
    /** @see System#MUTE_STREAMS_AFFECTED */
    private int mMuteAffectedStreams;
    private int mMuteAffectedStreams;


@@ -286,6 +289,10 @@ public class AudioService extends IAudioService.Stub {


        mVibrateSetting = System.getInt(cr, System.VIBRATE_ON, 0);
        mVibrateSetting = System.getInt(cr, System.VIBRATE_ON, 0);


        mRingerModeAffectedStreams = Settings.System.getInt(cr,
                Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                ((1 << AudioManager.STREAM_RING)|(1 << AudioManager.STREAM_NOTIFICATION)|(1 << AudioManager.STREAM_SYSTEM)));

        mMuteAffectedStreams = System.getInt(cr,
        mMuteAffectedStreams = System.getInt(cr,
                System.MUTE_STREAMS_AFFECTED,
                System.MUTE_STREAMS_AFFECTED,
                ((1 << AudioSystem.STREAM_MUSIC)|(1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_SYSTEM)));
                ((1 << AudioSystem.STREAM_MUSIC)|(1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_SYSTEM)));
@@ -399,7 +406,7 @@ public class AudioService extends IAudioService.Stub {
        ensureValidStreamType(streamType);
        ensureValidStreamType(streamType);
        syncRingerAndNotificationStreamVolume(streamType, index, false);
        syncRingerAndNotificationStreamVolume(streamType, index, false);


        setStreamVolumeInt(streamType, index, false);
        setStreamVolumeInt(streamType, index, false, true);


        // UI, etc.
        // UI, etc.
        mVolumePanel.postVolumeChanged(streamType, flags);
        mVolumePanel.postVolumeChanged(streamType, flags);
@@ -437,7 +444,7 @@ public class AudioService extends IAudioService.Stub {
            }
            }
            if (streamType == AudioManager.STREAM_RING) {
            if (streamType == AudioManager.STREAM_RING) {
                // One-off to sync notification volume to ringer volume
                // One-off to sync notification volume to ringer volume
                setStreamVolumeInt(AudioManager.STREAM_NOTIFICATION, index, force);
                setStreamVolumeInt(AudioManager.STREAM_NOTIFICATION, index, force, true);
            }
            }
        }
        }
    }
    }
@@ -451,10 +458,11 @@ public class AudioService extends IAudioService.Stub {
     * @param index Desired volume index of the stream
     * @param index Desired volume index of the stream
     * @param force If true, set the volume even if the desired volume is same
     * @param force If true, set the volume even if the desired volume is same
     * as the current volume.
     * as the current volume.
     * @param lastAudible If true, stores new index as last audible one
     */
     */
    private void setStreamVolumeInt(int streamType, int index, boolean force) {
    private void setStreamVolumeInt(int streamType, int index, boolean force, boolean lastAudible) {
        VolumeStreamState streamState = mStreamStates[streamType];
        VolumeStreamState streamState = mStreamStates[streamType];
        if (streamState.setIndex(index) || force) {
        if (streamState.setIndex(index, lastAudible) || force) {
            // Post message to set system volume (it in turn will post a message
            // Post message to set system volume (it in turn will post a message
            // to persist). Do not change volume if stream is muted.
            // to persist). Do not change volume if stream is muted.
            if (streamState.muteCount() == 0) {
            if (streamState.muteCount() == 0) {
@@ -517,13 +525,20 @@ public class AudioService extends IAudioService.Stub {
                if (!isStreamAffectedByRingerMode(streamType)) continue;
                if (!isStreamAffectedByRingerMode(streamType)) continue;
                // Bring back last audible volume
                // Bring back last audible volume
                setStreamVolumeInt(streamType, mStreamStates[streamType].mLastAudibleIndex,
                setStreamVolumeInt(streamType, mStreamStates[streamType].mLastAudibleIndex,
                                   false);
                                   false, false);
            }
            }
        } else {
        } else {
            for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) {
            for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) {
                if (!isStreamAffectedByRingerMode(streamType)) continue;
                if (isStreamAffectedByRingerMode(streamType)) {
                    // Either silent or vibrate, either way volume is 0
                    // Either silent or vibrate, either way volume is 0
                setStreamVolumeInt(streamType, 0, false);
                    setStreamVolumeInt(streamType, 0, false, false);
                } else {
                    // restore stream volume in the case the stream changed from affected
                    // to non affected by ringer mode. Does not arm to do it for streams that
                    // are not affected as well.
                    setStreamVolumeInt(streamType, mStreamStates[streamType].mLastAudibleIndex,
                            false, false);
                }
            }
            }
        }
        }
        
        
@@ -621,7 +636,7 @@ public class AudioService extends IAudioService.Stub {
            int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
            int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
            int index = mStreamStates[streamType].mIndex;
            int index = mStreamStates[streamType].mIndex;
            syncRingerAndNotificationStreamVolume(streamType, index, true);
            syncRingerAndNotificationStreamVolume(streamType, index, true);
            setStreamVolumeInt(streamType, index, true);
            setStreamVolumeInt(streamType, index, true, true);
        }
        }
    }
    }


@@ -791,7 +806,7 @@ public class AudioService extends IAudioService.Stub {
                int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
                int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
                int index = mStreamStates[streamType].mIndex;
                int index = mStreamStates[streamType].mIndex;
                syncRingerAndNotificationStreamVolume(streamType, index, true);
                syncRingerAndNotificationStreamVolume(streamType, index, true);
                setStreamVolumeInt(streamType, index, true);
                setStreamVolumeInt(streamType, index, true, true);
            }
            }
        }
        }
    }
    }
@@ -941,9 +956,7 @@ public class AudioService extends IAudioService.Stub {
    }
    }


    public boolean isStreamAffectedByRingerMode(int streamType) {
    public boolean isStreamAffectedByRingerMode(int streamType) {
        int ringerModeAffectedStreams = Settings.System.getInt(mContentResolver,
        return (mRingerModeAffectedStreams & (1 << streamType)) != 0;
                Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
        return (ringerModeAffectedStreams & (1 << streamType)) != 0;
    }
    }


    public boolean isStreamAffectedByMute(int streamType) {
    public boolean isStreamAffectedByMute(int streamType) {
@@ -1095,15 +1108,15 @@ public class AudioService extends IAudioService.Stub {
        }
        }


        public boolean adjustIndex(int deltaIndex) {
        public boolean adjustIndex(int deltaIndex) {
            return setIndex(mIndex + deltaIndex);
            return setIndex(mIndex + deltaIndex, true);
        }
        }


        public boolean setIndex(int index) {
        public boolean setIndex(int index, boolean lastAudible) {
            int oldIndex = mIndex;
            int oldIndex = mIndex;
            mIndex = getValidIndex(index);
            mIndex = getValidIndex(index);


            if (oldIndex != mIndex) {
            if (oldIndex != mIndex) {
                if (mIndex > 0) {
                if (lastAudible) {
                    mLastAudibleIndex = mIndex;
                    mLastAudibleIndex = mIndex;
                }
                }
                return true;
                return true;
@@ -1153,7 +1166,7 @@ public class AudioService extends IAudioService.Stub {
                                mDeathHandlers.add(this);
                                mDeathHandlers.add(this);
                                // If the stream is not yet muted by any client, set lvel to 0
                                // If the stream is not yet muted by any client, set lvel to 0
                                if (muteCount() == 0) {
                                if (muteCount() == 0) {
                                    setIndex(0);
                                    setIndex(0, false);
                                    sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0,
                                    sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0,
                                            VolumeStreamState.this, 0);
                                            VolumeStreamState.this, 0);
                                }
                                }
@@ -1180,7 +1193,7 @@ public class AudioService extends IAudioService.Stub {
                                    // If the stream is not mut any more, restore it's volume if
                                    // If the stream is not mut any more, restore it's volume if
                                    // ringer mode allows it
                                    // ringer mode allows it
                                    if (!isStreamAffectedByRingerMode(mStreamType) || mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
                                    if (!isStreamAffectedByRingerMode(mStreamType) || mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
                                        setIndex(mLastAudibleIndex);
                                        setIndex(mLastAudibleIndex, false);
                                        sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0,
                                        sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0,
                                                VolumeStreamState.this, 0);
                                                VolumeStreamState.this, 0);
                                    }
                                    }
@@ -1405,6 +1418,10 @@ public class AudioService extends IAudioService.Stub {
        public void onChange(boolean selfChange) {
        public void onChange(boolean selfChange) {
            super.onChange(selfChange);
            super.onChange(selfChange);
            
            
            mRingerModeAffectedStreams = Settings.System.getInt(mContentResolver,
                    Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                    0);

            /*
            /*
             * Ensure all stream types that should be affected by ringer mode
             * Ensure all stream types that should be affected by ringer mode
             * are in the proper state.
             * are in the proper state.