Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // #define LOG_NDEBUG 0 |
| 18 | |
| 19 | #define LOG_TAG "MtpDeviceJNI" |
| 20 | #include "utils/Log.h" |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <assert.h> |
| 24 | #include <limits.h> |
| 25 | #include <unistd.h> |
| 26 | #include <fcntl.h> |
| 27 | |
| 28 | #include "jni.h" |
| 29 | #include "JNIHelp.h" |
| 30 | #include "android_runtime/AndroidRuntime.h" |
| 31 | #include "private/android_filesystem_config.h" |
| 32 | |
| 33 | #include "MtpTypes.h" |
| 34 | #include "MtpDevice.h" |
| 35 | #include "MtpDeviceInfo.h" |
| 36 | #include "MtpStorageInfo.h" |
| 37 | #include "MtpObjectInfo.h" |
| 38 | |
| 39 | using namespace android; |
| 40 | |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | |
| 43 | static jfieldID field_context; |
| 44 | |
| 45 | jclass clazz_deviceInfo; |
| 46 | jclass clazz_storageInfo; |
| 47 | jclass clazz_objectInfo; |
| 48 | |
| 49 | jmethodID constructor_deviceInfo; |
| 50 | jmethodID constructor_storageInfo; |
| 51 | jmethodID constructor_objectInfo; |
| 52 | |
| 53 | // MtpDeviceInfo fields |
| 54 | static jfieldID field_deviceInfo_manufacturer; |
| 55 | static jfieldID field_deviceInfo_model; |
| 56 | static jfieldID field_deviceInfo_version; |
| 57 | static jfieldID field_deviceInfo_serialNumber; |
| 58 | |
| 59 | // MtpStorageInfo fields |
| 60 | static jfieldID field_storageInfo_storageId; |
| 61 | static jfieldID field_storageInfo_maxCapacity; |
| 62 | static jfieldID field_storageInfo_freeSpace; |
| 63 | static jfieldID field_storageInfo_description; |
| 64 | static jfieldID field_storageInfo_volumeIdentifier; |
| 65 | |
| 66 | // MtpObjectInfo fields |
| 67 | static jfieldID field_objectInfo_handle; |
| 68 | static jfieldID field_objectInfo_storageId; |
| 69 | static jfieldID field_objectInfo_format; |
| 70 | static jfieldID field_objectInfo_protectionStatus; |
| 71 | static jfieldID field_objectInfo_compressedSize; |
| 72 | static jfieldID field_objectInfo_thumbFormat; |
| 73 | static jfieldID field_objectInfo_thumbCompressedSize; |
| 74 | static jfieldID field_objectInfo_thumbPixWidth; |
| 75 | static jfieldID field_objectInfo_thumbPixHeight; |
| 76 | static jfieldID field_objectInfo_imagePixWidth; |
| 77 | static jfieldID field_objectInfo_imagePixHeight; |
| 78 | static jfieldID field_objectInfo_imagePixDepth; |
| 79 | static jfieldID field_objectInfo_parent; |
| 80 | static jfieldID field_objectInfo_associationType; |
| 81 | static jfieldID field_objectInfo_associationDesc; |
| 82 | static jfieldID field_objectInfo_sequenceNumber; |
| 83 | static jfieldID field_objectInfo_name; |
| 84 | static jfieldID field_objectInfo_dateCreated; |
| 85 | static jfieldID field_objectInfo_dateModified; |
| 86 | static jfieldID field_objectInfo_keywords; |
| 87 | |
| 88 | #ifdef HAVE_ANDROID_OS |
| 89 | |
| 90 | MtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice) |
| 91 | { |
| 92 | return (MtpDevice*)env->GetIntField(javaDevice, field_context); |
| 93 | } |
| 94 | |
| 95 | static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
| 96 | if (env->ExceptionCheck()) { |
| 97 | LOGE("An exception was thrown by callback '%s'.", methodName); |
| 98 | LOGE_EX(env); |
| 99 | env->ExceptionClear(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | #endif // HAVE_ANDROID_OS |
| 104 | |
| 105 | // ---------------------------------------------------------------------------- |
| 106 | |
| 107 | static jboolean |
| 108 | android_mtp_MtpDevice_open(JNIEnv *env, jobject thiz, jstring deviceName, jint fd) |
| 109 | { |
| 110 | #ifdef HAVE_ANDROID_OS |
| 111 | LOGD("open\n"); |
| 112 | const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL); |
| 113 | MtpDevice* device = MtpDevice::open(deviceNameStr, fd); |
| 114 | env->ReleaseStringUTFChars(deviceName, deviceNameStr); |
| 115 | |
| 116 | if (device) |
| 117 | env->SetIntField(thiz, field_context, (int)device); |
| 118 | return (device != NULL); |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | static void |
| 123 | android_mtp_MtpDevice_close(JNIEnv *env, jobject thiz) |
| 124 | { |
| 125 | #ifdef HAVE_ANDROID_OS |
| 126 | LOGD("close\n"); |
| 127 | MtpDevice* device = get_device_from_object(env, thiz); |
| 128 | if (device) { |
| 129 | device->close(); |
| 130 | delete device; |
| 131 | env->SetIntField(thiz, field_context, 0); |
| 132 | } |
| 133 | #endif |
| 134 | } |
| 135 | |
| 136 | static jobject |
| 137 | android_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz) |
| 138 | { |
| 139 | #ifdef HAVE_ANDROID_OS |
| 140 | MtpDevice* device = get_device_from_object(env, thiz); |
| 141 | if (!device) { |
| 142 | LOGD("android_mtp_MtpDevice_get_device_info device is null"); |
| 143 | return NULL; |
| 144 | } |
| 145 | MtpDeviceInfo* deviceInfo = device->getDeviceInfo(); |
| 146 | if (!deviceInfo) { |
| 147 | LOGD("android_mtp_MtpDevice_get_device_info deviceInfo is null"); |
| 148 | return NULL; |
| 149 | } |
| 150 | jobject info = env->NewObject(clazz_deviceInfo, constructor_deviceInfo); |
| 151 | if (info == NULL) { |
| 152 | LOGE("Could not create a MtpDeviceInfo object"); |
| 153 | delete deviceInfo; |
| 154 | return NULL; |
| 155 | } |
| 156 | |
| 157 | if (deviceInfo->mManufacturer) |
| 158 | env->SetObjectField(info, field_deviceInfo_manufacturer, |
| 159 | env->NewStringUTF(deviceInfo->mManufacturer)); |
| 160 | if (deviceInfo->mModel) |
| 161 | env->SetObjectField(info, field_deviceInfo_model, |
| 162 | env->NewStringUTF(deviceInfo->mModel)); |
| 163 | if (deviceInfo->mVersion) |
| 164 | env->SetObjectField(info, field_deviceInfo_version, |
| 165 | env->NewStringUTF(deviceInfo->mVersion)); |
| 166 | if (deviceInfo->mSerial) |
| 167 | env->SetObjectField(info, field_deviceInfo_serialNumber, |
| 168 | env->NewStringUTF(deviceInfo->mSerial)); |
| 169 | |
| 170 | delete deviceInfo; |
| 171 | return info; |
| 172 | #else |
| 173 | return NULL; |
| 174 | #endif |
| 175 | } |
| 176 | |
| 177 | static jintArray |
| 178 | android_mtp_MtpDevice_get_storage_ids(JNIEnv *env, jobject thiz) |
| 179 | { |
| 180 | #ifdef HAVE_ANDROID_OS |
| 181 | MtpDevice* device = get_device_from_object(env, thiz); |
| 182 | if (!device) |
| 183 | return NULL; |
| 184 | MtpStorageIDList* storageIDs = device->getStorageIDs(); |
| 185 | if (!storageIDs) |
| 186 | return NULL; |
| 187 | |
| 188 | int length = storageIDs->size(); |
| 189 | jintArray array = env->NewIntArray(length); |
| 190 | // FIXME is this cast safe? |
| 191 | env->SetIntArrayRegion(array, 0, length, (const jint *)storageIDs->array()); |
| 192 | |
| 193 | delete storageIDs; |
| 194 | return array; |
| 195 | #else |
| 196 | return NULL; |
| 197 | #endif |
| 198 | } |
| 199 | |
| 200 | static jobject |
| 201 | android_mtp_MtpDevice_get_storage_info(JNIEnv *env, jobject thiz, jint storageID) |
| 202 | { |
| 203 | #ifdef HAVE_ANDROID_OS |
| 204 | MtpDevice* device = get_device_from_object(env, thiz); |
| 205 | if (!device) |
| 206 | return NULL; |
| 207 | MtpStorageInfo* storageInfo = device->getStorageInfo(storageID); |
| 208 | if (!storageInfo) |
| 209 | return NULL; |
| 210 | |
| 211 | jobject info = env->NewObject(clazz_storageInfo, constructor_storageInfo); |
| 212 | if (info == NULL) { |
| 213 | LOGE("Could not create a MtpStorageInfo object"); |
| 214 | delete storageInfo; |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | if (storageInfo->mStorageID) |
| 219 | env->SetIntField(info, field_storageInfo_storageId, storageInfo->mStorageID); |
| 220 | if (storageInfo->mMaxCapacity) |
| 221 | env->SetLongField(info, field_storageInfo_maxCapacity, storageInfo->mMaxCapacity); |
| 222 | if (storageInfo->mFreeSpaceBytes) |
| 223 | env->SetLongField(info, field_storageInfo_freeSpace, storageInfo->mFreeSpaceBytes); |
| 224 | if (storageInfo->mStorageDescription) |
| 225 | env->SetObjectField(info, field_storageInfo_description, |
| 226 | env->NewStringUTF(storageInfo->mStorageDescription)); |
| 227 | if (storageInfo->mVolumeIdentifier) |
| 228 | env->SetObjectField(info, field_storageInfo_volumeIdentifier, |
| 229 | env->NewStringUTF(storageInfo->mVolumeIdentifier)); |
| 230 | |
| 231 | delete storageInfo; |
| 232 | return info; |
| 233 | #else |
| 234 | return NULL; |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | static jintArray |
| 239 | android_mtp_MtpDevice_get_object_handles(JNIEnv *env, jobject thiz, |
| 240 | jint storageID, jint format, jint objectID) |
| 241 | { |
| 242 | #ifdef HAVE_ANDROID_OS |
| 243 | MtpDevice* device = get_device_from_object(env, thiz); |
| 244 | if (!device) |
| 245 | return NULL; |
| 246 | MtpObjectHandleList* handles = device->getObjectHandles(storageID, format, objectID); |
| 247 | if (!handles) |
| 248 | return NULL; |
| 249 | |
| 250 | int length = handles->size(); |
| 251 | jintArray array = env->NewIntArray(length); |
| 252 | // FIXME is this cast safe? |
| 253 | env->SetIntArrayRegion(array, 0, length, (const jint *)handles->array()); |
| 254 | |
| 255 | delete handles; |
| 256 | return array; |
| 257 | #else |
| 258 | return NULL; |
| 259 | #endif |
| 260 | } |
| 261 | |
| 262 | static jobject |
| 263 | android_mtp_MtpDevice_get_object_info(JNIEnv *env, jobject thiz, jint objectID) |
| 264 | { |
| 265 | #ifdef HAVE_ANDROID_OS |
| 266 | MtpDevice* device = get_device_from_object(env, thiz); |
| 267 | if (!device) |
| 268 | return NULL; |
| 269 | MtpObjectInfo* objectInfo = device->getObjectInfo(objectID); |
| 270 | if (!objectInfo) |
| 271 | return NULL; |
| 272 | jobject info = env->NewObject(clazz_objectInfo, constructor_objectInfo); |
| 273 | if (info == NULL) { |
| 274 | LOGE("Could not create a MtpObjectInfo object"); |
| 275 | delete objectInfo; |
| 276 | return NULL; |
| 277 | } |
| 278 | |
| 279 | if (objectInfo->mHandle) |
| 280 | env->SetIntField(info, field_objectInfo_handle, objectInfo->mHandle); |
| 281 | if (objectInfo->mStorageID) |
| 282 | env->SetIntField(info, field_objectInfo_storageId, objectInfo->mStorageID); |
| 283 | if (objectInfo->mFormat) |
| 284 | env->SetIntField(info, field_objectInfo_format, objectInfo->mFormat); |
| 285 | if (objectInfo->mProtectionStatus) |
| 286 | env->SetIntField(info, field_objectInfo_protectionStatus, objectInfo->mProtectionStatus); |
| 287 | if (objectInfo->mCompressedSize) |
| 288 | env->SetIntField(info, field_objectInfo_compressedSize, objectInfo->mCompressedSize); |
| 289 | if (objectInfo->mThumbFormat) |
| 290 | env->SetIntField(info, field_objectInfo_thumbFormat, objectInfo->mThumbFormat); |
| 291 | if (objectInfo->mThumbCompressedSize) |
| 292 | env->SetIntField(info, field_objectInfo_thumbCompressedSize, objectInfo->mThumbCompressedSize); |
| 293 | if (objectInfo->mThumbPixWidth) |
| 294 | env->SetIntField(info, field_objectInfo_thumbPixWidth, objectInfo->mThumbPixWidth); |
| 295 | if (objectInfo->mThumbPixHeight) |
| 296 | env->SetIntField(info, field_objectInfo_thumbPixHeight, objectInfo->mThumbPixHeight); |
| 297 | if (objectInfo->mImagePixWidth) |
| 298 | env->SetIntField(info, field_objectInfo_imagePixWidth, objectInfo->mImagePixWidth); |
| 299 | if (objectInfo->mImagePixHeight) |
| 300 | env->SetIntField(info, field_objectInfo_imagePixHeight, objectInfo->mImagePixHeight); |
| 301 | if (objectInfo->mImagePixDepth) |
| 302 | env->SetIntField(info, field_objectInfo_imagePixDepth, objectInfo->mImagePixDepth); |
| 303 | if (objectInfo->mParent) |
| 304 | env->SetIntField(info, field_objectInfo_parent, objectInfo->mParent); |
| 305 | if (objectInfo->mAssociationType) |
| 306 | env->SetIntField(info, field_objectInfo_associationType, objectInfo->mAssociationType); |
| 307 | if (objectInfo->mAssociationDesc) |
| 308 | env->SetIntField(info, field_objectInfo_associationDesc, objectInfo->mAssociationDesc); |
| 309 | if (objectInfo->mSequenceNumber) |
| 310 | env->SetIntField(info, field_objectInfo_sequenceNumber, objectInfo->mSequenceNumber); |
| 311 | if (objectInfo->mName) |
| 312 | env->SetObjectField(info, field_objectInfo_name, env->NewStringUTF(objectInfo->mName)); |
| 313 | if (objectInfo->mDateCreated) |
Mike Lockwood | b966b9d | 2011-03-09 17:28:33 -0500 | [diff] [blame] | 314 | env->SetLongField(info, field_objectInfo_dateCreated, objectInfo->mDateCreated * 1000LL); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 315 | if (objectInfo->mDateModified) |
Mike Lockwood | b966b9d | 2011-03-09 17:28:33 -0500 | [diff] [blame] | 316 | env->SetLongField(info, field_objectInfo_dateModified, objectInfo->mDateModified * 1000LL); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 317 | if (objectInfo->mKeywords) |
| 318 | env->SetObjectField(info, field_objectInfo_keywords, |
| 319 | env->NewStringUTF(objectInfo->mKeywords)); |
| 320 | |
| 321 | delete objectInfo; |
| 322 | return info; |
| 323 | #else |
| 324 | return NULL; |
| 325 | #endif |
| 326 | } |
| 327 | |
| 328 | struct get_object_callback_data { |
| 329 | JNIEnv *env; |
| 330 | jbyteArray array; |
| 331 | }; |
| 332 | |
| 333 | static bool get_object_callback(void* data, int offset, int length, void* clientData) |
| 334 | { |
| 335 | get_object_callback_data* cbData = (get_object_callback_data *)clientData; |
| 336 | cbData->env->SetByteArrayRegion(cbData->array, offset, length, (jbyte *)data); |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | static jbyteArray |
| 341 | android_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize) |
| 342 | { |
| 343 | #ifdef HAVE_ANDROID_OS |
| 344 | MtpDevice* device = get_device_from_object(env, thiz); |
| 345 | if (!device) |
| 346 | return NULL; |
| 347 | |
| 348 | jbyteArray array = env->NewByteArray(objectSize); |
| 349 | if (!array) { |
| 350 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | get_object_callback_data data; |
| 355 | data.env = env; |
| 356 | data.array = array; |
| 357 | |
| 358 | if (device->readObject(objectID, get_object_callback, objectSize, &data)) |
| 359 | return array; |
| 360 | #endif |
| 361 | return NULL; |
| 362 | } |
| 363 | |
| 364 | static jbyteArray |
| 365 | android_mtp_MtpDevice_get_thumbnail(JNIEnv *env, jobject thiz, jint objectID) |
| 366 | { |
| 367 | #ifdef HAVE_ANDROID_OS |
| 368 | MtpDevice* device = get_device_from_object(env, thiz); |
| 369 | if (!device) |
| 370 | return NULL; |
| 371 | |
| 372 | int length; |
| 373 | void* thumbnail = device->getThumbnail(objectID, length); |
| 374 | if (! thumbnail) |
| 375 | return NULL; |
| 376 | jbyteArray array = env->NewByteArray(length); |
| 377 | env->SetByteArrayRegion(array, 0, length, (const jbyte *)thumbnail); |
| 378 | |
| 379 | free(thumbnail); |
| 380 | return array; |
| 381 | #else |
| 382 | return NULL; |
| 383 | #endif |
| 384 | } |
| 385 | |
| 386 | static jboolean |
| 387 | android_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id) |
| 388 | { |
| 389 | #ifdef HAVE_ANDROID_OS |
| 390 | MtpDevice* device = get_device_from_object(env, thiz); |
| 391 | if (device) |
| 392 | return device->deleteObject(object_id); |
| 393 | else |
| 394 | #endif |
| 395 | return NULL; |
| 396 | } |
| 397 | |
| 398 | static jlong |
| 399 | android_mtp_MtpDevice_get_parent(JNIEnv *env, jobject thiz, jint object_id) |
| 400 | { |
| 401 | #ifdef HAVE_ANDROID_OS |
| 402 | MtpDevice* device = get_device_from_object(env, thiz); |
| 403 | if (device) |
| 404 | return device->getParent(object_id); |
| 405 | else |
| 406 | #endif |
| 407 | return -1; |
| 408 | } |
| 409 | |
| 410 | static jlong |
| 411 | android_mtp_MtpDevice_get_storage_id(JNIEnv *env, jobject thiz, jint object_id) |
| 412 | { |
| 413 | #ifdef HAVE_ANDROID_OS |
| 414 | MtpDevice* device = get_device_from_object(env, thiz); |
| 415 | if (device) |
| 416 | return device->getStorageID(object_id); |
| 417 | else |
| 418 | #endif |
| 419 | return -1; |
| 420 | } |
| 421 | |
| 422 | static jboolean |
| 423 | android_mtp_MtpDevice_import_file(JNIEnv *env, jobject thiz, jint object_id, jstring dest_path) |
| 424 | { |
| 425 | #ifdef HAVE_ANDROID_OS |
| 426 | MtpDevice* device = get_device_from_object(env, thiz); |
| 427 | if (device) { |
| 428 | const char *destPathStr = env->GetStringUTFChars(dest_path, NULL); |
| 429 | bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664); |
| 430 | env->ReleaseStringUTFChars(dest_path, destPathStr); |
| 431 | return result; |
| 432 | } |
| 433 | #endif |
| 434 | return NULL; |
| 435 | } |
| 436 | |
| 437 | // ---------------------------------------------------------------------------- |
| 438 | |
| 439 | static JNINativeMethod gMethods[] = { |
| 440 | {"native_open", "(Ljava/lang/String;I)Z", |
| 441 | (void *)android_mtp_MtpDevice_open}, |
| 442 | {"native_close", "()V", (void *)android_mtp_MtpDevice_close}, |
| 443 | {"native_get_device_info", "()Landroid/mtp/MtpDeviceInfo;", |
| 444 | (void *)android_mtp_MtpDevice_get_device_info}, |
| 445 | {"native_get_storage_ids", "()[I", (void *)android_mtp_MtpDevice_get_storage_ids}, |
| 446 | {"native_get_storage_info", "(I)Landroid/mtp/MtpStorageInfo;", |
| 447 | (void *)android_mtp_MtpDevice_get_storage_info}, |
| 448 | {"native_get_object_handles","(III)[I", |
| 449 | (void *)android_mtp_MtpDevice_get_object_handles}, |
| 450 | {"native_get_object_info", "(I)Landroid/mtp/MtpObjectInfo;", |
| 451 | (void *)android_mtp_MtpDevice_get_object_info}, |
| 452 | {"native_get_object", "(II)[B",(void *)android_mtp_MtpDevice_get_object}, |
| 453 | {"native_get_thumbnail", "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail}, |
| 454 | {"native_delete_object", "(I)Z", (void *)android_mtp_MtpDevice_delete_object}, |
| 455 | {"native_get_parent", "(I)J", (void *)android_mtp_MtpDevice_get_parent}, |
| 456 | {"native_get_storage_id", "(I)J", (void *)android_mtp_MtpDevice_get_storage_id}, |
| 457 | {"native_import_file", "(ILjava/lang/String;)Z", |
| 458 | (void *)android_mtp_MtpDevice_import_file}, |
| 459 | }; |
| 460 | |
| 461 | static const char* const kClassPathName = "android/mtp/MtpDevice"; |
| 462 | |
| 463 | int register_android_mtp_MtpDevice(JNIEnv *env) |
| 464 | { |
| 465 | jclass clazz; |
| 466 | |
| 467 | LOGD("register_android_mtp_MtpDevice\n"); |
| 468 | |
| 469 | clazz = env->FindClass("android/mtp/MtpDeviceInfo"); |
| 470 | if (clazz == NULL) { |
| 471 | LOGE("Can't find android/mtp/MtpDeviceInfo"); |
| 472 | return -1; |
| 473 | } |
| 474 | constructor_deviceInfo = env->GetMethodID(clazz, "<init>", "()V"); |
| 475 | if (constructor_deviceInfo == NULL) { |
| 476 | LOGE("Can't find android/mtp/MtpDeviceInfo constructor"); |
| 477 | return -1; |
| 478 | } |
| 479 | field_deviceInfo_manufacturer = env->GetFieldID(clazz, "mManufacturer", "Ljava/lang/String;"); |
| 480 | if (field_deviceInfo_manufacturer == NULL) { |
| 481 | LOGE("Can't find MtpDeviceInfo.mManufacturer"); |
| 482 | return -1; |
| 483 | } |
| 484 | field_deviceInfo_model = env->GetFieldID(clazz, "mModel", "Ljava/lang/String;"); |
| 485 | if (field_deviceInfo_model == NULL) { |
| 486 | LOGE("Can't find MtpDeviceInfo.mModel"); |
| 487 | return -1; |
| 488 | } |
| 489 | field_deviceInfo_version = env->GetFieldID(clazz, "mVersion", "Ljava/lang/String;"); |
| 490 | if (field_deviceInfo_version == NULL) { |
| 491 | LOGE("Can't find MtpDeviceInfo.mVersion"); |
| 492 | return -1; |
| 493 | } |
| 494 | field_deviceInfo_serialNumber = env->GetFieldID(clazz, "mSerialNumber", "Ljava/lang/String;"); |
| 495 | if (field_deviceInfo_serialNumber == NULL) { |
| 496 | LOGE("Can't find MtpDeviceInfo.mSerialNumber"); |
| 497 | return -1; |
| 498 | } |
Mike Lockwood | 40304e2 | 2011-02-11 08:19:11 -0500 | [diff] [blame] | 499 | clazz_deviceInfo = (jclass)env->NewGlobalRef(clazz); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 500 | |
| 501 | clazz = env->FindClass("android/mtp/MtpStorageInfo"); |
| 502 | if (clazz == NULL) { |
| 503 | LOGE("Can't find android/mtp/MtpStorageInfo"); |
| 504 | return -1; |
| 505 | } |
| 506 | constructor_storageInfo = env->GetMethodID(clazz, "<init>", "()V"); |
| 507 | if (constructor_storageInfo == NULL) { |
| 508 | LOGE("Can't find android/mtp/MtpStorageInfo constructor"); |
| 509 | return -1; |
| 510 | } |
| 511 | field_storageInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I"); |
| 512 | if (field_storageInfo_storageId == NULL) { |
| 513 | LOGE("Can't find MtpStorageInfo.mStorageId"); |
| 514 | return -1; |
| 515 | } |
| 516 | field_storageInfo_maxCapacity = env->GetFieldID(clazz, "mMaxCapacity", "J"); |
| 517 | if (field_storageInfo_maxCapacity == NULL) { |
| 518 | LOGE("Can't find MtpStorageInfo.mMaxCapacity"); |
| 519 | return -1; |
| 520 | } |
| 521 | field_storageInfo_freeSpace = env->GetFieldID(clazz, "mFreeSpace", "J"); |
| 522 | if (field_storageInfo_freeSpace == NULL) { |
| 523 | LOGE("Can't find MtpStorageInfo.mFreeSpace"); |
| 524 | return -1; |
| 525 | } |
| 526 | field_storageInfo_description = env->GetFieldID(clazz, "mDescription", "Ljava/lang/String;"); |
| 527 | if (field_storageInfo_description == NULL) { |
| 528 | LOGE("Can't find MtpStorageInfo.mDescription"); |
| 529 | return -1; |
| 530 | } |
| 531 | field_storageInfo_volumeIdentifier = env->GetFieldID(clazz, "mVolumeIdentifier", "Ljava/lang/String;"); |
| 532 | if (field_storageInfo_volumeIdentifier == NULL) { |
| 533 | LOGE("Can't find MtpStorageInfo.mVolumeIdentifier"); |
| 534 | return -1; |
| 535 | } |
Mike Lockwood | 40304e2 | 2011-02-11 08:19:11 -0500 | [diff] [blame] | 536 | clazz_storageInfo = (jclass)env->NewGlobalRef(clazz); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 537 | |
| 538 | clazz = env->FindClass("android/mtp/MtpObjectInfo"); |
| 539 | if (clazz == NULL) { |
| 540 | LOGE("Can't find android/mtp/MtpObjectInfo"); |
| 541 | return -1; |
| 542 | } |
| 543 | constructor_objectInfo = env->GetMethodID(clazz, "<init>", "()V"); |
| 544 | if (constructor_objectInfo == NULL) { |
| 545 | LOGE("Can't find android/mtp/MtpObjectInfo constructor"); |
| 546 | return -1; |
| 547 | } |
| 548 | field_objectInfo_handle = env->GetFieldID(clazz, "mHandle", "I"); |
| 549 | if (field_objectInfo_handle == NULL) { |
| 550 | LOGE("Can't find MtpObjectInfo.mHandle"); |
| 551 | return -1; |
| 552 | } |
| 553 | field_objectInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I"); |
| 554 | if (field_objectInfo_storageId == NULL) { |
| 555 | LOGE("Can't find MtpObjectInfo.mStorageId"); |
| 556 | return -1; |
| 557 | } |
| 558 | field_objectInfo_format = env->GetFieldID(clazz, "mFormat", "I"); |
| 559 | if (field_objectInfo_format == NULL) { |
| 560 | LOGE("Can't find MtpObjectInfo.mFormat"); |
| 561 | return -1; |
| 562 | } |
| 563 | field_objectInfo_protectionStatus = env->GetFieldID(clazz, "mProtectionStatus", "I"); |
| 564 | if (field_objectInfo_protectionStatus == NULL) { |
| 565 | LOGE("Can't find MtpObjectInfo.mProtectionStatus"); |
| 566 | return -1; |
| 567 | } |
| 568 | field_objectInfo_compressedSize = env->GetFieldID(clazz, "mCompressedSize", "I"); |
| 569 | if (field_objectInfo_compressedSize == NULL) { |
| 570 | LOGE("Can't find MtpObjectInfo.mCompressedSize"); |
| 571 | return -1; |
| 572 | } |
| 573 | field_objectInfo_thumbFormat = env->GetFieldID(clazz, "mThumbFormat", "I"); |
| 574 | if (field_objectInfo_thumbFormat == NULL) { |
| 575 | LOGE("Can't find MtpObjectInfo.mThumbFormat"); |
| 576 | return -1; |
| 577 | } |
| 578 | field_objectInfo_thumbCompressedSize = env->GetFieldID(clazz, "mThumbCompressedSize", "I"); |
| 579 | if (field_objectInfo_thumbCompressedSize == NULL) { |
| 580 | LOGE("Can't find MtpObjectInfo.mThumbCompressedSize"); |
| 581 | return -1; |
| 582 | } |
| 583 | field_objectInfo_thumbPixWidth = env->GetFieldID(clazz, "mThumbPixWidth", "I"); |
| 584 | if (field_objectInfo_thumbPixWidth == NULL) { |
| 585 | LOGE("Can't find MtpObjectInfo.mThumbPixWidth"); |
| 586 | return -1; |
| 587 | } |
| 588 | field_objectInfo_thumbPixHeight = env->GetFieldID(clazz, "mThumbPixHeight", "I"); |
| 589 | if (field_objectInfo_thumbPixHeight == NULL) { |
| 590 | LOGE("Can't find MtpObjectInfo.mThumbPixHeight"); |
| 591 | return -1; |
| 592 | } |
| 593 | field_objectInfo_imagePixWidth = env->GetFieldID(clazz, "mImagePixWidth", "I"); |
| 594 | if (field_objectInfo_imagePixWidth == NULL) { |
| 595 | LOGE("Can't find MtpObjectInfo.mImagePixWidth"); |
| 596 | return -1; |
| 597 | } |
| 598 | field_objectInfo_imagePixHeight = env->GetFieldID(clazz, "mImagePixHeight", "I"); |
| 599 | if (field_objectInfo_imagePixHeight == NULL) { |
| 600 | LOGE("Can't find MtpObjectInfo.mImagePixHeight"); |
| 601 | return -1; |
| 602 | } |
| 603 | field_objectInfo_imagePixDepth = env->GetFieldID(clazz, "mImagePixDepth", "I"); |
| 604 | if (field_objectInfo_imagePixDepth == NULL) { |
| 605 | LOGE("Can't find MtpObjectInfo.mImagePixDepth"); |
| 606 | return -1; |
| 607 | } |
| 608 | field_objectInfo_parent = env->GetFieldID(clazz, "mParent", "I"); |
| 609 | if (field_objectInfo_parent == NULL) { |
| 610 | LOGE("Can't find MtpObjectInfo.mParent"); |
| 611 | return -1; |
| 612 | } |
| 613 | field_objectInfo_associationType = env->GetFieldID(clazz, "mAssociationType", "I"); |
| 614 | if (field_objectInfo_associationType == NULL) { |
| 615 | LOGE("Can't find MtpObjectInfo.mAssociationType"); |
| 616 | return -1; |
| 617 | } |
| 618 | field_objectInfo_associationDesc = env->GetFieldID(clazz, "mAssociationDesc", "I"); |
| 619 | if (field_objectInfo_associationDesc == NULL) { |
| 620 | LOGE("Can't find MtpObjectInfo.mAssociationDesc"); |
| 621 | return -1; |
| 622 | } |
| 623 | field_objectInfo_sequenceNumber = env->GetFieldID(clazz, "mSequenceNumber", "I"); |
| 624 | if (field_objectInfo_sequenceNumber == NULL) { |
| 625 | LOGE("Can't find MtpObjectInfo.mSequenceNumber"); |
| 626 | return -1; |
| 627 | } |
| 628 | field_objectInfo_name = env->GetFieldID(clazz, "mName", "Ljava/lang/String;"); |
| 629 | if (field_objectInfo_name == NULL) { |
| 630 | LOGE("Can't find MtpObjectInfo.mName"); |
| 631 | return -1; |
| 632 | } |
| 633 | field_objectInfo_dateCreated = env->GetFieldID(clazz, "mDateCreated", "J"); |
| 634 | if (field_objectInfo_dateCreated == NULL) { |
| 635 | LOGE("Can't find MtpObjectInfo.mDateCreated"); |
| 636 | return -1; |
| 637 | } |
| 638 | field_objectInfo_dateModified = env->GetFieldID(clazz, "mDateModified", "J"); |
| 639 | if (field_objectInfo_dateModified == NULL) { |
| 640 | LOGE("Can't find MtpObjectInfo.mDateModified"); |
| 641 | return -1; |
| 642 | } |
| 643 | field_objectInfo_keywords = env->GetFieldID(clazz, "mKeywords", "Ljava/lang/String;"); |
| 644 | if (field_objectInfo_keywords == NULL) { |
| 645 | LOGE("Can't find MtpObjectInfo.mKeywords"); |
| 646 | return -1; |
| 647 | } |
Mike Lockwood | 40304e2 | 2011-02-11 08:19:11 -0500 | [diff] [blame] | 648 | clazz_objectInfo = (jclass)env->NewGlobalRef(clazz); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 649 | |
| 650 | clazz = env->FindClass("android/mtp/MtpDevice"); |
| 651 | if (clazz == NULL) { |
| 652 | LOGE("Can't find android/mtp/MtpDevice"); |
| 653 | return -1; |
| 654 | } |
| 655 | field_context = env->GetFieldID(clazz, "mNativeContext", "I"); |
| 656 | if (field_context == NULL) { |
| 657 | LOGE("Can't find MtpDevice.mNativeContext"); |
| 658 | return -1; |
| 659 | } |
| 660 | |
| 661 | return AndroidRuntime::registerNativeMethods(env, |
| 662 | "android/mtp/MtpDevice", gMethods, NELEM(gMethods)); |
| 663 | } |