use of android.mtp.MtpDevice in project android_frameworks_base by AOSPA.
the class MtpClient method getStorageList.
/**
* Retrieves a list of all {@link android.mtp.MtpStorageInfo}
* for the MTP or PTP device with the given USB device name
*
* @param deviceName the name of the USB device
* @return the list of MtpStorageInfo
*/
public List<MtpStorageInfo> getStorageList(String deviceName) {
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
int[] storageIds = device.getStorageIds();
if (storageIds == null) {
return null;
}
int length = storageIds.length;
ArrayList<MtpStorageInfo> storageList = new ArrayList<MtpStorageInfo>(length);
for (int i = 0; i < length; i++) {
MtpStorageInfo info = device.getStorageInfo(storageIds[i]);
if (info == null) {
Log.w(TAG, "getStorageInfo failed");
} else {
storageList.add(info);
}
}
return storageList;
}
use of android.mtp.MtpDevice in project android_frameworks_base by AOSPA.
the class MtpManager method createDeviceRecord.
private MtpDeviceRecord createDeviceRecord(UsbDevice device) {
final MtpDevice mtpDevice = mDevices.get(device.getDeviceId());
final boolean opened = mtpDevice != null;
final String name = device.getProductName();
MtpRoot[] roots;
int[] operationsSupported = null;
int[] eventsSupported = null;
if (opened) {
try {
roots = getRoots(device.getDeviceId());
} catch (IOException exp) {
Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exp);
// If we failed to fetch roots for the device, we still returns device model
// with an empty set of roots so that the device is shown DocumentsUI as long as
// the device is physically connected.
roots = new MtpRoot[0];
}
final MtpDeviceInfo info = mtpDevice.getDeviceInfo();
if (info != null) {
operationsSupported = info.getOperationsSupported();
eventsSupported = info.getEventsSupported();
}
} else {
roots = new MtpRoot[0];
}
return new MtpDeviceRecord(device.getDeviceId(), name, device.getSerialNumber(), opened, roots, operationsSupported, eventsSupported);
}
use of android.mtp.MtpDevice in project android_frameworks_base by ResurrectionRemix.
the class MtpManager method openDevice.
synchronized MtpDeviceRecord openDevice(int deviceId) throws IOException {
UsbDevice rawDevice = null;
for (final UsbDevice candidate : mManager.getDeviceList().values()) {
if (candidate.getDeviceId() == deviceId) {
rawDevice = candidate;
break;
}
}
ensureNotNull(rawDevice, "Not found USB device: " + deviceId);
if (!mManager.hasPermission(rawDevice)) {
mManager.grantPermission(rawDevice);
if (!mManager.hasPermission(rawDevice)) {
throw new IOException("Failed to grant a device permission.");
}
}
final MtpDevice device = new MtpDevice(rawDevice);
final UsbDeviceConnection connection = ensureNotNull(mManager.openDevice(rawDevice), "Failed to open a USB connection.");
if (!device.open(connection)) {
// We cannot open connection when another application use the device.
throw new BusyDeviceException();
}
// Handle devices that fail to obtain storages just after opening a MTP session.
final int[] storageIds = ensureNotNull(device.getStorageIds(), "Not found MTP storages in the device.");
mDevices.put(deviceId, device);
return createDeviceRecord(rawDevice);
}
use of android.mtp.MtpDevice in project android_frameworks_base by ResurrectionRemix.
the class MtpManager method createDeviceRecord.
private MtpDeviceRecord createDeviceRecord(UsbDevice device) {
final MtpDevice mtpDevice = mDevices.get(device.getDeviceId());
final boolean opened = mtpDevice != null;
final String name = device.getProductName();
MtpRoot[] roots;
int[] operationsSupported = null;
int[] eventsSupported = null;
if (opened) {
try {
roots = getRoots(device.getDeviceId());
} catch (IOException exp) {
Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exp);
// If we failed to fetch roots for the device, we still returns device model
// with an empty set of roots so that the device is shown DocumentsUI as long as
// the device is physically connected.
roots = new MtpRoot[0];
}
final MtpDeviceInfo info = mtpDevice.getDeviceInfo();
if (info != null) {
operationsSupported = info.getOperationsSupported();
eventsSupported = info.getEventsSupported();
}
} else {
roots = new MtpRoot[0];
}
return new MtpDeviceRecord(device.getDeviceId(), name, device.getSerialNumber(), opened, roots, operationsSupported, eventsSupported);
}
use of android.mtp.MtpDevice in project android_frameworks_base by DirtyUnicorns.
the class MtpManager method createDeviceRecord.
private MtpDeviceRecord createDeviceRecord(UsbDevice device) {
final MtpDevice mtpDevice = mDevices.get(device.getDeviceId());
final boolean opened = mtpDevice != null;
final String name = device.getProductName();
MtpRoot[] roots;
int[] operationsSupported = null;
int[] eventsSupported = null;
if (opened) {
try {
roots = getRoots(device.getDeviceId());
} catch (IOException exp) {
Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exp);
// If we failed to fetch roots for the device, we still returns device model
// with an empty set of roots so that the device is shown DocumentsUI as long as
// the device is physically connected.
roots = new MtpRoot[0];
}
final MtpDeviceInfo info = mtpDevice.getDeviceInfo();
if (info != null) {
operationsSupported = info.getOperationsSupported();
eventsSupported = info.getEventsSupported();
}
} else {
roots = new MtpRoot[0];
}
return new MtpDeviceRecord(device.getDeviceId(), name, device.getSerialNumber(), opened, roots, operationsSupported, eventsSupported);
}
Aggregations