Fix testResolveInCallIntent.

This text existing in a separate cts test module for some reason;
so I'm moving it to the main Telecom module because having a full module
for a single test is just silly.

I also modified the test itself to better enforce what its trying to;
that is that there is an InCallService on the device which can potentially
show an InCall UI.

Test: Run CtsTelecomTestcts-tradefed run cts-dev -m CtsTelecomTestCases -t android.telecom.cts.BasicInCallServiceTest#testResolveInCallIntent
Fixes: 151112367
Change-Id: I4066b129b79b477340e486210e87b764a95fdbca
diff --git a/tests/tests/telecom/src/android/telecom/cts/BasicInCallServiceTest.java b/tests/tests/telecom/src/android/telecom/cts/BasicInCallServiceTest.java
index ef20d33..75b9372 100644
--- a/tests/tests/telecom/src/android/telecom/cts/BasicInCallServiceTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/BasicInCallServiceTest.java
@@ -18,16 +18,23 @@
 
 import static android.telecom.cts.TestUtils.shouldTestTelecom;
 
-import android.telecom.cts.MockInCallService.InCallServiceCallbacks;
-
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
 import android.net.Uri;
 import android.telecom.Call;
 import android.telecom.InCallService;
+import android.telecom.TelecomManager;
+import android.telecom.cts.MockInCallService.InCallServiceCallbacks;
 import android.test.InstrumentationTestCase;
 import android.text.TextUtils;
 
+import com.android.compatibility.common.util.CddTest;
+
+import org.junit.Test;
+
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -56,6 +63,32 @@
         super.tearDown();
     }
 
+    @CddTest(requirement = "7.4.1.2/C-1-3")
+    public void testResolveInCallIntent() {
+        if (!shouldTestTelecom(mContext)) {
+            return;
+        }
+        PackageManager packageManager = mContext.getPackageManager();
+        Intent serviceIntent = new Intent(InCallService.SERVICE_INTERFACE);
+        List<ResolveInfo> resolveInfo = packageManager.queryIntentServices(serviceIntent,
+                PackageManager.GET_META_DATA);
+
+        assertNotNull(resolveInfo);
+        assertTrue(resolveInfo.size() >= 1);
+
+        // Ensure at least one InCallService is able to handle the UI for calls.
+        assertTrue(resolveInfo
+                .stream()
+                .filter(r -> r.serviceInfo != null
+                        && r.serviceInfo.metaData != null
+                        && r.serviceInfo.metaData.containsKey(
+                                TelecomManager.METADATA_IN_CALL_SERVICE_UI)
+                        && r.serviceInfo.permission.equals(
+                                android.Manifest.permission.BIND_INCALL_SERVICE)
+                        && r.serviceInfo.name != null)
+                .count() >= 1);
+    }
+
     /**
      * Tests that when sending a CALL intent via the Telecom -> Telephony stack, Telecom
      * binds to the registered {@link InCallService}s and adds a new call. This test will
diff --git a/tests/tests/telecom4/Android.mk b/tests/tests/telecom4/Android.mk
deleted file mode 100644
index 2fc8558..0000000
--- a/tests/tests/telecom4/Android.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2015 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-# don't include this package in any target
-LOCAL_MODULE_TAGS := optional
-# and when built explicitly put it in the data partition
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    ctstestrunner-axt \
-    compatibility-device-util-axt
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := CtsTelecom4TestCases
-LOCAL_SDK_VERSION := current
-
-# Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
-
-LOCAL_JAVA_LIBRARIES += android.test.runner.stubs
-LOCAL_JAVA_LIBRARIES += android.test.base.stubs
-
-include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/telecom4/AndroidManifest.xml b/tests/tests/telecom4/AndroidManifest.xml
deleted file mode 100644
index a887fdf..0000000
--- a/tests/tests/telecom4/AndroidManifest.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2019 The Android Open Source Project
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.telecom4.cts">
-
-    <application>
-        <uses-library android:name="android.test.runner" />
-    </application>
-
-    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
-                     android:targetPackage="android.telecom4.cts">
-        <meta-data android:name="listener"
-            android:value="com.android.cts.runner.CtsTestRunListener" />
-    </instrumentation>
-
-</manifest>
-
diff --git a/tests/tests/telecom4/AndroidTest.xml b/tests/tests/telecom4/AndroidTest.xml
deleted file mode 100644
index c88f8a6..0000000
--- a/tests/tests/telecom4/AndroidTest.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2019 The Android Open Source Project
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-<configuration description="Config for CTS Telecom test cases">
-    <option name="test-suite-tag" value="cts" />
-    <option name="config-descriptor:metadata" key="component" value="telecom" />
-    <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
-    <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
-    <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
-    <option name="not-shardable" value="true" />
-    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
-        <option name="cleanup-apks" value="true" />
-        <option name="test-file-name" value="CtsTelecom4TestCases.apk" />
-    </target_preparer>
-    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
-        <option name="package" value="android.telecom4.cts" />
-        <option name="runtime-hint" value="7m30s" />
-    </test>
-</configuration>
diff --git a/tests/tests/telecom4/OWNERS b/tests/tests/telecom4/OWNERS
deleted file mode 100644
index 93fe555..0000000
--- a/tests/tests/telecom4/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-# Bug component: 20868
-
diff --git a/tests/tests/telecom4/src/android/telecom4/cts/InCallServiceImplTest.java b/tests/tests/telecom4/src/android/telecom4/cts/InCallServiceImplTest.java
deleted file mode 100644
index 0e68c64..0000000
--- a/tests/tests/telecom4/src/android/telecom4/cts/InCallServiceImplTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.telecom4.cts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.util.Log;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.compatibility.common.util.CddTest;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Build, install and run the tests by running the commands below:
- * make CtsTelecom4TestCases -j64
- * cts-tradefed run cts -m CtsTelecom4TestCases --test android.telecom4.cts.InCallServiceImplTest
- */
-@RunWith(AndroidJUnit4.class)
-public class InCallServiceImplTest {
-    private static final String TAG = "InCallServiceTest";
-    private static final String IN_CALL_SERVICE_ACTION = "android.telecom.InCallService";
-    private static final String IN_CALL_SERVICE_PERMISSION =
-            "android.permission.BIND_INCALL_SERVICE";
-
-    private Context mContext;
-    private PackageManager mPackageManager;
-
-    @Before
-    public void setup() {
-        mContext = InstrumentationRegistry.getContext();
-        mPackageManager = mContext.getPackageManager();
-    }
-
-    @CddTest(requirement = "7.4.1.2/C-1-3")
-    @Test
-    public void resolveInCallIntent() {
-        if (!hasTelephonyFeature()) {
-            Log.d(TAG, "Bypass the test since telephony is not available.");
-            return;
-        }
-
-        Intent intent = new Intent();
-        intent.setAction(IN_CALL_SERVICE_ACTION);
-        ResolveInfo resolveInfo = mPackageManager.resolveService(intent,
-                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
-
-        assertNotNull(resolveInfo);
-        assertNotNull(resolveInfo.serviceInfo);
-        assertNotNull(resolveInfo.serviceInfo.packageName);
-        assertNotNull(resolveInfo.serviceInfo.name);
-        assertEquals(IN_CALL_SERVICE_PERMISSION, resolveInfo.serviceInfo.permission);
-    }
-
-    private boolean hasTelephonyFeature() {
-        return mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
-    }
-}