Merge "Access removable volumes through /mnt/media_rw" into pi-dev

This commit is contained in:
Jerry Zhang
2018-05-15 21:35:43 +00:00
committed by Android (Google) Code Review
5 changed files with 25 additions and 7 deletions

View File

@@ -78,6 +78,7 @@ public final class StorageVolume implements Parcelable {
private final String mId;
private final File mPath;
private final File mInternalPath;
private final String mDescription;
private final boolean mPrimary;
private final boolean mRemovable;
@@ -118,11 +119,12 @@ public final class StorageVolume implements Parcelable {
public static final int STORAGE_ID_PRIMARY = 0x00010001;
/** {@hide} */
public StorageVolume(String id, File path, String description, boolean primary,
boolean removable, boolean emulated, boolean allowMassStorage,
public StorageVolume(String id, File path, File internalPath, String description,
boolean primary, boolean removable, boolean emulated, boolean allowMassStorage,
long maxFileSize, UserHandle owner, String fsUuid, String state) {
mId = Preconditions.checkNotNull(id);
mPath = Preconditions.checkNotNull(path);
mInternalPath = Preconditions.checkNotNull(internalPath);
mDescription = Preconditions.checkNotNull(description);
mPrimary = primary;
mRemovable = removable;
@@ -137,6 +139,7 @@ public final class StorageVolume implements Parcelable {
private StorageVolume(Parcel in) {
mId = in.readString();
mPath = new File(in.readString());
mInternalPath = new File(in.readString());
mDescription = in.readString();
mPrimary = in.readInt() != 0;
mRemovable = in.readInt() != 0;
@@ -163,6 +166,16 @@ public final class StorageVolume implements Parcelable {
return mPath.toString();
}
/**
* Returns the path of the underlying filesystem.
*
* @return the internal path
* @hide
*/
public String getInternalPath() {
return mInternalPath.toString();
}
/** {@hide} */
public File getPathFile() {
return mPath;
@@ -351,6 +364,7 @@ public final class StorageVolume implements Parcelable {
pw.increaseIndent();
pw.printPair("mId", mId);
pw.printPair("mPath", mPath);
pw.printPair("mInternalPath", mInternalPath);
pw.printPair("mDescription", mDescription);
pw.printPair("mPrimary", mPrimary);
pw.printPair("mRemovable", mRemovable);
@@ -384,6 +398,7 @@ public final class StorageVolume implements Parcelable {
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(mId);
parcel.writeString(mPath.toString());
parcel.writeString(mInternalPath.toString());
parcel.writeString(mDescription);
parcel.writeInt(mPrimary ? 1 : 0);
parcel.writeInt(mRemovable ? 1 : 0);

View File

@@ -333,6 +333,10 @@ public class VolumeInfo implements Parcelable {
if (userPath == null) {
userPath = new File("/dev/null");
}
File internalPath = getInternalPathForUser(userId);
if (internalPath == null) {
internalPath = new File("/dev/null");
}
String description = null;
String derivedFsUuid = fsUuid;
@@ -371,7 +375,7 @@ public class VolumeInfo implements Parcelable {
description = context.getString(android.R.string.unknownName);
}
return new StorageVolume(id, userPath, description, isPrimary(), removable,
return new StorageVolume(id, userPath, internalPath, description, isPrimary(), removable,
emulated, allowMassStorage, maxFileSize, new UserHandle(userId),
derivedFsUuid, envState);
}

View File

@@ -16,7 +16,6 @@
package android.mtp;
import android.content.Context;
import android.os.storage.StorageVolume;
/**
@@ -36,7 +35,7 @@ public class MtpStorage {
public MtpStorage(StorageVolume volume, int storageId) {
mStorageId = storageId;
mPath = volume.getPath();
mPath = volume.getInternalPath();
mDescription = volume.getDescription(null);
mRemovable = volume.isRemovable();
mMaxFileSize = volume.getMaxFileSize();

View File

@@ -399,8 +399,8 @@ public class MtpStorageManager {
*/
public synchronized MtpStorage addMtpStorage(StorageVolume volume) {
int storageId = ((getNextStorageId() & 0x0000FFFF) << 16) + 1;
MtpObject root = new MtpObject(volume.getPath(), storageId, null, true);
MtpStorage storage = new MtpStorage(volume, storageId);
MtpObject root = new MtpObject(storage.getPath(), storageId, null, true);
mRoots.put(storageId, root);
return storage;
}

View File

@@ -2795,7 +2795,7 @@ class StorageManagerService extends IStorageManager.Stub
final String uuid = null;
final String state = Environment.MEDIA_REMOVED;
res.add(0, new StorageVolume(id, path,
res.add(0, new StorageVolume(id, path, path,
description, primary, removable, emulated,
allowMassStorage, maxFileSize, owner, uuid, state));
}