Add method for getting all active phones.

Bug: 18232725
Change-Id: I373e9cfba703553043749431aeeaffaea62411b7
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index e957924..fe40b17 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -48,6 +48,7 @@
 import android.preference.PreferenceManager;
 import android.provider.Settings.System;
 import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
 import android.util.Log;
 
 import com.android.internal.telephony.Call;
@@ -58,11 +59,15 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
+import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.phone.common.CallLogAsync;
 import com.android.server.sip.SipService;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Global state for the telephony subsystem when running in the primary
  * phone process.
@@ -480,12 +485,26 @@
     }
 
     /**
-     * Returns the Phone associated with this instance
+     * Returns the Phone associated with this instance.
+     * WARNING: This method should be used carefully, now that there may be multiple phones.
      */
     public static Phone getPhone() {
         return getInstance().phone;
     }
 
+    /**
+     * Returns a list of the currently active phones for the Telephony package.
+     */
+    public static List<Phone> getPhones() {
+        int[] subIds = SubscriptionController.getInstance().getActiveSubIdList();
+        List<Phone> phones = new ArrayList<Phone>(subIds.length);
+
+        for (int i = 0; i < subIds.length; i++) {
+            phones.add(PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subIds[i])));
+        }
+        return phones;
+    }
+
     /* package */ BluetoothManager getBluetoothManager() {
         return bluetoothManager;
     }