Add getObjectPropValue function to MtpDevice.
In the MTP spec, the object size is stored in MtpObjectInfo as unsigned
32-bit integer and fetched by the getObjectInfo operation. For the
objects that are more than 4GB, the object size is provided as one of
extra properties, which are fetched by different operation.
The CL adds to getObjectPropValue method to MtpDevice class so that
client code can obtain 4GB+ object size from object property.
BUG=27805369
Change-Id: I0b91facd07cdc19866cb29f7df08bb1698bcf60b
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index d2a93a7..bd89a51 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -611,7 +611,7 @@
return NULL;
if (!readData())
return NULL;
- MtpResponseCode ret = readResponse();
+ const MtpResponseCode ret = readResponse();
if (ret == MTP_RESPONSE_OK) {
MtpProperty* property = new MtpProperty;
if (property->read(mData))
@@ -622,6 +622,25 @@
return NULL;
}
+bool MtpDevice::getObjectPropValue(MtpObjectHandle handle, MtpProperty* property) {
+ if (property == nullptr)
+ return false;
+
+ Mutex::Autolock autoLock(mMutex);
+
+ mRequest.reset();
+ mRequest.setParameter(1, handle);
+ mRequest.setParameter(2, property->getPropertyCode());
+ if (!sendRequest(MTP_OPERATION_GET_OBJECT_PROP_VALUE))
+ return false;
+ if (!readData())
+ return false;
+ if (readResponse() != MTP_RESPONSE_OK)
+ return false;
+ property->setCurrentValue(mData);
+ return true;
+}
+
bool MtpDevice::readObject(MtpObjectHandle handle,
ReadObjectCallback callback,
uint32_t expectedLength,
diff --git a/media/mtp/MtpDevice.h b/media/mtp/MtpDevice.h
index ce60811..4be44cf 100644
--- a/media/mtp/MtpDevice.h
+++ b/media/mtp/MtpDevice.h
@@ -107,6 +107,9 @@
MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);
+ // Reads value of |property| for |handle|. Returns true on success.
+ bool getObjectPropValue(MtpObjectHandle handle, MtpProperty* property);
+
bool readObject(MtpObjectHandle handle, ReadObjectCallback callback,
uint32_t objectSize, void* clientData);
bool readObject(MtpObjectHandle handle, const char* destPath, int group,
diff --git a/media/mtp/MtpProperty.cpp b/media/mtp/MtpProperty.cpp
index 2be2d79..039e4f5 100644
--- a/media/mtp/MtpProperty.cpp
+++ b/media/mtp/MtpProperty.cpp
@@ -236,6 +236,12 @@
mCurrentValue.str = NULL;
}
+void MtpProperty::setCurrentValue(MtpDataPacket& packet) {
+ free(mCurrentValue.str);
+ mCurrentValue.str = NULL;
+ readValue(packet, mCurrentValue);
+}
+
void MtpProperty::setFormRange(int min, int max, int step) {
mFormFlag = kFormRange;
switch (mType) {
diff --git a/media/mtp/MtpProperty.h b/media/mtp/MtpProperty.h
index 2e2ead1..03c08e1 100644
--- a/media/mtp/MtpProperty.h
+++ b/media/mtp/MtpProperty.h
@@ -81,13 +81,16 @@
int defaultValue = 0);
virtual ~MtpProperty();
- inline MtpPropertyCode getPropertyCode() const { return mCode; }
+ MtpPropertyCode getPropertyCode() const { return mCode; }
+ MtpDataType getDataType() const { return mType; }
bool read(MtpDataPacket& packet);
void write(MtpDataPacket& packet);
void setDefaultValue(const uint16_t* string);
void setCurrentValue(const uint16_t* string);
+ void setCurrentValue(MtpDataPacket& packet);
+ const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }
void setFormRange(int min, int max, int step);
void setFormEnum(const int* values, int count);