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

Commit f82cd8f4 authored by Amit Mahajan's avatar Amit Mahajan Committed by Android (Google) Code Review
Browse files

Merge "Show only APNs belonging to carrier (mno/mvno) under apn settings." into mnc-dev

parents aeb09164 17b0c481
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -346,12 +346,14 @@
            </intent-filter>
            </intent-filter>
        </activity-alias>
        </activity-alias>


        <!-- Runs in the phone process since it needs access to UiccController -->
        <activity android:name="Settings$ApnSettingsActivity"
        <activity android:name="Settings$ApnSettingsActivity"
                android:label="@string/apn_settings"
                android:label="@string/apn_settings"
                android:launchMode="singleTask"
                android:launchMode="singleTask"
                android:taskAffinity="com.android.settings"
                android:taskAffinity="com.android.settings"
                android:configChanges="orientation|keyboardHidden|screenSize"
                android:configChanges="orientation|keyboardHidden|screenSize"
                android:parentActivityName="Settings$WirelessSettingsActivity">
                android:parentActivityName="Settings$WirelessSettingsActivity"
                android:process="com.android.phone">
            <intent-filter android:priority="1">
            <intent-filter android:priority="1">
                <action android:name="android.settings.APN_SETTINGS" />
                <action android:name="android.settings.APN_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.DEFAULT" />
+10 −1
Original line number Original line Diff line number Diff line
@@ -98,6 +98,8 @@ public class ApnEditor extends InstrumentedPreferenceActivity
    private Resources mRes;
    private Resources mRes;
    private TelephonyManager mTelephonyManager;
    private TelephonyManager mTelephonyManager;
    private int mBearerInitialVal = 0;
    private int mBearerInitialVal = 0;
    private String mMvnoTypeStr;
    private String mMvnoMatchDataStr;


    /**
    /**
     * Standard projection for the interesting columns of a normal note.
     * Standard projection for the interesting columns of a normal note.
@@ -195,7 +197,8 @@ public class ApnEditor extends InstrumentedPreferenceActivity


        final Intent intent = getIntent();
        final Intent intent = getIntent();
        final String action = intent.getAction();
        final String action = intent.getAction();
        mSubId = intent.getIntExtra("sub_id", SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);


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


@@ -209,6 +212,8 @@ public class ApnEditor extends InstrumentedPreferenceActivity
                        icicle.getInt(SAVED_POS));
                        icicle.getInt(SAVED_POS));
            }
            }
            mNewApn = true;
            mNewApn = true;
            mMvnoTypeStr = intent.getStringExtra(ApnSettings.MVNO_TYPE);
            mMvnoMatchDataStr = intent.getStringExtra(ApnSettings.MVNO_MATCH_DATA);
            // If we were unable to create a new note, then just finish
            // If we were unable to create a new note, then just finish
            // this activity.  A RESULT_CANCELED will be sent back to the
            // this activity.  A RESULT_CANCELED will be sent back to the
            // original activity if they requested a result.
            // original activity if they requested a result.
@@ -325,6 +330,10 @@ public class ApnEditor extends InstrumentedPreferenceActivity
            mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX));
            mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX));
            mMvnoMatchData.setEnabled(false);
            mMvnoMatchData.setEnabled(false);
            mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX));
            mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX));
            if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) {
                mMvnoType.setValue(mMvnoTypeStr);
                mMvnoMatchData.setText(mMvnoMatchDataStr);
            }
        }
        }


        mName.setSummary(checkNull(mName.getText()));
        mName.setSummary(checkNull(mName.getText()));
+60 −7
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import android.preference.PreferenceScreen;
import android.provider.Telephony;
import android.provider.Telephony;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.view.Menu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuInflater;
@@ -50,6 +51,10 @@ import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.dataconnection.ApnSetting;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.UiccController;

import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -65,11 +70,16 @@ public class ApnSettings extends SettingsPreferenceFragment implements
        "content://telephony/carriers/preferapn";
        "content://telephony/carriers/preferapn";


    public static final String APN_ID = "apn_id";
    public static final String APN_ID = "apn_id";
    public static final String SUB_ID = "sub_id";
    public static final String MVNO_TYPE = "mvno_type";
    public static final String MVNO_MATCH_DATA = "mvno_match_data";


    private static final int ID_INDEX = 0;
    private static final int ID_INDEX = 0;
    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 MVNO_TYPE_INDEX = 4;
    private static final int MVNO_MATCH_DATA_INDEX = 5;


    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;
@@ -88,6 +98,9 @@ public class ApnSettings extends SettingsPreferenceFragment implements
    private RestoreApnProcessHandler mRestoreApnProcessHandler;
    private RestoreApnProcessHandler mRestoreApnProcessHandler;
    private HandlerThread mRestoreDefaultApnThread;
    private HandlerThread mRestoreDefaultApnThread;
    private SubscriptionInfo mSubscriptionInfo;
    private SubscriptionInfo mSubscriptionInfo;
    private UiccController mUiccController;
    private String mMvnoType;
    private String mMvnoMatchData;


    private UserManager mUm;
    private UserManager mUm;


@@ -134,7 +147,7 @@ public class ApnSettings extends SettingsPreferenceFragment implements
    public void onCreate(Bundle icicle) {
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        super.onCreate(icicle);
        final Activity activity = getActivity();
        final Activity activity = getActivity();
        final int subId = activity.getIntent().getIntExtra("sub_id",
        final int subId = activity.getIntent().getIntExtra(SUB_ID,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);


        mUm = (UserManager) getSystemService(Context.USER_SERVICE);
        mUm = (UserManager) getSystemService(Context.USER_SERVICE);
@@ -147,6 +160,7 @@ public class ApnSettings extends SettingsPreferenceFragment implements
        }
        }


        mSubscriptionInfo = SubscriptionManager.from(activity).getActiveSubscriptionInfo(subId);
        mSubscriptionInfo = SubscriptionManager.from(activity).getActiveSubscriptionInfo(subId);
        mUiccController = UiccController.getInstance();
    }
    }


    @Override
    @Override
@@ -215,14 +229,22 @@ public class ApnSettings extends SettingsPreferenceFragment implements
            + "\" AND NOT (type='ia' AND (apn=\"\" OR apn IS NULL))";
            + "\" AND NOT (type='ia' AND (apn=\"\" OR apn IS NULL))";


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


        if (cursor != null) {
        if (cursor != null) {
            IccRecords r = null;
            if (mUiccController != null && mSubscriptionInfo != null) {
                r = mUiccController.getIccRecords(SubscriptionManager.getPhoneId(
                        mSubscriptionInfo.getSubscriptionId()), UiccController.APP_FAM_3GPP);
            }
            PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
            PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
            apnList.removeAll();
            apnList.removeAll();


            ArrayList<Preference> mmsApnList = new ArrayList<Preference>();
            ArrayList<ApnPreference> mnoApnList = new ArrayList<ApnPreference>();
            ArrayList<ApnPreference> mvnoApnList = new ArrayList<ApnPreference>();
            ArrayList<ApnPreference> mnoMmsApnList = new ArrayList<ApnPreference>();
            ArrayList<ApnPreference> mvnoMmsApnList = new ArrayList<ApnPreference>();


            mSelectedKey = getSelectedApnKey();
            mSelectedKey = getSelectedApnKey();
            cursor.moveToFirst();
            cursor.moveToFirst();
@@ -231,6 +253,8 @@ 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);
                String mvnoType = cursor.getString(MVNO_TYPE_INDEX);
                String mvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);


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


@@ -246,20 +270,45 @@ public class ApnSettings extends SettingsPreferenceFragment implements
                    if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
                    if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
                        pref.setChecked();
                        pref.setChecked();
                    }
                    }
                    apnList.addPreference(pref);
                    addApnToList(pref, mnoApnList, mvnoApnList, r, mvnoType, mvnoMatchData);
                } else {
                } else {
                    mmsApnList.add(pref);
                    addApnToList(pref, mnoMmsApnList, mvnoMmsApnList, r, mvnoType, mvnoMatchData);
                }
                }
                cursor.moveToNext();
                cursor.moveToNext();
            }
            }
            cursor.close();
            cursor.close();


            for (Preference preference : mmsApnList) {
            if (!mvnoApnList.isEmpty()) {
                mnoApnList = mvnoApnList;
                mnoMmsApnList = mvnoMmsApnList;

                // Also save the mvno info
            }

            for (Preference preference : mnoApnList) {
                apnList.addPreference(preference);
            }
            for (Preference preference : mnoMmsApnList) {
                apnList.addPreference(preference);
                apnList.addPreference(preference);
            }
            }
        }
        }
    }
    }


    private void addApnToList(ApnPreference pref, ArrayList<ApnPreference> mnoList,
                              ArrayList<ApnPreference> mvnoList, IccRecords r, String mvnoType,
                              String mvnoMatchData) {
        if (r != null && !TextUtils.isEmpty(mvnoType) && !TextUtils.isEmpty(mvnoMatchData)) {
            if (ApnSetting.mvnoMatches(r, mvnoType, mvnoMatchData)) {
                mvnoList.add(pref);
                // Since adding to mvno list, save mvno info
                mMvnoType = mvnoType;
                mMvnoMatchData = mvnoMatchData;
            }
        } else {
            mnoList.add(pref);
        }
    }

    @Override
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        if (!mUnavailable) {
        if (!mUnavailable) {
@@ -293,7 +342,11 @@ public class ApnSettings extends SettingsPreferenceFragment implements
        Intent intent = new Intent(Intent.ACTION_INSERT, Telephony.Carriers.CONTENT_URI);
        Intent intent = new Intent(Intent.ACTION_INSERT, Telephony.Carriers.CONTENT_URI);
        int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
        int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
                : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
                : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        intent.putExtra("sub_id", subId);
        intent.putExtra(SUB_ID, subId);
        if (!TextUtils.isEmpty(mMvnoType) && !TextUtils.isEmpty(mMvnoMatchData)) {
            intent.putExtra(MVNO_TYPE, mMvnoType);
            intent.putExtra(MVNO_MATCH_DATA, mMvnoMatchData);
        }
        startActivity(intent);
        startActivity(intent);
    }
    }