summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authormaxwen <max.weninger@gmail.com>2013-03-13 00:07:54 +0100
committerThomas Wendt <thoemy@gmx.net>2013-03-13 00:22:34 +0100
commitc1419e82f6b13cb4908433097ae30c579b39d5d0 (patch)
treeffcdbac04a1bfe21b85ed2c0b49aca24de141a05 /media
parentef44d827bd6a789b62741c32e57c29ea80289976 (diff)
downloadframeworks_base-c1419e82f6b13cb4908433097ae30c579b39d5d0.zip
frameworks_base-c1419e82f6b13cb4908433097ae30c579b39d5d0.tar.gz
frameworks_base-c1419e82f6b13cb4908433097ae30c579b39d5d0.tar.bz2
AudioService: Restore volumes after boot and when a headset is plugged
The correct volume levels for <device>_speaker and <device>_headset are not restored after booting and when a headset device is plugged in or out. This fixes a glitch where the first volume change event causes the volume to be reset to the last stored value instead of increasing/decreasting it by one step. Change-Id: I6a483af34fd6d9dd706c6979202bf0cf26d80854
Diffstat (limited to 'media')
-rwxr-xr-xmedia/java/android/media/AudioService.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 5c4b315..3343ae8 100755
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -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
@@ -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);
@@ -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
@@ -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) {