Search in sources :

Example 31 with SettingNotFoundException

use of android.provider.Settings.SettingNotFoundException in project android_frameworks_opt_telephony by LineageOS.

the class SubscriptionInfoUpdater method handleSimLoaded.

protected 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.
    IccCard iccCard = PhoneFactory.getPhone(phoneId).getIccCard();
    if (iccCard == null) {
        // Possibly a race condition.
        logd("handleSimLoaded: IccCard null");
        return;
    }
    IccRecords records = iccCard.getIccRecords();
    if (records == null) {
        // Possibly a race condition.
        logd("handleSimLoaded: IccRecords null");
        return;
    }
    if (IccUtils.stripTrailingFs(records.getFullIccId()) == null) {
        logd("handleSimLoaded: IccID null");
        return;
    }
    sIccId[phoneId] = IccUtils.stripTrailingFs(records.getFullIccId());
    updateSubscriptionInfoByIccId(phoneId, true);
    List<SubscriptionInfo> subscriptionInfos = SubscriptionController.getInstance().getSubInfoUsingSlotIndexPrivileged(phoneId);
    if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
        loge("empty subinfo for phoneId: " + phoneId + "could not update ContentResolver");
    } else {
        for (SubscriptionInfo sub : subscriptionInfos) {
            int subId = sub.getSubscriptionId();
            TelephonyManager tm = (TelephonyManager) sContext.getSystemService(Context.TELEPHONY_SERVICE);
            String operator = tm.getSimOperatorNumeric(subId);
            if (!TextUtils.isEmpty(operator)) {
                if (subId == SubscriptionController.getInstance().getDefaultSubId()) {
                    MccTable.updateMccMncConfiguration(sContext, operator);
                }
                SubscriptionController.getInstance().setMccMnc(operator, subId);
            } else {
                logd("EVENT_RECORDS_LOADED Operator name is null");
            }
            String iso = tm.getSimCountryIsoForPhone(phoneId);
            if (!TextUtils.isEmpty(iso)) {
                SubscriptionController.getInstance().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);
            }
            String imsi = tm.createForSubscriptionId(subId).getSubscriberId();
            if (imsi != null) {
                SubscriptionController.getInstance().setImsi(imsi, subId);
            }
            String[] ehplmns = records.getEhplmns();
            String[] hplmns = records.getPlmnsFromHplmnActRecord();
            if (ehplmns != null || hplmns != null) {
                SubscriptionController.getInstance().setAssociatedPlmns(ehplmns, hplmns, subId);
            }
            /* Update preferred network type and network selection mode on SIM change.
                 * Storing last subId in SharedPreference for now to detect SIM change.
                 */
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(sContext);
            int storedSubId = sp.getInt(CURR_SUBID + phoneId, -1);
            if (storedSubId != subId) {
                int networkType = Settings.Global.getInt(PhoneFactory.getPhone(phoneId).getContext().getContentResolver(), Settings.Global.PREFERRED_NETWORK_MODE + subId, -1);
                if (networkType == -1) {
                    networkType = RILConstants.PREFERRED_NETWORK_MODE;
                    try {
                        networkType = TelephonyManager.getIntAtIndex(sContext.getContentResolver(), 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(phoneId).getContext().getContentResolver(), Global.PREFERRED_NETWORK_MODE + subId, networkType);
                }
                // Set the modem network mode
                PhoneFactory.getPhone(phoneId).setPreferredNetworkType(networkType, null);
                // Only support automatic selection mode on SIM change.
                PhoneFactory.getPhone(phoneId).getNetworkSelectionMode(obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, new Integer(phoneId)));
                // Update stored subId
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt(CURR_SUBID + phoneId, subId);
                editor.apply();
            }
        }
    }
    // Update set of enabled carrier apps now that the privilege rules may have changed.
    CarrierAppUtils.disableCarrierAppsUntilPrivileged(sContext.getOpPackageName(), TelephonyManager.getDefault(), mCurrentlyActiveUserId, sContext);
    /**
     * The sim loading sequence will be
     *  1. ACTION_SUBINFO_CONTENT_CHANGE happens through updateSubscriptionInfoByIccId() above.
     *  2. ACTION_SIM_STATE_CHANGED/ACTION_SIM_CARD_STATE_CHANGED
     *  /ACTION_SIM_APPLICATION_STATE_CHANGED
     *  3. ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED
     *  4. ACTION_CARRIER_CONFIG_CHANGED
     */
    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);
}
Also used : IccRecords(com.android.internal.telephony.uicc.IccRecords) TelephonyManager(android.telephony.TelephonyManager) SharedPreferences(android.content.SharedPreferences) SubscriptionInfo(android.telephony.SubscriptionInfo) SettingNotFoundException(android.provider.Settings.SettingNotFoundException)

Aggregations

SettingNotFoundException (android.provider.Settings.SettingNotFoundException)31 ContentResolver (android.content.ContentResolver)16 RemoteException (android.os.RemoteException)7 UserInfo (android.content.pm.UserInfo)6 Vibrator (android.os.Vibrator)6 InputDevice (android.view.InputDevice)6 IOException (java.io.IOException)5 KeyStoreException (java.security.KeyStoreException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 CertificateException (java.security.cert.CertificateException)5 SharedPreferences (android.content.SharedPreferences)3 SubscriptionInfo (android.telephony.SubscriptionInfo)2 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)2 SimpleHogBug (edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)2 Context (android.content.Context)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 UserManager (android.os.UserManager)1 ListPreference (android.preference.ListPreference)1 Settings (android.provider.Settings)1 TelephonyManager (android.telephony.TelephonyManager)1