Loading media/java/android/media/AudioService.java +27 −0 Original line number Diff line number Diff line Loading @@ -529,6 +529,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished { intentFilter.addAction(Intent.ACTION_USER_BACKGROUND); intentFilter.addAction(Intent.ACTION_USER_SWITCHED); intentFilter.addAction(Intent.ACTION_WIFI_DISPLAY_AUDIO); intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); // Register a configuration change listener only if requested by system properties Loading Loading @@ -3941,6 +3942,16 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } } } } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) { state = intent.getIntExtra("state", 0); if (state == 1) { // Headset plugged in adjustCurrentStreamVolume(); // TODO: Cap volume at safe levels } else { // Headset disconnected adjustCurrentStreamVolume(); } } else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) || action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) { state = intent.getIntExtra("state", 0); Loading Loading @@ -4031,6 +4042,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished { 0, null, SAFE_VOLUME_CONFIGURE_TIMEOUT_MS); adjustCurrentStreamVolume(); } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { // a package is being removed, not replaced Loading Loading @@ -4084,6 +4097,20 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } } } private void adjustCurrentStreamVolume() { VolumeStreamState streamState; int device; for (int stream = 0; stream < AudioSystem.getNumStreamTypes(); stream++) { if (stream == mStreamVolumeAlias[stream]) { streamState = mStreamStates[mStreamVolumeAlias[stream]]; device = getDeviceForStream(stream); // apply stored value for device streamState.applyDeviceVolume(device); } } } } private void masterVolumeChanged(final int flags) { Loading Loading
media/java/android/media/AudioService.java +27 −0 Original line number Diff line number Diff line Loading @@ -529,6 +529,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished { intentFilter.addAction(Intent.ACTION_USER_BACKGROUND); intentFilter.addAction(Intent.ACTION_USER_SWITCHED); intentFilter.addAction(Intent.ACTION_WIFI_DISPLAY_AUDIO); intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); // Register a configuration change listener only if requested by system properties Loading Loading @@ -3941,6 +3942,16 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } } } } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) { state = intent.getIntExtra("state", 0); if (state == 1) { // Headset plugged in adjustCurrentStreamVolume(); // TODO: Cap volume at safe levels } else { // Headset disconnected adjustCurrentStreamVolume(); } } else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) || action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) { state = intent.getIntExtra("state", 0); Loading Loading @@ -4031,6 +4042,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished { 0, null, SAFE_VOLUME_CONFIGURE_TIMEOUT_MS); adjustCurrentStreamVolume(); } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { // a package is being removed, not replaced Loading Loading @@ -4084,6 +4097,20 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } } } private void adjustCurrentStreamVolume() { VolumeStreamState streamState; int device; for (int stream = 0; stream < AudioSystem.getNumStreamTypes(); stream++) { if (stream == mStreamVolumeAlias[stream]) { streamState = mStreamStates[mStreamVolumeAlias[stream]]; device = getDeviceForStream(stream); // apply stored value for device streamState.applyDeviceVolume(device); } } } } private void masterVolumeChanged(final int flags) { Loading