Loading media/java/android/media/AudioService.java +125 −104 Original line number Diff line number Diff line Loading @@ -821,28 +821,42 @@ public class AudioService extends IAudioService.Stub implements OnFinished { VolumeStreamState streamState = mStreamStates[streamTypeAlias]; final int device = getDeviceForStream(streamTypeAlias); // get last audible index if stream is muted, current index otherwise final int aliasIndex = streamState.getIndex(device, int aliasIndex = streamState.getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); boolean adjustVolume = true; // convert one UI step (+/-1) into a number of internal units on the stream alias int step = rescaleIndex(10, streamType, streamTypeAlias); int step; int index; int oldIndex; if ((direction == AudioManager.ADJUST_RAISE) && !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) { index = mStreamStates[streamType].getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); oldIndex = index; } else { flags &= ~AudioManager.FLAG_FIXED_VOLUME; if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { flags |= AudioManager.FLAG_FIXED_VOLUME; index = mStreamStates[streamType].getMaxIndex(); // Always toggle between max safe volume and 0 for fixed volume devices where safe // volume is enforced, and max and 0 for the others. // This is simulated by stepping by the full allowed volume range if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE && (device & mSafeMediaVolumeDevices) != 0) { step = mSafeMediaVolumeIndex; } else { step = streamState.getMaxIndex(); } if (aliasIndex != 0) { aliasIndex = step; } } else { // convert one UI step (+/-1) into a number of internal units on the stream alias step = rescaleIndex(10, streamType, streamTypeAlias); } if ((direction == AudioManager.ADJUST_RAISE) && !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) { index = mStreamStates[streamType].getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); oldIndex = index; } else { // If either the client forces allowing ringer modes for this adjustment, Loading Loading @@ -896,7 +910,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { index = mStreamStates[streamType].getIndex(device, false /* lastAudible */); } } } sendVolumeUpdate(streamType, oldIndex, index, flags); } Loading Loading @@ -924,19 +937,27 @@ public class AudioService extends IAudioService.Stub implements OnFinished { final int device = getDeviceForStream(streamType); int oldIndex; flags &= ~AudioManager.FLAG_FIXED_VOLUME; if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { flags |= AudioManager.FLAG_FIXED_VOLUME; index = mStreamStates[streamType].getMaxIndex(); oldIndex = index; } else { // get last audible index if stream is muted, current index otherwise oldIndex = streamState.getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); index = rescaleIndex(index * 10, streamType, mStreamVolumeAlias[streamType]); flags &= ~AudioManager.FLAG_FIXED_VOLUME; if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { flags |= AudioManager.FLAG_FIXED_VOLUME; // volume is either 0 or max allowed for fixed volume devices if (index != 0) { if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE && (device & mSafeMediaVolumeDevices) != 0) { index = mSafeMediaVolumeIndex; } else { index = streamState.getMaxIndex(); } } } if (!checkSafeMediaVolume(mStreamVolumeAlias[streamType], index, device)) { return; } Loading @@ -963,7 +984,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { // get last audible index if stream is muted, current index otherwise index = mStreamStates[streamType].getIndex(device, (mStreamStates[streamType].muteCount() != 0) /* lastAudible */); } sendVolumeUpdate(streamType, oldIndex, index, flags); } Loading Loading @@ -1202,13 +1222,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished { public int getStreamVolume(int streamType) { ensureValidStreamType(streamType); int device = getDeviceForStream(streamType); int index; int index = mStreamStates[streamType].getIndex(device, false /* lastAudible */); if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && if (index != 0 && (mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && (device & mFixedVolumeDevices) != 0) { index = mStreamStates[streamType].getMaxIndex(); } else { index = mStreamStates[streamType].getIndex(device, false /* lastAudible */); } return (index + 5) / 10; } Loading Loading @@ -2702,15 +2720,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } remainingDevices &= ~device; // ignore settings for fixed volume devices: volume should always be at max if ((mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { if (muteCount() == 0) { mIndex.put(device, mIndexMax); } mLastAudibleIndex.put(device, mIndexMax); continue; } // retrieve current volume for device String name = getSettingNameForDevice(false /* lastAudible */, device); // if no volume stored for current stream and device, use default volume if default Loading @@ -2723,6 +2732,18 @@ public class AudioService extends IAudioService.Stub implements OnFinished { continue; } // ignore settings for fixed volume devices: volume should always be at max or 0 if ((mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { if ((muteCount()) == 0 && (index != 0)) { mIndex.put(device, mIndexMax); } else { mIndex.put(device, 0); } mLastAudibleIndex.put(device, mIndexMax); continue; } // retrieve last audible volume for device name = getSettingNameForDevice(true /* lastAudible */, device); // use stored last audible index if present, otherwise use current index if not 0 Loading Loading
media/java/android/media/AudioService.java +125 −104 Original line number Diff line number Diff line Loading @@ -821,28 +821,42 @@ public class AudioService extends IAudioService.Stub implements OnFinished { VolumeStreamState streamState = mStreamStates[streamTypeAlias]; final int device = getDeviceForStream(streamTypeAlias); // get last audible index if stream is muted, current index otherwise final int aliasIndex = streamState.getIndex(device, int aliasIndex = streamState.getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); boolean adjustVolume = true; // convert one UI step (+/-1) into a number of internal units on the stream alias int step = rescaleIndex(10, streamType, streamTypeAlias); int step; int index; int oldIndex; if ((direction == AudioManager.ADJUST_RAISE) && !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) { index = mStreamStates[streamType].getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); oldIndex = index; } else { flags &= ~AudioManager.FLAG_FIXED_VOLUME; if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { flags |= AudioManager.FLAG_FIXED_VOLUME; index = mStreamStates[streamType].getMaxIndex(); // Always toggle between max safe volume and 0 for fixed volume devices where safe // volume is enforced, and max and 0 for the others. // This is simulated by stepping by the full allowed volume range if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE && (device & mSafeMediaVolumeDevices) != 0) { step = mSafeMediaVolumeIndex; } else { step = streamState.getMaxIndex(); } if (aliasIndex != 0) { aliasIndex = step; } } else { // convert one UI step (+/-1) into a number of internal units on the stream alias step = rescaleIndex(10, streamType, streamTypeAlias); } if ((direction == AudioManager.ADJUST_RAISE) && !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) { index = mStreamStates[streamType].getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); oldIndex = index; } else { // If either the client forces allowing ringer modes for this adjustment, Loading Loading @@ -896,7 +910,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { index = mStreamStates[streamType].getIndex(device, false /* lastAudible */); } } } sendVolumeUpdate(streamType, oldIndex, index, flags); } Loading Loading @@ -924,19 +937,27 @@ public class AudioService extends IAudioService.Stub implements OnFinished { final int device = getDeviceForStream(streamType); int oldIndex; flags &= ~AudioManager.FLAG_FIXED_VOLUME; if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { flags |= AudioManager.FLAG_FIXED_VOLUME; index = mStreamStates[streamType].getMaxIndex(); oldIndex = index; } else { // get last audible index if stream is muted, current index otherwise oldIndex = streamState.getIndex(device, (streamState.muteCount() != 0) /* lastAudible */); index = rescaleIndex(index * 10, streamType, mStreamVolumeAlias[streamType]); flags &= ~AudioManager.FLAG_FIXED_VOLUME; if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { flags |= AudioManager.FLAG_FIXED_VOLUME; // volume is either 0 or max allowed for fixed volume devices if (index != 0) { if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE && (device & mSafeMediaVolumeDevices) != 0) { index = mSafeMediaVolumeIndex; } else { index = streamState.getMaxIndex(); } } } if (!checkSafeMediaVolume(mStreamVolumeAlias[streamType], index, device)) { return; } Loading @@ -963,7 +984,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { // get last audible index if stream is muted, current index otherwise index = mStreamStates[streamType].getIndex(device, (mStreamStates[streamType].muteCount() != 0) /* lastAudible */); } sendVolumeUpdate(streamType, oldIndex, index, flags); } Loading Loading @@ -1202,13 +1222,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished { public int getStreamVolume(int streamType) { ensureValidStreamType(streamType); int device = getDeviceForStream(streamType); int index; int index = mStreamStates[streamType].getIndex(device, false /* lastAudible */); if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && if (index != 0 && (mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) && (device & mFixedVolumeDevices) != 0) { index = mStreamStates[streamType].getMaxIndex(); } else { index = mStreamStates[streamType].getIndex(device, false /* lastAudible */); } return (index + 5) / 10; } Loading Loading @@ -2702,15 +2720,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } remainingDevices &= ~device; // ignore settings for fixed volume devices: volume should always be at max if ((mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { if (muteCount() == 0) { mIndex.put(device, mIndexMax); } mLastAudibleIndex.put(device, mIndexMax); continue; } // retrieve current volume for device String name = getSettingNameForDevice(false /* lastAudible */, device); // if no volume stored for current stream and device, use default volume if default Loading @@ -2723,6 +2732,18 @@ public class AudioService extends IAudioService.Stub implements OnFinished { continue; } // ignore settings for fixed volume devices: volume should always be at max or 0 if ((mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC) && ((device & mFixedVolumeDevices) != 0)) { if ((muteCount()) == 0 && (index != 0)) { mIndex.put(device, mIndexMax); } else { mIndex.put(device, 0); } mLastAudibleIndex.put(device, mIndexMax); continue; } // retrieve last audible volume for device name = getSettingNameForDevice(true /* lastAudible */, device); // use stored last audible index if present, otherwise use current index if not 0 Loading