summaryrefslogtreecommitdiffstats
path: root/services
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 /services
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 'services')
-rw-r--r--services/java/com/android/server/AppWidgetService.java9
-rw-r--r--services/java/com/android/server/PackageManagerService.java12
-rw-r--r--services/java/com/android/server/am/UsageStatsService.java5
3 files changed, 19 insertions, 7 deletions
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java
index 3c46954..f8b8ecc 100644
--- a/services/java/com/android/server/AppWidgetService.java
+++ b/services/java/com/android/server/AppWidgetService.java
@@ -816,7 +816,10 @@ class AppWidgetService extends IAppWidgetService.Stub
temp.delete();
}
- writeStateToFileLocked(temp);
+ if (!writeStateToFileLocked(temp)) {
+ Log.w(TAG, "Failed to persist new settings");
+ return;
+ }
//noinspection ResultOfMethodCallIgnored
real.delete();
@@ -824,7 +827,7 @@ class AppWidgetService extends IAppWidgetService.Stub
temp.renameTo(real);
}
- void writeStateToFileLocked(File file) {
+ boolean writeStateToFileLocked(File file) {
FileOutputStream stream = null;
int N;
@@ -877,6 +880,7 @@ class AppWidgetService extends IAppWidgetService.Stub
out.endDocument();
stream.close();
+ return true;
} catch (IOException e) {
try {
if (stream != null) {
@@ -889,6 +893,7 @@ class AppWidgetService extends IAppWidgetService.Stub
//noinspection ResultOfMethodCallIgnored
file.delete();
}
+ return false;
}
}
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 2f16b84..5eb78c3 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -2049,7 +2049,7 @@ class PackageManagerService extends IPackageManager.Stub {
scanMode |= SCAN_FORWARD_LOCKED;
}
File resFile = destResourceFile;
- if ((scanMode & SCAN_FORWARD_LOCKED) != 0) {
+ if (ps != null && ((scanMode & SCAN_FORWARD_LOCKED) != 0)) {
resFile = getFwdLockedResource(ps.name);
}
// Note that we invoke the following method only if we are about to unpack an application
@@ -6529,15 +6529,19 @@ class PackageManagerService extends IPackageManager.Stub {
|FileUtils.S_IRGRP|FileUtils.S_IWGRP
|FileUtils.S_IROTH,
-1, -1);
+ return;
} catch(XmlPullParserException e) {
Log.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e);
-
} catch(java.io.IOException e) {
Log.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e);
-
}
-
+ // Clean up partially written file
+ if (mSettingsFilename.exists()) {
+ if (!mSettingsFilename.delete()) {
+ Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename);
+ }
+ }
//Debug.stopMethodTracing();
}
diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java
index 66868a3..373b44e 100644
--- a/services/java/com/android/server/am/UsageStatsService.java
+++ b/services/java/com/android/server/am/UsageStatsService.java
@@ -381,7 +381,10 @@ public final class UsageStatsService extends IUsageStats.Stub {
mFileLeaf = getCurrentDateStr(FILE_PREFIX);
// Copy current file to back up
File backupFile = new File(mFile.getPath() + ".bak");
- mFile.renameTo(backupFile);
+ if (!mFile.renameTo(backupFile)) {
+ Log.w(TAG, "Failed to persist new stats");
+ return;
+ }
try {
// Write mStats to file
writeStatsFLOCK();