OSDN Git Service

Work on issue #3101415: Crespo apps seem to have their UID changed over time.
authorDianne Hackborn <hackbod@google.com>
Fri, 15 Oct 2010 19:54:40 +0000 (12:54 -0700)
committerDianne Hackborn <hackbod@google.com>
Fri, 15 Oct 2010 21:46:33 +0000 (14:46 -0700)
fsync!

Change-Id: Ie6c5397202579935ac69bf61d3e7b3081ecf269c

core/java/android/app/ContextImpl.java
core/java/android/os/FileUtils.java
core/java/com/android/internal/os/AtomicFile.java
core/java/com/android/internal/os/BatteryStatsImpl.java
keystore/java/android/security/SystemKeyStore.java
services/java/com/android/server/BatteryService.java
services/java/com/android/server/DropBoxManagerService.java
services/java/com/android/server/PackageManagerService.java
services/java/com/android/server/WallpaperManagerService.java
services/java/com/android/server/am/ActivityManagerService.java
services/java/com/android/server/am/UsageStatsService.java

index fda08f6..2dd5819 100644 (file)
@@ -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();
index a17b7fe..9b57873 100644 (file)
@@ -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;
index e675ef0..b093977 100644 (file)
@@ -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);
index a9e5052..36acb85 100644 (file)
@@ -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) {
index 1093219..47718e6 100644 (file)
@@ -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);
index e6c32d9..fc4e06f 100644 (file)
@@ -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);
index 9829f9a..0e45145 100644 (file)
@@ -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 {
index 174b3ef..cc7a027 100644 (file)
@@ -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();
                 }
index c837a3a..859c85c 100644 (file)
@@ -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) {}
index 9c06c33..7eb295b 100644 (file)
@@ -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();
index 8463b5a..6e8f248 100644 (file)
@@ -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();
         }
     }