[don't auto-merge] Don't re-read SharedPreferences unnecessarily.
Bug: 3211034
Bug: 3216290
Change-Id: Idd5cc25965d400f20122372ca1cf47d4703dd87c
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 2dd5819..5998074 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -367,7 +367,8 @@
}
Map map = null;
- if (prefsFile.exists() && prefsFile.canRead()) {
+ FileStatus stat = new FileStatus();
+ if (FileUtils.getFileStatus(prefsFile.getPath(), stat) && prefsFile.canRead()) {
try {
FileInputStream str = new FileInputStream(prefsFile);
map = XmlUtils.readMapXml(str);
@@ -380,7 +381,7 @@
Log.w(TAG, "getSharedPreferences", e);
}
}
- sp.replace(map);
+ sp.replace(map, stat);
}
return sp;
}
@@ -2768,12 +2769,16 @@
}
}
- public void replace(Map newContents) {
+ /* package */ void replace(Map newContents, FileStatus stat) {
synchronized (this) {
mLoaded = true;
if (newContents != null) {
mMap = newContents;
}
+ if (stat != null) {
+ mStatTimestamp = stat.mtime;
+ mStatSize = stat.size;
+ }
}
}