18182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood/*
28182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * Copyright (C) 2010 The Android Open Source Project
38182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood *
48182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * Licensed under the Apache License, Version 2.0 (the "License");
58182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * you may not use this file except in compliance with the License.
68182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * You may obtain a copy of the License at
78182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood *
88182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood *      http://www.apache.org/licenses/LICENSE-2.0
98182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood *
108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * Unless required by applicable law or agreed to in writing, software
118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * distributed under the License is distributed on an "AS IS" BASIS,
128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * See the License for the specific language governing permissions and
148182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood * limitations under the License.
158182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood */
168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodpackage android.mtp;
188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
19c4308f01c965571dc2354107c3574df113e397eeMike Lockwoodimport android.hardware.usb.UsbDevice;
20acc29cc91be634070c92a807df412ced97b9b375Mike Lockwoodimport android.hardware.usb.UsbDeviceConnection;
218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodimport android.os.ParcelFileDescriptor;
228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodimport android.util.Log;
238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
248182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood/**
250cdd9f7def708a71a0d0722361f52c0416370dc6Scott Main * This class represents an MTP or PTP device connected on the USB host bus. An application can
260cdd9f7def708a71a0d0722361f52c0416370dc6Scott Main * instantiate an object of this type, by referencing an attached {@link
270cdd9f7def708a71a0d0722361f52c0416370dc6Scott Main * android.hardware.usb.UsbDevice} and then use methods in this class to get information about the
280cdd9f7def708a71a0d0722361f52c0416370dc6Scott Main * device and objects stored on it, as well as open the connection and transfer data.
298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood */
308182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwoodpublic final class MtpDevice {
318182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
328182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private static final String TAG = "MtpDevice";
338182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
348182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private final UsbDevice mDevice;
358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    static {
378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        System.loadLibrary("media_jni");
388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
40540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
41540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * MtpClient constructor
42540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
43c4308f01c965571dc2354107c3574df113e397eeMike Lockwood     * @param device the {@link android.hardware.usb.UsbDevice} for the MTP or PTP device
44540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public MtpDevice(UsbDevice device) {
468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        mDevice = device;
478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
49540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
50acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood     * Opens the MTP device.  Once the device is open it takes ownership of the
51acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood     * {@link android.hardware.usb.UsbDeviceConnection}.
52acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood     * The connection will be closed when you call {@link #close()}
53acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood     * The connection will also be closed if this method fails.
54540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
55acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood     * @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
56540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return true if the device was successfully opened.
57540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
58acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood    public boolean open(UsbDeviceConnection connection) {
59acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood        boolean result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
60acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood        if (!result) {
61acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood            connection.close();
628182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        }
63acc29cc91be634070c92a807df412ced97b9b375Mike Lockwood        return result;
648182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
658182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
66540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
6711dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Closes all resources related to the MtpDevice object.
6811dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * After this is called, the object can not be used until {@link #open} is called again
6911dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * with a new {@link android.hardware.usb.UsbDeviceConnection}.
70540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public void close() {
728182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        native_close();
738182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
748182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
758182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    @Override
768182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    protected void finalize() throws Throwable {
778182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        try {
788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            native_close();
798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        } finally {
808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood            super.finalize();
818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        }
828182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
838182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
84540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
85540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Returns the name of the USB device
8611dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * This returns the same value as {@link android.hardware.usb.UsbDevice#getDeviceName}
8711dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * for the device's {@link android.hardware.usb.UsbDevice}
88540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
89540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the device name
90540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public String getDeviceName() {
928182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return mDevice.getDeviceName();
938182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
948182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
95540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
9611dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Returns the USB ID of the USB device.
9711dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * This returns the same value as {@link android.hardware.usb.UsbDevice#getDeviceId}
9811dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * for the device's {@link android.hardware.usb.UsbDevice}
99540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
100540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the device ID
101540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public int getDeviceId() {
1038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return mDevice.getDeviceId();
1048182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1058182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
1068182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    @Override
1078182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public String toString() {
1088182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return mDevice.getDeviceName();
1098182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
111540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
11211dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Returns the {@link MtpDeviceInfo} for this device
113540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
114540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the device info
115540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1168182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public MtpDeviceInfo getDeviceInfo() {
1178182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_device_info();
1188182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1198182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
120540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
121540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Returns the list of IDs for all storage units on this device
12211dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Information about each storage unit can be accessed via {@link #getStorageInfo}.
123540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
12411dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * @return the list of storage IDs
125540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1268182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public int[] getStorageIds() {
1278182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_storage_ids();
1288182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1298182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
130540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
131540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Returns the list of object handles for all objects on the given storage unit,
132540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * with the given format and parent.
13311dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Information about each object can be accessed via {@link #getObjectInfo}.
134540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
135540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param storageId the storage unit to query
136540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param format the format of the object to return, or zero for all formats
137540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle the parent object to query, or zero for the storage root
138540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the object handles
139540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public int[] getObjectHandles(int storageId, int format, int objectHandle) {
1418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_object_handles(storageId, format, objectHandle);
1428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
144540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
145540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Returns the data for an object as a byte array.
14611dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * This call may block for an arbitrary amount of time depending on the size
14711dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * of the data and speed of the devices.
148540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
149540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle handle of the object to read
150540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectSize the size of the object (this should match
15111dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     *      {@link MtpObjectInfo#getCompressedSize}
152540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the object's data, or null if reading fails
153540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public byte[] getObject(int objectHandle, int objectSize) {
1558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_object(objectHandle, objectSize);
1568182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1578182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
158540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
159540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Returns the thumbnail data for an object as a byte array.
16011dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * The size and format of the thumbnail data can be determined via
16111dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * {@link MtpObjectInfo#getThumbCompressedSize} and
16211dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * {@link MtpObjectInfo#getThumbFormat}.
16311dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * For typical devices the format is JPEG.
164540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
165540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle handle of the object to read
166540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the object's thumbnail, or null if reading fails
167540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1688182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public byte[] getThumbnail(int objectHandle) {
1698182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_thumbnail(objectHandle);
1708182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1718182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
172540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
17311dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Retrieves the {@link MtpStorageInfo} for a storage unit.
174540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
175540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param storageId the ID of the storage unit
176540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the MtpStorageInfo
177540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1788182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public MtpStorageInfo getStorageInfo(int storageId) {
1798182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_storage_info(storageId);
1808182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1818182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
182540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
18311dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Retrieves the {@link MtpObjectInfo} for an object.
184540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
185540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle the handle of the object
186540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the MtpObjectInfo
187540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
1888182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public MtpObjectInfo getObjectInfo(int objectHandle) {
1898182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_object_info(objectHandle);
1908182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
1918182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
192540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
19311dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * Deletes an object on the device.  This call may block, since
19411dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * deleting a directory containing many files may take a long time
19511dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * on some devices.
196540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
197540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle handle of the object to delete
198540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return true if the deletion succeeds
199540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
2008182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public boolean deleteObject(int objectHandle) {
2018182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_delete_object(objectHandle);
2028182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2038182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
204540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
205540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Retrieves the object handle for the parent of an object on the device.
206540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
207540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle handle of the object to query
208540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the parent's handle, or zero if it is in the root of the storage
209540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
2108182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public long getParent(int objectHandle) {
2118182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_parent(objectHandle);
2128182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2138182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
214540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
215540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Retrieves the ID of the storage unit containing the given object on the device.
216540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
217540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle handle of the object to query
218540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return the object's storage unit ID
219540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
22062cfeeb821afb2f3d3b78ad93caa13408cd26eacMike Lockwood    public long getStorageId(int objectHandle) {
2218182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_get_storage_id(objectHandle);
2228182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2238182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
224540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood    /**
225540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * Copies the data for an object to a file in external storage.
22611dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * This call may block for an arbitrary amount of time depending on the size
22711dd5ae97b1cd5889bb66862fd12718da62a9c75Mike Lockwood     * of the data and speed of the devices.
228540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *
229540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param objectHandle handle of the object to read
230540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @param destPath path to destination for the file transfer.
231540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *      This path should be in the external storage as defined by
232540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     *      {@link android.os.Environment#getExternalStorageDirectory}
233540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     * @return true if the file transfer succeeds
234540380fb0a45b12af3970f9ea1ed041607451f46Mike Lockwood     */
2358182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    public boolean importFile(int objectHandle, String destPath) {
2368182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood        return native_import_file(objectHandle, destPath);
2378182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    }
2388182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2398182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    // used by the JNI code
2408182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private int mNativeContext;
2418182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood
2428182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native boolean native_open(String deviceName, int fd);
2438182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native void native_close();
2448182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native MtpDeviceInfo native_get_device_info();
2458182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native int[] native_get_storage_ids();
2468182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native MtpStorageInfo native_get_storage_info(int storageId);
2478182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native int[] native_get_object_handles(int storageId, int format, int objectHandle);
2488182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native MtpObjectInfo native_get_object_info(int objectHandle);
2498182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native byte[] native_get_object(int objectHandle, int objectSize);
2508182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native byte[] native_get_thumbnail(int objectHandle);
2518182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native boolean native_delete_object(int objectHandle);
2528182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native long native_get_parent(int objectHandle);
2538182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native long native_get_storage_id(int objectHandle);
2548182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood    private native boolean native_import_file(int objectHandle, String destPath);
2558182e72479a8b0d832df9c392890b25bfa6f97b5Mike Lockwood}
256