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

Commit a52c5698 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Support configuring the protocol in APN settings.

Bug: 3333633
Change-Id: I0797cd97074fe1b8a1318168b86fe4627488215a
parent bd044818
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -354,6 +354,22 @@
        <item>3</item>
    </string-array>

    <!-- Authentication Types used in APN editor -->
    <string-array name="apn_protocol_entries">
        <item>IPv4</item>
        <item>IPv6</item>
        <item>IPv4/IPv6</item>
    </string-array>

    <string-array translatable="false" name="apn_protocol_values">
        <!-- Do not translate. -->
        <item>IP</item>
        <!-- Do not translate. -->
        <item>IPV6</item>
        <!-- Do not translate. -->
        <item>IPV4V6</item>
    </string-array>

    <!-- Apps on SD instalaltion location options in ApplicationSettings -->
    <string-array name="app_install_location_entries">
        <item>Internal device storage</item>
+2 −0
Original line number Diff line number Diff line
@@ -1397,6 +1397,8 @@
    <string name="apn_auth_type_pap_chap">PAP or CHAP</string>
    <!-- Edit access point labels: The type of APN -->
    <string name="apn_type">APN type</string>
    <!-- Edit access point labels: The protocol of the APN, e.g., "IPv4", "IPv6", or "IPv4/IPv6". -->
    <string name="apn_protocol">APN protocol</string>
    <!-- Edit access point screen menu option to delete this APN -->
    <string name="menu_delete">Delete APN</string>
    <!-- APNs screen menu option to create a brand spanking new APN -->
+7 −0
Original line number Diff line number Diff line
@@ -114,4 +114,11 @@
        android:singleLine="true"
        android:inputType="textNoSuggestions"
        />
    <ListPreference
        android:title="@string/apn_protocol"
        android:dialogTitle="@string/apn_protocol"
        android:key="apn_protocol"
        android:entries="@array/apn_protocol_entries"
        android:entryValues="@array/apn_protocol_values"
        />
</PreferenceScreen>   
+49 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.view.Menu;
import android.view.MenuItem;

import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.telephony.RILConstants;


public class ApnEditor extends PreferenceActivity
@@ -47,6 +48,7 @@ public class ApnEditor extends PreferenceActivity

    private final static String SAVED_POS = "pos";
    private final static String KEY_AUTH_TYPE = "auth_type";
    private final static String KEY_PROTOCOL = "apn_protocol";

    private static final int MENU_DELETE = Menu.FIRST;
    private static final int MENU_SAVE = Menu.FIRST + 1;
@@ -67,6 +69,7 @@ public class ApnEditor extends PreferenceActivity
    private EditTextPreference mMmsPort;
    private ListPreference mAuthType;
    private EditTextPreference mApnType;
    private ListPreference mProtocol;

    private String mCurMnc;
    private String mCurMcc;
@@ -97,6 +100,7 @@ public class ApnEditor extends PreferenceActivity
            Telephony.Carriers.MMSPORT, // 13
            Telephony.Carriers.AUTH_TYPE, // 14
            Telephony.Carriers.TYPE, // 15
            Telephony.Carriers.PROTOCOL, // 16
    };

    private static final int ID_INDEX = 0;
@@ -114,6 +118,7 @@ public class ApnEditor extends PreferenceActivity
    private static final int MMSPORT_INDEX = 13;
    private static final int AUTH_TYPE_INDEX = 14;
    private static final int TYPE_INDEX = 15;
    private static final int PROTOCOL_INDEX = 16;


    @Override
@@ -137,9 +142,12 @@ public class ApnEditor extends PreferenceActivity
        mMnc = (EditTextPreference) findPreference("apn_mnc");
        mApnType = (EditTextPreference) findPreference("apn_type");

        mAuthType = (ListPreference) findPreference("auth_type");
        mAuthType = (ListPreference) findPreference(KEY_AUTH_TYPE);
        mAuthType.setOnPreferenceChangeListener(this);

        mProtocol = (ListPreference) findPreference(KEY_PROTOCOL);
        mProtocol.setOnPreferenceChangeListener(this);

        mRes = getResources();

        final Intent intent = getIntent();
@@ -234,6 +242,7 @@ public class ApnEditor extends PreferenceActivity
                mAuthType.setValueIndex(authVal);
            }

            mProtocol.setValue(mCursor.getString(PROTOCOL_INDEX));
        }

        mName.setSummary(checkNull(mName.getText()));
@@ -260,6 +269,28 @@ public class ApnEditor extends PreferenceActivity
        } else {
            mAuthType.setSummary(sNotSet);
        }

        mProtocol.setSummary(
                checkNull(protocolDescription(mProtocol.getValue())));
    }

    /**
     * Returns the UI choice (e.g., "IPv4/IPv6") corresponding to the given
     * raw value of the protocol preference (e.g., "IPV4V6"). If unknown,
     * return null.
     */
    private String protocolDescription(String raw) {
        int protocolIndex = mProtocol.findIndexOfValue(raw);
        if (protocolIndex == -1) {
            return null;
        } else {
            String[] values = mRes.getStringArray(R.array.apn_protocol_entries);
            try {
                return values[protocolIndex];
            } catch (ArrayIndexOutOfBoundsException e) {
                return null;
            }
        }
    }

    public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -274,6 +305,16 @@ public class ApnEditor extends PreferenceActivity
            } catch (NumberFormatException e) {
                return false;
            }
            return true;
        }

        if (KEY_PROTOCOL.equals(key)) {
            String protocol = protocolDescription((String) newValue);
            if (protocol == null) {
                return false;
            }
            mProtocol.setSummary(protocol);
            mProtocol.setValue((String) newValue);
        }
        return true;
    }
@@ -396,6 +437,13 @@ public class ApnEditor extends PreferenceActivity
            values.put(Telephony.Carriers.AUTH_TYPE, Integer.parseInt(authVal));
        }

        values.put(Telephony.Carriers.PROTOCOL, checkNotSet(mProtocol.getValue()));

        // Hardcode IPv4 roaming for now until the carriers sort out all the
        // billing arrangements.
        values.put(Telephony.Carriers.ROAMING_PROTOCOL,
                RILConstants.SETUP_DATA_PROTOCOL_IP);

        values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType.getText()));

        values.put(Telephony.Carriers.MCC, mcc);