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

Commit 70359a38 authored by jianzhou's avatar jianzhou Committed by Xiaojing Zhang
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
parent bff75531
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ public class ApnEditor extends PreferenceActivity
    private String mCurMnc;
    private String mCurMnc;
    private String mCurMcc;
    private String mCurMcc;
    private long mSubId;
    private long mSubId;
    private boolean mDisableEditor = false;


    private Uri mUri;
    private Uri mUri;
    private Cursor mCursor;
    private Cursor mCursor;
@@ -202,6 +203,12 @@ public class ApnEditor extends PreferenceActivity
        mSubId = intent.getLongExtra(SelectSubscription.SUBSCRIPTION_KEY,
        mSubId = intent.getLongExtra(SelectSubscription.SUBSCRIPTION_KEY,
                SubscriptionManager.getDefaultSubId());
                SubscriptionManager.getDefaultSubId());
        Log.d(TAG,"ApnEditor onCreate received sub: " + mSubId);
        Log.d(TAG,"ApnEditor onCreate received sub: " + mSubId);
        mDisableEditor = intent.getBooleanExtra("DISABLE_EDITOR",false);
        if (mDisableEditor) {
            getPreferenceScreen().setEnabled(false);
            Log.d(TAG, "ApnEditor form is disabled.");
        }

        mFirstTime = icicle == null;
        mFirstTime = icicle == null;


        if (action.equals(Intent.ACTION_EDIT)) {
        if (action.equals(Intent.ACTION_EDIT)) {
@@ -476,6 +483,10 @@ public class ApnEditor extends PreferenceActivity
    @Override
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        super.onCreateOptionsMenu(menu);
        if (mDisableEditor) {
            Log.d(TAG, "Form is disabled. Do not create the options menu.");
            return true;
        }
        // If it's a new APN, then cancel will delete the new entry in onPause
        // If it's a new APN, then cancel will delete the new entry in onPause
        if (!mNewApn) {
        if (!mNewApn) {
            menu.add(0, MENU_DELETE, 0, R.string.menu_delete)
            menu.add(0, MENU_DELETE, 0, R.string.menu_delete)
@@ -542,6 +553,12 @@ public class ApnEditor extends PreferenceActivity
        String mcc = checkNotSet(mMcc.getText());
        String mcc = checkNotSet(mMcc.getText());
        String mnc = checkNotSet(mMnc.getText());
        String mnc = checkNotSet(mMnc.getText());


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

        if (getErrorMsg() != null && !force) {
        if (getErrorMsg() != null && !force) {
            showDialog(ERROR_DIALOG_ID);
            showDialog(ERROR_DIALOG_ID);
            return false;
            return false;
+8 −1
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ public class ApnPreference extends Preference implements
    private static CompoundButton mCurrentChecked = null;
    private static CompoundButton mCurrentChecked = null;
    private boolean mProtectFromCheckedChange = false;
    private boolean mProtectFromCheckedChange = false;
    private boolean mSelectable = true;
    private boolean mSelectable = true;
    private boolean mApnReadOnly = false;


    @Override
    @Override
    public View getView(View convertView, ViewGroup parent) {
    public View getView(View convertView, ViewGroup parent) {
@@ -118,7 +119,9 @@ public class ApnPreference extends Preference implements
            if (context != null) {
            if (context != null) {
                int pos = Integer.parseInt(getKey());
                int pos = Integer.parseInt(getKey());
                Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
                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);
            }
            }
        }
        }
    }
    }
@@ -130,4 +133,8 @@ public class ApnPreference extends Preference implements
    public boolean getSelectable() {
    public boolean getSelectable() {
        return mSelectable;
        return mSelectable;
    }
    }

    public void setApnReadOnly(boolean apnReadOnly){
        mApnReadOnly = apnReadOnly;
    }
}
}
+4 −1
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ public class ApnSettings extends SettingsPreferenceFragment implements
    private static final int NAME_INDEX = 1;
    private static final int NAME_INDEX = 1;
    private static final int APN_INDEX = 2;
    private static final int APN_INDEX = 2;
    private static final int TYPES_INDEX = 3;
    private static final int TYPES_INDEX = 3;
    private static final int RO_INDEX = 4;


    private static final int MENU_NEW = Menu.FIRST;
    private static final int MENU_NEW = Menu.FIRST;
    private static final int MENU_RESTORE = Menu.FIRST + 1;
    private static final int MENU_RESTORE = Menu.FIRST + 1;
@@ -216,7 +217,7 @@ public class ApnSettings extends SettingsPreferenceFragment implements
    private void fillList() {
    private void fillList() {
        String where = getOperatorNumericSelection();
        String where = getOperatorNumericSelection();
        Cursor cursor = getContentResolver().query(getUri(Telephony.Carriers.CONTENT_URI),
        Cursor cursor = getContentResolver().query(getUri(Telephony.Carriers.CONTENT_URI),
                new String[] {"_id", "name", "apn", "type"}, where, null,
                new String[] {"_id", "name", "apn", "type", "read_only"}, where, null,
                Telephony.Carriers.DEFAULT_SORT_ORDER);
                Telephony.Carriers.DEFAULT_SORT_ORDER);


        if (cursor != null) {
        if (cursor != null) {
@@ -232,9 +233,11 @@ public class ApnSettings extends SettingsPreferenceFragment implements
                String apn = cursor.getString(APN_INDEX);
                String apn = cursor.getString(APN_INDEX);
                String key = cursor.getString(ID_INDEX);
                String key = cursor.getString(ID_INDEX);
                String type = cursor.getString(TYPES_INDEX);
                String type = cursor.getString(TYPES_INDEX);
                boolean readOnly = (cursor.getInt(RO_INDEX) == 1);


                ApnPreference pref = new ApnPreference(getActivity());
                ApnPreference pref = new ApnPreference(getActivity());


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