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

Commit aa4ac1e5 authored by Mattias Nilsson's avatar Mattias Nilsson Committed by Mattias Nilsson
Browse files

Do not allow editing of mcc, mnc for carrier id APNs

A user that is allowed to edit mcc, mnc or mvno data can break
the APN list. If a carrier or OEM has added an APN that is
matched with carrier id there is no need to edit those fields.

Apn Editor should not throw any error when a user backs out of
from a carrier id APN where mcc, mnc is empty.

Disable editing of these fields and check for carrier id APN
before adding error message.

Test: Add carrier APN, insert sim and back out from ApnEditor
Bug: 222103038
Change-Id: I4e86cdd3e8caaf3dbfefe9b9f82f11c2804577ff
parent cfb201c4
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ public class ApnEditor extends SettingsPreferenceFragment
    private String[] mReadOnlyApnFields;
    private boolean mReadOnlyApn;
    private Uri mCarrierUri;
    private boolean mIsCarrierIdApn;

    /**
     * APN types for data connections.  These are usage categories for an APN
@@ -227,7 +228,8 @@ public class ApnEditor extends SettingsPreferenceFragment
            Telephony.Carriers.MVNO_TYPE,   // 21
            Telephony.Carriers.MVNO_MATCH_DATA,  // 22
            Telephony.Carriers.EDITED_STATUS,   // 23
            Telephony.Carriers.USER_EDITABLE    //24
            Telephony.Carriers.USER_EDITABLE,   // 24
            Telephony.Carriers.CARRIER_ID       // 25
    };

    private static final int ID_INDEX = 0;
@@ -262,6 +264,7 @@ public class ApnEditor extends SettingsPreferenceFragment
    private static final int MVNO_MATCH_DATA_INDEX = 22;
    private static final int EDITED_INDEX = 23;
    private static final int USER_EDITABLE_INDEX = 24;
    private static final int CARRIER_ID_INDEX = 25;

    @Override
    public void onCreate(Bundle icicle) {
@@ -312,6 +315,9 @@ public class ApnEditor extends SettingsPreferenceFragment
        } else {
            mApnData = new ApnData(sProjection.length);
        }
        final int carrierId = mApnData.getInteger(CARRIER_ID_INDEX,
                TelephonyManager.UNKNOWN_CARRIER_ID);
        mIsCarrierIdApn = (carrierId > TelephonyManager.UNKNOWN_CARRIER_ID);

        final boolean isUserEdited = mApnData.getInteger(EDITED_INDEX,
                Telephony.Carriers.USER_EDITED) == Telephony.Carriers.USER_EDITED;
@@ -326,6 +332,10 @@ public class ApnEditor extends SettingsPreferenceFragment
        } else if (!ArrayUtils.isEmpty(mReadOnlyApnFields)) {
            disableFields(mReadOnlyApnFields);
        }
        // Make sure that a user cannot break carrier id APN matching
        if (mIsCarrierIdApn) {
            disableFieldsForCarrieridApn();
        }

        for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
            getPreferenceScreen().getPreference(i).setOnPreferenceChangeListener(this);
@@ -517,6 +527,16 @@ public class ApnEditor extends SettingsPreferenceFragment
        mMvnoMatchData.setEnabled(false);
    }

    /**
     * Disables fields for a carrier id APN to avoid breaking the match criteria
     */
    private void disableFieldsForCarrieridApn() {
        mMcc.setEnabled(false);
        mMnc.setEnabled(false);
        mMvnoType.setEnabled(false);
        mMvnoMatchData.setEnabled(false);
    }

    @Override
    public int getMetricsCategory() {
        return SettingsEnums.APN_EDITOR;
@@ -1150,11 +1170,15 @@ public class ApnEditor extends SettingsPreferenceFragment
        final String apn = checkNotSet(mApn.getText());
        final String mcc = checkNotSet(mMcc.getText());
        final String mnc = checkNotSet(mMnc.getText());

        boolean doNotCheckMccMnc = mIsCarrierIdApn && TextUtils.isEmpty(mcc)
                && TextUtils.isEmpty(mnc);
        if (TextUtils.isEmpty(name)) {
            errorMsg = getResources().getString(R.string.error_name_empty);
        } else if (TextUtils.isEmpty(apn)) {
            errorMsg = getResources().getString(R.string.error_apn_empty);
        } else if (doNotCheckMccMnc) {
            Log.d(TAG, "validateApnData: carrier id APN does not have mcc/mnc defined");
            // no op, skip mcc mnc null check
        } else if (mcc == null || mcc.length() != 3) {
            errorMsg = getResources().getString(R.string.error_mcc_not3);
        } else if ((mnc == null || (mnc.length() & 0xFFFE) != 2)) {