Change EuiccConnector to only refresh eSIM profile list when rebinding

EuiccConnector picks the best LPA to use. In order to detect whether
there is a new LPA installed, it listens to all app package status
changes which including deleting, installation, and modification. The
profile list refresh was placed in the wrong place which will be
triggered on any app package status changes. In order to fix this issue,
we should only refresh the eSIM profile list when EuiccConnector rebind
a LPA.
Bug: 171616491
Test: Manually tested

Change-Id: I7c49734b10ea4df7615dc9fbc6db6d2ae3169185
(cherry picked from commit d25d66d642b10eda7908fe5cb70a2742faf96049)
diff --git a/src/java/com/android/internal/telephony/euicc/EuiccConnector.java b/src/java/com/android/internal/telephony/euicc/EuiccConnector.java
index f135e62..d58c5d4 100644
--- a/src/java/com/android/internal/telephony/euicc/EuiccConnector.java
+++ b/src/java/com/android/internal/telephony/euicc/EuiccConnector.java
@@ -404,6 +404,8 @@
 
         start();
 
+        // All app package changes could trigger the package monitor receiver. It is not limited to
+        // apps extended from EuiccService.
         mPackageMonitor.register(mContext, null /* thread */, null /* user */);
         mContext.registerReceiver(
                 mUserUnlockedReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
@@ -555,10 +557,10 @@
                 mSelectedComponent = findBestComponent();
                 if (mSelectedComponent != null) {
                     transitionTo(mAvailableState);
+                    updateSubscriptionInfoListForAllAccessibleEuiccs();
                 } else if (getCurrentState() != mUnavailableState) {
                     transitionTo(mUnavailableState);
                 }
-                updateSubscriptionInfoListForAllAccessibleEuiccs();
                 return HANDLED;
             } else if (isEuiccCommand(message.what)) {
                 BaseEuiccCommandCallback callback = getCallback(message);
@@ -651,11 +653,16 @@
                 if (bestComponent == null) {
                     isSameComponent = mSelectedComponent != null;
                 } else {
+                    // Checks whether the bound component is the same as the best component. If it
+                    // is not, set isSameComponent to false and the connector will bind the best
+                    // component instead.
                     isSameComponent = mSelectedComponent == null
                             || Objects.equals(new ComponentName(bestComponent.packageName,
                             bestComponent.name),
                         new ComponentName(mSelectedComponent.packageName, mSelectedComponent.name));
                 }
+                // Checks whether the bound component is impacted by the package changes. If it is,
+                // change the forceRebind to true so the connector will re-bind the component.
                 boolean forceRebind = bestComponent != null
                         && Objects.equals(bestComponent.packageName, affectedPackage);
                 if (!isSameComponent || forceRebind) {
@@ -666,8 +673,8 @@
                     } else {
                         transitionTo(mBindingState);
                     }
+                    updateSubscriptionInfoListForAllAccessibleEuiccs();
                 }
-                updateSubscriptionInfoListForAllAccessibleEuiccs();
                 return HANDLED;
             } else if (message.what == CMD_CONNECT_TIMEOUT) {
                 transitionTo(mAvailableState);