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

Commit 7e92ef3a authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Volumes know parent disks; unsupported disks.

This is cleaner and more direct than the reverse of having the disk
publish child volume membership.  Rename state constants to match
public API.  Add state representing bad removal.  Make it clear that
volume flags are related to mounting.

Send new unsupported disk event when we finish scanning an entire
disk and have no meaningful volumes.

Splice disk labels into description when known.  Only adoptable
slots are directly visible to apps.

Bug: 19993667
Change-Id: I12fda95be0d82781f70c3d85c039749052dc936b
parent 1783f149
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.DebugUtils;

import com.android.internal.util.IndentingPrintWriter;
@@ -46,7 +47,6 @@ public class DiskInfo implements Parcelable {
    public final int flags;
    public long size;
    public String label;
    public String[] volumeIds;

    public DiskInfo(String id, int flags) {
        this.id = Preconditions.checkNotNull(id);
@@ -58,7 +58,6 @@ public class DiskInfo implements Parcelable {
        flags = parcel.readInt();
        size = parcel.readLong();
        label = parcel.readString();
        volumeIds = parcel.readStringArray();
    }

    public @NonNull String getId() {
@@ -66,11 +65,19 @@ public class DiskInfo implements Parcelable {
    }

    public String getDescription() {
        // TODO: splice vendor label into these strings
        final Resources res = Resources.getSystem();
        if ((flags & FLAG_SD) != 0) {
            return Resources.getSystem().getString(com.android.internal.R.string.storage_sd_card);
            if (TextUtils.isEmpty(label)) {
                return res.getString(com.android.internal.R.string.storage_sd_card);
            } else {
                return res.getString(com.android.internal.R.string.storage_sd_card_label, label);
            }
        } else if ((flags & FLAG_USB) != 0) {
            return Resources.getSystem().getString(com.android.internal.R.string.storage_usb);
            if (TextUtils.isEmpty(label)) {
                return res.getString(com.android.internal.R.string.storage_usb_drive);
            } else {
                return res.getString(com.android.internal.R.string.storage_usb_drive_label, label);
            }
        } else {
            return null;
        }
@@ -96,13 +103,11 @@ public class DiskInfo implements Parcelable {
    }

    public void dump(IndentingPrintWriter pw) {
        pw.println("DiskInfo:");
        pw.println("DiskInfo{" + id + "}:");
        pw.increaseIndent();
        pw.printPair("id", id);
        pw.printPair("flags", DebugUtils.flagsToString(getClass(), "FLAG_", flags));
        pw.printPair("size", size);
        pw.printPair("label", label);
        pw.printPair("volumeIds", volumeIds);
        pw.decreaseIndent();
        pw.println();
    }
@@ -156,6 +161,5 @@ public class DiskInfo implements Parcelable {
        parcel.writeInt(this.flags);
        parcel.writeLong(size);
        parcel.writeString(label);
        parcel.writeStringArray(volumeIds);
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -98,6 +98,13 @@ public interface IMountServiceListener extends IInterface {
                    reply.writeNoException();
                    return true;
                }
                case TRANSACTION_onDiskUnsupported: {
                    data.enforceInterface(DESCRIPTOR);
                    final DiskInfo disk = (DiskInfo) data.readParcelable(null);
                    onDiskUnsupported(disk);
                    reply.writeNoException();
                    return true;
                }
            }
            return super.onTransact(code, data, reply, flags);
        }
@@ -198,6 +205,22 @@ public interface IMountServiceListener extends IInterface {
                    _data.recycle();
                }
            }

            @Override
            public void onDiskUnsupported(DiskInfo disk) throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    _data.writeParcelable(disk, 0);
                    mRemote.transact(Stub.TRANSACTION_onDiskUnsupported, _data, _reply,
                            android.os.IBinder.FLAG_ONEWAY);
                    _reply.readException();
                } finally {
                    _reply.recycle();
                    _data.recycle();
                }
            }
        }

        static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
@@ -206,6 +229,7 @@ public interface IMountServiceListener extends IInterface {

        static final int TRANSACTION_onVolumeStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 2);
        static final int TRANSACTION_onVolumeMetadataChanged = (IBinder.FIRST_CALL_TRANSACTION + 3);
        static final int TRANSACTION_onDiskUnsupported = (IBinder.FIRST_CALL_TRANSACTION + 4);
    }

    /**
@@ -230,4 +254,6 @@ public interface IMountServiceListener extends IInterface {
            throws RemoteException;

    public void onVolumeMetadataChanged(VolumeInfo vol) throws RemoteException;

    public void onDiskUnsupported(DiskInfo disk) throws RemoteException;
}
+3 −0
Original line number Diff line number Diff line
@@ -43,4 +43,7 @@ public class StorageEventListener {

    public void onVolumeMetadataChanged(VolumeInfo vol) {
    }

    public void onDiskUnsupported(DiskInfo disk) {
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ public class StorageManager {
        private static final int MSG_STORAGE_STATE_CHANGED = 1;
        private static final int MSG_VOLUME_STATE_CHANGED = 2;
        private static final int MSG_VOLUME_METADATA_CHANGED = 3;
        private static final int MSG_DISK_UNSUPPORTED = 4;

        final StorageEventListener mCallback;
        final Handler mHandler;
@@ -113,6 +114,10 @@ public class StorageManager {
                    mCallback.onVolumeMetadataChanged((VolumeInfo) args.arg1);
                    args.recycle();
                    return true;
                case MSG_DISK_UNSUPPORTED:
                    mCallback.onDiskUnsupported((DiskInfo) args.arg1);
                    args.recycle();
                    return true;
            }
            args.recycle();
            return false;
@@ -147,6 +152,13 @@ public class StorageManager {
            args.arg1 = vol;
            mHandler.obtainMessage(MSG_VOLUME_METADATA_CHANGED, args).sendToTarget();
        }

        @Override
        public void onDiskUnsupported(DiskInfo disk) {
            final SomeArgs args = SomeArgs.obtain();
            args.arg1 = disk;
            mHandler.obtainMessage(MSG_DISK_UNSUPPORTED, args).sendToTarget();
        }
    }

    /**
+30 −28
Original line number Diff line number Diff line
@@ -63,15 +63,17 @@ public class VolumeInfo implements Parcelable {
    public static final int TYPE_OBB = 4;

    public static final int STATE_UNMOUNTED = 0;
    public static final int STATE_MOUNTING = 1;
    public static final int STATE_CHECKING = 1;
    public static final int STATE_MOUNTED = 2;
    public static final int STATE_FORMATTING = 3;
    public static final int STATE_UNMOUNTING = 4;
    public static final int STATE_UNMOUNTABLE = 5;
    public static final int STATE_REMOVED = 6;
    public static final int STATE_MOUNTED_READ_ONLY = 3;
    public static final int STATE_FORMATTING = 4;
    public static final int STATE_EJECTING = 5;
    public static final int STATE_UNMOUNTABLE = 6;
    public static final int STATE_REMOVED = 7;
    public static final int STATE_BAD_REMOVAL = 8;

    public static final int FLAG_PRIMARY = 1 << 0;
    public static final int FLAG_VISIBLE = 1 << 1;
    public static final int MOUNT_FLAG_PRIMARY = 1 << 0;
    public static final int MOUNT_FLAG_VISIBLE = 1 << 1;

    public static final int USER_FLAG_INITED = 1 << 0;
    public static final int USER_FLAG_SNOOZED = 1 << 1;
@@ -97,10 +99,10 @@ public class VolumeInfo implements Parcelable {

    static {
        sStateToEnvironment.put(VolumeInfo.STATE_UNMOUNTED, Environment.MEDIA_UNMOUNTED);
        sStateToEnvironment.put(VolumeInfo.STATE_MOUNTING, Environment.MEDIA_CHECKING);
        sStateToEnvironment.put(VolumeInfo.STATE_CHECKING, Environment.MEDIA_CHECKING);
        sStateToEnvironment.put(VolumeInfo.STATE_MOUNTED, Environment.MEDIA_MOUNTED);
        sStateToEnvironment.put(VolumeInfo.STATE_FORMATTING, Environment.MEDIA_UNMOUNTED);
        sStateToEnvironment.put(VolumeInfo.STATE_UNMOUNTING, Environment.MEDIA_EJECTING);
        sStateToEnvironment.put(VolumeInfo.STATE_EJECTING, Environment.MEDIA_EJECTING);
        sStateToEnvironment.put(VolumeInfo.STATE_UNMOUNTABLE, Environment.MEDIA_UNMOUNTABLE);
        sStateToEnvironment.put(VolumeInfo.STATE_REMOVED, Environment.MEDIA_REMOVED);

@@ -115,8 +117,9 @@ public class VolumeInfo implements Parcelable {
    /** vold state */
    public final String id;
    public final int type;
    public int flags = 0;
    public int userId = -1;
    public final String diskId;
    public int mountFlags = 0;
    public int mountUserId = -1;
    public int state = STATE_UNMOUNTED;
    public String fsType;
    public String fsUuid;
@@ -125,28 +128,28 @@ public class VolumeInfo implements Parcelable {

    /** Framework state */
    public final int mtpIndex;
    public String diskId;
    public String nickname;
    public int userFlags = 0;

    public VolumeInfo(String id, int type, int mtpIndex) {
    public VolumeInfo(String id, int type, String diskId, int mtpIndex) {
        this.id = Preconditions.checkNotNull(id);
        this.type = type;
        this.diskId = diskId;
        this.mtpIndex = mtpIndex;
    }

    public VolumeInfo(Parcel parcel) {
        id = parcel.readString();
        type = parcel.readInt();
        flags = parcel.readInt();
        userId = parcel.readInt();
        diskId = parcel.readString();
        mountFlags = parcel.readInt();
        mountUserId = parcel.readInt();
        state = parcel.readInt();
        fsType = parcel.readString();
        fsUuid = parcel.readString();
        fsLabel = parcel.readString();
        path = parcel.readString();
        mtpIndex = parcel.readInt();
        diskId = parcel.readString();
        nickname = parcel.readString();
        userFlags = parcel.readInt();
    }
@@ -209,11 +212,11 @@ public class VolumeInfo implements Parcelable {
    }

    public boolean isPrimary() {
        return (flags & FLAG_PRIMARY) != 0;
        return (mountFlags & MOUNT_FLAG_PRIMARY) != 0;
    }

    public boolean isVisible() {
        return (flags & FLAG_VISIBLE) != 0;
        return (mountFlags & MOUNT_FLAG_VISIBLE) != 0;
    }

    public boolean isInited() {
@@ -225,7 +228,7 @@ public class VolumeInfo implements Parcelable {
    }

    public boolean isVisibleToUser(int userId) {
        if (type == TYPE_PUBLIC && userId == this.userId) {
        if (type == TYPE_PUBLIC && userId == this.mountUserId) {
            return isVisible();
        } else if (type == TYPE_EMULATED) {
            return isVisible();
@@ -241,7 +244,7 @@ public class VolumeInfo implements Parcelable {
    public File getPathForUser(int userId) {
        if (path == null) {
            return null;
        } else if (type == TYPE_PUBLIC && userId == this.userId) {
        } else if (type == TYPE_PUBLIC && userId == this.mountUserId) {
            return new File(path);
        } else if (type == TYPE_EMULATED) {
            return new File(path, Integer.toString(userId));
@@ -333,12 +336,12 @@ public class VolumeInfo implements Parcelable {
    }

    public void dump(IndentingPrintWriter pw) {
        pw.println("VolumeInfo:");
        pw.println("VolumeInfo{" + id + "}:");
        pw.increaseIndent();
        pw.printPair("id", id);
        pw.printPair("type", DebugUtils.valueToString(getClass(), "TYPE_", type));
        pw.printPair("flags", DebugUtils.flagsToString(getClass(), "FLAG_", flags));
        pw.printPair("userId", userId);
        pw.printPair("diskId", diskId);
        pw.printPair("mountFlags", DebugUtils.flagsToString(getClass(), "MOUNT_FLAG_", mountFlags));
        pw.printPair("mountUserId", mountUserId);
        pw.printPair("state", DebugUtils.valueToString(getClass(), "STATE_", state));
        pw.println();
        pw.printPair("fsType", fsType);
@@ -347,7 +350,6 @@ public class VolumeInfo implements Parcelable {
        pw.println();
        pw.printPair("path", path);
        pw.printPair("mtpIndex", mtpIndex);
        pw.printPair("diskId", diskId);
        pw.printPair("nickname", nickname);
        pw.printPair("userFlags", DebugUtils.flagsToString(getClass(), "USER_FLAG_", userFlags));
        pw.decreaseIndent();
@@ -401,15 +403,15 @@ public class VolumeInfo implements Parcelable {
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeString(id);
        parcel.writeInt(type);
        parcel.writeInt(this.flags);
        parcel.writeInt(userId);
        parcel.writeString(diskId);
        parcel.writeInt(mountFlags);
        parcel.writeInt(mountUserId);
        parcel.writeInt(state);
        parcel.writeString(fsType);
        parcel.writeString(fsUuid);
        parcel.writeString(fsLabel);
        parcel.writeString(path);
        parcel.writeInt(mtpIndex);
        parcel.writeString(diskId);
        parcel.writeString(nickname);
        parcel.writeInt(userFlags);
    }
Loading