Re-evaluate disallowed reasons when carrier config changes

Bug: 377926314
Test: SatelliteManagerTestOnMockService
Flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn

Change-Id: Ie59875000acacf1f6e75ea5566b89b7606f6d11f
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
index 0b7337b..f5b230f 100644
--- a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
@@ -575,8 +575,9 @@
 
         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);
@@ -1230,9 +1231,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();
@@ -1597,42 +1598,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: "
@@ -2519,6 +2530,8 @@
         }
 
         synchronized (mSatelliteDisallowedReasonsLock) {
+            logd("mSatelliteDisallowedReasons:"
+                    + String.join(", ", mSatelliteDisallowedReasons.toString()));
             return mSatelliteDisallowedReasons;
         }
     }
@@ -2820,13 +2833,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) {