Loading media/mtp/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ LOCAL_SRC_FILES:= \ MtpDeviceInfo.cpp \ MtpObjectInfo.cpp \ MtpPacket.cpp \ MtpProperty.cpp \ MtpRequestPacket.cpp \ MtpResponsePacket.cpp \ MtpStorageInfo.cpp \ Loading media/mtp/MtpDataPacket.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,13 @@ uint64_t MtpDataPacket::getUInt64() { return result; } void MtpDataPacket::getUInt128(uint128_t& value) { value[0] = getUInt32(); value[1] = getUInt32(); value[2] = getUInt32(); value[3] = getUInt32(); } void MtpDataPacket::getString(MtpStringBuffer& string) { string.readFromPacket(this); Loading Loading @@ -217,6 +224,20 @@ void MtpDataPacket::putUInt64(uint64_t value) { mPacketSize = mOffset; } void MtpDataPacket::putInt128(const int128_t& value) { putInt32(value[0]); putInt32(value[1]); putInt32(value[2]); putInt32(value[3]); } void MtpDataPacket::putUInt128(const uint128_t& value) { putUInt32(value[0]); putUInt32(value[1]); putUInt32(value[2]); putUInt32(value[3]); } void MtpDataPacket::putAInt8(const int8_t* values, int count) { putUInt32(count); for (int i = 0; i < count; i++) Loading media/mtp/MtpDataPacket.h +4 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ public: inline int32_t getInt32() { return (int32_t)getUInt32(); } uint64_t getUInt64(); inline int64_t getInt64() { return (int64_t)getUInt64(); } void getUInt128(uint128_t& value); inline void getInt128(int128_t& value) { getUInt128((uint128_t&)value); } void getString(MtpStringBuffer& string); Int8List* getAInt8(); Loading @@ -63,6 +65,8 @@ public: void putUInt32(uint32_t value); void putInt64(int64_t value); void putUInt64(uint64_t value); void putInt128(const int128_t& value); void putUInt128(const uint128_t& value); void putAInt8(const int8_t* values, int count); void putAUInt8(const uint8_t* values, int count); Loading media/mtp/MtpDevice.cpp +41 −11 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -28,6 +31,7 @@ #include "MtpDebug.h" #include "MtpDeviceInfo.h" #include "MtpObjectInfo.h" #include "MtpProperty.h" #include "MtpStorageInfo.h" #include "MtpStringBuffer.h" Loading @@ -50,6 +54,8 @@ MtpDevice::MtpDevice(struct usb_device* device, int interface, MtpDevice::~MtpDevice() { close(); for (int i = 0; i < mDeviceProperties.size(); i++) delete mDeviceProperties[i]; } void MtpDevice::initialize() { Loading @@ -57,6 +63,18 @@ void MtpDevice::initialize() { 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); } } } } } Loading @@ -76,7 +94,6 @@ const char* MtpDevice::getDeviceName() { } bool MtpDevice::openSession() { printf("openSession\n"); mSessionID = 0; mTransactionID = 0; MtpSessionID newSession = 1; Loading Loading @@ -107,7 +124,6 @@ MtpDeviceInfo* MtpDevice::getDeviceInfo() { 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); Loading Loading @@ -137,7 +153,6 @@ MtpStorageInfo* MtpDevice::getStorageInfo(MtpStorageID storageID) { 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); Loading @@ -157,7 +172,6 @@ MtpObjectHandleList* MtpDevice::getObjectHandles(MtpStorageID storageID, if (!readData()) return NULL; MtpResponseCode ret = readResponse(); printf("getObjectHandles returned %04X\n", ret); if (ret == MTP_RESPONSE_OK) { return mData.getAUInt32(); } Loading @@ -172,7 +186,6 @@ MtpObjectInfo* MtpDevice::getObjectInfo(MtpObjectHandle handle) { 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); Loading @@ -181,8 +194,25 @@ printf("getObjectInfo returned %04X\n", ret); 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++); Loading @@ -192,7 +222,7 @@ bool MtpDevice::sendRequest(MtpOperationCode operation) { } bool MtpDevice::sendData(MtpOperationCode operation) { printf("sendData\n"); LOGD("sendData\n"); mData.setOperationCode(mRequest.getOperationCode()); mData.setTransactionID(mRequest.getTransactionID()); int ret = mData.write(mEndpointOut); Loading @@ -203,26 +233,26 @@ bool MtpDevice::sendData(MtpOperationCode operation) { 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; } } Loading media/mtp/MtpDevice.h +3 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ private: struct usb_endpoint* mEndpointOut; struct usb_endpoint* mEndpointIntr; MtpDeviceInfo* mDeviceInfo; MtpPropertyList mDeviceProperties; // a unique ID for the device int mID; Loading Loading @@ -70,6 +71,8 @@ public: MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent); MtpObjectInfo* getObjectInfo(MtpObjectHandle handle); MtpProperty* getDevicePropDesc(MtpDeviceProperty code); private: bool sendRequest(MtpOperationCode operation); bool sendData(MtpOperationCode operation); Loading Loading
media/mtp/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ LOCAL_SRC_FILES:= \ MtpDeviceInfo.cpp \ MtpObjectInfo.cpp \ MtpPacket.cpp \ MtpProperty.cpp \ MtpRequestPacket.cpp \ MtpResponsePacket.cpp \ MtpStorageInfo.cpp \ Loading
media/mtp/MtpDataPacket.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,13 @@ uint64_t MtpDataPacket::getUInt64() { return result; } void MtpDataPacket::getUInt128(uint128_t& value) { value[0] = getUInt32(); value[1] = getUInt32(); value[2] = getUInt32(); value[3] = getUInt32(); } void MtpDataPacket::getString(MtpStringBuffer& string) { string.readFromPacket(this); Loading Loading @@ -217,6 +224,20 @@ void MtpDataPacket::putUInt64(uint64_t value) { mPacketSize = mOffset; } void MtpDataPacket::putInt128(const int128_t& value) { putInt32(value[0]); putInt32(value[1]); putInt32(value[2]); putInt32(value[3]); } void MtpDataPacket::putUInt128(const uint128_t& value) { putUInt32(value[0]); putUInt32(value[1]); putUInt32(value[2]); putUInt32(value[3]); } void MtpDataPacket::putAInt8(const int8_t* values, int count) { putUInt32(count); for (int i = 0; i < count; i++) Loading
media/mtp/MtpDataPacket.h +4 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ public: inline int32_t getInt32() { return (int32_t)getUInt32(); } uint64_t getUInt64(); inline int64_t getInt64() { return (int64_t)getUInt64(); } void getUInt128(uint128_t& value); inline void getInt128(int128_t& value) { getUInt128((uint128_t&)value); } void getString(MtpStringBuffer& string); Int8List* getAInt8(); Loading @@ -63,6 +65,8 @@ public: void putUInt32(uint32_t value); void putInt64(int64_t value); void putUInt64(uint64_t value); void putInt128(const int128_t& value); void putUInt128(const uint128_t& value); void putAInt8(const int8_t* values, int count); void putAUInt8(const uint8_t* values, int count); Loading
media/mtp/MtpDevice.cpp +41 −11 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -28,6 +31,7 @@ #include "MtpDebug.h" #include "MtpDeviceInfo.h" #include "MtpObjectInfo.h" #include "MtpProperty.h" #include "MtpStorageInfo.h" #include "MtpStringBuffer.h" Loading @@ -50,6 +54,8 @@ MtpDevice::MtpDevice(struct usb_device* device, int interface, MtpDevice::~MtpDevice() { close(); for (int i = 0; i < mDeviceProperties.size(); i++) delete mDeviceProperties[i]; } void MtpDevice::initialize() { Loading @@ -57,6 +63,18 @@ void MtpDevice::initialize() { 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); } } } } } Loading @@ -76,7 +94,6 @@ const char* MtpDevice::getDeviceName() { } bool MtpDevice::openSession() { printf("openSession\n"); mSessionID = 0; mTransactionID = 0; MtpSessionID newSession = 1; Loading Loading @@ -107,7 +124,6 @@ MtpDeviceInfo* MtpDevice::getDeviceInfo() { 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); Loading Loading @@ -137,7 +153,6 @@ MtpStorageInfo* MtpDevice::getStorageInfo(MtpStorageID storageID) { 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); Loading @@ -157,7 +172,6 @@ MtpObjectHandleList* MtpDevice::getObjectHandles(MtpStorageID storageID, if (!readData()) return NULL; MtpResponseCode ret = readResponse(); printf("getObjectHandles returned %04X\n", ret); if (ret == MTP_RESPONSE_OK) { return mData.getAUInt32(); } Loading @@ -172,7 +186,6 @@ MtpObjectInfo* MtpDevice::getObjectInfo(MtpObjectHandle handle) { 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); Loading @@ -181,8 +194,25 @@ printf("getObjectInfo returned %04X\n", ret); 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++); Loading @@ -192,7 +222,7 @@ bool MtpDevice::sendRequest(MtpOperationCode operation) { } bool MtpDevice::sendData(MtpOperationCode operation) { printf("sendData\n"); LOGD("sendData\n"); mData.setOperationCode(mRequest.getOperationCode()); mData.setTransactionID(mRequest.getTransactionID()); int ret = mData.write(mEndpointOut); Loading @@ -203,26 +233,26 @@ bool MtpDevice::sendData(MtpOperationCode operation) { 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; } } Loading
media/mtp/MtpDevice.h +3 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ private: struct usb_endpoint* mEndpointOut; struct usb_endpoint* mEndpointIntr; MtpDeviceInfo* mDeviceInfo; MtpPropertyList mDeviceProperties; // a unique ID for the device int mID; Loading Loading @@ -70,6 +71,8 @@ public: MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent); MtpObjectInfo* getObjectInfo(MtpObjectHandle handle); MtpProperty* getDevicePropDesc(MtpDeviceProperty code); private: bool sendRequest(MtpOperationCode operation); bool sendData(MtpOperationCode operation); Loading