Loading services/java/com/android/server/MountService.java +83 −42 Original line number Diff line number Diff line Loading @@ -402,6 +402,13 @@ class MountService extends IMountService.Stub case H_UNMOUNT_PM_UPDATE: { if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_UPDATE"); UnmountCallBack ucb = (UnmountCallBack) msg.obj; if (!mUpdatingStatus && !isPrimaryStorage(ucb.path)) { // If PM isn't already updating, and this isn't an ASEC // mount, then go ahead and do the unmount immediately. if (DEBUG_UNMOUNT) Slog.i(TAG, " skipping PackageManager for " + ucb.path); ucb.handleFinished(); break; } mForceUnmounts.add(ucb); if (DEBUG_UNMOUNT) Slog.i(TAG, " registered = " + mUpdatingStatus); // Register only if needed. Loading Loading @@ -1000,7 +1007,9 @@ class MountService extends IMountService.Stub Runtime.getRuntime().gc(); // Redundant probably. But no harm in updating state again. if (isPrimaryStorage(path)) { mPms.updateExternalMediaStatus(false, false); } try { final Command cmd = new Command("volume", "unmount", path); if (removeEncryption) { Loading Loading @@ -1082,10 +1091,13 @@ class MountService extends IMountService.Stub mSendUmsConnectedOnBoot = avail; } final StorageVolume primary = getPrimaryPhysicalVolume(); if (avail == false && primary != null && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) { final String path = primary.getPath(); final ArrayList<String> volumes = getShareableVolumes(); boolean mediaShared = false; for (String path : volumes) { if (getVolumeState(path).equals(Environment.MEDIA_SHARED)) mediaShared = true; } if (avail == false && mediaShared) { /* * USB mass storage disconnected while enabled */ Loading @@ -1095,12 +1107,16 @@ class MountService extends IMountService.Stub try { int rc; Slog.w(TAG, "Disabling UMS after cable disconnect"); for (String path : volumes) { if (getVolumeState(path).equals(Environment.MEDIA_SHARED)) { doShareUnshareVolume(path, "ums", false); if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) { Slog.e(TAG, String.format( "Failed to remount {%s} on UMS enabled-disconnect (%d)", path, rc)); } } } } catch (Exception ex) { Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex); } Loading Loading @@ -1438,6 +1454,30 @@ class MountService extends IMountService.Stub } } private boolean isPrimaryStorage(String path) { synchronized (mVolumesLock) { for (StorageVolume volume : mVolumes) { if (volume.isPrimary() && volume.getPath().equals(path)) { return true; } } return false; } } private ArrayList<String> getShareableVolumes() { // Sharable volumes have android:allowMassStorage="true" in storage_list.xml ArrayList<String> volumesToMount = new ArrayList<String>(); synchronized (mVolumesLock) { for (StorageVolume v : mVolumes) { if (v.allowMassStorage()) { volumesToMount.add(v.getPath()); } } } return volumesToMount; } public void setUsbMassStorageEnabled(boolean enable) { waitForReady(); validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); Loading @@ -1447,10 +1487,10 @@ class MountService extends IMountService.Stub // TODO: Add support for multiple share methods for (String path : getShareableVolumes()) { /* * If the volume is mounted and we're enabling then unmount it */ String path = primary.getPath(); String vs = getVolumeState(path); String method = "ums"; if (enable && vs.equals(Environment.MEDIA_MOUNTED)) { Loading @@ -1477,16 +1517,17 @@ class MountService extends IMountService.Stub } } } } public boolean isUsbMassStorageEnabled() { waitForReady(); final StorageVolume primary = getPrimaryPhysicalVolume(); if (primary != null) { return doGetVolumeShared(primary.getPath(), "ums"); } else { return false; for (String path : getShareableVolumes()) { if (doGetVolumeShared(path, "ums")) return true; } // no volume is shared return false; } /** Loading Loading
services/java/com/android/server/MountService.java +83 −42 Original line number Diff line number Diff line Loading @@ -402,6 +402,13 @@ class MountService extends IMountService.Stub case H_UNMOUNT_PM_UPDATE: { if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_UPDATE"); UnmountCallBack ucb = (UnmountCallBack) msg.obj; if (!mUpdatingStatus && !isPrimaryStorage(ucb.path)) { // If PM isn't already updating, and this isn't an ASEC // mount, then go ahead and do the unmount immediately. if (DEBUG_UNMOUNT) Slog.i(TAG, " skipping PackageManager for " + ucb.path); ucb.handleFinished(); break; } mForceUnmounts.add(ucb); if (DEBUG_UNMOUNT) Slog.i(TAG, " registered = " + mUpdatingStatus); // Register only if needed. Loading Loading @@ -1000,7 +1007,9 @@ class MountService extends IMountService.Stub Runtime.getRuntime().gc(); // Redundant probably. But no harm in updating state again. if (isPrimaryStorage(path)) { mPms.updateExternalMediaStatus(false, false); } try { final Command cmd = new Command("volume", "unmount", path); if (removeEncryption) { Loading Loading @@ -1082,10 +1091,13 @@ class MountService extends IMountService.Stub mSendUmsConnectedOnBoot = avail; } final StorageVolume primary = getPrimaryPhysicalVolume(); if (avail == false && primary != null && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) { final String path = primary.getPath(); final ArrayList<String> volumes = getShareableVolumes(); boolean mediaShared = false; for (String path : volumes) { if (getVolumeState(path).equals(Environment.MEDIA_SHARED)) mediaShared = true; } if (avail == false && mediaShared) { /* * USB mass storage disconnected while enabled */ Loading @@ -1095,12 +1107,16 @@ class MountService extends IMountService.Stub try { int rc; Slog.w(TAG, "Disabling UMS after cable disconnect"); for (String path : volumes) { if (getVolumeState(path).equals(Environment.MEDIA_SHARED)) { doShareUnshareVolume(path, "ums", false); if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) { Slog.e(TAG, String.format( "Failed to remount {%s} on UMS enabled-disconnect (%d)", path, rc)); } } } } catch (Exception ex) { Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex); } Loading Loading @@ -1438,6 +1454,30 @@ class MountService extends IMountService.Stub } } private boolean isPrimaryStorage(String path) { synchronized (mVolumesLock) { for (StorageVolume volume : mVolumes) { if (volume.isPrimary() && volume.getPath().equals(path)) { return true; } } return false; } } private ArrayList<String> getShareableVolumes() { // Sharable volumes have android:allowMassStorage="true" in storage_list.xml ArrayList<String> volumesToMount = new ArrayList<String>(); synchronized (mVolumesLock) { for (StorageVolume v : mVolumes) { if (v.allowMassStorage()) { volumesToMount.add(v.getPath()); } } } return volumesToMount; } public void setUsbMassStorageEnabled(boolean enable) { waitForReady(); validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); Loading @@ -1447,10 +1487,10 @@ class MountService extends IMountService.Stub // TODO: Add support for multiple share methods for (String path : getShareableVolumes()) { /* * If the volume is mounted and we're enabling then unmount it */ String path = primary.getPath(); String vs = getVolumeState(path); String method = "ums"; if (enable && vs.equals(Environment.MEDIA_MOUNTED)) { Loading @@ -1477,16 +1517,17 @@ class MountService extends IMountService.Stub } } } } public boolean isUsbMassStorageEnabled() { waitForReady(); final StorageVolume primary = getPrimaryPhysicalVolume(); if (primary != null) { return doGetVolumeShared(primary.getPath(), "ums"); } else { return false; for (String path : getShareableVolumes()) { if (doGetVolumeShared(path, "ums")) return true; } // no volume is shared return false; } /** Loading