Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67eb83ba authored by Zim's avatar Zim
Browse files

Add StorageVolume#getStorageUuid

Unlike getUuid that returns fsUuid, this returns the 'converted'
fsUuid. This means that for the default internal storage:
- fsUuid = null
- uuid = UUID_DEFAUlT

Test: atest StorageManagerTest#testGetPrimaryVolume
Bug: 170481432
Change-Id: I4c590e5536326e5c2a0b62520f9853de680027ae
parent 05bea5b0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31546,6 +31546,7 @@ package android.os.storage {
    method @Nullable public java.io.File getDirectory();
    method @Nullable public String getMediaStoreVolumeName();
    method public String getState();
    method @Nullable public java.util.UUID getStorageUuid();
    method @Nullable public String getUuid();
    method public boolean isEmulated();
    method public boolean isPrimary();
+29 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.internal.util.Preconditions;
import java.io.CharArrayWriter;
import java.io.File;
import java.util.Locale;
import java.util.UUID;

/**
 * Information about a shared/external storage volume for a specific user.
@@ -98,6 +99,7 @@ public final class StorageVolume implements Parcelable {
    private final boolean mAllowMassStorage;
    private final long mMaxFileSize;
    private final UserHandle mOwner;
    private final UUID mUuid;
    private final String mFsUuid;
    private final String mState;

@@ -133,7 +135,7 @@ 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, String fsUuid, String state) {
            long maxFileSize, UserHandle owner, UUID uuid, String fsUuid, String state) {
        mId = Preconditions.checkNotNull(id);
        mPath = Preconditions.checkNotNull(path);
        mInternalPath = Preconditions.checkNotNull(internalPath);
@@ -144,6 +146,7 @@ public final class StorageVolume implements Parcelable {
        mAllowMassStorage = allowMassStorage;
        mMaxFileSize = maxFileSize;
        mOwner = Preconditions.checkNotNull(owner);
        mUuid = uuid;
        mFsUuid = fsUuid;
        mState = Preconditions.checkNotNull(state);
    }
@@ -159,6 +162,11 @@ public final class StorageVolume implements Parcelable {
        mAllowMassStorage = in.readInt() != 0;
        mMaxFileSize = in.readLong();
        mOwner = in.readParcelable(null);
        if (in.readInt() != 0) {
            mUuid = StorageManager.convert(in.readString());
        } else {
            mUuid = null;
        }
        mFsUuid = in.readString8();
        mState = in.readString8();
    }
@@ -287,6 +295,20 @@ public final class StorageVolume implements Parcelable {
        return mOwner;
    }

    /**
     * Gets the converted volume UUID. If a valid UUID is returned, it is compatible with other
     * APIs that make use of {@link UUID} like {@link StorageManager#allocateBytes} and
     * {@link android.content.pm.ApplicationInfo#storageUuid}
     *
     * @return the UUID for the volume or {@code null} for "portable" storage devices which haven't
     * been adopted.
     *
     * @see <a href="https://source.android.com/devices/storage/adoptable">Adoptable storage</a>
     */
    public @Nullable UUID getStorageUuid() {
        return mUuid;
    }

    /**
     * Gets the volume UUID, if any.
     */
@@ -513,6 +535,12 @@ public final class StorageVolume implements Parcelable {
        parcel.writeInt(mAllowMassStorage ? 1 : 0);
        parcel.writeLong(mMaxFileSize);
        parcel.writeParcelable(mOwner, flags);
        if (mUuid != null) {
            parcel.writeInt(1);
            parcel.writeString8(StorageManager.convert(mUuid));
        } else {
            parcel.writeInt(0);
        }
        parcel.writeString8(mFsUuid);
        parcel.writeString8(mState);
    }
+6 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import java.io.File;
import java.util.Comparator;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;

/**
 * Information about a storage volume that may be mounted. A volume may be a
@@ -401,6 +402,7 @@ public class VolumeInfo implements Parcelable {
        }

        String description = null;
        UUID uuid = null;
        String derivedFsUuid = fsUuid;
        long maxFileSize = 0;

@@ -410,7 +412,10 @@ public class VolumeInfo implements Parcelable {
            final VolumeInfo privateVol = storage.findPrivateForEmulated(this);
            if (privateVol != null) {
                description = storage.getBestVolumeDescription(privateVol);
                uuid = StorageManager.convert(privateVol.fsUuid);
                derivedFsUuid = privateVol.fsUuid;
            } else {
                uuid = StorageManager.UUID_DEFAULT;
            }

            if (isPrimaryEmulatedForUser(userId)) {
@@ -439,7 +444,7 @@ public class VolumeInfo implements Parcelable {

        return new StorageVolume(id, userPath, internalPath, description, isPrimary(), removable,
                emulated, allowMassStorage, maxFileSize, new UserHandle(userId),
                derivedFsUuid, envState);
                uuid, derivedFsUuid, envState);
    }

    @UnsupportedAppUsage
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class VolumeRecord implements Parcelable {
        }

        return new StorageVolume(id, userPath, internalPath, description, primary, removable,
                emulated, allowMassStorage, maxFileSize, user, fsUuid, envState);
                emulated, allowMassStorage, maxFileSize, user, null /* uuid */, fsUuid, envState);
    }

    public void dump(IndentingPrintWriter pw) {
+1 −1
Original line number Diff line number Diff line
@@ -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, "", "");
                true, false, true, false, -1, UserHandle.CURRENT, null /* uuid */, "", "");

        final StorageVolume primary = mainStorage;

Loading