summaryrefslogtreecommitdiffstats
path: root/core/java/android/preference
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-10-10 10:58:47 -0700
committerBrad Fitzpatrick <bradfitz@android.com>2010-10-10 15:26:24 -0700
commitdd644c179c1bf47d82d776d7f644e4fc1467159d (patch)
treed566c1c17f2b325e3760a34ca10cf71d965893f2 /core/java/android/preference
parent4e1658afb8a79aa03a5ca712b02b2a33fb00bf6d (diff)
downloadframeworks_base-dd644c179c1bf47d82d776d7f644e4fc1467159d.zip
frameworks_base-dd644c179c1bf47d82d776d7f644e4fc1467159d.tar.gz
frameworks_base-dd644c179c1bf47d82d776d7f644e4fc1467159d.tar.bz2
Fallback to SharedPreferences$Editor.commit() when no apply() exists.
Gingerbread widened the SharedPreferences.Editor interface, adding an apply() method. Most people don't implement this interface themselves, but a couple apps do. A few spots in the core framework take a SharedPreferences[.Editor] from apps, which might be a pre-Gingerbread implementation without an apply() method. This patch makes sure we never depend on the presence of an apply() method, falling back to commit() if apply() isn't available. Change-Id: I32693ac9227a60b694526a26a30234fb17a40581
Diffstat (limited to 'core/java/android/preference')
-rw-r--r--core/java/android/preference/Preference.java9
-rw-r--r--core/java/android/preference/PreferenceManager.java25
2 files changed, 28 insertions, 6 deletions
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index dde6493..36d676a 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -1195,7 +1195,14 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
private void tryCommit(SharedPreferences.Editor editor) {
if (mPreferenceManager.shouldCommit()) {
- editor.apply();
+ try {
+ editor.apply();
+ } catch (AbstractMethodError unused) {
+ // The app injected its own pre-Gingerbread
+ // SharedPreferences.Editor implementation without
+ // an apply method.
+ editor.commit();
+ }
}
}
diff --git a/core/java/android/preference/PreferenceManager.java b/core/java/android/preference/PreferenceManager.java
index fa83897..e44a090 100644
--- a/core/java/android/preference/PreferenceManager.java
+++ b/core/java/android/preference/PreferenceManager.java
@@ -443,7 +443,16 @@ public class PreferenceManager {
pm.setSharedPreferencesMode(sharedPreferencesMode);
pm.inflateFromResource(context, resId, null);
- defaultValueSp.edit().putBoolean(KEY_HAS_SET_DEFAULT_VALUES, true).apply();
+ SharedPreferences.Editor editor =
+ defaultValueSp.edit().putBoolean(KEY_HAS_SET_DEFAULT_VALUES, true);
+ try {
+ editor.apply();
+ } catch (AbstractMethodError unused) {
+ // The app injected its own pre-Gingerbread
+ // SharedPreferences.Editor implementation without
+ // an apply method.
+ editor.commit();
+ }
}
}
@@ -478,15 +487,21 @@ public class PreferenceManager {
boolean shouldCommit() {
return !mNoCommit;
}
-
+
private void setNoCommit(boolean noCommit) {
if (!noCommit && mEditor != null) {
- mEditor.apply();
+ try {
+ mEditor.apply();
+ } catch (AbstractMethodError unused) {
+ // The app injected its own pre-Gingerbread
+ // SharedPreferences.Editor implementation without
+ // an apply method.
+ mEditor.commit();
+ }
}
-
mNoCommit = noCommit;
}
-
+
/**
* Returns the activity that shows the preferences. This is useful for doing
* managed queries, but in most cases the use of {@link #getContext()} is