Search in sources :

Example 21 with StatFs

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);
}
Also used : StatFs(android.os.StatFs)

Example 22 with StatFs

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;
}
Also used : StatFs(android.os.StatFs) Media(org.storymaker.app.model.Media) File(java.io.File)

Example 23 with StatFs

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;
}
Also used : StatFs(android.os.StatFs) File(java.io.File) IOException(java.io.IOException)

Example 24 with StatFs

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;
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 25 with StatFs

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);
        }
    }
}
Also used : StatFs(android.os.StatFs) IOException(java.io.IOException) File(java.io.File)

Aggregations

StatFs (android.os.StatFs)196 File (java.io.File)120 IOException (java.io.IOException)30 FileOutputStream (java.io.FileOutputStream)17 TargetApi (android.annotation.TargetApi)15 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 FileNotFoundException (java.io.FileNotFoundException)11 ContentResolver (android.content.ContentResolver)10 DropBoxManager (android.os.DropBoxManager)10 TextView (android.widget.TextView)10 DropBoxManagerService (com.android.server.DropBoxManagerService)10 Test (org.junit.Test)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 IntentFilter (android.content.IntentFilter)6 Context (android.content.Context)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 Button (android.widget.Button)5 SuppressLint (android.annotation.SuppressLint)3 SDCardInfo (com.yzy.supercleanmaster.model.SDCardInfo)3