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;
}
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);
}
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);
}
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;
}
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));
}
}
}
Aggregations