Skip to content

Commit 9545dc0

Browse files
committed
Include primary flag in StorageVolume.
Bug: 7003520 Change-Id: Iaae2ae22253820c954c51e0199c31087bc825f3f
1 parent 162fabb commit 9545dc0

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

core/java/android/os/storage/StorageVolume.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,45 @@
2626
*/
2727
public class StorageVolume implements Parcelable {
2828

29-
//private static final String TAG = "StorageVolume";
29+
private int mStorageId;
3030

3131
private final String mPath;
3232
private final int mDescriptionId;
33+
private final boolean mPrimary;
3334
private final boolean mRemovable;
3435
private final boolean mEmulated;
3536
private final int mMtpReserveSpace;
3637
private final boolean mAllowMassStorage;
37-
private int mStorageId;
38-
// maximum file size for the storage, or zero for no limit
38+
/** Maximum file size for the storage, or zero for no limit */
3939
private final long mMaxFileSize;
4040

4141
// StorageVolume extra for ACTION_MEDIA_REMOVED, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_CHECKING,
4242
// ACTION_MEDIA_NOFS, ACTION_MEDIA_MOUNTED, ACTION_MEDIA_SHARED, ACTION_MEDIA_UNSHARED,
4343
// ACTION_MEDIA_BAD_REMOVAL, ACTION_MEDIA_UNMOUNTABLE and ACTION_MEDIA_EJECT broadcasts.
4444
public static final String EXTRA_STORAGE_VOLUME = "storage_volume";
4545

46-
public StorageVolume(String path, int descriptionId, boolean removable,
46+
public StorageVolume(String path, int descriptionId, boolean primary, boolean removable,
4747
boolean emulated, int mtpReserveSpace, boolean allowMassStorage, long maxFileSize) {
4848
mPath = path;
4949
mDescriptionId = descriptionId;
50+
mPrimary = primary;
5051
mRemovable = removable;
5152
mEmulated = emulated;
5253
mMtpReserveSpace = mtpReserveSpace;
5354
mAllowMassStorage = allowMassStorage;
5455
mMaxFileSize = maxFileSize;
5556
}
5657

57-
// for parcelling only
58-
private StorageVolume(String path, int descriptionId, boolean removable,
59-
boolean emulated, int mtpReserveSpace, int storageId,
60-
boolean allowMassStorage, long maxFileSize) {
61-
mPath = path;
62-
mDescriptionId = descriptionId;
63-
mRemovable = removable;
64-
mEmulated = emulated;
65-
mMtpReserveSpace = mtpReserveSpace;
66-
mAllowMassStorage = allowMassStorage;
67-
mStorageId = storageId;
68-
mMaxFileSize = maxFileSize;
58+
private StorageVolume(Parcel in) {
59+
mStorageId = in.readInt();
60+
mPath = in.readString();
61+
mDescriptionId = in.readInt();
62+
mPrimary = in.readByte() != 0;
63+
mRemovable = in.readByte() != 0;
64+
mEmulated = in.readByte() != 0;
65+
mMtpReserveSpace = in.readInt();
66+
mAllowMassStorage = in.readByte() != 0;
67+
mMaxFileSize = in.readLong();
6968
}
7069

7170
/**
@@ -90,6 +89,10 @@ public int getDescriptionId() {
9089
return mDescriptionId;
9190
}
9291

92+
public boolean isPrimary() {
93+
return mPrimary;
94+
}
95+
9396
/**
9497
* Returns true if the volume is removable.
9598
*
@@ -183,37 +186,31 @@ public String toString() {
183186
+ mRemovable + ", mStorageId=" + mStorageId + "]";
184187
}
185188

186-
public static final Parcelable.Creator<StorageVolume> CREATOR =
187-
new Parcelable.Creator<StorageVolume>() {
189+
public static final Creator<StorageVolume> CREATOR = new Creator<StorageVolume>() {
190+
@Override
188191
public StorageVolume createFromParcel(Parcel in) {
189-
String path = in.readString();
190-
int descriptionId = in.readInt();
191-
int removable = in.readInt();
192-
int emulated = in.readInt();
193-
int storageId = in.readInt();
194-
int mtpReserveSpace = in.readInt();
195-
int allowMassStorage = in.readInt();
196-
long maxFileSize = in.readLong();
197-
return new StorageVolume(path, descriptionId,
198-
removable == 1, emulated == 1, mtpReserveSpace,
199-
storageId, allowMassStorage == 1, maxFileSize);
192+
return new StorageVolume(in);
200193
}
201194

195+
@Override
202196
public StorageVolume[] newArray(int size) {
203197
return new StorageVolume[size];
204198
}
205199
};
206200

201+
@Override
207202
public int describeContents() {
208203
return 0;
209204
}
210205

206+
@Override
211207
public void writeToParcel(Parcel parcel, int flags) {
208+
parcel.writeInt(mStorageId);
212209
parcel.writeString(mPath);
213210
parcel.writeInt(mDescriptionId);
211+
parcel.writeInt(mPrimary ? 1 : 0);
214212
parcel.writeInt(mRemovable ? 1 : 0);
215213
parcel.writeInt(mEmulated ? 1 : 0);
216-
parcel.writeInt(mStorageId);
217214
parcel.writeInt(mMtpReserveSpace);
218215
parcel.writeInt(mAllowMassStorage ? 1 : 0);
219216
parcel.writeLong(mMaxFileSize);

services/java/com/android/server/MountService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,8 @@ private void readStorageList() {
11141114
Slog.e(TAG, "path or description is null in readStorageList");
11151115
} else {
11161116
String pathString = path.toString();
1117-
StorageVolume volume = new StorageVolume(pathString,
1118-
descriptionId, removable, emulated,
1119-
mtpReserve, allowMassStorage, maxFileSize);
1117+
StorageVolume volume = new StorageVolume(pathString, descriptionId, primary,
1118+
removable, emulated, mtpReserve, allowMassStorage, maxFileSize);
11201119
if (primary) {
11211120
if (mPrimaryVolume == null) {
11221121
mPrimaryVolume = volume;

0 commit comments

Comments
 (0)