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

Commit 4621b366 authored by Maunik Shah's avatar Maunik Shah
Browse files

frameworks/base: Add 'allowMTP' option for storage volume

Added 'allowMTP' option for each storage volume to decide whether
to show up volume in MTP mode or not. If it not defined, by default
it will be visible on MTP. If someone wants to hide the volume,
one can set it 'false'.

Change-Id: I700c6c04f67f93d881aa0a4581e2d23112453f39
parent 931e9c4e
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class StorageVolume implements Parcelable {
    private final long mMaxFileSize;
    /** When set, indicates exclusive ownership of this volume */
    private final UserHandle mOwner;
    private final boolean mAllowMtp;

    private String mUuid;
    private String mUserLabel;
@@ -60,7 +61,7 @@ public class StorageVolume implements Parcelable {

    public StorageVolume(File path, int descriptionId, boolean primary, boolean removable,
            boolean emulated, int mtpReserveSpace, boolean allowMassStorage, long maxFileSize,
            UserHandle owner) {
            UserHandle owner, boolean allowMtp) {
        mPath = path;
        mDescriptionId = descriptionId;
        mPrimary = primary;
@@ -70,6 +71,7 @@ public class StorageVolume implements Parcelable {
        mAllowMassStorage = allowMassStorage;
        mMaxFileSize = maxFileSize;
        mOwner = owner;
        mAllowMtp = allowMtp;
    }

    private StorageVolume(Parcel in) {
@@ -86,12 +88,13 @@ public class StorageVolume implements Parcelable {
        mUuid = in.readString();
        mUserLabel = in.readString();
        mState = in.readString();
        mAllowMtp = in.readInt() != 0;
    }

    public static StorageVolume fromTemplate(StorageVolume template, File path, UserHandle owner) {
        return new StorageVolume(path, template.mDescriptionId, template.mPrimary,
                template.mRemovable, template.mEmulated, template.mMtpReserveSpace,
                template.mAllowMassStorage, template.mMaxFileSize, owner);
                template.mAllowMassStorage, template.mMaxFileSize, owner, template.mAllowMtp);
    }

    /**
@@ -238,6 +241,10 @@ public class StorageVolume implements Parcelable {
        return mState;
    }

    public boolean isMtpEnabled() {
        return mAllowMtp;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof StorageVolume && mPath != null) {
@@ -275,6 +282,7 @@ public class StorageVolume implements Parcelable {
        pw.printPair("mUuid", mUuid);
        pw.printPair("mUserLabel", mUserLabel);
        pw.printPair("mState", mState);
        pw.printPair("mAllowMtp", mAllowMtp);
        pw.decreaseIndent();
    }

@@ -310,5 +318,6 @@ public class StorageVolume implements Parcelable {
        parcel.writeString(mUuid);
        parcel.writeString(mUserLabel);
        parcel.writeString(mState);
        parcel.writeInt(mAllowMtp ? 1 : 0);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -7242,6 +7242,8 @@
        <!-- number of megabytes of storage MTP should reserve for free storage
             (used for emulated storage that is shared with system's data partition) -->
        <attr name="mtpReserve" format="integer" />
        <!-- make false if don't want to get mounted on MTP -->
        <attr name="allowMtp" format="boolean" />
        <!-- true if the storage can be shared via USB mass storage -->
        <attr name="allowMassStorage" format="boolean" />
        <!-- maximum file size for the volume in megabytes, zero or unspecified if it is unbounded -->
+5 −3
Original line number Diff line number Diff line
@@ -1367,6 +1367,8 @@ class MountService extends IMountService.Stub
                            com.android.internal.R.styleable.Storage_mtpReserve, 0);
                    boolean allowMassStorage = a.getBoolean(
                            com.android.internal.R.styleable.Storage_allowMassStorage, false);
                    boolean allowMtp = a.getBoolean(
                            com.android.internal.R.styleable.Storage_allowMtp, true);
                    // resource parser does not support longs, so XML value is in megabytes
                    long maxFileSize = a.getInt(
                            com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L;
@@ -1375,13 +1377,13 @@ class MountService extends IMountService.Stub
                            " primary: " + primary + " removable: " + removable +
                            " emulated: " + emulated +  " mtpReserve: " + mtpReserve +
                            " allowMassStorage: " + allowMassStorage +
                            " maxFileSize: " + maxFileSize);
                            " maxFileSize: " + maxFileSize + " allowMtp: " + allowMtp);

                    if (emulated) {
                        // For devices with emulated storage, we create separate
                        // volumes for each known user.
                        mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false,
                                true, mtpReserve, false, maxFileSize, null);
                                true, mtpReserve, false, maxFileSize, null, allowMtp);

                        final UserManagerService userManager = UserManagerService.getInstance();
                        for (UserInfo user : userManager.getUsers(false)) {
@@ -1394,7 +1396,7 @@ class MountService extends IMountService.Stub
                        } else {
                            final StorageVolume volume = new StorageVolume(new File(path),
                                    descriptionId, primary, removable, emulated, mtpReserve,
                                    allowMassStorage, maxFileSize, null);
                                    allowMassStorage, maxFileSize, null, allowMtp);
                            addVolumeLocked(volume);

                            // Until we hear otherwise, treat as unmounted