Loading media/java/android/media/AudioService.java +15 −8 Original line number Diff line number Diff line Loading @@ -279,7 +279,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished { private boolean mLinkNotificationWithVolume; private static final int HEADSET_VOLUME_RESTORE_CAP_MUSIC = 8; // Out of 15 // Cap used for safe headset volume restore. The value directly applies // to AudioSystem.STREAM_MUSIC volume and is rescaled for other streams. private static final int HEADSET_VOLUME_RESTORE_CAP = 10; private final AudioSystem.ErrorCallback mAudioSystemCallback = new AudioSystem.ErrorCallback() { public void onError(int error) { Loading Loading @@ -2392,12 +2394,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished { int device = AudioSystem.getDevicesForStream(stream); if ((device & (device - 1)) != 0) { // Multiple device selection is either: // - speaker + one other device: give priority to speaker in this case. // - speaker + one other device: give priority to the non-speaker device in this case. // - one A2DP device + another device: happens with duplicated output. In this case // retain the device on the A2DP output as the other must not correspond to an active // selection if not the speaker. if ((device & AudioSystem.DEVICE_OUT_SPEAKER) != 0) { device = AudioSystem.DEVICE_OUT_SPEAKER; device ^= AudioSystem.DEVICE_OUT_SPEAKER; } else { device &= AudioSystem.DEVICE_OUT_ALL_A2DP; } Loading Loading @@ -3543,14 +3545,19 @@ public class AudioService extends IAudioService.Stub implements OnFinished { setBluetoothA2dpOnInt(false); } // Media volume restore capping // Volume restore capping final boolean capVolumeRestore = Settings.System.getInt(mContentResolver, Settings.System.SAFE_HEADSET_VOLUME_RESTORE, 1) == 1; if (capVolumeRestore) { final int volume = getStreamVolume(AudioSystem.STREAM_MUSIC); if (volume > HEADSET_VOLUME_RESTORE_CAP_MUSIC) { setStreamVolume(AudioSystem.STREAM_MUSIC, HEADSET_VOLUME_RESTORE_CAP_MUSIC, 0); for (int stream = 0; stream < AudioSystem.getNumStreamTypes(); stream++) { if (stream == mStreamVolumeAlias[stream]) { final int volume = getStreamVolume(stream); final int restoreCap = rescaleIndex(HEADSET_VOLUME_RESTORE_CAP, AudioSystem.STREAM_MUSIC, stream); if (volume > restoreCap) { setStreamVolume(stream, restoreCap, 0); } } } } } else { Loading Loading
media/java/android/media/AudioService.java +15 −8 Original line number Diff line number Diff line Loading @@ -279,7 +279,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished { private boolean mLinkNotificationWithVolume; private static final int HEADSET_VOLUME_RESTORE_CAP_MUSIC = 8; // Out of 15 // Cap used for safe headset volume restore. The value directly applies // to AudioSystem.STREAM_MUSIC volume and is rescaled for other streams. private static final int HEADSET_VOLUME_RESTORE_CAP = 10; private final AudioSystem.ErrorCallback mAudioSystemCallback = new AudioSystem.ErrorCallback() { public void onError(int error) { Loading Loading @@ -2392,12 +2394,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished { int device = AudioSystem.getDevicesForStream(stream); if ((device & (device - 1)) != 0) { // Multiple device selection is either: // - speaker + one other device: give priority to speaker in this case. // - speaker + one other device: give priority to the non-speaker device in this case. // - one A2DP device + another device: happens with duplicated output. In this case // retain the device on the A2DP output as the other must not correspond to an active // selection if not the speaker. if ((device & AudioSystem.DEVICE_OUT_SPEAKER) != 0) { device = AudioSystem.DEVICE_OUT_SPEAKER; device ^= AudioSystem.DEVICE_OUT_SPEAKER; } else { device &= AudioSystem.DEVICE_OUT_ALL_A2DP; } Loading Loading @@ -3543,14 +3545,19 @@ public class AudioService extends IAudioService.Stub implements OnFinished { setBluetoothA2dpOnInt(false); } // Media volume restore capping // Volume restore capping final boolean capVolumeRestore = Settings.System.getInt(mContentResolver, Settings.System.SAFE_HEADSET_VOLUME_RESTORE, 1) == 1; if (capVolumeRestore) { final int volume = getStreamVolume(AudioSystem.STREAM_MUSIC); if (volume > HEADSET_VOLUME_RESTORE_CAP_MUSIC) { setStreamVolume(AudioSystem.STREAM_MUSIC, HEADSET_VOLUME_RESTORE_CAP_MUSIC, 0); for (int stream = 0; stream < AudioSystem.getNumStreamTypes(); stream++) { if (stream == mStreamVolumeAlias[stream]) { final int volume = getStreamVolume(stream); final int restoreCap = rescaleIndex(HEADSET_VOLUME_RESTORE_CAP, AudioSystem.STREAM_MUSIC, stream); if (volume > restoreCap) { setStreamVolume(stream, restoreCap, 0); } } } } } else { Loading