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

Commit 0cd0e797 authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge "MTP: Add host support for deleting objects."

parents 188c432c e0a89f61
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ public final class Mtp
            return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/storage");
        }

        public static Uri getContentUri(int deviceID, int storageID) {
            return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID + "/storage/" + storageID);
        }

        /**
         * Storage unit identifier
         * <P>Type: TEXT</P>
+39 −1
Original line number Diff line number Diff line
@@ -182,13 +182,51 @@ android_media_MtpClient_wait_for_event(JNIEnv *env, jobject thiz)
    client->waitForEvent(env);
}

static jboolean
android_media_MtpClient_delete_object(JNIEnv *env, jobject thiz,
        jint device_id, jint object_id)
{
    MyClient *client = (MyClient *)env->GetIntField(thiz, field_context);
    MtpDevice* device = client->getDevice(device_id);
    if (device)
        return device->deleteObject(object_id);
    else
        return NULL;
}

static jint
android_media_MtpClient_get_parent(JNIEnv *env, jobject thiz,
        jint device_id, jint object_id)
{
    MyClient *client = (MyClient *)env->GetIntField(thiz, field_context);
    MtpDevice* device = client->getDevice(device_id);
    if (device)
        return device->getParent(object_id);
    else
        return -1;
}

static jint
android_media_MtpClient_get_storage_id(JNIEnv *env, jobject thiz,
        jint device_id, jint object_id)
{
    MyClient *client = (MyClient *)env->GetIntField(thiz, field_context);
    MtpDevice* device = client->getDevice(device_id);
    if (device)
        return device->getStorageID(object_id);
    else
        return -1;
}

// ----------------------------------------------------------------------------

static JNINativeMethod gMethods[] = {
    {"native_setup",            "()V",  (void *)android_media_MtpClient_setup},
    {"native_finalize",         "()V",  (void *)android_media_MtpClient_finalize},
    {"native_wait_for_event",   "()V",  (void *)android_media_MtpClient_wait_for_event},

    {"native_delete_object",   "(II)Z", (void *)android_media_MtpClient_delete_object},
    {"native_get_parent",      "(II)I", (void *)android_media_MtpClient_get_parent},
    {"native_get_storage_id",  "(II)I", (void *)android_media_MtpClient_get_storage_id},
};

static const char* const kClassPathName = "android/media/MtpClient";
+15 −0
Original line number Diff line number Diff line
@@ -43,6 +43,18 @@ public class MtpClient {
        mEventThread.start();
    }

    public boolean deleteObject(int deviceID, int objectID) {
        return native_delete_object(deviceID, objectID);
    }

    public int getParent(int deviceID, int objectID) {
        return native_get_parent(deviceID, objectID);
    }

    public int getStorageID(int deviceID, int objectID) {
        return native_get_storage_id(deviceID, objectID);
    }

    private class MtpEventThread extends Thread {

        private boolean mDone;
@@ -77,4 +89,7 @@ public class MtpClient {
    private native final void native_setup();
    private native final void native_finalize();
    private native void native_wait_for_event();
    private native boolean native_delete_object(int deviceID, int objectID);
    private native int native_get_parent(int deviceID, int objectID);
    private native int native_get_storage_id(int deviceID, int objectID);
}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
@@ -108,6 +108,16 @@ public final class MtpCursor extends AbstractWindowedCursor {
        return mCount;
    }

    @Override
    public boolean requery() {
        Log.d(TAG, "requery");
        mCount = NO_COUNT;
        if (mWindow != null) {
            mWindow.clear();
        }
        return super.requery();
    }

    private void fillWindow(int startPos) {
        if (mWindow == null) {
            // If there isn't a window set already it will only be accessed locally
+28 −0
Original line number Diff line number Diff line
@@ -179,6 +179,8 @@ MtpObjectHandleList* MtpDevice::getObjectHandles(MtpStorageID storageID,
}

MtpObjectInfo* MtpDevice::getObjectInfo(MtpObjectHandle handle) {
    // FIXME - we might want to add some caching here

    mRequest.reset();
    mRequest.setParameter(1, handle);
    if (!sendRequest(MTP_OPERATION_GET_OBJECT_INFO))
@@ -205,7 +207,33 @@ void* MtpDevice::getThumbnail(MtpObjectHandle handle, int& outLength) {
    }
    outLength = 0;
    return NULL;
}

bool MtpDevice::deleteObject(MtpObjectHandle handle) {
    mRequest.reset();
    mRequest.setParameter(1, handle);
    if (sendRequest(MTP_OPERATION_DELETE_OBJECT)) {
        MtpResponseCode ret = readResponse();
        if (ret == MTP_RESPONSE_OK)
            return true;
    }
    return false;
}

MtpObjectHandle MtpDevice::getParent(MtpObjectHandle handle) {
    MtpObjectInfo* info = getObjectInfo(handle);
    if (info)
        return info->mParent;
    else
        return -1;
}

MtpObjectHandle MtpDevice::getStorageID(MtpObjectHandle handle) {
    MtpObjectInfo* info = getObjectInfo(handle);
    if (info)
        return info->mStorageID;
    else
        return -1;
}

MtpProperty* MtpDevice::getDevicePropDesc(MtpDeviceProperty code) {
Loading