use of android.mtp.MtpObjectInfo in project android_frameworks_base by ParanoidAndroid.
the class MtpClient method getObjectList.
/**
* Retrieves a list of {@link android.mtp.MtpObjectInfo} for all objects
* on the MTP or PTP device with the given USB device name and given storage ID
* and/or object handle.
* If the object handle is zero, then all objects in the root of the storage unit
* will be returned. Otherwise, all immediate children of the object will be returned.
* If the storage ID is also zero, then all objects on all storage units will be returned.
*
* @param deviceName the name of the USB device
* @param storageId the ID of the storage unit to query, or zero for all
* @param objectHandle the handle of the parent object to query, or zero for the storage root
* @return the list of MtpObjectInfo
*/
public List<MtpObjectInfo> getObjectList(String deviceName, int storageId, int objectHandle) {
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
if (objectHandle == 0) {
// all objects in root of storage
objectHandle = 0xFFFFFFFF;
}
int[] handles = device.getObjectHandles(storageId, 0, objectHandle);
if (handles == null) {
return null;
}
int length = handles.length;
ArrayList<MtpObjectInfo> objectList = new ArrayList<MtpObjectInfo>(length);
for (int i = 0; i < length; i++) {
MtpObjectInfo info = device.getObjectInfo(handles[i]);
if (info == null) {
Log.w(TAG, "getObjectInfo failed");
} else {
objectList.add(info);
}
}
return objectList;
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by ParanoidAndroid.
the class ObjectViewer method onResume.
@Override
protected void onResume() {
super.onResume();
MtpObjectInfo info = mClient.getObjectInfo(mDeviceName, mObjectID);
if (info != null) {
TextView view = (TextView) findViewById(R.id.name);
mFileName = info.getName();
view.setText(mFileName);
view = (TextView) findViewById(R.id.format);
view.setText(Integer.toHexString(info.getFormat()).toUpperCase());
view = (TextView) findViewById(R.id.size);
view.setText(Long.toString(info.getCompressedSize()));
view = (TextView) findViewById(R.id.thumb_width);
view.setText(Long.toString(info.getThumbPixWidth()));
view = (TextView) findViewById(R.id.thumb_height);
view.setText(Long.toString(info.getThumbPixHeight()));
view = (TextView) findViewById(R.id.thumb_size);
view.setText(Long.toString(info.getThumbCompressedSize()));
view = (TextView) findViewById(R.id.width);
view.setText(Long.toString(info.getImagePixWidth()));
view = (TextView) findViewById(R.id.height);
view.setText(Long.toString(info.getImagePixHeight()));
view = (TextView) findViewById(R.id.depth);
view.setText(Long.toString(info.getImagePixDepth()));
view = (TextView) findViewById(R.id.sequence);
view.setText(Long.toString(info.getSequenceNumber()));
view = (TextView) findViewById(R.id.created);
Date date = new Date(info.getDateCreated() * 1000);
view.setText(date.toString());
view = (TextView) findViewById(R.id.modified);
date = new Date(info.getDateModified() * 1000);
view.setText(date.toString());
view = (TextView) findViewById(R.id.keywords);
view.setText(info.getKeywords());
int thumbFormat = info.getThumbFormat();
if (thumbFormat == MtpConstants.FORMAT_EXIF_JPEG || thumbFormat == MtpConstants.FORMAT_JFIF) {
byte[] thumbnail = mClient.getThumbnail(mDeviceName, info.getObjectHandle());
if (thumbnail != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length);
if (bitmap != null) {
ImageView thumbView = (ImageView) findViewById(R.id.thumbnail);
thumbView.setImageBitmap(bitmap);
}
}
}
}
}
use of android.mtp.MtpObjectInfo in project platform_frameworks_base by android.
the class ObjectViewer method onResume.
@Override
protected void onResume() {
super.onResume();
MtpObjectInfo info = mClient.getObjectInfo(mDeviceName, mObjectID);
if (info != null) {
TextView view = (TextView) findViewById(R.id.name);
mFileName = info.getName();
view.setText(mFileName);
view = (TextView) findViewById(R.id.format);
view.setText(Integer.toHexString(info.getFormat()).toUpperCase(Locale.ROOT));
view = (TextView) findViewById(R.id.size);
view.setText(Long.toString(info.getCompressedSize()));
view = (TextView) findViewById(R.id.thumb_width);
view.setText(Long.toString(info.getThumbPixWidth()));
view = (TextView) findViewById(R.id.thumb_height);
view.setText(Long.toString(info.getThumbPixHeight()));
view = (TextView) findViewById(R.id.thumb_size);
view.setText(Long.toString(info.getThumbCompressedSize()));
view = (TextView) findViewById(R.id.width);
view.setText(Long.toString(info.getImagePixWidth()));
view = (TextView) findViewById(R.id.height);
view.setText(Long.toString(info.getImagePixHeight()));
view = (TextView) findViewById(R.id.depth);
view.setText(Long.toString(info.getImagePixDepth()));
view = (TextView) findViewById(R.id.sequence);
view.setText(Long.toString(info.getSequenceNumber()));
view = (TextView) findViewById(R.id.created);
Date date = new Date(info.getDateCreated() * 1000);
view.setText(date.toString());
view = (TextView) findViewById(R.id.modified);
date = new Date(info.getDateModified() * 1000);
view.setText(date.toString());
view = (TextView) findViewById(R.id.keywords);
view.setText(info.getKeywords());
int thumbFormat = info.getThumbFormat();
if (thumbFormat == MtpConstants.FORMAT_EXIF_JPEG || thumbFormat == MtpConstants.FORMAT_JFIF) {
byte[] thumbnail = mClient.getThumbnail(mDeviceName, info.getObjectHandle());
if (thumbnail != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length);
if (bitmap != null) {
ImageView thumbView = (ImageView) findViewById(R.id.thumbnail);
thumbView.setImageBitmap(bitmap);
}
}
}
}
}
use of android.mtp.MtpObjectInfo in project platform_frameworks_base by android.
the class MtpFileWriter method flush.
void flush(MtpManager manager, MtpDatabase database, int[] operationsSupported) throws IOException, ErrnoException {
// Skip unnecessary flush.
if (!mDirty) {
return;
}
// Get the placeholder object info.
final Identifier identifier = database.createIdentifier(mDocumentId);
final MtpObjectInfo placeholderObjectInfo = manager.getObjectInfo(identifier.mDeviceId, identifier.mObjectHandle);
// Delete the target object info if it already exists (as a placeholder).
manager.deleteDocument(identifier.mDeviceId, identifier.mObjectHandle);
// Create the target object info with a correct file size and upload the file.
final long size = Os.lseek(mCacheFd.getFileDescriptor(), 0, OsConstants.SEEK_END);
final MtpObjectInfo targetObjectInfo = new MtpObjectInfo.Builder(placeholderObjectInfo).setCompressedSize(size).build();
Os.lseek(mCacheFd.getFileDescriptor(), 0, OsConstants.SEEK_SET);
final int newObjectHandle = manager.createDocument(identifier.mDeviceId, targetObjectInfo, mCacheFd);
final MtpObjectInfo newObjectInfo = manager.getObjectInfo(identifier.mDeviceId, newObjectHandle);
final Identifier parentIdentifier = database.getParentIdentifier(identifier.mDocumentId);
database.updateObject(identifier.mDocumentId, identifier.mDeviceId, parentIdentifier.mDocumentId, operationsSupported, newObjectInfo, size);
mDirty = false;
}
use of android.mtp.MtpObjectInfo in project platform_frameworks_base by android.
the class TestMtpManager method createDocument.
@Override
int createDocument(int deviceId, MtpObjectInfo objectInfo, ParcelFileDescriptor source) throws IOException {
final String key = pack(deviceId, CREATED_DOCUMENT_HANDLE);
if (mObjectInfos.containsKey(key)) {
throw new IOException();
}
final MtpObjectInfo newInfo = new MtpObjectInfo.Builder(objectInfo).setObjectHandle(CREATED_DOCUMENT_HANDLE).build();
mObjectInfos.put(key, newInfo);
if (objectInfo.getFormat() != 0x3001) {
try (final ParcelFileDescriptor.AutoCloseInputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(source)) {
final byte[] buffer = new byte[objectInfo.getCompressedSize()];
if (inputStream.read(buffer, 0, objectInfo.getCompressedSize()) != objectInfo.getCompressedSize()) {
throw new IOException();
}
mImportFileBytes.put(pack(deviceId, CREATED_DOCUMENT_HANDLE), buffer);
}
}
return CREATED_DOCUMENT_HANDLE;
}
Aggregations