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

Commit 6ecb63f1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Pass the SubscriptionController instance from PhoneFactory"

parents c81d89a3 4ee804f7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ public class PhoneFactory {
                sSubInfoRecordUpdater = TelephonyComponentFactory.getInstance().inject(
                        SubscriptionInfoUpdater.class.getName()).
                        makeSubscriptionInfoUpdater(pfhandlerThread.
                        getLooper(), context, sCommandsInterfaces);
                        getLooper(), context, SubscriptionController.getInstance());

                // Only bring up IMS if the device supports having an IMS stack.
                if (context.getPackageManager().hasSystemFeature(
+42 −62
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ public class SubscriptionInfoUpdater extends Handler {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)

    protected static String[] sIccId = new String[SUPPORTED_MODEM_COUNT];
    protected SubscriptionController mSubscriptionController = null;
    private static String[] sInactiveIccIds = new String[SUPPORTED_MODEM_COUNT];
    private static int[] sSimCardState = new int[SUPPORTED_MODEM_COUNT];
    private static int[] sSimApplicationState = new int[SUPPORTED_MODEM_COUNT];
@@ -134,14 +135,13 @@ public class SubscriptionInfoUpdater extends Handler {
        void run(boolean hasChanges);
    }

    // TODO: The SubscriptionController instance should be passed in here from PhoneFactory
    // rather than invoking the static getter all over the place.
    @VisibleForTesting public SubscriptionInfoUpdater(Looper looper, Context context,
            CommandsInterface[] ci) {
    @VisibleForTesting
    public SubscriptionInfoUpdater(Looper looper, Context context, SubscriptionController sc) {
        logd("Constructor invoked");
        mBackgroundHandler = new Handler(looper);

        sContext = context;
        mSubscriptionController = sc;
        mSubscriptionManager = SubscriptionManager.from(sContext);
        mEuiccManager = (EuiccManager) sContext.getSystemService(Context.EUICC_SERVICE);

@@ -308,7 +308,7 @@ public class SubscriptionInfoUpdater extends Handler {
                cardIds.add(getCardIdFromPhoneId(msg.arg1));
                updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
                    if (hasChanges) {
                        SubscriptionController.getInstance().notifySubscriptionInfoChanged();
                        mSubscriptionController.notifySubscriptionInfoChanged();
                    }
                });
                handleSimNotReady(msg.arg1);
@@ -319,7 +319,7 @@ public class SubscriptionInfoUpdater extends Handler {
                Runnable r = (Runnable) msg.obj;
                updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
                    if (hasChanges) {
                        SubscriptionController.getInstance().notifySubscriptionInfoChanged();
                        mSubscriptionController.notifySubscriptionInfoChanged();
                    }
                    if (r != null) {
                        r.run();
@@ -414,7 +414,7 @@ public class SubscriptionInfoUpdater extends Handler {
        cardIds.add(getCardIdFromPhoneId(phoneId));
        updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
            if (hasChanges) {
            SubscriptionController.getInstance().notifySubscriptionInfoChanged();
                mSubscriptionController.notifySubscriptionInfoChanged();
            }
        });
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_READY, null);
@@ -459,8 +459,9 @@ public class SubscriptionInfoUpdater extends Handler {
        // handleSimNotReady so this will be evaluated again.
        UiccSlot slot = UiccController.getInstance().getUiccSlotForPhone(phoneId);
        if (slot == null || slot.getIccId() == null) return false;
        SubscriptionInfo info = SubscriptionController.getInstance()
                .getSubInfoForIccId(IccUtils.stripTrailingFs(slot.getIccId()));
        SubscriptionInfo info =
                mSubscriptionController.getSubInfoForIccId(
                        IccUtils.stripTrailingFs(slot.getIccId()));
        return info != null && !info.areUiccApplicationsEnabled();
    }

@@ -487,8 +488,8 @@ public class SubscriptionInfoUpdater extends Handler {
        sIccId[phoneId] = IccUtils.stripTrailingFs(records.getFullIccId());

        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
        List<SubscriptionInfo> subscriptionInfos = SubscriptionController.getInstance()
                .getSubInfoUsingSlotIndexPrivileged(phoneId);
        List<SubscriptionInfo> subscriptionInfos =
                mSubscriptionController.getSubInfoUsingSlotIndexPrivileged(phoneId);
        if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
            loge("empty subinfo for phoneId: " + phoneId + "could not update ContentResolver");
        } else {
@@ -499,10 +500,10 @@ public class SubscriptionInfoUpdater extends Handler {
                String operator = tm.getSimOperatorNumeric(subId);

                if (!TextUtils.isEmpty(operator)) {
                    if (subId == SubscriptionController.getInstance().getDefaultSubId()) {
                    if (subId == mSubscriptionController.getDefaultSubId()) {
                        MccTable.updateMccMncConfiguration(sContext, operator);
                    }
                    SubscriptionController.getInstance().setMccMnc(operator, subId);
                    mSubscriptionController.setMccMnc(operator, subId);
                } else {
                    logd("EVENT_RECORDS_LOADED Operator name is null");
                }
@@ -510,25 +511,25 @@ public class SubscriptionInfoUpdater extends Handler {
                String iso = tm.getSimCountryIsoForPhone(phoneId);

                if (!TextUtils.isEmpty(iso)) {
                    SubscriptionController.getInstance().setCountryIso(iso, subId);
                    mSubscriptionController.setCountryIso(iso, subId);
                } else {
                    logd("EVENT_RECORDS_LOADED sim country iso is null");
                }

                String msisdn = tm.getLine1Number(subId);
                if (msisdn != null) {
                    SubscriptionController.getInstance().setDisplayNumber(msisdn, subId);
                    mSubscriptionController.setDisplayNumber(msisdn, subId);
                }

                String imsi = tm.createForSubscriptionId(subId).getSubscriberId();
                if (imsi != null) {
                    SubscriptionController.getInstance().setImsi(imsi, subId);
                    mSubscriptionController.setImsi(imsi, subId);
                }

                String[] ehplmns = records.getEhplmns();
                String[] hplmns = records.getPlmnsFromHplmnActRecord();
                if (ehplmns != null || hplmns != null) {
                    SubscriptionController.getInstance().setAssociatedPlmns(ehplmns, hplmns, subId);
                    mSubscriptionController.setAssociatedPlmns(ehplmns, hplmns, subId);
                }

                /* Update preferred network type and network selection mode on SIM change.
@@ -620,8 +621,8 @@ public class SubscriptionInfoUpdater extends Handler {
        if (!TextUtils.isEmpty(iccId)) {
            // If iccId is new, add a subscription record in the db.
            String strippedIccId = IccUtils.stripTrailingFs(iccId);
            if (SubscriptionController.getInstance().getSubInfoForIccId(strippedIccId) == null) {
                SubscriptionController.getInstance().insertEmptySubInfoRecord(
            if (mSubscriptionController.getSubInfoForIccId(strippedIccId) == null) {
                mSubscriptionController.insertEmptySubInfoRecord(
                        strippedIccId, "CARD", SubscriptionManager.INVALID_PHONE_INDEX,
                        SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
            }
@@ -707,7 +708,7 @@ public class SubscriptionInfoUpdater extends Handler {
        // Clear phoneId only when sim absent is not enough. It's possible to switch SIM profile
        // within the same slot. Need to clear the slot index of the previous sub. Thus always clear
        // for the changing slot first.
        SubscriptionController.getInstance().clearSubInfoRecord(phoneId);
        mSubscriptionController.clearSubInfoRecord(phoneId);

        // If SIM is not absent, insert new record or update existing record.
        if (!ICCID_STRING_FOR_NO_SIM.equals(sIccId[phoneId])) {
@@ -716,8 +717,8 @@ public class SubscriptionInfoUpdater extends Handler {
            mSubscriptionManager.addSubscriptionInfoRecord(sIccId[phoneId], phoneId);
        }

        List<SubscriptionInfo> subInfos = SubscriptionController.getInstance()
                .getSubInfoUsingSlotIndexPrivileged(phoneId);
        List<SubscriptionInfo> subInfos =
                mSubscriptionController.getSubInfoUsingSlotIndexPrivileged(phoneId);
        if (subInfos != null) {
            boolean changed = false;
            for (int i = 0; i < subInfos.size(); i++) {
@@ -736,7 +737,7 @@ public class SubscriptionInfoUpdater extends Handler {
            }
            if (changed) {
                // refresh Cached Active Subscription Info List
                SubscriptionController.getInstance().refreshCachedActiveSubscriptionInfoList();
                mSubscriptionController.refreshCachedActiveSubscriptionInfoList();
            }
        }

@@ -766,22 +767,22 @@ public class SubscriptionInfoUpdater extends Handler {
            }
            updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
                if (hasChanges) {
                    SubscriptionController.getInstance().notifySubscriptionInfoChanged();
                    mSubscriptionController.notifySubscriptionInfoChanged();
                }
                if (DBG) logd("updateSubscriptionInfoByIccId: SubscriptionInfo update complete");
            });
        }

        SubscriptionController.getInstance().notifySubscriptionInfoChanged();
        mSubscriptionController.notifySubscriptionInfoChanged();
        if (DBG) logd("updateSubscriptionInfoByIccId: SubscriptionInfo update complete");
    }

    private static void setSubInfoInitialized() {
    private void setSubInfoInitialized() {
        // Should only be triggered once.
        if (!sIsSubInfoInitialized) {
            if (DBG) logd("SubInfo Initialized");
            sIsSubInfoInitialized = true;
            SubscriptionController.getInstance().notifySubInfoReady();
            mSubscriptionController.notifySubInfoReady();
            MultiSimSettingController.getInstance().notifyAllSubscriptionLoaded();
        }
    }
@@ -891,8 +892,9 @@ public class SubscriptionInfoUpdater extends Handler {
        // Update or insert records for all embedded subscriptions (except non-removable ones if the
        // current eUICC is non-removable, since we assume these are still accessible though not
        // returned by the eUICC controller).
        List<SubscriptionInfo> existingSubscriptions = SubscriptionController.getInstance()
                .getSubscriptionInfoListForEmbeddedSubscriptionUpdate(embeddedIccids, isRemovable);
        List<SubscriptionInfo> existingSubscriptions =
                mSubscriptionController.getSubscriptionInfoListForEmbeddedSubscriptionUpdate(
                        embeddedIccids, isRemovable);
        ContentResolver contentResolver = sContext.getContentResolver();
        for (EuiccProfileInfo embeddedProfile : embeddedProfiles) {
            int index =
@@ -901,7 +903,7 @@ public class SubscriptionInfoUpdater extends Handler {
            int nameSource = SubscriptionManager.NAME_SOURCE_CARRIER_ID;
            if (index < 0) {
                // No existing entry for this ICCID; create an empty one.
                SubscriptionController.getInstance().insertEmptySubInfoRecord(
                mSubscriptionController.insertEmptySubInfoRecord(
                        embeddedProfile.getIccid(), SubscriptionManager.SIM_NOT_INSERTED);
            } else {
                nameSource = existingSubscriptions.get(index).getNameSource();
@@ -963,7 +965,7 @@ public class SubscriptionInfoUpdater extends Handler {
                    SubscriptionManager.ICC_ID + "=\"" + embeddedProfile.getIccid() + "\"", null);

            // refresh Cached Active Subscription Info List
            SubscriptionController.getInstance().refreshCachedActiveSubscriptionInfoList();
            mSubscriptionController.refreshCachedActiveSubscriptionInfoList();
        }

        // Remove all remaining subscriptions which have embedded = true. We set embedded to false
@@ -991,7 +993,7 @@ public class SubscriptionInfoUpdater extends Handler {
            contentResolver.update(SubscriptionManager.CONTENT_URI, values, whereClause, null);

            // refresh Cached Active Subscription Info List
            SubscriptionController.getInstance().refreshCachedActiveSubscriptionInfoList();
            mSubscriptionController.refreshCachedActiveSubscriptionInfoList();
        }

        if (DBG) logd("updateEmbeddedSubscriptions done hasChanges=" + hasChanges);
@@ -1041,20 +1043,14 @@ public class SubscriptionInfoUpdater extends Handler {
            return;
        }

        SubscriptionController sc = SubscriptionController.getInstance();
        if (sc == null) {
            loge("SubscriptionController was null");
            return;
        }

        int currentSubId = sc.getSubIdUsingPhoneId(phoneId);
        int currentSubId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
        if (!SubscriptionManager.isValidSubscriptionId(currentSubId)
                || currentSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
            if (DBG) logd("No subscription is active for phone being updated");
            return;
        }

        SubscriptionInfo currentSubInfo = sc.getSubscriptionInfo(currentSubId);
        SubscriptionInfo currentSubInfo = mSubscriptionController.getSubscriptionInfo(currentSubId);
        if (currentSubInfo == null) {
            loge("Couldn't retrieve subscription info for current subscription");
            return;
@@ -1098,8 +1094,8 @@ public class SubscriptionInfoUpdater extends Handler {
                            && currentSubInfo.getGroupUuid() != null) {
                        cv.put(SubscriptionManager.GROUP_UUID, (String) null);
                        if (DBG) logd("Group Removed for" + currentSubId);
                    } else if (SubscriptionController.getInstance().canPackageManageGroup(groupUuid,
                        configPackageName)) {
                    } else if (mSubscriptionController.canPackageManageGroup(
                            groupUuid, configPackageName)) {
                        cv.put(SubscriptionManager.GROUP_UUID, groupUuid.toString());
                        cv.put(SubscriptionManager.GROUP_OWNER, configPackageName);
                        if (DBG) logd("Group Added for" + currentSubId);
@@ -1114,8 +1110,8 @@ public class SubscriptionInfoUpdater extends Handler {
        }
        if (cv.size() > 0 && sContext.getContentResolver().update(SubscriptionManager
                    .getUriForSubscriptionId(currentSubId), cv, null, null) > 0) {
            sc.refreshCachedActiveSubscriptionInfoList();
            sc.notifySubscriptionInfoChanged();
            mSubscriptionController.refreshCachedActiveSubscriptionInfoList();
            mSubscriptionController.notifySubscriptionInfoChanged();
            MultiSimSettingController.getInstance().notifySubscriptionGroupChanged(groupUuid);
        }
    }
@@ -1129,22 +1125,6 @@ public class SubscriptionInfoUpdater extends Handler {
        return -1;
    }

    private boolean isNewSim(String iccId, String decIccId, String[] oldIccId) {
        boolean newSim = true;
        for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
            if(iccId.equals(oldIccId[i])) {
                newSim = false;
                break;
            } else if (decIccId != null && decIccId.equals(oldIccId[i])) {
                newSim = false;
                break;
            }
        }
        logd("newSim = " + newSim);

        return newSim;
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    protected void broadcastSimStateChanged(int phoneId, String state, String reason) {
        Intent i = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
+2 −2
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@ public class TelephonyComponentFactory {
    }

    public SubscriptionInfoUpdater makeSubscriptionInfoUpdater(Looper looper, Context context,
            CommandsInterface[] ci) {
        return new SubscriptionInfoUpdater(looper, context, ci);
            SubscriptionController sc) {
        return new SubscriptionInfoUpdater(looper, context, sc);
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.List;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.SubscriptionInfoUpdater;
@@ -49,10 +48,10 @@ public class VendorSubscriptionInfoUpdater extends SubscriptionInfoUpdater {
            .getSupportedModemCount();

    static VendorSubscriptionInfoUpdater init(Looper looper, Context context,
            CommandsInterface[] ci) {
            SubscriptionController sc) {
        synchronized (VendorSubscriptionInfoUpdater.class) {
            if (sInstance == null) {
                sInstance = new VendorSubscriptionInfoUpdater(looper, context, ci);
                sInstance = new VendorSubscriptionInfoUpdater(looper, context, sc);
            } else {
                Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
            }
@@ -68,8 +67,8 @@ public class VendorSubscriptionInfoUpdater extends SubscriptionInfoUpdater {
    }

    protected VendorSubscriptionInfoUpdater(Looper looper, Context context,
            CommandsInterface[] ci) {
        super(looper, context, ci);
            SubscriptionController sc) {
        super(looper, context, sc);
        sContext = context;
        mIsRecordUpdateRequired = new boolean[SUPPORTED_MODEM_COUNT];

@@ -105,7 +104,7 @@ public class VendorSubscriptionInfoUpdater extends SubscriptionInfoUpdater {
        cardIds.add(getCardIdFromPhoneId(phoneId));
        updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
            if (hasChanges) {
                SubscriptionController.getInstance().notifySubscriptionInfoChanged();
                mSubscriptionController.notifySubscriptionInfoChanged();
            }
        });
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_READY, null);
+2 −2
Original line number Diff line number Diff line
@@ -162,8 +162,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
                .getActiveSubIdList(/*visibleOnly*/false);
        mIccRecord = mUiccProfile.getIccRecords();

        mUpdater = new SubscriptionInfoUpdater(Looper.myLooper(), mContext,
            new CommandsInterface[]{mSimulatedCommands});
        mUpdater =
                new SubscriptionInfoUpdater(Looper.myLooper(), mContext, mSubscriptionController);
        processAllMessages();

        assertFalse(mUpdater.isSubInfoInitialized());