summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Tunstall <ptunstall@gmail.com>2012-05-22 14:43:28 +0100
committerSteve Kondik <shade@chemlab.org>2012-05-28 04:19:17 -0700
commit7619ca4ea3f565d86214a88e514beb320268d1bd (patch)
treee37112937ec351c038a8a89cf6ba7af5c48d5081
parent4f2fa52476131dea43ebde95333ec149d0e6d468 (diff)
downloadframeworks_base-7619ca4ea3f565d86214a88e514beb320268d1bd.zip
frameworks_base-7619ca4ea3f565d86214a88e514beb320268d1bd.tar.gz
frameworks_base-7619ca4ea3f565d86214a88e514beb320268d1bd.tar.bz2
Sound preference: Safe volume restore when plugging in a headset (1/2)
When enabled, volumes that were above a threshold (~55%) the previous time something was connected to the audio jack will be restored to that threshold rather than their full level. Affects all sound streams apart from voice call audio. Change-Id: I0007a09ce75b55c95986e38a4cbb24fe4e8200a9
-rw-r--r--core/java/android/provider/Settings.java5
-rw-r--r--media/java/android/media/AudioService.java29
2 files changed, 33 insertions, 1 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 550fba3..69aa0eb 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1627,6 +1627,11 @@ public final class Settings {
public static final String VOLUME_BLUETOOTH_SCO = "volume_bluetooth_sco";
/**
+ * Whether to prevent loud volume levels when headset is first plugged in.
+ */
+ public static final String SAFE_HEADSET_VOLUME_RESTORE = "safe_headset_volume_restore";
+
+ /**
* Whether the notifications should use the ring volume (value of 1) or a separate
* notification volume (value of 0). In most cases, users will have this enabled so the
* notification and ringer volumes will be the same. However, power users can disable this
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index aebd1e3..b557dd9 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -2572,6 +2572,15 @@ public class AudioService extends IAudioService.Stub {
//Save and restore volumes for headset and speaker
int lastVolume;
if (state == 1) {
+ // Headset plugged in
+ int volumeRestoreCap;
+ if (Settings.System.getInt(mContentResolver,
+ Settings.System.SAFE_HEADSET_VOLUME_RESTORE, 1) == 0) {
+ // Don't cap
+ volumeRestoreCap = 8;
+ } else {
+ volumeRestoreCap = 4;
+ }
for (int stream = 0; stream < STREAM_VOLUME_HEADSET_SETTINGS.length; stream++) {
try {
lastVolume = System.getInt(mContentResolver,
@@ -2582,9 +2591,27 @@ public class AudioService extends IAudioService.Stub {
System.putInt(mContentResolver, STREAM_VOLUME_SPEAKER_SETTINGS[stream],
getStreamVolume(stream));
if (lastVolume >= 0)
- setStreamVolume(stream, lastVolume, 0);
+ if (stream == 0) {
+ // Don't touch voice call volume
+ setStreamVolume(stream, lastVolume, 0);
+ } else if (stream != 3) {
+ if (lastVolume > volumeRestoreCap) {
+ setStreamVolume(stream, volumeRestoreCap, 0);
+ } else {
+ setStreamVolume(stream, lastVolume, 0);
+ }
+ } else {
+ // For media volume the cap is doubled to correspond
+ // with its finer granularity
+ if (lastVolume > (volumeRestoreCap * 2)) {
+ setStreamVolume(stream, (volumeRestoreCap * 2), 0);
+ } else {
+ setStreamVolume(stream, lastVolume, 0);
+ }
+ }
}
} else {
+ // Headset disconnected
for (int stream = 0; stream < STREAM_VOLUME_SPEAKER_SETTINGS.length; stream++) {
try {
lastVolume = System.getInt(mContentResolver,