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 Lockwood// ----------------------------------------------------------------------------
958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean
978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_open(JNIEnv *env, jobject thiz, jstring deviceName, jint fd)
988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
1003977472d9f3380a8323156dbc7d0090cf2f2d310James Dong    if (deviceNameStr == NULL) {
101e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return JNI_FALSE;
1023977472d9f3380a8323156dbc7d0090cf2f2d310James Dong    }
1033977472d9f3380a8323156dbc7d0090cf2f2d310James Dong
1048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
1058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->ReleaseStringUTFChars(deviceName, deviceNameStr);
1068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device)
108e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        env->SetLongField(thiz, field_context,  (jlong)device);
109e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    return (jboolean)(device != NULL);
1108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic void
1138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_close(JNIEnv *env, jobject thiz)
1148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device) {
1178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        device->close();
1188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete device;
119e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        env->SetLongField(thiz, field_context, 0);
1208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject
1248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz)
1258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device) {
1285baa3a62a97544669fba6d65a11c07f252e654ddSteve Block        ALOGD("android_mtp_MtpDevice_get_device_info device is null");
1298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDeviceInfo* deviceInfo = device->getDeviceInfo();
1328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!deviceInfo) {
1335baa3a62a97544669fba6d65a11c07f252e654ddSteve Block        ALOGD("android_mtp_MtpDevice_get_device_info deviceInfo is null");
1348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jobject info = env->NewObject(clazz_deviceInfo, constructor_deviceInfo);
1378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (info == NULL) {
1383762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Could not create a MtpDeviceInfo object");
1398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete deviceInfo;
1408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mManufacturer)
1448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_manufacturer,
1458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mManufacturer));
1468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mModel)
1478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_model,
1488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mModel));
1498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mVersion)
1508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_version,
1518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mVersion));
1528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (deviceInfo->mSerial)
1538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_deviceInfo_serialNumber,
1548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(deviceInfo->mSerial));
1558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete deviceInfo;
1578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return info;
1588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jintArray
1618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_ids(JNIEnv *env, jobject thiz)
1628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
1658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpStorageIDList* storageIDs = device->getStorageIDs();
1678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!storageIDs)
1688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    int length = storageIDs->size();
1718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jintArray array = env->NewIntArray(length);
1728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    // FIXME is this cast safe?
1738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->SetIntArrayRegion(array, 0, length, (const jint *)storageIDs->array());
1748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete storageIDs;
1768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return array;
1778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
1788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject
1808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_info(JNIEnv *env, jobject thiz, jint storageID)
1818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
1828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
1838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
1848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpStorageInfo* storageInfo = device->getStorageInfo(storageID);
1868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!storageInfo)
1878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jobject info = env->NewObject(clazz_storageInfo, constructor_storageInfo);
1908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (info == NULL) {
1913762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Could not create a MtpStorageInfo object");
1928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete storageInfo;
1938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
1948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mStorageID)
1978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_storageInfo_storageId, storageInfo->mStorageID);
1988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mMaxCapacity)
1998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetLongField(info, field_storageInfo_maxCapacity, storageInfo->mMaxCapacity);
2008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mFreeSpaceBytes)
2018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetLongField(info, field_storageInfo_freeSpace, storageInfo->mFreeSpaceBytes);
2028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mStorageDescription)
2038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_storageInfo_description,
2048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(storageInfo->mStorageDescription));
2058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (storageInfo->mVolumeIdentifier)
2068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_storageInfo_volumeIdentifier,
2078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(storageInfo->mVolumeIdentifier));
2088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete storageInfo;
2108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return info;
2118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
2128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jintArray
2148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object_handles(JNIEnv *env, jobject thiz,
2158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        jint storageID, jint format, jint objectID)
2168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
2178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
2188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
2198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpObjectHandleList* handles = device->getObjectHandles(storageID, format, objectID);
2218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!handles)
2228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    int length = handles->size();
2258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jintArray array = env->NewIntArray(length);
2268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    // FIXME is this cast safe?
2278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->SetIntArrayRegion(array, 0, length, (const jint *)handles->array());
2288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete handles;
2308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return array;
2318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
2328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jobject
2348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object_info(JNIEnv *env, jobject thiz, jint objectID)
2358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
2368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
2378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
2388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpObjectInfo* objectInfo = device->getObjectInfo(objectID);
2408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!objectInfo)
2418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jobject info = env->NewObject(clazz_objectInfo, constructor_objectInfo);
2438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (info == NULL) {
2443762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Could not create a MtpObjectInfo object");
2458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        delete objectInfo;
2468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
2478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mHandle)
2508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_handle, objectInfo->mHandle);
2518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mStorageID)
2528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_storageId, objectInfo->mStorageID);
2538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mFormat)
2548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_format, objectInfo->mFormat);
2558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mProtectionStatus)
2568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_protectionStatus, objectInfo->mProtectionStatus);
2578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mCompressedSize)
2588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_compressedSize, objectInfo->mCompressedSize);
2598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbFormat)
2608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbFormat, objectInfo->mThumbFormat);
2618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbCompressedSize)
2628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbCompressedSize, objectInfo->mThumbCompressedSize);
2638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbPixWidth)
2648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbPixWidth, objectInfo->mThumbPixWidth);
2658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mThumbPixHeight)
2668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_thumbPixHeight, objectInfo->mThumbPixHeight);
2678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mImagePixWidth)
2688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_imagePixWidth, objectInfo->mImagePixWidth);
2698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mImagePixHeight)
2708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_imagePixHeight, objectInfo->mImagePixHeight);
2718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mImagePixDepth)
2728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_imagePixDepth, objectInfo->mImagePixDepth);
2738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mParent)
2748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_parent, objectInfo->mParent);
2758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mAssociationType)
2768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_associationType, objectInfo->mAssociationType);
2778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mAssociationDesc)
2788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_associationDesc, objectInfo->mAssociationDesc);
2798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mSequenceNumber)
2808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetIntField(info, field_objectInfo_sequenceNumber, objectInfo->mSequenceNumber);
2818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mName)
2828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_objectInfo_name, env->NewStringUTF(objectInfo->mName));
2838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mDateCreated)
284b966b9d9e882835691e5adda292d89dd704df71cMike Lockwood        env->SetLongField(info, field_objectInfo_dateCreated, objectInfo->mDateCreated * 1000LL);
2858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mDateModified)
286b966b9d9e882835691e5adda292d89dd704df71cMike Lockwood        env->SetLongField(info, field_objectInfo_dateModified, objectInfo->mDateModified * 1000LL);
2878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (objectInfo->mKeywords)
2888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->SetObjectField(info, field_objectInfo_keywords,
2898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            env->NewStringUTF(objectInfo->mKeywords));
2908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    delete objectInfo;
2928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return info;
2938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
2948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstruct get_object_callback_data {
2968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    JNIEnv *env;
2978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jbyteArray array;
2988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood};
2998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic bool get_object_callback(void* data, int offset, int length, void* clientData)
3018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    get_object_callback_data* cbData = (get_object_callback_data *)clientData;
3038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    cbData->env->SetByteArrayRegion(cbData->array, offset, length, (jbyte *)data);
3048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return true;
3058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jbyteArray
3088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize)
3098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
3128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jbyteArray array = env->NewByteArray(objectSize);
3158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!array) {
3168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
3178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
3198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    get_object_callback_data data;
3218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    data.env = env;
3228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    data.array = array;
3238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device->readObject(objectID, get_object_callback, objectSize, &data))
3258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return array;
3268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return NULL;
3278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jbyteArray
3308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_thumbnail(JNIEnv *env, jobject thiz, jint objectID)
3318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (!device)
3348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    int length;
3378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    void* thumbnail = device->getThumbnail(objectID, length);
3388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (! thumbnail)
3398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return NULL;
3408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jbyteArray array = env->NewByteArray(length);
3418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    env->SetByteArrayRegion(array, 0, length, (const jbyte *)thumbnail);
3428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    free(thumbnail);
3448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return array;
3458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean
3488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id)
3498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
351e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    if (device && device->deleteObject(object_id)) {
352e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return JNI_TRUE;
353e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    } else {
354e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return JNI_FALSE;
355e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    }
3568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jlong
3598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_parent(JNIEnv *env, jobject thiz, jint object_id)
3608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device)
363e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return (jlong)device->getParent(object_id);
3648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    else
3658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
3668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jlong
3698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_get_storage_id(JNIEnv *env, jobject thiz, jint object_id)
3708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device)
373e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        return (jlong)device->getStorageID(object_id);
3748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    else
3758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
3768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic jboolean
3798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodandroid_mtp_MtpDevice_import_file(JNIEnv *env, jobject thiz, jint object_id, jstring dest_path)
3808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
3818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    MtpDevice* device = get_device_from_object(env, thiz);
3828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (device) {
3838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
3843977472d9f3380a8323156dbc7d0090cf2f2d310James Dong        if (destPathStr == NULL) {
385e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat            return JNI_FALSE;
3863977472d9f3380a8323156dbc7d0090cf2f2d310James Dong        }
3873977472d9f3380a8323156dbc7d0090cf2f2d310James Dong
388e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat        jboolean result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
3898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        env->ReleaseStringUTFChars(dest_path, destPathStr);
3908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return result;
3918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
392c1b9bbb21c8ad5109978a4e9e770cd18b0257434Mike Lockwood
393e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    return JNI_FALSE;
3948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
3958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood// ----------------------------------------------------------------------------
3978182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
3988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodstatic JNINativeMethod gMethods[] = {
3998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_open",             "(Ljava/lang/String;I)Z",
4008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_open},
4018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_close",            "()V",  (void *)android_mtp_MtpDevice_close},
4028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_device_info",  "()Landroid/mtp/MtpDeviceInfo;",
4038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_device_info},
4048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_storage_ids",  "()[I", (void *)android_mtp_MtpDevice_get_storage_ids},
4058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_storage_info", "(I)Landroid/mtp/MtpStorageInfo;",
4068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_storage_info},
4078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_object_handles","(III)[I",
4088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_object_handles},
4098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_object_info",  "(I)Landroid/mtp/MtpObjectInfo;",
4108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_get_object_info},
4118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_object",       "(II)[B",(void *)android_mtp_MtpDevice_get_object},
4128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_thumbnail",    "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail},
4138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_delete_object",    "(I)Z", (void *)android_mtp_MtpDevice_delete_object},
4148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_parent",       "(I)J", (void *)android_mtp_MtpDevice_get_parent},
4158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_get_storage_id",   "(I)J", (void *)android_mtp_MtpDevice_get_storage_id},
4168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    {"native_import_file",     "(ILjava/lang/String;)Z",
4178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                                        (void *)android_mtp_MtpDevice_import_file},
4188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood};
4198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodint register_android_mtp_MtpDevice(JNIEnv *env)
4218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood{
4228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    jclass clazz;
4238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4245baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    ALOGD("register_android_mtp_MtpDevice\n");
4258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpDeviceInfo");
4278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
4283762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpDeviceInfo");
4298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    constructor_deviceInfo = env->GetMethodID(clazz, "<init>", "()V");
4328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (constructor_deviceInfo == NULL) {
4333762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpDeviceInfo constructor");
4348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_manufacturer = env->GetFieldID(clazz, "mManufacturer", "Ljava/lang/String;");
4378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_manufacturer == NULL) {
4383762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mManufacturer");
4398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_model = env->GetFieldID(clazz, "mModel", "Ljava/lang/String;");
4428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_model == NULL) {
4433762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mModel");
4448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_version = env->GetFieldID(clazz, "mVersion", "Ljava/lang/String;");
4478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_version == NULL) {
4483762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mVersion");
4498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_deviceInfo_serialNumber = env->GetFieldID(clazz, "mSerialNumber", "Ljava/lang/String;");
4528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_deviceInfo_serialNumber == NULL) {
4533762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDeviceInfo.mSerialNumber");
4548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
45640304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood    clazz_deviceInfo = (jclass)env->NewGlobalRef(clazz);
4578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpStorageInfo");
4598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
4603762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpStorageInfo");
4618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    constructor_storageInfo = env->GetMethodID(clazz, "<init>", "()V");
4648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (constructor_storageInfo == NULL) {
4653762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpStorageInfo constructor");
4668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4678182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I");
4698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_storageId == NULL) {
4703762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mStorageId");
4718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_maxCapacity = env->GetFieldID(clazz, "mMaxCapacity", "J");
4748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_maxCapacity == NULL) {
4753762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mMaxCapacity");
4768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_freeSpace = env->GetFieldID(clazz, "mFreeSpace", "J");
4798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_freeSpace == NULL) {
4803762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mFreeSpace");
4818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_description = env->GetFieldID(clazz, "mDescription", "Ljava/lang/String;");
4848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_description == NULL) {
4853762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mDescription");
4868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4878182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
4888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_storageInfo_volumeIdentifier = env->GetFieldID(clazz, "mVolumeIdentifier", "Ljava/lang/String;");
4898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_storageInfo_volumeIdentifier == NULL) {
4903762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpStorageInfo.mVolumeIdentifier");
4918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
49340304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood    clazz_storageInfo = (jclass)env->NewGlobalRef(clazz);
4948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
4958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpObjectInfo");
4968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
4973762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpObjectInfo");
4988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
4998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    constructor_objectInfo = env->GetMethodID(clazz, "<init>", "()V");
5018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (constructor_objectInfo == NULL) {
5023762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpObjectInfo constructor");
5038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_handle = env->GetFieldID(clazz, "mHandle", "I");
5068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_handle == NULL) {
5073762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mHandle");
5088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I");
5118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_storageId == NULL) {
5123762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mStorageId");
5138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_format = env->GetFieldID(clazz, "mFormat", "I");
5168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_format == NULL) {
5173762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mFormat");
5188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_protectionStatus = env->GetFieldID(clazz, "mProtectionStatus", "I");
5218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_protectionStatus == NULL) {
5223762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mProtectionStatus");
5238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5258182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_compressedSize = env->GetFieldID(clazz, "mCompressedSize", "I");
5268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_compressedSize == NULL) {
5273762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mCompressedSize");
5288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbFormat = env->GetFieldID(clazz, "mThumbFormat", "I");
5318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbFormat == NULL) {
5323762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbFormat");
5338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbCompressedSize = env->GetFieldID(clazz, "mThumbCompressedSize", "I");
5368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbCompressedSize == NULL) {
5373762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbCompressedSize");
5388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbPixWidth = env->GetFieldID(clazz, "mThumbPixWidth", "I");
5418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbPixWidth == NULL) {
5423762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbPixWidth");
5438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_thumbPixHeight = env->GetFieldID(clazz, "mThumbPixHeight", "I");
5468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_thumbPixHeight == NULL) {
5473762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mThumbPixHeight");
5488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_imagePixWidth = env->GetFieldID(clazz, "mImagePixWidth", "I");
5518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_imagePixWidth == NULL) {
5523762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mImagePixWidth");
5538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_imagePixHeight = env->GetFieldID(clazz, "mImagePixHeight", "I");
5568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_imagePixHeight == NULL) {
5573762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mImagePixHeight");
5588182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5598182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5608182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_imagePixDepth = env->GetFieldID(clazz, "mImagePixDepth", "I");
5618182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_imagePixDepth == NULL) {
5623762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mImagePixDepth");
5638182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_parent = env->GetFieldID(clazz, "mParent", "I");
5668182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_parent == NULL) {
5673762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mParent");
5688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_associationType = env->GetFieldID(clazz, "mAssociationType", "I");
5718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_associationType == NULL) {
5723762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mAssociationType");
5738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_associationDesc = env->GetFieldID(clazz, "mAssociationDesc", "I");
5768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_associationDesc == NULL) {
5773762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mAssociationDesc");
5788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_sequenceNumber = env->GetFieldID(clazz, "mSequenceNumber", "I");
5818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_sequenceNumber == NULL) {
5823762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mSequenceNumber");
5838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5848182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5858182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_name = env->GetFieldID(clazz, "mName", "Ljava/lang/String;");
5868182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_name == NULL) {
5873762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mName");
5888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_dateCreated = env->GetFieldID(clazz, "mDateCreated", "J");
5918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_dateCreated == NULL) {
5923762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mDateCreated");
5938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
5958182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_dateModified = env->GetFieldID(clazz, "mDateModified", "J");
5968182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_dateModified == NULL) {
5973762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mDateModified");
5988182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
5998182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
6008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    field_objectInfo_keywords = env->GetFieldID(clazz, "mKeywords", "Ljava/lang/String;");
6018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_objectInfo_keywords == NULL) {
6023762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpObjectInfo.mKeywords");
6038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
60540304e227247c788d1c0e8d41c386cdb10cba91bMike Lockwood    clazz_objectInfo = (jclass)env->NewGlobalRef(clazz);
6068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
6078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    clazz = env->FindClass("android/mtp/MtpDevice");
6088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (clazz == NULL) {
6093762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find android/mtp/MtpDevice");
6108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
612e2e59326f13cf291bf5b37989390fd2a55a94f0cAshok Bhat    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
6138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    if (field_context == NULL) {
6143762c311729fe9f3af085c14c5c1fb471d994c03Steve Block        ALOGE("Can't find MtpDevice.mNativeContext");
6158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return -1;
6168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
6178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
6188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    return AndroidRuntime::registerNativeMethods(env,
6198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood                "android/mtp/MtpDevice", gMethods, NELEM(gMethods));
6208182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
621