Search in sources :

Example 16 with MtpObjectInfo

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);
}
Also used : Intent(android.content.Intent) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 17 with MtpObjectInfo

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;
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 18 with MtpObjectInfo

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));
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 19 with MtpObjectInfo

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));
}
Also used : Cursor(android.database.Cursor) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 20 with MtpObjectInfo

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));
}
Also used : MtpObjectInfo(android.mtp.MtpObjectInfo)

Aggregations

MtpObjectInfo (android.mtp.MtpObjectInfo)53 IOException (java.io.IOException)20 ParcelFileDescriptor (android.os.ParcelFileDescriptor)15 Cursor (android.database.Cursor)10 Intent (android.content.Intent)6 Bitmap (android.graphics.Bitmap)6 MtpDevice (android.mtp.MtpDevice)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)5 Point (android.graphics.Point)5 FileNotFoundException (java.io.FileNotFoundException)5