summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorLei Zhang <rzhang@google.com>2012-03-02 11:40:12 -0800
committerLei Zhang <rzhang@google.com>2012-03-02 11:48:28 -0800
commitd674dd50b7caf57aa8c9e7e4bc75c92d5f576167 (patch)
tree3d436753fa5193a83b77ef2f354f7d8e2169434b /media
parente5feb487dc1f9927510081aeb75601a66a688a93 (diff)
downloadframeworks_base-d674dd50b7caf57aa8c9e7e4bc75c92d5f576167.zip
frameworks_base-d674dd50b7caf57aa8c9e7e4bc75c92d5f576167.tar.gz
frameworks_base-d674dd50b7caf57aa8c9e7e4bc75c92d5f576167.tar.bz2
Add batch volume adjust support to adjustMasterVolume() in AudioManager and
AudioService. Change-Id: I34382839622a5cc5f2a8768aed011e8224cadff9
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AudioManager.java9
-rw-r--r--media/java/android/media/AudioService.java81
2 files changed, 57 insertions, 33 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index a836718..cb206b7 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -616,16 +616,15 @@ public class AudioManager {
* Adjusts the master volume for the device's audio amplifier.
* <p>
*
- * @param direction The direction to adjust the volume. One of
- * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or
- * {@link #ADJUST_SAME}.
+ * @param steps The number of volume steps to adjust. A positive
+ * value will raise the volume.
* @param flags One or more flags.
* @hide
*/
- public void adjustMasterVolume(int direction, int flags) {
+ public void adjustMasterVolume(int steps, int flags) {
IAudioService service = getService();
try {
- service.adjustMasterVolume(direction, flags);
+ service.adjustMasterVolume(steps, flags);
} catch (RemoteException e) {
Log.e(TAG, "Dead object in adjustMasterVolume", e);
}
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index e9ac807..985cdf4 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -153,6 +153,9 @@ public class AudioService extends IAudioService.Stub {
// but to support integer based AudioManager API we translate it to 0 - 100
private static final int MAX_MASTER_VOLUME = 100;
+ // Maximum volume adjust steps allowed in a single batch call.
+ private static final int MAX_BATCH_VOLUME_ADJUST_STEPS = 4;
+
/* Sound effect file names */
private static final String SOUND_EFFECTS_PATH = "/media/audio/ui/";
private static final String[] SOUND_EFFECT_FILES = new String[] {
@@ -592,38 +595,19 @@ public class AudioService extends IAudioService.Stub {
}
/** @see AudioManager#adjustMasterVolume(int) */
- public void adjustMasterVolume(int direction, int flags) {
- ensureValidDirection(direction);
+ public void adjustMasterVolume(int steps, int flags) {
+ ensureValidSteps(steps);
int volume = Math.round(AudioSystem.getMasterVolume() * MAX_MASTER_VOLUME);
int delta = 0;
-
- if (direction == AudioManager.ADJUST_RAISE) {
- // This is the default value if we make it to the end
- delta = mMasterVolumeRamp[1];
- // If we're raising the volume move down the ramp array until we
- // find the volume we're above and use that groups delta.
- for (int i = mMasterVolumeRamp.length - 1; i > 1; i -= 2) {
- if (volume >= mMasterVolumeRamp[i - 1]) {
- delta = mMasterVolumeRamp[i];
- break;
- }
- }
- } else if (direction == AudioManager.ADJUST_LOWER){
- int length = mMasterVolumeRamp.length;
- // This is the default value if we make it to the end
- delta = -mMasterVolumeRamp[length - 1];
- // If we're lowering the volume move up the ramp array until we
- // find the volume we're below and use the group below it's delta
- for (int i = 2; i < length; i += 2) {
- if (volume <= mMasterVolumeRamp[i]) {
- delta = -mMasterVolumeRamp[i - 1];
- break;
- }
- }
+ int numSteps = Math.abs(steps);
+ int direction = steps > 0 ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
+ for (int i = 0; i < numSteps; ++i) {
+ delta = findVolumeDelta(direction, volume);
+ volume += delta;
}
-// Log.d(TAG, "adjustMasterVolume volume: " + volume + " delta: " + delta + " direction: " + direction);
- setMasterVolume(volume + delta, flags);
+ //Log.d(TAG, "adjustMasterVolume volume: " + volume + " steps: " + steps);
+ setMasterVolume(volume, flags);
}
/** @see AudioManager#setStreamVolume(int, int, int) */
@@ -658,6 +642,41 @@ public class AudioService extends IAudioService.Stub {
sendVolumeUpdate(streamType, oldIndex, index, flags);
}
+ private int findVolumeDelta(int direction, int volume) {
+ int delta = 0;
+ if (direction == AudioManager.ADJUST_RAISE) {
+ if (volume == MAX_MASTER_VOLUME) {
+ return 0;
+ }
+ // This is the default value if we make it to the end
+ delta = mMasterVolumeRamp[1];
+ // If we're raising the volume move down the ramp array until we
+ // find the volume we're above and use that groups delta.
+ for (int i = mMasterVolumeRamp.length - 1; i > 1; i -= 2) {
+ if (volume >= mMasterVolumeRamp[i - 1]) {
+ delta = mMasterVolumeRamp[i];
+ break;
+ }
+ }
+ } else if (direction == AudioManager.ADJUST_LOWER){
+ if (volume == 0) {
+ return 0;
+ }
+ int length = mMasterVolumeRamp.length;
+ // This is the default value if we make it to the end
+ delta = -mMasterVolumeRamp[length - 1];
+ // If we're lowering the volume move up the ramp array until we
+ // find the volume we're below and use the group below it's delta
+ for (int i = 2; i < length; i += 2) {
+ if (volume <= mMasterVolumeRamp[i]) {
+ delta = -mMasterVolumeRamp[i - 1];
+ break;
+ }
+ }
+ }
+ return delta;
+ }
+
// UI update and Broadcast Intent
private void sendVolumeUpdate(int streamType, int oldIndex, int index, int flags) {
if (!mVoiceCapable && (streamType == AudioSystem.STREAM_RING)) {
@@ -1866,6 +1885,12 @@ public class AudioService extends IAudioService.Stub {
}
}
+ private void ensureValidSteps(int steps) {
+ if (Math.abs(steps) > MAX_BATCH_VOLUME_ADJUST_STEPS) {
+ throw new IllegalArgumentException("Bad volume adjust steps " + steps);
+ }
+ }
+
private void ensureValidStreamType(int streamType) {
if (streamType < 0 || streamType >= mStreamStates.length) {
throw new IllegalArgumentException("Bad stream type " + streamType);