use of android.os.StatFs in project superCleanMaster by joyoyao.
the class StorageUtil method getSystemSpaceInfo.
public static SDCardInfo getSystemSpaceInfo(Context context) {
File path = Environment.getDataDirectory();
// File path = context.getCacheDir().getAbsoluteFile();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
long totalSize = blockSize * totalBlocks;
long availSize = availableBlocks * blockSize;
SDCardInfo info = new SDCardInfo();
info.total = totalSize;
info.free = availSize;
return info;
}
use of android.os.StatFs in project android-app-common-tasks by multidots.
the class CropImage method calculatePicturesRemaining.
private static int calculatePicturesRemaining(Activity activity) {
try {
/*if (!ImageManager.hasStorage()) {
return NO_STORAGE_ERROR;
} else {*/
String storageDirectory;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
storageDirectory = Environment.getExternalStorageDirectory().toString();
} else {
storageDirectory = activity.getFilesDir().toString();
}
StatFs stat = new StatFs(storageDirectory);
float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F;
return (int) remaining;
//}
} catch (Exception ex) {
// blank since we really don't know.
return CANNOT_STAT_ERROR;
}
}
use of android.os.StatFs in project android-app-common-tasks by multidots.
the class CropImage method calculatePicturesRemaining.
private static int calculatePicturesRemaining(Activity activity) {
try {
/*if (!ImageManager.hasStorage()) {
return NO_STORAGE_ERROR;
} else {*/
String storageDirectory;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
storageDirectory = Environment.getExternalStorageDirectory().toString();
} else {
storageDirectory = activity.getFilesDir().toString();
}
StatFs stat = new StatFs(storageDirectory);
float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F;
return (int) remaining;
//}
} catch (Exception ex) {
// blank since we really don't know.
return CANNOT_STAT_ERROR;
}
}
use of android.os.StatFs in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class AppCacheTest method testFreeStorage.
// TODO: flaky test, omit from LargeTest for now
//@LargeTest
public void testFreeStorage() throws Exception {
boolean TRACKING = true;
StatFs st = new StatFs("/data");
long blks1 = getFreeStorageBlks(st);
if (localLOGV || TRACKING)
Log.i(TAG, "Available free blocks=" + blks1);
long availableMem = getFreeStorageSize(st);
File cacheDir = mContext.getCacheDir();
assertNotNull(cacheDir);
createTestFiles1(cacheDir, "testtmpdir", 5);
long blks2 = getFreeStorageBlks(st);
if (localLOGV || TRACKING)
Log.i(TAG, "Available blocks after writing test files in application cache=" + blks2);
// Create receiver and register it
FreeStorageReceiver receiver = new FreeStorageReceiver();
mContext.registerReceiver(receiver, new IntentFilter(FreeStorageReceiver.ACTION_FREE));
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent(FreeStorageReceiver.ACTION_FREE), 0);
// Invoke PackageManager api
if (!invokePMFreeStorage(availableMem, receiver, pi)) {
fail("Could not invoke PackageManager free storage API");
}
long blks3 = getFreeStorageBlks(st);
if (localLOGV || TRACKING)
Log.i(TAG, "Available blocks after freeing cache" + blks3);
assertEquals(receiver.getResultCode(), 1);
mContext.unregisterReceiver(receiver);
// Verify result
verifyTestFiles1(cacheDir, "testtmpdir", 5);
}
Aggregations