am 7c61fa70: Merge "Fix problems in tablet silent mode." into ics-mr1

* commit '7c61fa70a50e15466f807dd194e530bc4fd3a96a':
  Fix problems in tablet silent mode.
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index dd0eb58..ae058d3 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -537,6 +537,9 @@
         ensureValidDirection(direction);
         ensureValidStreamType(streamType);
 
+        // use stream type alias here so that streams with same alias have the same behavior,
+        // including with regard to silent mode control (e.g the use of STREAM_RING below and in
+        // checkForRingerModeChange() in place of STREAM_RING or STREAM_NOTIFICATION)
         int streamTypeAlias = STREAM_VOLUME_ALIAS[streamType];
         VolumeStreamState streamState = mStreamStates[streamTypeAlias];
         final int oldIndex = (streamState.muteCount() != 0) ? streamState.mLastAudibleIndex : streamState.mIndex;
@@ -545,9 +548,8 @@
         // If either the client forces allowing ringer modes for this adjustment,
         // or the stream type is one that is affected by ringer modes
         if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
-             (!mVoiceCapable && streamType != AudioSystem.STREAM_VOICE_CALL &&
-               streamType != AudioSystem.STREAM_BLUETOOTH_SCO) ||
-                (mVoiceCapable && streamTypeAlias == AudioSystem.STREAM_RING)) {
+                streamTypeAlias == AudioSystem.STREAM_RING ||
+                (!mVoiceCapable && streamTypeAlias == AudioSystem.STREAM_MUSIC)) {
             // do not vibrate if already in vibrate mode
             if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
                 flags &= ~AudioManager.FLAG_VIBRATE;
@@ -561,10 +563,19 @@
         int index;
         if (streamState.muteCount() != 0) {
             if (adjustVolume) {
-                streamState.adjustLastAudibleIndex(direction);
-                // Post a persist volume msg
-                sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
-                        SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
+                // adjust volume on all stream types sharing the same alias otherwise a query
+                // on last audible index for an alias would not give the correct value
+                int numStreamTypes = AudioSystem.getNumStreamTypes();
+                for (int i = numStreamTypes - 1; i >= 0; i--) {
+                    if (STREAM_VOLUME_ALIAS[i] == streamTypeAlias) {
+                        VolumeStreamState s = mStreamStates[i];
+
+                        s.adjustLastAudibleIndex(direction);
+                        // Post a persist volume msg
+                        sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, i,
+                                SENDMSG_REPLACE, 0, 1, s, PERSIST_DELAY);
+                    }
+                }
             }
             index = streamState.mLastAudibleIndex;
         } else {