MTP: host support for retrieving device property descriptors

Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index 0282086..5c39628 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#define LOG_TAG "MtpDevice"
+#include "utils/Log.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -28,6 +31,7 @@
 #include "MtpDebug.h"
 #include "MtpDeviceInfo.h"
 #include "MtpObjectInfo.h"
+#include "MtpProperty.h"
 #include "MtpStorageInfo.h"
 #include "MtpStringBuffer.h"
 
@@ -50,6 +54,8 @@
 
 MtpDevice::~MtpDevice() {
     close();
+    for (int i = 0; i < mDeviceProperties.size(); i++)
+        delete mDeviceProperties[i];
 }
 
 void MtpDevice::initialize() {
@@ -57,6 +63,18 @@
     mDeviceInfo = getDeviceInfo();
     if (mDeviceInfo) {
         mDeviceInfo->print();
+
+        if (mDeviceInfo->mDeviceProperties) {
+            int count = mDeviceInfo->mDeviceProperties->size();
+            for (int i = 0; i < count; i++) {
+                MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i];
+                MtpProperty* property = getDevicePropDesc(propCode);
+                if (property) {
+                    property->print();
+                    mDeviceProperties.push(property);
+                }
+            }
+        }
     }
 }
 
@@ -76,7 +94,6 @@
 }
 
 bool MtpDevice::openSession() {
-printf("openSession\n");
     mSessionID = 0;
     mTransactionID = 0;
     MtpSessionID newSession = 1;
@@ -107,7 +124,6 @@
     if (!readData())
         return NULL;
     MtpResponseCode ret = readResponse();
-printf("getDeviceInfo returned %04X\n", ret);
     if (ret == MTP_RESPONSE_OK) {
         MtpDeviceInfo* info = new MtpDeviceInfo;
         info->read(mData);
@@ -137,7 +153,6 @@
     if (!readData())
         return NULL;
     MtpResponseCode ret = readResponse();
-printf("getStorageInfo returned %04X\n", ret);
     if (ret == MTP_RESPONSE_OK) {
         MtpStorageInfo* info = new MtpStorageInfo(storageID);
         info->read(mData);
@@ -157,7 +172,6 @@
     if (!readData())
         return NULL;
     MtpResponseCode ret = readResponse();
-printf("getObjectHandles returned %04X\n", ret);
     if (ret == MTP_RESPONSE_OK) {
         return mData.getAUInt32();
     }
@@ -172,7 +186,6 @@
     if (!readData())
         return NULL;
     MtpResponseCode ret = readResponse();
-printf("getObjectInfo returned %04X\n", ret);
     if (ret == MTP_RESPONSE_OK) {
         MtpObjectInfo* info = new MtpObjectInfo(handle);
         info->read(mData);
@@ -181,8 +194,25 @@
     return NULL;
 }
 
+MtpProperty* MtpDevice::getDevicePropDesc(MtpDeviceProperty code) {
+    mRequest.reset();
+    mRequest.setParameter(1, code);
+    if (!sendRequest(MTP_OPERATION_GET_DEVICE_PROP_DESC))
+        return NULL;
+    if (!readData())
+        return NULL;
+    MtpResponseCode ret = readResponse();
+    if (ret == MTP_RESPONSE_OK) {
+        MtpProperty* property = new MtpProperty;
+        property->read(mData);
+        return property;
+    }
+    return NULL;
+}
+
+
 bool MtpDevice::sendRequest(MtpOperationCode operation) {
-    printf("sendRequest: %s\n", MtpDebug::getOperationCodeName(operation));
+    LOGD("sendRequest: %s\n", MtpDebug::getOperationCodeName(operation));
     mRequest.setOperationCode(operation);
     if (mTransactionID > 0)
         mRequest.setTransactionID(mTransactionID++);
@@ -192,7 +222,7 @@
 }
 
 bool MtpDevice::sendData(MtpOperationCode operation) {
-    printf("sendData\n");
+    LOGD("sendData\n");
     mData.setOperationCode(mRequest.getOperationCode());
     mData.setTransactionID(mRequest.getTransactionID());
     int ret = mData.write(mEndpointOut);
@@ -203,26 +233,26 @@
 bool MtpDevice::readData() {
     mData.reset();
     int ret = mData.read(mEndpointIn);
-    printf("readData returned %d\n", ret);
+    LOGD("readData returned %d\n", ret);
     if (ret >= MTP_CONTAINER_HEADER_SIZE) {
         mData.dump();
         return true;
     }
     else {
-        printf("readResponse failed\n");
+        LOGD("readResponse failed\n");
         return false;
     }
 }
 
 MtpResponseCode MtpDevice::readResponse() {
-    printf("readResponse\n");
+    LOGD("readResponse\n");
     int ret = mResponse.read(mEndpointIn);
     if (ret >= MTP_CONTAINER_HEADER_SIZE) {
         mResponse.dump();
         return mResponse.getResponseCode();
     }
     else {
-        printf("readResponse failed\n");
+        LOGD("readResponse failed\n");
         return -1;
     }
 }