MTP: Add support for retrieving thumbnails to MTP content provider.
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/mtp/MtpCursor.cpp b/media/mtp/MtpCursor.cpp
index 42d9e38..d63a5bf 100644
--- a/media/mtp/MtpCursor.cpp
+++ b/media/mtp/MtpCursor.cpp
@@ -62,6 +62,7 @@
#define OBJECT_DATE_CREATED 218
#define OBJECT_DATE_MODIFIED 219
#define OBJECT_KEYWORDS 220
+#define OBJECT_THUMB 221
MtpCursor::MtpCursor(MtpClient* client, int queryType, int deviceID,
int storageID, int objectID, int columnCount, int* columns)
@@ -364,6 +365,10 @@
if (!putString(window, objectInfo->mKeywords, row, i))
goto fail;
break;
+ case OBJECT_THUMB:
+ if (!putThumbnail(window, objectID, row, i))
+ goto fail;
+ break;
default:
LOGE("fillStorage: unknown column %d\n", mColumns[i]);
goto fail;
@@ -421,4 +426,28 @@
return true;
}
+bool MtpCursor::putThumbnail(CursorWindow* window, int objectID, int row, int column) {
+ MtpDevice* device = mClient->getDevice(mDeviceID);
+ int size;
+ void* thumbnail = device->getThumbnail(objectID, size);
+
+ LOGD("putThumbnail: %p, size: %d\n", thumbnail, size);
+ int offset = window->alloc(size);
+ if (!offset) {
+ window->freeLastRow();
+ LOGE("Failed allocating %u bytes for thumbnail", size);
+ return false;
+ }
+ if (size > 0)
+ window->copyIn(offset, (const uint8_t*)thumbnail, size);
+
+ // This must be updated after the call to alloc(), since that
+ // may move the field around in the window
+ field_slot_t * fieldSlot = window->getFieldSlot(row, column);
+ fieldSlot->type = FIELD_TYPE_BLOB;
+ fieldSlot->data.buffer.offset = offset;
+ fieldSlot->data.buffer.size = size;
+ return true;
+}
+
} // namespace android