blob: d6958b324ca3485a18b14f46d334ef8ffa6034b7 [file] [log] [blame]
Mike Lockwood8182e722010-12-30 15:38:45 -05001/*
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
17package android.mtp;
18
Daichi Hirono60fa3612016-04-19 12:50:34 +090019import android.annotation.NonNull;
20import android.annotation.Nullable;
Philip P. Moltmannec3cbb22016-09-14 13:24:52 -070021import android.content.Context;
Mike Lockwoodc4308f02011-03-01 08:04:54 -080022import android.hardware.usb.UsbDevice;
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050023import android.hardware.usb.UsbDeviceConnection;
Daichi Hirono0b494662015-09-10 20:38:15 +090024import android.os.CancellationSignal;
Tomasz Mikolajewski74d4ff82015-08-04 18:34:03 +090025import android.os.ParcelFileDescriptor;
Mike Lockwood8182e722010-12-30 15:38:45 -050026
Philip P. Moltmannec3cbb22016-09-14 13:24:52 -070027import android.os.UserManager;
Philip P. Moltmannb828b772016-09-13 16:35:45 -070028import com.android.internal.annotations.GuardedBy;
Daichi Hirono2dd48252016-01-12 15:46:41 +090029import com.android.internal.util.Preconditions;
Philip P. Moltmannb828b772016-09-13 16:35:45 -070030import dalvik.system.CloseGuard;
Daichi Hirono2dd48252016-01-12 15:46:41 +090031
Daichi Hirono52da3ad2015-12-24 17:52:10 +090032import java.io.IOException;
33
Mike Lockwood8182e722010-12-30 15:38:45 -050034/**
Scott Main0cdd9f72011-05-05 15:53:44 -070035 * This class represents an MTP or PTP device connected on the USB host bus. An application can
36 * instantiate an object of this type, by referencing an attached {@link
37 * android.hardware.usb.UsbDevice} and then use methods in this class to get information about the
38 * device and objects stored on it, as well as open the connection and transfer data.
Mike Lockwood8182e722010-12-30 15:38:45 -050039 */
40public final class MtpDevice {
41
42 private static final String TAG = "MtpDevice";
43
44 private final UsbDevice mDevice;
45
46 static {
47 System.loadLibrary("media_jni");
48 }
49
Philip P. Moltmannb828b772016-09-13 16:35:45 -070050 /** Make sure that MTP device is closed properly */
51 @GuardedBy("mLock")
52 private CloseGuard mCloseGuard = CloseGuard.get();
53
54 /** Current connection to the {@link #mDevice}, or null if device is not connected */
55 @GuardedBy("mLock")
56 private UsbDeviceConnection mConnection;
57
58 private final Object mLock = new Object();
59
Mike Lockwood540380f2011-02-09 21:48:53 -050060 /**
61 * MtpClient constructor
62 *
Mike Lockwoodc4308f02011-03-01 08:04:54 -080063 * @param device the {@link android.hardware.usb.UsbDevice} for the MTP or PTP device
Mike Lockwood540380f2011-02-09 21:48:53 -050064 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +090065 public MtpDevice(@NonNull UsbDevice device) {
66 Preconditions.checkNotNull(device);
Mike Lockwood8182e722010-12-30 15:38:45 -050067 mDevice = device;
68 }
69
Mike Lockwood540380f2011-02-09 21:48:53 -050070 /**
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050071 * Opens the MTP device. Once the device is open it takes ownership of the
Daichi Hirono0b494662015-09-10 20:38:15 +090072 * {@link android.hardware.usb.UsbDeviceConnection}.
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050073 * The connection will be closed when you call {@link #close()}
74 * The connection will also be closed if this method fails.
Mike Lockwood540380f2011-02-09 21:48:53 -050075 *
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050076 * @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
Mike Lockwood540380f2011-02-09 21:48:53 -050077 * @return true if the device was successfully opened.
78 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +090079 public boolean open(@NonNull UsbDeviceConnection connection) {
Philip P. Moltmannec3cbb22016-09-14 13:24:52 -070080 boolean result = false;
81
82 Context context = connection.getContext();
Philip P. Moltmannec3cbb22016-09-14 13:24:52 -070083
Philip P. Moltmannb828b772016-09-13 16:35:45 -070084 synchronized (mLock) {
85 if (context != null) {
86 UserManager userManager = (UserManager) context
87 .getSystemService(Context.USER_SERVICE);
88
89 if (!userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
90 result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
91 }
92 }
93
94 if (!result) {
95 connection.close();
96 } else {
97 mConnection = connection;
98 mCloseGuard.open("close");
Philip P. Moltmannec3cbb22016-09-14 13:24:52 -070099 }
100 }
101
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500102 return result;
Mike Lockwood8182e722010-12-30 15:38:45 -0500103 }
104
Mike Lockwood540380f2011-02-09 21:48:53 -0500105 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400106 * Closes all resources related to the MtpDevice object.
107 * After this is called, the object can not be used until {@link #open} is called again
108 * with a new {@link android.hardware.usb.UsbDeviceConnection}.
Mike Lockwood540380f2011-02-09 21:48:53 -0500109 */
Mike Lockwood8182e722010-12-30 15:38:45 -0500110 public void close() {
Philip P. Moltmannb828b772016-09-13 16:35:45 -0700111 synchronized (mLock) {
112 if (mConnection != null) {
113 mCloseGuard.close();
114
115 native_close();
116
117 mConnection.close();
118 mConnection = null;
119 }
120 }
Mike Lockwood8182e722010-12-30 15:38:45 -0500121 }
122
123 @Override
124 protected void finalize() throws Throwable {
Mike Lockwood8182e722010-12-30 15:38:45 -0500125 try {
Philip P. Moltmannb828b772016-09-13 16:35:45 -0700126 mCloseGuard.warnIfOpen();
127 close();
Mike Lockwood8182e722010-12-30 15:38:45 -0500128 } finally {
129 super.finalize();
130 }
131 }
132
Mike Lockwood540380f2011-02-09 21:48:53 -0500133 /**
134 * Returns the name of the USB device
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400135 * This returns the same value as {@link android.hardware.usb.UsbDevice#getDeviceName}
136 * for the device's {@link android.hardware.usb.UsbDevice}
Mike Lockwood540380f2011-02-09 21:48:53 -0500137 *
138 * @return the device name
139 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900140 public @NonNull String getDeviceName() {
Mike Lockwood8182e722010-12-30 15:38:45 -0500141 return mDevice.getDeviceName();
142 }
143
Mike Lockwood540380f2011-02-09 21:48:53 -0500144 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400145 * Returns the USB ID of the USB device.
146 * This returns the same value as {@link android.hardware.usb.UsbDevice#getDeviceId}
147 * for the device's {@link android.hardware.usb.UsbDevice}
Mike Lockwood540380f2011-02-09 21:48:53 -0500148 *
149 * @return the device ID
150 */
Mike Lockwood8182e722010-12-30 15:38:45 -0500151 public int getDeviceId() {
152 return mDevice.getDeviceId();
153 }
154
155 @Override
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900156 public @NonNull String toString() {
Mike Lockwood8182e722010-12-30 15:38:45 -0500157 return mDevice.getDeviceName();
158 }
159
Mike Lockwood540380f2011-02-09 21:48:53 -0500160 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400161 * Returns the {@link MtpDeviceInfo} for this device
Mike Lockwood540380f2011-02-09 21:48:53 -0500162 *
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900163 * @return the device info, or null if fetching device info fails
Mike Lockwood540380f2011-02-09 21:48:53 -0500164 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900165 public @Nullable MtpDeviceInfo getDeviceInfo() {
Mike Lockwood8182e722010-12-30 15:38:45 -0500166 return native_get_device_info();
167 }
168
Mike Lockwood540380f2011-02-09 21:48:53 -0500169 /**
170 * Returns the list of IDs for all storage units on this device
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400171 * Information about each storage unit can be accessed via {@link #getStorageInfo}.
Mike Lockwood540380f2011-02-09 21:48:53 -0500172 *
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900173 * @return the list of storage IDs, or null if fetching storage IDs fails
Mike Lockwood540380f2011-02-09 21:48:53 -0500174 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900175 public @Nullable int[] getStorageIds() {
Mike Lockwood8182e722010-12-30 15:38:45 -0500176 return native_get_storage_ids();
177 }
178
Mike Lockwood540380f2011-02-09 21:48:53 -0500179 /**
180 * Returns the list of object handles for all objects on the given storage unit,
181 * with the given format and parent.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400182 * Information about each object can be accessed via {@link #getObjectInfo}.
Mike Lockwood540380f2011-02-09 21:48:53 -0500183 *
184 * @param storageId the storage unit to query
185 * @param format the format of the object to return, or zero for all formats
Daichi Hirono660727c2015-06-12 10:45:08 +0900186 * @param objectHandle the parent object to query, -1 for the storage root,
187 * or zero for all objects
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900188 * @return the object handles, or null if fetching object handles fails
Mike Lockwood540380f2011-02-09 21:48:53 -0500189 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900190 public @Nullable int[] getObjectHandles(int storageId, int format, int objectHandle) {
Mike Lockwood8182e722010-12-30 15:38:45 -0500191 return native_get_object_handles(storageId, format, objectHandle);
192 }
193
Mike Lockwood540380f2011-02-09 21:48:53 -0500194 /**
195 * Returns the data for an object as a byte array.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400196 * This call may block for an arbitrary amount of time depending on the size
197 * of the data and speed of the devices.
Mike Lockwood540380f2011-02-09 21:48:53 -0500198 *
199 * @param objectHandle handle of the object to read
200 * @param objectSize the size of the object (this should match
Daichi Hironoe0e66542016-01-15 14:42:53 +0900201 * {@link MtpObjectInfo#getCompressedSize})
Mike Lockwood540380f2011-02-09 21:48:53 -0500202 * @return the object's data, or null if reading fails
203 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900204 public @Nullable byte[] getObject(int objectHandle, int objectSize) {
Daichi Hironoe0e66542016-01-15 14:42:53 +0900205 Preconditions.checkArgumentNonnegative(objectSize, "objectSize should not be negative");
Mike Lockwood8182e722010-12-30 15:38:45 -0500206 return native_get_object(objectHandle, objectSize);
207 }
208
Mike Lockwood540380f2011-02-09 21:48:53 -0500209 /**
Daichi Hirono52da3ad2015-12-24 17:52:10 +0900210 * Obtains object bytes in the specified range and writes it to an array.
211 * This call may block for an arbitrary amount of time depending on the size
212 * of the data and speed of the devices.
213 *
214 * @param objectHandle handle of the object to read
Daichi Hirono2dd48252016-01-12 15:46:41 +0900215 * @param offset Start index of reading range. It must be a non-negative value at most
216 * 0xffffffff.
Daichi Hirono399df702016-04-13 11:07:44 +0900217 * @param size Size of reading range. It must be a non-negative value at most Integer.MAX_VALUE
218 * or 0xffffffff. If 0xffffffff is specified, the method obtains the full bytes of object.
Daichi Hirono52da3ad2015-12-24 17:52:10 +0900219 * @param buffer Array to write data.
220 * @return Size of bytes that are actually read.
221 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900222 public long getPartialObject(int objectHandle, long offset, long size, @NonNull byte[] buffer)
Daichi Hirono52da3ad2015-12-24 17:52:10 +0900223 throws IOException {
224 return native_get_partial_object(objectHandle, offset, size, buffer);
225 }
226
227 /**
Daichi Hirono038832b2016-01-22 19:34:25 +0900228 * Obtains object bytes in the specified range and writes it to an array.
229 * This call may block for an arbitrary amount of time depending on the size
230 * of the data and speed of the devices.
231 *
232 * This is a vender-extended operation supported by Android that enables us to pass
233 * unsigned 64-bit offset. Check if the MTP device supports the operation by using
234 * {@link MtpDeviceInfo#getOperationsSupported()}.
235 *
236 * @param objectHandle handle of the object to read
237 * @param offset Start index of reading range. It must be a non-negative value.
Daichi Hirono399df702016-04-13 11:07:44 +0900238 * @param size Size of reading range. It must be a non-negative value at most Integer.MAX_VALUE.
Daichi Hirono038832b2016-01-22 19:34:25 +0900239 * @param buffer Array to write data.
240 * @return Size of bytes that are actually read.
241 * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT_64
242 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900243 public long getPartialObject64(int objectHandle, long offset, long size, @NonNull byte[] buffer)
Daichi Hirono038832b2016-01-22 19:34:25 +0900244 throws IOException {
245 return native_get_partial_object_64(objectHandle, offset, size, buffer);
246 }
247
248 /**
Mike Lockwood540380f2011-02-09 21:48:53 -0500249 * Returns the thumbnail data for an object as a byte array.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400250 * The size and format of the thumbnail data can be determined via
251 * {@link MtpObjectInfo#getThumbCompressedSize} and
252 * {@link MtpObjectInfo#getThumbFormat}.
253 * For typical devices the format is JPEG.
Mike Lockwood540380f2011-02-09 21:48:53 -0500254 *
255 * @param objectHandle handle of the object to read
256 * @return the object's thumbnail, or null if reading fails
257 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900258 public @Nullable byte[] getThumbnail(int objectHandle) {
Mike Lockwood8182e722010-12-30 15:38:45 -0500259 return native_get_thumbnail(objectHandle);
260 }
261
Mike Lockwood540380f2011-02-09 21:48:53 -0500262 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400263 * Retrieves the {@link MtpStorageInfo} for a storage unit.
Mike Lockwood540380f2011-02-09 21:48:53 -0500264 *
265 * @param storageId the ID of the storage unit
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900266 * @return the MtpStorageInfo, or null if fetching storage info fails
Mike Lockwood540380f2011-02-09 21:48:53 -0500267 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900268 public @Nullable MtpStorageInfo getStorageInfo(int storageId) {
Mike Lockwood8182e722010-12-30 15:38:45 -0500269 return native_get_storage_info(storageId);
270 }
271
Mike Lockwood540380f2011-02-09 21:48:53 -0500272 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400273 * Retrieves the {@link MtpObjectInfo} for an object.
Mike Lockwood540380f2011-02-09 21:48:53 -0500274 *
275 * @param objectHandle the handle of the object
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900276 * @return the MtpObjectInfo, or null if fetching object info fails
Mike Lockwood540380f2011-02-09 21:48:53 -0500277 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900278 public @Nullable MtpObjectInfo getObjectInfo(int objectHandle) {
Mike Lockwood8182e722010-12-30 15:38:45 -0500279 return native_get_object_info(objectHandle);
280 }
281
Mike Lockwood540380f2011-02-09 21:48:53 -0500282 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400283 * Deletes an object on the device. This call may block, since
284 * deleting a directory containing many files may take a long time
285 * on some devices.
Mike Lockwood540380f2011-02-09 21:48:53 -0500286 *
287 * @param objectHandle handle of the object to delete
288 * @return true if the deletion succeeds
289 */
Mike Lockwood8182e722010-12-30 15:38:45 -0500290 public boolean deleteObject(int objectHandle) {
291 return native_delete_object(objectHandle);
292 }
293
Mike Lockwood540380f2011-02-09 21:48:53 -0500294 /**
295 * Retrieves the object handle for the parent of an object on the device.
296 *
297 * @param objectHandle handle of the object to query
298 * @return the parent's handle, or zero if it is in the root of the storage
299 */
Mike Lockwood8182e722010-12-30 15:38:45 -0500300 public long getParent(int objectHandle) {
301 return native_get_parent(objectHandle);
302 }
303
Mike Lockwood540380f2011-02-09 21:48:53 -0500304 /**
305 * Retrieves the ID of the storage unit containing the given object on the device.
306 *
307 * @param objectHandle handle of the object to query
308 * @return the object's storage unit ID
309 */
Mike Lockwood62cfeeb2011-03-11 18:39:03 -0500310 public long getStorageId(int objectHandle) {
Mike Lockwood8182e722010-12-30 15:38:45 -0500311 return native_get_storage_id(objectHandle);
312 }
313
Mike Lockwood540380f2011-02-09 21:48:53 -0500314 /**
315 * Copies the data for an object to a file in external storage.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400316 * This call may block for an arbitrary amount of time depending on the size
317 * of the data and speed of the devices.
Mike Lockwood540380f2011-02-09 21:48:53 -0500318 *
319 * @param objectHandle handle of the object to read
320 * @param destPath path to destination for the file transfer.
321 * This path should be in the external storage as defined by
322 * {@link android.os.Environment#getExternalStorageDirectory}
323 * @return true if the file transfer succeeds
324 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900325 public boolean importFile(int objectHandle, @NonNull String destPath) {
Mike Lockwood8182e722010-12-30 15:38:45 -0500326 return native_import_file(objectHandle, destPath);
327 }
328
Tomasz Mikolajewski74d4ff82015-08-04 18:34:03 +0900329 /**
330 * Copies the data for an object to a file descriptor.
331 * This call may block for an arbitrary amount of time depending on the size
332 * of the data and speed of the devices. The file descriptor is not closed
333 * on completion, and must be done by the caller.
334 *
335 * @param objectHandle handle of the object to read
336 * @param descriptor file descriptor to write the data to for the file transfer.
337 * @return true if the file transfer succeeds
338 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900339 public boolean importFile(int objectHandle, @NonNull ParcelFileDescriptor descriptor) {
Tomasz Mikolajewski74d4ff82015-08-04 18:34:03 +0900340 return native_import_file(objectHandle, descriptor.getFd());
341 }
342
Tomasz Mikolajewskib0499052015-08-06 19:13:09 +0900343 /**
344 * Copies the data for an object from a file descriptor.
345 * This call may block for an arbitrary amount of time depending on the size
346 * of the data and speed of the devices. The file descriptor is not closed
347 * on completion, and must be done by the caller.
348 *
349 * @param objectHandle handle of the target file
Tomasz Mikolajewskib80a3cf2015-08-24 16:10:51 +0900350 * @param size size of the file in bytes
Tomasz Mikolajewskib0499052015-08-06 19:13:09 +0900351 * @param descriptor file descriptor to read the data from.
352 * @return true if the file transfer succeeds
353 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900354 public boolean sendObject(
355 int objectHandle, long size, @NonNull ParcelFileDescriptor descriptor) {
Tomasz Mikolajewskib80a3cf2015-08-24 16:10:51 +0900356 return native_send_object(objectHandle, size, descriptor.getFd());
Tomasz Mikolajewskib0499052015-08-06 19:13:09 +0900357 }
358
359 /**
360 * Uploads an object metadata for a new entry. The {@link MtpObjectInfo} can be
361 * created with the {@link MtpObjectInfo.Builder} class.
362 *
363 * The returned {@link MtpObjectInfo} has the new object handle field filled in.
364 *
365 * @param info metadata of the entry
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900366 * @return object info of the created entry, or null if sending object info fails
Tomasz Mikolajewskib0499052015-08-06 19:13:09 +0900367 */
Daichi Hirono452e8fe2016-07-05 17:29:48 +0900368 public @Nullable MtpObjectInfo sendObjectInfo(@NonNull MtpObjectInfo info) {
Tomasz Mikolajewskib0499052015-08-06 19:13:09 +0900369 return native_send_object_info(info);
370 }
371
Daichi Hirono0b494662015-09-10 20:38:15 +0900372 /**
373 * Reads an event from the device. It blocks the current thread until it gets an event.
374 * It throws OperationCanceledException if it is cancelled by signal.
375 *
376 * @param signal signal for cancellation
377 * @return obtained event
Daichi Hirono60fa3612016-04-19 12:50:34 +0900378 * @throws IOException
Daichi Hirono0b494662015-09-10 20:38:15 +0900379 */
Daichi Hirono60fa3612016-04-19 12:50:34 +0900380 public @NonNull MtpEvent readEvent(@Nullable CancellationSignal signal) throws IOException {
Daichi Hirono0b494662015-09-10 20:38:15 +0900381 final int handle = native_submit_event_request();
Daichi Hirono60fa3612016-04-19 12:50:34 +0900382 Preconditions.checkState(handle >= 0, "Other thread is reading an event.");
Daichi Hirono0b494662015-09-10 20:38:15 +0900383
384 if (signal != null) {
385 signal.setOnCancelListener(new CancellationSignal.OnCancelListener() {
386 @Override
387 public void onCancel() {
388 native_discard_event_request(handle);
389 }
390 });
391 }
392
393 try {
394 return native_reap_event_request(handle);
395 } finally {
396 if (signal != null) {
397 signal.setOnCancelListener(null);
398 }
399 }
400 }
401
Daichi Hirono787821b2016-03-24 21:05:51 +0900402 /**
403 * Returns object size in 64-bit integer.
404 *
Daichi Hirono1337deb2016-03-28 08:53:15 +0900405 * Though MtpObjectInfo#getCompressedSize returns the object size in 32-bit unsigned integer,
406 * this method returns the object size in 64-bit integer from the object property. Thus it can
407 * fetch 4GB+ object size correctly. If the device does not support objectSize property, it
408 * throws IOException.
Daichi Hirono787821b2016-03-24 21:05:51 +0900409 * @hide
410 */
411 public long getObjectSizeLong(int handle, int format) throws IOException {
412 return native_get_object_size_long(handle, format);
413 }
414
Mike Lockwood8182e722010-12-30 15:38:45 -0500415 // used by the JNI code
Ashok Bhate2e59322013-12-17 19:04:19 +0000416 private long mNativeContext;
Mike Lockwood8182e722010-12-30 15:38:45 -0500417
418 private native boolean native_open(String deviceName, int fd);
419 private native void native_close();
420 private native MtpDeviceInfo native_get_device_info();
421 private native int[] native_get_storage_ids();
422 private native MtpStorageInfo native_get_storage_info(int storageId);
423 private native int[] native_get_object_handles(int storageId, int format, int objectHandle);
424 private native MtpObjectInfo native_get_object_info(int objectHandle);
Daichi Hironoe0e66542016-01-15 14:42:53 +0900425 private native byte[] native_get_object(int objectHandle, long objectSize);
Daichi Hirono2dd48252016-01-12 15:46:41 +0900426 private native long native_get_partial_object(
427 int objectHandle, long offset, long objectSize, byte[] buffer) throws IOException;
Daichi Hirono038832b2016-01-22 19:34:25 +0900428 private native int native_get_partial_object_64(
429 int objectHandle, long offset, long objectSize, byte[] buffer) throws IOException;
Mike Lockwood8182e722010-12-30 15:38:45 -0500430 private native byte[] native_get_thumbnail(int objectHandle);
431 private native boolean native_delete_object(int objectHandle);
Daichi Hironoe0e66542016-01-15 14:42:53 +0900432 private native int native_get_parent(int objectHandle);
433 private native int native_get_storage_id(int objectHandle);
Mike Lockwood8182e722010-12-30 15:38:45 -0500434 private native boolean native_import_file(int objectHandle, String destPath);
Tomasz Mikolajewski74d4ff82015-08-04 18:34:03 +0900435 private native boolean native_import_file(int objectHandle, int fd);
Daichi Hironoe0e66542016-01-15 14:42:53 +0900436 private native boolean native_send_object(int objectHandle, long size, int fd);
Tomasz Mikolajewskib0499052015-08-06 19:13:09 +0900437 private native MtpObjectInfo native_send_object_info(MtpObjectInfo info);
Daichi Hirono60fa3612016-04-19 12:50:34 +0900438 private native int native_submit_event_request() throws IOException;
439 private native MtpEvent native_reap_event_request(int handle) throws IOException;
Daichi Hirono0b494662015-09-10 20:38:15 +0900440 private native void native_discard_event_request(int handle);
Daichi Hirono787821b2016-03-24 21:05:51 +0900441 private native long native_get_object_size_long(int handle, int format) throws IOException;
Mike Lockwood8182e722010-12-30 15:38:45 -0500442}