From 4d31288fe30b2e8f2e0a5ff54b402912fd830df1 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Wed, 28 Oct 2009 16:59:17 -0700 Subject: [PATCH] Fix for 1974140. Delete entry if not valid on hitting home. If user doesn't enter an APN or name, then delete the entry on hitting home. And if user has enough information but doesn't enter a name, then set the name to "Untitled" to avoid blank APNs in the list. --- AndroidManifest.xml | 2 +- res/values/strings.xml | 3 +++ src/com/android/settings/ApnEditor.java | 24 ++++++++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6ddd679bd2f..fd53b958adb 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -105,7 +105,7 @@ diff --git a/res/values/strings.xml b/res/values/strings.xml index b01608a736c..9ec279261fd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2144,4 +2144,7 @@ found in the list of installed applications. Settings backup Are you sure you want to stop backing up your settings and erase all copies on Google servers? + + + Untitled diff --git a/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java index 0e7ab5efd30..62856d119e7 100644 --- a/src/com/android/settings/ApnEditor.java +++ b/src/com/android/settings/ApnEditor.java @@ -150,7 +150,7 @@ public class ApnEditor extends PreferenceActivity if (action.equals(Intent.ACTION_EDIT)) { mUri = intent.getData(); } else if (action.equals(Intent.ACTION_INSERT)) { - if (mFirstTime) { + if (mFirstTime || icicle.getInt(SAVED_POS) == 0) { mUri = getContentResolver().insert(intent.getData(), new ContentValues()); } else { mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, @@ -185,12 +185,14 @@ public class ApnEditor extends PreferenceActivity @Override public void onResume() { super.onResume(); - getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); } @Override public void onPause() { - getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); super.onPause(); } @@ -328,8 +330,9 @@ public class ApnEditor extends PreferenceActivity @Override protected void onSaveInstanceState(Bundle icicle) { super.onSaveInstanceState(icicle); - validateAndSave(true); - icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX)); + if (validateAndSave(true)) { + icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX)); + } } /** @@ -366,9 +369,18 @@ public class ApnEditor extends PreferenceActivity return false; } + // If it's a new APN and a name or apn haven't been entered, then erase the entry + if (force && mNewApn && name.length() < 1 && apn.length() < 1) { + getContentResolver().delete(mUri, null, null); + return false; + } + ContentValues values = new ContentValues(); - values.put(Telephony.Carriers.NAME, name); + // Add a dummy name "Untitled", if the user exits the screen without adding a name but + // entered other information worth keeping. + values.put(Telephony.Carriers.NAME, + name.length() < 1 ? getResources().getString(R.string.untitled_apn) : name); values.put(Telephony.Carriers.APN, apn); values.put(Telephony.Carriers.PROXY, checkNotSet(mProxy.getText())); values.put(Telephony.Carriers.PORT, checkNotSet(mPort.getText()));