Fix MtpDevice to read 0-byte object correctly.
If a requested object is 0 bytes, the remote MTP device can return
MTP_CONTAINER_TYPE_RESPONSE at the first response package. Previous
implementation does not handle the case.
BUG=26317907
Change-Id: I6ae1138bf1b24aa197575bea0440cc032ffd622a
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index f8b913a..23e432e 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -659,6 +659,13 @@
return false;
}
+ // If object size 0 byte, the remote device can reply response packet
+ // without sending any data packets.
+ if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) {
+ mResponse.copyFrom(mData);
+ return mResponse.getResponseCode() == MTP_RESPONSE_OK;
+ }
+
const uint32_t fullLength = mData.getContainerLength();
if ((!expectedLength && fullLength < MTP_CONTAINER_HEADER_SIZE) ||
(expectedLength && *expectedLength + MTP_CONTAINER_HEADER_SIZE != fullLength)) {