18182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood/* 28182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * Copyright (C) 2010 The Android Open Source Project 38182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * 48182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * Licensed under the Apache License, Version 2.0 (the "License"); 58182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * you may not use this file except in compliance with the License. 68182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * You may obtain a copy of the License at 78182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * 88182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * http://www.apache.org/licenses/LICENSE-2.0 98182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * 108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * Unless required by applicable law or agreed to in writing, software 118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * distributed under the License is distributed on an "AS IS" BASIS, 128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * See the License for the specific language governing permissions and 148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * limitations under the License. 158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood */ 168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// #define LOG_NDEBUG 0 188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#define LOG_TAG "MtpDeviceJNI" 208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "utils/Log.h" 218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include <stdio.h> 238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include <assert.h> 248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include <limits.h> 258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include <unistd.h> 268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include <fcntl.h> 278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "jni.h" 298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "JNIHelp.h" 308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "android_runtime/AndroidRuntime.h" 318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "private/android_filesystem_config.h" 328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpTypes.h" 348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpDevice.h" 358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpDeviceInfo.h" 368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpStorageInfo.h" 378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpObjectInfo.h" 388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodusing namespace android; 408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ---------------------------------------------------------------------------- 428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_context; 448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodjclass clazz_deviceInfo; 468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodjclass clazz_storageInfo; 478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodjclass clazz_objectInfo; 488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 498182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodjmethodID constructor_deviceInfo; 508182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodjmethodID constructor_storageInfo; 518182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodjmethodID constructor_objectInfo; 528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// MtpDeviceInfo fields 548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_manufacturer; 558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_model; 568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_version; 578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_serialNumber; 588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// MtpStorageInfo fields 608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_storageId; 618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_maxCapacity; 628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_freeSpace; 638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_description; 648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_volumeIdentifier; 658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// MtpObjectInfo fields 678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_handle; 688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_storageId; 698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_format; 708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_protectionStatus; 718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_compressedSize; 728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbFormat; 738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbCompressedSize; 748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbPixWidth; 758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbPixHeight; 768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_imagePixWidth; 778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_imagePixHeight; 788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_imagePixDepth; 798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_parent; 808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_associationType; 818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_associationDesc; 828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_sequenceNumber; 838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_name; 848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_dateCreated; 858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_dateModified; 868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_keywords; 878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 888182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodMtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice) 898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return (MtpDevice*)env->GetIntField(javaDevice, field_context); 918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { 948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (env->ExceptionCheck()) { 953762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("An exception was thrown by callback '%s'.", methodName); 968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood LOGE_EX(env); 978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->ExceptionClear(); 988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 1008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ---------------------------------------------------------------------------- 1028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean 1048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_open(JNIEnv *env, jobject thiz, jstring deviceName, jint fd) 1058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 1068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL); 1073977472d9f3380a8323156dbc7d0090cf2f2d310James Dong if (deviceNameStr == NULL) { 1083977472d9f3380a8323156dbc7d0090cf2f2d310James Dong return false; 1093977472d9f3380a8323156dbc7d0090cf2f2d310James Dong } 1103977472d9f3380a8323156dbc7d0090cf2f2d310James Dong 1118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = MtpDevice::open(deviceNameStr, fd); 1128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->ReleaseStringUTFChars(deviceName, deviceNameStr); 1138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device) 1158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(thiz, field_context, (int)device); 1168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return (device != NULL); 1178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 1188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic void 1208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_close(JNIEnv *env, jobject thiz) 1218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 1228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 1238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device) { 1248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood device->close(); 1258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete device; 1268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(thiz, field_context, 0); 1278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 1288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 1298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject 1318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz) 1328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 1338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 1348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) { 1355baa3a62a97544669fba6d65a11c07f252e654ddSteve Block ALOGD("android_mtp_MtpDevice_get_device_info device is null"); 1368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 1388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDeviceInfo* deviceInfo = device->getDeviceInfo(); 1398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!deviceInfo) { 1405baa3a62a97544669fba6d65a11c07f252e654ddSteve Block ALOGD("android_mtp_MtpDevice_get_device_info deviceInfo is null"); 1418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 1438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jobject info = env->NewObject(clazz_deviceInfo, constructor_deviceInfo); 1448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (info == NULL) { 1453762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Could not create a MtpDeviceInfo object"); 1468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete deviceInfo; 1478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 1498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (deviceInfo->mManufacturer) 1518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_deviceInfo_manufacturer, 1528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(deviceInfo->mManufacturer)); 1538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (deviceInfo->mModel) 1548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_deviceInfo_model, 1558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(deviceInfo->mModel)); 1568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (deviceInfo->mVersion) 1578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_deviceInfo_version, 1588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(deviceInfo->mVersion)); 1598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (deviceInfo->mSerial) 1608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_deviceInfo_serialNumber, 1618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(deviceInfo->mSerial)); 1628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete deviceInfo; 1648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return info; 1658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 1668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jintArray 1688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_ids(JNIEnv *env, jobject thiz) 1698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 1708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 1718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) 1728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpStorageIDList* storageIDs = device->getStorageIDs(); 1748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!storageIDs) 1758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood int length = storageIDs->size(); 1788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jintArray array = env->NewIntArray(length); 1798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood // FIXME is this cast safe? 1808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntArrayRegion(array, 0, length, (const jint *)storageIDs->array()); 1818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete storageIDs; 1838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return array; 1848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 1858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject 1878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_info(JNIEnv *env, jobject thiz, jint storageID) 1888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 1898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 1908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) 1918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpStorageInfo* storageInfo = device->getStorageInfo(storageID); 1938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!storageInfo) 1948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 1958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 1968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jobject info = env->NewObject(clazz_storageInfo, constructor_storageInfo); 1978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (info == NULL) { 1983762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Could not create a MtpStorageInfo object"); 1998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete storageInfo; 2008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 2018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 2028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (storageInfo->mStorageID) 2048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_storageInfo_storageId, storageInfo->mStorageID); 2058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (storageInfo->mMaxCapacity) 2068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetLongField(info, field_storageInfo_maxCapacity, storageInfo->mMaxCapacity); 2078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (storageInfo->mFreeSpaceBytes) 2088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetLongField(info, field_storageInfo_freeSpace, storageInfo->mFreeSpaceBytes); 2098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (storageInfo->mStorageDescription) 2108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_storageInfo_description, 2118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(storageInfo->mStorageDescription)); 2128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (storageInfo->mVolumeIdentifier) 2138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_storageInfo_volumeIdentifier, 2148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(storageInfo->mVolumeIdentifier)); 2158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete storageInfo; 2178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return info; 2188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 2198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jintArray 2218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object_handles(JNIEnv *env, jobject thiz, 2228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jint storageID, jint format, jint objectID) 2238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 2248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 2258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) 2268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 2278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpObjectHandleList* handles = device->getObjectHandles(storageID, format, objectID); 2288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!handles) 2298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 2308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood int length = handles->size(); 2328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jintArray array = env->NewIntArray(length); 2338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood // FIXME is this cast safe? 2348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntArrayRegion(array, 0, length, (const jint *)handles->array()); 2358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete handles; 2378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return array; 2388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 2398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject 2418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object_info(JNIEnv *env, jobject thiz, jint objectID) 2428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 2438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 2448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) 2458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 2468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpObjectInfo* objectInfo = device->getObjectInfo(objectID); 2478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!objectInfo) 2488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 2498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jobject info = env->NewObject(clazz_objectInfo, constructor_objectInfo); 2508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (info == NULL) { 2513762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Could not create a MtpObjectInfo object"); 2528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete objectInfo; 2538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 2548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 2558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mHandle) 2578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_handle, objectInfo->mHandle); 2588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mStorageID) 2598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_storageId, objectInfo->mStorageID); 2608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mFormat) 2618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_format, objectInfo->mFormat); 2628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mProtectionStatus) 2638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_protectionStatus, objectInfo->mProtectionStatus); 2648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mCompressedSize) 2658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_compressedSize, objectInfo->mCompressedSize); 2668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mThumbFormat) 2678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_thumbFormat, objectInfo->mThumbFormat); 2688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mThumbCompressedSize) 2698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_thumbCompressedSize, objectInfo->mThumbCompressedSize); 2708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mThumbPixWidth) 2718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_thumbPixWidth, objectInfo->mThumbPixWidth); 2728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mThumbPixHeight) 2738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_thumbPixHeight, objectInfo->mThumbPixHeight); 2748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mImagePixWidth) 2758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_imagePixWidth, objectInfo->mImagePixWidth); 2768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mImagePixHeight) 2778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_imagePixHeight, objectInfo->mImagePixHeight); 2788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mImagePixDepth) 2798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_imagePixDepth, objectInfo->mImagePixDepth); 2808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mParent) 2818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_parent, objectInfo->mParent); 2828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mAssociationType) 2838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_associationType, objectInfo->mAssociationType); 2848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mAssociationDesc) 2858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_associationDesc, objectInfo->mAssociationDesc); 2868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mSequenceNumber) 2878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetIntField(info, field_objectInfo_sequenceNumber, objectInfo->mSequenceNumber); 2888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mName) 2898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_objectInfo_name, env->NewStringUTF(objectInfo->mName)); 2908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mDateCreated) 291b966b9d9e882835691e5adda292d89dd704df71cMike Lockwood env->SetLongField(info, field_objectInfo_dateCreated, objectInfo->mDateCreated * 1000LL); 2928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mDateModified) 293b966b9d9e882835691e5adda292d89dd704df71cMike Lockwood env->SetLongField(info, field_objectInfo_dateModified, objectInfo->mDateModified * 1000LL); 2948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (objectInfo->mKeywords) 2958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetObjectField(info, field_objectInfo_keywords, 2968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->NewStringUTF(objectInfo->mKeywords)); 2978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 2988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood delete objectInfo; 2998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return info; 3008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstruct get_object_callback_data { 3038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood JNIEnv *env; 3048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jbyteArray array; 3058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}; 3068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic bool get_object_callback(void* data, int offset, int length, void* clientData) 3088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood get_object_callback_data* cbData = (get_object_callback_data *)clientData; 3108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood cbData->env->SetByteArrayRegion(cbData->array, offset, length, (jbyte *)data); 3118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return true; 3128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jbyteArray 3158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize) 3168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 3188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) 3198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 3208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jbyteArray array = env->NewByteArray(objectSize); 3228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!array) { 3238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jniThrowException(env, "java/lang/OutOfMemoryError", NULL); 3248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 3258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 3268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood get_object_callback_data data; 3288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood data.env = env; 3298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood data.array = array; 3308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device->readObject(objectID, get_object_callback, objectSize, &data)) 3328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return array; 3338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 3348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jbyteArray 3378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_thumbnail(JNIEnv *env, jobject thiz, jint objectID) 3388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 3408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (!device) 3418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 3428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood int length; 3448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood void* thumbnail = device->getThumbnail(objectID, length); 3458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (! thumbnail) 3468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 3478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jbyteArray array = env->NewByteArray(length); 3488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->SetByteArrayRegion(array, 0, length, (const jbyte *)thumbnail); 3498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood free(thumbnail); 3518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return array; 3528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean 3558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id) 3568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 3588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device) 3598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return device->deleteObject(object_id); 3608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood else 3618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return NULL; 3628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jlong 3658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_parent(JNIEnv *env, jobject thiz, jint object_id) 3668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 3688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device) 3698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return device->getParent(object_id); 3708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood else 3718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 3728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jlong 3758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_id(JNIEnv *env, jobject thiz, jint object_id) 3768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 3788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device) 3798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return device->getStorageID(object_id); 3808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood else 3818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 3828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 3838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 3848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean 3858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_import_file(JNIEnv *env, jobject thiz, jint object_id, jstring dest_path) 3868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 3878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood MtpDevice* device = get_device_from_object(env, thiz); 3888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (device) { 3898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood const char *destPathStr = env->GetStringUTFChars(dest_path, NULL); 3903977472d9f3380a8323156dbc7d0090cf2f2d310James Dong if (destPathStr == NULL) { 3913977472d9f3380a8323156dbc7d0090cf2f2d310James Dong return false; 3923977472d9f3380a8323156dbc7d0090cf2f2d310James Dong } 3933977472d9f3380a8323156dbc7d0090cf2f2d310James Dong 3948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664); 3958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood env->ReleaseStringUTFChars(dest_path, destPathStr); 3968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return result; 3978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 398c1b9bbb21c8ad5109978a4e9e770cd18b0257434Mike Lockwood 3993977472d9f3380a8323156dbc7d0090cf2f2d310James Dong return false; 4008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 4018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ---------------------------------------------------------------------------- 4038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic JNINativeMethod gMethods[] = { 4058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_open", "(Ljava/lang/String;I)Z", 4068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood (void *)android_mtp_MtpDevice_open}, 4078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_close", "()V", (void *)android_mtp_MtpDevice_close}, 4088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_device_info", "()Landroid/mtp/MtpDeviceInfo;", 4098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood (void *)android_mtp_MtpDevice_get_device_info}, 4108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_storage_ids", "()[I", (void *)android_mtp_MtpDevice_get_storage_ids}, 4118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_storage_info", "(I)Landroid/mtp/MtpStorageInfo;", 4128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood (void *)android_mtp_MtpDevice_get_storage_info}, 4138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_object_handles","(III)[I", 4148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood (void *)android_mtp_MtpDevice_get_object_handles}, 4158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_object_info", "(I)Landroid/mtp/MtpObjectInfo;", 4168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood (void *)android_mtp_MtpDevice_get_object_info}, 4178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_object", "(II)[B",(void *)android_mtp_MtpDevice_get_object}, 4188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_thumbnail", "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail}, 4198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_delete_object", "(I)Z", (void *)android_mtp_MtpDevice_delete_object}, 4208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_parent", "(I)J", (void *)android_mtp_MtpDevice_get_parent}, 4218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_get_storage_id", "(I)J", (void *)android_mtp_MtpDevice_get_storage_id}, 4228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood {"native_import_file", "(ILjava/lang/String;)Z", 4238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood (void *)android_mtp_MtpDevice_import_file}, 4248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}; 4258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic const char* const kClassPathName = "android/mtp/MtpDevice"; 4278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodint register_android_mtp_MtpDevice(JNIEnv *env) 4298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{ 4308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood jclass clazz; 4318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4325baa3a62a97544669fba6d65a11c07f252e654ddSteve Block ALOGD("register_android_mtp_MtpDevice\n"); 4338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood clazz = env->FindClass("android/mtp/MtpDeviceInfo"); 4358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (clazz == NULL) { 4363762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpDeviceInfo"); 4378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood constructor_deviceInfo = env->GetMethodID(clazz, "<init>", "()V"); 4408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (constructor_deviceInfo == NULL) { 4413762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpDeviceInfo constructor"); 4428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_deviceInfo_manufacturer = env->GetFieldID(clazz, "mManufacturer", "Ljava/lang/String;"); 4458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_deviceInfo_manufacturer == NULL) { 4463762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpDeviceInfo.mManufacturer"); 4478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_deviceInfo_model = env->GetFieldID(clazz, "mModel", "Ljava/lang/String;"); 4508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_deviceInfo_model == NULL) { 4513762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpDeviceInfo.mModel"); 4528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_deviceInfo_version = env->GetFieldID(clazz, "mVersion", "Ljava/lang/String;"); 4558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_deviceInfo_version == NULL) { 4563762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpDeviceInfo.mVersion"); 4578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_deviceInfo_serialNumber = env->GetFieldID(clazz, "mSerialNumber", "Ljava/lang/String;"); 4608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_deviceInfo_serialNumber == NULL) { 4613762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpDeviceInfo.mSerialNumber"); 4628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 46440304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood clazz_deviceInfo = (jclass)env->NewGlobalRef(clazz); 4658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 4668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood clazz = env->FindClass("android/mtp/MtpStorageInfo"); 4678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (clazz == NULL) { 4683762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpStorageInfo"); 4698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood constructor_storageInfo = env->GetMethodID(clazz, "<init>", "()V"); 4728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (constructor_storageInfo == NULL) { 4733762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpStorageInfo constructor"); 4748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_storageInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I"); 4778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_storageInfo_storageId == NULL) { 4783762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpStorageInfo.mStorageId"); 4798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_storageInfo_maxCapacity = env->GetFieldID(clazz, "mMaxCapacity", "J"); 4828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_storageInfo_maxCapacity == NULL) { 4833762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpStorageInfo.mMaxCapacity"); 4848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_storageInfo_freeSpace = env->GetFieldID(clazz, "mFreeSpace", "J"); 4878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_storageInfo_freeSpace == NULL) { 4883762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpStorageInfo.mFreeSpace"); 4898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_storageInfo_description = env->GetFieldID(clazz, "mDescription", "Ljava/lang/String;"); 4928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_storageInfo_description == NULL) { 4933762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpStorageInfo.mDescription"); 4948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 4958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 4968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_storageInfo_volumeIdentifier = env->GetFieldID(clazz, "mVolumeIdentifier", "Ljava/lang/String;"); 4978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_storageInfo_volumeIdentifier == NULL) { 4983762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpStorageInfo.mVolumeIdentifier"); 4998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 50140304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood clazz_storageInfo = (jclass)env->NewGlobalRef(clazz); 5028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 5038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood clazz = env->FindClass("android/mtp/MtpObjectInfo"); 5048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (clazz == NULL) { 5053762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpObjectInfo"); 5068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood constructor_objectInfo = env->GetMethodID(clazz, "<init>", "()V"); 5098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (constructor_objectInfo == NULL) { 5103762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpObjectInfo constructor"); 5118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_handle = env->GetFieldID(clazz, "mHandle", "I"); 5148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_handle == NULL) { 5153762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mHandle"); 5168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I"); 5198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_storageId == NULL) { 5203762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mStorageId"); 5218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_format = env->GetFieldID(clazz, "mFormat", "I"); 5248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_format == NULL) { 5253762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mFormat"); 5268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_protectionStatus = env->GetFieldID(clazz, "mProtectionStatus", "I"); 5298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_protectionStatus == NULL) { 5303762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mProtectionStatus"); 5318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_compressedSize = env->GetFieldID(clazz, "mCompressedSize", "I"); 5348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_compressedSize == NULL) { 5353762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mCompressedSize"); 5368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_thumbFormat = env->GetFieldID(clazz, "mThumbFormat", "I"); 5398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_thumbFormat == NULL) { 5403762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mThumbFormat"); 5418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_thumbCompressedSize = env->GetFieldID(clazz, "mThumbCompressedSize", "I"); 5448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_thumbCompressedSize == NULL) { 5453762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mThumbCompressedSize"); 5468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_thumbPixWidth = env->GetFieldID(clazz, "mThumbPixWidth", "I"); 5498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_thumbPixWidth == NULL) { 5503762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mThumbPixWidth"); 5518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_thumbPixHeight = env->GetFieldID(clazz, "mThumbPixHeight", "I"); 5548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_thumbPixHeight == NULL) { 5553762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mThumbPixHeight"); 5568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_imagePixWidth = env->GetFieldID(clazz, "mImagePixWidth", "I"); 5598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_imagePixWidth == NULL) { 5603762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mImagePixWidth"); 5618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_imagePixHeight = env->GetFieldID(clazz, "mImagePixHeight", "I"); 5648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_imagePixHeight == NULL) { 5653762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mImagePixHeight"); 5668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_imagePixDepth = env->GetFieldID(clazz, "mImagePixDepth", "I"); 5698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_imagePixDepth == NULL) { 5703762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mImagePixDepth"); 5718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_parent = env->GetFieldID(clazz, "mParent", "I"); 5748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_parent == NULL) { 5753762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mParent"); 5768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_associationType = env->GetFieldID(clazz, "mAssociationType", "I"); 5798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_associationType == NULL) { 5803762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mAssociationType"); 5818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_associationDesc = env->GetFieldID(clazz, "mAssociationDesc", "I"); 5848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_associationDesc == NULL) { 5853762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mAssociationDesc"); 5868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_sequenceNumber = env->GetFieldID(clazz, "mSequenceNumber", "I"); 5898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_sequenceNumber == NULL) { 5903762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mSequenceNumber"); 5918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_name = env->GetFieldID(clazz, "mName", "Ljava/lang/String;"); 5948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_name == NULL) { 5953762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mName"); 5968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 5978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 5988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_dateCreated = env->GetFieldID(clazz, "mDateCreated", "J"); 5998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_dateCreated == NULL) { 6003762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mDateCreated"); 6018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 6028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 6038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_dateModified = env->GetFieldID(clazz, "mDateModified", "J"); 6048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_dateModified == NULL) { 6053762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mDateModified"); 6068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 6078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 6088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_objectInfo_keywords = env->GetFieldID(clazz, "mKeywords", "Ljava/lang/String;"); 6098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_objectInfo_keywords == NULL) { 6103762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpObjectInfo.mKeywords"); 6118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 6128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 61340304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood clazz_objectInfo = (jclass)env->NewGlobalRef(clazz); 6148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 6158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood clazz = env->FindClass("android/mtp/MtpDevice"); 6168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (clazz == NULL) { 6173762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find android/mtp/MtpDevice"); 6188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 6198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 6208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood field_context = env->GetFieldID(clazz, "mNativeContext", "I"); 6218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood if (field_context == NULL) { 6223762c311729fe9f3af085c14c5c1fb471d994c03Steve Block ALOGE("Can't find MtpDevice.mNativeContext"); 6238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return -1; 6248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood } 6258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood 6268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood return AndroidRuntime::registerNativeMethods(env, 6278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood "android/mtp/MtpDevice", gMethods, NELEM(gMethods)); 6288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood} 629