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

Commit 5c66471a authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Stop sending object handle with sendObject request.

According to the MTP spec, the sendObject request must follow
sendObjectInfo request and we could not send an object handle with
sendObject request. The CL stops sending object handle with a sendObject
request. Instead it checks if the given object handle equals to the
object handle returned by the previous sendObjectInfo request.

Bug: 31918048
Test: manually invoked sendObjectInfo and sendObject.
Change-Id: I0a80bdf67bf2913522821ac705f3dc548d3edead
(cherry picked from commit 8d20945c)
parent cb85a295
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -220,7 +220,9 @@ MtpDevice::MtpDevice(struct usb_device* device, int interface,
        mTransactionID(0),
        mReceivedResponse(false),
        mProcessingEvent(false),
        mCurrentEventHandle(0)
        mCurrentEventHandle(0),
        mLastSendObjectInfoTransactionID(0),
        mLastSendObjectInfoObjectHandle(0)
{
    mRequestIn1 = usb_request_new(device, ep_in);
    mRequestIn2 = usb_request_new(device, ep_in);
@@ -490,6 +492,8 @@ MtpObjectHandle MtpDevice::sendObjectInfo(MtpObjectInfo* info) {
   if (sendRequest(MTP_OPERATION_SEND_OBJECT_INFO) && sendData()) {
        MtpResponseCode ret = readResponse();
        if (ret == MTP_RESPONSE_OK) {
            mLastSendObjectInfoTransactionID = mRequest.getTransactionID();
            mLastSendObjectInfoObjectHandle = mResponse.getParameter(3);
            info->mStorageID = mResponse.getParameter(1);
            info->mParent = mResponse.getParameter(2);
            info->mHandle = mResponse.getParameter(3);
@@ -502,9 +506,14 @@ MtpObjectHandle MtpDevice::sendObjectInfo(MtpObjectInfo* info) {
bool MtpDevice::sendObject(MtpObjectHandle handle, int size, int srcFD) {
    Mutex::Autolock autoLock(mMutex);

    if (mLastSendObjectInfoTransactionID + 1 != mTransactionID ||
            mLastSendObjectInfoObjectHandle != handle) {
        ALOGE("A sendObject request must follow the sendObjectInfo request.");
        return false;
    }

    int remaining = size;
    mRequest.reset();
    mRequest.setParameter(1, handle);
    bool error = false;
    if (sendRequest(MTP_OPERATION_SEND_OBJECT)) {
        // send data header
+4 −0
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@ private:
    bool                    mProcessingEvent;
    int                     mCurrentEventHandle;

    // to check if a sendObject request follows the last sendObjectInfo request.
    MtpTransactionID        mLastSendObjectInfoTransactionID;
    MtpObjectHandle         mLastSendObjectInfoObjectHandle;

    // to ensure only one MTP transaction at a time
    Mutex                   mMutex;
    Mutex                   mEventMutex;