Search in sources :

Example 1 with IccRecords

use of com.android.internal.telephony.uicc.IccRecords in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ApnSettings method fillList.

private void fillList() {
    final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    final String mccmnc = mSubscriptionInfo == null ? "" : tm.getSimOperator(mSubscriptionInfo.getSubscriptionId());
    Log.d(TAG, "mccmnc = " + mccmnc);
    StringBuilder where = new StringBuilder("numeric=\"" + mccmnc + "\" AND NOT (type='ia' AND (apn=\"\" OR apn IS NULL)) AND user_visible!=0");
    if (SystemProperties.getBoolean("persist.sys.hideapn", true)) {
        Log.d(TAG, "hiden apn feature enable.");
        if (getResources().getBoolean(R.bool.config_hide_ims_apns)) {
            mHideImsApn = true;
        }
        // Filer fota and dm for specail carrier
        if (getResources().getBoolean(R.bool.config_hide_dm_enabled)) {
            for (String plmn : getResources().getStringArray(R.array.hidedm_plmn_list)) {
                if (plmn.equals(mccmnc)) {
                    where.append(" and name <>\"" + APN_NAME_DM + "\"");
                    break;
                }
            }
        }
        if (getResources().getBoolean(R.bool.config_hidesupl_enable)) {
            boolean needHideSupl = false;
            for (String plmn : getResources().getStringArray(R.array.hidesupl_plmn_list)) {
                if (plmn.equals(mccmnc)) {
                    needHideSupl = true;
                    break;
                }
            }
            if (needHideSupl) {
                where.append(" and type <>\"" + PhoneConstants.APN_TYPE_SUPL + "\"");
            }
        }
        // Hide mms if config is true
        if (getResources().getBoolean(R.bool.config_hide_mms_enable)) {
            where.append(" and type <>\"" + PhoneConstants.APN_TYPE_MMS + "\"");
        }
    }
    if (getResources().getBoolean(R.bool.config_regional_hide_ims_and_dun_apns)) {
        where.append(" AND type <>\"" + PhoneConstants.APN_TYPE_DUN + "\"");
        where.append(" AND type <>\"" + PhoneConstants.APN_TYPE_IMS + "\"");
    }
    if (mHideImsApn) {
        where.append(" AND NOT (type='ims')");
    }
    if (isOperatorIccId()) {
        where.append(" AND type <>\"" + PhoneConstants.APN_TYPE_EMERGENCY + "\"");
        where.append(" AND type <>\"" + PhoneConstants.APN_TYPE_IMS + "\"");
    }
    Log.d(TAG, "where---" + where);
    Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, new String[] { "_id", "name", "apn", "type", "mvno_type", "mvno_match_data", "read_only", "bearer", "bearer_bitmask" }, where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER);
    if (cursor != null) {
        IccRecords r = null;
        if (mUiccController != null && mSubscriptionInfo != null) {
            r = mUiccController.getIccRecords(SubscriptionManager.getPhoneId(mSubscriptionInfo.getSubscriptionId()), UiccController.APP_FAM_3GPP);
        }
        PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
        apnList.removeAll();
        ArrayList<ApnPreference> mnoApnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mvnoApnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mnoMmsApnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mvnoMmsApnList = new ArrayList<ApnPreference>();
        mSelectedKey = getSelectedApnKey();
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String name = cursor.getString(NAME_INDEX);
            String apn = cursor.getString(APN_INDEX);
            String key = cursor.getString(ID_INDEX);
            String type = cursor.getString(TYPES_INDEX);
            String mvnoType = cursor.getString(MVNO_TYPE_INDEX);
            String mvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);
            boolean readOnly = (cursor.getInt(RO_INDEX) == 1);
            String localizedName = getLocalizedName(getActivity(), cursor, NAME_INDEX);
            if (!TextUtils.isEmpty(localizedName)) {
                name = localizedName;
            }
            int bearer = cursor.getInt(BEARER_INDEX);
            int bearerBitMask = cursor.getInt(BEARER_BITMASK_INDEX);
            int fullBearer = bearer | bearerBitMask;
            int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId() : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
            int radioTech = networkTypeToRilRidioTechnology(TelephonyManager.getDefault().getDataNetworkType(subId));
            if (!ServiceState.bitmaskHasTech(fullBearer, radioTech) && (bearer != 0 || bearerBitMask != 0)) {
                // In OOS, show APN with bearer as default
                if ((radioTech != ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) || (bearer == 0 && radioTech == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN)) {
                    cursor.moveToNext();
                    continue;
                }
            }
            ApnPreference pref = new ApnPreference(getPrefContext());
            pref.setApnReadOnly(readOnly);
            pref.setKey(key);
            pref.setTitle(name);
            pref.setSummary(apn);
            pref.setPersistent(false);
            pref.setOnPreferenceChangeListener(this);
            boolean selectable = ((type == null) || !type.equals("mms"));
            pref.setSelectable(selectable);
            if (selectable) {
                if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
                    pref.setChecked();
                }
                addApnToList(pref, mnoApnList, mvnoApnList, r, mvnoType, mvnoMatchData);
            } else {
                addApnToList(pref, mnoMmsApnList, mvnoMmsApnList, r, mvnoType, mvnoMatchData);
            }
            cursor.moveToNext();
        }
        cursor.close();
        if (!mvnoApnList.isEmpty()) {
            mnoApnList = mvnoApnList;
            mnoMmsApnList = mvnoMmsApnList;
        // Also save the mvno info
        }
        for (Preference preference : mnoApnList) {
            apnList.addPreference(preference);
        }
        for (Preference preference : mnoMmsApnList) {
            apnList.addPreference(preference);
        }
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) IccRecords(com.android.internal.telephony.uicc.IccRecords) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Cursor(android.database.Cursor)

Aggregations

Cursor (android.database.Cursor)1 Preference (android.support.v7.preference.Preference)1 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1 TelephonyManager (android.telephony.TelephonyManager)1 IccRecords (com.android.internal.telephony.uicc.IccRecords)1 ArrayList (java.util.ArrayList)1