summaryrefslogtreecommitdiffstats
path: root/core/java/com
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2009-09-29 15:20:32 -0700
committerSuchi Amalapurapu <asuchitra@google.com>2009-09-30 15:36:29 -0700
commit8550f255232eb4e4852466c5297fdc125887f5af (patch)
tree7c5388e75ee4f5596c7e797370bbace5cd22072a /core/java/com
parenta33e3f79259b56b03c7912af35944f34ad190e3c (diff)
downloadframeworks_base-8550f255232eb4e4852466c5297fdc125887f5af.zip
frameworks_base-8550f255232eb4e4852466c5297fdc125887f5af.tar.gz
frameworks_base-8550f255232eb4e4852466c5297fdc125887f5af.tar.bz2
Check if rename of backed up file fails before persisting new changes.
If not these system services will end up with inconsistent settings files when the device runs out of storage. Delete mangled settings file in PackageManager if the current write fails so that we don't end up overwriting the backed up version with the mangled version Include null check when retrieving fwd locked resource for an existing package
Diffstat (limited to 'core/java/com')
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 7a8a3be..4b26b8f 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -2988,7 +2988,10 @@ public final class BatteryStatsImpl extends BatteryStats {
if (mBackupFile.exists()) {
mBackupFile.delete();
}
- mFile.renameTo(mBackupFile);
+ if (!mFile.renameTo(mBackupFile)) {
+ Log.w("BatteryStats", "Failed to back up file before writing new stats");
+ return;
+ }
}
try {
@@ -3003,8 +3006,14 @@ public final class BatteryStatsImpl extends BatteryStats {
mBackupFile.delete();
mLastWriteTime = SystemClock.elapsedRealtime();
+ return;
} catch (IOException e) {
- Log.e("BatteryStats", "Error writing battery statistics", e);
+ Log.w("BatteryStats", "Error writing battery statistics", e);
+ }
+ if (mFile.exists()) {
+ if (!mFile.delete()) {
+ Log.w(TAG, "Failed to delete mangled file " + mFile);
+ }
}
}