Modify Settings to use new SIM call manager API

Mofify the telephony settings to query the SIM
call manager per subId, instead of using the
SIM call manager associated with the default
voice subscription ID.

Test: manual
Bug: 131627085
Merged-In: I4e481d74c1b2bf8944b3c973c074146136592900
Change-Id: Id3dd81618d122ddf4c2b24957b474908fdbf8818
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 877e0b5..5a4026d 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -375,7 +375,8 @@
             prefSet.removePreference(mEnableVideoCalling);
         }
 
-        final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManager();
+        final PhoneAccountHandle simCallManager = mTelecomManager.getSimCallManagerForSubscription(
+                mPhone.getSubId());
         if (simCallManager != null) {
             Intent intent = PhoneAccountSettingsFragment.buildPhoneAccountConfigureIntent(
                     this, simCallManager);
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index 03e0097..38cef9b 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -150,12 +150,17 @@
 
 
     /**
-     * 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 = TelephonyManager.from(context).getPhoneCount();
-        for (int i = 0; i < phoneCount; i++) {
-            if (isWifiCallingEnabled(context, i)) {
+        SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
+        if (subManager == null) {
+            Log.e(MobileNetworkFragment.LOG_TAG,
+                    "isWifiCallingEnabled: couldn't get system service.");
+            return false;
+        }
+        for (int subId : subManager.getActiveSubscriptionIdList()) {
+            if (isWifiCallingEnabled(context, subId)) {
                 return true;
             }
         }
@@ -163,11 +168,12 @@
     }
 
     /**
-     * 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) {
@@ -1889,14 +1895,14 @@
             }
 
             // Removes the preference if the wifi calling is disabled.
-            if (!isWifiCallingEnabled(getContext(), SubscriptionManager.getPhoneId(mSubId))) {
+            if (!isWifiCallingEnabled(getContext(), mSubId)) {
                 mCallingCategory.removePreference(mWiFiCallingPref);
                 return;
             }
 
             // See what Telecom thinks the SIM call manager is.
             final PhoneAccountHandle simCallManager =
-                    TelecomManager.from(getContext()).getSimCallManager();
+                    TelecomManager.from(getContext()).getSimCallManagerForSubscription(mSubId);
 
             // Check which SIM call manager is for the current sub ID.
             PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);