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

Commit ca76ad33 authored by Amit Mahajan's avatar Amit Mahajan Committed by android-build-merger
Browse files

Merge "changed slotId to phoneId for handling SIM states." am: 47a09425

am: 3d3209c1

Change-Id: Ia237a6d03784ef9c600d16387988e04357bce370
parents 13b70171 3d3209c1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -86,13 +86,13 @@ public class IntentBroadcaster {
     * Wrapper for ActivityManager.broadcastStickyIntent() that also stores intent to be rebroadcast
     * on USER_UNLOCKED
     */
    public void broadcastStickyIntent(Intent intent, int slotId) {
    public void broadcastStickyIntent(Intent intent, int phoneId) {
        logd("Broadcasting and adding intent for rebroadcast: " + intent.getAction() + " "
                + intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)
                + " for slotId " + slotId);
                + " for phoneId " + phoneId);
        synchronized (mRebroadcastIntents) {
            ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL);
            mRebroadcastIntents.put(slotId, intent);
            mRebroadcastIntents.put(phoneId, intent);
        }
    }

+89 −90
Original line number Diff line number Diff line
@@ -197,13 +197,13 @@ public class SubscriptionInfoUpdater extends Handler {
    /**
     * Update subscriptions when given a new ICC state.
     */
    public void updateInternalIccState(String simStatus, String reason, int slotId,
    public void updateInternalIccState(String simStatus, String reason, int phoneId,
            boolean absentAndInactive) {
        logd("updateInternalIccState to simStatus " + simStatus + " reason " + reason
                + " slotId " + slotId);
                + " phoneId " + phoneId);
        int message = internalIccStateToMessage(simStatus);
        if (message != EVENT_INVALID) {
            sendMessage(obtainMessage(message, slotId, absentAndInactive ? 1 : 0, reason));
            sendMessage(obtainMessage(message, phoneId, absentAndInactive ? 1 : 0, reason));
        }
    }

@@ -371,15 +371,15 @@ public class SubscriptionInfoUpdater extends Handler {
                EVENT_REFRESH_EMBEDDED_SUBSCRIPTIONS, cardId, 0 /* arg2 */, callback));
    }

    private void handleSimLocked(int slotId, String reason) {
        if (sIccId[slotId] != null && sIccId[slotId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (slotId + 1) + " hot plug in");
            sIccId[slotId] = null;
    private void handleSimLocked(int phoneId, String reason) {
        if (sIccId[phoneId] != null && sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (phoneId + 1) + " hot plug in");
            sIccId[phoneId] = null;
        }

        String iccId = sIccId[slotId];
        String iccId = sIccId[phoneId];
        if (iccId == null) {
            IccCard iccCard = PhoneFactory.getPhone(slotId).getIccCard();
            IccCard iccCard = PhoneFactory.getPhone(phoneId).getIccCard();
            if (iccCard == null) {
                logd("handleSimLocked: IccCard null");
                return;
@@ -393,18 +393,18 @@ public class SubscriptionInfoUpdater extends Handler {
                logd("handleSimLocked: IccID null");
                return;
            }
            sIccId[slotId] = IccUtils.stripTrailingFs(records.getFullIccId());
            sIccId[phoneId] = IccUtils.stripTrailingFs(records.getFullIccId());
        } else {
            logd("NOT Querying IccId its already set sIccid[" + slotId + "]=" + iccId);
            logd("NOT Querying IccId its already set sIccid[" + phoneId + "]=" + iccId);
        }

        updateSubscriptionInfoByIccId(slotId, true /* updateEmbeddedSubs */);
        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);

        broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED, reason);
        broadcastSimCardStateChanged(slotId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(slotId, getSimStateFromLockedReason(reason));
        updateSubscriptionCarrierId(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
        updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_LOCKED, reason);
        broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(phoneId, getSimStateFromLockedReason(reason));
        updateSubscriptionCarrierId(phoneId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
        updateCarrierServices(phoneId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
    }

    private static int getSimStateFromLockedReason(String lockedReason) {
@@ -423,32 +423,31 @@ public class SubscriptionInfoUpdater extends Handler {
        }
    }

    private void handleSimNotReady(int slotId) {
        logd("handleSimNotReady: slotId: " + slotId);
    private void handleSimNotReady(int phoneId) {
        logd("handleSimNotReady: phoneId: " + phoneId);

        IccCard iccCard = PhoneFactory.getPhone(slotId).getIccCard();
        IccCard iccCard = PhoneFactory.getPhone(phoneId).getIccCard();
        if (iccCard.isEmptyProfile()) {
            // ICC_NOT_READY is a terminal state for an eSIM on the boot profile. At this
            // phase, the subscription list is accessible. Treating NOT_READY
            // as equivalent to ABSENT, once the rest of the system can handle it.
            sIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
            updateSubscriptionInfoByIccId(slotId, false /* updateEmbeddedSubs */);
            sIccId[phoneId] = ICCID_STRING_FOR_NO_SIM;
            updateSubscriptionInfoByIccId(phoneId, false /* updateEmbeddedSubs */);
        }

        broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_NOT_READY,
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_NOT_READY,
                null);
        broadcastSimCardStateChanged(slotId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(slotId, TelephonyManager.SIM_STATE_NOT_READY);
        broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_NOT_READY);
    }

    private void handleSimLoaded(int slotId) {
        logd("handleSimLoaded: slotId: " + slotId);
    private void handleSimLoaded(int phoneId) {
        logd("handleSimLoaded: phoneId: " + phoneId);

        // The SIM should be loaded at this state, but it is possible in cases such as SIM being
        // removed or a refresh RESET that the IccRecords could be null. The right behavior is to
        // not broadcast the SIM loaded.
        int loadedSlotId = slotId;
        IccCard iccCard = PhoneFactory.getPhone(slotId).getIccCard();
        IccCard iccCard = PhoneFactory.getPhone(phoneId).getIccCard();
        if (iccCard == null) {  // Possibly a race condition.
            logd("handleSimLoaded: IccCard null");
            return;
@@ -462,13 +461,13 @@ public class SubscriptionInfoUpdater extends Handler {
            logd("handleSimLoaded: IccID null");
            return;
        }
        sIccId[slotId] = IccUtils.stripTrailingFs(records.getFullIccId());
        sIccId[phoneId] = IccUtils.stripTrailingFs(records.getFullIccId());

        updateSubscriptionInfoByIccId(slotId, true /* updateEmbeddedSubs */);
        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
        List<SubscriptionInfo> subscriptionInfos = SubscriptionController.getInstance()
                .getSubInfoUsingSlotIndexPrivileged(slotId);
                .getSubInfoUsingSlotIndexPrivileged(phoneId);
        if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
            loge("empty subinfo for slotId: " + slotId + "could not update ContentResolver");
            loge("empty subinfo for phoneId: " + phoneId + "could not update ContentResolver");
        } else {
            for (SubscriptionInfo sub : subscriptionInfos) {
                int subId = sub.getSubscriptionId();
@@ -485,7 +484,7 @@ public class SubscriptionInfoUpdater extends Handler {
                    logd("EVENT_RECORDS_LOADED Operator name is null");
                }

                String iso = tm.getSimCountryIsoForPhone(slotId);
                String iso = tm.getSimCountryIsoForPhone(phoneId);

                if (!TextUtils.isEmpty(iso)) {
                    SubscriptionController.getInstance().setCountryIso(iso, subId);
@@ -514,11 +513,11 @@ public class SubscriptionInfoUpdater extends Handler {
                 */
                SharedPreferences sp =
                        PreferenceManager.getDefaultSharedPreferences(sContext);
                int storedSubId = sp.getInt(CURR_SUBID + slotId, -1);
                int storedSubId = sp.getInt(CURR_SUBID + phoneId, -1);

                if (storedSubId != subId) {
                    int networkType = Settings.Global.getInt(
                            PhoneFactory.getPhone(slotId).getContext().getContentResolver(),
                            PhoneFactory.getPhone(phoneId).getContext().getContentResolver(),
                            Settings.Global.PREFERRED_NETWORK_MODE + subId,
                            -1 /* invalid network mode */);

@@ -527,28 +526,28 @@ public class SubscriptionInfoUpdater extends Handler {
                        try {
                            networkType = TelephonyManager.getIntAtIndex(
                                    sContext.getContentResolver(),
                                    Settings.Global.PREFERRED_NETWORK_MODE, slotId);
                                    Settings.Global.PREFERRED_NETWORK_MODE, phoneId);
                        } catch (SettingNotFoundException retrySnfe) {
                            Rlog.e(LOG_TAG, "Settings Exception Reading Value At Index for "
                                    + "Settings.Global.PREFERRED_NETWORK_MODE");
                        }
                        Settings.Global.putInt(
                                PhoneFactory.getPhone(slotId).getContext().getContentResolver(),
                                PhoneFactory.getPhone(phoneId).getContext().getContentResolver(),
                                Global.PREFERRED_NETWORK_MODE + subId,
                                networkType);
                    }

                    // Set the modem network mode
                    PhoneFactory.getPhone(slotId).setPreferredNetworkType(networkType, null);
                    PhoneFactory.getPhone(phoneId).setPreferredNetworkType(networkType, null);

                    // Only support automatic selection mode on SIM change.
                    PhoneFactory.getPhone(slotId).getNetworkSelectionMode(
                    PhoneFactory.getPhone(phoneId).getNetworkSelectionMode(
                            obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE,
                                    new Integer(slotId)));
                                    new Integer(phoneId)));

                    // Update stored subId
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putInt(CURR_SUBID + slotId, subId);
                    editor.putInt(CURR_SUBID + phoneId, subId);
                    editor.apply();
                }
            }
@@ -567,80 +566,80 @@ public class SubscriptionInfoUpdater extends Handler {
         *  3. ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED
         *  4. ACTION_CARRIER_CONFIG_CHANGED
         */
        broadcastSimStateChanged(loadedSlotId, IccCardConstants.INTENT_VALUE_ICC_LOADED, null);
        broadcastSimCardStateChanged(loadedSlotId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(loadedSlotId, TelephonyManager.SIM_STATE_LOADED);
        updateSubscriptionCarrierId(loadedSlotId, IccCardConstants.INTENT_VALUE_ICC_LOADED);
        updateCarrierServices(loadedSlotId, IccCardConstants.INTENT_VALUE_ICC_LOADED);
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_LOADED, null);
        broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_LOADED);
        updateSubscriptionCarrierId(phoneId, IccCardConstants.INTENT_VALUE_ICC_LOADED);
        updateCarrierServices(phoneId, IccCardConstants.INTENT_VALUE_ICC_LOADED);
    }

    private void updateCarrierServices(int slotId, String simState) {
    private void updateCarrierServices(int phoneId, String simState) {
        CarrierConfigManager configManager =
                (CarrierConfigManager) sContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        configManager.updateConfigForPhoneId(slotId, simState);
        mCarrierServiceBindHelper.updateForPhoneId(slotId, simState);
        configManager.updateConfigForPhoneId(phoneId, simState);
        mCarrierServiceBindHelper.updateForPhoneId(phoneId, simState);
    }

    private void updateSubscriptionCarrierId(int slotId, String simState) {
        if (PhoneFactory.getPhone(slotId) != null) {
            PhoneFactory.getPhone(slotId).resolveSubscriptionCarrierId(simState);
    private void updateSubscriptionCarrierId(int phoneId, String simState) {
        if (PhoneFactory.getPhone(phoneId) != null) {
            PhoneFactory.getPhone(phoneId).resolveSubscriptionCarrierId(simState);
        }
    }

    private void handleSimAbsent(int slotId, int absentAndInactive) {
        if (sIccId[slotId] != null && !sIccId[slotId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (slotId + 1) + " hot plug out, absentAndInactive=" + absentAndInactive);
    private void handleSimAbsent(int phoneId, int absentAndInactive) {
        if (sIccId[phoneId] != null && !sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (phoneId + 1) + " hot plug out, absentAndInactive=" + absentAndInactive);
        }
        sIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
        updateSubscriptionInfoByIccId(slotId, true /* updateEmbeddedSubs */);
        // Do not broadcast if the SIM is absent and inactive, because the logical slotId here is
        sIccId[phoneId] = ICCID_STRING_FOR_NO_SIM;
        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
        // Do not broadcast if the SIM is absent and inactive, because the logical phoneId here is
        // no longer correct
        if (absentAndInactive == 0) {
            broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_ABSENT, null);
            broadcastSimCardStateChanged(slotId, TelephonyManager.SIM_STATE_ABSENT);
            broadcastSimApplicationStateChanged(slotId, TelephonyManager.SIM_STATE_UNKNOWN);
            updateSubscriptionCarrierId(slotId, IccCardConstants.INTENT_VALUE_ICC_ABSENT);
            updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_ABSENT);
            broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_ABSENT, null);
            broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_ABSENT);
            broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_UNKNOWN);
            updateSubscriptionCarrierId(phoneId, IccCardConstants.INTENT_VALUE_ICC_ABSENT);
            updateCarrierServices(phoneId, IccCardConstants.INTENT_VALUE_ICC_ABSENT);
        }
    }

    private void handleSimError(int slotId) {
        if (sIccId[slotId] != null && !sIccId[slotId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (slotId + 1) + " Error ");
    private void handleSimError(int phoneId) {
        if (sIccId[phoneId] != null && !sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (phoneId + 1) + " Error ");
        }
        sIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
        updateSubscriptionInfoByIccId(slotId, true /* updateEmbeddedSubs */);
        broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR,
        sIccId[phoneId] = ICCID_STRING_FOR_NO_SIM;
        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR,
                IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
        broadcastSimCardStateChanged(slotId, TelephonyManager.SIM_STATE_CARD_IO_ERROR);
        broadcastSimApplicationStateChanged(slotId, TelephonyManager.SIM_STATE_NOT_READY);
        updateSubscriptionCarrierId(slotId, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
        updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
        broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_CARD_IO_ERROR);
        broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_NOT_READY);
        updateSubscriptionCarrierId(phoneId, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
        updateCarrierServices(phoneId, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
    }

    private synchronized void updateSubscriptionInfoByIccId(int slotIndex,
    private synchronized void updateSubscriptionInfoByIccId(int phoneId,
            boolean updateEmbeddedSubs) {
        logd("updateSubscriptionInfoByIccId:+ Start");
        if (!SubscriptionManager.isValidSlotIndex(slotIndex)) {
            loge("[updateSubscriptionInfoByIccId]- invalid slotIndex=" + slotIndex);
        logd("updateSubscriptionInfoByIccId:+ Start - phoneId: " + phoneId);
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
            loge("[updateSubscriptionInfoByIccId]- invalid phoneId=" + phoneId);
            return;
        }
        logd("updateSubscriptionInfoByIccId: removing subscription info record: slotIndex "
                + slotIndex);
        // Clear slotIndex only when sim absent is not enough. It's possible to switch SIM profile
        logd("updateSubscriptionInfoByIccId: removing subscription info record: phoneId "
                + phoneId);
        // 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(slotIndex);
        SubscriptionController.getInstance().clearSubInfoRecord(phoneId);

        // If SIM is not absent, insert new record or update existing record.
        if (!ICCID_STRING_FOR_NO_SIM.equals(sIccId[slotIndex])) {
        if (!ICCID_STRING_FOR_NO_SIM.equals(sIccId[phoneId])) {
            logd("updateSubscriptionInfoByIccId: adding subscription info record: iccid: "
                    + sIccId[slotIndex] + "slot: " + slotIndex);
            mSubscriptionManager.addSubscriptionInfoRecord(sIccId[slotIndex], slotIndex);
                    + sIccId[phoneId] + ", phoneId:" + phoneId);
            mSubscriptionManager.addSubscriptionInfoRecord(sIccId[phoneId], phoneId);
        }

        List<SubscriptionInfo> subInfos = SubscriptionController.getInstance()
                .getSubInfoUsingSlotIndexPrivileged(slotIndex);
                .getSubInfoUsingSlotIndexPrivileged(phoneId);
        if (subInfos != null) {
            boolean changed = false;
            for (int i = 0; i < subInfos.size(); i++) {
@@ -1068,7 +1067,7 @@ public class SubscriptionInfoUpdater extends Handler {
    }

    @UnsupportedAppUsage
    private void broadcastSimStateChanged(int slotId, String state, String reason) {
    private void broadcastSimStateChanged(int phoneId, String state, String reason) {
        Intent i = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        // TODO - we'd like this intent to have a single snapshot of all sim state,
        // but until then this should not use REPLACE_PENDING or we may lose
@@ -1079,10 +1078,10 @@ public class SubscriptionInfoUpdater extends Handler {
        i.putExtra(PhoneConstants.PHONE_NAME_KEY, "Phone");
        i.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE, state);
        i.putExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON, reason);
        SubscriptionManager.putPhoneIdAndSubIdExtra(i, slotId);
        SubscriptionManager.putPhoneIdAndSubIdExtra(i, phoneId);
        logd("Broadcasting intent ACTION_SIM_STATE_CHANGED " + state + " reason " + reason +
                " for phone: " + slotId);
        IntentBroadcaster.getInstance().broadcastStickyIntent(i, slotId);
                " for phone: " + phoneId);
        IntentBroadcaster.getInstance().broadcastStickyIntent(i, phoneId);
    }

    private void broadcastSimCardStateChanged(int phoneId, int state) {