Merge "StorageVolume: Add getStorageId() accessor" into honeycomb-mr2
This commit is contained in:
committed by
Android (Google) Code Review
commit
27ac64ecee
@@ -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.
|
||||
*
|
||||
@@ -81,6 +92,25 @@ public class StorageVolume implements Parcelable {
|
||||
return mEmulated;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user