Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdb93b70 authored by Nancy Chen's avatar Nancy Chen
Browse files

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
parent 4a7c43ab
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.widget.Toast;

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 @@ public class SpecialCharSequenceMgr {
                        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 @@ public class SpecialCharSequenceMgr {
                            subscriptionAccountHandles, callback);
                    dialogFragment.show(((Activity) context).getFragmentManager(),
                            TAG_SELECT_ACCT_FRAGMENT);
                } else {
                    return false;
                }

                return true;
@@ -305,12 +302,11 @@ public class SpecialCharSequenceMgr {
            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 @@ public class SpecialCharSequenceMgr {
                    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)
+18 −22
Original line number Diff line number Diff line
@@ -18,11 +18,12 @@ package com.android.dialer.calllog;

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 @@ public class PhoneAccountUtils {
     * 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 @@ public class PhoneAccountUtils {
    /**
     * 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 @@ public class PhoneAccountUtils {
    /**
     * 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 @@ public class PhoneAccountUtils {
    /**
     * 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 @@ public class PhoneAccountUtils {
     * @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 @@ public class PhoneAccountUtils {
     * 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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public abstract class CallLogCache {
     * 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);
+2 −16
Original line number Diff line number Diff line
@@ -15,22 +15,9 @@
 */
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 @@ public final class DialerCompatUtils {
     * {@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
+7 −8
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ 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;
@@ -59,8 +60,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
        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);
@@ -69,7 +69,6 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
            target.add(quickResponseSettingsHeader);
        }


        TelephonyManager telephonyManager =
                (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

@@ -78,7 +77,8 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
        // 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);
@@ -102,10 +102,9 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
            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);
Loading