summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2010-10-15 12:54:40 -0700
committerDianne Hackborn <hackbod@google.com>2010-10-15 14:46:33 -0700
commit8bdf5935c0db4a66ab33a10b43398d2523cfa15d (patch)
tree5483e26cd1fb2de239b2f01f3d35c52aeeb7b598
parentefb581018bbede2ecdc76bcd9722ded5b6903254 (diff)
downloadframeworks_base-8bdf5935c0db4a66ab33a10b43398d2523cfa15d.zip
frameworks_base-8bdf5935c0db4a66ab33a10b43398d2523cfa15d.tar.gz
frameworks_base-8bdf5935c0db4a66ab33a10b43398d2523cfa15d.tar.bz2
Work on issue #3101415: Crespo apps seem to have their UID changed over time.
fsync! Change-Id: Ie6c5397202579935ac69bf61d3e7b3081ecf269c
-rw-r--r--core/java/android/app/ContextImpl.java1
-rw-r--r--core/java/android/os/FileUtils.java24
-rw-r--r--core/java/com/android/internal/os/AtomicFile.java3
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java2
-rw-r--r--keystore/java/android/security/SystemKeyStore.java1
-rw-r--r--services/java/com/android/server/BatteryService.java3
-rw-r--r--services/java/com/android/server/DropBoxManagerService.java5
-rw-r--r--services/java/com/android/server/PackageManagerService.java16
-rw-r--r--services/java/com/android/server/WallpaperManagerService.java2
-rw-r--r--services/java/com/android/server/am/ActivityManagerService.java1
-rw-r--r--services/java/com/android/server/am/UsageStatsService.java3
11 files changed, 52 insertions, 9 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index fda08f6..2dd5819 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -3140,6 +3140,7 @@ class ContextImpl extends Context {
return;
}
XmlUtils.writeMapXml(mcr.mapToWriteToDisk, str);
+ FileUtils.sync(str);
str.close();
setFilePermissionsFromMode(mFile.getPath(), mMode, 0);
FileStatus stat = new FileStatus();
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java
index a17b7fe..9b57873 100644
--- a/core/java/android/os/FileUtils.java
+++ b/core/java/android/os/FileUtils.java
@@ -91,7 +91,22 @@ public class FileUtils
* @return volume ID or -1
*/
public static native int getFatVolumeId(String mountPoint);
-
+
+ /**
+ * Perform an fsync on the given FileOutputStream. The stream at this
+ * point must be flushed but not yet closed.
+ */
+ public static boolean sync(FileOutputStream stream) {
+ try {
+ if (stream != null) {
+ stream.getFD().sync();
+ }
+ return true;
+ } catch (IOException e) {
+ }
+ return false;
+ }
+
// copy a file from srcFile to destFile, return true if succeed, return
// false if fail
public static boolean copyFile(File srcFile, File destFile) {
@@ -118,7 +133,7 @@ public class FileUtils
if (destFile.exists()) {
destFile.delete();
}
- OutputStream out = new FileOutputStream(destFile);
+ FileOutputStream out = new FileOutputStream(destFile);
try {
byte[] buffer = new byte[4096];
int bytesRead;
@@ -126,6 +141,11 @@ public class FileUtils
out.write(buffer, 0, bytesRead);
}
} finally {
+ out.flush();
+ try {
+ out.getFD().sync();
+ } catch (IOException e) {
+ }
out.close();
}
return true;
diff --git a/core/java/com/android/internal/os/AtomicFile.java b/core/java/com/android/internal/os/AtomicFile.java
index e675ef0..b093977 100644
--- a/core/java/com/android/internal/os/AtomicFile.java
+++ b/core/java/com/android/internal/os/AtomicFile.java
@@ -77,6 +77,7 @@ public class AtomicFile {
public void finishWrite(FileOutputStream str) {
if (str != null) {
+ FileUtils.sync(str);
try {
str.close();
mBackupName.delete();
@@ -88,6 +89,7 @@ public class AtomicFile {
public void failWrite(FileOutputStream str) {
if (str != null) {
+ FileUtils.sync(str);
try {
str.close();
mBaseName.delete();
@@ -109,6 +111,7 @@ public class AtomicFile {
public void truncate() throws IOException {
try {
FileOutputStream fos = new FileOutputStream(mBaseName);
+ FileUtils.sync(fos);
fos.close();
} catch (FileNotFoundException e) {
throw new IOException("Couldn't append " + mBaseName);
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index a9e5052..36acb85 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothHeadset;
import android.net.TrafficStats;
import android.os.BatteryManager;
import android.os.BatteryStats;
+import android.os.FileUtils;
import android.os.Handler;
import android.os.Message;
import android.os.Parcel;
@@ -4482,6 +4483,7 @@ public final class BatteryStatsImpl extends BatteryStats {
FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite());
stream.write(next.marshall());
stream.flush();
+ FileUtils.sync(stream);
stream.close();
mFile.commit();
} catch (IOException e) {
diff --git a/keystore/java/android/security/SystemKeyStore.java b/keystore/java/android/security/SystemKeyStore.java
index 1093219..47718e6 100644
--- a/keystore/java/android/security/SystemKeyStore.java
+++ b/keystore/java/android/security/SystemKeyStore.java
@@ -94,6 +94,7 @@ public class SystemKeyStore {
FileOutputStream fos = new FileOutputStream(keyFile);
fos.write(retKey);
fos.flush();
+ FileUtils.sync(fos);
fos.close();
FileUtils.setPermissions(keyFile.getName(), (FileUtils.S_IRUSR | FileUtils.S_IWUSR),
-1, -1);
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index e6c32d9..fc4e06f 100644
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -26,6 +26,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.BatteryManager;
import android.os.Binder;
+import android.os.FileUtils;
import android.os.IBinder;
import android.os.DropBoxManager;
import android.os.RemoteException;
@@ -384,7 +385,7 @@ class BatteryService extends Binder {
dumpFile = new File(DUMPSYS_DATA_PATH + BATTERY_STATS_SERVICE_NAME + ".dump");
dumpStream = new FileOutputStream(dumpFile);
batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
- dumpStream.getFD().sync();
+ FileUtils.sync(dumpStream);
// add dump file to drop box
db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
diff --git a/services/java/com/android/server/DropBoxManagerService.java b/services/java/com/android/server/DropBoxManagerService.java
index 9829f9a..0e45145 100644
--- a/services/java/com/android/server/DropBoxManagerService.java
+++ b/services/java/com/android/server/DropBoxManagerService.java
@@ -26,6 +26,7 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.os.Debug;
import android.os.DropBoxManager;
+import android.os.FileUtils;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.StatFs;
@@ -183,7 +184,8 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
int bufferSize = mBlockSize;
if (bufferSize > 4096) bufferSize = 4096;
if (bufferSize < 512) bufferSize = 512;
- output = new BufferedOutputStream(new FileOutputStream(temp), bufferSize);
+ FileOutputStream foutput = new FileOutputStream(temp);
+ output = new BufferedOutputStream(foutput, bufferSize);
if (read == buffer.length && ((flags & DropBoxManager.IS_GZIPPED) == 0)) {
output = new GZIPOutputStream(output);
flags = flags | DropBoxManager.IS_GZIPPED;
@@ -200,6 +202,7 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
read = input.read(buffer);
if (read <= 0) {
+ FileUtils.sync(foutput);
output.close(); // Get a final size measurement
output = null;
} else {
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 174b3ef..cc7a027 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -5955,8 +5955,8 @@ class PackageManagerService extends IPackageManager.Stub {
private void extractPublicFiles(PackageParser.Package newPackage,
File publicZipFile) throws IOException {
- final ZipOutputStream publicZipOutStream =
- new ZipOutputStream(new FileOutputStream(publicZipFile));
+ final FileOutputStream fstr = new FileOutputStream(publicZipFile);
+ final ZipOutputStream publicZipOutStream = new ZipOutputStream(fstr);
final ZipFile privateZip = new ZipFile(newPackage.mPath);
// Copy manifest, resources.arsc and res directory to public zip
@@ -5981,6 +5981,9 @@ class PackageManagerService extends IPackageManager.Stub {
}
}
+ publicZipOutStream.finish();
+ publicZipOutStream.flush();
+ FileUtils.sync(fstr);
publicZipOutStream.close();
FileUtils.setPermissions(
publicZipFile.getAbsolutePath(),
@@ -8482,8 +8485,8 @@ class PackageManagerService extends IPackageManager.Stub {
mPastSignatures.clear();
try {
- BufferedOutputStream str = new BufferedOutputStream(new FileOutputStream(
- mSettingsFilename));
+ FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
+ BufferedOutputStream str = new BufferedOutputStream(fstr);
//XmlSerializer serializer = XmlUtils.serializerInstance();
XmlSerializer serializer = new FastXmlSerializer();
@@ -8564,6 +8567,7 @@ class PackageManagerService extends IPackageManager.Stub {
serializer.endDocument();
str.flush();
+ FileUtils.sync(fstr);
str.close();
// New settings successfully written, old ones are no longer
@@ -8580,7 +8584,8 @@ class PackageManagerService extends IPackageManager.Stub {
File tempFile = new File(mPackageListFilename.toString() + ".tmp");
JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
- str = new BufferedOutputStream(new FileOutputStream(journal.chooseForWrite()));
+ fstr = new FileOutputStream(journal.chooseForWrite());
+ str = new BufferedOutputStream(fstr);
try {
StringBuilder sb = new StringBuilder();
for (PackageSetting pkg : mPackages.values()) {
@@ -8616,6 +8621,7 @@ class PackageManagerService extends IPackageManager.Stub {
str.write(sb.toString().getBytes());
}
str.flush();
+ FileUtils.sync(fstr);
str.close();
journal.commit();
}
diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java
index c837a3a..859c85c 100644
--- a/services/java/com/android/server/WallpaperManagerService.java
+++ b/services/java/com/android/server/WallpaperManagerService.java
@@ -35,6 +35,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Binder;
import android.os.Bundle;
+import android.os.FileUtils;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.FileObserver;
@@ -836,6 +837,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
} catch (IOException ex) {}
}
if (fos != null) {
+ FileUtils.sync(fos);
try {
fos.close();
} catch (IOException ex) {}
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 9c06c33..7eb295b 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -6074,6 +6074,7 @@ public final class ActivityManagerService extends ActivityManagerNative
Slog.w(TAG, "Failure writing last done pre-boot receivers", e);
file.delete();
} finally {
+ FileUtils.sync(fos);
if (dos != null) {
try {
dos.close();
diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java
index 8463b5a..6e8f248 100644
--- a/services/java/com/android/server/am/UsageStatsService.java
+++ b/services/java/com/android/server/am/UsageStatsService.java
@@ -23,6 +23,8 @@ import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import com.android.internal.os.PkgUsageStats;
+
+import android.os.FileUtils;
import android.os.Parcel;
import android.os.Process;
import android.os.ServiceManager;
@@ -471,6 +473,7 @@ public final class UsageStatsService extends IUsageStats.Stub {
out.recycle();
stream.flush();
} finally {
+ FileUtils.sync(stream);
stream.close();
}
}