Snap for 12680993 from 09bbb91f21792c0c0e0815a6f1815cf7923361a9 to 25Q1-release

Change-Id: I71ed22c99c5f3af4541fdb6b9465af624e8c8a2a
diff --git a/res/values/config.xml b/res/values/config.xml
index 847c4c5..03da05b 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -394,4 +394,10 @@
 
     <!-- Whether to turn off OEM-enabled satellite during emergency call -->
     <bool name="config_turn_off_oem_enabled_satellite_during_emergency_call">false</bool>
+
+    <!-- The timeout duration in milliseconds used to determine how long does it wait for modem to
+         get in-service state when dialing emergency routing emergency calls in airplane mode before
+         starting the call. If the value is 0, it doesn't wait and starts the call right after
+         turning radio power on. -->
+    <integer name="config_in_service_wait_timer_when_dialing_emergency_routing_ecc_in_apm">3000</integer>
 </resources>
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index dcddf2b..bab260c 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -571,8 +571,10 @@
                 // Initialize EmergencyStateTracker if domain selection is supported
                 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
                         .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
+                int inServiceWaitTimeWhenDialEccInApm = getResources().getInteger(R.integer
+                        .config_in_service_wait_timer_when_dialing_emergency_routing_ecc_in_apm);
                 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall,
-                        mFeatureFlags);
+                        inServiceWaitTimeWhenDialEccInApm, mFeatureFlags);
                 DynamicRoutingController.getInstance().initialize(this);
             }
 
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
index d0d0e8f..0a1a1ad 100644
--- a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
@@ -169,6 +169,7 @@
     protected static final int EVENT_COUNTRY_CODE_CHANGED = 5;
     protected static final int EVENT_LOCATION_SETTINGS_ENABLED = 6;
     protected static final int CMD_UPDATE_SYSTEM_SELECTION_CHANNELS = 7;
+    protected static final int EVENT_LOCATION_SETTINGS_DISABLED = 8;
 
     public static final int DEFAULT_REGIONAL_SATELLITE_CONFIG_ID = 0;
     public static final int UNKNOWN_REGIONAL_SATELLITE_CONFIG_ID = -1;
@@ -398,6 +399,9 @@
                 if (mLocationManager.isLocationEnabled()) {
                     plogd("Location settings is just enabled");
                     sendRequestAsync(EVENT_LOCATION_SETTINGS_ENABLED, null);
+                } else {
+                    plogd("Location settings is just enabled");
+                    sendRequestAsync(EVENT_LOCATION_SETTINGS_DISABLED, null);
                 }
             }
         }
@@ -476,6 +480,8 @@
         mNotifySatelliteAvailabilityEnabled =
                 context.getResources().getBoolean(
                         R.bool.config_satellite_should_notify_availability);
+        initializeSatelliteSystemNotification(context);
+        registerDefaultSmsAppChangedBroadcastReceiver(context);
 
         mInternalSatelliteSupportedStateCallback = new ISatelliteSupportedStateCallback.Stub() {
             @Override
@@ -550,6 +556,7 @@
                         + satelliteSubscriberProvisionStatus);
             }
         };
+        initializeSatelliteSystemNotification(context);
         result = mSatelliteController.registerForSatelliteProvisionStateChanged(
                 mInternalSatelliteProvisionStateCallback);
         plogd("registerForSatelliteProvisionStateChanged result: " + result);
@@ -565,14 +572,13 @@
 
         // Init the SatelliteOnDeviceAccessController so that the S2 level can be cached
         initSatelliteOnDeviceAccessController();
-        initializeSatelliteSystemNotification(context);
         registerLocationModeChangedBroadcastReceiver(context);
-        registerDefaultSmsAppChangedBroadcastReceiver(context);
 
         mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
         mCarrierConfigChangeListener =
-                (slotIndex, subId, carrierId, specificCarrierId) ->
-                        handleCarrierConfigChanged(slotIndex, subId, carrierId, specificCarrierId);
+                (slotIndex, subId, carrierId, specificCarrierId) -> handleCarrierConfigChanged(
+                    context, slotIndex, subId, carrierId, specificCarrierId);
+
         if (mCarrierConfigManager != null) {
             mCarrierConfigManager.registerCarrierConfigChangeListener(
                     new HandlerExecutor(new Handler(looper)), mCarrierConfigChangeListener);
@@ -632,6 +638,7 @@
                 updateSatelliteConfigData((Context) ar.userObj);
                 break;
             case EVENT_LOCATION_SETTINGS_ENABLED:
+            case EVENT_LOCATION_SETTINGS_DISABLED:
                 // Fall through
             case EVENT_COUNTRY_CODE_CHANGED:
                 handleSatelliteAllowedRegionPossiblyChanged(msg.what);
@@ -1225,9 +1232,9 @@
     }
 
     private void registerDefaultSmsAppChangedBroadcastReceiver(Context context) {
-        if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
+        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
             plogd("registerDefaultSmsAppChangedBroadcastReceiver: Flag "
-                    + "oemEnabledSatellite is disabled");
+                    + "carrierRoamingNbIotNtn is disabled");
             return;
         }
         IntentFilter intentFilter = new IntentFilter();
@@ -1397,12 +1404,17 @@
         logd("mSatelliteDisallowedReasons:"
                 + String.join(", ", mSatelliteDisallowedReasons.toString()));
         notifySatelliteDisallowedReasonsChanged();
-        if (mNotifySatelliteAvailabilityEnabled) {
+        if (mFeatureFlags.carrierRoamingNbIotNtn() && mNotifySatelliteAvailabilityEnabled) {
             showSatelliteSystemNotification();
         }
     }
 
     private void showSatelliteSystemNotification() {
+        if (mNotificationManager == null) {
+            logd("showSatelliteSystemNotification: NotificationManager is null");
+            return;
+        }
+
         if (mSatelliteDisallowedReasons.isEmpty()) {
             if (!hasAlreadyNotified(KEY_AVAILABLE_NOTIFICATION_SHOWN, 0)) {
                 mNotificationManager.notifyAsUser(
@@ -1515,6 +1527,10 @@
         );
         notificationChannel.setSound(null, null);
         mNotificationManager = context.getSystemService(NotificationManager.class);
+        if(mNotificationManager == null) {
+            ploge("initializeSatelliteSystemNotification: notificationManager is null");
+            return;
+        }
         mNotificationManager.createNotificationChannel(notificationChannel);
 
         createAvailableNotifications(context);
@@ -1587,42 +1603,52 @@
                 public void onReceive(Context context, Intent intent) {
                     if (intent.getAction()
                             .equals(Intent.ACTION_PACKAGE_CHANGED)) {
-                        boolean isDefaultMsgAppSupported = false;
-                        ComponentName componentName =
-                                SmsApplication.getDefaultSmsApplicationAsUser(
-                                        context, true, context.getUser());
-                        logd("Current default SMS app:" + componentName);
-                        if (componentName != null) {
-                            String packageName = componentName.getPackageName();
-                            List<String> supportedMsgApps =
-                                    mSatelliteController.getSatelliteSupportedMsgApps(
-                                            mSatelliteController.getSelectedSatelliteSubId());
-                            if (supportedMsgApps.contains(packageName)) {
-                                isDefaultMsgAppSupported = true;
-                            }
-                        } else {
-                            logd("No default SMS app");
-                        }
-
-                        if (isDefaultMsgAppSupported) {
-                            if (mSatelliteDisallowedReasons.contains(Integer.valueOf(
-                                    SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP))) {
-                                mSatelliteDisallowedReasons.remove(Integer.valueOf(
-                                        SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP));
-                                handleEventDisallowedReasonsChanged();
-                            }
-                        } else {
-                            if (!mSatelliteDisallowedReasons.contains(Integer.valueOf(
-                                    SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP))) {
-                                mSatelliteDisallowedReasons.add(Integer.valueOf(
-                                        SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP));
-                                handleEventDisallowedReasonsChanged();
-                            }
-                        }
+                        evaluatePossibleChangeInDefaultSmsApp(context);
                     }
                 }
             };
 
+    private void evaluatePossibleChangeInDefaultSmsApp(@NonNull Context context) {
+        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
+            plogd("evaluatePossibleChangeInDefaultSmsApp: Flag "
+                    + "carrierRoamingNbIotNtn is disabled");
+            return;
+        }
+
+        boolean isDefaultMsgAppSupported = false;
+        ComponentName componentName = SmsApplication.getDefaultSmsApplicationAsUser(
+                        context, true, context.getUser());
+        plogd("Current default SMS app:" + componentName);
+        if (componentName != null) {
+            String packageName = componentName.getPackageName();
+            List<String> supportedMsgApps =
+                    mSatelliteController.getSatelliteSupportedMsgApps(
+                            mSatelliteController.getSelectedSatelliteSubId());
+            plogd("supportedMsgApps:" + String.join(", ", supportedMsgApps));
+            if (supportedMsgApps.contains(packageName)) {
+                isDefaultMsgAppSupported = true;
+            }
+        } else {
+            plogd("No default SMS app");
+        }
+
+        if (isDefaultMsgAppSupported) {
+            if (mSatelliteDisallowedReasons.contains(Integer.valueOf(
+                    SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP))) {
+                mSatelliteDisallowedReasons.remove(Integer.valueOf(
+                        SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP));
+                handleEventDisallowedReasonsChanged();
+            }
+        } else {
+            if (!mSatelliteDisallowedReasons.contains(Integer.valueOf(
+                    SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP))) {
+                mSatelliteDisallowedReasons.add(Integer.valueOf(
+                        SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP));
+                handleEventDisallowedReasonsChanged();
+            }
+        }
+    }
+
     private void handleSatelliteAllowedRegionPossiblyChanged(int handleEvent) {
         if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
             ploge("handleSatelliteAllowedRegionPossiblyChanged: "
@@ -2509,6 +2535,8 @@
         }
 
         synchronized (mSatelliteDisallowedReasonsLock) {
+            logd("mSatelliteDisallowedReasons:"
+                    + String.join(", ", mSatelliteDisallowedReasons.toString()));
             return mSatelliteDisallowedReasons;
         }
     }
@@ -2810,13 +2838,16 @@
         }
     }
 
-    private void handleCarrierConfigChanged(int slotIndex, int subId,
-            int carrierId, int specificCarrierId) {
+    private void handleCarrierConfigChanged(@NonNull Context context, int slotIndex,
+            int subId, int carrierId, int specificCarrierId) {
         if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
             plogd("handleCarrierConfigChanged: carrierRoamingNbIotNtn flag is disabled");
             return;
         }
+        plogd("handleCarrierConfigChanged: slotIndex=" + slotIndex + ", subId=" + subId
+                + ", carrierId=" + carrierId + ", specificCarrierId=" + specificCarrierId);
         updateSatelliteRegionalConfig(subId);
+        evaluatePossibleChangeInDefaultSmsApp(context);
     }
 
     private void plogv(@NonNull String log) {