use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.
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();
}
use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.
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 android_frameworks_base by crdroidandroid.
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 android_frameworks_base by crdroidandroid.
the class MountService method onVolumeCreatedLocked.
private void onVolumeCreatedLocked(VolumeInfo vol) {
// power off alarm need the access to external storage for audio files.
// So in power off alarm mode, primary storage need to be mounted.
boolean isAlarmBoot = SystemProperties.getBoolean("ro.alarm_boot", false);
if (mPms.isOnlyCoreApps() && !isAlarmBoot) {
Slog.d(TAG, "System booted in core-only mode; ignoring volume " + vol.getId());
return;
}
if (vol.type == VolumeInfo.TYPE_EMULATED) {
final StorageManager storage = mContext.getSystemService(StorageManager.class);
final VolumeInfo privateVol = storage.findPrivateForEmulated(vol);
if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, mPrimaryStorageUuid) && VolumeInfo.ID_PRIVATE_INTERNAL.equals(privateVol.id)) {
Slog.v(TAG, "Found primary storage at " + vol);
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else if (Objects.equals(privateVol.fsUuid, mPrimaryStorageUuid)) {
Slog.v(TAG, "Found primary storage at " + vol);
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
}
} else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
// TODO: only look at first public partition
if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, mPrimaryStorageUuid) && vol.disk.isDefaultPrimary()) {
Slog.v(TAG, "Found primary storage at " + vol);
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_PRIMARY;
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
}
// make sdcard visible.
if (vol.disk.isAdoptable() || vol.disk.isSd()) {
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
}
vol.mountUserId = mCurrentUserId;
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else {
Slog.d(TAG, "Skipping automatic mounting of " + vol);
}
}
use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.
the class DeviceStorageMonitorService method onStart.
/**
* Initializes the disk space threshold value and posts an empty message to
* kickstart the process.
*/
@Override
public void onStart() {
// cache storage thresholds
final StorageManager sm = StorageManager.from(getContext());
mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH);
mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH);
mMemCacheStartTrimThreshold = ((mMemLowThreshold * 3) + mMemFullThreshold) / 4;
mMemCacheTrimToThreshold = mMemLowThreshold + ((mMemLowThreshold - mMemCacheStartTrimThreshold) * 2);
mFreeMemAfterLastCacheClear = mTotalMemory;
checkMemory(true);
mCacheFileDeletedObserver = new CacheFileDeletedObserver();
mCacheFileDeletedObserver.startWatching();
publishBinderService(SERVICE, mRemoteService);
publishLocalService(DeviceStorageMonitorInternal.class, mLocalService);
}
Aggregations