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

Commit acffe4dd authored by Nancy Chen's avatar Nancy Chen Committed by Android (Google) Code Review
Browse files

Merge "Guard against methods that use the PhoneAccount object pre-MSIM." into...

Merge "Guard against methods that use the PhoneAccount object pre-MSIM." into ub-contactsdialer-b-dev
parents 244979ea ee5b3dcb
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.widget.EditText;
import android.widget.Toast;

import com.android.common.io.MoreCloseables;
import com.android.contacts.common.compat.CompatUtils;
import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler;
import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
@@ -246,13 +247,14 @@ public class SpecialCharSequenceMgr {

                List<PhoneAccountHandle> subscriptionAccountHandles =
                        PhoneAccountUtils.getSubscriptionPhoneAccounts(context);

                Context applicationContext = context.getApplicationContext();
                boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
                        TelecomUtil.getDefaultOutgoingPhoneAccount(applicationContext,
                                PhoneAccount.SCHEME_TEL));

                if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
                if (!CompatUtils.isMSIMCompatible()) {
                    handleAdnQuery(handler, sc, Uri.parse("content://icc/adn"));
                } else if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
                    Uri uri = TelecomUtil.getAdnUriForPhoneAccount(applicationContext, null);
                    handleAdnQuery(handler, sc, uri);
                } else if (subscriptionAccountHandles.size() > 1){
@@ -303,7 +305,8 @@ public class SpecialCharSequenceMgr {
            boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(
                    TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL));

            if (subscriptionAccountHandles.size() == 1 || hasUserSelectedDefault) {
            if (!CompatUtils.isMSIMCompatible() || 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);
@@ -332,12 +335,16 @@ public class SpecialCharSequenceMgr {
                    R.string.imei : R.string.meid;

            List<String> deviceIds = new ArrayList<String>();
            if (!CompatUtils.isMSIMCompatible()) {
                deviceIds.add(telephonyManager.getDeviceId());
            } else {
                for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) {
                    String deviceId = telephonyManager.getDeviceId(slot);
                    if (!TextUtils.isEmpty(deviceId)) {
                        deviceIds.add(deviceId);
                    }
                }
            }

            AlertDialog alert = new AlertDialog.Builder(context)
                    .setTitle(labelResId)
+0 −11
Original line number Diff line number Diff line
@@ -20,17 +20,6 @@ import android.os.Build;
import com.android.contacts.common.compat.SdkVersionOverride;

public final class DialerCompatUtils {
    /**
     * Determines if this version is compatible with video calling. Can also force the version to be
     * lower through SdkVersionOverride.
     *
     * @return {@code true} if video calling is allowed, {@code false} otherwise.
     */
    public static boolean isVideoCompatible() {
        return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP)
                >= Build.VERSION_CODES.M;
    }

    /**
     * Determines if this version is compatible with a default dialer. Can also force the version to
     * be lower through SdkVersionOverride.
+18 −3
Original line number Diff line number Diff line
@@ -25,9 +25,12 @@ import android.provider.CallLog.Calls;
import android.support.v4.content.ContextCompat;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.android.contacts.common.compat.CompatUtils;
import com.android.dialer.compat.DialerCompatUtils;

import java.util.ArrayList;
@@ -111,7 +114,7 @@ public class TelecomUtil {
    }

    public static List<PhoneAccountHandle> getCallCapablePhoneAccounts(Context context) {
        if (hasReadPhoneStatePermission(context)) {
        if (hasReadPhoneStatePermission(context) && CompatUtils.isMSIMCompatible()) {
            return getTelecomManager(context).getCallCapablePhoneAccounts();
        }
        return new ArrayList<>();
@@ -127,14 +130,22 @@ public class TelecomUtil {
    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 false;
    }

    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 null;
    }
@@ -210,4 +221,8 @@ public class TelecomUtil {
    private static TelecomManager getTelecomManager(Context context) {
        return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    }

    private static TelephonyManager getTelephonyManager(Context context) {
        return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    }
}