Loading media/java/android/media/AudioService.java +35 −18 Original line number Diff line number Diff line Loading @@ -163,6 +163,9 @@ public class AudioService extends IAudioService.Stub { */ private int mRingerMode; /** @see System#MODE_RINGER_STREAMS_AFFECTED */ private int mRingerModeAffectedStreams; /** @see System#MUTE_STREAMS_AFFECTED */ private int mMuteAffectedStreams; Loading Loading @@ -286,6 +289,10 @@ public class AudioService extends IAudioService.Stub { 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, System.MUTE_STREAMS_AFFECTED, ((1 << AudioSystem.STREAM_MUSIC)|(1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_SYSTEM))); Loading Loading @@ -399,7 +406,7 @@ public class AudioService extends IAudioService.Stub { ensureValidStreamType(streamType); syncRingerAndNotificationStreamVolume(streamType, index, false); setStreamVolumeInt(streamType, index, false); setStreamVolumeInt(streamType, index, false, true); // UI, etc. mVolumePanel.postVolumeChanged(streamType, flags); Loading Loading @@ -437,7 +444,7 @@ public class AudioService extends IAudioService.Stub { } if (streamType == AudioManager.STREAM_RING) { // One-off to sync notification volume to ringer volume setStreamVolumeInt(AudioManager.STREAM_NOTIFICATION, index, force); setStreamVolumeInt(AudioManager.STREAM_NOTIFICATION, index, force, true); } } } Loading @@ -451,10 +458,11 @@ public class AudioService extends IAudioService.Stub { * @param index Desired volume index of the stream * @param force If true, set the volume even if the desired volume is same * 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]; if (streamState.setIndex(index) || force) { if (streamState.setIndex(index, lastAudible) || force) { // Post message to set system volume (it in turn will post a message // to persist). Do not change volume if stream is muted. if (streamState.muteCount() == 0) { Loading Loading @@ -517,13 +525,20 @@ public class AudioService extends IAudioService.Stub { if (!isStreamAffectedByRingerMode(streamType)) continue; // Bring back last audible volume setStreamVolumeInt(streamType, mStreamStates[streamType].mLastAudibleIndex, false); false, false); } } else { for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { if (!isStreamAffectedByRingerMode(streamType)) continue; if (isStreamAffectedByRingerMode(streamType)) { // 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); } } } Loading Loading @@ -621,7 +636,7 @@ public class AudioService extends IAudioService.Stub { int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE); int index = mStreamStates[streamType].mIndex; syncRingerAndNotificationStreamVolume(streamType, index, true); setStreamVolumeInt(streamType, index, true); setStreamVolumeInt(streamType, index, true, true); } } Loading Loading @@ -791,7 +806,7 @@ public class AudioService extends IAudioService.Stub { int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE); int index = mStreamStates[streamType].mIndex; syncRingerAndNotificationStreamVolume(streamType, index, true); setStreamVolumeInt(streamType, index, true); setStreamVolumeInt(streamType, index, true, true); } } } Loading Loading @@ -941,9 +956,7 @@ public class AudioService extends IAudioService.Stub { } public boolean isStreamAffectedByRingerMode(int streamType) { int ringerModeAffectedStreams = Settings.System.getInt(mContentResolver, Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); return (ringerModeAffectedStreams & (1 << streamType)) != 0; return (mRingerModeAffectedStreams & (1 << streamType)) != 0; } public boolean isStreamAffectedByMute(int streamType) { Loading Loading @@ -1095,15 +1108,15 @@ public class AudioService extends IAudioService.Stub { } 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; mIndex = getValidIndex(index); if (oldIndex != mIndex) { if (mIndex > 0) { if (lastAudible) { mLastAudibleIndex = mIndex; } return true; Loading Loading @@ -1153,7 +1166,7 @@ public class AudioService extends IAudioService.Stub { mDeathHandlers.add(this); // If the stream is not yet muted by any client, set lvel to 0 if (muteCount() == 0) { setIndex(0); setIndex(0, false); sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0, VolumeStreamState.this, 0); } Loading @@ -1180,7 +1193,7 @@ public class AudioService extends IAudioService.Stub { // If the stream is not mut any more, restore it's volume if // ringer mode allows it if (!isStreamAffectedByRingerMode(mStreamType) || mRingerMode == AudioManager.RINGER_MODE_NORMAL) { setIndex(mLastAudibleIndex); setIndex(mLastAudibleIndex, false); sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0, VolumeStreamState.this, 0); } Loading Loading @@ -1405,6 +1418,10 @@ public class AudioService extends IAudioService.Stub { public void onChange(boolean 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 * are in the proper state. Loading Loading
media/java/android/media/AudioService.java +35 −18 Original line number Diff line number Diff line Loading @@ -163,6 +163,9 @@ public class AudioService extends IAudioService.Stub { */ private int mRingerMode; /** @see System#MODE_RINGER_STREAMS_AFFECTED */ private int mRingerModeAffectedStreams; /** @see System#MUTE_STREAMS_AFFECTED */ private int mMuteAffectedStreams; Loading Loading @@ -286,6 +289,10 @@ public class AudioService extends IAudioService.Stub { 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, System.MUTE_STREAMS_AFFECTED, ((1 << AudioSystem.STREAM_MUSIC)|(1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_SYSTEM))); Loading Loading @@ -399,7 +406,7 @@ public class AudioService extends IAudioService.Stub { ensureValidStreamType(streamType); syncRingerAndNotificationStreamVolume(streamType, index, false); setStreamVolumeInt(streamType, index, false); setStreamVolumeInt(streamType, index, false, true); // UI, etc. mVolumePanel.postVolumeChanged(streamType, flags); Loading Loading @@ -437,7 +444,7 @@ public class AudioService extends IAudioService.Stub { } if (streamType == AudioManager.STREAM_RING) { // One-off to sync notification volume to ringer volume setStreamVolumeInt(AudioManager.STREAM_NOTIFICATION, index, force); setStreamVolumeInt(AudioManager.STREAM_NOTIFICATION, index, force, true); } } } Loading @@ -451,10 +458,11 @@ public class AudioService extends IAudioService.Stub { * @param index Desired volume index of the stream * @param force If true, set the volume even if the desired volume is same * 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]; if (streamState.setIndex(index) || force) { if (streamState.setIndex(index, lastAudible) || force) { // Post message to set system volume (it in turn will post a message // to persist). Do not change volume if stream is muted. if (streamState.muteCount() == 0) { Loading Loading @@ -517,13 +525,20 @@ public class AudioService extends IAudioService.Stub { if (!isStreamAffectedByRingerMode(streamType)) continue; // Bring back last audible volume setStreamVolumeInt(streamType, mStreamStates[streamType].mLastAudibleIndex, false); false, false); } } else { for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { if (!isStreamAffectedByRingerMode(streamType)) continue; if (isStreamAffectedByRingerMode(streamType)) { // 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); } } } Loading Loading @@ -621,7 +636,7 @@ public class AudioService extends IAudioService.Stub { int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE); int index = mStreamStates[streamType].mIndex; syncRingerAndNotificationStreamVolume(streamType, index, true); setStreamVolumeInt(streamType, index, true); setStreamVolumeInt(streamType, index, true, true); } } Loading Loading @@ -791,7 +806,7 @@ public class AudioService extends IAudioService.Stub { int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE); int index = mStreamStates[streamType].mIndex; syncRingerAndNotificationStreamVolume(streamType, index, true); setStreamVolumeInt(streamType, index, true); setStreamVolumeInt(streamType, index, true, true); } } } Loading Loading @@ -941,9 +956,7 @@ public class AudioService extends IAudioService.Stub { } public boolean isStreamAffectedByRingerMode(int streamType) { int ringerModeAffectedStreams = Settings.System.getInt(mContentResolver, Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); return (ringerModeAffectedStreams & (1 << streamType)) != 0; return (mRingerModeAffectedStreams & (1 << streamType)) != 0; } public boolean isStreamAffectedByMute(int streamType) { Loading Loading @@ -1095,15 +1108,15 @@ public class AudioService extends IAudioService.Stub { } 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; mIndex = getValidIndex(index); if (oldIndex != mIndex) { if (mIndex > 0) { if (lastAudible) { mLastAudibleIndex = mIndex; } return true; Loading Loading @@ -1153,7 +1166,7 @@ public class AudioService extends IAudioService.Stub { mDeathHandlers.add(this); // If the stream is not yet muted by any client, set lvel to 0 if (muteCount() == 0) { setIndex(0); setIndex(0, false); sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0, VolumeStreamState.this, 0); } Loading @@ -1180,7 +1193,7 @@ public class AudioService extends IAudioService.Stub { // If the stream is not mut any more, restore it's volume if // ringer mode allows it if (!isStreamAffectedByRingerMode(mStreamType) || mRingerMode == AudioManager.RINGER_MODE_NORMAL) { setIndex(mLastAudibleIndex); setIndex(mLastAudibleIndex, false); sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, mStreamType, SENDMSG_NOOP, 0, 0, VolumeStreamState.this, 0); } Loading Loading @@ -1405,6 +1418,10 @@ public class AudioService extends IAudioService.Stub { public void onChange(boolean 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 * are in the proper state. Loading