MtpObjectHandleList* MtpStorage::getObjectList(MtpStorageID storageID, MtpObjectHandle parent) { MTPD("MtpStorage::getObjectList, parent: %u\n", parent); //append object id (numerical #s) of database to int array MtpObjectHandleList* list = new MtpObjectHandleList(); if (parent == MTP_PARENT_ROOT) { MTPD("parent == MTP_PARENT_ROOT\n"); parent = 0; } if (mtpmap.find(parent) == mtpmap.end()) { MTPE("parent handle not found, returning empty list\n"); return list; } Tree* tree = mtpmap[parent]; if (!tree->wasAlreadyRead()) { std::string path = getNodePath(tree); MTPD("reading directory on demand for tree %p (%u), path: %s\n", tree, tree->Mtpid(), path.c_str()); readDir(path, tree); } mtpmap[parent]->getmtpids(list); MTPD("returning %u objects in %s.\n", list->size(), tree->getName().c_str()); return list; }
static jintArray android_mtp_MtpDevice_get_object_handles(JNIEnv *env, jobject thiz, jint storageID, jint format, jint objectID) { MtpDevice* device = get_device_from_object(env, thiz); if (!device) return NULL; MtpObjectHandleList* handles = device->getObjectHandles(storageID, format, objectID); if (!handles) return NULL; int length = handles->size(); jintArray array = env->NewIntArray(length); // FIXME is this cast safe? env->SetIntArrayRegion(array, 0, length, (const jint *)handles->array()); delete handles; return array; }