diff options
| -rwxr-xr-x | core/res/res/values/config.xml | 11 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 1 | ||||
| -rw-r--r-- | media/java/android/media/AudioService.java | 40 |
3 files changed, 39 insertions, 13 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 87099f855094..7927db8fa4be 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -65,6 +65,17 @@ master volume stream and nothing else . --> <bool name="config_useMasterVolume">false</bool> + <!-- Array of integer pairs controlling the rate at which the master volume changes + in response to volume up and down key events. + The first integer of each pair is compared against the current master volume + (in range 0 to 100). + The last pair with first integer <= the current volume is chosen, + and the second integer of the pair indicates the amount to increase the master volume + when volume up is pressed. --> + <integer-array name="config_masterVolumeRamp"> + <item>0</item> <item>5</item> <!-- default: always increase volume by 5% --> + </integer-array> + <!-- Flag indicating whether the AUDIO_BECOMING_NOISY notification should be sent during an change to the audio output device. --> <bool name="config_sendAudioBecomingNoisy">true</bool> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 6e374e826b65..bc08aad97e86 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -862,6 +862,7 @@ <java-symbol type="array" name="preloaded_drawables" /> <java-symbol type="array" name="special_locale_codes" /> <java-symbol type="array" name="special_locale_names" /> + <java-symbol type="array" name="config_masterVolumeRamp" /> <java-symbol type="drawable" name="default_wallpaper" /> <java-symbol type="drawable" name="ic_suggestions_add" /> diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 23060aa90b1f..eae03beae6fc 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -137,10 +137,6 @@ public class AudioService extends IAudioService.Stub { // Timeout for connection to bluetooth headset service private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; - // Amount to raise/lower master volume - // FIXME - this should probably be in a resource - private static final float MASTER_VOLUME_INCREMENT = 0.05f; - /** @see AudioSystemThread */ private AudioSystemThread mAudioSystemThread; /** @see AudioHandler */ @@ -286,6 +282,8 @@ public class AudioService extends IAudioService.Stub { // True if we have master volume support private final boolean mUseMasterVolume; + private final int[] mMasterVolumeRamp; + // List of binder death handlers for setMode() client processes. // The last process to have called setMode() is at the top of the list. private final ArrayList <SetModeDeathHandler> mSetModeDeathHandlers = new ArrayList <SetModeDeathHandler>(); @@ -416,6 +414,9 @@ public class AudioService extends IAudioService.Stub { mUseMasterVolume = context.getResources().getBoolean( com.android.internal.R.bool.config_useMasterVolume); restoreMasterVolume(); + + mMasterVolumeRamp = context.getResources().getIntArray( + com.android.internal.R.array.config_masterVolumeRamp); } private void createAudioSystemThread() { @@ -620,19 +621,27 @@ public class AudioService extends IAudioService.Stub { /** @see AudioManager#adjustMasterVolume(int) */ public void adjustMasterVolume(int direction, int flags) { ensureValidDirection(direction); - - float volume = AudioSystem.getMasterVolume(); - if (volume >= 0.0) { - // get current master volume adjusted to 0 to 100 + int volume = Math.round(AudioSystem.getMasterVolume() * MAX_MASTER_VOLUME); + int delta = 0; + for (int i = 0; i < mMasterVolumeRamp.length; i += 2) { + int testVolume = mMasterVolumeRamp[i]; + int testDelta = mMasterVolumeRamp[i + 1]; if (direction == AudioManager.ADJUST_RAISE) { - volume += MASTER_VOLUME_INCREMENT; - if (volume > 1.0f) volume = 1.0f; + if (volume >= testVolume) { + delta = testDelta; + } else { + break; + } } else if (direction == AudioManager.ADJUST_LOWER) { - volume -= MASTER_VOLUME_INCREMENT; - if (volume < 0.0f) volume = 0.0f; + if (volume - testDelta >= testVolume) { + delta = -testDelta; + } else { + break; + } } - doSetMasterVolume(volume, flags); } +// Log.d(TAG, "adjustMasterVolume volume: " + volume + " delta: " + delta + " direction: " + direction); + setMasterVolume(volume + delta, flags); } /** @see AudioManager#setStreamVolume(int, int, int) */ @@ -805,6 +814,11 @@ public class AudioService extends IAudioService.Stub { } public void setMasterVolume(int volume, int flags) { + if (volume < 0) { + volume = 0; + } else if (volume > MAX_MASTER_VOLUME) { + volume = MAX_MASTER_VOLUME; + } doSetMasterVolume((float)volume / MAX_MASTER_VOLUME, flags); } |