Add a test API for sending EVENT_DISPLAY_EMERGENCY_MESSAGE

Bug: 305030915
Test: SMS, MMS, call with live network.
atest SatelliteSOSMessageRecommenderTest TelephonyConnectionServiceTest ImsCallingTest
Manually triggered an emergency call and verify the log as expected.

Change-Id: Ieb9b5d9cde95bcb1d9d4a53a933e0e867b459820
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 4e673d8..cb4f239 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -12667,6 +12667,30 @@
     }
 
     /**
+     * This API can be used in only testing to override connectivity status in monitoring emergency
+     * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
+     *
+     * @param handoverType The type of handover from emergency call to satellite messaging. Use one
+     *                     of the following values to enable the override:
+     *                     0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
+     *                     1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
+     *                     To disable the override, use -1 for handoverType.
+     * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
+     *                     delaySeconds after the emergency call starts.
+     * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
+     */
+    public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
+        Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
+        TelephonyPermissions.enforceShellOnly(
+                Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
+        TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
+                SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+                "setEmergencyCallToSatelliteHandoverType");
+        return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
+                handoverType, delaySeconds);
+    }
+
+    /**
      * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
      *
      * <p>This method behaves in one of the following ways:
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index 1ee48c4..d6ecc48 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -189,6 +189,8 @@
             "set-satellite-pointing-ui-class-name";
     private static final String SET_SATELLITE_DEVICE_ALIGNED_TIMEOUT_DURATION =
             "set-satellite-device-aligned-timeout-duration";
+    private static final String SET_EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE =
+            "set-emergency-call-to-satellite-handover-type";
 
     private static final String INVALID_ENTRY_ERROR = "An emergency number (only allow '0'-'9', "
             + "'*', '#' or '+') needs to be specified after -a in the command ";
@@ -380,6 +382,8 @@
                 return handleSetSatellitePointingUiClassNameCommand();
             case SET_SATELLITE_DEVICE_ALIGNED_TIMEOUT_DURATION:
                 return handleSettSatelliteDeviceAlignedTimeoutDuration();
+            case SET_EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE:
+                return handleSetEmergencyCallToSatelliteHandoverType();
             default: {
                 return handleDefaultCommands(cmd);
             }
@@ -779,6 +783,14 @@
         pw.println("           launch. If no option is specified, it will launch the default.");
         pw.println("      -c: the satellite pointing UI app class name that Telephony will");
         pw.println("           launch.");
+        pw.println("  set-emergency-call-to-satellite-handover-type [-t HANDOVER_TYPE ");
+        pw.println("    -d DELAY_SECONDS] Override connectivity status in monitoring emergency ");
+        pw.println("    call and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.");
+        pw.println("    Options are:");
+        pw.println("      -t: the emergency call to satellite handover type.");
+        pw.println("          If no option is specified, override is disabled.");
+        pw.println("      -d: the delay in seconds in sending EVENT_DISPLAY_EMERGENCY_MESSAGE.");
+        pw.println("          If no option is specified, there is no delay in sending the event.");
     }
 
     private void onHelpImei() {
@@ -3217,6 +3229,55 @@
         return 0;
     }
 
+    private int handleSetEmergencyCallToSatelliteHandoverType() {
+        PrintWriter errPw = getErrPrintWriter();
+        int handoverType = -1;
+        int delaySeconds = 0;
+
+        String opt;
+        while ((opt = getNextOption()) != null) {
+            switch (opt) {
+                case "-t": {
+                    try {
+                        handoverType = Integer.parseInt(getNextArgRequired());
+                    } catch (NumberFormatException e) {
+                        errPw.println("SetEmergencyCallToSatelliteHandoverType: require an integer"
+                                + " for handoverType");
+                        return -1;
+                    }
+                    break;
+                }
+                case "-d": {
+                    try {
+                        delaySeconds = Integer.parseInt(getNextArgRequired());
+                    } catch (NumberFormatException e) {
+                        errPw.println("SetEmergencyCallToSatelliteHandoverType: require an integer"
+                                + " for delaySeconds");
+                        return -1;
+                    }
+                    break;
+                }
+            }
+        }
+        Log.d(LOG_TAG, "handleSetEmergencyCallToSatelliteHandoverType: handoverType="
+                + handoverType + ", delaySeconds=" + delaySeconds);
+
+        try {
+            boolean result =
+                    mInterface.setEmergencyCallToSatelliteHandoverType(handoverType, delaySeconds);
+            if (VDBG) {
+                Log.v(LOG_TAG, "setEmergencyCallToSatelliteHandoverType result =" + result);
+            }
+            getOutPrintWriter().println(result);
+        } catch (RemoteException e) {
+            Log.e(LOG_TAG, "setEmergencyCallToSatelliteHandoverType: " + handoverType
+                    + ", error = " + e.getMessage());
+            errPw.println("Exception: " + e.getMessage());
+            return -1;
+        }
+        return 0;
+    }
+
     private int handleSetSatelliteListeningTimeoutDuration() {
         PrintWriter errPw = getErrPrintWriter();
         long timeoutMillis = 0;
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index cad71c4..83d721b 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -19,8 +19,8 @@
 import static android.telephony.CarrierConfigManager.KEY_USE_ONLY_DIALED_SIM_ECC_LIST_BOOL;
 import static android.telephony.DomainSelectionService.SELECTOR_TYPE_CALLING;
 import static android.telephony.TelephonyManager.HAL_SERVICE_VOICE;
-import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
 
+import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
 import static com.android.internal.telephony.flags.Flags.carrierEnabledSatelliteFlag;
 
 import android.annotation.NonNull;
@@ -4171,11 +4171,11 @@
     private void handleEmergencyCallStartedForSatelliteSOSMessageRecommender(
             @NonNull TelephonyConnection connection, @NonNull Phone phone) {
         if (mSatelliteSOSMessageRecommender == null) {
-            mSatelliteSOSMessageRecommender = new SatelliteSOSMessageRecommender(
+            mSatelliteSOSMessageRecommender = new SatelliteSOSMessageRecommender(phone.getContext(),
                     phone.getContext().getMainLooper());
         }
         connection.addTelephonyConnectionListener(mEmergencyConnectionSatelliteListener);
-        mSatelliteSOSMessageRecommender.onEmergencyCallStarted(connection, phone);
+        mSatelliteSOSMessageRecommender.onEmergencyCallStarted(connection);
     }
 
     /**