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