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

Commit 23c6b886 authored by Mengjun Leng's avatar Mengjun Leng Committed by Linux Build Service Account
Browse files

Settings: Add the read only APN feature.

Disable the edit screen for read only APNs

Some operators don't want their APNs to be edited by
end user to avoid mistaken changes. End user should
be able to only view the APNs, but not edit.

Change-Id: I89f26ccc687d6989c562f164dbe53961a4d8a057
CRs-Fixed: 774852
parent 8a2f809f
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class ApnEditor extends SettingsPreferenceFragment

    private String mCurMnc;
    private String mCurMcc;
    private boolean mDisableEditor = false;

    private Uri mUri;
    private Cursor mCursor;
@@ -204,6 +205,11 @@ public class ApnEditor extends SettingsPreferenceFragment
        final String action = intent.getAction();
        mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        mDisableEditor = intent.getBooleanExtra("DISABLE_EDITOR", false);
        if (mDisableEditor) {
            getPreferenceScreen().setEnabled(false);
            Log.d(TAG, "ApnEditor form is disabled.");
        }

        mFirstTime = icicle == null;

@@ -536,6 +542,10 @@ public class ApnEditor extends SettingsPreferenceFragment
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        if (mDisableEditor) {
            Log.d(TAG, "Form is disabled. Do not create the options menu.");
            return;
        }
        // If it's a new APN, then cancel will delete the new entry in onPause
        if (!mNewApn) {
            menu.add(0, MENU_DELETE, 0, R.string.menu_delete)
@@ -602,6 +612,13 @@ public class ApnEditor extends SettingsPreferenceFragment
     * @return true if the data was saved
     */
    private boolean validateAndSave(boolean force) {

        // If the form is not editable, do nothing and return.
        if (mDisableEditor){
            Log.d(TAG, "Form is disabled. Nothing to save.");
            return true;
        }

        String name = checkNotSet(mName.getText());
        String apn = checkNotSet(mApn.getText());
        String mcc = checkNotSet(mMcc.getText());
+8 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class ApnPreference extends Preference implements
    private static CompoundButton mCurrentChecked = null;
    private boolean mProtectFromCheckedChange = false;
    private boolean mSelectable = true;
    private boolean mApnReadOnly = false;

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
@@ -116,7 +117,9 @@ public class ApnPreference extends Preference implements
            if (context != null) {
                int pos = Integer.parseInt(getKey());
                Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
                context.startActivity(new Intent(Intent.ACTION_EDIT, url));
                Intent intent = new Intent(Intent.ACTION_EDIT, url);
                intent.putExtra("DISABLE_EDITOR", mApnReadOnly);
                context.startActivity(intent);
            }
        }
    }
@@ -128,4 +131,8 @@ public class ApnPreference extends Preference implements
    public boolean getSelectable() {
        return mSelectable;
    }

    public void setApnReadOnly(boolean apnReadOnly) {
        mApnReadOnly = apnReadOnly;
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class ApnSettings extends RestrictedSettingsFragment implements
    private static final int TYPES_INDEX = 3;
    private static final int MVNO_TYPE_INDEX = 4;
    private static final int MVNO_MATCH_DATA_INDEX = 5;
    private static final int RO_INDEX = 6;

    private static final int MENU_NEW = Menu.FIRST;
    private static final int MENU_RESTORE = Menu.FIRST + 1;
@@ -251,8 +252,8 @@ public class ApnSettings extends RestrictedSettingsFragment implements
        }

        Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, new String[] {
                "_id", "name", "apn", "type", "mvno_type", "mvno_match_data"}, where.toString(),
                null, Telephony.Carriers.DEFAULT_SORT_ORDER);
                "_id", "name", "apn", "type", "mvno_type", "mvno_match_data", "read_only"},
                where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER);

        if (cursor != null) {
            IccRecords r = null;
@@ -277,9 +278,11 @@ public class ApnSettings extends RestrictedSettingsFragment implements
                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);

                ApnPreference pref = new ApnPreference(getPrefContext());

                pref.setApnReadOnly(readOnly);
                pref.setKey(key);
                pref.setTitle(name);
                pref.setSummary(apn);