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