Search in sources :

Example 61 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)

Example 62 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 63 with StatFs

use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.

the class CommonUtil method getSDcardTotalSize.

/**
   * 获取手机SD卡总空间
   */
private static long getSDcardTotalSize() {
    if (checkSdCard()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long blockCountLong = mStatFs.getBlockCountLong();
        return blockSizeLong * blockCountLong;
    } else {
        return 0;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 64 with StatFs

use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.

the class CommonUtil method getSDcardAvailableSize.

/**
   * 获取SDka可用空间
   */
private static long getSDcardAvailableSize() {
    if (checkSdCard()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long availableBlocksLong = mStatFs.getAvailableBlocksLong();
        return blockSizeLong * availableBlocksLong;
    } else {
        return 0;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 65 with StatFs

use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.

the class CommonUtil method getPhoneTotalSize.

/**
   * 获取手机内部存储总空间
   */
public static long getPhoneTotalSize() {
    if (!checkSdCard()) {
        File path = Environment.getDataDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long blockCountLong = mStatFs.getBlockCountLong();
        return blockSizeLong * blockCountLong;
    } else {
        return getSDcardTotalSize();
    }
}
Also used : StatFs(android.os.StatFs) 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