Merge "Automatically unmute call if user decides not to add call" into klp-dev
diff --git a/InCallUI/src/com/android/incallui/AudioModeProvider.java b/InCallUI/src/com/android/incallui/AudioModeProvider.java
index 36ec20f..8224d3e 100644
--- a/InCallUI/src/com/android/incallui/AudioModeProvider.java
+++ b/InCallUI/src/com/android/incallui/AudioModeProvider.java
@@ -84,6 +84,10 @@
         return mAudioMode;
     }
 
+    public boolean getMute() {
+        return mMuted;
+    }
+
     /* package */ interface AudioModeListener {
         void onAudioMode(int newMode);
         void onMute(boolean muted);
diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
index 6e64e65..bc9efe5 100644
--- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
@@ -32,6 +32,8 @@
     private Call mCall;
     private AudioModeProvider mAudioModeProvider;
     private ProximitySensor mProximitySensor;
+    private boolean mAutomaticallyMuted = false;
+    private boolean mPreviousMuteState = false;
 
     public CallButtonPresenter() {
     }
@@ -166,6 +168,11 @@
     }
 
     public void addCallClicked() {
+        // Automatically mute the current call
+        mAutomaticallyMuted = true;
+        mPreviousMuteState = mAudioModeProvider.getMute();
+        getUi().setMute(true);
+
         CallCommandClient.getInstance().addCall();
     }
 
@@ -204,6 +211,12 @@
             ui.showMerge(call.can(Capabilities.MERGE_CALLS));
             ui.showSwap(call.can(Capabilities.SWAP_CALLS));
             ui.showAddCall(call.can(Capabilities.ADD_CALL));
+
+            // Restore the previous mute state
+            if (mAutomaticallyMuted && mAudioModeProvider.getMute() != mPreviousMuteState) {
+                ui.setMute(mPreviousMuteState);
+                mAutomaticallyMuted = false;
+            }
         }
     }