Merge change Icb89d482 into eclair

* changes:
  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
This commit is contained in:
Android (Google) Code Review
2009-09-30 18:37:45 -04:00
5 changed files with 31 additions and 9 deletions

View File

@@ -2760,6 +2760,7 @@ class ApplicationContext extends Context {
if (mFile.exists()) {
if (!mFile.renameTo(mBackupFile)) {
Log.e(TAG, "Couldn't rename file " + mFile + " to backup file " + mBackupFile);
return false;
}
}

View File

@@ -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);
}
}
}