From e54a3031c97ce55c8b15410d7fb78442c451ecad Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 10 Dec 2019 18:59:36 -0800 Subject: [PATCH] Do not get CM instance in getActiveModemCount unless needed. TM#getActiveModemCount might be called before ConnectivityService is initialized. So do not try to get ConnectivityService instance unless it's needed (very rarely). Otherwise it will throw WTF exception. Bug: 144373595 Test: sanity Change-Id: I7a90ec45a0a3700a0c6852c505d68f438f26768c Merged-In: I7a90ec45a0a3700a0c6852c505d68f438f26768c --- .../java/android/telephony/TelephonyManager.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 4fb26fdf1d2c2..5d7f3b4693120 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -416,14 +416,14 @@ public class TelephonyManager { int modemCount = 1; switch (getMultiSimConfiguration()) { case UNKNOWN: - ConnectivityManager cm = mContext == null ? null : (ConnectivityManager) mContext - .getSystemService(Context.CONNECTIVITY_SERVICE); + modemCount = MODEM_COUNT_SINGLE_MODEM; // check for voice and data support, 0 if not supported - if (!isVoiceCapable() && !isSmsCapable() && cm != null - && !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { - modemCount = MODEM_COUNT_NO_MODEM; - } else { - modemCount = MODEM_COUNT_SINGLE_MODEM; + if (!isVoiceCapable() && !isSmsCapable() && mContext != null) { + ConnectivityManager cm = (ConnectivityManager) mContext + .getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm != null && !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { + modemCount = MODEM_COUNT_NO_MODEM; + } } break; case DSDS: