use of android.os.StatFs in project android_frameworks_base by ParanoidAndroid.
the class PackageManagerTests method checkInt.
private boolean checkInt(long pkgLen) {
StatFs intStats = new StatFs(Environment.getDataDirectory().getPath());
long intSize = (long) intStats.getBlockCount() * (long) intStats.getBlockSize();
long iSize = (long) intStats.getAvailableBlocks() * (long) intStats.getBlockSize();
// TODO check for thresholds here?
return pkgLen <= iSize;
}
use of android.os.StatFs in project android_frameworks_base by ParanoidAndroid.
the class DefaultContainerService method isUnderExternalThreshold.
/**
* Measure a file to see if it fits in the external free space.
*
* @param apkFile file to check
* @return true if file fits
* @throws IOException when file does not exist
*/
private boolean isUnderExternalThreshold(File apkFile, boolean isForwardLocked) throws IOException {
if (Environment.isExternalStorageEmulated()) {
return false;
}
final int sizeMb = calculateContainerSize(apkFile, isForwardLocked);
final int availSdMb;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
final StatFs sdStats = new StatFs(Environment.getExternalStorageDirectory().getPath());
final int blocksToMb = (1 << 20) / sdStats.getBlockSize();
availSdMb = sdStats.getAvailableBlocks() / blocksToMb;
} else {
availSdMb = -1;
}
return availSdMb > sizeMb;
}
use of android.os.StatFs in project android_frameworks_base by ParanoidAndroid.
the class DropBoxManagerService method init.
///////////////////////////////////////////////////////////////////////////
/** If never run before, scans disk contents to build in-memory tracking data. */
private synchronized void init() throws IOException {
if (mStatFs == null) {
if (!mDropBoxDir.isDirectory() && !mDropBoxDir.mkdirs()) {
throw new IOException("Can't mkdir: " + mDropBoxDir);
}
try {
mStatFs = new StatFs(mDropBoxDir.getPath());
mBlockSize = mStatFs.getBlockSize();
} catch (IllegalArgumentException e) {
// StatFs throws this on error
throw new IOException("Can't statfs: " + mDropBoxDir);
}
}
if (mAllFiles == null) {
File[] files = mDropBoxDir.listFiles();
if (files == null)
throw new IOException("Can't list files: " + mDropBoxDir);
mAllFiles = new FileList();
mFilesByTag = new HashMap<String, FileList>();
// Scan pre-existing files.
for (File file : files) {
if (file.getName().endsWith(".tmp")) {
Slog.i(TAG, "Cleaning temp file: " + file);
file.delete();
continue;
}
EntryFile entry = new EntryFile(file, mBlockSize);
if (entry.tag == null) {
Slog.w(TAG, "Unrecognized file: " + file);
continue;
} else if (entry.timestampMillis == 0) {
Slog.w(TAG, "Invalid filename: " + file);
file.delete();
continue;
}
enrollEntry(entry);
}
}
}
use of android.os.StatFs in project android_frameworks_base by ParanoidAndroid.
the class DropBoxTest method testAgeLimits.
public void testAgeLimits() throws Exception {
File dir = getEmptyDir("testAgeLimits");
int blockSize = new StatFs(dir.getPath()).getBlockSize();
// Limit storage to 10 blocks with an expiration of 1 second
int kb = blockSize * 10 / 1024;
ContentResolver cr = getContext().getContentResolver();
Settings.Global.putString(cr, Settings.Global.DROPBOX_AGE_SECONDS, "1");
Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
// Write one normal entry and another so big that it is instantly tombstoned
long before = System.currentTimeMillis();
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(service);
dropbox.addText("DropBoxTest", "TEST");
addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
// Verify that things are as expected
DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
assertEquals("TEST", e0.getText(80));
assertEquals(null, e1.getText(80));
assertEquals(-1, getEntrySize(e1));
e0.close();
e1.close();
// Wait a second and write another entry -- old ones should be expunged
Thread.sleep(2000);
dropbox.addText("DropBoxTest", "TEST1");
e0 = dropbox.getNextEntry(null, before);
assertTrue(null == dropbox.getNextEntry(null, e0.getTimeMillis()));
assertEquals("TEST1", e0.getText(80));
e0.close();
}
use of android.os.StatFs in project Anki-Android by Ramblurr.
the class CustomExceptionHandler method getAvailableInternalMemorySize.
private long getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
Aggregations