Search in sources :

Example 1 with EuiccManager

use of android.telephony.euicc.EuiccManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MobileNetworkUtils method showEuiccSettings.

/**
 * Whether to show the entry point to eUICC settings.
 *
 * <p>We show the entry point on any device which supports eUICC as long as either the eUICC
 * was ever provisioned (that is, at least one profile was ever downloaded onto it), or if
 * the user has enabled development mode.
 */
public static boolean showEuiccSettings(Context context) {
    EuiccManager euiccManager = (EuiccManager) context.getSystemService(EuiccManager.class);
    if (!euiccManager.isEnabled()) {
        return false;
    }
    final ContentResolver cr = context.getContentResolver();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(TelephonyManager.class);
    String currentCountry = tm.getNetworkCountryIso().toLowerCase();
    String supportedCountries = Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
    final String unsupportedCountries = Settings.Global.getString(cr, Settings.Global.EUICC_UNSUPPORTED_COUNTRIES);
    boolean inEsimSupportedCountries = false;
    if (TextUtils.isEmpty(supportedCountries)) {
        // White list is empty, use blacklist.
        Log.d(TAG, "Using blacklist unsupportedCountries=" + unsupportedCountries);
        inEsimSupportedCountries = !isEsimUnsupportedCountry(currentCountry, unsupportedCountries);
    } else {
        Log.d(TAG, "Using whitelist supportedCountries=" + supportedCountries);
        inEsimSupportedCountries = isEsimSupportedCountry(currentCountry, supportedCountries);
    }
    Log.d(TAG, "inEsimSupportedCountries=" + inEsimSupportedCountries);
    final boolean esimIgnoredDevice = Arrays.asList(TextUtils.split(SystemProperties.get(KEY_ESIM_CID_IGNORE, ""), ",")).contains(SystemProperties.get(KEY_CID, null));
    final boolean enabledEsimUiByDefault = SystemProperties.getBoolean(KEY_ENABLE_ESIM_UI_BY_DEFAULT, true);
    final boolean euiccProvisioned = Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
    final boolean inDeveloperMode = Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
    return (inDeveloperMode || euiccProvisioned || (!esimIgnoredDevice && enabledEsimUiByDefault && inEsimSupportedCountries));
}
Also used : TelephonyManager(android.telephony.TelephonyManager) EuiccManager(android.telephony.euicc.EuiccManager) ContentResolver(android.content.ContentResolver)

Example 2 with EuiccManager

use of android.telephony.euicc.EuiccManager in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionController method getAccessibleSubscriptionInfoList.

@Override
public List<SubscriptionInfo> getAccessibleSubscriptionInfoList(String callingPackage) {
    EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
    if (!euiccManager.isEnabled()) {
        if (DBG) {
            logdl("[getAccessibleSubInfoList] Embedded subscriptions are disabled");
        }
        return null;
    }
    // Verify that the given package belongs to the calling UID.
    mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
    // Perform the operation as ourselves. If the caller cannot read phone state, they may still
    // have carrier privileges per the subscription metadata, so we always need to make the
    // query and then filter the results.
    final long identity = Binder.clearCallingIdentity();
    List<SubscriptionInfo> subList;
    try {
        subList = getSubInfo(SubscriptionManager.IS_EMBEDDED + "=1", null);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    if (subList == null) {
        if (DBG)
            logdl("[getAccessibleSubInfoList] No info returned");
        return null;
    }
    // Filter the list to only include subscriptions which the (restored) caller can manage.
    List<SubscriptionInfo> filteredList = subList.stream().filter(subscriptionInfo -> subscriptionInfo.canManageSubscription(mContext, callingPackage)).sorted(SUBSCRIPTION_INFO_COMPARATOR).collect(Collectors.toList());
    if (VDBG) {
        logdl("[getAccessibleSubInfoList] " + filteredList.size() + " infos returned");
    }
    return filteredList;
}
Also used : EuiccManager(android.telephony.euicc.EuiccManager) SubscriptionInfo(android.telephony.SubscriptionInfo) DataEnabledOverride(com.android.internal.telephony.dataconnection.DataEnabledOverride)

Example 3 with EuiccManager

use of android.telephony.euicc.EuiccManager in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionController method setDisplayNameUsingSrc.

/**
 * Set display name by simInfo index with name source
 * @param displayName the display name of SIM card
 * @param subId the unique SubInfoRecord index in database
 * @param nameSource SIM display name source
 * @return the number of records updated
 */
@Override
public int setDisplayNameUsingSrc(String displayName, int subId, @SimDisplayNameSource int nameSource) {
    if (DBG) {
        logd("[setDisplayName]+  displayName:" + displayName + " subId:" + subId + " nameSource:" + nameSource);
    }
    enforceModifyPhoneState("setDisplayNameUsingSrc");
    // Now that all security checks passes, perform the operation as ourselves.
    final long identity = Binder.clearCallingIdentity();
    try {
        validateSubId(subId);
        List<SubscriptionInfo> allSubInfo = getSubInfo(null, null);
        // if there is no sub in the db, return 0 since subId does not exist in db
        if (allSubInfo == null || allSubInfo.isEmpty())
            return 0;
        for (SubscriptionInfo subInfo : allSubInfo) {
            int subInfoNameSource = subInfo.getNameSource();
            boolean isHigherPriority = (getNameSourcePriority(subInfoNameSource) > getNameSourcePriority(nameSource));
            boolean isEqualPriorityAndName = (getNameSourcePriority(subInfoNameSource) == getNameSourcePriority(nameSource)) && (TextUtils.equals(displayName, subInfo.getDisplayName()));
            if (subInfo.getSubscriptionId() == subId && isExistingNameSourceStillValid(subInfo) && (isHigherPriority || isEqualPriorityAndName)) {
                logd("Name source " + subInfoNameSource + "'s priority " + getNameSourcePriority(subInfoNameSource) + " is greater than " + "name source " + nameSource + "'s priority " + getNameSourcePriority(nameSource) + ", return now.");
                return 0;
            }
        }
        String nameToSet;
        if (TextUtils.isEmpty(displayName) || displayName.trim().length() == 0) {
            nameToSet = mTelephonyManager.getSimOperatorName(subId);
            if (TextUtils.isEmpty(nameToSet)) {
                if (nameSource == SubscriptionManager.NAME_SOURCE_USER_INPUT && SubscriptionManager.isValidSlotIndex(getSlotIndex(subId))) {
                    nameToSet = "CARD " + (getSlotIndex(subId) + 1);
                } else {
                    nameToSet = mContext.getString(SubscriptionManager.DEFAULT_NAME_RES);
                }
            }
        } else {
            nameToSet = displayName;
        }
        ContentValues value = new ContentValues(1);
        value.put(SubscriptionManager.DISPLAY_NAME, nameToSet);
        if (nameSource >= SubscriptionManager.NAME_SOURCE_CARRIER_ID) {
            if (DBG)
                logd("Set nameSource=" + nameSource);
            value.put(SubscriptionManager.NAME_SOURCE, nameSource);
        }
        if (DBG)
            logd("[setDisplayName]- mDisplayName:" + nameToSet + " set");
        // Update the nickname on the eUICC chip if it's an embedded subscription.
        SubscriptionInfo sub = getSubscriptionInfo(subId);
        if (sub != null && sub.isEmbedded()) {
            // Ignore the result.
            int cardId = sub.getCardId();
            if (DBG)
                logd("Updating embedded sub nickname on cardId: " + cardId);
            EuiccManager euiccManager = ((EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE)).createForCardId(cardId);
            euiccManager.updateSubscriptionNickname(subId, displayName, // specified on the intent).
            PendingIntent.getService(mContext, 0, /* requestCode */
            new Intent(), 0));
        }
        int result = updateDatabase(value, subId, true);
        // Refresh the Cache of Active Subscription Info List
        refreshCachedActiveSubscriptionInfoList();
        notifySubscriptionInfoChanged();
        return result;
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : ContentValues(android.content.ContentValues) EuiccManager(android.telephony.euicc.EuiccManager) SubscriptionInfo(android.telephony.SubscriptionInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) DataEnabledOverride(com.android.internal.telephony.dataconnection.DataEnabledOverride)

Example 4 with EuiccManager

use of android.telephony.euicc.EuiccManager in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionController method getAvailableSubscriptionInfoList.

@Override
public List<SubscriptionInfo> getAvailableSubscriptionInfoList(String callingPackage, String callingFeatureId) {
    try {
        enforceReadPrivilegedPhoneState("getAvailableSubscriptionInfoList");
    } catch (SecurityException e) {
        try {
            mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE, null);
            // If caller doesn't have READ_PRIVILEGED_PHONE_STATE permission but only
            // has READ_PHONE_STATE permission, log this event.
            EventLog.writeEvent(0x534e4554, "185235454", Binder.getCallingUid());
        } catch (SecurityException ex) {
        // Ignore
        }
        throw new SecurityException("Need READ_PRIVILEGED_PHONE_STATE to call " + " getAvailableSubscriptionInfoList");
    }
    // Now that all security checks pass, perform the operation as ourselves.
    final long identity = Binder.clearCallingIdentity();
    try {
        String selection = SubscriptionManager.SIM_SLOT_INDEX + ">=0 OR " + SubscriptionManager.SUBSCRIPTION_TYPE + "=" + SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM;
        EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
        if (euiccManager.isEnabled()) {
            selection += " OR " + SubscriptionManager.IS_EMBEDDED + "=1";
        }
        // Available eSIM profiles are reported by EuiccManager. However for physical SIMs if
        // they are in inactive slot or programmatically disabled, they are still considered
        // available. In this case we get their iccid from slot info and include their
        // subscriptionInfos.
        List<String> iccIds = getIccIdsOfInsertedPhysicalSims();
        if (!iccIds.isEmpty()) {
            selection += " OR (" + getSelectionForIccIdList(iccIds.toArray(new String[0])) + ")";
        }
        List<SubscriptionInfo> subList = getSubInfo(selection, null);
        if (subList != null) {
            subList.sort(SUBSCRIPTION_INFO_COMPARATOR);
            if (VDBG)
                logdl("[getAvailableSubInfoList]- " + subList.size() + " infos return");
        } else {
            if (DBG)
                logdl("[getAvailableSubInfoList]- no info return");
        }
        return subList;
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : EuiccManager(android.telephony.euicc.EuiccManager) SubscriptionInfo(android.telephony.SubscriptionInfo) DataEnabledOverride(com.android.internal.telephony.dataconnection.DataEnabledOverride)

Example 5 with EuiccManager

use of android.telephony.euicc.EuiccManager in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionController method enablePhysicalSubscription.

private boolean enablePhysicalSubscription(SubscriptionInfo info, boolean enable) {
    if (info == null || !SubscriptionManager.isValidSubscriptionId(info.getSubscriptionId())) {
        return false;
    }
    int subId = info.getSubscriptionId();
    UiccSlotInfo slotInfo = null;
    int physicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
    UiccSlotInfo[] slotsInfo = mTelephonyManager.getUiccSlotsInfo();
    if (slotsInfo == null)
        return false;
    for (int i = 0; i < slotsInfo.length; i++) {
        UiccSlotInfo curSlotInfo = slotsInfo[i];
        if (curSlotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT) {
            if (TextUtils.equals(IccUtils.stripTrailingFs(curSlotInfo.getCardId()), IccUtils.stripTrailingFs(info.getCardString()))) {
                slotInfo = curSlotInfo;
                physicalSlotIndex = i;
                break;
            }
        }
    }
    // Can't find the existing SIM.
    if (slotInfo == null)
        return false;
    if (enable && !slotInfo.getIsActive()) {
        // We need to send intents to Euicc if we are turning on an inactive slot.
        // Euicc will decide whether to ask user to switch to DSDS, or change SIM
        // slot mapping.
        EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
        if (euiccManager != null && euiccManager.isEnabled()) {
            enableSubscriptionOverEuiccManager(subId, enable, physicalSlotIndex);
        } else {
            // Enable / disable uicc applications.
            if (!info.areUiccApplicationsEnabled())
                setUiccApplicationsEnabled(enable, subId);
            // or switch slot if not.
            if (mTelephonyManager.isMultiSimSupported() == MULTISIM_ALLOWED) {
                PhoneConfigurationManager.getInstance().switchMultiSimConfig(mTelephonyManager.getSupportedModemCount());
            } else {
                UiccController.getInstance().switchSlots(new int[] { physicalSlotIndex }, null);
            }
        }
        return true;
    } else {
        // Enable / disable uicc applications.
        setUiccApplicationsEnabled(enable, subId);
        return true;
    }
}
Also used : EuiccManager(android.telephony.euicc.EuiccManager) UiccSlotInfo(android.telephony.UiccSlotInfo)

Aggregations

EuiccManager (android.telephony.euicc.EuiccManager)11 ContentResolver (android.content.ContentResolver)4 SubscriptionInfo (android.telephony.SubscriptionInfo)3 DataEnabledOverride (com.android.internal.telephony.dataconnection.DataEnabledOverride)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 TelephonyManager (android.telephony.TelephonyManager)2 ContentValues (android.content.ContentValues)1 UiccSlotInfo (android.telephony.UiccSlotInfo)1 Test (org.junit.Test)1 Config (org.robolectric.annotation.Config)1