Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9b6fd9f authored by Calvin On's avatar Calvin On Committed by Haiping Yang
Browse files

Refresh embedded subscriptions on user unlock.

The LPA is not reachable/available until after user unlock,
so the first refresh action taken by SubscriptionInfoUpdater
is guaranteed to fail.

This adds a retry to the refresh embedded subscriptions
operation after user unlock.  This gives SubscriptionInfoUpdater
another chance to correctly populate the subscription database
with the correct eUICC-related fields (e.g. isEmbedded).

Bug: 146587029
Bug: 146081151

Change-Id: I818a8b78ae48f95d29fd0dc354726739c4232c06
(cherry picked from commit 0fd23438cd59b12d98c18a563ea309e4edc431a8)
(cherry picked from commit 67f8615c4fc3b9f47022de8de6bdc040d85186d2)
parent 742b9521
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 *@hide
@@ -119,6 +120,28 @@ public class SubscriptionInfoUpdater extends Handler {
    private int mCurrentlyActiveUserId;
    private CarrierServiceBindHelper mCarrierServiceBindHelper;

    private volatile boolean shouldRetryUpdateEmbeddedSubscriptions = false;
    private final CopyOnWriteArraySet<Integer> retryUpdateEmbeddedSubscriptionCards =
        new CopyOnWriteArraySet<>();
    private final BroadcastReceiver mUserUnlockedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
                // The LPA may not have been ready before user unlock, and so previous attempts
                // to refresh the list of embedded subscriptions may have failed. This retries
                // the refresh operation after user unlock.
                if (shouldRetryUpdateEmbeddedSubscriptions) {
                    logd("Retrying refresh embedded subscriptions after user unlock.");
                    for (int cardId : retryUpdateEmbeddedSubscriptionCards){
                        requestEmbeddedSubscriptionInfoListRefresh(cardId, null);
                    }
                    retryUpdateEmbeddedSubscriptionCards.clear();
                    sContext.unregisterReceiver(mUserUnlockedReceiver);
                }
            }
        }
    };

    /**
     * Runnable with a boolean parameter. This is used in
     * updateEmbeddedSubscriptions(List<Integer> cardIds, @Nullable UpdateEmbeddedSubsCallback).
@@ -143,6 +166,10 @@ public class SubscriptionInfoUpdater extends Handler {
        mEuiccManager = (EuiccManager) sContext.getSystemService(Context.EUICC_SERVICE);

        mCarrierServiceBindHelper = new CarrierServiceBindHelper(sContext);

        sContext.registerReceiver(
                mUserUnlockedReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));

        initializeCarrierApps();

        PhoneConfigurationManager.registerForMultiSimConfigChange(
@@ -815,6 +842,7 @@ public class SubscriptionInfoUpdater extends Handler {
        // Do nothing if eUICCs are disabled. (Previous entries may remain in the cache, but they
        // are filtered out of list calls as long as EuiccManager.isEnabled returns false).
        if (!mEuiccManager.isEnabled()) {
            if (DBG) logd("updateEmbeddedSubscriptions: eUICC not enabled");
            callback.run(false /* hasChanges */);
            return;
        }
@@ -859,7 +887,9 @@ public class SubscriptionInfoUpdater extends Handler {
        if (DBG) logd("updateEmbeddedSubscriptionsCache");

        if (result == null) {
            // IPC to the eUICC controller failed.
            if (DBG) logd("updateEmbeddedSubscriptionsCache: IPC to the eUICC controller failed");
            retryUpdateEmbeddedSubscriptionCards.add(cardId);
            shouldRetryUpdateEmbeddedSubscriptions = true;
            return false;
        }