Add API coverage for new ConnectionService APIs.

Flagged under existing mainline cleanup flag.

Test: THIS is a test.
Bug: 317391843
Change-Id: If3e888d1ff3dec658b9b7d55be785f3aa9dca4d4
diff --git a/tests/tests/telecom/src/android/telecom/cts/ConferenceTest.java b/tests/tests/telecom/src/android/telecom/cts/ConferenceTest.java
index 557a8b4..1f7a309 100644
--- a/tests/tests/telecom/src/android/telecom/cts/ConferenceTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/ConferenceTest.java
@@ -36,6 +36,8 @@
 
 import androidx.test.InstrumentationRegistry;
 
+import com.android.server.telecom.flags.Flags;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -96,6 +98,13 @@
         if (!mShouldTestTelecom) {
             return;
         }
+        // Part of adding the conference is calling TelecomManager#addConference, so we should have
+        // gotten confirmation of that.
+        if (Flags.telecomResolveHiddenDependencies()) {
+            assertTrue(connectionService.waitForEvent(
+                    MockConnectionService.EVENT_CONNECTION_SERVICE_CREATE_CONFERENCE_COMPLETE));
+        }
+
         final Call conf = mInCallService.getLastConferenceCall();
         assertCallState(conf, Call.STATE_ACTIVE);
 
diff --git a/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java b/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
index 79b0ee2..0b7a20d 100644
--- a/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
@@ -160,6 +160,28 @@
     }
 
     @Override
+    public void onCreateConnectionComplete(Connection connection) {
+        ConnectionService testImpl = getTestImpl();
+        if (testImpl != null) {
+            testImpl.onCreateConnectionComplete(connection);
+        } else {
+            Log.e(LOG_TAG, "onCreateConnectionComplete called when "
+                    + "sConnectionService null!");
+        }
+    }
+
+    @Override
+    public void onCreateConferenceComplete(Conference conference) {
+        ConnectionService testImpl = getTestImpl();
+        if (testImpl != null) {
+            testImpl.onCreateConferenceComplete(conference);
+        } else {
+            Log.e(LOG_TAG, "onCreateConferenceComplete called when "
+                    + "sConnectionService null!");
+        }
+    }
+
+    @Override
     public void onCreateIncomingConferenceFailed(PhoneAccountHandle connectionManagerPhoneAccount,
             ConnectionRequest request) {
         ConnectionService testImpl = getTestImpl();
diff --git a/tests/tests/telecom/src/android/telecom/cts/IncomingCallTest.java b/tests/tests/telecom/src/android/telecom/cts/IncomingCallTest.java
index b26cf8b..617e554 100644
--- a/tests/tests/telecom/src/android/telecom/cts/IncomingCallTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/IncomingCallTest.java
@@ -39,6 +39,8 @@
 import android.telecom.VideoProfile;
 import android.telephony.TelephonyCallback;
 
+import com.android.server.telecom.flags.Flags;
+
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -108,6 +110,11 @@
         setupConnectionService(null, FLAG_REGISTER | FLAG_ENABLE);
         Uri testNumber = createTestNumber();
         addAndVerifyNewIncomingCall(testNumber, null);
+        // Confirm that we got ConnectionService#onCreateConnectionComplete
+        if (Flags.telecomResolveHiddenDependencies()) {
+            assertTrue(connectionService.waitForEvent(
+                    MockConnectionService.EVENT_CONNECTION_SERVICE_CREATE_CONNECTION_COMPLETE));
+        }
         final Connection connection3 = verifyConnectionForIncomingCall();
         Collection<Connection> connections = CtsConnectionService.getAllConnectionsFromTelecom();
         assertEquals(1, connections.size());
diff --git a/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java b/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java
index aa685fd..8e6e7d4 100644
--- a/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java
@@ -29,7 +29,6 @@
 import android.telecom.RemoteConference;
 import android.telecom.RemoteConnection;
 import android.telecom.TelecomManager;
-import android.util.Log;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -53,8 +52,10 @@
     public static final int EVENT_CONNECTION_SERVICE_FOCUS_LOST = 1;
     public static final int EVENT_CONNECTION_SERVICE_CREATE_CONNECTION = 2;
     public static final int EVENT_CONNECTION_SERVICE_CREATE_CONNECTION_FAILED = 3;
+    public static final int EVENT_CONNECTION_SERVICE_CREATE_CONNECTION_COMPLETE = 4;
+    public static final int EVENT_CONNECTION_SERVICE_CREATE_CONFERENCE_COMPLETE = 5;
     // Update TOTAL_EVENT below with last event.
-    private static final int TOTAL_EVENT = EVENT_CONNECTION_SERVICE_CREATE_CONNECTION_FAILED + 1;
+    private static final int TOTAL_EVENT = EVENT_CONNECTION_SERVICE_CREATE_CONFERENCE_COMPLETE + 1;
 
     private static final int DEFAULT_EVENT_TIMEOUT_MS = 2000;
 
@@ -233,6 +234,16 @@
     }
 
     @Override
+    public void onCreateConnectionComplete(Connection connection) {
+        mEventLock[EVENT_CONNECTION_SERVICE_CREATE_CONNECTION_COMPLETE].release();
+    }
+
+    @Override
+    public void onCreateConferenceComplete(Conference conference) {
+        mEventLock[EVENT_CONNECTION_SERVICE_CREATE_CONFERENCE_COMPLETE].release();
+    }
+
+    @Override
     public void onRemoteExistingConnectionAdded(RemoteConnection connection) {
         // Keep track of the remote connections added to the service
         remoteConnections.add(connection);
diff --git a/tests/tests/telecom/src/android/telecom/cts/OutgoingCallTest.java b/tests/tests/telecom/src/android/telecom/cts/OutgoingCallTest.java
index e479461..e634c32 100644
--- a/tests/tests/telecom/src/android/telecom/cts/OutgoingCallTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/OutgoingCallTest.java
@@ -39,6 +39,7 @@
 import android.telephony.emergency.EmergencyNumber;
 
 import com.android.compatibility.common.util.SystemUtil;
+import com.android.server.telecom.flags.Flags;
 
 import java.util.List;
 import java.util.Map;
@@ -187,6 +188,11 @@
         AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
 
         placeAndVerifyCall();
+        // Confirm that we got ConnectionService#onCreateConnectionComplete
+        if (Flags.telecomResolveHiddenDependencies()) {
+            assertTrue(connectionService.waitForEvent(
+                    MockConnectionService.EVENT_CONNECTION_SERVICE_CREATE_CONNECTION_COMPLETE));
+        }
         verifyConnectionForOutgoingCall();
         if (mInCallCallbacks.getService().getCallAudioState().getSupportedRouteMask() ==
                 CallAudioState.ROUTE_SPEAKER) {