diff options
| author | 2021-12-03 00:15:50 +0000 | |
|---|---|---|
| committer | 2021-12-03 00:15:50 +0000 | |
| commit | 45450c2bf209d15b9dd4897e77cd73dffaeaf00a (patch) | |
| tree | 849301281c7ad4956500585c006e7c0f25f98686 | |
| parent | 0f642cfedfe5d4f9873974cf7d838e4c8d9b0f58 (diff) | |
| parent | 3632fde8513b42fb277496281926e5e517f1d160 (diff) | |
Merge "Expose StorageVolume.isStub() as @SystemApi API"
7 files changed, 36 insertions, 12 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 96a7434fdea1..c4aec0edf93e 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -9202,6 +9202,7 @@ package android.os.storage { public final class StorageVolume implements android.os.Parcelable { method @NonNull public String getId(); + method public boolean isStub(); } } diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java index 2adcbc318614..0c2f8b639092 100644 --- a/core/java/android/os/storage/StorageVolume.java +++ b/core/java/android/os/storage/StorageVolume.java @@ -99,6 +99,7 @@ public final class StorageVolume implements Parcelable { @UnsupportedAppUsage private final boolean mRemovable; private final boolean mEmulated; + private final boolean mStub; private final boolean mAllowMassStorage; private final long mMaxFileSize; private final UserHandle mOwner; @@ -137,8 +138,9 @@ public final class StorageVolume implements Parcelable { /** {@hide} */ public StorageVolume(String id, File path, File internalPath, String description, - boolean primary, boolean removable, boolean emulated, boolean allowMassStorage, - long maxFileSize, UserHandle owner, UUID uuid, String fsUuid, String state) { + boolean primary, boolean removable, boolean emulated, boolean stub, + boolean allowMassStorage, long maxFileSize, UserHandle owner, UUID uuid, String fsUuid, + String state) { mId = Preconditions.checkNotNull(id); mPath = Preconditions.checkNotNull(path); mInternalPath = Preconditions.checkNotNull(internalPath); @@ -146,6 +148,7 @@ public final class StorageVolume implements Parcelable { mPrimary = primary; mRemovable = removable; mEmulated = emulated; + mStub = stub; mAllowMassStorage = allowMassStorage; mMaxFileSize = maxFileSize; mOwner = Preconditions.checkNotNull(owner); @@ -162,6 +165,7 @@ public final class StorageVolume implements Parcelable { mPrimary = in.readInt() != 0; mRemovable = in.readInt() != 0; mEmulated = in.readInt() != 0; + mStub = in.readInt() != 0; mAllowMassStorage = in.readInt() != 0; mMaxFileSize = in.readLong(); mOwner = in.readParcelable(null); @@ -264,13 +268,23 @@ public final class StorageVolume implements Parcelable { /** * Returns true if the volume is emulated. * - * @return is removable + * @return is emulated */ public boolean isEmulated() { return mEmulated; } /** + * Returns true if the volume is a stub volume (a volume managed from outside Android). + * + * @hide + */ + @SystemApi + public boolean isStub() { + return mStub; + } + + /** * Returns true if this volume can be shared via USB mass storage. * * @return whether mass storage is allowed @@ -506,6 +520,7 @@ public final class StorageVolume implements Parcelable { pw.printPair("mPrimary", mPrimary); pw.printPair("mRemovable", mRemovable); pw.printPair("mEmulated", mEmulated); + pw.printPair("mStub", mStub); pw.printPair("mAllowMassStorage", mAllowMassStorage); pw.printPair("mMaxFileSize", mMaxFileSize); pw.printPair("mOwner", mOwner); @@ -540,6 +555,7 @@ public final class StorageVolume implements Parcelable { parcel.writeInt(mPrimary ? 1 : 0); parcel.writeInt(mRemovable ? 1 : 0); parcel.writeInt(mEmulated ? 1 : 0); + parcel.writeInt(mStub ? 1 : 0); parcel.writeInt(mAllowMassStorage ? 1 : 0); parcel.writeLong(mMaxFileSize); parcel.writeParcelable(mOwner, flags); @@ -621,6 +637,7 @@ public final class StorageVolume implements Parcelable { mPrimary, mRemovable, mEmulated, + /* stub= */ false, /* allowMassStorage= */ false, /* maxFileSize= */ 0, mOwner, diff --git a/core/java/android/os/storage/VolumeInfo.java b/core/java/android/os/storage/VolumeInfo.java index 39a2e1353237..ebd143c33990 100644 --- a/core/java/android/os/storage/VolumeInfo.java +++ b/core/java/android/os/storage/VolumeInfo.java @@ -404,6 +404,7 @@ public class VolumeInfo implements Parcelable { final boolean removable; final boolean emulated; + final boolean stub = type == TYPE_STUB; final boolean allowMassStorage = false; final String envState = reportUnmounted ? Environment.MEDIA_UNMOUNTED : getEnvironmentForState(state); @@ -459,8 +460,8 @@ public class VolumeInfo implements Parcelable { } return new StorageVolume(id, userPath, internalPath, description, isPrimary(), removable, - emulated, allowMassStorage, maxFileSize, new UserHandle(userId), - uuid, derivedFsUuid, envState); + emulated, stub, allowMassStorage, maxFileSize, new UserHandle(userId), uuid, + derivedFsUuid, envState); } @UnsupportedAppUsage diff --git a/core/java/android/os/storage/VolumeRecord.java b/core/java/android/os/storage/VolumeRecord.java index 1cc982e7dbb5..eac09aab46cd 100644 --- a/core/java/android/os/storage/VolumeRecord.java +++ b/core/java/android/os/storage/VolumeRecord.java @@ -105,6 +105,7 @@ public class VolumeRecord implements Parcelable { final boolean primary = false; final boolean removable = true; final boolean emulated = false; + final boolean stub = false; final boolean allowMassStorage = false; final long maxFileSize = 0; final UserHandle user = new UserHandle(UserHandle.USER_NULL); @@ -116,7 +117,8 @@ public class VolumeRecord implements Parcelable { } return new StorageVolume(id, userPath, internalPath, description, primary, removable, - emulated, allowMassStorage, maxFileSize, user, null /* uuid */, fsUuid, envState); + emulated, stub, allowMassStorage, maxFileSize, user, null /* uuid */, fsUuid, + envState); } public void dump(IndentingPrintWriter pw) { diff --git a/media/tests/MtpTests/src/android/mtp/MtpDatabaseTest.java b/media/tests/MtpTests/src/android/mtp/MtpDatabaseTest.java index 48be6fea845f..669ad6240e30 100644 --- a/media/tests/MtpTests/src/android/mtp/MtpDatabaseTest.java +++ b/media/tests/MtpTests/src/android/mtp/MtpDatabaseTest.java @@ -132,7 +132,7 @@ public class MtpDatabaseTest { StorageVolume mainStorage = new StorageVolume(MAIN_STORAGE_ID_STR, mMainStorageDir, mMainStorageDir, "Primary Storage", - true, false, true, false, -1, UserHandle.CURRENT, null /* uuid */, "", ""); + true, false, true, false, false, -1, UserHandle.CURRENT, null /* uuid */, "", ""); final StorageVolume primary = mainStorage; diff --git a/media/tests/MtpTests/src/android/mtp/MtpStorageManagerTest.java b/media/tests/MtpTests/src/android/mtp/MtpStorageManagerTest.java index fdf65823b1f3..abdc7e559fb3 100644 --- a/media/tests/MtpTests/src/android/mtp/MtpStorageManagerTest.java +++ b/media/tests/MtpTests/src/android/mtp/MtpStorageManagerTest.java @@ -132,9 +132,10 @@ public class MtpStorageManagerTest { secondaryStorageDir = createNewDir(TEMP_DIR_FILE); StorageVolume mainStorage = new StorageVolume("1", mainStorageDir, mainStorageDir, - "", true, false, true, false, -1, UserHandle.CURRENT, null /* uuid */, "", ""); + "", true, false, true, false, false, -1, UserHandle.CURRENT, null /* uuid */, "", + ""); StorageVolume secondaryStorage = new StorageVolume("2", secondaryStorageDir, - secondaryStorageDir, "", false, false, true, false, -1, UserHandle.CURRENT, + secondaryStorageDir, "", false, false, true, false, false, -1, UserHandle.CURRENT, null /* uuid */, "", ""); objectsAdded = new ArrayList<>(); diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index d79f2f31d056..c7f4b4d03648 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -3844,14 +3844,15 @@ class StorageManagerService extends IStorageManager.Stub final boolean primary = false; final boolean removable = false; final boolean emulated = true; + final boolean stub = false; final boolean allowMassStorage = false; final long maxFileSize = 0; final UserHandle user = new UserHandle(userId); final String envState = Environment.MEDIA_MOUNTED_READ_ONLY; final String description = mContext.getString(android.R.string.unknownName); - res.add(new StorageVolume(id, path, path, description, primary, removable, - emulated, allowMassStorage, maxFileSize, user, null /*uuid */, id, envState)); + res.add(new StorageVolume(id, path, path, description, primary, removable, emulated, + stub, allowMassStorage, maxFileSize, user, null /*uuid */, id, envState)); } if (!foundPrimary) { @@ -3866,6 +3867,7 @@ class StorageManagerService extends IStorageManager.Stub final boolean primary = true; final boolean removable = primaryPhysical; final boolean emulated = !primaryPhysical; + final boolean stub = false; final boolean allowMassStorage = false; final long maxFileSize = 0L; final UserHandle owner = new UserHandle(userId); @@ -3874,7 +3876,7 @@ class StorageManagerService extends IStorageManager.Stub final String state = Environment.MEDIA_REMOVED; res.add(0, new StorageVolume(id, path, path, - description, primary, removable, emulated, + description, primary, removable, emulated, stub, allowMassStorage, maxFileSize, owner, uuid, fsUuid, state)); } |