Search in sources :

Example 11 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 12 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 13 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 14 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 15 with StatFs

use of android.os.StatFs in project SmartAndroidSource by jaychou2012.

the class SystemInfo method getSDCardAvailableStorage.

/**
	 * Get the Device's SDCardAvailableStorage
	 * 
	 * @return the Device's SDCardAvailableStorage
	 */
public String getSDCardAvailableStorage() {
    long[] sdCardInfo = new long[2];
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File sdcardDir = Environment.getExternalStorageDirectory();
        StatFs sf = new StatFs(sdcardDir.getPath());
        long bSize = sf.getBlockSize();
        long bCount = sf.getBlockCount();
        long availBlocks = sf.getAvailableBlocks();
        sdCardInfo[1] = bSize * availBlocks;
    }
    return sdCardInfo[1] / (1024 * 1024) + "MB";
}
Also used : StatFs(android.os.StatFs) RandomAccessFile(java.io.RandomAccessFile) 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