Merge "Support carrier presence-based video calling icon." into ub-contactsdialer-b-dev
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)
diff --git a/src/com/android/dialer/calllog/PhoneAccountUtils.java b/src/com/android/dialer/calllog/PhoneAccountUtils.java
index 7dc3292..8c3985b 100644
--- a/src/com/android/dialer/calllog/PhoneAccountUtils.java
+++ b/src/com/android/dialer/calllog/PhoneAccountUtils.java
@@ -18,11 +18,12 @@
 
 import android.content.ComponentName;
 import android.content.Context;
+import android.support.annotation.Nullable;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
-import android.telecom.TelecomManager;
 import android.text.TextUtils;
 
+import com.android.contacts.common.compat.CompatUtils;
 import com.android.dialer.util.TelecomUtil;
 
 import java.util.ArrayList;
@@ -36,14 +37,11 @@
      * Return a list of phone accounts that are subscription/SIM accounts.
      */
     public static List<PhoneAccountHandle> getSubscriptionPhoneAccounts(Context context) {
-        final TelecomManager telecomManager =
-                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
-
         List<PhoneAccountHandle> subscriptionAccountHandles = new ArrayList<PhoneAccountHandle>();
         final List<PhoneAccountHandle> accountHandles =
                 TelecomUtil.getCallCapablePhoneAccounts(context);
         for (PhoneAccountHandle accountHandle : accountHandles) {
-            PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
+            PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle);
             if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
                 subscriptionAccountHandles.add(accountHandle);
             }
@@ -54,7 +52,9 @@
     /**
      * Compose PhoneAccount object from component name and account id.
      */
-    public static PhoneAccountHandle getAccount(String componentString, String accountId) {
+    @Nullable
+    public static PhoneAccountHandle getAccount(@Nullable String componentString,
+            @Nullable String accountId) {
         if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) {
             return null;
         }
@@ -65,7 +65,9 @@
     /**
      * Extract account label from PhoneAccount object.
      */
-    public static String getAccountLabel(Context context, PhoneAccountHandle accountHandle) {
+    @Nullable
+    public static String getAccountLabel(Context context,
+            @Nullable PhoneAccountHandle accountHandle) {
         PhoneAccount account = getAccountOrNull(context, accountHandle);
         if (account != null && account.getLabel() != null) {
             return account.getLabel().toString();
@@ -76,10 +78,8 @@
     /**
      * Extract account color from PhoneAccount object.
      */
-    public static int getAccountColor(Context context, PhoneAccountHandle accountHandle) {
-        TelecomManager telecomManager =
-                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
-        final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
+    public static int getAccountColor(Context context, @Nullable PhoneAccountHandle accountHandle) {
+        final PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle);
 
         // For single-sim devices the PhoneAccount will be NO_HIGHLIGHT_COLOR by default, so it is
         // safe to always use the account highlight color.
@@ -92,10 +92,8 @@
      * @return {@code true} if call subjects are supported, {@code false} otherwise.
      */
     public static boolean getAccountSupportsCallSubject(Context context,
-            PhoneAccountHandle accountHandle) {
-        TelecomManager telecomManager =
-                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
-        final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
+            @Nullable PhoneAccountHandle accountHandle) {
+        final PhoneAccount account = TelecomUtil.getPhoneAccount(context, accountHandle);
 
         return account == null ? false :
                 account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT);
@@ -105,14 +103,12 @@
      * Retrieve the account metadata, but if the account does not exist or the device has only a
      * single registered and enabled account, return null.
      */
-     static PhoneAccount getAccountOrNull(Context context,
-            PhoneAccountHandle accountHandle) {
-        TelecomManager telecomManager =
-                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
-        final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
-        if (telecomManager.getCallCapablePhoneAccounts().size() <= 1) {
+    @Nullable
+    private static PhoneAccount getAccountOrNull(Context context,
+            @Nullable PhoneAccountHandle accountHandle) {
+        if (TelecomUtil.getCallCapablePhoneAccounts(context).size() <= 1) {
             return null;
         }
-        return account;
+        return TelecomUtil.getPhoneAccount(context, accountHandle);
     }
 }
diff --git a/src/com/android/dialer/calllog/calllogcache/CallLogCache.java b/src/com/android/dialer/calllog/calllogcache/CallLogCache.java
index e64c012..dc1217c 100644
--- a/src/com/android/dialer/calllog/calllogcache/CallLogCache.java
+++ b/src/com/android/dialer/calllog/calllogcache/CallLogCache.java
@@ -49,7 +49,7 @@
      * Return the most compatible version of the TelecomCallLogCache.
      */
     public static CallLogCache getCallLogCache(Context context) {
-        if (CompatUtils.isMSIMCompatible()) {
+        if (CompatUtils.isClassAvailable("android.telecom.PhoneAccountHandle")) {
             return new CallLogCacheLollipopMr1(context);
         }
         return new CallLogCacheLollipop(context);
diff --git a/src/com/android/dialer/compat/DialerCompatUtils.java b/src/com/android/dialer/compat/DialerCompatUtils.java
index 1bcdd14..a9c9c53 100644
--- a/src/com/android/dialer/compat/DialerCompatUtils.java
+++ b/src/com/android/dialer/compat/DialerCompatUtils.java
@@ -15,23 +15,10 @@
  */
 package com.android.dialer.compat;
 
-import android.os.Build;
-
-import com.android.contacts.common.compat.SdkVersionOverride;
+import com.android.contacts.common.compat.CompatUtils;
 
 public final class DialerCompatUtils {
     /**
-     * Determines if this version is compatible with a default dialer. Can also force the version to
-     * be lower through SdkVersionOverride.
-     *
-     * @return {@code true} if default dialer is a feature on this device, {@code false} otherwise.
-     */
-    public static boolean isDefaultDialerCompatible() {
-        return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP)
-                >= Build.VERSION_CODES.M;
-    }
-
-    /**
      * Determines if this version has access to the
      * {@link android.provider.CallLog.Calls.CACHED_PHOTO_URI} column
      *
@@ -39,7 +26,6 @@
      * {@code false} otherwise
      */
     public static boolean isCallsCachedPhotoUriCompatible() {
-        return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M)
-                >= Build.VERSION_CODES.M;
+        return CompatUtils.isMarshmallowCompatible();
     }
 }
\ No newline at end of file
diff --git a/src/com/android/dialer/compat/UserManagerCompat.java b/src/com/android/dialer/compat/UserManagerCompat.java
new file mode 100644
index 0000000..a1fdcc6
--- /dev/null
+++ b/src/com/android/dialer/compat/UserManagerCompat.java
@@ -0,0 +1,37 @@
+package com.android.dialer.compat;
+
+import android.content.Context;
+import android.os.Process;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.contacts.common.compat.CompatUtils;
+
+/**
+ * Compatibility class for {@link UserManager}.
+ */
+public class UserManagerCompat {
+    /**
+     * A user id constant to indicate the "system" user of the device. Copied from
+     * {@link UserHandle}.
+     */
+    private static final int USER_SYSTEM = 0;
+    /**
+     * Range of uids allocated for a user.
+     */
+    private static final int PER_USER_RANGE = 100000;
+
+    /**
+     * Used to check if this process is running under the system user. The system user is the
+     * initial user that is implicitly created on first boot and hosts most of the system services.
+     *
+     * @return whether this process is running under the system user.
+     */
+    public static boolean isSystemUser(UserManager userManager) {
+        if (CompatUtils.isMarshmallowCompatible()) {
+            return userManager.isSystemUser();
+        }
+        // Adapted from {@link UserManager} and {@link UserHandle}.
+        return (Process.myUid() / PER_USER_RANGE) == USER_SYSTEM;
+    }
+}
diff --git a/src/com/android/dialer/list/SearchFragment.java b/src/com/android/dialer/list/SearchFragment.java
index d65223a..d1a0be0 100644
--- a/src/com/android/dialer/list/SearchFragment.java
+++ b/src/com/android/dialer/list/SearchFragment.java
@@ -15,8 +15,6 @@
  */
 package com.android.dialer.list;
 
-import static android.Manifest.permission.READ_CONTACTS;
-
 import android.animation.Animator;
 import android.animation.AnimatorInflater;
 import android.animation.AnimatorListenerAdapter;
@@ -359,7 +357,11 @@
 
     @Override
     protected void startLoading() {
-        if (PermissionsUtil.hasPermission(getActivity(), READ_CONTACTS)) {
+        if (getActivity() == null) {
+            return;
+        }
+
+        if (PermissionsUtil.hasContactsPermissions(getActivity())) {
             super.startLoading();
         } else if (TextUtils.isEmpty(getQueryString())) {
             // Clear out any existing call shortcuts.
diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java
index d7b8e11..a187157 100644
--- a/src/com/android/dialer/settings/DialerSettingsActivity.java
+++ b/src/com/android/dialer/settings/DialerSettingsActivity.java
@@ -28,9 +28,12 @@
 import android.view.MenuItem;
 import android.widget.Toast;
 
+import com.android.contacts.common.compat.CompatUtils;
 import com.android.contacts.common.compat.SdkVersionOverride;
+import com.android.contacts.common.compat.TelephonyManagerCompat;
 import com.android.dialer.R;
 import com.android.dialer.compat.SettingsCompat;
+import com.android.dialer.compat.UserManagerCompat;
 import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity;
 
 import java.util.List;
@@ -57,8 +60,7 @@
         soundSettingsHeader.id = R.id.settings_header_sounds_and_vibration;
         target.add(soundSettingsHeader);
 
-        if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M)
-                >= Build.VERSION_CODES.M) {
+        if (CompatUtils.isMarshmallowCompatible()) {
             Header quickResponseSettingsHeader = new Header();
             Intent quickResponseSettingsIntent =
                     new Intent(TelecomManager.ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS);
@@ -67,16 +69,16 @@
             target.add(quickResponseSettingsHeader);
         }
 
-
         TelephonyManager telephonyManager =
                 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 
-        // "Call Settings" (full settings) is shown if the current user is primary user and there 
-        // is only one SIM. Before N, "Calling accounts" setting is shown if the current user is 
+        // "Call Settings" (full settings) is shown if the current user is primary user and there
+        // is only one SIM. Before N, "Calling accounts" setting is shown if the current user is
         // primary user and there are multiple SIMs. In N+, "Calling accounts" is shown whenever
         // "Call Settings" is not shown.
         boolean isPrimaryUser = isPrimaryUser();
-        if (isPrimaryUser && telephonyManager.getPhoneCount() <= 1) {
+        if (isPrimaryUser
+                && TelephonyManagerCompat.getPhoneCount(telephonyManager) <= 1) {
             Header callSettingsHeader = new Header();
             Intent callSettingsIntent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS);
             callSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -100,10 +102,9 @@
             blockedCallsHeader.intent = new Intent(this, BlockedNumbersSettingsActivity.class);
             target.add(blockedCallsHeader);
 
-            if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M)
-                    >= Build.VERSION_CODES.M
-                    && (telephonyManager.isTtyModeSupported()
-                    || telephonyManager.isHearingAidCompatibilitySupported())) {
+            if (TelephonyManagerCompat.isTtyModeSupported(telephonyManager)
+                    || TelephonyManagerCompat
+                    .isHearingAidCompatibilitySupported(telephonyManager)) {
                 Header accessibilitySettingsHeader = new Header();
                 Intent accessibilitySettingsIntent =
                         new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS);
@@ -158,7 +159,6 @@
      * @return Whether the current user is the primary user.
      */
     private boolean isPrimaryUser() {
-        final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
-        return userManager.isSystemUser();
+        return UserManagerCompat.isSystemUser((UserManager) getSystemService(Context.USER_SERVICE));
     }
 }
diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java
index 3d5c257..95d6a81 100644
--- a/src/com/android/dialer/util/DialerUtils.java
+++ b/src/com/android/dialer/util/DialerUtils.java
@@ -87,8 +87,7 @@
                     intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras);
                 }
 
-                final boolean hasCallPermission = TelecomUtil.placeCall(context, intent.getData(),
-                        intent.getExtras());
+                final boolean hasCallPermission = TelecomUtil.placeCall((Activity) context, intent);
                 if (!hasCallPermission) {
                     // TODO: Make calling activity show request permission dialog and handle
                     // callback results appropriately.
diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java
index a617af6..bd201c4 100644
--- a/src/com/android/dialer/util/TelecomUtil.java
+++ b/src/com/android/dialer/util/TelecomUtil.java
@@ -17,12 +17,15 @@
 package com.android.dialer.util;
 
 import android.Manifest;
+import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.net.Uri;
-import android.os.Bundle;
 import android.provider.CallLog.Calls;
+import android.support.annotation.Nullable;
 import android.support.v4.content.ContextCompat;
+import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
 import android.telephony.PhoneNumberUtils;
@@ -31,6 +34,7 @@
 import android.util.Log;
 
 import com.android.contacts.common.compat.CompatUtils;
+import com.android.contacts.common.compat.telecom.TelecomManagerCompat;
 import com.android.dialer.compat.DialerCompatUtils;
 
 import java.util.ArrayList;
@@ -60,7 +64,7 @@
     public static void silenceRinger(Context context) {
         if (hasModifyPhoneStatePermission(context)) {
             try {
-                getTelecomManager(context).silenceRinger();
+                TelecomManagerCompat.silenceRinger(getTelecomManager(context));
             } catch (SecurityException e) {
                 // Just in case
                 Log.w(TAG, "TelecomManager.silenceRinger called without permission.");
@@ -81,7 +85,8 @@
     public static Uri getAdnUriForPhoneAccount(Context context, PhoneAccountHandle handle) {
         if (hasModifyPhoneStatePermission(context)) {
             try {
-                return getTelecomManager(context).getAdnUriForPhoneAccount(handle);
+                return TelecomManagerCompat.getAdnUriForPhoneAccount(
+                        getTelecomManager(context), handle);
             } catch (SecurityException e) {
                 Log.w(TAG, "TelecomManager.getAdnUriForPhoneAccount called without permission.");
             }
@@ -93,11 +98,8 @@
             PhoneAccountHandle handle) {
         if (hasModifyPhoneStatePermission(context)) {
             try {
-                if (handle == null) {
-                    return getTelecomManager(context).handleMmi(dialString);
-                } else {
-                    return getTelecomManager(context).handleMmi(dialString, handle);
-                }
+                return TelecomManagerCompat.handleMmi(
+                        getTelecomManager(context), dialString, handle);
             } catch (SecurityException e) {
                 Log.w(TAG, "TelecomManager.handleMmi called without permission.");
             }
@@ -105,17 +107,23 @@
         return false;
     }
 
+    @Nullable
     public static PhoneAccountHandle getDefaultOutgoingPhoneAccount(Context context,
             String uriScheme) {
         if (hasReadPhoneStatePermission(context)) {
-            return getTelecomManager(context).getDefaultOutgoingPhoneAccount(uriScheme);
+            return TelecomManagerCompat.getDefaultOutgoingPhoneAccount(
+                    getTelecomManager(context), uriScheme);
         }
         return null;
     }
 
+    public static PhoneAccount getPhoneAccount(Context context, PhoneAccountHandle handle) {
+        return TelecomManagerCompat.getPhoneAccount(getTelecomManager(context), handle);
+    }
+
     public static List<PhoneAccountHandle> getCallCapablePhoneAccounts(Context context) {
-        if (hasReadPhoneStatePermission(context) && CompatUtils.isMSIMCompatible()) {
-            return getTelecomManager(context).getCallCapablePhoneAccounts();
+        if (hasReadPhoneStatePermission(context)) {
+            return TelecomManagerCompat.getCallCapablePhoneAccounts(getTelecomManager(context));
         }
         return new ArrayList<>();
     }
@@ -130,22 +138,17 @@
     public static boolean isVoicemailNumber(Context context, PhoneAccountHandle accountHandle,
             String number) {
         if (hasReadPhoneStatePermission(context)) {
-            if (CompatUtils.isMSIMCompatible()) {
-                return getTelecomManager(context).isVoiceMailNumber(accountHandle, number);
-            } else {
-                return PhoneNumberUtils.isVoiceMailNumber(number);
-            }
+            return TelecomManagerCompat.isVoiceMailNumber(getTelecomManager(context),
+                    accountHandle, number);
         }
         return false;
     }
 
+    @Nullable
     public static String getVoicemailNumber(Context context, PhoneAccountHandle accountHandle) {
         if (hasReadPhoneStatePermission(context)) {
-            if (CompatUtils.isMSIMCompatible()) {
-                return getTelecomManager(context).getVoiceMailNumber(accountHandle);
-            } else {
-                return getTelephonyManager(context).getVoiceMailNumber();
-            }
+            return TelecomManagerCompat.getVoiceMailNumber(getTelecomManager(context),
+                    getTelephonyManager(context), accountHandle);
         }
         return null;
     }
@@ -153,16 +156,15 @@
     /**
      * Tries to place a call using the {@link TelecomManager}.
      *
-     * @param context a valid context.
-     * @param address Handle to call.
-     * @param extras Bundle of extras to attach to the call intent.
+     * @param activity a valid activity.
+     * @param intent the call intent.
      *
      * @return {@code true} if we successfully attempted to place the call, {@code false} if it
      *         failed due to a permission check.
      */
-    public static boolean placeCall(Context context, Uri address, Bundle extras) {
-        if (hasCallPhonePermission(context)) {
-            getTelecomManager(context).placeCall(address, extras);
+    public static boolean placeCall(Activity activity, Intent intent) {
+        if (hasCallPhonePermission(activity)) {
+            TelecomManagerCompat.placeCall(activity, getTelecomManager(activity), intent);
             return true;
         }
         return false;
@@ -200,12 +202,8 @@
     }
 
     public static boolean isDefaultDialer(Context context) {
-        if (!DialerCompatUtils.isDefaultDialerCompatible()) {
-            return false;
-        }
-
         final boolean result = TextUtils.equals(context.getPackageName(),
-                getTelecomManager(context).getDefaultDialerPackage());
+                TelecomManagerCompat.getDefaultDialerPackage(getTelecomManager(context)));
         if (result) {
             sWarningLogged = false;
         } else {
diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
index a97fce3..28caed4 100644
--- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
@@ -26,6 +26,7 @@
 import com.android.contacts.common.CallUtil;
 import com.android.dialer.PhoneCallDetails;
 import com.android.dialer.R;
+import com.android.dialer.calllog.calllogcache.TestTelecomCallLogCache;
 import com.android.dialer.util.AppCompatConstants;
 
 /**
diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java
index 23ee7b3..b6202b9 100644
--- a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java
+++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java
@@ -28,6 +28,7 @@
 
 import com.android.dialer.PhoneCallDetails;
 import com.android.dialer.R;
+import com.android.dialer.calllog.calllogcache.TestTelecomCallLogCache;
 import com.android.dialer.util.AppCompatConstants;
 import com.android.dialer.util.LocaleTestUtils;
 
diff --git a/tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java b/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java
similarity index 94%
rename from tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java
rename to tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java
index fcf9884..077a498 100644
--- a/tests/src/com/android/dialer/calllog/TestTelecomCallLogCache.java
+++ b/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java
@@ -14,14 +14,12 @@
  * limitations under the License
  */
 
-package com.android.dialer.calllog;
+package com.android.dialer.calllog.calllogcache;
 
 import android.content.Context;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 
-import com.android.dialer.calllog.calllogcache.CallLogCache;
-
 /**
  * Modified version of {@link com.android.dialer.calllog.calllogcache.CallLogCache} to be used in
  * tests that allows injecting the voicemail number.
diff --git a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java
index ae0dba8..da41dfc 100644
--- a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java
+++ b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java
@@ -39,7 +39,6 @@
 import android.provider.VoicemailContract.Voicemails;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
-import android.telecom.TelecomManager;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.text.format.DateFormat;
@@ -56,8 +55,10 @@
 import android.widget.TimePicker;
 import android.widget.Toast;
 
+import com.android.contacts.common.compat.telecom.TelecomManagerCompat;
 import com.android.dialer.tests.R;
 import com.android.dialer.util.AppCompatConstants;
+import com.android.dialer.util.TelecomUtil;
 
 import java.util.Calendar;
 import java.util.List;
@@ -439,9 +440,8 @@
     }
 
     private PhoneAccountHandle getManualAccount() {
-        TelecomManager telecomManager =
-            (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
-        List <PhoneAccountHandle> accountHandles = telecomManager.getCallCapablePhoneAccounts();
+        List <PhoneAccountHandle> accountHandles = TelecomUtil.getCallCapablePhoneAccounts(this);
+        //TODO: hide the corresponding radio buttons if no accounts are available.
         if (mAccount0.isChecked()) {
             return accountHandles.get(0);
         } else if (mAccount1.isChecked()){
@@ -567,11 +567,9 @@
         final ContentResolver resolver = getContentResolver();
         int numberPresentation = Calls.PRESENTATION_ALLOWED;
 
-        TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
-
         String accountAddress = null;
-        if (tm != null && accountHandle != null) {
-            PhoneAccount account = tm.getPhoneAccount(accountHandle);
+        if (accountHandle != null) {
+            PhoneAccount account = TelecomUtil.getPhoneAccount(this, accountHandle);
             if (account != null) {
                 Uri address = account.getSubscriptionAddress();
                 if (address != null) {