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

Commit 9e837861 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

MTP: Compatibility fixes for transferring strings



Change-Id: Ic06d754ee68b0389439cdc34f73adff0f2b33afa
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 243efd2c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -325,9 +325,12 @@ void MtpDataPacket::putString(const uint16_t* string) {
        else
            break;
    }
    putUInt8(count);
    putUInt8(count > 0 ? count + 1 : 0);
    for (int i = 0; i < count; i++)
        putUInt16(string[i]);
    // only terminate with zero if string is not empty
    if (count > 0)
        putUInt16(0);
}

#ifdef MTP_DEVICE 
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public:
    void                putString(const MtpStringBuffer& string);
    void                putString(const char* string);
    void                putString(const uint16_t* string);
    inline void         putEmptyString() { putUInt16(0); }
    inline void         putEmptyString() { putUInt8(0); }
    inline void         putEmptyArray() { putUInt32(0); }


+4 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ void MtpStringBuffer::readFromPacket(MtpDataPacket* packet) {
void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const {
    int count = mCharCount;
    const uint8_t* src = mBuffer;
    packet->putUInt8(count);
    packet->putUInt8(count > 0 ? count + 1 : 0);

    // expand utf8 to 16 bit chars
    for (int i = 0; i < count; i++) {
@@ -133,6 +133,9 @@ void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const {
        }
        packet->putUInt16(ch);
    }
    // only terminate with zero if string is not empty
    if (count > 0)
        packet->putUInt16(0);
}

}  // namespace android