am 13d1057d: am 2610d712: Don\'t unmute when trying to show volume UI. DO NOT MERGE

* commit '13d1057d5b3ca46d00d627a89f0d37836b9db8fd':
  Don't unmute when trying to show volume UI. DO NOT MERGE
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index 1fba7bb..03a5920 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -93,7 +93,6 @@
     private final MediaSessionService mService;
     private final boolean mUseMasterVolume;
 
-    private final IBinder mICallback = new Binder();
     private final Object mLock = new Object();
     private final ArrayList<ISessionControllerCallback> mControllerCallbacks =
             new ArrayList<ISessionControllerCallback>();
@@ -260,13 +259,13 @@
                 boolean isMasterMute = mAudioManager.isMasterMute();
                 if (isMute) {
                     mAudioManagerInternal.setMasterMuteForUid(!isMasterMute,
-                            flags, packageName, mICallback, uid);
+                            flags, packageName, mService.mICallback, uid);
                 } else {
                     mAudioManagerInternal.adjustMasterVolumeForUid(direction, flags, packageName,
                             uid);
                     if (isMasterMute) {
                         mAudioManagerInternal.setMasterMuteForUid(false,
-                                flags, packageName, mICallback, uid);
+                                flags, packageName, mService.mICallback, uid);
                     }
                 }
                 return;
@@ -280,7 +279,7 @@
                     } else {
                         mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream, direction,
                                 flags, packageName, uid);
-                        if (isStreamMute) {
+                        if (isStreamMute && direction != 0) {
                             mAudioManager.setStreamMute(stream, false);
                         }
                     }
@@ -295,7 +294,7 @@
                         mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(
                                 AudioManager.USE_DEFAULT_STREAM_TYPE, direction, flags, packageName,
                                 uid);
-                        if (isStreamMute) {
+                        if (isStreamMute && direction != 0) {
                             mAudioManager.setStreamMute(AudioManager.USE_DEFAULT_STREAM_TYPE,
                                     false);
                         }
@@ -307,7 +306,7 @@
                 } else {
                     mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
                             packageName, uid);
-                    if (isStreamMute) {
+                    if (isStreamMute && direction != 0) {
                         mAudioManager.setStreamMute(stream, false);
                     }
                 }
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 105ec77..22acfea 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -77,6 +77,8 @@
 
     private static final int WAKELOCK_TIMEOUT = 5000;
 
+    /* package */final IBinder mICallback = new Binder();
+
     private final SessionManagerImpl mSessionManagerImpl;
     private final MediaSessionStack mPriorityStack;
 
@@ -91,6 +93,7 @@
 
     private KeyguardManager mKeyguardManager;
     private IAudioService mAudioService;
+    private AudioManager mAudioManager;
     private ContentResolver mContentResolver;
     private SettingsObserver mSettingsObserver;
 
@@ -118,6 +121,7 @@
         mKeyguardManager =
                 (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
         mAudioService = getAudioService();
+        mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
         mContentResolver = getContext().getContentResolver();
         mSettingsObserver = new SettingsObserver();
         mSettingsObserver.observe();
@@ -589,8 +593,6 @@
                 "android.media.AudioService.WAKELOCK_ACQUIRED";
         private static final int WAKELOCK_RELEASE_ON_FINISHED = 1980; // magic number
 
-        private final IBinder mICallback = new Binder();
-
         private boolean mVoiceButtonDown = false;
         private boolean mVoiceButtonHandled = false;
 
@@ -845,14 +847,14 @@
                     } else {
                         boolean isStreamMute = mAudioService.isStreamMute(suggestedStream);
                         if (direction == MediaSessionManager.DIRECTION_MUTE) {
-                            mAudioService.setStreamMute(suggestedStream, !isStreamMute, mICallback);
+                            mAudioManager.setStreamMute(suggestedStream, !isStreamMute);
                         } else {
                             mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream,
                                     flags, packageName);
                             // Do not call setStreamMute when direction = 0 which is used just to
                             // show the UI.
                             if (isStreamMute && direction != 0) {
-                                mAudioService.setStreamMute(suggestedStream, false, mICallback);
+                                mAudioManager.setStreamMute(suggestedStream, false);
                             }
                         }
                     }