am cee0b97e: Merge "Free AssetManager weak refs before unmounting" into gingerbread

Merge commit 'cee0b97eed0a460e2da58500e24d3e4dac5cb9f6' into gingerbread-plus-aosp

* commit 'cee0b97eed0a460e2da58500e24d3e4dac5cb9f6':
  Free AssetManager weak refs before unmounting
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index f83119f..131dded 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -826,6 +826,15 @@
         if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) {
             return VoldResponseCode.OpFailedVolNotMounted;
         }
+
+        /*
+         * Force a GC to make sure AssetManagers in other threads of the
+         * system_server are cleaned up. We have to do this since AssetManager
+         * instances are kept as a WeakReference and it's possible we have files
+         * open on the external storage.
+         */
+        Runtime.getRuntime().gc();
+
         // Redundant probably. But no harm in updating state again.
         mPms.updateExternalMediaStatus(false, false);
         try {
@@ -1277,6 +1286,14 @@
         waitForReady();
         warnOnNotMounted();
 
+        /*
+         * Force a GC to make sure AssetManagers in other threads of the
+         * system_server are cleaned up. We have to do this since AssetManager
+         * instances are kept as a WeakReference and it's possible we have files
+         * open on the external storage.
+         */
+        Runtime.getRuntime().gc();
+
         int rc = StorageResultCode.OperationSucceeded;
         try {
             mConnector.doCommand(String.format("asec destroy %s%s", id, (force ? " force" : "")));
@@ -1341,6 +1358,14 @@
             }
          }
 
+        /*
+         * Force a GC to make sure AssetManagers in other threads of the
+         * system_server are cleaned up. We have to do this since AssetManager
+         * instances are kept as a WeakReference and it's possible we have files
+         * open on the external storage.
+         */
+        Runtime.getRuntime().gc();
+
         int rc = StorageResultCode.OperationSucceeded;
         String cmd = String.format("asec unmount %s%s", id, (force ? " force" : ""));
         try {