diff options
| author | 2011-05-04 08:57:12 -0700 | |
|---|---|---|
| committer | 2011-05-04 08:57:12 -0700 | |
| commit | 2572051c4f6589e5ca8b21158a24a7fa606a5e67 (patch) | |
| tree | 64cbd050402aede01867443e9ad93ad9ddeb46cd | |
| parent | a2a8419db82ae40146bdfd215e3de3be39c7249c (diff) | |
| parent | 0aa5d7b7f225236ac8461d0b6835b9c6152a2699 (diff) | |
am 0aa5d7b7: DO NOT MERGE Fix deadlock in MountService
* commit '0aa5d7b7f225236ac8461d0b6835b9c6152a2699':
DO NOT MERGE Fix deadlock in MountService
| -rw-r--r-- | services/java/com/android/server/MountService.java | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index a528aa36d365..de23823b32cf 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -444,31 +444,46 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC * to make the media scanner run. */ if ("simulator".equals(SystemProperties.get("ro.product.device"))) { - notifyVolumeStateChange(null, "/sdcard", VolumeState.NoMedia, VolumeState.Mounted); + notifyVolumeStateChange(null, "/sdcard", VolumeState.NoMedia, + VolumeState.Mounted); return; } new Thread() { @Override public void run() { try { + // it is not safe to call vold with mVolumeStates locked + // so we make a copy of the paths and states and process them + // outside the lock + String[] paths, states; + int count; synchronized (mVolumeStates) { - for (String path : mVolumeStates.keySet()) { - String state = mVolumeStates.get(path); - - if (state.equals(Environment.MEDIA_UNMOUNTED)) { - int rc = doMountVolume(path); - if (rc != StorageResultCode.OperationSucceeded) { - Slog.e(TAG, String.format("Boot-time mount failed (%d)", - rc)); - } - } else if (state.equals(Environment.MEDIA_SHARED)) { - /* - * Bootstrap UMS enabled state since vold indicates - * the volume is shared (runtime restart while ums enabled) - */ - notifyVolumeStateChange(null, path, VolumeState.NoMedia, - VolumeState.Shared); + Set<String> keys = mVolumeStates.keySet(); + count = keys.size(); + paths = (String[])keys.toArray(new String[count]); + states = new String[count]; + for (int i = 0; i < count; i++) { + states[i] = mVolumeStates.get(paths[i]); + } + } + + for (int i = 0; i < count; i++) { + String path = paths[i]; + String state = states[i]; + + if (state.equals(Environment.MEDIA_UNMOUNTED)) { + int rc = doMountVolume(path); + if (rc != StorageResultCode.OperationSucceeded) { + Slog.e(TAG, String.format("Boot-time mount failed (%d)", + rc)); } + } else if (state.equals(Environment.MEDIA_SHARED)) { + /* + * Bootstrap UMS enabled state since vold indicates + * the volume is shared (runtime restart while ums enabled) + */ + notifyVolumeStateChange(null, path, VolumeState.NoMedia, + VolumeState.Shared); } } |