From ee5b3dcb3f505395ed95eeca0085783030135a2d Mon Sep 17 00:00:00 2001 From: Nancy Chen Date: Tue, 8 Dec 2015 16:52:51 -0800 Subject: Guard against methods that use the PhoneAccount object pre-MSIM. Use alternative means or just return empty lists when calling methods that require MSIM in pre-LMr1 devices. Also move compatability checks to ContactsCommon for methods that may be called in ContactsCommon as well as Dialer Bug: 25776171 Change-Id: I074bb147dbd53d623f322482ad735391c84ae5ad --- src/com/android/dialer/SpecialCharSequenceMgr.java | 21 ++++++++++++++------- .../android/dialer/compat/DialerCompatUtils.java | 11 ----------- src/com/android/dialer/util/TelecomUtil.java | 21 ++++++++++++++++++--- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/com/android/dialer/SpecialCharSequenceMgr.java b/src/com/android/dialer/SpecialCharSequenceMgr.java index d9e293888..c212597f6 100644 --- a/src/com/android/dialer/SpecialCharSequenceMgr.java +++ b/src/com/android/dialer/SpecialCharSequenceMgr.java @@ -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 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,10 +335,14 @@ public class SpecialCharSequenceMgr { R.string.imei : R.string.meid; List deviceIds = new ArrayList(); - for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) { - String deviceId = telephonyManager.getDeviceId(slot); - if (!TextUtils.isEmpty(deviceId)) { - deviceIds.add(deviceId); + 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); + } } } diff --git a/src/com/android/dialer/compat/DialerCompatUtils.java b/src/com/android/dialer/compat/DialerCompatUtils.java index 07a279aa4..1bcdd14ad 100644 --- a/src/com/android/dialer/compat/DialerCompatUtils.java +++ b/src/com/android/dialer/compat/DialerCompatUtils.java @@ -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. diff --git a/src/com/android/dialer/util/TelecomUtil.java b/src/com/android/dialer/util/TelecomUtil.java index a0c833462..a617af6d2 100644 --- a/src/com/android/dialer/util/TelecomUtil.java +++ b/src/com/android/dialer/util/TelecomUtil.java @@ -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 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)) { - return getTelecomManager(context).isVoiceMailNumber(accountHandle, number); + 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)) { - return getTelecomManager(context).getVoiceMailNumber(accountHandle); + 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); + } } -- cgit v1.2.3