Check emergency routing information for emergency calls only

Modify the code to check emergency routing information only for
emergency calls.
EmergencyNumberTracker is required to check emergency routing
information.
EmergencyNumberTracker can be accessed through the phone object.
If it is not an emergency call and SIM is not inserted,
the phone returned by getPhoneForAccount is null.

Bug: 348599476
Test: build and manual test
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:817fbef49fcfcdcf686d1c8dd48623d89078f9fa)
Merged-In: If46cdb4d41ab128360461ac230e8f851b942e719
Change-Id: If46cdb4d41ab128360461ac230e8f851b942e719
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index cf8d55f..81ade13 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -1189,8 +1189,10 @@
         }
 
         if (mDomainSelectionResolver.isDomainSelectionSupported()) {
-            // Normal routing emergency number shall be handled by normal call domain selctor.
-            int routing = getEmergencyCallRouting(phone, number, needToTurnOnRadio);
+            // Normal routing emergency number shall be handled by normal call domain selector.
+            int routing = (isEmergencyNumber)
+                    ? getEmergencyCallRouting(phone, number, needToTurnOnRadio)
+                    : EmergencyNumber.EMERGENCY_CALL_ROUTING_UNKNOWN;
             if (isEmergencyNumber && routing != EmergencyNumber.EMERGENCY_CALL_ROUTING_NORMAL) {
                 final Connection resultConnection =
                         placeEmergencyConnection(phone,
@@ -2932,6 +2934,9 @@
     }
 
     private int getEmergencyCallRouting(Phone phone, String number, boolean needToTurnOnRadio) {
+        if (phone == null) {
+            return EmergencyNumber.EMERGENCY_CALL_ROUTING_UNKNOWN;
+        }
         // This method shall be called only if AOSP domain selection is enabled.
         if (mDynamicRoutingController == null) {
             mDynamicRoutingController = DynamicRoutingController.getInstance();