Search in sources :

Example 81 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class AppFuseTest method testWriteFile_flushError.

public void testWriteFile_flushError() 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;
        }

        @Override
        public int writeObjectBytes(long fileHandle, int inode, long offset, int size, byte[] bytes) {
            return size;
        }

        @Override
        public void flushFileHandle(long fileHandle) throws IOException {
            throw new IOException();
        }
    });
    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');
        try {
            IoUtils.close(fd.getFileDescriptor());
            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 82 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

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 83 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class AppFuseTest method testOpenFile_fileNotFound.

public void testOpenFile_fileNotFound() 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_ONLY);
        fail();
    } catch (FileNotFoundException exp) {
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException)

Example 84 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class PackageManagerTests method mountMedia.

boolean mountMedia() {
    // We can't mount emulated storage.
    if (Environment.isExternalStorageEmulated()) {
        return true;
    }
    if (checkMediaState(Environment.MEDIA_MOUNTED)) {
        return true;
    }
    final String path = Environment.getExternalStorageDirectory().toString();
    StorageListener observer = new StorageListener(Environment.MEDIA_MOUNTED);
    StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
    sm.registerListener(observer);
    try {
        // Wait on observer
        synchronized (observer) {
            int ret = getMs().mountVolume(path);
            if (ret != StorageResultCode.OperationSucceeded) {
                throw new Exception("Could not mount the media");
            }
            long waitTime = 0;
            while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
                observer.wait(WAIT_TIME_INCR);
                waitTime += WAIT_TIME_INCR;
            }
            if (!observer.isDone()) {
                throw new Exception("Timed out waiting for unmount media notification");
            }
            return true;
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception : " + e);
        return false;
    } finally {
        sm.unregisterListener(observer);
    }
}
Also used : StorageListener(android.os.storage.StorageListener) StorageManager(android.os.storage.StorageManager) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) ErrnoException(android.system.ErrnoException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) PackageParserException(android.content.pm.PackageParser.PackageParserException)

Example 85 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class MountServiceTests method testAttemptMountNonObb.

@LargeTest
public void testAttemptMountNonObb() {
    StorageManager sm = getStorageManager();
    final File outFile = getFilePath("test1_nosig.obb");
    mountObb(sm, R.raw.test1_nosig, outFile, OnObbStateChangeListener.ERROR_INTERNAL);
    assertFalse("OBB should not be mounted", sm.isObbMounted(outFile.getPath()));
    assertNull("OBB's mounted path should be null", sm.getMountedObbPath(outFile.getPath()));
}
Also used : StorageManager(android.os.storage.StorageManager) File(java.io.File) LargeTest(android.test.suitebuilder.annotation.LargeTest)

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