Iterate through Phones when routing Emergency Call
Iterate through the Phones directly instead of iterating based on the
Sub ID. If there are no SIMs in the device, then this approach did not
work historically (and would always use the first Phone).
Also, re-order the logic for getFirstPhoneForEmergencyCall to first
consider the user's voice calling preference, instead of always using
Slot 0.
Change-Id: Ib77347373ed98b138effe3c4735edb4eaa650aa5
Fixes: 28598339
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index 40e4ef9..0af667a 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -605,35 +605,46 @@
return chosenPhone;
}
+ /**
+ * Retrieves the most sensible Phone to use for an emergency call using the following Priority
+ * list (for multi-SIM devices):
+ * 1) The User's SIM preference for Voice calling
+ * 2) The First Phone that is currently IN_SERVICE or is available for emergency calling
+ * 3) The First Phone that has a SIM card in it (Starting from Slot 0...N)
+ * 4) The Default Phone (Currently set as Slot 0)
+ */
private Phone getFirstPhoneForEmergencyCall() {
Phone firstPhoneWithSim = null;
- for (int i = 0; i < TelephonyManager.getDefault().getSimCount(); i++) {
- int[] subIds = SubscriptionController.getInstance().getSubIdUsingSlotId(i);
- if (subIds.length == 0)
- continue;
- int phoneId = SubscriptionController.getInstance().getPhoneId(subIds[0]);
- Phone phone = PhoneFactory.getPhone(phoneId);
+ // 1)
+ int phoneId = SubscriptionManager.getDefaultVoicePhoneId();
+ if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
+ Phone defaultPhone = PhoneFactory.getPhone(phoneId);
+ if (defaultPhone != null && isAvailableForEmergencyCalls(defaultPhone)) {
+ return defaultPhone;
+ }
+ }
+
+ for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
+ Phone phone = PhoneFactory.getPhone(i);
if (phone == null)
continue;
-
- if (ServiceState.STATE_IN_SERVICE == phone.getServiceState().getState() ||
- phone.getServiceState().isEmergencyOnly()) {
- // the slot has the radio on & state is in service. This will be quicker,
- // so just shortcut and use this option.
- Log.d(this, "getFirstPhoneForEmergencyCall, radio on & in service, slotId:" + i);
+ // 2)
+ if (isAvailableForEmergencyCalls(phone)) {
+ // the slot has the radio on & state is in service.
+ Log.d(this, "getFirstPhoneForEmergencyCall, radio on & in service, Phone Id:" + i);
return phone;
}
-
+ // 3)
if (firstPhoneWithSim == null && TelephonyManager.getDefault().hasIccCard(i)) {
// The slot has a SIM card inserted, but is not in service, so keep track of this
// Phone. Do not return because we want to make sure that none of the other Phones
// are in service (because that is always faster).
- Log.d(this, "getFirstPhoneForEmergencyCall, SIM card inserted, slotId:" + i);
+ Log.d(this, "getFirstPhoneForEmergencyCall, SIM card inserted, Phone Id:" + i);
firstPhoneWithSim = phone;
}
}
-
+ // 4)
if (firstPhoneWithSim == null) {
// No SIMs inserted, get the default.
Log.d(this, "getFirstPhoneForEmergencyCall, return default phone");
@@ -644,6 +655,14 @@
}
/**
+ * Returns true if the state of the Phone is IN_SERVICE or available for emergency calling only.
+ */
+ private boolean isAvailableForEmergencyCalls(Phone phone) {
+ return ServiceState.STATE_IN_SERVICE == phone.getServiceState().getState() ||
+ phone.getServiceState().isEmergencyOnly();
+ }
+
+ /**
* Determines if the connection should allow mute.
*
* @param phone The current phone.