Add the rest of the background audio screen API am: 8951278d3f am: efeefd04bf am: dd93624b7f
am: bae797673b

Change-Id: Ie4225b3bbab002046ddc1ca183a70f1c081bd555
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 3d89dcd..33c7db9 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -2013,6 +2013,37 @@
     }
 
     /**
+     * Instructs Telecom to bring a call into the AUDIO_PROCESSING state.
+     *
+     * Used by the background audio call screener (also the default dialer) to signal that
+     * they want to manually enter the AUDIO_PROCESSING state. The user will be aware that there is
+     * an ongoing call at this time.
+     *
+     * @param call The call to manipulate
+     */
+    public void enterBackgroundAudioProcessing(Call call) {
+        if (!mCalls.contains(call)) {
+            Log.w(this, "Trying to exit audio processing on an untracked call");
+            return;
+        }
+
+        Call activeCall = getActiveCall();
+        if (activeCall != call) {
+            Log.w(this, "Ignoring enter audio processing because there's already a call active");
+        }
+
+        // We only want this to work on active or ringing calls
+        if (call.getState() == CallState.RINGING) {
+            // After the connection service sets up the call with the other end, it'll set the call
+            // state to AUDIO_PROCESSING
+            answerCallForAudioProcessing(call);
+        } else if (call.getState() == CallState.ACTIVE) {
+            setCallState(call, CallState.AUDIO_PROCESSING,
+                    "audio processing set by dialer request");
+        }
+    }
+
+    /**
      * Instructs Telecom to bring a call out of the AUDIO_PROCESSING state.
      *
      * Used by the background audio call screener (also the default dialer) to signal that it's
diff --git a/src/com/android/server/telecom/InCallAdapter.java b/src/com/android/server/telecom/InCallAdapter.java
index 81314ea..039b446 100644
--- a/src/com/android/server/telecom/InCallAdapter.java
+++ b/src/com/android/server/telecom/InCallAdapter.java
@@ -321,7 +321,22 @@
 
     @Override
     public void enterBackgroundAudioProcessing(String callId) {
-        // TODO: implement this
+        try {
+            Log.startSession(LogUtils.Sessions.ICA_ENTER_AUDIO_PROCESSING, mOwnerComponentName);
+            // TODO: enforce the extra permission.
+            Binder.withCleanCallingIdentity(() -> {
+                synchronized (mLock) {
+                    Call call = mCallIdMapper.getCall(callId);
+                    if (call != null) {
+                        mCallsManager.enterBackgroundAudioProcessing(call);
+                    } else {
+                        Log.w(this, "enterBackgroundAudioProcessing, unknown call id: %s", callId);
+                    }
+                }
+            });
+        } finally {
+            Log.endSession();
+        }
     }
 
     @Override