Search in sources :

Example 41 with StatFs

use of android.os.StatFs in project android-common by litesuits.

the class SdCardUtil method getSDCardInfo.

/**
     * Get SD card info detail.
     */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static SDCardInfo getSDCardInfo() {
    SDCardInfo sd = new SDCardInfo();
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        sd.isExist = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            File sdcardDir = Environment.getExternalStorageDirectory();
            StatFs sf = new StatFs(sdcardDir.getPath());
            sd.totalBlocks = sf.getBlockCountLong();
            sd.blockByteSize = sf.getBlockSizeLong();
            sd.availableBlocks = sf.getAvailableBlocksLong();
            sd.availableBytes = sf.getAvailableBytes();
            sd.freeBlocks = sf.getFreeBlocksLong();
            sd.freeBytes = sf.getFreeBytes();
            sd.totalBytes = sf.getTotalBytes();
        }
    }
    if (Log.isPrint) {
        Log.i(TAG, sd.toString());
    }
    return sd;
}
Also used : StatFs(android.os.StatFs) TargetApi(android.annotation.TargetApi)

Example 42 with StatFs

use of android.os.StatFs in project RxSample by Aload.

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;
    }
    return allSize != 0 && availableSize > limitSize;
}
Also used : StatFs(android.os.StatFs) File(java.io.File) IOException(java.io.IOException)

Example 43 with StatFs

use of android.os.StatFs in project orWall by EthACKdotOrg.

the class Toolbox method hasEnoughSpaceOnPartition.

/**
     * Check if there is enough space on partition where target is located
     * 
     * @param size
     *            size of file to put on partition
     * @param target
     *            path where to put the file
     * 
     * @return true if it will fit on partition of target, false if it will not fit.
     */
public boolean hasEnoughSpaceOnPartition(String target, long size) {
    try {
        // new File(target).getFreeSpace() (API 9) is not working on data partition
        // get directory without file
        String directory = new File(target).getParent().toString();
        StatFs stat = new StatFs(directory);
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        long availableSpace = availableBlocks * blockSize;
        Log.i(RootCommands.TAG, "Checking for enough space: Target: " + target + ", directory: " + directory + " size: " + size + ", availableSpace: " + availableSpace);
        if (size < availableSpace) {
            return true;
        } else {
            Log.e(RootCommands.TAG, "Not enough space on partition!");
            return false;
        }
    } catch (Exception e) {
        // if new StatFs(directory) fails catch IllegalArgumentException and just return true as
        // workaround
        Log.e(RootCommands.TAG, "Problem while getting available space on partition!", e);
        return true;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BrokenBusyboxException(org.sufficientlysecure.rootcommands.util.BrokenBusyboxException)

Example 44 with StatFs

use of android.os.StatFs in project AndroidUtilCode by Blankj.

the class SDCardUtils method getFreeSpace.

/**
     * 获取SD卡剩余空间
     *
     * @return SD卡剩余空间
     */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getFreeSpace() {
    if (!isSDCardEnable())
        return null;
    StatFs stat = new StatFs(getSDCardPath());
    long blockSize, availableBlocks;
    availableBlocks = stat.getAvailableBlocksLong();
    blockSize = stat.getBlockSizeLong();
    return ConvertUtils.byte2FitMemorySize(availableBlocks * blockSize);
}
Also used : StatFs(android.os.StatFs) TargetApi(android.annotation.TargetApi)

Example 45 with StatFs

use of android.os.StatFs in project AndroidUtilCode by Blankj.

the class SDCardUtils method getSDCardInfo.

/**
     * 获取SD卡信息
     *
     * @return SDCardInfo
     */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getSDCardInfo() {
    if (!isSDCardEnable())
        return null;
    SDCardInfo sd = new SDCardInfo();
    sd.isExist = true;
    StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
    sd.totalBlocks = sf.getBlockCountLong();
    sd.blockByteSize = sf.getBlockSizeLong();
    sd.availableBlocks = sf.getAvailableBlocksLong();
    sd.availableBytes = sf.getAvailableBytes();
    sd.freeBlocks = sf.getFreeBlocksLong();
    sd.freeBytes = sf.getFreeBytes();
    sd.totalBytes = sf.getTotalBytes();
    return sd.toString();
}
Also used : StatFs(android.os.StatFs) TargetApi(android.annotation.TargetApi)

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