Add the rest of the background audio screen API

Allow in-call apps to enter background call screening via an api from
android.telecom.Call instead of from the call screening service.

Test: CTS
Bug: 140317205
Change-Id: I6d12ead022236799aaccb8dae1267c2a5d24c156
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index ce9f877..66132d9 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -2020,6 +2020,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