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

Commit 9f09b2d9 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Persist nickname and flags for volumes."

parents 1a2fdb49 d95d3bfb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.os.storage;

import android.annotation.NonNull;
import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
@@ -59,6 +60,10 @@ public class DiskInfo implements Parcelable {
        volumeIds = parcel.readStringArray();
    }

    public @NonNull String getId() {
        return id;
    }

    public String getDescription() {
        // TODO: splice vendor label into these strings
        if ((flags & FLAG_SD) != 0) {
+61 −3
Original line number Diff line number Diff line
@@ -923,12 +923,13 @@ public interface IMountService extends IInterface {
            }

            @Override
            public VolumeInfo[] getVolumes() throws RemoteException {
            public VolumeInfo[] getVolumes(int _flags) throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
                VolumeInfo[] _result;
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    _data.writeInt(_flags);
                    mRemote.transact(Stub.TRANSACTION_getVolumes, _data, _reply, 0);
                    _reply.readException();
                    _result = _reply.createTypedArray(VolumeInfo.CREATOR);
@@ -1029,6 +1030,39 @@ public interface IMountService extends IInterface {
                    _data.recycle();
                }
            }

            @Override
            public void setVolumeNickname(String volId, String nickname) throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    _data.writeString(volId);
                    _data.writeString(nickname);
                    mRemote.transact(Stub.TRANSACTION_setVolumeNickname, _data, _reply, 0);
                    _reply.readException();
                } finally {
                    _reply.recycle();
                    _data.recycle();
                }
            }

            @Override
            public void setVolumeUserFlags(String volId, int flags, int mask) throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    _data.writeString(volId);
                    _data.writeInt(flags);
                    _data.writeInt(mask);
                    mRemote.transact(Stub.TRANSACTION_setVolumeUserFlags, _data, _reply, 0);
                    _reply.readException();
                } finally {
                    _reply.recycle();
                    _data.recycle();
                }
            }
        }

        private static final String DESCRIPTOR = "IMountService";
@@ -1132,6 +1166,9 @@ public interface IMountService extends IInterface {
        static final int TRANSACTION_partitionPrivate = IBinder.FIRST_CALL_TRANSACTION + 50;
        static final int TRANSACTION_partitionMixed = IBinder.FIRST_CALL_TRANSACTION + 51;

        static final int TRANSACTION_setVolumeNickname = IBinder.FIRST_CALL_TRANSACTION + 52;
        static final int TRANSACTION_setVolumeUserFlags = IBinder.FIRST_CALL_TRANSACTION + 53;

        /**
         * Cast an IBinder object into an IMountService interface, generating a
         * proxy if needed.
@@ -1566,7 +1603,8 @@ public interface IMountService extends IInterface {
                }
                case TRANSACTION_getVolumes: {
                    data.enforceInterface(DESCRIPTOR);
                    VolumeInfo[] volumes = getVolumes();
                    int _flags = data.readInt();
                    VolumeInfo[] volumes = getVolumes(_flags);
                    reply.writeNoException();
                    reply.writeTypedArray(volumes, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
                    return true;
@@ -1614,6 +1652,23 @@ public interface IMountService extends IInterface {
                    reply.writeNoException();
                    return true;
                }
                case TRANSACTION_setVolumeNickname: {
                    data.enforceInterface(DESCRIPTOR);
                    String volId = data.readString();
                    String nickname = data.readString();
                    setVolumeNickname(volId, nickname);
                    reply.writeNoException();
                    return true;
                }
                case TRANSACTION_setVolumeUserFlags: {
                    data.enforceInterface(DESCRIPTOR);
                    String volId = data.readString();
                    int _flags = data.readInt();
                    int _mask = data.readInt();
                    setVolumeUserFlags(volId, _flags, _mask);
                    reply.writeNoException();
                    return true;
                }
            }
            return super.onTransact(code, data, reply, flags);
        }
@@ -1902,7 +1957,7 @@ public interface IMountService extends IInterface {
    public void waitForAsecScan() throws RemoteException;

    public DiskInfo[] getDisks() throws RemoteException;
    public VolumeInfo[] getVolumes() throws RemoteException;
    public VolumeInfo[] getVolumes(int flags) throws RemoteException;

    public void mount(String volId) throws RemoteException;
    public void unmount(String volId) throws RemoteException;
@@ -1911,4 +1966,7 @@ public interface IMountService extends IInterface {
    public void partitionPublic(String diskId) throws RemoteException;
    public void partitionPrivate(String diskId) throws RemoteException;
    public void partitionMixed(String diskId, int ratio) throws RemoteException;

    public void setVolumeNickname(String volId, String nickname) throws RemoteException;
    public void setVolumeUserFlags(String volId, int flags, int mask) throws RemoteException;
}
+26 −0
Original line number Diff line number Diff line
@@ -91,6 +91,13 @@ public interface IMountServiceListener extends IInterface {
                    reply.writeNoException();
                    return true;
                }
                case TRANSACTION_onVolumeMetadataChanged: {
                    data.enforceInterface(DESCRIPTOR);
                    final VolumeInfo vol = (VolumeInfo) data.readParcelable(null);
                    onVolumeMetadataChanged(vol);
                    reply.writeNoException();
                    return true;
                }
            }
            return super.onTransact(code, data, reply, flags);
        }
@@ -175,6 +182,22 @@ public interface IMountServiceListener extends IInterface {
                    _data.recycle();
                }
            }

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

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

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

    /**
@@ -204,4 +228,6 @@ public interface IMountServiceListener extends IInterface {

    public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
            throws RemoteException;

    public void onVolumeMetadataChanged(VolumeInfo vol) throws RemoteException;
}
+3 −0
Original line number Diff line number Diff line
@@ -40,4 +40,7 @@ public class StorageEventListener {

    public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
    }

    public void onVolumeMetadataChanged(VolumeInfo vol) {
    }
}
+50 −1
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ public class StorageManager {
    /** {@hide} */
    public static final String PROP_PRIMARY_PHYSICAL = "ro.vold.primary_physical";

    /** {@hide} */
    public static final int FLAG_ALL_METADATA = 1 << 0;

    private final Context mContext;
    private final ContentResolver mResolver;

@@ -83,6 +86,7 @@ public class StorageManager {
            Handler.Callback {
        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;

        final StorageEventListener mCallback;
        final Handler mHandler;
@@ -105,6 +109,10 @@ public class StorageManager {
                    mCallback.onVolumeStateChanged((VolumeInfo) args.arg1, args.argi2, args.argi3);
                    args.recycle();
                    return true;
                case MSG_VOLUME_METADATA_CHANGED:
                    mCallback.onVolumeMetadataChanged((VolumeInfo) args.arg1);
                    args.recycle();
                    return true;
            }
            args.recycle();
            return false;
@@ -132,6 +140,13 @@ public class StorageManager {
            args.argi3 = newState;
            mHandler.obtainMessage(MSG_VOLUME_STATE_CHANGED, args).sendToTarget();
        }

        @Override
        public void onVolumeMetadataChanged(VolumeInfo vol) {
            final SomeArgs args = SomeArgs.obtain();
            args.arg1 = vol;
            mHandler.obtainMessage(MSG_VOLUME_METADATA_CHANGED, args).sendToTarget();
        }
    }

    /**
@@ -480,8 +495,13 @@ public class StorageManager {

    /** {@hide} */
    public @NonNull List<VolumeInfo> getVolumes() {
        return getVolumes(0);
    }

    /** {@hide} */
    public @NonNull List<VolumeInfo> getVolumes(int flags) {
        try {
            return Arrays.asList(mMountService.getVolumes());
            return Arrays.asList(mMountService.getVolumes(flags));
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -555,6 +575,35 @@ public class StorageManager {
        }
    }

    /** {@hide} */
    public void setVolumeNickname(String volId, String nickname) {
        try {
            mMountService.setVolumeNickname(volId, nickname);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    /** {@hide} */
    public void setVolumeInited(String volId, boolean inited) {
        try {
            mMountService.setVolumeUserFlags(volId, inited ? VolumeInfo.USER_FLAG_INITED : 0,
                    VolumeInfo.USER_FLAG_INITED);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    /** {@hide} */
    public void setVolumeSnoozed(String volId, boolean snoozed) {
        try {
            mMountService.setVolumeUserFlags(volId, snoozed ? VolumeInfo.USER_FLAG_SNOOZED : 0,
                    VolumeInfo.USER_FLAG_SNOOZED);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    /** {@hide} */
    public @Nullable StorageVolume getStorageVolume(File file) {
        return getStorageVolume(getVolumeList(), file);
Loading