summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorJerry Zhang <zhangjerry@google.com>2018-05-10 18:28:29 -0700
committerJerry Zhang <zhangjerry@google.com>2018-05-14 11:39:12 -0700
commit71938e18ca4ad77519da70565710ef37e79443f8 (patch)
tree174a1009e429cf4099659ba9ad0cb8d548dc2709 /core/java
parent14de2930ba6a9d23a746e354b41bd9ede544eee7 (diff)
Access removable volumes through /mnt/media_rw
Due to permissions changes, we now need to access the underlying filesystem of removable devices in order to get write access. Add internalPath to StorageVolume, and have VolumeInfo set the field on creation. Bug: 77849654 Test: Can write to emulated sdcard through MTP Change-Id: I63302ecf2dd2600a1c9f3f6ab106c3695654cbaa
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/os/storage/StorageVolume.java19
-rw-r--r--core/java/android/os/storage/VolumeInfo.java6
2 files changed, 22 insertions, 3 deletions
diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java
index 839a8bf42b10..fd5a22a9c551 100644
--- a/core/java/android/os/storage/StorageVolume.java
+++ b/core/java/android/os/storage/StorageVolume.java
@@ -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);
diff --git a/core/java/android/os/storage/VolumeInfo.java b/core/java/android/os/storage/VolumeInfo.java
index 9e3e386eedb2..a2a8d7fff37c 100644
--- a/core/java/android/os/storage/VolumeInfo.java
+++ b/core/java/android/os/storage/VolumeInfo.java
@@ -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);
}