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

Commit 6b792986 authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue Committed by Android (Google) Code Review
Browse files

Merge "Add StorageVolume#getStorageUuid"

parents 1138fcdb 67eb83ba
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -31552,6 +31552,7 @@ package android.os.storage {
    method @Nullable public java.io.File getDirectory();
    method @Nullable public java.io.File getDirectory();
    method @Nullable public String getMediaStoreVolumeName();
    method @Nullable public String getMediaStoreVolumeName();
    method public String getState();
    method public String getState();
    method @Nullable public java.util.UUID getStorageUuid();
    method @Nullable public String getUuid();
    method @Nullable public String getUuid();
    method public boolean isEmulated();
    method public boolean isEmulated();
    method public boolean isPrimary();
    method public boolean isPrimary();
+29 −1
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.internal.util.Preconditions;
import java.io.CharArrayWriter;
import java.io.CharArrayWriter;
import java.io.File;
import java.io.File;
import java.util.Locale;
import java.util.Locale;
import java.util.UUID;


/**
/**
 * Information about a shared/external storage volume for a specific user.
 * 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 boolean mAllowMassStorage;
    private final long mMaxFileSize;
    private final long mMaxFileSize;
    private final UserHandle mOwner;
    private final UserHandle mOwner;
    private final UUID mUuid;
    private final String mFsUuid;
    private final String mFsUuid;
    private final String mState;
    private final String mState;


@@ -133,7 +135,7 @@ public final class StorageVolume implements Parcelable {
    /** {@hide} */
    /** {@hide} */
    public StorageVolume(String id, File path, File internalPath, String description,
    public StorageVolume(String id, File path, File internalPath, String description,
            boolean primary, boolean removable, boolean emulated, boolean allowMassStorage,
            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);
        mId = Preconditions.checkNotNull(id);
        mPath = Preconditions.checkNotNull(path);
        mPath = Preconditions.checkNotNull(path);
        mInternalPath = Preconditions.checkNotNull(internalPath);
        mInternalPath = Preconditions.checkNotNull(internalPath);
@@ -144,6 +146,7 @@ public final class StorageVolume implements Parcelable {
        mAllowMassStorage = allowMassStorage;
        mAllowMassStorage = allowMassStorage;
        mMaxFileSize = maxFileSize;
        mMaxFileSize = maxFileSize;
        mOwner = Preconditions.checkNotNull(owner);
        mOwner = Preconditions.checkNotNull(owner);
        mUuid = uuid;
        mFsUuid = fsUuid;
        mFsUuid = fsUuid;
        mState = Preconditions.checkNotNull(state);
        mState = Preconditions.checkNotNull(state);
    }
    }
@@ -159,6 +162,11 @@ public final class StorageVolume implements Parcelable {
        mAllowMassStorage = in.readInt() != 0;
        mAllowMassStorage = in.readInt() != 0;
        mMaxFileSize = in.readLong();
        mMaxFileSize = in.readLong();
        mOwner = in.readParcelable(null);
        mOwner = in.readParcelable(null);
        if (in.readInt() != 0) {
            mUuid = StorageManager.convert(in.readString());
        } else {
            mUuid = null;
        }
        mFsUuid = in.readString8();
        mFsUuid = in.readString8();
        mState = in.readString8();
        mState = in.readString8();
    }
    }
@@ -287,6 +295,20 @@ public final class StorageVolume implements Parcelable {
        return mOwner;
        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.
     * Gets the volume UUID, if any.
     */
     */
@@ -513,6 +535,12 @@ public final class StorageVolume implements Parcelable {
        parcel.writeInt(mAllowMassStorage ? 1 : 0);
        parcel.writeInt(mAllowMassStorage ? 1 : 0);
        parcel.writeLong(mMaxFileSize);
        parcel.writeLong(mMaxFileSize);
        parcel.writeParcelable(mOwner, flags);
        parcel.writeParcelable(mOwner, flags);
        if (mUuid != null) {
            parcel.writeInt(1);
            parcel.writeString8(StorageManager.convert(mUuid));
        } else {
            parcel.writeInt(0);
        }
        parcel.writeString8(mFsUuid);
        parcel.writeString8(mFsUuid);
        parcel.writeString8(mState);
        parcel.writeString8(mState);
    }
    }
+6 −1
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import java.io.File;
import java.util.Comparator;
import java.util.Comparator;
import java.util.Locale;
import java.util.Locale;
import java.util.Objects;
import java.util.Objects;
import java.util.UUID;


/**
/**
 * Information about a storage volume that may be mounted. A volume may be a
 * 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;
        String description = null;
        UUID uuid = null;
        String derivedFsUuid = fsUuid;
        String derivedFsUuid = fsUuid;
        long maxFileSize = 0;
        long maxFileSize = 0;


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


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


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


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


        return new StorageVolume(id, userPath, internalPath, description, primary, removable,
        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) {
    public void dump(IndentingPrintWriter pw) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -132,7 +132,7 @@ public class MtpDatabaseTest {


        StorageVolume mainStorage = new StorageVolume(MAIN_STORAGE_ID_STR,
        StorageVolume mainStorage = new StorageVolume(MAIN_STORAGE_ID_STR,
                mMainStorageDir, mMainStorageDir, "Primary Storage",
                mMainStorageDir, mMainStorageDir, "Primary Storage",
				true, false, true, false, -1, UserHandle.CURRENT, "", "");
                true, false, true, false, -1, UserHandle.CURRENT, null /* uuid */, "", "");


        final StorageVolume primary = mainStorage;
        final StorageVolume primary = mainStorage;


Loading