use of android.mtp.MtpObjectInfo in project android_frameworks_base by DirtyUnicorns.
the class ObjectBrowser method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
MtpObjectInfo info = mObjectList.get(position);
Intent intent;
if (info.getFormat() == MtpConstants.FORMAT_ASSOCIATION) {
intent = new Intent(this, ObjectBrowser.class);
} else {
intent = new Intent(this, ObjectViewer.class);
}
intent.putExtra("device", mDeviceName);
intent.putExtra("storage", mStorageID);
intent.putExtra("object", info.getObjectHandle());
startActivity(intent);
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by DirtyUnicorns.
the class TestMtpManager method createDocument.
@Override
int createDocument(int deviceId, MtpObjectInfo objectInfo, ParcelFileDescriptor source) throws IOException {
Assert.assertNotSame(0, objectInfo.getStorageId());
Assert.assertNotSame(-1, objectInfo.getStorageId());
Assert.assertNotSame(0, objectInfo.getParent());
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;
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by DirtyUnicorns.
the class MtpDocumentsProviderTest method testOpenDocument_shortBytes.
public void testOpenDocument_shortBytes() throws Exception {
mMtpManager = new TestMtpManager(getContext()) {
@Override
MtpObjectInfo getObjectInfo(int deviceId, int objectHandle) throws IOException {
if (objectHandle == 1) {
return new MtpObjectInfo.Builder(super.getObjectInfo(deviceId, objectHandle)).setObjectHandle(1).setCompressedSize(1024 * 1024).build();
}
return super.getObjectInfo(deviceId, objectHandle);
}
};
setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY);
setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 0, 0, "") });
final byte[] bytes = "Hello world".getBytes();
setupDocuments(0, 0, MtpManager.OBJECT_HANDLE_ROOT_CHILDREN, "1", new MtpObjectInfo[] { new MtpObjectInfo.Builder().setName("test.txt").setObjectHandle(1).setCompressedSize(bytes.length).setParent(-1).build() });
mMtpManager.setImportFileBytes(0, 1, bytes);
try (final ParcelFileDescriptor fd = mProvider.openDocument("3", "r", null)) {
final byte[] readBytes = new byte[1024 * 1024];
assertEquals(11, Os.read(fd.getFileDescriptor(), readBytes, 0, readBytes.length));
}
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by DirtyUnicorns.
the class MtpDocumentsProviderTest method testQueryDocument_directory.
public void testQueryDocument_directory() throws IOException, InterruptedException, TimeoutException {
setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY);
setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 1000, 1000, "") });
setupDocuments(0, 0, MtpManager.OBJECT_HANDLE_ROOT_CHILDREN, "1", new MtpObjectInfo[] { new MtpObjectInfo.Builder().setObjectHandle(2).setStorageId(1).setFormat(MtpConstants.FORMAT_ASSOCIATION).setName("directory").setDateModified(1422716400000L).build() });
final Cursor cursor = mProvider.queryDocument("3", null);
assertEquals(1, cursor.getCount());
cursor.moveToNext();
assertEquals("3", cursor.getString(0));
assertEquals(DocumentsContract.Document.MIME_TYPE_DIR, cursor.getString(1));
assertEquals("directory", cursor.getString(2));
assertEquals(1422716400000L, cursor.getLong(3));
assertEquals(DocumentsContract.Document.FLAG_SUPPORTS_DELETE | DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE, cursor.getInt(4));
assertEquals(0, cursor.getInt(5));
}
use of android.mtp.MtpObjectInfo in project android_frameworks_base by DirtyUnicorns.
the class MtpDocumentsProviderTest method setupDocuments.
private String[] setupDocuments(int deviceId, int storageId, int parentHandle, String parentDocumentId, MtpObjectInfo[] objects) throws FileNotFoundException {
final int[] handles = new int[objects.length];
int i = 0;
for (final MtpObjectInfo info : objects) {
handles[i] = info.getObjectHandle();
mMtpManager.setObjectInfo(deviceId, info);
}
mMtpManager.setObjectHandles(deviceId, storageId, parentHandle, handles);
return getStrings(mProvider.queryChildDocuments(parentDocumentId, strings(DocumentsContract.Document.COLUMN_DOCUMENT_ID), null));
}
Aggregations