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"
3187eac99a21772ae56018cb81db6966557b459554Ruben Brunk#include "android_runtime/Log.h"
328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "private/android_filesystem_config.h"
338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpTypes.h"
358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpDevice.h"
368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpDeviceInfo.h"
378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpStorageInfo.h"
388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood#include "MtpObjectInfo.h"
398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodusing namespace android;
418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ----------------------------------------------------------------------------
438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_context;
458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodjclass clazz_deviceInfo;
478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodjclass clazz_storageInfo;
488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodjclass clazz_objectInfo;
498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
508182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodjmethodID constructor_deviceInfo;
518182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodjmethodID constructor_storageInfo;
528182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodjmethodID constructor_objectInfo;
538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// MtpDeviceInfo fields
558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_manufacturer;
568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_model;
578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_version;
588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_deviceInfo_serialNumber;
598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// MtpStorageInfo fields
618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_storageId;
628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_maxCapacity;
638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_freeSpace;
648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_description;
658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_storageInfo_volumeIdentifier;
668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// MtpObjectInfo fields
688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_handle;
698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_storageId;
708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_format;
718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_protectionStatus;
728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_compressedSize;
738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbFormat;
748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbCompressedSize;
758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbPixWidth;
768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_thumbPixHeight;
778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_imagePixWidth;
788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_imagePixHeight;
798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_imagePixDepth;
808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_parent;
818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_associationType;
828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_associationDesc;
838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_sequenceNumber;
848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_name;
858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_dateCreated;
868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_dateModified;
878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jfieldID field_objectInfo_keywords;
888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
898182e72479a8b0d832df9c392890b25bfa6f97b5Mike LockwoodMtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice)
908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
91e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    return (MtpDevice*)env->GetLongField(javaDevice, field_context);
928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (env->ExceptionCheck()) {
963762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("An exception was thrown by callback '%s'.", methodName);
978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        LOGE_EX(env);
988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->ExceptionClear();
998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ----------------------------------------------------------------------------
1038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean
1058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_open(JNIEnv *env, jobject thiz, jstring deviceName, jint fd)
1068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
1083977472d9f3380a8323156dbc7d0090cf2f2d310James Dong    if (deviceNameStr == NULL) {
109e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return JNI_FALSE;
1103977472d9f3380a8323156dbc7d0090cf2f2d310James Dong    }
1113977472d9f3380a8323156dbc7d0090cf2f2d310James Dong
1128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
1138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->ReleaseStringUTFChars(deviceName, deviceNameStr);
1148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device)
116e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        env->SetLongField(thiz, field_context,  (jlong)device);
117e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    return (jboolean)(device != NULL);
1188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic void
1218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_close(JNIEnv *env, jobject thiz)
1228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device) {
1258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        device->close();
1268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete device;
127e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        env->SetLongField(thiz, field_context, 0);
1288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject
1328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz)
1338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device) {
1365baa3a62a97544669fba6d65a11c07f252e654ddSteve Block        ALOGD("android_mtp_MtpDevice_get_device_info device is null");
1378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDeviceInfo* deviceInfo = device->getDeviceInfo();
1408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!deviceInfo) {
1415baa3a62a97544669fba6d65a11c07f252e654ddSteve Block        ALOGD("android_mtp_MtpDevice_get_device_info deviceInfo is null");
1428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jobject info = env->NewObject(clazz_deviceInfo, constructor_deviceInfo);
1458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (info == NULL) {
1463762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Could not create a MtpDeviceInfo object");
1478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete deviceInfo;
1488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mManufacturer)
1528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_manufacturer,
1538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mManufacturer));
1548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mModel)
1558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_model,
1568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mModel));
1578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mVersion)
1588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_version,
1598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mVersion));
1608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mSerial)
1618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_serialNumber,
1628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mSerial));
1638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete deviceInfo;
1658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return info;
1668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jintArray
1698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_ids(JNIEnv *env, jobject thiz)
1708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
1738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpStorageIDList* storageIDs = device->getStorageIDs();
1758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!storageIDs)
1768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    int length = storageIDs->size();
1798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jintArray array = env->NewIntArray(length);
1808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    // FIXME is this cast safe?
1818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->SetIntArrayRegion(array, 0, length, (const jint *)storageIDs->array());
1828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete storageIDs;
1848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return array;
1858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject
1888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_info(JNIEnv *env, jobject thiz, jint storageID)
1898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
1928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpStorageInfo* storageInfo = device->getStorageInfo(storageID);
1948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!storageInfo)
1958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jobject info = env->NewObject(clazz_storageInfo, constructor_storageInfo);
1988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (info == NULL) {
1993762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Could not create a MtpStorageInfo object");
2008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete storageInfo;
2018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mStorageID)
2058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_storageInfo_storageId, storageInfo->mStorageID);
2068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mMaxCapacity)
2078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetLongField(info, field_storageInfo_maxCapacity, storageInfo->mMaxCapacity);
2088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mFreeSpaceBytes)
2098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetLongField(info, field_storageInfo_freeSpace, storageInfo->mFreeSpaceBytes);
2108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mStorageDescription)
2118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_storageInfo_description,
2128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(storageInfo->mStorageDescription));
2138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mVolumeIdentifier)
2148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_storageInfo_volumeIdentifier,
2158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(storageInfo->mVolumeIdentifier));
2168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete storageInfo;
2188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return info;
2198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
2208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jintArray
2228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object_handles(JNIEnv *env, jobject thiz,
2238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        jint storageID, jint format, jint objectID)
2248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
2258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
2268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
2278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpObjectHandleList* handles = device->getObjectHandles(storageID, format, objectID);
2298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!handles)
2308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    int length = handles->size();
2338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jintArray array = env->NewIntArray(length);
2348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    // FIXME is this cast safe?
2358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->SetIntArrayRegion(array, 0, length, (const jint *)handles->array());
2368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete handles;
2388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return array;
2398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
2408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject
2428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object_info(JNIEnv *env, jobject thiz, jint objectID)
2438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
2448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
2458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
2468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpObjectInfo* objectInfo = device->getObjectInfo(objectID);
2488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!objectInfo)
2498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jobject info = env->NewObject(clazz_objectInfo, constructor_objectInfo);
2518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (info == NULL) {
2523762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Could not create a MtpObjectInfo object");
2538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete objectInfo;
2548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mHandle)
2588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_handle, objectInfo->mHandle);
2598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mStorageID)
2608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_storageId, objectInfo->mStorageID);
2618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mFormat)
2628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_format, objectInfo->mFormat);
2638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mProtectionStatus)
2648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_protectionStatus, objectInfo->mProtectionStatus);
2658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mCompressedSize)
2668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_compressedSize, objectInfo->mCompressedSize);
2678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbFormat)
2688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbFormat, objectInfo->mThumbFormat);
2698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbCompressedSize)
2708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbCompressedSize, objectInfo->mThumbCompressedSize);
2718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbPixWidth)
2728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbPixWidth, objectInfo->mThumbPixWidth);
2738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbPixHeight)
2748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbPixHeight, objectInfo->mThumbPixHeight);
2758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mImagePixWidth)
2768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_imagePixWidth, objectInfo->mImagePixWidth);
2778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mImagePixHeight)
2788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_imagePixHeight, objectInfo->mImagePixHeight);
2798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mImagePixDepth)
2808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_imagePixDepth, objectInfo->mImagePixDepth);
2818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mParent)
2828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_parent, objectInfo->mParent);
2838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mAssociationType)
2848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_associationType, objectInfo->mAssociationType);
2858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mAssociationDesc)
2868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_associationDesc, objectInfo->mAssociationDesc);
2878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mSequenceNumber)
2888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_sequenceNumber, objectInfo->mSequenceNumber);
2898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mName)
2908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_objectInfo_name, env->NewStringUTF(objectInfo->mName));
2918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mDateCreated)
292b966b9d9e882835691e5adda292d89dd704df71cMike Lockwood        env->SetLongField(info, field_objectInfo_dateCreated, objectInfo->mDateCreated * 1000LL);
2938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mDateModified)
294b966b9d9e882835691e5adda292d89dd704df71cMike Lockwood        env->SetLongField(info, field_objectInfo_dateModified, objectInfo->mDateModified * 1000LL);
2958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mKeywords)
2968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_objectInfo_keywords,
2978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(objectInfo->mKeywords));
2988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete objectInfo;
3008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return info;
3018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstruct get_object_callback_data {
3048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    JNIEnv *env;
3058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jbyteArray array;
3068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood};
3078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic bool get_object_callback(void* data, int offset, int length, void* clientData)
3098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    get_object_callback_data* cbData = (get_object_callback_data *)clientData;
3118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    cbData->env->SetByteArrayRegion(cbData->array, offset, length, (jbyte *)data);
3128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return true;
3138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jbyteArray
3168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize)
3178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
3208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jbyteArray array = env->NewByteArray(objectSize);
3238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!array) {
3248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
3258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
3278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    get_object_callback_data data;
3298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    data.env = env;
3308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    data.array = array;
3318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device->readObject(objectID, get_object_callback, objectSize, &data))
3338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return array;
3348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return NULL;
3358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jbyteArray
3388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_thumbnail(JNIEnv *env, jobject thiz, jint objectID)
3398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
3428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    int length;
3458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    void* thumbnail = device->getThumbnail(objectID, length);
3468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (! thumbnail)
3478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jbyteArray array = env->NewByteArray(length);
3498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->SetByteArrayRegion(array, 0, length, (const jbyte *)thumbnail);
3508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    free(thumbnail);
3528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return array;
3538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean
3568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id)
3578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
359e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    if (device && device->deleteObject(object_id)) {
360e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return JNI_TRUE;
361e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    } else {
362e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return JNI_FALSE;
363e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    }
3648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jlong
3678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_parent(JNIEnv *env, jobject thiz, jint object_id)
3688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device)
371e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return (jlong)device->getParent(object_id);
3728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    else
3738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
3748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jlong
3778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_id(JNIEnv *env, jobject thiz, jint object_id)
3788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device)
381e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return (jlong)device->getStorageID(object_id);
3828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    else
3838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
3848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean
3878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_import_file(JNIEnv *env, jobject thiz, jint object_id, jstring dest_path)
3888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device) {
3918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
3923977472d9f3380a8323156dbc7d0090cf2f2d310James Dong        if (destPathStr == NULL) {
393e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat            return JNI_FALSE;
3943977472d9f3380a8323156dbc7d0090cf2f2d310James Dong        }
3953977472d9f3380a8323156dbc7d0090cf2f2d310James Dong
396e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        jboolean result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
3978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->ReleaseStringUTFChars(dest_path, destPathStr);
3988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return result;
3998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
400c1b9bbb21c8ad5109978a4e9e770cd18b0257434Mike Lockwood
401e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    return JNI_FALSE;
4028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
4038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ----------------------------------------------------------------------------
4058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic JNINativeMethod gMethods[] = {
4078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_open",             "(Ljava/lang/String;I)Z",
4088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_open},
4098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_close",            "()V",  (void *)android_mtp_MtpDevice_close},
4108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_device_info",  "()Landroid/mtp/MtpDeviceInfo;",
4118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_device_info},
4128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_storage_ids",  "()[I", (void *)android_mtp_MtpDevice_get_storage_ids},
4138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_storage_info", "(I)Landroid/mtp/MtpStorageInfo;",
4148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_storage_info},
4158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_object_handles","(III)[I",
4168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_object_handles},
4178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_object_info",  "(I)Landroid/mtp/MtpObjectInfo;",
4188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_object_info},
4198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_object",       "(II)[B",(void *)android_mtp_MtpDevice_get_object},
4208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_thumbnail",    "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail},
4218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_delete_object",    "(I)Z", (void *)android_mtp_MtpDevice_delete_object},
4228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_parent",       "(I)J", (void *)android_mtp_MtpDevice_get_parent},
4238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_storage_id",   "(I)J", (void *)android_mtp_MtpDevice_get_storage_id},
4248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_import_file",     "(ILjava/lang/String;)Z",
4258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_import_file},
4268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood};
4278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic const char* const kClassPathName = "android/mtp/MtpDevice";
4298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodint register_android_mtp_MtpDevice(JNIEnv *env)
4318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
4328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jclass clazz;
4338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4345baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    ALOGD("register_android_mtp_MtpDevice\n");
4358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpDeviceInfo");
4378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
4383762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpDeviceInfo");
4398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    constructor_deviceInfo = env->GetMethodID(clazz, "<init>", "()V");
4428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (constructor_deviceInfo == NULL) {
4433762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpDeviceInfo constructor");
4448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_manufacturer = env->GetFieldID(clazz, "mManufacturer", "Ljava/lang/String;");
4478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_manufacturer == NULL) {
4483762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mManufacturer");
4498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_model = env->GetFieldID(clazz, "mModel", "Ljava/lang/String;");
4528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_model == NULL) {
4533762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mModel");
4548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_version = env->GetFieldID(clazz, "mVersion", "Ljava/lang/String;");
4578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_version == NULL) {
4583762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mVersion");
4598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_serialNumber = env->GetFieldID(clazz, "mSerialNumber", "Ljava/lang/String;");
4628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_serialNumber == NULL) {
4633762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mSerialNumber");
4648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
46640304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood    clazz_deviceInfo = (jclass)env->NewGlobalRef(clazz);
4678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpStorageInfo");
4698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
4703762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpStorageInfo");
4718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    constructor_storageInfo = env->GetMethodID(clazz, "<init>", "()V");
4748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (constructor_storageInfo == NULL) {
4753762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpStorageInfo constructor");
4768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I");
4798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_storageId == NULL) {
4803762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mStorageId");
4818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_maxCapacity = env->GetFieldID(clazz, "mMaxCapacity", "J");
4848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_maxCapacity == NULL) {
4853762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mMaxCapacity");
4868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_freeSpace = env->GetFieldID(clazz, "mFreeSpace", "J");
4898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_freeSpace == NULL) {
4903762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mFreeSpace");
4918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_description = env->GetFieldID(clazz, "mDescription", "Ljava/lang/String;");
4948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_description == NULL) {
4953762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mDescription");
4968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_volumeIdentifier = env->GetFieldID(clazz, "mVolumeIdentifier", "Ljava/lang/String;");
4998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_volumeIdentifier == NULL) {
5003762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mVolumeIdentifier");
5018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
50340304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood    clazz_storageInfo = (jclass)env->NewGlobalRef(clazz);
5048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
5058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpObjectInfo");
5068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
5073762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpObjectInfo");
5088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    constructor_objectInfo = env->GetMethodID(clazz, "<init>", "()V");
5118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (constructor_objectInfo == NULL) {
5123762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpObjectInfo constructor");
5138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_handle = env->GetFieldID(clazz, "mHandle", "I");
5168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_handle == NULL) {
5173762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mHandle");
5188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I");
5218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_storageId == NULL) {
5223762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mStorageId");
5238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_format = env->GetFieldID(clazz, "mFormat", "I");
5268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_format == NULL) {
5273762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mFormat");
5288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_protectionStatus = env->GetFieldID(clazz, "mProtectionStatus", "I");
5318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_protectionStatus == NULL) {
5323762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mProtectionStatus");
5338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_compressedSize = env->GetFieldID(clazz, "mCompressedSize", "I");
5368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_compressedSize == NULL) {
5373762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mCompressedSize");
5388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbFormat = env->GetFieldID(clazz, "mThumbFormat", "I");
5418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbFormat == NULL) {
5423762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbFormat");
5438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbCompressedSize = env->GetFieldID(clazz, "mThumbCompressedSize", "I");
5468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbCompressedSize == NULL) {
5473762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbCompressedSize");
5488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbPixWidth = env->GetFieldID(clazz, "mThumbPixWidth", "I");
5518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbPixWidth == NULL) {
5523762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbPixWidth");
5538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbPixHeight = env->GetFieldID(clazz, "mThumbPixHeight", "I");
5568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbPixHeight == NULL) {
5573762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbPixHeight");
5588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_imagePixWidth = env->GetFieldID(clazz, "mImagePixWidth", "I");
5618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_imagePixWidth == NULL) {
5623762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mImagePixWidth");
5638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_imagePixHeight = env->GetFieldID(clazz, "mImagePixHeight", "I");
5668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_imagePixHeight == NULL) {
5673762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mImagePixHeight");
5688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_imagePixDepth = env->GetFieldID(clazz, "mImagePixDepth", "I");
5718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_imagePixDepth == NULL) {
5723762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mImagePixDepth");
5738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_parent = env->GetFieldID(clazz, "mParent", "I");
5768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_parent == NULL) {
5773762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mParent");
5788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_associationType = env->GetFieldID(clazz, "mAssociationType", "I");
5818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_associationType == NULL) {
5823762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mAssociationType");
5838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_associationDesc = env->GetFieldID(clazz, "mAssociationDesc", "I");
5868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_associationDesc == NULL) {
5873762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mAssociationDesc");
5888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_sequenceNumber = env->GetFieldID(clazz, "mSequenceNumber", "I");
5918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_sequenceNumber == NULL) {
5923762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mSequenceNumber");
5938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_name = env->GetFieldID(clazz, "mName", "Ljava/lang/String;");
5968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_name == NULL) {
5973762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mName");
5988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
6008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_dateCreated = env->GetFieldID(clazz, "mDateCreated", "J");
6018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_dateCreated == NULL) {
6023762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mDateCreated");
6038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
6058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_dateModified = env->GetFieldID(clazz, "mDateModified", "J");
6068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_dateModified == NULL) {
6073762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mDateModified");
6088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
6108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_keywords = env->GetFieldID(clazz, "mKeywords", "Ljava/lang/String;");
6118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_keywords == NULL) {
6123762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mKeywords");
6138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
61540304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood    clazz_objectInfo = (jclass)env->NewGlobalRef(clazz);
6168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
6178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpDevice");
6188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
6193762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpDevice");
6208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
622e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
6238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_context == NULL) {
6243762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDevice.mNativeContext");
6258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
6278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
6288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return AndroidRuntime::registerNativeMethods(env,
6298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                "android/mtp/MtpDevice", gMethods, NELEM(gMethods));
6308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
631