Fix SelfManagedConnectionTest failures.

The CONTROL_INCALL_EXPERIENCE didn't granted expectedly so in some test
we didn't bind to necessary InCallServices. While test is flaky due to
other cts InCallService may got bound in the test. Add bind check for
the test InCallService.

Bug: 199343544
Test: CtsTelecomTestCases
Change-Id: I475eee08e1ea799fb4e4d4b8716d4d13152c16e4
diff --git a/tests/tests/telecom/ThirdPtyDialerTestApp/AndroidManifest.xml b/tests/tests/telecom/ThirdPtyDialerTestApp/AndroidManifest.xml
index 18a7bb3..e6de45e 100644
--- a/tests/tests/telecom/ThirdPtyDialerTestApp/AndroidManifest.xml
+++ b/tests/tests/telecom/ThirdPtyDialerTestApp/AndroidManifest.xml
@@ -29,7 +29,7 @@
     <uses-permission android:name="com.android.voicemail.permission.WRITE_VOICEMAIL"/>
 
     <application android:label="ThirdPtyDialerTestApp">
-        <service android:name=".android.telecom.cts.thirdptydialer.CtsThirdPtyDialerInCallService"
+        <service android:name=".CtsThirdPtyDialerInCallService"
                  android:permission="android.permission.BIND_INCALL_SERVICE"
                  android:launchMode="singleInstance"
                  android:exported="true">
diff --git a/tests/tests/telecom/ThirdPtyDialerTestAppTwo/AndroidManifest.xml b/tests/tests/telecom/ThirdPtyDialerTestAppTwo/AndroidManifest.xml
index b4e0511..173418b 100644
--- a/tests/tests/telecom/ThirdPtyDialerTestAppTwo/AndroidManifest.xml
+++ b/tests/tests/telecom/ThirdPtyDialerTestAppTwo/AndroidManifest.xml
@@ -29,7 +29,7 @@
     <uses-permission android:name="android.permission.CALL_COMPANION_APP"/>
 
     <application android:label="ThirdPtyDialerTestAppTwo">
-        <service android:name=".android.telecom.cts.thirdptydialertwo.CtsThirdPtyDialerInCallServiceTwo"
+        <service android:name=".CtsThirdPtyDialerInCallServiceTwo"
                  android:permission="android.permission.BIND_INCALL_SERVICE"
                  android:launchMode="singleInstance"
                  android:exported="true">
diff --git a/tests/tests/telecom/ThirdPtyInCallServiceTestApp/AndroidManifest.xml b/tests/tests/telecom/ThirdPtyInCallServiceTestApp/AndroidManifest.xml
index 146cd7c..b3cdd6c 100644
--- a/tests/tests/telecom/ThirdPtyInCallServiceTestApp/AndroidManifest.xml
+++ b/tests/tests/telecom/ThirdPtyInCallServiceTestApp/AndroidManifest.xml
@@ -15,9 +15,10 @@
 -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-     package="android.telecom.cts.thirdptyincallservice"
-     android:versionCode="1"
-     android:versionName="1.0">
+          package="android.telecom.cts.thirdptyincallservice"
+          android:versionCode="1"
+          android:versionName="1.0"
+          android:sharedUserId="android.telecom.cts">
 
     <!-- sdk 15 is the max for read call log -->
     <uses-sdk android:minSdkVersion="15"/>
diff --git a/tests/tests/telecom/src/android/telecom/cts/SelfManagedConnectionTest.java b/tests/tests/telecom/src/android/telecom/cts/SelfManagedConnectionTest.java
index a889434..92e0a21 100644
--- a/tests/tests/telecom/src/android/telecom/cts/SelfManagedConnectionTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/SelfManagedConnectionTest.java
@@ -198,10 +198,13 @@
                 .asInterface(controlConn.getService());
         control.resetLatchForServiceBound(true /* bind */);
 
+        mUiAutomation.adoptShellPermissionIdentity("android.permission.CONTROL_INCALL_EXPERIENCE");
         SelfManagedConnection connection = placeAndVerifySelfManagedCall();
         control.checkBindStatus(true /* bindStatus */);
+        assertTrue(control.checkBindStatus(true /* bindStatus */));
         connection.waitOnInCallServiceTrackingChanged();
         assertTrue(connection.isTracked());
+        mUiAutomation.dropShellPermissionIdentity();
 
         connection.disconnectAndDestroy();
         assertIsInCall(false);
@@ -220,14 +223,15 @@
                 DEFAULT_DIALER_INCALLSERVICE_2);
         ICtsThirdPartyInCallServiceControl control = ICtsThirdPartyInCallServiceControl.Stub
                 .asInterface(controlConn.getService());
-        assertTrue(setDefaultDialer(DEFAULT_DIALER_PKG_2));
+        TestUtils.setDefaultDialer(getInstrumentation(), DEFAULT_DIALER_PKG_2);
         control.resetLatchForServiceBound(true /* bind */);
 
         SelfManagedConnection connection = placeAndVerifySelfManagedCall();
-        control.checkBindStatus(true /* bindStatus */);
+        assertTrue(control.checkBindStatus(true /* bindStatus */));
 
         connection.waitOnInCallServiceTrackingChanged();
         assertTrue(connection.isAlternativeUiShowing());
+        mUiAutomation.dropShellPermissionIdentity();
 
         connection.disconnectAndDestroy();
         assertIsInCall(false);