From 7fa24aa8da3d2ab22b3a7d53fe64d14c31c076b8 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Wed, 23 Mar 2011 14:52:34 -0400 Subject: MountService: Add support for multiple volumes Change-Id: I4eaa781cf302c7aaae170af2489b6b29120c0b81 Signed-off-by: Mike Lockwood --- services/java/com/android/server/MountService.java | 219 +++++++++++---------- 1 file changed, 111 insertions(+), 108 deletions(-) diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index 4e80147..59f0852 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -148,7 +148,8 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC private Context mContext; private NativeDaemonConnector mConnector; - private String mLegacyState = Environment.MEDIA_REMOVED; + private final HashMap mVolumeStates = new HashMap(); + private String mExternalStoragePath; private PackageManagerService mPms; private boolean mUmsEnabling; // Used as a lock for methods that register/unregister listeners. @@ -453,22 +454,25 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC @Override public void run() { try { - String path = Environment.getExternalStorageDirectory().getPath(); - String state = getVolumeState(path); - - if (mEmulateExternalStorage) { - notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Mounted); - } else 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)); + 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); + } } - } 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); } /* @@ -519,35 +523,36 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC } private void updatePublicVolumeState(String path, String state) { - if (!path.equals(Environment.getExternalStorageDirectory().getPath())) { - Slog.w(TAG, "Multiple volumes not currently supported"); - return; + String oldState; + synchronized(mVolumeStates) { + oldState = mVolumeStates.put(path, state); } - - if (mLegacyState.equals(state)) { - Slog.w(TAG, String.format("Duplicate state transition (%s -> %s)", mLegacyState, state)); + if (state.equals(oldState)) { + Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s", + state, state, path)); return; } - // Update state on PackageManager, but only of real events - if (!mEmulateExternalStorage) { - if (Environment.MEDIA_UNMOUNTED.equals(state)) { - mPms.updateExternalMediaStatus(false, false); - /* - * Some OBBs might have been unmounted when this volume was - * unmounted, so send a message to the handler to let it know to - * remove those from the list of mounted OBBS. - */ - mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_FLUSH_MOUNT_STATE, - path)); - } else if (Environment.MEDIA_MOUNTED.equals(state)) { - mPms.updateExternalMediaStatus(true, false); - } - } + Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")"); - String oldState = mLegacyState; - mLegacyState = state; + if (path.equals(mExternalStoragePath)) { + // Update state on PackageManager, but only of real events + if (!mEmulateExternalStorage) { + if (Environment.MEDIA_UNMOUNTED.equals(state)) { + mPms.updateExternalMediaStatus(false, false); + /* + * Some OBBs might have been unmounted when this volume was + * unmounted, so send a message to the handler to let it know to + * remove those from the list of mounted OBBS. + */ + mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage( + OBB_FLUSH_MOUNT_STATE, path)); + } else if (Environment.MEDIA_MOUNTED.equals(state)) { + mPms.updateExternalMediaStatus(true, false); + } + } + } synchronized (mListeners) { for (int i = mListeners.size() -1; i >= 0; i--) { MountServiceBinderListener bl = mListeners.get(i); @@ -578,20 +583,15 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC /** * Determine media state and UMS detection status */ - String path = Environment.getExternalStorageDirectory().getPath(); - String state = Environment.MEDIA_REMOVED; - try { String[] vols = mConnector.doListCommand( "volume list", VoldResponseCode.VolumeListResult); for (String volstr : vols) { String[] tok = volstr.split(" "); // FMT: