@@ -424,6 +424,11 @@ public void onError(int error) {
424424 */
425425 public final static int STREAM_REMOTE_MUSIC = -200 ;
426426
427+ // Devices for which the volume is fixed and VolumePanel slider should be disabled
428+ final int mFixedVolumeDevices = AudioSystem .DEVICE_OUT_AUX_DIGITAL |
429+ AudioSystem .DEVICE_OUT_DGTL_DOCK_HEADSET |
430+ AudioSystem .DEVICE_OUT_ALL_USB ;
431+
427432 ///////////////////////////////////////////////////////////////////////////
428433 // Construction
429434 ///////////////////////////////////////////////////////////////////////////
@@ -762,58 +767,66 @@ public void adjustStreamVolume(int streamType, int direction, int flags) {
762767 return ;
763768 }
764769
765- // If either the client forces allowing ringer modes for this adjustment,
766- // or the stream type is one that is affected by ringer modes
767- if (((flags & AudioManager .FLAG_ALLOW_RINGER_MODES ) != 0 ) ||
768- (streamTypeAlias == getMasterStreamType ())) {
769- int ringerMode = getRingerMode ();
770- // do not vibrate if already in vibrate mode
771- if (ringerMode == AudioManager .RINGER_MODE_VIBRATE ) {
772- flags &= ~AudioManager .FLAG_VIBRATE ;
773- }
774- // Check if the ringer mode changes with this volume adjustment. If
775- // it does, it will handle adjusting the volume, so we won't below
776- adjustVolume = checkForRingerModeChange (aliasIndex , direction , step );
777- if ((streamTypeAlias == getMasterStreamType ()) &&
778- (mRingerMode == AudioManager .RINGER_MODE_SILENT )) {
779- streamState .setLastAudibleIndex (0 , device );
780- }
781- }
782-
783- // If stream is muted, adjust last audible index only
784770 int index ;
785- final int oldIndex = mStreamStates [streamType ].getIndex (device ,
786- (mStreamStates [streamType ].muteCount () != 0 ) /* lastAudible */ );
771+ int oldIndex ;
787772
788- if (streamState .muteCount () != 0 ) {
789- if (adjustVolume ) {
790- // Post a persist volume msg
791- // no need to persist volume on all streams sharing the same alias
792- streamState .adjustLastAudibleIndex (direction * step , device );
793- sendMsg (mAudioHandler ,
794- MSG_PERSIST_VOLUME ,
795- SENDMSG_QUEUE ,
796- PERSIST_LAST_AUDIBLE ,
797- device ,
798- streamState ,
799- PERSIST_DELAY );
800- }
801- index = mStreamStates [streamType ].getIndex (device , true /* lastAudible */ );
773+ if ((streamTypeAlias == AudioSystem .STREAM_MUSIC ) &&
774+ ((device & mFixedVolumeDevices ) != 0 )) {
775+ flags |= AudioManager .FLAG_FIXED_VOLUME ;
776+ index = mStreamStates [streamType ].getMaxIndex ();
777+ oldIndex = index ;
802778 } else {
803- if (adjustVolume && streamState .adjustIndex (direction * step , device )) {
804- // Post message to set system volume (it in turn will post a message
805- // to persist). Do not change volume if stream is muted.
806- sendMsg (mAudioHandler ,
807- MSG_SET_DEVICE_VOLUME ,
808- SENDMSG_QUEUE ,
809- device ,
810- 0 ,
811- streamState ,
812- 0 );
779+ // If either the client forces allowing ringer modes for this adjustment,
780+ // or the stream type is one that is affected by ringer modes
781+ if (((flags & AudioManager .FLAG_ALLOW_RINGER_MODES ) != 0 ) ||
782+ (streamTypeAlias == getMasterStreamType ())) {
783+ int ringerMode = getRingerMode ();
784+ // do not vibrate if already in vibrate mode
785+ if (ringerMode == AudioManager .RINGER_MODE_VIBRATE ) {
786+ flags &= ~AudioManager .FLAG_VIBRATE ;
787+ }
788+ // Check if the ringer mode changes with this volume adjustment. If
789+ // it does, it will handle adjusting the volume, so we won't below
790+ adjustVolume = checkForRingerModeChange (aliasIndex , direction , step );
791+ if ((streamTypeAlias == getMasterStreamType ()) &&
792+ (mRingerMode == AudioManager .RINGER_MODE_SILENT )) {
793+ streamState .setLastAudibleIndex (0 , device );
794+ }
813795 }
814- index = mStreamStates [streamType ].getIndex (device , false /* lastAudible */ );
815- }
816796
797+ // If stream is muted, adjust last audible index only
798+ oldIndex = mStreamStates [streamType ].getIndex (device ,
799+ (mStreamStates [streamType ].muteCount () != 0 ) /* lastAudible */ );
800+
801+ if (streamState .muteCount () != 0 ) {
802+ if (adjustVolume ) {
803+ // Post a persist volume msg
804+ // no need to persist volume on all streams sharing the same alias
805+ streamState .adjustLastAudibleIndex (direction * step , device );
806+ sendMsg (mAudioHandler ,
807+ MSG_PERSIST_VOLUME ,
808+ SENDMSG_QUEUE ,
809+ PERSIST_LAST_AUDIBLE ,
810+ device ,
811+ streamState ,
812+ PERSIST_DELAY );
813+ }
814+ index = mStreamStates [streamType ].getIndex (device , true /* lastAudible */ );
815+ } else {
816+ if (adjustVolume && streamState .adjustIndex (direction * step , device )) {
817+ // Post message to set system volume (it in turn will post a message
818+ // to persist). Do not change volume if stream is muted.
819+ sendMsg (mAudioHandler ,
820+ MSG_SET_DEVICE_VOLUME ,
821+ SENDMSG_QUEUE ,
822+ device ,
823+ 0 ,
824+ streamState ,
825+ 0 );
826+ }
827+ index = mStreamStates [streamType ].getIndex (device , false /* lastAudible */ );
828+ }
829+ }
817830 sendVolumeUpdate (streamType , oldIndex , index , flags );
818831 }
819832
@@ -839,40 +852,47 @@ public void setStreamVolume(int streamType, int index, int flags) {
839852 VolumeStreamState streamState = mStreamStates [mStreamVolumeAlias [streamType ]];
840853
841854 final int device = getDeviceForStream (streamType );
855+ int oldIndex ;
842856
843- // get last audible index if stream is muted, current index otherwise
844- final int oldIndex = streamState .getIndex (device ,
845- (streamState .muteCount () != 0 ) /* lastAudible */ );
846-
847- index = rescaleIndex (index * 10 , streamType , mStreamVolumeAlias [streamType ]);
857+ if ((mStreamVolumeAlias [streamType ] == AudioSystem .STREAM_MUSIC ) &&
858+ ((device & mFixedVolumeDevices ) != 0 )) {
859+ flags |= AudioManager .FLAG_FIXED_VOLUME ;
860+ index = mStreamStates [streamType ].getMaxIndex ();
861+ oldIndex = index ;
862+ } else {
863+ // get last audible index if stream is muted, current index otherwise
864+ oldIndex = streamState .getIndex (device ,
865+ (streamState .muteCount () != 0 ) /* lastAudible */ );
848866
849- if (!checkSafeMediaVolume (mStreamVolumeAlias [streamType ], index , device )) {
850- return ;
851- }
867+ index = rescaleIndex (index * 10 , streamType , mStreamVolumeAlias [streamType ]);
852868
853- // setting volume on master stream type also controls silent mode
854- if (((flags & AudioManager .FLAG_ALLOW_RINGER_MODES ) != 0 ) ||
855- (mStreamVolumeAlias [streamType ] == getMasterStreamType ())) {
856- int newRingerMode ;
857- if (index == 0 ) {
858- newRingerMode = mHasVibrator ? AudioManager .RINGER_MODE_VIBRATE
859- : AudioManager .RINGER_MODE_SILENT ;
860- setStreamVolumeInt (mStreamVolumeAlias [streamType ],
861- index ,
862- device ,
863- false ,
864- true );
865- } else {
866- newRingerMode = AudioManager .RINGER_MODE_NORMAL ;
869+ if (!checkSafeMediaVolume (mStreamVolumeAlias [streamType ], index , device )) {
870+ return ;
867871 }
868- setRingerMode (newRingerMode );
869- }
870872
871- setStreamVolumeInt (mStreamVolumeAlias [streamType ], index , device , false , true );
872- // get last audible index if stream is muted, current index otherwise
873- index = mStreamStates [streamType ].getIndex (device ,
874- (mStreamStates [streamType ].muteCount () != 0 ) /* lastAudible */ );
873+ // setting volume on master stream type also controls silent mode
874+ if (((flags & AudioManager .FLAG_ALLOW_RINGER_MODES ) != 0 ) ||
875+ (mStreamVolumeAlias [streamType ] == getMasterStreamType ())) {
876+ int newRingerMode ;
877+ if (index == 0 ) {
878+ newRingerMode = mHasVibrator ? AudioManager .RINGER_MODE_VIBRATE
879+ : AudioManager .RINGER_MODE_SILENT ;
880+ setStreamVolumeInt (mStreamVolumeAlias [streamType ],
881+ index ,
882+ device ,
883+ false ,
884+ true );
885+ } else {
886+ newRingerMode = AudioManager .RINGER_MODE_NORMAL ;
887+ }
888+ setRingerMode (newRingerMode );
889+ }
875890
891+ setStreamVolumeInt (mStreamVolumeAlias [streamType ], index , device , false , true );
892+ // get last audible index if stream is muted, current index otherwise
893+ index = mStreamStates [streamType ].getIndex (device ,
894+ (mStreamStates [streamType ].muteCount () != 0 ) /* lastAudible */ );
895+ }
876896 sendVolumeUpdate (streamType , oldIndex , index , flags );
877897 }
878898
@@ -988,13 +1008,15 @@ private void sendVolumeUpdate(int streamType, int oldIndex, int index, int flags
9881008
9891009 mVolumePanel .postVolumeChanged (streamType , flags );
9901010
991- oldIndex = (oldIndex + 5 ) / 10 ;
992- index = (index + 5 ) / 10 ;
993- Intent intent = new Intent (AudioManager .VOLUME_CHANGED_ACTION );
994- intent .putExtra (AudioManager .EXTRA_VOLUME_STREAM_TYPE , streamType );
995- intent .putExtra (AudioManager .EXTRA_VOLUME_STREAM_VALUE , index );
996- intent .putExtra (AudioManager .EXTRA_PREV_VOLUME_STREAM_VALUE , oldIndex );
997- sendBroadcastToAll (intent );
1011+ if ((flags & AudioManager .FLAG_FIXED_VOLUME ) == 0 ) {
1012+ oldIndex = (oldIndex + 5 ) / 10 ;
1013+ index = (index + 5 ) / 10 ;
1014+ Intent intent = new Intent (AudioManager .VOLUME_CHANGED_ACTION );
1015+ intent .putExtra (AudioManager .EXTRA_VOLUME_STREAM_TYPE , streamType );
1016+ intent .putExtra (AudioManager .EXTRA_VOLUME_STREAM_VALUE , index );
1017+ intent .putExtra (AudioManager .EXTRA_PREV_VOLUME_STREAM_VALUE , oldIndex );
1018+ sendBroadcastToAll (intent );
1019+ }
9981020 }
9991021
10001022 // UI update and Broadcast Intent
@@ -1109,7 +1131,15 @@ public boolean isMasterMute() {
11091131 public int getStreamVolume (int streamType ) {
11101132 ensureValidStreamType (streamType );
11111133 int device = getDeviceForStream (streamType );
1112- return (mStreamStates [streamType ].getIndex (device , false /* lastAudible */ ) + 5 ) / 10 ;
1134+ int index ;
1135+
1136+ if ((mStreamVolumeAlias [streamType ] == AudioSystem .STREAM_MUSIC ) &&
1137+ (device & mFixedVolumeDevices ) != 0 ) {
1138+ index = mStreamStates [streamType ].getMaxIndex ();
1139+ } else {
1140+ index = mStreamStates [streamType ].getIndex (device , false /* lastAudible */ );
1141+ }
1142+ return (index + 5 ) / 10 ;
11131143 }
11141144
11151145 public int getMasterVolume () {
0 commit comments