Add Authentication Type field to the APN settings.
Bug: 1817100
This commit is contained in:
@@ -27,28 +27,31 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.provider.Telephony;
|
||||
import com.android.internal.telephony.TelephonyProperties;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
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 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_SAVE = Menu.FIRST + 1;
|
||||
private static final int MENU_CANCEL = Menu.FIRST + 2;
|
||||
|
||||
|
||||
private static String sNotSet;
|
||||
private EditTextPreference mName;
|
||||
private EditTextPreference mApn;
|
||||
@@ -62,16 +65,18 @@ public class ApnEditor extends PreferenceActivity
|
||||
private EditTextPreference mMnc;
|
||||
private EditTextPreference mMmsProxy;
|
||||
private EditTextPreference mMmsPort;
|
||||
private ListPreference mAuthType;
|
||||
private EditTextPreference mApnType;
|
||||
|
||||
private String mCurMnc;
|
||||
private String mCurMcc;
|
||||
|
||||
|
||||
private Uri mUri;
|
||||
private Cursor mCursor;
|
||||
private boolean mNewApn;
|
||||
private boolean mFirstTime;
|
||||
private Resources mRes;
|
||||
|
||||
|
||||
/**
|
||||
* 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.MMSPROXY,// 12
|
||||
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 NAME_INDEX = 1;
|
||||
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 MMSPROXY_INDEX = 12;
|
||||
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
|
||||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -128,21 +136,24 @@ public class ApnEditor extends PreferenceActivity
|
||||
mMcc = (EditTextPreference) findPreference("apn_mcc");
|
||||
mMnc = (EditTextPreference) findPreference("apn_mnc");
|
||||
mApnType = (EditTextPreference) findPreference("apn_type");
|
||||
|
||||
|
||||
mAuthType = (ListPreference) findPreference("auth_type");
|
||||
mAuthType.setOnPreferenceChangeListener(this);
|
||||
|
||||
mRes = getResources();
|
||||
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final String action = intent.getAction();
|
||||
|
||||
mFirstTime = icicle == null;
|
||||
|
||||
|
||||
if (action.equals(Intent.ACTION_EDIT)) {
|
||||
mUri = intent.getData();
|
||||
} else if (action.equals(Intent.ACTION_INSERT)) {
|
||||
if (mFirstTime) {
|
||||
mUri = getContentResolver().insert(intent.getData(), new ContentValues());
|
||||
} else {
|
||||
mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,
|
||||
mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,
|
||||
icicle.getInt(SAVED_POS));
|
||||
}
|
||||
mNewApn = true;
|
||||
@@ -155,7 +166,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// The new entry was created, so assume all will end well and
|
||||
// set the result to be returned.
|
||||
setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
|
||||
@@ -167,7 +178,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
|
||||
mCursor = managedQuery(mUri, sProjection, null, null);
|
||||
mCursor.moveToFirst();
|
||||
|
||||
|
||||
fillUi();
|
||||
}
|
||||
|
||||
@@ -176,15 +187,15 @@ public class ApnEditor extends PreferenceActivity
|
||||
super.onResume();
|
||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
private void fillUi() {
|
||||
if (mFirstTime) {
|
||||
if (mFirstTime) {
|
||||
mFirstTime = false;
|
||||
// Fill in all the values from the db in both text editor and summary
|
||||
mName.setText(mCursor.getString(NAME_INDEX));
|
||||
@@ -201,7 +212,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
mMnc.setText(mCursor.getString(MNC_INDEX));
|
||||
mApnType.setText(mCursor.getString(TYPE_INDEX));
|
||||
if (mNewApn) {
|
||||
String numeric =
|
||||
String numeric =
|
||||
SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
|
||||
// MCC is first 3 chars and then in 2 - 3 chars of MNC
|
||||
if (numeric != null && numeric.length() > 4) {
|
||||
@@ -216,8 +227,13 @@ public class ApnEditor extends PreferenceActivity
|
||||
mCurMcc = mcc;
|
||||
}
|
||||
}
|
||||
int authVal = mCursor.getInt(AUTH_TYPE_INDEX);
|
||||
if (authVal != -1) {
|
||||
mAuthType.setValueIndex(authVal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
mName.setSummary(checkNull(mName.getText()));
|
||||
mApn.setSummary(checkNull(mApn.getText()));
|
||||
mProxy.setSummary(checkNull(mProxy.getText()));
|
||||
@@ -231,6 +247,33 @@ public class ApnEditor extends PreferenceActivity
|
||||
mMcc.setSummary(checkNull(mMcc.getText()));
|
||||
mMnc.setSummary(checkNull(mMnc.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
|
||||
@@ -268,7 +311,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
switch (keyCode) {
|
||||
@@ -288,7 +331,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
validateAndSave(true);
|
||||
icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check the key fields' validity and save if valid.
|
||||
* @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 mcc = checkNotSet(mMcc.getText());
|
||||
String mnc = checkNotSet(mMnc.getText());
|
||||
|
||||
|
||||
String errorMsg = null;
|
||||
if (name.length() < 1) {
|
||||
errorMsg = mRes.getString(R.string.error_name_empty);
|
||||
@@ -311,20 +354,20 @@ public class ApnEditor extends PreferenceActivity
|
||||
} else if ((mnc.length() & 0xFFFE) != 2) {
|
||||
errorMsg = mRes.getString(R.string.error_mnc_not23);
|
||||
}
|
||||
|
||||
|
||||
if (errorMsg != null && !force) {
|
||||
showErrorMessage(errorMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!mCursor.moveToFirst()) {
|
||||
Log.w(TAG,
|
||||
"Could not go to the first row in the Cursor when saving data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(Telephony.Carriers.NAME, name);
|
||||
values.put(Telephony.Carriers.APN, apn);
|
||||
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.SERVER, checkNotSet(mServer.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.MCC, mcc);
|
||||
values.put(Telephony.Carriers.MNC, mnc);
|
||||
|
||||
|
||||
values.put(Telephony.Carriers.NUMERIC, mcc + mnc);
|
||||
|
||||
|
||||
if (mCurMnc != null && mCurMcc != null) {
|
||||
if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc)) {
|
||||
values.put(Telephony.Carriers.CURRENT, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getContentResolver().update(mUri, values, null, null);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -365,7 +414,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
getContentResolver().delete(mUri, null, null);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
private String starify(String value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return sNotSet;
|
||||
@@ -377,7 +426,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
return new String(password);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String checkNull(String value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return sNotSet;
|
||||
@@ -385,7 +434,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String checkNotSet(String value) {
|
||||
if (value == null || value.equals(sNotSet)) {
|
||||
return "";
|
||||
@@ -393,7 +442,7 @@ public class ApnEditor extends PreferenceActivity
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Preference pref = findPreference(key);
|
||||
if (pref != null) {
|
||||
|
Reference in New Issue
Block a user