Revert "Migrate system dialer config to RoleManager"

This reverts commit 391207681a4fd9d8033e64d88f4c38c61c871b95.

Reason for revert: b/123970954

Change-Id: Idc2cfb4cc3d86ec5cf7cbc766b4e9df21050d6d5
(cherry picked from commit 00caa74eab4f2de0e96bd9dcbe9698086561c72b)
diff --git a/res/values/config.xml b/res/values/config.xml
index 540bece..c0e9669 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -27,6 +27,9 @@
          handle playing of the tones. -->
     <bool name="allow_local_dtmf_tones">true</bool>
 
+    <!-- Package name for the default in-call UI and dialer [DO NOT TRANSLATE] -->
+    <string name="ui_default_package" translatable="false">com.android.dialer</string>
+
     <!-- Class name for the default in-call UI Service [DO NOT TRANSLATE] -->
     <string name="incall_default_class" translatable="false">com.android.incallui.InCallServiceImpl</string>
 
diff --git a/src/com/android/server/telecom/DefaultDialerCache.java b/src/com/android/server/telecom/DefaultDialerCache.java
index 749cb40..3b36119 100644
--- a/src/com/android/server/telecom/DefaultDialerCache.java
+++ b/src/com/android/server/telecom/DefaultDialerCache.java
@@ -141,7 +141,7 @@
         mContext = context;
         mDefaultDialerManagerAdapter = defaultDialerManagerAdapter;
         mLock = lock;
-        mSystemDialerName = TelecomServiceImpl.getSystemDialerPackage(mContext);
+        mSystemDialerName = mContext.getResources().getString(R.string.ui_default_package);
 
         IntentFilter packageIntentFilter = new IntentFilter();
         packageIntentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index ac894e9..f221f91 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -750,7 +750,7 @@
 
         Resources resources = mContext.getResources();
         mSystemInCallComponentName = new ComponentName(
-                TelecomServiceImpl.getSystemDialerPackage(mContext),
+                resources.getString(R.string.ui_default_package),
                 resources.getString(R.string.incall_default_class));
 
         mSystemStateHelper.addListener(mSystemStateListener);
diff --git a/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java b/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
index 0cfdc4c..440bb10 100644
--- a/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
+++ b/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
@@ -464,7 +464,7 @@
         Intent systemDialerIntent = new Intent();
         final Resources resources = mContext.getResources();
         systemDialerIntent.setClassName(
-                TelecomServiceImpl.getSystemDialerPackage(mContext),
+                resources.getString(R.string.ui_default_package),
                 resources.getString(R.string.dialer_default_class));
         systemDialerIntent.setAction(Intent.ACTION_DIAL);
         systemDialerIntent.setData(handle);
diff --git a/src/com/android/server/telecom/RoleManagerAdapter.java b/src/com/android/server/telecom/RoleManagerAdapter.java
index 647d7bf..b7e347e 100644
--- a/src/com/android/server/telecom/RoleManagerAdapter.java
+++ b/src/com/android/server/telecom/RoleManagerAdapter.java
@@ -16,7 +16,6 @@
 
 package com.android.server.telecom;
 
-import android.content.Intent;
 import android.os.UserHandle;
 
 import java.util.List;
@@ -26,14 +25,6 @@
  * and remove direct dependencies.
  */
 public interface RoleManagerAdapter {
-
-    /**
-     * The name of the dialer role.
-     *
-     * @see Intent#ACTION_DIAL
-     */
-    String ROLE_DIALER = "android.app.role.DIALER";
-
     /**
      * Returns the package name of the app which fills the {@link android.app.role.RoleManager} call
      * redirection role.
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 189ce29..f702612 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -28,13 +28,14 @@
 import android.Manifest;
 import android.app.ActivityManager;
 import android.app.AppOpsManager;
-import android.app.role.RoleManager;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
 import android.content.res.Resources;
 import android.net.Uri;
 import android.os.Binder;
@@ -43,6 +44,7 @@
 import android.os.Process;
 import android.os.UserHandle;
 import android.provider.Settings;
+import android.telecom.CallScreeningService;
 import android.telecom.Log;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
@@ -55,9 +57,7 @@
 import android.util.EventLog;
 
 import com.android.internal.telecom.ITelecomService;
-import com.android.internal.util.ArrayUtils;
 import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.Preconditions;
 import com.android.server.telecom.components.UserCallIntentProcessorFactory;
 import com.android.server.telecom.settings.BlockedNumbersActivity;
 
@@ -676,7 +676,7 @@
                 // No need to synchronize
                 Resources resources = mContext.getResources();
                 return new ComponentName(
-                        TelecomServiceImpl.getSystemDialerPackage(mContext),
+                        resources.getString(R.string.ui_default_package),
                         resources.getString(R.string.dialer_default_class));
             } finally {
                 Log.endSession();
@@ -712,7 +712,7 @@
         public String getSystemDialerPackage() {
             try {
                 Log.startSession("TSI.gSDP");
-                return TelecomServiceImpl.getSystemDialerPackage(mContext);
+                return mContext.getResources().getString(R.string.ui_default_package);
             } finally {
                 Log.endSession();
             }
@@ -1747,15 +1747,6 @@
         mNuisanceCallReporter = nuisanceCallReporter;
     }
 
-    public static String getSystemDialerPackage(Context context) {
-        String[] holders = context.getResources().getStringArray(
-                com.android.internal.R.array.config_defaultRoleHolders);
-        return TextUtils.withoutPrefix(RoleManagerAdapter.ROLE_DIALER + ": ",
-                Preconditions.checkNotNull(
-                        ArrayUtils.find(holders, s -> s.startsWith(RoleManagerAdapter.ROLE_DIALER)),
-                        "No system dialer configured"));
-    }
-
     public ITelecomService.Stub getBinder() {
         return mBinderImpl;
     }
diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java
index 3714279..0e3234e 100644
--- a/src/com/android/server/telecom/TelecomSystem.java
+++ b/src/com/android/server/telecom/TelecomSystem.java
@@ -256,7 +256,7 @@
                         mContactsAsyncHelper, mLock);
 
         EmergencyCallHelper emergencyCallHelper = new EmergencyCallHelper(mContext,
-                TelecomServiceImpl.getSystemDialerPackage(mContext), timeoutsAdapter);
+                mContext.getResources().getString(R.string.ui_default_package), timeoutsAdapter);
 
         InCallControllerFactory inCallControllerFactory = new InCallControllerFactory() {
             @Override
diff --git a/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java b/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
index 964436f..553c263 100644
--- a/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
+++ b/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
@@ -546,10 +546,6 @@
         when(mResources.getBoolean(eq(id))).thenReturn(value);
     }
 
-    public void putStringArrayResource(int id, String[] value) {
-        when(mResources.getStringArray(eq(id))).thenReturn(value);
-    }
-
     public void setTelecomManager(TelecomManager telecomManager) {
         mTelecomManager = telecomManager;
     }
diff --git a/tests/src/com/android/server/telecom/tests/InCallControllerTests.java b/tests/src/com/android/server/telecom/tests/InCallControllerTests.java
index 79f4fc4..04b7d96 100644
--- a/tests/src/com/android/server/telecom/tests/InCallControllerTests.java
+++ b/tests/src/com/android/server/telecom/tests/InCallControllerTests.java
@@ -16,22 +16,6 @@
 
 package com.android.server.telecom.tests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.ArgumentMatchers.matches;
-import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 import android.Manifest;
 import android.content.ComponentName;
 import android.content.ContentResolver;
@@ -43,8 +27,8 @@
 import android.content.pm.ServiceInfo;
 import android.content.res.Resources;
 import android.os.Bundle;
-import android.os.Handler;
 import android.os.IBinder;
+import android.os.Handler;
 import android.os.Looper;
 import android.os.UserHandle;
 import android.telecom.InCallService;
@@ -87,6 +71,23 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.matches;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
 @RunWith(JUnit4.class)
 public class InCallControllerTests extends TelecomTestCase {
     @Mock CallsManager mMockCallsManager;
@@ -125,9 +126,7 @@
         MockitoAnnotations.initMocks(this);
         when(mMockCall.getAnalytics()).thenReturn(new Analytics.CallInfo());
         doReturn(mMockResources).when(mMockContext).getResources();
-        doReturn(new String[] { RoleManagerAdapter.ROLE_DIALER + ": " + SYS_PKG })
-                .when(mMockResources)
-                .getString(com.android.internal.R.array.config_defaultRoleHolders);
+        doReturn(SYS_PKG).when(mMockResources).getString(R.string.ui_default_package);
         doReturn(SYS_CLASS).when(mMockResources).getString(R.string.incall_default_class);
         doReturn(true).when(mMockResources).getBoolean(R.bool.grant_location_permission_enabled);
         mEmergencyCallHelper = new EmergencyCallHelper(mMockContext, SYS_PKG,
diff --git a/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java b/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
index 760e4db..9d363e9 100644
--- a/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
+++ b/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
@@ -16,23 +16,6 @@
 
 package com.android.server.telecom.tests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNotNull;
-import static org.mockito.Matchers.isNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 import android.Manifest;
 import android.app.Activity;
 import android.app.AppOpsManager;
@@ -54,10 +37,10 @@
 import com.android.server.telecom.Call;
 import com.android.server.telecom.CallsManager;
 import com.android.server.telecom.NewOutgoingCallIntentBroadcaster;
+import com.android.server.telecom.RoleManagerAdapter;
 import com.android.server.telecom.PhoneAccountRegistrar;
 import com.android.server.telecom.PhoneNumberUtilsAdapter;
 import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
-import com.android.server.telecom.RoleManagerAdapter;
 import com.android.server.telecom.SystemStateHelper;
 import com.android.server.telecom.TelecomSystem;
 
@@ -68,6 +51,23 @@
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNotNull;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 @RunWith(JUnit4.class)
 public class NewOutgoingCallIntentBroadcasterTest extends TelecomTestCase {
     private static class ReceiverIntentPair {
@@ -196,9 +196,7 @@
 
         String ui_package_string = "sample_string_1";
         String dialer_default_class_string = "sample_string_2";
-        mComponentContextFixture.putStringArrayResource(
-                com.android.internal.R.array.config_defaultRoleHolders,
-                new String[] {RoleManagerAdapter.ROLE_DIALER + ": " + ui_package_string});
+        mComponentContextFixture.putResource(R.string.ui_default_package, ui_package_string);
         mComponentContextFixture.putResource(R.string.dialer_default_class,
                 dialer_default_class_string);
 
diff --git a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
index 1da2e49..1197396 100644
--- a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
+++ b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
@@ -516,10 +516,9 @@
     }
 
     private void setupInCallServices() throws Exception {
-        mComponentContextFixture.putStringArrayResource(
-                com.android.internal.R.array.config_defaultRoleHolders,
-                new String[] { RoleManagerAdapter.ROLE_DIALER + ": "
-                        + mInCallServiceComponentNameX.getPackageName() });
+        mComponentContextFixture.putResource(
+                com.android.server.telecom.R.string.ui_default_package,
+                mInCallServiceComponentNameX.getPackageName());
         mComponentContextFixture.putResource(
                 com.android.server.telecom.R.string.incall_default_class,
                 mInCallServiceComponentNameX.getClassName());