use of android.mtp.MtpObjectInfo in project android_frameworks_base by AOSPA.
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 AOSPA.
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 crdroidandroid.
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 android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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));
}
Aggregations