summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ContextImpl.java12
-rw-r--r--core/java/android/content/Context.java27
-rw-r--r--core/java/android/content/ContextWrapper.java11
-rw-r--r--core/java/android/preference/PreferenceManager.java8
4 files changed, 39 insertions, 19 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 23c4198e348f..a703c531b1c3 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -321,11 +321,6 @@ class ContextImpl extends Context {
}
@Override
- public File getSharedPrefsFile(String name) {
- return makeFilename(getPreferencesDir(), name + ".xml");
- }
-
- @Override
public SharedPreferences getSharedPreferences(String name, int mode) {
// At least one application in the world actually passes in a null
// name. This happened to work because when we generated the file name
@@ -337,7 +332,7 @@ class ContextImpl extends Context {
}
}
- final File file = getSharedPrefsFile(name);
+ final File file = getSharedPreferencesPath(name);
return getSharedPreferences(file, mode);
}
@@ -571,6 +566,11 @@ class ContextImpl extends Context {
}
@Override
+ public File getSharedPreferencesPath(String name) {
+ return makeFilename(getPreferencesDir(), name + ".xml");
+ }
+
+ @Override
public String[] fileList() {
final String[] list = getFilesDir().list();
return (list != null) ? list : EMPTY_STRING_ARRAY;
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 6cc549745f66..4c7e853491cc 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -606,13 +606,13 @@ public abstract class Context {
public abstract String getPackageCodePath();
/**
- * {@hide}
- * Return the full path to the shared prefs file for the given prefs group name.
- *
- * <p>Note: this is not generally useful for applications, since they should
- * not be directly accessing the file system.
+ * @hide
+ * @deprecated use {@link #getSharedPreferencesPath(String)}
*/
- public abstract File getSharedPrefsFile(String name);
+ @Deprecated
+ public File getSharedPrefsFile(String name) {
+ return getSharedPreferencesPath(name);
+ }
/**
* Retrieve and hold the contents of the preferences file 'name', returning
@@ -654,6 +654,7 @@ public abstract class Context {
* @return The single {@link SharedPreferences} instance that can be used
* to retrieve and modify the preference values.
*
+ * @see #getSharedPreferencesPath(String)
* @see #MODE_PRIVATE
* @see #MODE_WORLD_READABLE
* @see #MODE_WORLD_WRITEABLE
@@ -739,6 +740,20 @@ public abstract class Context {
public abstract File getFileStreamPath(String name);
/**
+ * Returns the absolute path on the filesystem where a file created with
+ * {@link #getSharedPreferences(String, int)} is stored.
+ * <p>
+ * The returned path may change over time if the calling app is moved to an
+ * adopted storage device, so only relative paths should be persisted.
+ *
+ * @param name The name of the shared preferences for which you would like
+ * to get a path.
+ * @return An absolute path to the given file.
+ * @see #getSharedPreferences(String, int)
+ */
+ public abstract File getSharedPreferencesPath(String name);
+
+ /**
* Returns the absolute path to the directory on the filesystem where files
* created with {@link #openFileOutput} are stored.
* <p>
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index a345aae27205..f5e915989cad 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -160,12 +160,6 @@ public class ContextWrapper extends Context {
return mBase.getPackageCodePath();
}
- /** @hide */
- @Override
- public File getSharedPrefsFile(String name) {
- return mBase.getSharedPrefsFile(name);
- }
-
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
return mBase.getSharedPreferences(name, mode);
@@ -199,6 +193,11 @@ public class ContextWrapper extends Context {
}
@Override
+ public File getSharedPreferencesPath(String name) {
+ return mBase.getSharedPreferencesPath(name);
+ }
+
+ @Override
public String[] fileList() {
return mBase.fileList();
}
diff --git a/core/java/android/preference/PreferenceManager.java b/core/java/android/preference/PreferenceManager.java
index 4e4b1c90eca9..fda632689c28 100644
--- a/core/java/android/preference/PreferenceManager.java
+++ b/core/java/android/preference/PreferenceManager.java
@@ -371,7 +371,13 @@ public class PreferenceManager {
getDefaultSharedPreferencesMode());
}
- private static String getDefaultSharedPreferencesName(Context context) {
+ /**
+ * Returns the name used for storing default shared preferences.
+ *
+ * @see #getDefaultSharedPreferences(Context)
+ * @see Context#getSharedPreferencesPath(String)
+ */
+ public static String getDefaultSharedPreferencesName(Context context) {
return context.getPackageName() + "_preferences";
}