summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2010-09-14 14:49:41 -0700
committerKenny Root <kroot@google.com>2010-09-14 14:49:41 -0700
commitaa48540222ef11115b29b8d7f2b7bd1ece772418 (patch)
tree985a28185e02c467f4685798c65653ac1cd69839
parente7b92d7b53343119173558302ecfb3986ae0fbd6 (diff)
downloadframeworks_base-aa48540222ef11115b29b8d7f2b7bd1ece772418.zip
frameworks_base-aa48540222ef11115b29b8d7f2b7bd1ece772418.tar.gz
frameworks_base-aa48540222ef11115b29b8d7f2b7bd1ece772418.tar.bz2
Free AssetManager weak refs before unmounting
AssetManagers are kept in WeakReference pools so there's a change another thread in the system_server has opened a file on the external card. Attempt to force a garbage collection to free these references each time we're about to unmount a volume on the external storage. Change-Id: I6e816e8c67b179887e488dc6758b43bcdd5914fb
-rw-r--r--services/java/com/android/server/MountService.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index 6e8b42e..cfba07a 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -826,6 +826,15 @@ class MountService extends IMountService.Stub
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 @@ class MountService extends IMountService.Stub
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 @@ class MountService extends IMountService.Stub
}
}
+ /*
+ * 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 {