Merge "Introducing StubVolume in StorageManager"

This commit is contained in:
Treehugger Robot
2018-11-13 19:20:38 +00:00
committed by Gerrit Code Review
6 changed files with 24 additions and 11 deletions

View File

@@ -125,6 +125,8 @@ public final class Sm {
filterType = VolumeInfo.TYPE_PRIVATE; filterType = VolumeInfo.TYPE_PRIVATE;
} else if ("emulated".equals(filter)) { } else if ("emulated".equals(filter)) {
filterType = VolumeInfo.TYPE_EMULATED; filterType = VolumeInfo.TYPE_EMULATED;
} else if ("stub".equals(filter)) {
filterType = VolumeInfo.TYPE_STUB;
} else { } else {
filterType = -1; filterType = -1;
} }
@@ -298,7 +300,7 @@ public final class Sm {
private static int showUsage() { private static int showUsage() {
System.err.println("usage: sm list-disks [adoptable]"); System.err.println("usage: sm list-disks [adoptable]");
System.err.println(" sm list-volumes [public|private|emulated|all]"); System.err.println(" sm list-volumes [public|private|emulated|stub|all]");
System.err.println(" sm has-adoptable"); System.err.println(" sm has-adoptable");
System.err.println(" sm get-primary-storage-uuid"); System.err.println(" sm get-primary-storage-uuid");
System.err.println(" sm set-force-adoptable [on|off|default]"); System.err.println(" sm set-force-adoptable [on|off|default]");

View File

@@ -774,7 +774,7 @@ public class StorageManager {
try { try {
for (VolumeInfo vol : mStorageManager.getVolumes(0)) { for (VolumeInfo vol : mStorageManager.getVolumes(0)) {
if (vol.path != null && FileUtils.contains(vol.path, pathString) if (vol.path != null && FileUtils.contains(vol.path, pathString)
&& vol.type != VolumeInfo.TYPE_PUBLIC) { && vol.type != VolumeInfo.TYPE_PUBLIC && vol.type != VolumeInfo.TYPE_STUB) {
// TODO: verify that emulated adopted devices have UUID of // TODO: verify that emulated adopted devices have UUID of
// underlying volume // underlying volume
try { try {

View File

@@ -84,6 +84,7 @@ public class VolumeInfo implements Parcelable {
public static final int TYPE_EMULATED = IVold.VOLUME_TYPE_EMULATED; public static final int TYPE_EMULATED = IVold.VOLUME_TYPE_EMULATED;
public static final int TYPE_ASEC = IVold.VOLUME_TYPE_ASEC; public static final int TYPE_ASEC = IVold.VOLUME_TYPE_ASEC;
public static final int TYPE_OBB = IVold.VOLUME_TYPE_OBB; public static final int TYPE_OBB = IVold.VOLUME_TYPE_OBB;
public static final int TYPE_STUB = IVold.VOLUME_TYPE_STUB;
public static final int STATE_UNMOUNTED = IVold.VOLUME_STATE_UNMOUNTED; public static final int STATE_UNMOUNTED = IVold.VOLUME_STATE_UNMOUNTED;
public static final int STATE_CHECKING = IVold.VOLUME_STATE_CHECKING; public static final int STATE_CHECKING = IVold.VOLUME_STATE_CHECKING;
@@ -295,7 +296,7 @@ public class VolumeInfo implements Parcelable {
} }
public boolean isVisibleForUser(int userId) { public boolean isVisibleForUser(int userId) {
if (type == TYPE_PUBLIC && mountUserId == userId) { if ((type == TYPE_PUBLIC || type == TYPE_STUB) && mountUserId == userId) {
return isVisible(); return isVisible();
} else if (type == TYPE_EMULATED) { } else if (type == TYPE_EMULATED) {
return isVisible(); return isVisible();
@@ -327,7 +328,7 @@ public class VolumeInfo implements Parcelable {
public File getPathForUser(int userId) { public File getPathForUser(int userId) {
if (path == null) { if (path == null) {
return null; return null;
} else if (type == TYPE_PUBLIC) { } else if (type == TYPE_PUBLIC || type == TYPE_STUB) {
return new File(path); return new File(path);
} else if (type == TYPE_EMULATED) { } else if (type == TYPE_EMULATED) {
return new File(path, Integer.toString(userId)); return new File(path, Integer.toString(userId));
@@ -344,7 +345,7 @@ public class VolumeInfo implements Parcelable {
public File getInternalPathForUser(int userId) { public File getInternalPathForUser(int userId) {
if (path == null) { if (path == null) {
return null; return null;
} else if (type == TYPE_PUBLIC) { } else if (type == TYPE_PUBLIC || type == TYPE_STUB) {
// TODO: plumb through cleaner path from vold // TODO: plumb through cleaner path from vold
return new File(path.replace("/storage/", "/mnt/media_rw/")); return new File(path.replace("/storage/", "/mnt/media_rw/"));
} else { } else {
@@ -390,7 +391,7 @@ public class VolumeInfo implements Parcelable {
removable = true; removable = true;
} }
} else if (type == TYPE_PUBLIC) { } else if (type == TYPE_PUBLIC || type == TYPE_STUB) {
emulated = false; emulated = false;
removable = true; removable = true;
@@ -447,7 +448,8 @@ public class VolumeInfo implements Parcelable {
public @Nullable Intent buildBrowseIntentForUser(int userId) { public @Nullable Intent buildBrowseIntentForUser(int userId) {
final Uri uri; final Uri uri;
if (type == VolumeInfo.TYPE_PUBLIC && mountUserId == userId) { if ((type == VolumeInfo.TYPE_PUBLIC || type == VolumeInfo.TYPE_STUB)
&& mountUserId == userId) {
uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, fsUuid); uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, fsUuid);
} else if (type == VolumeInfo.TYPE_EMULATED && isPrimary()) { } else if (type == VolumeInfo.TYPE_EMULATED && isPrimary()) {
uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY,

View File

@@ -184,7 +184,8 @@ public class ExternalStorageProvider extends FileSystemProvider {
title = mStorageManager.getBestVolumeDescription(privateVol); title = mStorageManager.getBestVolumeDescription(privateVol);
storageUuid = StorageManager.convert(privateVol.fsUuid); storageUuid = StorageManager.convert(privateVol.fsUuid);
} }
} else if (volume.getType() == VolumeInfo.TYPE_PUBLIC } else if ((volume.getType() == VolumeInfo.TYPE_PUBLIC
|| volume.getType() == VolumeInfo.TYPE_STUB)
&& volume.getMountUserId() == userId) { && volume.getMountUserId() == userId) {
rootId = volume.getFsUuid(); rootId = volume.getFsUuid();
title = mStorageManager.getBestVolumeDescription(volume); title = mStorageManager.getBestVolumeDescription(volume);

View File

@@ -152,7 +152,8 @@ public class StorageMeasurement {
final MeasurementDetails details = new MeasurementDetails(); final MeasurementDetails details = new MeasurementDetails();
if (mVolume == null) return details; if (mVolume == null) return details;
if (mVolume.getType() == VolumeInfo.TYPE_PUBLIC) { if (mVolume.getType() == VolumeInfo.TYPE_PUBLIC
|| mVolume.getType() == VolumeInfo.TYPE_STUB) {
details.totalSize = mVolume.getPath().getTotalSpace(); details.totalSize = mVolume.getPath().getTotalSpace();
details.availSize = mVolume.getPath().getUsableSpace(); details.availSize = mVolume.getPath().getUsableSpace();
return details; return details;

View File

@@ -1190,6 +1190,9 @@ class StorageManagerService extends IStorageManager.Stub
} else if (vol.type == VolumeInfo.TYPE_PRIVATE) { } else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget(); mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else if (vol.type == VolumeInfo.TYPE_STUB) {
vol.mountUserId = mCurrentUserId;
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else { } else {
Slog.d(TAG, "Skipping automatic mounting of " + vol); Slog.d(TAG, "Skipping automatic mounting of " + vol);
} }
@@ -1200,6 +1203,7 @@ class StorageManagerService extends IStorageManager.Stub
case VolumeInfo.TYPE_PRIVATE: case VolumeInfo.TYPE_PRIVATE:
case VolumeInfo.TYPE_PUBLIC: case VolumeInfo.TYPE_PUBLIC:
case VolumeInfo.TYPE_EMULATED: case VolumeInfo.TYPE_EMULATED:
case VolumeInfo.TYPE_STUB:
break; break;
default: default:
return false; return false;
@@ -1276,7 +1280,8 @@ class StorageManagerService extends IStorageManager.Stub
} }
} }
if (vol.type == VolumeInfo.TYPE_PUBLIC && vol.state == VolumeInfo.STATE_EJECTING) { if ((vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_STUB)
&& vol.state == VolumeInfo.STATE_EJECTING) {
// TODO: this should eventually be handled by new ObbVolume state changes // TODO: this should eventually be handled by new ObbVolume state changes
/* /*
* Some OBBs might have been unmounted when this volume was * Some OBBs might have been unmounted when this volume was
@@ -1358,7 +1363,8 @@ class StorageManagerService extends IStorageManager.Stub
} }
boolean isTypeRestricted = false; boolean isTypeRestricted = false;
if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE) { if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE
|| vol.type == VolumeInfo.TYPE_STUB) {
isTypeRestricted = userManager isTypeRestricted = userManager
.hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, .hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA,
Binder.getCallingUserHandle()); Binder.getCallingUserHandle());
@@ -2749,6 +2755,7 @@ class StorageManagerService extends IStorageManager.Stub
final VolumeInfo vol = mVolumes.valueAt(i); final VolumeInfo vol = mVolumes.valueAt(i);
switch (vol.getType()) { switch (vol.getType()) {
case VolumeInfo.TYPE_PUBLIC: case VolumeInfo.TYPE_PUBLIC:
case VolumeInfo.TYPE_STUB:
case VolumeInfo.TYPE_EMULATED: case VolumeInfo.TYPE_EMULATED:
break; break;
default: default: