Do not test permissions based on Dialer role if unavailable

If the Dialer role is unavailable, it can not be set during testing.
Skip tests where this is the case so that they do not fail.

Bug: 190345365
Test: atest CtsTelecomTestCases:ThirdPartyInCallServiceTest
Change-Id: Ie2500914ce99c94feea70113afa123d05c0c064b
diff --git a/tests/tests/telecom/src/android/telecom/cts/CtsRoleManagerAdapter.java b/tests/tests/telecom/src/android/telecom/cts/CtsRoleManagerAdapter.java
index 2a05547..0b77a96 100644
--- a/tests/tests/telecom/src/android/telecom/cts/CtsRoleManagerAdapter.java
+++ b/tests/tests/telecom/src/android/telecom/cts/CtsRoleManagerAdapter.java
@@ -57,6 +57,10 @@
         mRoleHolders = new ConcurrentHashMap<>();
     }
 
+    public boolean isDialerRoleAvailable() {
+        return mRoleManager.isRoleAvailable(RoleManager.ROLE_DIALER);
+    }
+
     public void setDialerRoleHolder(String packageName)
             throws Exception {
         if (mRoleManager != null) {
diff --git a/tests/tests/telecom/src/android/telecom/cts/ThirdPartyInCallServiceTest.java b/tests/tests/telecom/src/android/telecom/cts/ThirdPartyInCallServiceTest.java
index 4166383..2fd4626 100644
--- a/tests/tests/telecom/src/android/telecom/cts/ThirdPartyInCallServiceTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/ThirdPartyInCallServiceTest.java
@@ -47,12 +47,18 @@
     private boolean mSkipNullUnboundLatch;
     private String mPreviousRoleHolder;
     private String mThirdPartyPackageName;
+    private boolean mIsDialerRoleAvailable;
 
     @Override
     public void setUp() throws Exception {
         super.setUp();
         mContext = getInstrumentation().getContext();
         mCtsRoleManagerAdapter = new CtsRoleManagerAdapter(getInstrumentation());
+
+        // Do not continue with tests if the Dialer role is not available.
+        mIsDialerRoleAvailable = mCtsRoleManagerAdapter.isDialerRoleAvailable();
+        if (!mIsDialerRoleAvailable) return;
+
         setUpControl();
         mICtsThirdPartyInCallServiceControl.resetLatchForServiceBound(false);
         mThirdPartyPackageName = CtsThirdPtyDialerInCallServiceControl.class.getPackage().getName();
@@ -63,8 +69,10 @@
 
     @Override
     public void tearDown() throws Exception {
-        mICtsThirdPartyInCallServiceControl.resetCalls();
-        mCtsRoleManagerAdapter.setDialerRoleHolder(mPreviousRoleHolder);
+        if (mIsDialerRoleAvailable) {
+            mICtsThirdPartyInCallServiceControl.resetCalls();
+            mCtsRoleManagerAdapter.setDialerRoleHolder(mPreviousRoleHolder);
+        }
         super.tearDown();
     }
 
@@ -75,6 +83,8 @@
      * @throws Exception
      */
     public void testPermissionGranted() throws Exception {
+        if (!mIsDialerRoleAvailable) return;
+
         assertFalse(mICtsThirdPartyInCallServiceControl.checkPermissionGrant(
                 Manifest.permission.READ_VOICEMAIL));
         assertFalse(mICtsThirdPartyInCallServiceControl.checkPermissionGrant(