From 5caefbff3feba750f68ba852f841bb155c1a134b Mon Sep 17 00:00:00 2001 From: Brad Ebinger Date: Tue, 7 May 2019 10:59:26 -0700 Subject: [PATCH] Resolve the SIM call manager per subId The SIM call manager used to be resolved based on what the default voice subscription ID was. This caused settings to be displayed for the incorrect subscription. A new API has been added that allows settings to query the SIM call manager per subId. Test: manual, unit testing Bug: 131627085 Change-Id: I7699508429f7df7a138c24c4c7a6e9f1148b84da --- .../network/telephony/MobileNetworkUtils.java | 19 ++++++++++++------- .../VideoCallingPreferenceController.java | 3 +-- .../WifiCallingPreferenceController.java | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java index 939598b5ec3..9b25338acea 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java +++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java @@ -80,12 +80,16 @@ public class MobileNetworkUtils { } /** - * Returns true if Wifi calling is enabled for at least one phone. + * Returns true if Wifi calling is enabled for at least one subscription. */ public static boolean isWifiCallingEnabled(Context context) { - int phoneCount = context.getSystemService(TelephonyManager.class).getPhoneCount(); - for (int i = 0; i < phoneCount; i++) { - if (isWifiCallingEnabled(context, i)) { + SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class); + if (subManager == null) { + Log.e(TAG, "isWifiCallingEnabled: couldn't get system service."); + return false; + } + for (int subId : subManager.getActiveSubscriptionIdList()) { + if (isWifiCallingEnabled(context, subId)) { return true; } } @@ -93,11 +97,12 @@ public class MobileNetworkUtils { } /** - * Returns true if Wifi calling is enabled for the specific phone with id {@code phoneId}. + * Returns true if Wifi calling is enabled for the specific subscription with id {@code subId}. */ - public static boolean isWifiCallingEnabled(Context context, int phoneId) { + public static boolean isWifiCallingEnabled(Context context, int subId) { final PhoneAccountHandle simCallManager = - TelecomManager.from(context).getSimCallManager(); + TelecomManager.from(context).getSimCallManagerForSubscription(subId); + final int phoneId = SubscriptionManager.getSlotIndex(subId); boolean isWifiCallingEnabled; if (simCallManager != null) { diff --git a/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java b/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java index 8c32df0ee12..1c788638151 100644 --- a/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java +++ b/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java @@ -63,8 +63,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC @Override public int getAvailabilityStatus(int subId) { return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID - && MobileNetworkUtils.isWifiCallingEnabled(mContext, - SubscriptionManager.getPhoneId(subId)) + && MobileNetworkUtils.isWifiCallingEnabled(mContext, subId) && isVideoCallEnabled(subId) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; diff --git a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java index 946f7416fed..c71ee3536b2 100644 --- a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java +++ b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java @@ -68,7 +68,6 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont super(context, key); mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class); mTelephonyManager = context.getSystemService(TelephonyManager.class); - mSimCallManager = context.getSystemService(TelecomManager.class).getSimCallManager(); mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper()); mEditableWfcRoamingMode = true; mUseWfcHomeModeForRoaming = false; @@ -77,8 +76,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont @Override public int getAvailabilityStatus(int subId) { return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID - && MobileNetworkUtils.isWifiCallingEnabled(mContext, - SubscriptionManager.getPhoneId(subId)) + && MobileNetworkUtils.isWifiCallingEnabled(mContext, subId) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @@ -155,6 +153,8 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont mSubId = subId; mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId); mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId)); + mSimCallManager = mContext.getSystemService(TelecomManager.class) + .getSimCallManagerForSubscription(mSubId); if (mCarrierConfigManager != null) { final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId); if (carrierConfig != null) {