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

Commit e00ab6c5 authored by Yifan Bai's avatar Yifan Bai Committed by Amit Mahajan
Browse files

Fix cannot build prefer or restore APN for Secondary SIM/Sub.

When built prefer or restore APN with URI, the URI does not contain Sub
Id. This leads to the fail of display selected APN on Secondary SIM/Sub.
To fix, SubId needs to be appended in the URI.

Change-Id: If4b98b0bdd02474b3e7b7537c5a1257dcdbe9511
parent 052768a8
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -393,14 +393,14 @@ public class ApnSettings extends SettingsPreferenceFragment implements

        ContentValues values = new ContentValues();
        values.put(APN_ID, mSelectedKey);
        resolver.update(PREFERAPN_URI, values, null, null);
        resolver.update(getUriForCurrSubId(PREFERAPN_URI), values, null, null);
    }

    private String getSelectedApnKey() {
        String key = null;

        Cursor cursor = getContentResolver().query(PREFERAPN_URI, new String[] {"_id"},
                null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
        Cursor cursor = getContentResolver().query(getUriForCurrSubId(PREFERAPN_URI),
                new String[] {"_id"}, null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            key = cursor.getString(ID_INDEX);
@@ -431,6 +431,17 @@ public class ApnSettings extends SettingsPreferenceFragment implements
        return true;
    }

    // Append subId to the Uri
    private Uri getUriForCurrSubId(Uri uri) {
        int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
                : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            return Uri.withAppendedPath(uri, "subId/" + String.valueOf(subId));
        } else {
            return uri;
        }
    }

    private class RestoreApnUiHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
@@ -468,7 +479,7 @@ public class ApnSettings extends SettingsPreferenceFragment implements
            switch (msg.what) {
                case EVENT_RESTORE_DEFAULTAPN_START:
                    ContentResolver resolver = getContentResolver();
                    resolver.delete(DEFAULTAPN_URI, null, null);
                    resolver.delete(getUriForCurrSubId(DEFAULTAPN_URI), null, null);
                    mRestoreApnUiHandler
                        .sendEmptyMessage(EVENT_RESTORE_DEFAULTAPN_COMPLETE);
                    break;