Change the provisioning status storing timeing and only pass the IccId different between previous to modem

1. The timing of saving the provisioning status of the SubscriberId list is changed to the point of processing the CMD_PROVISION_SATELLITE_TOKEN_UPDATED message.
2. The IccId is re-delivered to the modem only if it is different from the one previously delivered.

Bug: 358167517
Test: atest SatelliteController
Test: manual test with test apk
Flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn

Change-Id: Id8b105a97d90fae86f609cecd7f8c91393c1a410
diff --git a/src/java/com/android/internal/telephony/satellite/SatelliteController.java b/src/java/com/android/internal/telephony/satellite/SatelliteController.java
index 621f355..3cfb7ee 100644
--- a/src/java/com/android/internal/telephony/satellite/SatelliteController.java
+++ b/src/java/com/android/internal/telephony/satellite/SatelliteController.java
@@ -471,6 +471,9 @@
     // key : priority, low value is high, value : List<SubscriptionInfo>
     @GuardedBy("mSatelliteTokenProvisionedLock")
     private Map<Integer, List<SubscriptionInfo>> mSubsInfoListPerPriority = new HashMap<>();
+    // The last ICC ID that framework configured to modem.
+    @GuardedBy("mSatelliteTokenProvisionedLock")
+    private String mLastConfiguredIccId;
     @NonNull private final Object mSatelliteTokenProvisionedLock = new Object();
     private long mWaitTimeForSatelliteEnablingResponse;
     private long mDemoPointingAlignedDurationMillis;
@@ -1569,11 +1572,20 @@
                 synchronized (mSatelliteTokenProvisionedLock) {
                     subId = mSubscriberIdPerSub.getOrDefault(
                             argument.mProvisionSubscriberIdList.get(0).getSubscriberId(), -1);
+                    for (ProvisionSubscriberId subscriberId : argument.mProvisionSubscriberIdList) {
+                        mProvisionedSubscriberId.put(subscriberId.getSubscriberId(), true);
+                    }
                 }
                 setSatellitePhone(subId);
                 String iccId = mSubscriptionManagerService.getSubscriptionInfo(subId).getIccId();
-                logd("CMD_PROVISION_SATELLITE_TOKEN_UPDATED: subId=" + subId + ", iccId=" + iccId);
-                mSatelliteModemInterface.updateSatelliteSubscription(iccId, onCompleted);
+                argument.setIccId(iccId);
+                synchronized (mSatelliteTokenProvisionedLock) {
+                    if (!iccId.equals(mLastConfiguredIccId)) {
+                        logd("updateSatelliteSubscription subId=" + subId + ", iccId=" + iccId
+                                + " to modem");
+                        mSatelliteModemInterface.updateSatelliteSubscription(iccId, onCompleted);
+                    }
+                }
                 Consumer<Integer> result = new Consumer<Integer>() {
                     @Override
                     public void accept(Integer integer) {
@@ -1593,10 +1605,16 @@
                         (RequestProvisionSatelliteArgument) request.argument;
                 int error = SatelliteServiceUtils.getSatelliteError(ar,
                         "updateSatelliteSubscription");
-                logd("EVENT_PROVISION_SATELLITE_TOKEN_UPDATED =" + error);
+                if (error == SATELLITE_RESULT_SUCCESS) {
+                    synchronized (mSatelliteTokenProvisionedLock) {
+                        mLastConfiguredIccId = argument.getIccId();
+                    }
+                }
+                logd("updateSatelliteSubscription result=" + error);
                 Bundle bundle = new Bundle();
-                bundle.putBoolean(SatelliteManager.KEY_PROVISION_SATELLITE_TOKENS, true);
-                argument.mResult.send(SATELLITE_RESULT_SUCCESS, bundle);
+                bundle.putBoolean(SatelliteManager.KEY_PROVISION_SATELLITE_TOKENS,
+                        error == SATELLITE_RESULT_SUCCESS);
+                argument.mResult.send(error, bundle);
                 break;
             }
 
@@ -1624,9 +1642,9 @@
 
     private static final class RequestProvisionSatelliteArgument {
         public List<ProvisionSubscriberId> mProvisionSubscriberIdList;
-        @NonNull
-        public ResultReceiver mResult;
+        @NonNull public ResultReceiver mResult;
         public long mRequestId;
+        public String mIccId;
 
         RequestProvisionSatelliteArgument(List<ProvisionSubscriberId> provisionSubscriberIdList,
                 ResultReceiver result) {
@@ -1635,6 +1653,14 @@
             this.mRequestId = sNextSatelliteEnableRequestId.getAndUpdate(
                     n -> ((n + 1) % Long.MAX_VALUE));
         }
+
+        public void setIccId(String iccId) {
+            mIccId = iccId;
+        }
+
+        public String getIccId() {
+            return mIccId;
+        }
     }
 
     private void handleEventConfigDataUpdated() {
@@ -5680,12 +5706,6 @@
         }
 
         logd("provisionSatellite:" + list);
-        for (ProvisionSubscriberId subscriberId : list) {
-            synchronized (mSatelliteTokenProvisionedLock) {
-                mProvisionedSubscriberId.put(subscriberId.getSubscriberId(), true);
-            }
-        }
-
         RequestProvisionSatelliteArgument request = new RequestProvisionSatelliteArgument(list,
                 result);
         sendRequestAsync(CMD_PROVISION_SATELLITE_TOKEN_UPDATED, request, null);