Loading services/java/com/android/server/MountService.java +111 −108 Original line number Diff line number Diff line Loading @@ -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<String, String> mVolumeStates = new HashMap<String, String>(); private String mExternalStoragePath; private PackageManagerService mPms; private boolean mUmsEnabling; // Used as a lock for methods that register/unregister listeners. Loading Loading @@ -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); synchronized (mVolumeStates) { for (String path : mVolumeStates.keySet()) { String state = mVolumeStates.get(path); if (mEmulateExternalStorage) { notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Mounted); } else if (state.equals(Environment.MEDIA_UNMOUNTED)) { 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)); 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); notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Shared); } } } /* Loading Loading @@ -519,15 +523,19 @@ 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; } Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")"); if (path.equals(mExternalStoragePath)) { // Update state on PackageManager, but only of real events if (!mEmulateExternalStorage) { if (Environment.MEDIA_UNMOUNTED.equals(state)) { Loading @@ -538,16 +546,13 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC * 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)); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage( OBB_FLUSH_MOUNT_STATE, path)); } else if (Environment.MEDIA_MOUNTED.equals(state)) { mPms.updateExternalMediaStatus(true, false); } } String oldState = mLegacyState; mLegacyState = state; } synchronized (mListeners) { for (int i = mListeners.size() -1; i >= 0; i--) { MountServiceBinderListener bl = mListeners.get(i); Loading Loading @@ -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: <label> <mountpoint> <state> if (!tok[1].equals(path)) { Slog.w(TAG, String.format( "Skipping unknown volume '%s'",tok[1])); continue; } String path = tok[1]; String state = Environment.MEDIA_REMOVED; int st = Integer.parseInt(tok[2]); if (st == VolumeState.NoMedia) { state = Environment.MEDIA_REMOVED; Loading @@ -606,14 +606,15 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC } else { throw new Exception(String.format("Unexpected state %d", st)); } } if (state != null) { if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state); updatePublicVolumeState(path, state); } } } catch (Exception e) { Slog.e(TAG, "Error processing initial volume state", e); updatePublicVolumeState(path, Environment.MEDIA_REMOVED); updatePublicVolumeState(mExternalStoragePath, Environment.MEDIA_REMOVED); } try { Loading Loading @@ -1055,11 +1056,12 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC public MountService(Context context) { mContext = context; mExternalStoragePath = Environment.getExternalStorageDirectory().getPath(); mEmulateExternalStorage = context.getResources().getBoolean( com.android.internal.R.bool.config_emulateExternalStorage); if (mEmulateExternalStorage) { Slog.d(TAG, "using emulated external storage"); mLegacyState = Environment.MEDIA_MOUNTED; mVolumeStates.put(mExternalStoragePath, Environment.MEDIA_MOUNTED); } // XXX: This will go away soon in favor of IMountServiceObserver Loading Loading @@ -1127,9 +1129,9 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC validatePermission(android.Manifest.permission.SHUTDOWN); Slog.i(TAG, "Shutting down"); String path = Environment.getExternalStorageDirectory().getPath(); String state = getVolumeState(path); synchronized (mVolumeStates) { for (String path : mVolumeStates.keySet()) { String state = mVolumeStates.get(path); if (state.equals(Environment.MEDIA_SHARED)) { /* Loading Loading @@ -1178,6 +1180,8 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC } } } } } private boolean getUmsEnabling() { synchronized (mListeners) { Loading Loading @@ -1246,16 +1250,15 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC * @return state of the volume at the specified mount point */ public String getVolumeState(String mountPoint) { /* * XXX: Until we have multiple volume discovery, just hardwire * this to /sdcard */ if (!mountPoint.equals(Environment.getExternalStorageDirectory().getPath())) { synchronized (mVolumeStates) { String state = mVolumeStates.get(mountPoint); if (state == null) { Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume"); throw new IllegalArgumentException(); } return mLegacyState; return state; } } public boolean isExternalStorageEmulated() { Loading Loading
services/java/com/android/server/MountService.java +111 −108 Original line number Diff line number Diff line Loading @@ -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<String, String> mVolumeStates = new HashMap<String, String>(); private String mExternalStoragePath; private PackageManagerService mPms; private boolean mUmsEnabling; // Used as a lock for methods that register/unregister listeners. Loading Loading @@ -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); synchronized (mVolumeStates) { for (String path : mVolumeStates.keySet()) { String state = mVolumeStates.get(path); if (mEmulateExternalStorage) { notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Mounted); } else if (state.equals(Environment.MEDIA_UNMOUNTED)) { 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)); 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); notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Shared); } } } /* Loading Loading @@ -519,15 +523,19 @@ 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; } Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")"); if (path.equals(mExternalStoragePath)) { // Update state on PackageManager, but only of real events if (!mEmulateExternalStorage) { if (Environment.MEDIA_UNMOUNTED.equals(state)) { Loading @@ -538,16 +546,13 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC * 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)); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage( OBB_FLUSH_MOUNT_STATE, path)); } else if (Environment.MEDIA_MOUNTED.equals(state)) { mPms.updateExternalMediaStatus(true, false); } } String oldState = mLegacyState; mLegacyState = state; } synchronized (mListeners) { for (int i = mListeners.size() -1; i >= 0; i--) { MountServiceBinderListener bl = mListeners.get(i); Loading Loading @@ -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: <label> <mountpoint> <state> if (!tok[1].equals(path)) { Slog.w(TAG, String.format( "Skipping unknown volume '%s'",tok[1])); continue; } String path = tok[1]; String state = Environment.MEDIA_REMOVED; int st = Integer.parseInt(tok[2]); if (st == VolumeState.NoMedia) { state = Environment.MEDIA_REMOVED; Loading @@ -606,14 +606,15 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC } else { throw new Exception(String.format("Unexpected state %d", st)); } } if (state != null) { if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state); updatePublicVolumeState(path, state); } } } catch (Exception e) { Slog.e(TAG, "Error processing initial volume state", e); updatePublicVolumeState(path, Environment.MEDIA_REMOVED); updatePublicVolumeState(mExternalStoragePath, Environment.MEDIA_REMOVED); } try { Loading Loading @@ -1055,11 +1056,12 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC public MountService(Context context) { mContext = context; mExternalStoragePath = Environment.getExternalStorageDirectory().getPath(); mEmulateExternalStorage = context.getResources().getBoolean( com.android.internal.R.bool.config_emulateExternalStorage); if (mEmulateExternalStorage) { Slog.d(TAG, "using emulated external storage"); mLegacyState = Environment.MEDIA_MOUNTED; mVolumeStates.put(mExternalStoragePath, Environment.MEDIA_MOUNTED); } // XXX: This will go away soon in favor of IMountServiceObserver Loading Loading @@ -1127,9 +1129,9 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC validatePermission(android.Manifest.permission.SHUTDOWN); Slog.i(TAG, "Shutting down"); String path = Environment.getExternalStorageDirectory().getPath(); String state = getVolumeState(path); synchronized (mVolumeStates) { for (String path : mVolumeStates.keySet()) { String state = mVolumeStates.get(path); if (state.equals(Environment.MEDIA_SHARED)) { /* Loading Loading @@ -1178,6 +1180,8 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC } } } } } private boolean getUmsEnabling() { synchronized (mListeners) { Loading Loading @@ -1246,16 +1250,15 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC * @return state of the volume at the specified mount point */ public String getVolumeState(String mountPoint) { /* * XXX: Until we have multiple volume discovery, just hardwire * this to /sdcard */ if (!mountPoint.equals(Environment.getExternalStorageDirectory().getPath())) { synchronized (mVolumeStates) { String state = mVolumeStates.get(mountPoint); if (state == null) { Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume"); throw new IllegalArgumentException(); } return mLegacyState; return state; } } public boolean isExternalStorageEmulated() { Loading