Search in sources :

Example 31 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class SoundPool method load.

/**
     * Load the sound from the specified path.
     *
     * @param path the path to the audio file
     * @param priority the priority of the sound. Currently has no effect. Use
     *                 a value of 1 for future compatibility.
     * @return a sound ID. This value can be used to play or unload the sound.
     */
public int load(String path, int priority) {
    int id = 0;
    try {
        File f = new File(path);
        ParcelFileDescriptor fd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
        if (fd != null) {
            id = _load(fd.getFileDescriptor(), 0, f.length(), priority);
            fd.close();
        }
    } catch (java.io.IOException e) {
        Log.e(TAG, "error loading " + path);
    }
    return id;
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File)

Example 32 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class PipeManagerTest method testReadThumbnail_basic.

public void testReadThumbnail_basic() throws Exception {
    mtpManager.setThumbnail(0, 1, HELLO_BYTES);
    final ParcelFileDescriptor descriptor = mPipeManager.readThumbnail(mtpManager, new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
    assertDescriptor(descriptor, HELLO_BYTES);
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 33 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class PipeManagerTest method testReadThumbnail_error.

public void testReadThumbnail_error() throws Exception {
    final ParcelFileDescriptor descriptor = mPipeManager.readThumbnail(mtpManager, new Identifier(0, 0, 1, null, MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT));
    assertDescriptorError(descriptor);
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 34 with ParcelFileDescriptor

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

Example 35 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class MtpDocumentsProviderTest method testOpenDocument_writing.

public void testOpenDocument_writing() throws Exception {
    setupProvider(MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY);
    setupRoots(0, new MtpRoot[] { new MtpRoot(0, 0, "Storage", 0, 0, "") });
    final String documentId = mProvider.createDocument("2", "text/plain", "test.txt");
    {
        final ParcelFileDescriptor fd = mProvider.openDocument(documentId, "w", null);
        try (ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd)) {
            stream.write("Hello".getBytes());
        }
    }
    {
        final ParcelFileDescriptor fd = mProvider.openDocument(documentId, "r", null);
        try (ParcelFileDescriptor.AutoCloseInputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(fd)) {
            final byte[] bytes = new byte[5];
            stream.read(bytes);
            assertTrue(Arrays.equals("Hello".getBytes(), bytes));
        }
    }
}
Also used : AutoCloseOutputStream(android.os.ParcelFileDescriptor.AutoCloseOutputStream) AutoCloseOutputStream(android.os.ParcelFileDescriptor.AutoCloseOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Aggregations

ParcelFileDescriptor (android.os.ParcelFileDescriptor)526 IOException (java.io.IOException)199 FileNotFoundException (java.io.FileNotFoundException)136 RemoteException (android.os.RemoteException)127 File (java.io.File)127 FileDescriptor (java.io.FileDescriptor)58 FileOutputStream (java.io.FileOutputStream)58 AssetFileDescriptor (android.content.res.AssetFileDescriptor)44 FileInputStream (java.io.FileInputStream)36 Parcel (android.os.Parcel)35 Uri (android.net.Uri)33 Intent (android.content.Intent)30 Bundle (android.os.Bundle)29 Cursor (android.database.Cursor)27 StorageManager (android.os.storage.StorageManager)25 Request (android.app.DownloadManager.Request)24 Bitmap (android.graphics.Bitmap)22 InputStream (java.io.InputStream)18 ProfilerInfo (android.app.ProfilerInfo)17 Binder (android.os.Binder)17