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