Add CallManager/Phone.setEchoSuppressionEnabled().

Change-Id: I7bc6241e6fa815787799a53d6f3a076567edc361
diff --git a/telephony/java/com/android/internal/telephony/CallManager.java b/telephony/java/com/android/internal/telephony/CallManager.java
index 7c3508f..09b7d05 100644
--- a/telephony/java/com/android/internal/telephony/CallManager.java
+++ b/telephony/java/com/android/internal/telephony/CallManager.java
@@ -861,6 +861,25 @@
     }
 
     /**
+     * Enables or disables echo suppression.
+     */
+    public void setEchoSuppressionEnabled(boolean enabled) {
+        if (VDBG) {
+            Log.d(LOG_TAG, " setEchoSuppression(" + enabled + ")");
+            Log.d(LOG_TAG, this.toString());
+        }
+
+        if (hasActiveFgCall()) {
+            getActiveFgCall().getPhone().setEchoSuppressionEnabled(enabled);
+        }
+
+        if (VDBG) {
+            Log.d(LOG_TAG, "End setEchoSuppression(" + enabled + ")");
+            Log.d(LOG_TAG, this.toString());
+        }
+    }
+
+    /**
      * Play a DTMF tone on the active call.
      *
      * @param c should be one of 0-9, '*' or '#'. Other values will be
diff --git a/telephony/java/com/android/internal/telephony/Phone.java b/telephony/java/com/android/internal/telephony/Phone.java
index 9afade3..d5791eb 100644
--- a/telephony/java/com/android/internal/telephony/Phone.java
+++ b/telephony/java/com/android/internal/telephony/Phone.java
@@ -1169,6 +1169,11 @@
     boolean getMute();
 
     /**
+     * Enables or disables echo suppression.
+     */
+    void setEchoSuppressionEnabled(boolean enabled);
+
+    /**
      * Invokes RIL_REQUEST_OEM_HOOK_RAW on RIL implementation.
      *
      * @param data The data for the request.
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index ff28773..53503a5 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -505,6 +505,10 @@
         mCM.unregisterForResendIncallMute(h);
     }
 
+    public void setEchoSuppressionEnabled(boolean enabled) {
+        // no need for regular phone
+    }
+
     /**
      * Subclasses of Phone probably want to replace this with a
      * version scoped to their packages
diff --git a/telephony/java/com/android/internal/telephony/PhoneProxy.java b/telephony/java/com/android/internal/telephony/PhoneProxy.java
index e1511e6..6f08868 100644
--- a/telephony/java/com/android/internal/telephony/PhoneProxy.java
+++ b/telephony/java/com/android/internal/telephony/PhoneProxy.java
@@ -568,6 +568,10 @@
         return mActivePhone.getMute();
     }
 
+    public void setEchoSuppressionEnabled(boolean enabled) {
+        mActivePhone.setEchoSuppressionEnabled(enabled);
+    }
+
     public void invokeOemRilRequestRaw(byte[] data, Message response) {
         mActivePhone.invokeOemRilRequestRaw(data, response);
     }
diff --git a/telephony/java/com/android/internal/telephony/sip/SipPhone.java b/telephony/java/com/android/internal/telephony/sip/SipPhone.java
index af3e0886..e3c3d65 100755
--- a/telephony/java/com/android/internal/telephony/sip/SipPhone.java
+++ b/telephony/java/com/android/internal/telephony/sip/SipPhone.java
@@ -327,6 +327,20 @@
         Log.e(LOG_TAG, "call waiting not supported");
     }
 
+    @Override
+    public void setEchoSuppressionEnabled(boolean enabled) {
+        synchronized (SipPhone.class) {
+            AudioGroup audioGroup = foregroundCall.getAudioGroup();
+            if (audioGroup == null) return;
+            int mode = audioGroup.getMode();
+            audioGroup.setMode(enabled
+                    ? AudioGroup.MODE_ECHO_SUPPRESSION
+                    : AudioGroup.MODE_NORMAL);
+            Log.d(LOG_TAG, String.format("audioGroup mode change: %d --> %d",
+                    mode, audioGroup.getMode()));
+        }
+    }
+
     public void setMute(boolean muted) {
         synchronized (SipPhone.class) {
             foregroundCall.setMute(muted);