Add Authentication Type field to the APN settings.

Bug: 1817100
This commit is contained in:
Jaikumar Ganesh
2009-10-26 13:01:36 -07:00
parent b3735744fd
commit 195bc43460
3 changed files with 115 additions and 41 deletions

View File

@@ -291,4 +291,23 @@
<item>中文 (繁體)</item> <item>中文 (繁體)</item>
</string-array> </string-array>
<!-- Authentication Types used in APN editor -->
<string-array name="apn_auth_entries">
<item>None</item>
<item>PAP</item>
<item>CHAP</item>
<item>PAP or CHAP</item>
</string-array>
<string-array translatable="false" name="apn_auth_values">
<!-- Do not translate. -->
<item>0</item>
<!-- Do not translate. -->
<item>1</item>
<!-- Do not translate. -->
<item>2</item>
<!-- Do not translate. -->
<item>3</item>
</string-array>
</resources> </resources>

View File

@@ -101,6 +101,12 @@
android:singleLine="true" android:singleLine="true"
android:inputType="number" android:inputType="number"
/> />
<ListPreference
android:title="@string/apn_auth_type"
android:key="auth_type"
android:entries="@array/apn_auth_entries"
android:entryValues="@array/apn_auth_values"
/>
<EditTextPreference <EditTextPreference
android:title="@string/apn_type" android:title="@string/apn_type"
android:dialogTitle="@string/apn_type" android:dialogTitle="@string/apn_type"

View File

@@ -27,28 +27,31 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.provider.Telephony; import android.provider.Telephony;
import com.android.internal.telephony.TelephonyProperties;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import com.android.internal.telephony.TelephonyProperties;
public class ApnEditor extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener { public class ApnEditor extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener,
Preference.OnPreferenceChangeListener {
private final static String TAG = ApnEditor.class.getSimpleName(); private final static String TAG = ApnEditor.class.getSimpleName();
private final static String SAVED_POS = "pos"; private final static String SAVED_POS = "pos";
private final static String KEY_AUTH_TYPE = "auth_type";
private static final int MENU_DELETE = Menu.FIRST; private static final int MENU_DELETE = Menu.FIRST;
private static final int MENU_SAVE = Menu.FIRST + 1; private static final int MENU_SAVE = Menu.FIRST + 1;
private static final int MENU_CANCEL = Menu.FIRST + 2; private static final int MENU_CANCEL = Menu.FIRST + 2;
private static String sNotSet; private static String sNotSet;
private EditTextPreference mName; private EditTextPreference mName;
private EditTextPreference mApn; private EditTextPreference mApn;
@@ -62,16 +65,18 @@ public class ApnEditor extends PreferenceActivity
private EditTextPreference mMnc; private EditTextPreference mMnc;
private EditTextPreference mMmsProxy; private EditTextPreference mMmsProxy;
private EditTextPreference mMmsPort; private EditTextPreference mMmsPort;
private ListPreference mAuthType;
private EditTextPreference mApnType; private EditTextPreference mApnType;
private String mCurMnc; private String mCurMnc;
private String mCurMcc; private String mCurMcc;
private Uri mUri; private Uri mUri;
private Cursor mCursor; private Cursor mCursor;
private boolean mNewApn; private boolean mNewApn;
private boolean mFirstTime; private boolean mFirstTime;
private Resources mRes; private Resources mRes;
/** /**
* Standard projection for the interesting columns of a normal note. * Standard projection for the interesting columns of a normal note.
*/ */
@@ -90,9 +95,10 @@ public class ApnEditor extends PreferenceActivity
Telephony.Carriers.NUMERIC, // 11 Telephony.Carriers.NUMERIC, // 11
Telephony.Carriers.MMSPROXY,// 12 Telephony.Carriers.MMSPROXY,// 12
Telephony.Carriers.MMSPORT, // 13 Telephony.Carriers.MMSPORT, // 13
Telephony.Carriers.TYPE, // 14 Telephony.Carriers.AUTH_TYPE, // 14
Telephony.Carriers.TYPE, // 15
}; };
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;
@@ -106,8 +112,10 @@ public class ApnEditor extends PreferenceActivity
private static final int MNC_INDEX = 10; private static final int MNC_INDEX = 10;
private static final int MMSPROXY_INDEX = 12; private static final int MMSPROXY_INDEX = 12;
private static final int MMSPORT_INDEX = 13; private static final int MMSPORT_INDEX = 13;
private static final int TYPE_INDEX = 14; private static final int AUTH_TYPE_INDEX = 14;
private static final int TYPE_INDEX = 15;
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
@@ -128,21 +136,24 @@ public class ApnEditor extends PreferenceActivity
mMcc = (EditTextPreference) findPreference("apn_mcc"); mMcc = (EditTextPreference) findPreference("apn_mcc");
mMnc = (EditTextPreference) findPreference("apn_mnc"); mMnc = (EditTextPreference) findPreference("apn_mnc");
mApnType = (EditTextPreference) findPreference("apn_type"); mApnType = (EditTextPreference) findPreference("apn_type");
mAuthType = (ListPreference) findPreference("auth_type");
mAuthType.setOnPreferenceChangeListener(this);
mRes = getResources(); mRes = getResources();
final Intent intent = getIntent(); final Intent intent = getIntent();
final String action = intent.getAction(); final String action = intent.getAction();
mFirstTime = icicle == null; mFirstTime = icicle == null;
if (action.equals(Intent.ACTION_EDIT)) { if (action.equals(Intent.ACTION_EDIT)) {
mUri = intent.getData(); mUri = intent.getData();
} else if (action.equals(Intent.ACTION_INSERT)) { } else if (action.equals(Intent.ACTION_INSERT)) {
if (mFirstTime) { if (mFirstTime) {
mUri = getContentResolver().insert(intent.getData(), new ContentValues()); mUri = getContentResolver().insert(intent.getData(), new ContentValues());
} else { } else {
mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,
icicle.getInt(SAVED_POS)); icicle.getInt(SAVED_POS));
} }
mNewApn = true; mNewApn = true;
@@ -155,7 +166,7 @@ public class ApnEditor extends PreferenceActivity
finish(); finish();
return; return;
} }
// The new entry was created, so assume all will end well and // The new entry was created, so assume all will end well and
// set the result to be returned. // set the result to be returned.
setResult(RESULT_OK, (new Intent()).setAction(mUri.toString())); setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
@@ -167,7 +178,7 @@ public class ApnEditor extends PreferenceActivity
mCursor = managedQuery(mUri, sProjection, null, null); mCursor = managedQuery(mUri, sProjection, null, null);
mCursor.moveToFirst(); mCursor.moveToFirst();
fillUi(); fillUi();
} }
@@ -176,15 +187,15 @@ public class ApnEditor extends PreferenceActivity
super.onResume(); super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
} }
@Override @Override
public void onPause() { public void onPause() {
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause(); super.onPause();
} }
private void fillUi() { private void fillUi() {
if (mFirstTime) { if (mFirstTime) {
mFirstTime = false; mFirstTime = false;
// Fill in all the values from the db in both text editor and summary // Fill in all the values from the db in both text editor and summary
mName.setText(mCursor.getString(NAME_INDEX)); mName.setText(mCursor.getString(NAME_INDEX));
@@ -201,7 +212,7 @@ public class ApnEditor extends PreferenceActivity
mMnc.setText(mCursor.getString(MNC_INDEX)); mMnc.setText(mCursor.getString(MNC_INDEX));
mApnType.setText(mCursor.getString(TYPE_INDEX)); mApnType.setText(mCursor.getString(TYPE_INDEX));
if (mNewApn) { if (mNewApn) {
String numeric = String numeric =
SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
// MCC is first 3 chars and then in 2 - 3 chars of MNC // MCC is first 3 chars and then in 2 - 3 chars of MNC
if (numeric != null && numeric.length() > 4) { if (numeric != null && numeric.length() > 4) {
@@ -216,8 +227,13 @@ public class ApnEditor extends PreferenceActivity
mCurMcc = mcc; mCurMcc = mcc;
} }
} }
int authVal = mCursor.getInt(AUTH_TYPE_INDEX);
if (authVal != -1) {
mAuthType.setValueIndex(authVal);
}
} }
mName.setSummary(checkNull(mName.getText())); mName.setSummary(checkNull(mName.getText()));
mApn.setSummary(checkNull(mApn.getText())); mApn.setSummary(checkNull(mApn.getText()));
mProxy.setSummary(checkNull(mProxy.getText())); mProxy.setSummary(checkNull(mProxy.getText()));
@@ -231,6 +247,33 @@ public class ApnEditor extends PreferenceActivity
mMcc.setSummary(checkNull(mMcc.getText())); mMcc.setSummary(checkNull(mMcc.getText()));
mMnc.setSummary(checkNull(mMnc.getText())); mMnc.setSummary(checkNull(mMnc.getText()));
mApnType.setSummary(checkNull(mApnType.getText())); mApnType.setSummary(checkNull(mApnType.getText()));
String authVal = mAuthType.getValue();
if (authVal != null) {
int authValIndex = Integer.parseInt(authVal);
mAuthType.setValueIndex(authValIndex);
String []values = mRes.getStringArray(R.array.apn_auth_entries);
mAuthType.setSummary(values[authValIndex]);
} else {
mAuthType.setSummary(sNotSet);
}
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (KEY_AUTH_TYPE.equals(key)) {
try {
int index = Integer.parseInt((String) newValue);
mAuthType.setValueIndex(index);
String []values = mRes.getStringArray(R.array.apn_auth_entries);
mAuthType.setSummary(values[index]);
} catch (NumberFormatException e) {
return false;
}
}
return true;
} }
@Override @Override
@@ -268,7 +311,7 @@ public class ApnEditor extends PreferenceActivity
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) { switch (keyCode) {
@@ -288,7 +331,7 @@ public class ApnEditor extends PreferenceActivity
validateAndSave(true); validateAndSave(true);
icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX)); icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX));
} }
/** /**
* Check the key fields' validity and save if valid. * Check the key fields' validity and save if valid.
* @param force save even if the fields are not valid, if the app is * @param force save even if the fields are not valid, if the app is
@@ -300,7 +343,7 @@ public class ApnEditor extends PreferenceActivity
String apn = checkNotSet(mApn.getText()); String apn = checkNotSet(mApn.getText());
String mcc = checkNotSet(mMcc.getText()); String mcc = checkNotSet(mMcc.getText());
String mnc = checkNotSet(mMnc.getText()); String mnc = checkNotSet(mMnc.getText());
String errorMsg = null; String errorMsg = null;
if (name.length() < 1) { if (name.length() < 1) {
errorMsg = mRes.getString(R.string.error_name_empty); errorMsg = mRes.getString(R.string.error_name_empty);
@@ -311,20 +354,20 @@ public class ApnEditor extends PreferenceActivity
} else if ((mnc.length() & 0xFFFE) != 2) { } else if ((mnc.length() & 0xFFFE) != 2) {
errorMsg = mRes.getString(R.string.error_mnc_not23); errorMsg = mRes.getString(R.string.error_mnc_not23);
} }
if (errorMsg != null && !force) { if (errorMsg != null && !force) {
showErrorMessage(errorMsg); showErrorMessage(errorMsg);
return false; return false;
} }
if (!mCursor.moveToFirst()) { if (!mCursor.moveToFirst()) {
Log.w(TAG, Log.w(TAG,
"Could not go to the first row in the Cursor when saving data."); "Could not go to the first row in the Cursor when saving data.");
return false; return false;
} }
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Telephony.Carriers.NAME, name); values.put(Telephony.Carriers.NAME, name);
values.put(Telephony.Carriers.APN, apn); values.put(Telephony.Carriers.APN, apn);
values.put(Telephony.Carriers.PROXY, checkNotSet(mProxy.getText())); values.put(Telephony.Carriers.PROXY, checkNotSet(mProxy.getText()));
@@ -334,22 +377,28 @@ public class ApnEditor extends PreferenceActivity
values.put(Telephony.Carriers.USER, checkNotSet(mUser.getText())); values.put(Telephony.Carriers.USER, checkNotSet(mUser.getText()));
values.put(Telephony.Carriers.SERVER, checkNotSet(mServer.getText())); values.put(Telephony.Carriers.SERVER, checkNotSet(mServer.getText()));
values.put(Telephony.Carriers.PASSWORD, checkNotSet(mPassword.getText())); values.put(Telephony.Carriers.PASSWORD, checkNotSet(mPassword.getText()));
values.put(Telephony.Carriers.MMSC, checkNotSet(mMmsc.getText())); values.put(Telephony.Carriers.MMSC, checkNotSet(mMmsc.getText()));
String authVal = mAuthType.getValue();
if (authVal != null) {
values.put(Telephony.Carriers.AUTH_TYPE, Integer.parseInt(authVal));
}
values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType.getText())); values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType.getText()));
values.put(Telephony.Carriers.MCC, mcc); values.put(Telephony.Carriers.MCC, mcc);
values.put(Telephony.Carriers.MNC, mnc); values.put(Telephony.Carriers.MNC, mnc);
values.put(Telephony.Carriers.NUMERIC, mcc + mnc); values.put(Telephony.Carriers.NUMERIC, mcc + mnc);
if (mCurMnc != null && mCurMcc != null) { if (mCurMnc != null && mCurMcc != null) {
if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc)) { if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc)) {
values.put(Telephony.Carriers.CURRENT, 1); values.put(Telephony.Carriers.CURRENT, 1);
} }
} }
getContentResolver().update(mUri, values, null, null); getContentResolver().update(mUri, values, null, null);
return true; return true;
} }
@@ -365,7 +414,7 @@ public class ApnEditor extends PreferenceActivity
getContentResolver().delete(mUri, null, null); getContentResolver().delete(mUri, null, null);
finish(); finish();
} }
private String starify(String value) { private String starify(String value) {
if (value == null || value.length() == 0) { if (value == null || value.length() == 0) {
return sNotSet; return sNotSet;
@@ -377,7 +426,7 @@ public class ApnEditor extends PreferenceActivity
return new String(password); return new String(password);
} }
} }
private String checkNull(String value) { private String checkNull(String value) {
if (value == null || value.length() == 0) { if (value == null || value.length() == 0) {
return sNotSet; return sNotSet;
@@ -385,7 +434,7 @@ public class ApnEditor extends PreferenceActivity
return value; return value;
} }
} }
private String checkNotSet(String value) { private String checkNotSet(String value) {
if (value == null || value.equals(sNotSet)) { if (value == null || value.equals(sNotSet)) {
return ""; return "";
@@ -393,7 +442,7 @@ public class ApnEditor extends PreferenceActivity
return value; return value;
} }
} }
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key); Preference pref = findPreference(key);
if (pref != null) { if (pref != null) {