diff options
-rw-r--r-- | core/java/android/os/storage/StorageVolume.java | 39 | ||||
-rw-r--r-- | media/java/android/mtp/MtpStorage.java | 15 | ||||
-rw-r--r-- | services/java/com/android/server/MountService.java | 5 |
3 files changed, 49 insertions, 10 deletions
diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java index d79f6c8..d68e6fb 100644 --- a/core/java/android/os/storage/StorageVolume.java +++ b/core/java/android/os/storage/StorageVolume.java @@ -34,10 +34,10 @@ public class StorageVolume implements Parcelable { private final boolean mRemovable; private final boolean mEmulated; private final int mMtpReserveSpace; + private int mStorageId; public StorageVolume(String path, String description, - boolean removable, boolean emulated, - int mtpReserveSpace) { + boolean removable, boolean emulated, int mtpReserveSpace) { mPath = path; mDescription = description; mRemovable = removable; @@ -45,6 +45,17 @@ public class StorageVolume implements Parcelable { mMtpReserveSpace = mtpReserveSpace; } + // for parcelling only + private StorageVolume(String path, String description, + boolean removable, boolean emulated, int mtpReserveSpace, int storageId) { + mPath = path; + mDescription = description; + mRemovable = removable; + mEmulated = emulated; + mMtpReserveSpace = mtpReserveSpace; + mStorageId = storageId; + } + /** * Returns the mount path for the volume. * @@ -82,6 +93,25 @@ public class StorageVolume implements Parcelable { } /** + * Returns the MTP storage ID for the volume. + * this is also used for the storage_id column in the media provider. + * + * @return MTP storage ID + */ + public int getStorageId() { + return mStorageId; + } + + /** + * Do not call this unless you are MountService + */ + public void setStorageId(int index) { + // storage ID is 0x00010001 for primary storage, + // then 0x00020001, 0x00030001, etc. for secondary storages + mStorageId = ((index + 1) << 16) + 1; + } + + /** * Number of megabytes of space to leave unallocated by MTP. * MTP will subtract this value from the free space it reports back * to the host via GetStorageInfo, and will not allow new files to @@ -123,9 +153,11 @@ public class StorageVolume implements Parcelable { String description = in.readString(); int removable = in.readInt(); int emulated = in.readInt(); + int storageId = in.readInt(); int mtpReserveSpace = in.readInt(); return new StorageVolume(path, description, - removable == 1, emulated == 1, mtpReserveSpace); + removable == 1, emulated == 1, + mtpReserveSpace, storageId); } public StorageVolume[] newArray(int size) { @@ -142,6 +174,7 @@ public class StorageVolume implements Parcelable { parcel.writeString(mDescription); parcel.writeInt(mRemovable ? 1 : 0); parcel.writeInt(mEmulated ? 1 : 0); + parcel.writeInt(mStorageId); parcel.writeInt(mMtpReserveSpace); } } diff --git a/media/java/android/mtp/MtpStorage.java b/media/java/android/mtp/MtpStorage.java index 21a18ca..7932d34 100644 --- a/media/java/android/mtp/MtpStorage.java +++ b/media/java/android/mtp/MtpStorage.java @@ -16,6 +16,8 @@ package android.mtp; +import android.os.storage.StorageVolume; + /** * This class represents a storage unit on an MTP device. * Used only for MTP support in USB responder mode. @@ -31,13 +33,12 @@ public class MtpStorage { private final long mReserveSpace; private final boolean mRemovable; - public MtpStorage(int id, String path, String description, - long reserveSpace, boolean removable) { - mStorageId = id; - mPath = path; - mDescription = description; - mReserveSpace = reserveSpace; - mRemovable = removable; + public MtpStorage(StorageVolume volume) { + mStorageId = volume.getStorageId(); + mPath = volume.getPath(); + mDescription = volume.getDescription(); + mReserveSpace = volume.getMtpReserveSpace(); + mRemovable = volume.isRemovable(); } /** diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index 376d42f..347d70a 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -1145,6 +1145,11 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC } catch (IOException e) { throw new RuntimeException(e); } finally { + // compute storage ID for each volume + int length = mVolumes.size(); + for (int i = 0; i < length; i++) { + mVolumes.get(i).setStorageId(i); + } parser.close(); } } |