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" |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 31 | #include "android_runtime/Log.h" |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 89 | MtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice) |
| 90 | { |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 91 | return (MtpDevice*)env->GetLongField(javaDevice, field_context); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 94 | // ---------------------------------------------------------------------------- |
| 95 | |
| 96 | static jboolean |
| 97 | android_mtp_MtpDevice_open(JNIEnv *env, jobject thiz, jstring deviceName, jint fd) |
| 98 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 99 | const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL); |
James Dong | 3977472 | 2011-04-06 11:57:48 -0700 | [diff] [blame] | 100 | if (deviceNameStr == NULL) { |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 101 | return JNI_FALSE; |
James Dong | 3977472 | 2011-04-06 11:57:48 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 104 | MtpDevice* device = MtpDevice::open(deviceNameStr, fd); |
| 105 | env->ReleaseStringUTFChars(deviceName, deviceNameStr); |
| 106 | |
| 107 | if (device) |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 108 | env->SetLongField(thiz, field_context, (jlong)device); |
| 109 | return (jboolean)(device != NULL); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void |
| 113 | android_mtp_MtpDevice_close(JNIEnv *env, jobject thiz) |
| 114 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 115 | MtpDevice* device = get_device_from_object(env, thiz); |
| 116 | if (device) { |
| 117 | device->close(); |
| 118 | delete device; |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 119 | env->SetLongField(thiz, field_context, 0); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 120 | } |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static jobject |
| 124 | android_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz) |
| 125 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 126 | MtpDevice* device = get_device_from_object(env, thiz); |
| 127 | if (!device) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 128 | ALOGD("android_mtp_MtpDevice_get_device_info device is null"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 129 | return NULL; |
| 130 | } |
| 131 | MtpDeviceInfo* deviceInfo = device->getDeviceInfo(); |
| 132 | if (!deviceInfo) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 133 | ALOGD("android_mtp_MtpDevice_get_device_info deviceInfo is null"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 134 | return NULL; |
| 135 | } |
| 136 | jobject info = env->NewObject(clazz_deviceInfo, constructor_deviceInfo); |
| 137 | if (info == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 138 | ALOGE("Could not create a MtpDeviceInfo object"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static jintArray |
| 161 | android_mtp_MtpDevice_get_storage_ids(JNIEnv *env, jobject thiz) |
| 162 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static jobject |
| 180 | android_mtp_MtpDevice_get_storage_info(JNIEnv *env, jobject thiz, jint storageID) |
| 181 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 191 | ALOGE("Could not create a MtpStorageInfo object"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static jintArray |
| 214 | android_mtp_MtpDevice_get_object_handles(JNIEnv *env, jobject thiz, |
| 215 | jint storageID, jint format, jint objectID) |
| 216 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static jobject |
| 234 | android_mtp_MtpDevice_get_object_info(JNIEnv *env, jobject thiz, jint objectID) |
| 235 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 244 | ALOGE("Could not create a MtpObjectInfo object"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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) |
Mike Lockwood | b966b9d | 2011-03-09 17:28:33 -0500 | [diff] [blame] | 284 | env->SetLongField(info, field_objectInfo_dateCreated, objectInfo->mDateCreated * 1000LL); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 285 | if (objectInfo->mDateModified) |
Mike Lockwood | b966b9d | 2011-03-09 17:28:33 -0500 | [diff] [blame] | 286 | env->SetLongField(info, field_objectInfo_dateModified, objectInfo->mDateModified * 1000LL); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 287 | if (objectInfo->mKeywords) |
| 288 | env->SetObjectField(info, field_objectInfo_keywords, |
| 289 | env->NewStringUTF(objectInfo->mKeywords)); |
| 290 | |
| 291 | delete objectInfo; |
| 292 | return info; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | struct get_object_callback_data { |
| 296 | JNIEnv *env; |
| 297 | jbyteArray array; |
| 298 | }; |
| 299 | |
| 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 |
| 308 | android_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize) |
| 309 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 326 | return NULL; |
| 327 | } |
| 328 | |
| 329 | static jbyteArray |
| 330 | android_mtp_MtpDevice_get_thumbnail(JNIEnv *env, jobject thiz, jint objectID) |
| 331 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 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; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static jboolean |
| 348 | android_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id) |
| 349 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 350 | MtpDevice* device = get_device_from_object(env, thiz); |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 351 | if (device && device->deleteObject(object_id)) { |
| 352 | return JNI_TRUE; |
| 353 | } else { |
| 354 | return JNI_FALSE; |
| 355 | } |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static jlong |
| 359 | android_mtp_MtpDevice_get_parent(JNIEnv *env, jobject thiz, jint object_id) |
| 360 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 361 | MtpDevice* device = get_device_from_object(env, thiz); |
| 362 | if (device) |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 363 | return (jlong)device->getParent(object_id); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 364 | else |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 365 | return -1; |
| 366 | } |
| 367 | |
| 368 | static jlong |
| 369 | android_mtp_MtpDevice_get_storage_id(JNIEnv *env, jobject thiz, jint object_id) |
| 370 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 371 | MtpDevice* device = get_device_from_object(env, thiz); |
| 372 | if (device) |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 373 | return (jlong)device->getStorageID(object_id); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 374 | else |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 375 | return -1; |
| 376 | } |
| 377 | |
| 378 | static jboolean |
| 379 | android_mtp_MtpDevice_import_file(JNIEnv *env, jobject thiz, jint object_id, jstring dest_path) |
| 380 | { |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 381 | MtpDevice* device = get_device_from_object(env, thiz); |
| 382 | if (device) { |
| 383 | const char *destPathStr = env->GetStringUTFChars(dest_path, NULL); |
James Dong | 3977472 | 2011-04-06 11:57:48 -0700 | [diff] [blame] | 384 | if (destPathStr == NULL) { |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 385 | return JNI_FALSE; |
James Dong | 3977472 | 2011-04-06 11:57:48 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 388 | jboolean result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 389 | env->ReleaseStringUTFChars(dest_path, destPathStr); |
| 390 | return result; |
| 391 | } |
Mike Lockwood | c1b9bbb | 2011-07-13 11:06:57 -0400 | [diff] [blame] | 392 | |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 393 | return JNI_FALSE; |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 394 | } |
| 395 | |
Tomasz Mikolajewski | 74d4ff8 | 2015-08-04 18:34:03 +0900 | [diff] [blame] | 396 | static jboolean |
| 397 | android_mtp_MtpDevice_import_file_to_fd(JNIEnv *env, jobject thiz, jint object_id, jint fd) |
| 398 | { |
| 399 | MtpDevice* device = get_device_from_object(env, thiz); |
| 400 | if (device) |
| 401 | return device->readObject(object_id, fd); |
| 402 | else |
| 403 | return JNI_FALSE; |
| 404 | } |
| 405 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 406 | // ---------------------------------------------------------------------------- |
| 407 | |
| 408 | static JNINativeMethod gMethods[] = { |
| 409 | {"native_open", "(Ljava/lang/String;I)Z", |
| 410 | (void *)android_mtp_MtpDevice_open}, |
| 411 | {"native_close", "()V", (void *)android_mtp_MtpDevice_close}, |
| 412 | {"native_get_device_info", "()Landroid/mtp/MtpDeviceInfo;", |
| 413 | (void *)android_mtp_MtpDevice_get_device_info}, |
| 414 | {"native_get_storage_ids", "()[I", (void *)android_mtp_MtpDevice_get_storage_ids}, |
| 415 | {"native_get_storage_info", "(I)Landroid/mtp/MtpStorageInfo;", |
| 416 | (void *)android_mtp_MtpDevice_get_storage_info}, |
| 417 | {"native_get_object_handles","(III)[I", |
| 418 | (void *)android_mtp_MtpDevice_get_object_handles}, |
| 419 | {"native_get_object_info", "(I)Landroid/mtp/MtpObjectInfo;", |
| 420 | (void *)android_mtp_MtpDevice_get_object_info}, |
| 421 | {"native_get_object", "(II)[B",(void *)android_mtp_MtpDevice_get_object}, |
| 422 | {"native_get_thumbnail", "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail}, |
| 423 | {"native_delete_object", "(I)Z", (void *)android_mtp_MtpDevice_delete_object}, |
| 424 | {"native_get_parent", "(I)J", (void *)android_mtp_MtpDevice_get_parent}, |
| 425 | {"native_get_storage_id", "(I)J", (void *)android_mtp_MtpDevice_get_storage_id}, |
Tomasz Mikolajewski | 74d4ff8 | 2015-08-04 18:34:03 +0900 | [diff] [blame] | 426 | {"native_import_file", "(ILjava/lang/String;)Z", |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 427 | (void *)android_mtp_MtpDevice_import_file}, |
Tomasz Mikolajewski | 74d4ff8 | 2015-08-04 18:34:03 +0900 | [diff] [blame] | 428 | {"native_import_file", "(II)Z", (void *)android_mtp_MtpDevice_import_file_to_fd} |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 429 | }; |
| 430 | |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 431 | int register_android_mtp_MtpDevice(JNIEnv *env) |
| 432 | { |
| 433 | jclass clazz; |
| 434 | |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 435 | ALOGD("register_android_mtp_MtpDevice\n"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 436 | |
| 437 | clazz = env->FindClass("android/mtp/MtpDeviceInfo"); |
| 438 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 439 | ALOGE("Can't find android/mtp/MtpDeviceInfo"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 440 | return -1; |
| 441 | } |
| 442 | constructor_deviceInfo = env->GetMethodID(clazz, "<init>", "()V"); |
| 443 | if (constructor_deviceInfo == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 444 | ALOGE("Can't find android/mtp/MtpDeviceInfo constructor"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 445 | return -1; |
| 446 | } |
| 447 | field_deviceInfo_manufacturer = env->GetFieldID(clazz, "mManufacturer", "Ljava/lang/String;"); |
| 448 | if (field_deviceInfo_manufacturer == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 449 | ALOGE("Can't find MtpDeviceInfo.mManufacturer"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 450 | return -1; |
| 451 | } |
| 452 | field_deviceInfo_model = env->GetFieldID(clazz, "mModel", "Ljava/lang/String;"); |
| 453 | if (field_deviceInfo_model == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 454 | ALOGE("Can't find MtpDeviceInfo.mModel"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 455 | return -1; |
| 456 | } |
| 457 | field_deviceInfo_version = env->GetFieldID(clazz, "mVersion", "Ljava/lang/String;"); |
| 458 | if (field_deviceInfo_version == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 459 | ALOGE("Can't find MtpDeviceInfo.mVersion"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 460 | return -1; |
| 461 | } |
| 462 | field_deviceInfo_serialNumber = env->GetFieldID(clazz, "mSerialNumber", "Ljava/lang/String;"); |
| 463 | if (field_deviceInfo_serialNumber == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 464 | ALOGE("Can't find MtpDeviceInfo.mSerialNumber"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 465 | return -1; |
| 466 | } |
Mike Lockwood | 40304e2 | 2011-02-11 08:19:11 -0500 | [diff] [blame] | 467 | clazz_deviceInfo = (jclass)env->NewGlobalRef(clazz); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 468 | |
| 469 | clazz = env->FindClass("android/mtp/MtpStorageInfo"); |
| 470 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 471 | ALOGE("Can't find android/mtp/MtpStorageInfo"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 472 | return -1; |
| 473 | } |
| 474 | constructor_storageInfo = env->GetMethodID(clazz, "<init>", "()V"); |
| 475 | if (constructor_storageInfo == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 476 | ALOGE("Can't find android/mtp/MtpStorageInfo constructor"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 477 | return -1; |
| 478 | } |
| 479 | field_storageInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I"); |
| 480 | if (field_storageInfo_storageId == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 481 | ALOGE("Can't find MtpStorageInfo.mStorageId"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 482 | return -1; |
| 483 | } |
| 484 | field_storageInfo_maxCapacity = env->GetFieldID(clazz, "mMaxCapacity", "J"); |
| 485 | if (field_storageInfo_maxCapacity == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 486 | ALOGE("Can't find MtpStorageInfo.mMaxCapacity"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 487 | return -1; |
| 488 | } |
| 489 | field_storageInfo_freeSpace = env->GetFieldID(clazz, "mFreeSpace", "J"); |
| 490 | if (field_storageInfo_freeSpace == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 491 | ALOGE("Can't find MtpStorageInfo.mFreeSpace"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 492 | return -1; |
| 493 | } |
| 494 | field_storageInfo_description = env->GetFieldID(clazz, "mDescription", "Ljava/lang/String;"); |
| 495 | if (field_storageInfo_description == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 496 | ALOGE("Can't find MtpStorageInfo.mDescription"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 497 | return -1; |
| 498 | } |
| 499 | field_storageInfo_volumeIdentifier = env->GetFieldID(clazz, "mVolumeIdentifier", "Ljava/lang/String;"); |
| 500 | if (field_storageInfo_volumeIdentifier == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 501 | ALOGE("Can't find MtpStorageInfo.mVolumeIdentifier"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 502 | return -1; |
| 503 | } |
Mike Lockwood | 40304e2 | 2011-02-11 08:19:11 -0500 | [diff] [blame] | 504 | clazz_storageInfo = (jclass)env->NewGlobalRef(clazz); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 505 | |
| 506 | clazz = env->FindClass("android/mtp/MtpObjectInfo"); |
| 507 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 508 | ALOGE("Can't find android/mtp/MtpObjectInfo"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 509 | return -1; |
| 510 | } |
| 511 | constructor_objectInfo = env->GetMethodID(clazz, "<init>", "()V"); |
| 512 | if (constructor_objectInfo == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 513 | ALOGE("Can't find android/mtp/MtpObjectInfo constructor"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 514 | return -1; |
| 515 | } |
| 516 | field_objectInfo_handle = env->GetFieldID(clazz, "mHandle", "I"); |
| 517 | if (field_objectInfo_handle == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 518 | ALOGE("Can't find MtpObjectInfo.mHandle"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 519 | return -1; |
| 520 | } |
| 521 | field_objectInfo_storageId = env->GetFieldID(clazz, "mStorageId", "I"); |
| 522 | if (field_objectInfo_storageId == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 523 | ALOGE("Can't find MtpObjectInfo.mStorageId"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 524 | return -1; |
| 525 | } |
| 526 | field_objectInfo_format = env->GetFieldID(clazz, "mFormat", "I"); |
| 527 | if (field_objectInfo_format == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 528 | ALOGE("Can't find MtpObjectInfo.mFormat"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 529 | return -1; |
| 530 | } |
| 531 | field_objectInfo_protectionStatus = env->GetFieldID(clazz, "mProtectionStatus", "I"); |
| 532 | if (field_objectInfo_protectionStatus == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 533 | ALOGE("Can't find MtpObjectInfo.mProtectionStatus"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 534 | return -1; |
| 535 | } |
| 536 | field_objectInfo_compressedSize = env->GetFieldID(clazz, "mCompressedSize", "I"); |
| 537 | if (field_objectInfo_compressedSize == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 538 | ALOGE("Can't find MtpObjectInfo.mCompressedSize"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 539 | return -1; |
| 540 | } |
| 541 | field_objectInfo_thumbFormat = env->GetFieldID(clazz, "mThumbFormat", "I"); |
| 542 | if (field_objectInfo_thumbFormat == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 543 | ALOGE("Can't find MtpObjectInfo.mThumbFormat"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 544 | return -1; |
| 545 | } |
| 546 | field_objectInfo_thumbCompressedSize = env->GetFieldID(clazz, "mThumbCompressedSize", "I"); |
| 547 | if (field_objectInfo_thumbCompressedSize == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 548 | ALOGE("Can't find MtpObjectInfo.mThumbCompressedSize"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 549 | return -1; |
| 550 | } |
| 551 | field_objectInfo_thumbPixWidth = env->GetFieldID(clazz, "mThumbPixWidth", "I"); |
| 552 | if (field_objectInfo_thumbPixWidth == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 553 | ALOGE("Can't find MtpObjectInfo.mThumbPixWidth"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 554 | return -1; |
| 555 | } |
| 556 | field_objectInfo_thumbPixHeight = env->GetFieldID(clazz, "mThumbPixHeight", "I"); |
| 557 | if (field_objectInfo_thumbPixHeight == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 558 | ALOGE("Can't find MtpObjectInfo.mThumbPixHeight"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 559 | return -1; |
| 560 | } |
| 561 | field_objectInfo_imagePixWidth = env->GetFieldID(clazz, "mImagePixWidth", "I"); |
| 562 | if (field_objectInfo_imagePixWidth == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 563 | ALOGE("Can't find MtpObjectInfo.mImagePixWidth"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 564 | return -1; |
| 565 | } |
| 566 | field_objectInfo_imagePixHeight = env->GetFieldID(clazz, "mImagePixHeight", "I"); |
| 567 | if (field_objectInfo_imagePixHeight == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 568 | ALOGE("Can't find MtpObjectInfo.mImagePixHeight"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 569 | return -1; |
| 570 | } |
| 571 | field_objectInfo_imagePixDepth = env->GetFieldID(clazz, "mImagePixDepth", "I"); |
| 572 | if (field_objectInfo_imagePixDepth == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 573 | ALOGE("Can't find MtpObjectInfo.mImagePixDepth"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 574 | return -1; |
| 575 | } |
| 576 | field_objectInfo_parent = env->GetFieldID(clazz, "mParent", "I"); |
| 577 | if (field_objectInfo_parent == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 578 | ALOGE("Can't find MtpObjectInfo.mParent"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 579 | return -1; |
| 580 | } |
| 581 | field_objectInfo_associationType = env->GetFieldID(clazz, "mAssociationType", "I"); |
| 582 | if (field_objectInfo_associationType == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 583 | ALOGE("Can't find MtpObjectInfo.mAssociationType"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 584 | return -1; |
| 585 | } |
| 586 | field_objectInfo_associationDesc = env->GetFieldID(clazz, "mAssociationDesc", "I"); |
| 587 | if (field_objectInfo_associationDesc == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 588 | ALOGE("Can't find MtpObjectInfo.mAssociationDesc"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 589 | return -1; |
| 590 | } |
| 591 | field_objectInfo_sequenceNumber = env->GetFieldID(clazz, "mSequenceNumber", "I"); |
| 592 | if (field_objectInfo_sequenceNumber == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 593 | ALOGE("Can't find MtpObjectInfo.mSequenceNumber"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 594 | return -1; |
| 595 | } |
| 596 | field_objectInfo_name = env->GetFieldID(clazz, "mName", "Ljava/lang/String;"); |
| 597 | if (field_objectInfo_name == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 598 | ALOGE("Can't find MtpObjectInfo.mName"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 599 | return -1; |
| 600 | } |
| 601 | field_objectInfo_dateCreated = env->GetFieldID(clazz, "mDateCreated", "J"); |
| 602 | if (field_objectInfo_dateCreated == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 603 | ALOGE("Can't find MtpObjectInfo.mDateCreated"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 604 | return -1; |
| 605 | } |
| 606 | field_objectInfo_dateModified = env->GetFieldID(clazz, "mDateModified", "J"); |
| 607 | if (field_objectInfo_dateModified == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 608 | ALOGE("Can't find MtpObjectInfo.mDateModified"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 609 | return -1; |
| 610 | } |
| 611 | field_objectInfo_keywords = env->GetFieldID(clazz, "mKeywords", "Ljava/lang/String;"); |
| 612 | if (field_objectInfo_keywords == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 613 | ALOGE("Can't find MtpObjectInfo.mKeywords"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 614 | return -1; |
| 615 | } |
Mike Lockwood | 40304e2 | 2011-02-11 08:19:11 -0500 | [diff] [blame] | 616 | clazz_objectInfo = (jclass)env->NewGlobalRef(clazz); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 617 | |
| 618 | clazz = env->FindClass("android/mtp/MtpDevice"); |
| 619 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 620 | ALOGE("Can't find android/mtp/MtpDevice"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 621 | return -1; |
| 622 | } |
Ashok Bhat | e2e5932 | 2013-12-17 19:04:19 +0000 | [diff] [blame] | 623 | field_context = env->GetFieldID(clazz, "mNativeContext", "J"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 624 | if (field_context == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 625 | ALOGE("Can't find MtpDevice.mNativeContext"); |
Mike Lockwood | 8182e72 | 2010-12-30 15:38:45 -0500 | [diff] [blame] | 626 | return -1; |
| 627 | } |
| 628 | |
| 629 | return AndroidRuntime::registerNativeMethods(env, |
| 630 | "android/mtp/MtpDevice", gMethods, NELEM(gMethods)); |
| 631 | } |