Search in sources :

Example 1 with UiccController

use of com.android.internal.telephony.uicc.UiccController in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionInfoUpdater method updateEmbeddedSubscriptionsCache.

/**
 * Update the cached list of embedded subscription based on the passed in
 * GetEuiccProfileInfoListResult {@code result}.
 *
 * @return true if changes may have been made. This is not a guarantee that changes were made,
 * but notifications about subscription changes may be skipped if this returns false as an
 * optimization to avoid spurious notifications.
 */
private boolean updateEmbeddedSubscriptionsCache(int cardId, GetEuiccProfileInfoListResult result) {
    if (DBG)
        logd("updateEmbeddedSubscriptionsCache");
    if (result == null) {
        // IPC to the eUICC controller failed.
        return false;
    }
    // If the returned result is not RESULT_OK or the profile list is null, don't update cache.
    // Otherwise, update the cache.
    final EuiccProfileInfo[] embeddedProfiles;
    List<EuiccProfileInfo> list = result.getProfiles();
    if (result.getResult() == EuiccService.RESULT_OK && list != null) {
        embeddedProfiles = list.toArray(new EuiccProfileInfo[list.size()]);
        if (DBG) {
            logd("blockingGetEuiccProfileInfoList: got " + result.getProfiles().size() + " profiles");
        }
    } else {
        if (DBG) {
            logd("blockingGetEuiccProfileInfoList returns an error. " + "Result code=" + result.getResult() + ". Null profile list=" + (result.getProfiles() == null));
        }
        return false;
    }
    final boolean isRemovable = result.getIsRemovable();
    final String[] embeddedIccids = new String[embeddedProfiles.length];
    for (int i = 0; i < embeddedProfiles.length; i++) {
        embeddedIccids[i] = embeddedProfiles[i].getIccid();
    }
    if (DBG)
        logd("Get eUICC profile list of size " + embeddedProfiles.length);
    // Note that this only tracks whether we make any writes to the DB. It's possible this will
    // be set to true for an update even when the row contents remain exactly unchanged from
    // before, since we don't compare against the previous value. Since this is only intended to
    // avoid some spurious broadcasts (particularly for users who don't use eSIM at all), this
    // is fine.
    boolean hasChanges = false;
    // 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);
    ContentResolver contentResolver = sContext.getContentResolver();
    for (EuiccProfileInfo embeddedProfile : embeddedProfiles) {
        int index = findSubscriptionInfoForIccid(existingSubscriptions, embeddedProfile.getIccid());
        int prevCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
        int nameSource = SubscriptionManager.NAME_SOURCE_CARRIER_ID;
        if (index < 0) {
            // No existing entry for this ICCID; create an empty one.
            SubscriptionController.getInstance().insertEmptySubInfoRecord(embeddedProfile.getIccid(), SubscriptionManager.SIM_NOT_INSERTED);
        } else {
            nameSource = existingSubscriptions.get(index).getNameSource();
            prevCarrierId = existingSubscriptions.get(index).getCarrierId();
            existingSubscriptions.remove(index);
        }
        if (DBG) {
            logd("embeddedProfile " + embeddedProfile + " existing record " + (index < 0 ? "not found" : "found"));
        }
        ContentValues values = new ContentValues();
        values.put(SubscriptionManager.IS_EMBEDDED, 1);
        List<UiccAccessRule> ruleList = embeddedProfile.getUiccAccessRules();
        boolean isRuleListEmpty = false;
        if (ruleList == null || ruleList.size() == 0) {
            isRuleListEmpty = true;
        }
        values.put(SubscriptionManager.ACCESS_RULES, isRuleListEmpty ? null : UiccAccessRule.encodeRules(ruleList.toArray(new UiccAccessRule[ruleList.size()])));
        values.put(SubscriptionManager.IS_REMOVABLE, isRemovable);
        // override DISPLAY_NAME if the priority of existing nameSource is <= carrier
        if (SubscriptionController.getNameSourcePriority(nameSource) <= SubscriptionController.getNameSourcePriority(SubscriptionManager.NAME_SOURCE_CARRIER)) {
            values.put(SubscriptionManager.DISPLAY_NAME, embeddedProfile.getNickname());
            values.put(SubscriptionManager.NAME_SOURCE, SubscriptionManager.NAME_SOURCE_CARRIER);
        }
        values.put(SubscriptionManager.PROFILE_CLASS, embeddedProfile.getProfileClass());
        CarrierIdentifier cid = embeddedProfile.getCarrierIdentifier();
        if (cid != null) {
            // is no valid carrier id present.
            if (prevCarrierId == TelephonyManager.UNKNOWN_CARRIER_ID) {
                values.put(SubscriptionManager.CARRIER_ID, CarrierResolver.getCarrierIdFromIdentifier(sContext, cid));
            }
            String mcc = cid.getMcc();
            String mnc = cid.getMnc();
            values.put(SubscriptionManager.MCC_STRING, mcc);
            values.put(SubscriptionManager.MCC, mcc);
            values.put(SubscriptionManager.MNC_STRING, mnc);
            values.put(SubscriptionManager.MNC, mnc);
        }
        // If cardId = unsupported or unitialized, we have no reason to update DB.
        // Additionally, if the device does not support cardId for default eUICC, the CARD_ID
        // field should not contain the EID
        UiccController uiccController = UiccController.getInstance();
        if (cardId >= 0 && uiccController.getCardIdForDefaultEuicc() != TelephonyManager.UNSUPPORTED_CARD_ID) {
            values.put(SubscriptionManager.CARD_ID, uiccController.convertToCardString(cardId));
        }
        hasChanges = true;
        contentResolver.update(SubscriptionManager.CONTENT_URI, values, SubscriptionManager.ICC_ID + "=\"" + embeddedProfile.getIccid() + "\"", null);
        // refresh Cached Active Subscription Info List
        SubscriptionController.getInstance().refreshCachedActiveSubscriptionInfoList();
    }
    // SIM being removed and reinserted).
    if (!existingSubscriptions.isEmpty()) {
        if (DBG) {
            logd("Removing existing embedded subscriptions of size" + existingSubscriptions.size());
        }
        List<String> iccidsToRemove = new ArrayList<>();
        for (int i = 0; i < existingSubscriptions.size(); i++) {
            SubscriptionInfo info = existingSubscriptions.get(i);
            if (info.isEmbedded()) {
                if (DBG)
                    logd("Removing embedded subscription of IccId " + info.getIccId());
                iccidsToRemove.add("\"" + info.getIccId() + "\"");
            }
        }
        String whereClause = SubscriptionManager.ICC_ID + " IN (" + TextUtils.join(",", iccidsToRemove) + ")";
        ContentValues values = new ContentValues();
        values.put(SubscriptionManager.IS_EMBEDDED, 0);
        hasChanges = true;
        contentResolver.update(SubscriptionManager.CONTENT_URI, values, whereClause, null);
        // refresh Cached Active Subscription Info List
        SubscriptionController.getInstance().refreshCachedActiveSubscriptionInfoList();
    }
    if (DBG)
        logd("updateEmbeddedSubscriptions done hasChanges=" + hasChanges);
    return hasChanges;
}
Also used : ContentValues(android.content.ContentValues) UiccController(com.android.internal.telephony.uicc.UiccController) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) ContentResolver(android.content.ContentResolver) UiccAccessRule(android.telephony.UiccAccessRule) EuiccProfileInfo(android.service.euicc.EuiccProfileInfo) CarrierIdentifier(android.service.carrier.CarrierIdentifier)

Example 2 with UiccController

use of com.android.internal.telephony.uicc.UiccController in project android_frameworks_opt_telephony by LineageOS.

the class SimSlotState method getCurrentState.

/**
 * Returns the current SIM state.
 */
public static SimSlotState getCurrentState() {
    int numActiveSlots = 0;
    int numActiveSims = 0;
    int numActiveEsims = 0;
    UiccController uiccController = UiccController.getInstance();
    // since we cannot hold lock insider UiccController, using getUiccSlots() for length only
    for (int i = 0; i < uiccController.getUiccSlots().length; i++) {
        UiccSlot slot = uiccController.getUiccSlot(i);
        if (slot != null && slot.isActive()) {
            numActiveSlots++;
            // avoid CardState.isCardPresent() since this should not include restricted cards
            if (slot.getCardState() == CardState.CARDSTATE_PRESENT) {
                if (slot.isEuicc()) {
                    // need to check active profiles besides the presence of eSIM cards
                    UiccCard card = slot.getUiccCard();
                    if (card != null && card.getNumApplications() > 0) {
                        numActiveSims++;
                        numActiveEsims++;
                    }
                } else {
                    // physical SIMs do not always have non-null card
                    numActiveSims++;
                }
            }
        }
    }
    return new SimSlotState(numActiveSlots, numActiveSims, numActiveEsims);
}
Also used : UiccCard(com.android.internal.telephony.uicc.UiccCard) UiccController(com.android.internal.telephony.uicc.UiccController) UiccSlot(com.android.internal.telephony.uicc.UiccSlot)

Example 3 with UiccController

use of com.android.internal.telephony.uicc.UiccController in project android_frameworks_opt_telephony by LineageOS.

the class EuiccCardController method getEuiccCard.

private EuiccCard getEuiccCard(String cardId) {
    UiccController controller = UiccController.getInstance();
    int slotId = controller.getUiccSlotForCardId(cardId);
    if (slotId != UiccController.INVALID_SLOT_ID) {
        UiccSlot slot = controller.getUiccSlot(slotId);
        if (slot.isEuicc()) {
            return (EuiccCard) controller.getUiccCardForSlot(slotId);
        }
    }
    loge("EuiccCard is null. CardId : " + cardId);
    return null;
}
Also used : UiccController(com.android.internal.telephony.uicc.UiccController) EuiccCard(com.android.internal.telephony.uicc.euicc.EuiccCard) UiccSlot(com.android.internal.telephony.uicc.UiccSlot)

Example 4 with UiccController

use of com.android.internal.telephony.uicc.UiccController in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionInfoUpdater method updateSubscriptionInfoByIccId.

protected synchronized void updateSubscriptionInfoByIccId(int phoneId, boolean updateEmbeddedSubs) {
    logd("updateSubscriptionInfoByIccId:+ Start - phoneId: " + phoneId);
    if (!SubscriptionManager.isValidPhoneId(phoneId)) {
        loge("[updateSubscriptionInfoByIccId]- invalid phoneId=" + phoneId);
        return;
    }
    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(phoneId);
    // If SIM is not absent, insert new record or update existing record.
    if (!ICCID_STRING_FOR_NO_SIM.equals(sIccId[phoneId])) {
        logd("updateSubscriptionInfoByIccId: adding subscription info record: iccid: " + sIccId[phoneId] + ", phoneId:" + phoneId);
        mSubscriptionManager.addSubscriptionInfoRecord(sIccId[phoneId], phoneId);
    }
    List<SubscriptionInfo> subInfos = SubscriptionController.getInstance().getSubInfoUsingSlotIndexPrivileged(phoneId);
    if (subInfos != null) {
        boolean changed = false;
        for (int i = 0; i < subInfos.size(); i++) {
            SubscriptionInfo temp = subInfos.get(i);
            ContentValues value = new ContentValues(1);
            String msisdn = TelephonyManager.getDefault().getLine1Number(temp.getSubscriptionId());
            if (!TextUtils.equals(msisdn, temp.getNumber())) {
                value.put(SubscriptionManager.NUMBER, msisdn);
                sContext.getContentResolver().update(SubscriptionManager.getUriForSubscriptionId(temp.getSubscriptionId()), value, null, null);
                changed = true;
            }
        }
        if (changed) {
            // refresh Cached Active Subscription Info List
            SubscriptionController.getInstance().refreshCachedActiveSubscriptionInfoList();
        }
    }
    // TODO investigate if we can update for each slot separately.
    if (isAllIccIdQueryDone()) {
        // Ensure the modems are mapped correctly
        if (mSubscriptionManager.isActiveSubId(mSubscriptionManager.getDefaultDataSubscriptionId())) {
            mSubscriptionManager.setDefaultDataSubId(mSubscriptionManager.getDefaultDataSubscriptionId());
        } else {
            logd("bypass reset default data sub if inactive");
        }
        setSubInfoInitialized();
    }
    UiccController uiccController = UiccController.getInstance();
    UiccSlot[] uiccSlots = uiccController.getUiccSlots();
    if (uiccSlots != null && updateEmbeddedSubs) {
        List<Integer> cardIds = new ArrayList<>();
        for (UiccSlot uiccSlot : uiccSlots) {
            if (uiccSlot != null && uiccSlot.getUiccCard() != null) {
                int cardId = uiccController.convertToPublicCardId(uiccSlot.getUiccCard().getCardId());
                cardIds.add(cardId);
            }
        }
        updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
            if (hasChanges) {
                SubscriptionController.getInstance().notifySubscriptionInfoChanged();
            }
            if (DBG)
                logd("updateSubscriptionInfoByIccId: SubscriptionInfo update complete");
        });
    }
    SubscriptionController.getInstance().notifySubscriptionInfoChanged();
    if (DBG)
        logd("updateSubscriptionInfoByIccId: SubscriptionInfo update complete");
}
Also used : ContentValues(android.content.ContentValues) UiccController(com.android.internal.telephony.uicc.UiccController) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) UiccSlot(com.android.internal.telephony.uicc.UiccSlot)

Example 5 with UiccController

use of com.android.internal.telephony.uicc.UiccController in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionInfoUpdater method getCardIdFromPhoneId.

protected int getCardIdFromPhoneId(int phoneId) {
    UiccController uiccController = UiccController.getInstance();
    UiccCard card = uiccController.getUiccCardForPhone(phoneId);
    if (card != null) {
        return uiccController.convertToPublicCardId(card.getCardId());
    }
    return TelephonyManager.UNINITIALIZED_CARD_ID;
}
Also used : UiccCard(com.android.internal.telephony.uicc.UiccCard) UiccController(com.android.internal.telephony.uicc.UiccController)

Aggregations

UiccController (com.android.internal.telephony.uicc.UiccController)5 UiccSlot (com.android.internal.telephony.uicc.UiccSlot)3 ContentValues (android.content.ContentValues)2 SubscriptionInfo (android.telephony.SubscriptionInfo)2 UiccCard (com.android.internal.telephony.uicc.UiccCard)2 ArrayList (java.util.ArrayList)2 ContentResolver (android.content.ContentResolver)1 CarrierIdentifier (android.service.carrier.CarrierIdentifier)1 EuiccProfileInfo (android.service.euicc.EuiccProfileInfo)1 UiccAccessRule (android.telephony.UiccAccessRule)1 EuiccCard (com.android.internal.telephony.uicc.euicc.EuiccCard)1