Make TelecomManager APIs compatible with Lollipop. (1/3)

+ Add methods to TelecomManagerCompat
- Move TelecomManagerCompat to ContactsCommon because it is called
  within ContactsCommon
- Move TestTelecomCallLogCache to the right package so tests pass

Bug: 25776171

Change-Id: I1963959292d8038ab505488d831afd06e6fef6d0
diff --git a/src/com/android/dialer/SpecialCharSequenceMgr.java b/src/com/android/dialer/SpecialCharSequenceMgr.java
index c212597..4303f3e 100644
--- a/src/com/android/dialer/SpecialCharSequenceMgr.java
+++ b/src/com/android/dialer/SpecialCharSequenceMgr.java
@@ -42,6 +42,7 @@
 
 import com.android.common.io.MoreCloseables;
 import com.android.contacts.common.compat.CompatUtils;
+import com.android.contacts.common.compat.TelephonyManagerCompat;
 import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler;
 import com.android.contacts.common.util.ContactDisplayUtils;
 import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
@@ -252,12 +253,10 @@
                         TelecomUtil.getDefaultOutgoingPhoneAccount(applicationContext,
                                 PhoneAccount.SCHEME_TEL));
 
-                if (!CompatUtils.isMSIMCompatible()) {
-                    handleAdnQuery(handler, sc, Uri.parse("content://icc/adn"));
-                } else if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
+                if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) {
                     Uri uri = TelecomUtil.getAdnUriForPhoneAccount(applicationContext, null);
                     handleAdnQuery(handler, sc, uri);
-                } else if (subscriptionAccountHandles.size() > 1){
+                } else {
                     SelectPhoneAccountListener callback = new HandleAdnEntryAccountSelectedCallback(
                             applicationContext, handler, sc);
 
@@ -265,8 +264,6 @@
                             subscriptionAccountHandles, callback);
                     dialogFragment.show(((Activity) context).getFragmentManager(),
                             TAG_SELECT_ACCT_FRAGMENT);
-                } else {
-                    return false;
                 }
 
                 return true;
@@ -305,12 +302,11 @@
             boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
                     TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL));
 
-            if (!CompatUtils.isMSIMCompatible() || subscriptionAccountHandles.size() == 1
-                    || hasUserSelectedDefault) {
+            if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) {
                 // Don't bring up the dialog for single-SIM or if the default outgoing account is
                 // a subscription account.
                 return TelecomUtil.handleMmi(context, input, null);
-            } else if (subscriptionAccountHandles.size() > 1){
+            } else {
                 SelectPhoneAccountListener listener =
                         new HandleMmiAccountSelectedCallback(context, input);
 
@@ -335,15 +331,17 @@
                     R.string.imei : R.string.meid;
 
             List<String> deviceIds = new ArrayList<String>();
-            if (!CompatUtils.isMSIMCompatible()) {
-                deviceIds.add(telephonyManager.getDeviceId());
-            } else {
+            if (TelephonyManagerCompat.getPhoneCount(telephonyManager) > 1 &&
+                    CompatUtils.isMethodAvailable(TelephonyManagerCompat.TELEPHONY_MANAGER_CLASS,
+                            "getDeviceId", Integer.TYPE)) {
                 for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) {
                     String deviceId = telephonyManager.getDeviceId(slot);
                     if (!TextUtils.isEmpty(deviceId)) {
                         deviceIds.add(deviceId);
                     }
                 }
+            } else {
+                deviceIds.add(telephonyManager.getDeviceId());
             }
 
             AlertDialog alert = new AlertDialog.Builder(context)