Search in sources :

Example 96 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by AOSPA.

the class AppFuseTest method testWriteFile_writeError.

public void testWriteFile_writeError() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

        @Override
        public long getFileSize(int inode) throws FileNotFoundException {
            if (inode != INODE) {
                throw new FileNotFoundException();
            }
            return 5;
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(INODE, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE);
    try (final ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd)) {
        stream.write('a');
        fail();
    } catch (IOException e) {
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 97 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by AOSPA.

the class AppFuseTest method testOpenFile.

public void testOpenFile() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

        @Override
        public long getFileSize(int inode) throws FileNotFoundException {
            if (INODE == inode) {
                return 1024;
            }
            throw new FileNotFoundException();
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(INODE, ParcelFileDescriptor.MODE_READ_ONLY);
    fd.close();
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 98 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by AOSPA.

the class AppFuseTest method testReadFile.

public void testReadFile() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int fileInode = 10;
    final byte[] fileBytes = new byte[] { 'a', 'b', 'c', 'd', 'e' };
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

        @Override
        public long getFileSize(int inode) throws FileNotFoundException {
            if (inode == fileInode) {
                return fileBytes.length;
            }
            return super.getFileSize(inode);
        }

        @Override
        public long readObjectBytes(int inode, long offset, long size, byte[] bytes) throws IOException {
            if (inode == fileInode) {
                int i = 0;
                while (i < size && i + offset < fileBytes.length) {
                    bytes[i] = fileBytes[(int) (i + offset)];
                    i++;
                }
                return i;
            }
            return super.readObjectBytes(inode, offset, size, bytes);
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(fileInode, ParcelFileDescriptor.MODE_READ_ONLY);
    try (final ParcelFileDescriptor.AutoCloseInputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(fd)) {
        final byte[] buffer = new byte[1024];
        final int size = stream.read(buffer, 0, buffer.length);
        assertEquals(5, size);
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 99 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by AOSPA.

the class AppFuseTest method testOpenFile_illegalMode.

public void testOpenFile_illegalMode() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback());
    appFuse.mount(storageManager);
    try {
        appFuse.openFile(INODE, ParcelFileDescriptor.MODE_READ_WRITE);
        fail();
    } catch (IllegalArgumentException exp) {
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager)

Example 100 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by AOSPA.

the class AppFuseTest method testMount.

public void testMount() throws ErrnoException, IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final AppFuse appFuse = new AppFuse("test", new TestCallback());
    appFuse.mount(storageManager);
    final File file = appFuse.getMountPoint();
    assertTrue(file.isDirectory());
    assertEquals(1, Os.stat(file.getPath()).st_ino);
    appFuse.close();
    assertTrue(1 != Os.stat(file.getPath()).st_ino);
}
Also used : StorageManager(android.os.storage.StorageManager) File(java.io.File)

Aggregations

StorageManager (android.os.storage.StorageManager)161 File (java.io.File)43 IOException (java.io.IOException)42 VolumeInfo (android.os.storage.VolumeInfo)38 FileNotFoundException (java.io.FileNotFoundException)32 ParcelFileDescriptor (android.os.ParcelFileDescriptor)25 LargeTest (android.test.suitebuilder.annotation.LargeTest)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 RemoteException (android.os.RemoteException)14 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 StorageVolume (android.os.storage.StorageVolume)13 PackageParserException (android.content.pm.PackageParser.PackageParserException)12 NotFoundException (android.content.res.Resources.NotFoundException)12 StorageListener (android.os.storage.StorageListener)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ErrnoException (android.system.ErrnoException)12 NonNull (android.annotation.NonNull)10 ZipFile (java.util.zip.ZipFile)10