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

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

Merge changes Ia5fec45a,I74927f73,I5a3c0b07

* changes:
  MTP: Fix typo in MtpServer::doGetObjectPropList
  MTP: Implement GetPartialObject command
  MTP: Use DateTime form in GetObjectPropDesc for date/time properties.
parents aa0c8ab0 e3634c3a
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -948,18 +948,21 @@ MtpProperty* MyMtpDatabase::getObjectPropertyDesc(MtpObjectProperty property,
            result = new MtpProperty(property, MTP_TYPE_UINT128);
            break;
        case MTP_PROPERTY_NAME:
        case MTP_PROPERTY_DATE_MODIFIED:
        case MTP_PROPERTY_DISPLAY_NAME:
        case MTP_PROPERTY_DATE_ADDED:
        case MTP_PROPERTY_ARTIST:
        case MTP_PROPERTY_ALBUM_NAME:
        case MTP_PROPERTY_ALBUM_ARTIST:
        case MTP_PROPERTY_ORIGINAL_RELEASE_DATE:
        case MTP_PROPERTY_GENRE:
        case MTP_PROPERTY_COMPOSER:
        case MTP_PROPERTY_DESCRIPTION:
            result = new MtpProperty(property, MTP_TYPE_STR);
            break;
        case MTP_PROPERTY_DATE_MODIFIED:
        case MTP_PROPERTY_DATE_ADDED:
        case MTP_PROPERTY_ORIGINAL_RELEASE_DATE:
            result = new MtpProperty(property, MTP_TYPE_STR);
            result->setFormDateTime();
            break;
        case MTP_PROPERTY_OBJECT_FILE_NAME:
            // We allow renaming files and folders
            result = new MtpProperty(property, MTP_TYPE_STR, true);
+2 −2
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ void MtpPacket::setTransactionID(MtpTransactionID id) {

uint32_t MtpPacket::getParameter(int index) const {
    if (index < 1 || index > 5) {
        LOGE("index %d out of range in MtpRequestPacket::getParameter", index);
        LOGE("index %d out of range in MtpPacket::getParameter", index);
        return 0;
    }
    return getUInt32(MTP_CONTAINER_PARAMETER_OFFSET + (index - 1) * sizeof(uint32_t));
@@ -131,7 +131,7 @@ uint32_t MtpPacket::getParameter(int index) const {

void MtpPacket::setParameter(int index, uint32_t value) {
    if (index < 1 || index > 5) {
        LOGE("index %d out of range in MtpResponsePacket::setParameter", index);
        LOGE("index %d out of range in MtpPacket::setParameter", index);
        return;
    }
    int offset = MTP_CONTAINER_PARAMETER_OFFSET + (index - 1) * sizeof(uint32_t);
+4 −0
Original line number Diff line number Diff line
@@ -312,6 +312,10 @@ void MtpProperty::setFormEnum(const int* values, int count) {
    }
}

void MtpProperty::setFormDateTime() {
     mFormFlag = kFormDateTime;
}

void MtpProperty::print() {
    LOGV("MtpProperty %04X\n", mCode);
    LOGV("    type %04X\n", mType);
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public:
        kFormNone = 0,
        kFormRange = 1,
        kFormEnum = 2,
        kFormDateTime = 3,
    };

    uint32_t            mGroupCode;
@@ -90,6 +91,7 @@ public:

    void                setFormRange(int min, int max, int step);
    void                setFormEnum(const int* values, int count);
    void                setFormDateTime();

    void                print();

+44 −2
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ static const MtpOperationCode kSupportedOperationCodes[] = {
//    MTP_OPERATION_TERMINATE_OPEN_CAPTURE,
//    MTP_OPERATION_MOVE_OBJECT,
//    MTP_OPERATION_COPY_OBJECT,
//    MTP_OPERATION_GET_PARTIAL_OBJECT,
    MTP_OPERATION_GET_PARTIAL_OBJECT,
//    MTP_OPERATION_INITIATE_OPEN_CAPTURE,
    MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED,
    MTP_OPERATION_GET_OBJECT_PROP_DESC,
@@ -289,6 +289,9 @@ bool MtpServer::handleRequest() {
        case MTP_OPERATION_GET_OBJECT:
            response = doGetObject();
            break;
        case MTP_OPERATION_GET_PARTIAL_OBJECT:
            response = doGetPartialObject();
            break;
        case MTP_OPERATION_SEND_OBJECT_INFO:
            response = doSendObjectInfo();
            break;
@@ -536,7 +539,7 @@ MtpResponseCode MtpServer::doGetObjectPropList() {
    MtpObjectFormat format = mRequest.getParameter(2);
    MtpDeviceProperty property = mRequest.getParameter(3);
    int groupCode = mRequest.getParameter(4);
    int depth = mRequest.getParameter(4);
    int depth = mRequest.getParameter(5);
   LOGD("GetObjectPropList %d format: %s property: %s group: %d depth: %d\n",
            handle, MtpDebug::getFormatCodeName(format),
            MtpDebug::getObjectPropCodeName(property), groupCode, depth);
@@ -583,6 +586,45 @@ MtpResponseCode MtpServer::doGetObject() {
    return MTP_RESPONSE_OK;
}

MtpResponseCode MtpServer::doGetPartialObject() {
    MtpObjectHandle handle = mRequest.getParameter(1);
    uint32_t offset = mRequest.getParameter(2);
    uint32_t length = mRequest.getParameter(3);
    MtpString pathBuf;
    int64_t fileLength;
    int result = mDatabase->getObjectFilePath(handle, pathBuf, fileLength);
    if (result != MTP_RESPONSE_OK)
        return result;
    if (offset + length > fileLength)
        length = fileLength - offset;

    const char* filePath = (const char *)pathBuf;
    mtp_file_range  mfr;
    mfr.fd = open(filePath, O_RDONLY);
    if (mfr.fd < 0) {
        return MTP_RESPONSE_GENERAL_ERROR;
    }
    mfr.offset = offset;
    mfr.length = length;
    mResponse.setParameter(1, length);

    // send data header
    mData.setOperationCode(mRequest.getOperationCode());
    mData.setTransactionID(mRequest.getTransactionID());
    mData.writeDataHeader(mFD, length + MTP_CONTAINER_HEADER_SIZE);

    // then transfer the file
    int ret = ioctl(mFD, MTP_SEND_FILE, (unsigned long)&mfr);
    close(mfr.fd);
    if (ret < 0) {
        if (errno == ECANCELED)
            return MTP_RESPONSE_TRANSACTION_CANCELLED;
        else
            return MTP_RESPONSE_GENERAL_ERROR;
    }
    return MTP_RESPONSE_OK;
}

MtpResponseCode MtpServer::doSendObjectInfo() {
    MtpString path;
    MtpStorageID storageID = mRequest.getParameter(1);
Loading