Added getActiveSubInfoCount

Added getActiveSubInfoCount and migrated more modules
to use SubscrtipionManagerService.

Test: atest FrameworksTelephonyTests
Bug: 239607619
Merged-In: I114f28b781c5f09e26fed1b4af8002ff53fb2458
Change-Id: I114f28b781c5f09e26fed1b4af8002ff53fb2458
diff --git a/src/com/android/phone/settings/AccessibilitySettingsFragment.java b/src/com/android/phone/settings/AccessibilitySettingsFragment.java
index 475d878..4c29e65 100644
--- a/src/com/android/phone/settings/AccessibilitySettingsFragment.java
+++ b/src/com/android/phone/settings/AccessibilitySettingsFragment.java
@@ -40,6 +40,7 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.SubscriptionController;
+import com.android.internal.telephony.subscription.SubscriptionManagerService;
 import com.android.phone.PhoneGlobals;
 import com.android.phone.R;
 
@@ -183,10 +184,16 @@
             // Update RTT config with IMS Manager if the always-on carrier config isn't set to true.
             CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService(
                             Context.CARRIER_CONFIG_SERVICE);
-            for (int subId : SubscriptionController.getInstance().getActiveSubIdList(true)) {
+            int[] activeSubIds;
+            if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
+                activeSubIds = SubscriptionManagerService.getInstance().getActiveSubIdList(true);
+            } else {
+                activeSubIds = SubscriptionController.getInstance().getActiveSubIdList(true);
+            }
+            for (int subId : activeSubIds) {
                 if (!configManager.getConfigForSubId(subId).getBoolean(
                         CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL, false)) {
-                    int phoneId = SubscriptionController.getInstance().getPhoneId(subId);
+                    int phoneId = SubscriptionManager.getPhoneId(subId);
                     ImsManager imsManager = ImsManager.getInstance(getContext(), phoneId);
                     imsManager.setRttEnabled(mButtonRtt.isChecked());
                 }
@@ -264,6 +271,14 @@
     private boolean shouldShowRttSetting() {
         // Go through all the subs -- if we want to display the RTT setting for any of them, do
         // display it.
+        if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
+            for (int subId : SubscriptionManagerService.getInstance().getActiveSubIdList(true)) {
+                if (PhoneGlobals.getInstance().phoneMgr.isRttSupported(subId)) {
+                    return true;
+                }
+            }
+            return false;
+        }
         for (int subId : SubscriptionController.getInstance().getActiveSubIdList(true)) {
             if (PhoneGlobals.getInstance().phoneMgr.isRttSupported(subId)) {
                 return true;
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index a9b4c71..b04cd8f 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -64,6 +64,7 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.SubscriptionController;
+import com.android.internal.telephony.subscription.SubscriptionManagerService;
 import com.android.phone.PhoneGlobals;
 import com.android.phone.PhoneUtils;
 import com.android.phone.R;
@@ -535,18 +536,37 @@
                 return false;
             }
 
-            SubscriptionController controller = SubscriptionController.getInstance();
-            if (controller == null) {
-                Log.d(this, "isEmergencyPreferredAccount: SubscriptionController not available.");
-                return false;
-            }
-            // Only set an emergency preference on devices with multiple active subscriptions
-            // (include opportunistic subscriptions) in this check.
-            // API says never null, but this can return null in testing.
-            int[] activeSubIds = controller.getActiveSubIdList(false);
-            if (activeSubIds == null || activeSubIds.length <= 1) {
-                Log.d(this, "isEmergencyPreferredAccount: one or less active subscriptions.");
-                return false;
+            if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
+                if (SubscriptionManagerService.getInstance() == null) {
+                    Log.d(this,
+                            "isEmergencyPreferredAccount: SubscriptionManagerService not "
+                                    + "available.");
+                    return false;
+                }
+                // Only set an emergency preference on devices with multiple active subscriptions
+                // (include opportunistic subscriptions) in this check.
+                // API says never null, but this can return null in testing.
+                int[] activeSubIds = SubscriptionManagerService.getInstance()
+                        .getActiveSubIdList(false);
+                if (activeSubIds == null || activeSubIds.length <= 1) {
+                    Log.d(this, "isEmergencyPreferredAccount: one or less active subscriptions.");
+                    return false;
+                }
+            } else {
+                SubscriptionController controller = SubscriptionController.getInstance();
+                if (controller == null) {
+                    Log.d(this,
+                            "isEmergencyPreferredAccount: SubscriptionController not available.");
+                    return false;
+                }
+                // Only set an emergency preference on devices with multiple active subscriptions
+                // (include opportunistic subscriptions) in this check.
+                // API says never null, but this can return null in testing.
+                int[] activeSubIds = controller.getActiveSubIdList(false);
+                if (activeSubIds == null || activeSubIds.length <= 1) {
+                    Log.d(this, "isEmergencyPreferredAccount: one or less active subscriptions.");
+                    return false;
+                }
             }
             // Check to see if this PhoneAccount is associated with the default Data subscription.
             if (!SubscriptionManager.isValidSubscriptionId(subId)) {
@@ -554,10 +574,21 @@
                         + "valid.");
                 return false;
             }
-            int userDefaultData = controller.getDefaultDataSubId();
+            int userDefaultData = SubscriptionManager.getDefaultDataSubscriptionId();
             boolean isActiveDataValid = SubscriptionManager.isValidSubscriptionId(activeDataSubId);
-            boolean isActiveDataOpportunistic = isActiveDataValid
-                    && controller.isOpportunistic(activeDataSubId);
+
+            boolean isActiveDataOpportunistic;
+            if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
+                SubscriptionInfo subInfo;
+                subInfo = SubscriptionManagerService.getInstance()
+                        .getSubscriptionInfo(activeDataSubId);
+                isActiveDataOpportunistic = isActiveDataValid && subInfo != null
+                        && subInfo.isOpportunistic();
+            } else {
+                isActiveDataOpportunistic = isActiveDataValid
+                        && SubscriptionController.getInstance().isOpportunistic(activeDataSubId);
+            }
+
             // compare the activeDataSubId to the subId specified only if it is valid and not an
             // opportunistic subscription (only supports data). If not, use the current default
             // defined by the user.
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index bb96c7c..8cf2215 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -65,6 +65,8 @@
 import com.android.internal.telephony.imsphone.ImsExternalCallTracker;
 import com.android.internal.telephony.imsphone.ImsPhone;
 import com.android.internal.telephony.imsphone.ImsPhoneConnection;
+import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
+import com.android.internal.telephony.subscription.SubscriptionManagerService;
 import com.android.phone.FrameworksUtils;
 import com.android.phone.MMIDialogActivity;
 import com.android.phone.PhoneUtils;
@@ -804,6 +806,19 @@
                         return (phone.getState() == PhoneConstants.State.OFFHOOK)
                             || phone.getServiceStateTracker().isRadioOn();
                     } else {
+                        if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
+                            SubscriptionInfoInternal subInfo = SubscriptionManagerService
+                                    .getInstance().getSubscriptionInfoInternal(phone.getSubId());
+                            // Wait until we are in service and ready to make calls. This can happen
+                            // when we power down the radio on bluetooth to save power on watches or
+                            // if it is a test emergency number and we have to wait for the device
+                            // to move IN_SERVICE before the call can take place over normal
+                            // routing.
+                            return (phone.getState() == PhoneConstants.State.OFFHOOK)
+                                    // Do not wait for voice in service on opportunistic SIMs.
+                                    || (subInfo != null && subInfo.isOpportunistic())
+                                    || serviceState == ServiceState.STATE_IN_SERVICE;
+                        }
                         // Wait until we are in service and ready to make calls. This can happen
                         // when we power down the radio on bluetooth to save power on watches or if
                         // it is a test emergency number and we have to wait for the device to move
@@ -964,9 +979,16 @@
             // Notify Telecom of the new Connection type.
             // TODO: Switch out the underlying connection instead of creating a new
             // one and causing UI Jank.
-            boolean noActiveSimCard = SubscriptionController.getInstance()
-                    .getActiveSubInfoCount(phone.getContext().getOpPackageName(),
-                            phone.getContext().getAttributionTag()) == 0;
+            boolean noActiveSimCard;
+            if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
+                noActiveSimCard = SubscriptionManagerService.getInstance()
+                        .getActiveSubInfoCount(phone.getContext().getOpPackageName(),
+                                phone.getContext().getAttributionTag()) == 0;
+            } else {
+                noActiveSimCard = SubscriptionController.getInstance()
+                        .getActiveSubInfoCount(phone.getContext().getOpPackageName(),
+                                phone.getContext().getAttributionTag()) == 0;
+            }
             // If there's no active sim card and the device is in emergency mode, use E account.
             addExistingConnection(mPhoneUtilsProxy.makePstnPhoneAccountHandleWithPrefix(
                     phone, "", isEmergencyNumber && noActiveSimCard), repConnection);