UsbDevice: Move IO related methods to new UsbDeviceConnection class

UsbDevice is now just an immutable parcelable object like UsbInterface and
UsbEndpoint.
All IO related functionality is now contained in UsbDeviceConnection
and UsbRequest.

Bug: 4067029

Change-Id: Ia84da0b512a697acc940eee0c3566711c62e1a68
Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Mike Lockwood
2011-03-11 08:18:08 -05:00
parent 364903bac6
commit acc29cc91b
14 changed files with 604 additions and 592 deletions

View File

@@ -17,7 +17,7 @@
package android.mtp;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbDeviceConnection;
import android.os.ParcelFileDescriptor;
import android.util.Log;
@@ -44,17 +44,20 @@ public final class MtpDevice {
}
/**
* Opens the MTP or PTP device and return an {@link android.mtp.MtpDevice} for it.
* Opens the MTP device. Once the device is open it takes ownership of the
* {@link android.hardware.usb.UsbDeviceConnection}.
* The connection will be closed when you call {@link #close()}
* The connection will also be closed if this method fails.
*
* @param manager reference to {@link android.hardware.usb.UsbManager}
* @param connection an open {@link android.hardware.usb.UsbDeviceConnection} for the device
* @return true if the device was successfully opened.
*/
public boolean open(UsbManager manager) {
if (manager.openDevice(mDevice)) {
return native_open(mDevice.getDeviceName(), mDevice.getFileDescriptor());
} else {
return false;
public boolean open(UsbDeviceConnection connection) {
boolean result = native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
if (!result) {
connection.close();
}
return result;
}
/**