@@ -137,10 +137,6 @@ public class AudioService extends IAudioService.Stub {
137137 // Timeout for connection to bluetooth headset service
138138 private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000 ;
139139
140- // Amount to raise/lower master volume
141- // FIXME - this should probably be in a resource
142- private static final float MASTER_VOLUME_INCREMENT = 0.05f ;
143-
144140 /** @see AudioSystemThread */
145141 private AudioSystemThread mAudioSystemThread ;
146142 /** @see AudioHandler */
@@ -286,6 +282,8 @@ public void onError(int error) {
286282 // True if we have master volume support
287283 private final boolean mUseMasterVolume ;
288284
285+ private final int [] mMasterVolumeRamp ;
286+
289287 // List of binder death handlers for setMode() client processes.
290288 // The last process to have called setMode() is at the top of the list.
291289 private final ArrayList <SetModeDeathHandler > mSetModeDeathHandlers = new ArrayList <SetModeDeathHandler >();
@@ -416,6 +414,9 @@ public AudioService(Context context) {
416414 mUseMasterVolume = context .getResources ().getBoolean (
417415 com .android .internal .R .bool .config_useMasterVolume );
418416 restoreMasterVolume ();
417+
418+ mMasterVolumeRamp = context .getResources ().getIntArray (
419+ com .android .internal .R .array .config_masterVolumeRamp );
419420 }
420421
421422 private void createAudioSystemThread () {
@@ -620,19 +621,27 @@ public void adjustStreamVolume(int streamType, int direction, int flags) {
620621 /** @see AudioManager#adjustMasterVolume(int) */
621622 public void adjustMasterVolume (int direction , int flags ) {
622623 ensureValidDirection (direction );
623-
624- float volume = AudioSystem .getMasterVolume ();
625- if (volume >= 0.0 ) {
626- // get current master volume adjusted to 0 to 100
624+ int volume = Math .round (AudioSystem .getMasterVolume () * MAX_MASTER_VOLUME );
625+ int delta = 0 ;
626+ for (int i = 0 ; i < mMasterVolumeRamp .length ; i += 2 ) {
627+ int testVolume = mMasterVolumeRamp [i ];
628+ int testDelta = mMasterVolumeRamp [i + 1 ];
627629 if (direction == AudioManager .ADJUST_RAISE ) {
628- volume += MASTER_VOLUME_INCREMENT ;
629- if (volume > 1.0f ) volume = 1.0f ;
630+ if (volume >= testVolume ) {
631+ delta = testDelta ;
632+ } else {
633+ break ;
634+ }
630635 } else if (direction == AudioManager .ADJUST_LOWER ) {
631- volume -= MASTER_VOLUME_INCREMENT ;
632- if (volume < 0.0f ) volume = 0.0f ;
636+ if (volume - testDelta >= testVolume ) {
637+ delta = -testDelta ;
638+ } else {
639+ break ;
640+ }
633641 }
634- doSetMasterVolume (volume , flags );
635642 }
643+ // Log.d(TAG, "adjustMasterVolume volume: " + volume + " delta: " + delta + " direction: " + direction);
644+ setMasterVolume (volume + delta , flags );
636645 }
637646
638647 /** @see AudioManager#setStreamVolume(int, int, int) */
@@ -805,6 +814,11 @@ public int getMasterVolume() {
805814 }
806815
807816 public void setMasterVolume (int volume , int flags ) {
817+ if (volume < 0 ) {
818+ volume = 0 ;
819+ } else if (volume > MAX_MASTER_VOLUME ) {
820+ volume = MAX_MASTER_VOLUME ;
821+ }
808822 doSetMasterVolume ((float )volume / MAX_MASTER_VOLUME , flags );
809823 }
810824
0 commit comments