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

Commit b80a3cfd authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Add support for uploading files via MTP.

Change-Id: Id1811ab70cb28be471e0a99999e9ad5380deac49
parent c61b3aab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18115,7 +18115,7 @@ package android.mtp {
    method public boolean importFile(int, java.lang.String);
    method public boolean importFile(int, android.os.ParcelFileDescriptor);
    method public boolean open(android.hardware.usb.UsbDeviceConnection);
    method public boolean sendObject(int, android.os.ParcelFileDescriptor);
    method public boolean sendObject(int, int, android.os.ParcelFileDescriptor);
    method public android.mtp.MtpObjectInfo sendObjectInfo(android.mtp.MtpObjectInfo);
  }
+1 −1
Original line number Diff line number Diff line
@@ -19627,7 +19627,7 @@ package android.mtp {
    method public boolean importFile(int, java.lang.String);
    method public boolean importFile(int, android.os.ParcelFileDescriptor);
    method public boolean open(android.hardware.usb.UsbDeviceConnection);
    method public boolean sendObject(int, android.os.ParcelFileDescriptor);
    method public boolean sendObject(int, int, android.os.ParcelFileDescriptor);
    method public android.mtp.MtpObjectInfo sendObjectInfo(android.mtp.MtpObjectInfo);
  }
+4 −3
Original line number Diff line number Diff line
@@ -257,11 +257,12 @@ public final class MtpDevice {
     * on completion, and must be done by the caller.
     *
     * @param objectHandle handle of the target file
     * @param size size of the file in bytes
     * @param descriptor file descriptor to read the data from.
     * @return true if the file transfer succeeds
     */
    public boolean sendObject(int objectHandle, ParcelFileDescriptor descriptor) {
        return native_send_object(objectHandle, descriptor.getFd());
    public boolean sendObject(int objectHandle, int size, ParcelFileDescriptor descriptor) {
        return native_send_object(objectHandle, size, descriptor.getFd());
    }

    /**
@@ -294,6 +295,6 @@ public final class MtpDevice {
    private native long native_get_storage_id(int objectHandle);
    private native boolean native_import_file(int objectHandle, String destPath);
    private native boolean native_import_file(int objectHandle, int fd);
    private native boolean native_send_object(int objectHandle, int fd);
    private native boolean native_send_object(int objectHandle, int size, int fd);
    private native MtpObjectInfo native_send_object_info(MtpObjectInfo info);
}
+19 −19
Original line number Diff line number Diff line
@@ -273,25 +273,25 @@ public final class MtpObjectInfo {
        public Builder(MtpObjectInfo objectInfo) {
            mObjectInfo = new MtpObjectInfo();
            mObjectInfo.mHandle = -1;
            mObjectInfo.mAssociationDesc = mObjectInfo.mAssociationDesc;
            mObjectInfo.mAssociationType = mObjectInfo.mAssociationType;
            mObjectInfo.mCompressedSize = mObjectInfo.mCompressedSize;
            mObjectInfo.mDateCreated = mObjectInfo.mDateCreated;
            mObjectInfo.mDateModified = mObjectInfo.mDateModified;
            mObjectInfo.mFormat = mObjectInfo.mFormat;
            mObjectInfo.mImagePixDepth = mObjectInfo.mImagePixDepth;
            mObjectInfo.mImagePixHeight = mObjectInfo.mImagePixHeight;
            mObjectInfo.mImagePixWidth = mObjectInfo.mImagePixWidth;
            mObjectInfo.mKeywords = mObjectInfo.mKeywords;
            mObjectInfo.mName = mObjectInfo.mName;
            mObjectInfo.mParent = mObjectInfo.mParent;
            mObjectInfo.mProtectionStatus = mObjectInfo.mProtectionStatus;
            mObjectInfo.mSequenceNumber = mObjectInfo.mSequenceNumber;
            mObjectInfo.mStorageId = mObjectInfo.mStorageId;
            mObjectInfo.mThumbCompressedSize = mObjectInfo.mThumbCompressedSize;
            mObjectInfo.mThumbFormat = mObjectInfo.mThumbFormat;
            mObjectInfo.mThumbPixHeight = mObjectInfo.mThumbPixHeight;
            mObjectInfo.mThumbPixWidth = mObjectInfo.mThumbPixWidth;
            mObjectInfo.mAssociationDesc = objectInfo.mAssociationDesc;
            mObjectInfo.mAssociationType = objectInfo.mAssociationType;
            mObjectInfo.mCompressedSize = objectInfo.mCompressedSize;
            mObjectInfo.mDateCreated = objectInfo.mDateCreated;
            mObjectInfo.mDateModified = objectInfo.mDateModified;
            mObjectInfo.mFormat = objectInfo.mFormat;
            mObjectInfo.mImagePixDepth = objectInfo.mImagePixDepth;
            mObjectInfo.mImagePixHeight = objectInfo.mImagePixHeight;
            mObjectInfo.mImagePixWidth = objectInfo.mImagePixWidth;
            mObjectInfo.mKeywords = objectInfo.mKeywords;
            mObjectInfo.mName = objectInfo.mName;
            mObjectInfo.mParent = objectInfo.mParent;
            mObjectInfo.mProtectionStatus = objectInfo.mProtectionStatus;
            mObjectInfo.mSequenceNumber = objectInfo.mSequenceNumber;
            mObjectInfo.mStorageId = objectInfo.mStorageId;
            mObjectInfo.mThumbCompressedSize = objectInfo.mThumbCompressedSize;
            mObjectInfo.mThumbFormat = objectInfo.mThumbFormat;
            mObjectInfo.mThumbPixHeight = objectInfo.mThumbPixHeight;
            mObjectInfo.mThumbPixWidth = objectInfo.mThumbPixWidth;
        }

        public Builder setAssociationDesc(int value) {
+3 −8
Original line number Diff line number Diff line
@@ -412,18 +412,13 @@ android_mtp_MtpDevice_import_file_to_fd(JNIEnv *env, jobject thiz, jint object_i
}

static jboolean
android_mtp_MtpDevice_send_object(JNIEnv *env, jobject thiz, jint object_id, jint fd)
android_mtp_MtpDevice_send_object(JNIEnv *env, jobject thiz, jint object_id, jint size, jint fd)
{
    MtpDevice* device = get_device_from_object(env, thiz);
    if (!device)
        return JNI_FALSE;
    MtpObjectInfo* object_info = device->getObjectInfo(object_id);
    if (!object_info)
        return JNI_FALSE;

    bool result = device->sendObject(object_info, fd);
    delete object_info;
    return result;
    return device->sendObject(object_id, size, fd);
}

static jobject
@@ -516,7 +511,7 @@ static JNINativeMethod gMethods[] = {
    {"native_import_file",      "(ILjava/lang/String;)Z",
                                        (void *)android_mtp_MtpDevice_import_file},
    {"native_import_file",      "(II)Z",(void *)android_mtp_MtpDevice_import_file_to_fd},
    {"native_send_object",      "(II)Z",(void *)android_mtp_MtpDevice_send_object},
    {"native_send_object",      "(III)Z",(void *)android_mtp_MtpDevice_send_object},
    {"native_send_object_info", "(Landroid/mtp/MtpObjectInfo;)Landroid/mtp/MtpObjectInfo;",
                                        (void *)android_mtp_MtpDevice_send_object_info}
};
Loading