use of android.os.StatFs in project SeriesGuide by UweTrottmann.
the class HttpClientModule method calculateApiDiskCacheSize.
private static long calculateApiDiskCacheSize(File dir) {
long size = MIN_DISK_API_CACHE_SIZE;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
long available;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
available = statFs.getBlockCountLong() * statFs.getBlockSizeLong();
} else {
//noinspection deprecation
available = ((long) statFs.getBlockCount()) * statFs.getBlockSize();
}
// Target 2% of the total space.
size = available / 50;
} catch (IllegalArgumentException ignored) {
}
// Bound inside min/max size for disk cache.
return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE);
}
use of android.os.StatFs in project storymaker by StoryMaker.
the class MediaProjectManager method checkStorageSpace.
// return space required to pass info up the stack
public double checkStorageSpace() {
ArrayList<Media> mList = this.mProject.getMediaAsList();
Long totalBytesRequired = 0l;
//first check that all of the input images are accessible
for (Media media : mList) {
try {
if (media == null || media.getPath() == null) {
} else if (!new File(media.getPath()).exists()) {
throw new java.io.FileNotFoundException();
} else {
File currentFile = new File(media.getPath());
totalBytesRequired += (long) currentFile.length();
}
} catch (java.io.FileNotFoundException fnfe) {
Timber.e(fnfe, "Input image does not exist or is not readable" + ": " + media.getPath());
}
}
//get memory path
String memoryPath;
if (mUseInternal) {
memoryPath = Environment.getDataDirectory().getPath();
} else {
memoryPath = Environment.getExternalStorageDirectory().getPath();
}
//get memory
StatFs stat = new StatFs(memoryPath);
Long totalBytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
// FIXME we should raise this error via a intent, not a straight toast so it can be handled if the activity is hidden
if (totalBytesRequired > totalBytesAvailable) {
double totalMBRequired = totalBytesRequired / (double) (1024 * 1024);
// can't create toast message here because instances created by renderer have a null value for activity
return totalMBRequired;
}
return 0;
}
use of android.os.StatFs in project tinker by Tencent.
the class Utils method checkRomSpaceEnough.
@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
long allSize;
long availableSize = 0;
try {
File data = Environment.getDataDirectory();
StatFs sf = new StatFs(data.getPath());
availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
} catch (Exception e) {
allSize = 0;
}
if (allSize != 0 && availableSize > limitSize) {
return true;
}
return false;
}
use of android.os.StatFs in project atlas by alibaba.
the class ReplacedReceiver 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;
}
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);
}
}
}
Aggregations