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

Commit 452e8fe5 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Add NonNull and Nullable annotations to MtpDevice.

BUG=26758882

Change-Id: I5fa7130b671c71aefca848c109bf37389f57b9da
parent 7dba645a
Loading
Loading
Loading
Loading
+25 −23
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ public final class MtpDevice {
     *
     * @param device the {@link android.hardware.usb.UsbDevice} for the MTP or PTP device
     */
    public MtpDevice(UsbDevice device) {
    public MtpDevice(@NonNull UsbDevice device) {
        Preconditions.checkNotNull(device);
        mDevice = device;
    }

@@ -61,7 +62,7 @@ public final class MtpDevice {
     * @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
     * @return true if the device was successfully opened.
     */
    public boolean open(UsbDeviceConnection connection) {
    public boolean open(@NonNull UsbDeviceConnection connection) {
        boolean result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
        if (!result) {
            connection.close();
@@ -94,7 +95,7 @@ public final class MtpDevice {
     *
     * @return the device name
     */
    public String getDeviceName() {
    public @NonNull String getDeviceName() {
        return mDevice.getDeviceName();
    }

@@ -110,16 +111,16 @@ public final class MtpDevice {
    }

    @Override
    public String toString() {
    public @NonNull String toString() {
        return mDevice.getDeviceName();
    }

    /**
     * Returns the {@link MtpDeviceInfo} for this device
     *
     * @return the device info
     * @return the device info, or null if fetching device info fails
     */
    public MtpDeviceInfo getDeviceInfo() {
    public @Nullable MtpDeviceInfo getDeviceInfo() {
        return native_get_device_info();
    }

@@ -127,9 +128,9 @@ public final class MtpDevice {
     * Returns the list of IDs for all storage units on this device
     * Information about each storage unit can be accessed via {@link #getStorageInfo}.
     *
     * @return the list of storage IDs
     * @return the list of storage IDs, or null if fetching storage IDs fails
     */
    public int[] getStorageIds() {
    public @Nullable int[] getStorageIds() {
        return native_get_storage_ids();
    }

@@ -142,9 +143,9 @@ public final class MtpDevice {
     * @param format the format of the object to return, or zero for all formats
     * @param objectHandle the parent object to query, -1 for the storage root,
     *     or zero for all objects
     * @return the object handles
     * @return the object handles, or null if fetching object handles fails
     */
    public int[] getObjectHandles(int storageId, int format, int objectHandle) {
    public @Nullable int[] getObjectHandles(int storageId, int format, int objectHandle) {
        return native_get_object_handles(storageId, format, objectHandle);
    }

@@ -158,7 +159,7 @@ public final class MtpDevice {
     *      {@link MtpObjectInfo#getCompressedSize})
     * @return the object's data, or null if reading fails
     */
    public byte[] getObject(int objectHandle, int objectSize) {
    public @Nullable byte[] getObject(int objectHandle, int objectSize) {
        Preconditions.checkArgumentNonnegative(objectSize, "objectSize should not be negative");
        return native_get_object(objectHandle, objectSize);
    }
@@ -176,7 +177,7 @@ public final class MtpDevice {
     * @param buffer Array to write data.
     * @return Size of bytes that are actually read.
     */
    public long getPartialObject(int objectHandle, long offset, long size, byte[] buffer)
    public long getPartialObject(int objectHandle, long offset, long size, @NonNull byte[] buffer)
            throws IOException {
        return native_get_partial_object(objectHandle, offset, size, buffer);
    }
@@ -197,7 +198,7 @@ public final class MtpDevice {
     * @return Size of bytes that are actually read.
     * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT_64
     */
    public long getPartialObject64(int objectHandle, long offset, long size, byte[] buffer)
    public long getPartialObject64(int objectHandle, long offset, long size, @NonNull byte[] buffer)
            throws IOException {
        return native_get_partial_object_64(objectHandle, offset, size, buffer);
    }
@@ -212,7 +213,7 @@ public final class MtpDevice {
     * @param objectHandle handle of the object to read
     * @return the object's thumbnail, or null if reading fails
     */
    public byte[] getThumbnail(int objectHandle) {
    public @Nullable byte[] getThumbnail(int objectHandle) {
        return native_get_thumbnail(objectHandle);
    }

@@ -220,9 +221,9 @@ public final class MtpDevice {
     * Retrieves the {@link MtpStorageInfo} for a storage unit.
     *
     * @param storageId the ID of the storage unit
     * @return the MtpStorageInfo
     * @return the MtpStorageInfo, or null if fetching storage info fails
     */
    public MtpStorageInfo getStorageInfo(int storageId) {
    public @Nullable MtpStorageInfo getStorageInfo(int storageId) {
        return native_get_storage_info(storageId);
    }

@@ -230,9 +231,9 @@ public final class MtpDevice {
     * Retrieves the {@link MtpObjectInfo} for an object.
     *
     * @param objectHandle the handle of the object
     * @return the MtpObjectInfo
     * @return the MtpObjectInfo, or null if fetching object info fails
     */
    public MtpObjectInfo getObjectInfo(int objectHandle) {
    public @Nullable MtpObjectInfo getObjectInfo(int objectHandle) {
        return native_get_object_info(objectHandle);
    }

@@ -279,7 +280,7 @@ public final class MtpDevice {
     *      {@link android.os.Environment#getExternalStorageDirectory}
     * @return true if the file transfer succeeds
     */
    public boolean importFile(int objectHandle, String destPath) {
    public boolean importFile(int objectHandle, @NonNull String destPath) {
        return native_import_file(objectHandle, destPath);
    }

@@ -293,7 +294,7 @@ public final class MtpDevice {
     * @param descriptor file descriptor to write the data to for the file transfer.
     * @return true if the file transfer succeeds
     */
    public boolean importFile(int objectHandle, ParcelFileDescriptor descriptor) {
    public boolean importFile(int objectHandle, @NonNull ParcelFileDescriptor descriptor) {
        return native_import_file(objectHandle, descriptor.getFd());
    }

@@ -308,7 +309,8 @@ public final class MtpDevice {
     * @param descriptor file descriptor to read the data from.
     * @return true if the file transfer succeeds
     */
    public boolean sendObject(int objectHandle, long size, ParcelFileDescriptor descriptor) {
    public boolean sendObject(
            int objectHandle, long size, @NonNull ParcelFileDescriptor descriptor) {
        return native_send_object(objectHandle, size, descriptor.getFd());
    }

@@ -319,9 +321,9 @@ public final class MtpDevice {
     * The returned {@link MtpObjectInfo} has the new object handle field filled in.
     *
     * @param info metadata of the entry
     * @return object info of the created entry or null if the operation failed.
     * @return object info of the created entry, or null if sending object info fails
     */
    public MtpObjectInfo sendObjectInfo(MtpObjectInfo info) {
    public @Nullable MtpObjectInfo sendObjectInfo(@NonNull MtpObjectInfo info) {
        return native_send_object_info(info);
    }

+2 −2
Original line number Diff line number Diff line
@@ -601,12 +601,12 @@ android_mtp_MtpDevice_send_object_info(JNIEnv *env, jobject thiz, jobject info)
{
    MtpDevice* device = get_device_from_object(env, thiz);
    if (!device) {
        return JNI_FALSE;
        return NULL;
    }

    // Updating existing objects is not supported.
    if (env->GetIntField(info, field_objectInfo_handle) != -1) {
        return JNI_FALSE;
        return NULL;
    }

    MtpObjectInfo* object_info = new MtpObjectInfo(-1);