Merge "[don't auto-merge] Don't re-read SharedPreferences unnecessarily." into gingerbread

This commit is contained in:
Brad Fitzpatrick
2010-12-01 08:46:52 -08:00
committed by Android (Google) Code Review

View File

@@ -367,7 +367,8 @@ class ContextImpl extends Context {
} }
Map map = null; Map map = null;
if (prefsFile.exists() && prefsFile.canRead()) { FileStatus stat = new FileStatus();
if (FileUtils.getFileStatus(prefsFile.getPath(), stat) && prefsFile.canRead()) {
try { try {
FileInputStream str = new FileInputStream(prefsFile); FileInputStream str = new FileInputStream(prefsFile);
map = XmlUtils.readMapXml(str); map = XmlUtils.readMapXml(str);
@@ -380,7 +381,7 @@ class ContextImpl extends Context {
Log.w(TAG, "getSharedPreferences", e); Log.w(TAG, "getSharedPreferences", e);
} }
} }
sp.replace(map); sp.replace(map, stat);
} }
return sp; return sp;
} }
@@ -2768,12 +2769,16 @@ class ContextImpl extends Context {
} }
} }
public void replace(Map newContents) { /* package */ void replace(Map newContents, FileStatus stat) {
synchronized (this) { synchronized (this) {
mLoaded = true; mLoaded = true;
if (newContents != null) { if (newContents != null) {
mMap = newContents; mMap = newContents;
} }
if (stat != null) {
mStatTimestamp = stat.mtime;
mStatSize = stat.size;
}
} }
} }