Start to use importFile to file descriptor.
BUG=22908937 Change-Id: Ia4f01099816e7841e364d46c125542d006cd47a6
This commit is contained in:
@@ -35,7 +35,7 @@ class MtpManager {
|
||||
|
||||
private final UsbManager mManager;
|
||||
// TODO: Save and restore the set of opened device.
|
||||
private final SparseArray<MtpDevice> mDevices = new SparseArray<MtpDevice>();
|
||||
private final SparseArray<MtpDevice> mDevices = new SparseArray<>();
|
||||
|
||||
MtpManager(Context context) {
|
||||
mManager = (UsbManager)context.getSystemService(Context.USB_SERVICE);
|
||||
@@ -142,7 +142,8 @@ class MtpManager {
|
||||
|
||||
synchronized void importFile(int deviceId, int objectHandle, ParcelFileDescriptor target)
|
||||
throws IOException {
|
||||
throw new UnsupportedOperationException("Importing files is not supported.");
|
||||
final MtpDevice device = getDevice(deviceId);
|
||||
device.importFile(objectHandle, target);
|
||||
}
|
||||
|
||||
private MtpDevice getDevice(int deviceId) throws IOException {
|
||||
|
||||
@@ -47,12 +47,12 @@ class PipeManager {
|
||||
}
|
||||
|
||||
private static abstract class Task implements Runnable {
|
||||
protected final MtpManager mModel;
|
||||
protected final MtpManager mManager;
|
||||
protected final Identifier mIdentifier;
|
||||
protected final ParcelFileDescriptor[] mDescriptors;
|
||||
|
||||
Task(MtpManager model, Identifier identifier) throws IOException {
|
||||
mModel = model;
|
||||
Task(MtpManager manager, Identifier identifier) throws IOException {
|
||||
mManager = manager;
|
||||
mIdentifier = identifier;
|
||||
mDescriptors = ParcelFileDescriptor.createReliablePipe();
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class PipeManager {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mModel.importFile(
|
||||
mManager.importFile(
|
||||
mIdentifier.mDeviceId, mIdentifier.mObjectHandle, mDescriptors[1]);
|
||||
mDescriptors[1].close();
|
||||
} catch (IOException error) {
|
||||
@@ -94,7 +94,7 @@ class PipeManager {
|
||||
try (final ParcelFileDescriptor.AutoCloseOutputStream stream =
|
||||
new ParcelFileDescriptor.AutoCloseOutputStream(mDescriptors[1])) {
|
||||
try {
|
||||
stream.write(mModel.getThumbnail(
|
||||
stream.write(mManager.getThumbnail(
|
||||
mIdentifier.mDeviceId, mIdentifier.mObjectHandle));
|
||||
} catch (IOException error) {
|
||||
mDescriptors[1].closeWithError("Failed to stream a thumbnail.");
|
||||
|
||||
Reference in New Issue
Block a user