Example usage for android.os StatFs getAvailableBlocksLong

List of usage examples for android.os StatFs getAvailableBlocksLong

Introduction

In this page you can find the example usage for android.os StatFs getAvailableBlocksLong.

Prototype

public long getAvailableBlocksLong() 

Source Link

Document

The number of blocks that are free on the file system and available to applications.

Usage

From source file:com.esminis.server.mariadb.server.MariaDbServerLauncher.java

private long getFreeSpace(File file) {
    StatFs stat = new StatFs(file.getPath());
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
    }/* w w w  . j av a 2s. c o m*/
    return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}

From source file:eu.mhutti1.utils.storage.StorageDevice.java

public Long getAvailableBytes() {
    StatFs statFs = new StatFs(mFile.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return statFs.getBlockSizeLong() * statFs.getAvailableBlocksLong();
    } else {/*from  w w  w.j a v  a  2s.c  o m*/
        return (long) statFs.getBlockSize() * (long) statFs.getAvailableBlocks();
    }
}

From source file:rus.cpuinfo.AndroidDepedentModel.DevInfo.java

@NonNull
@SuppressLint("NewApi")
private String getAviableStorage() {

    StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());

    final long availBlocks = VersionUtil.IS_JELLY_BEAN_MR2()
            ? statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong()
            : statFs.getAvailableBlocks() * statFs.getBlockSize();

    // return String.format(Locale.getDefault(),"%s",availBlocks);
    return formatFileSize(getContext(), availBlocks).replaceAll(",", ".");

}

From source file:com.github.piasy.common.android.utils.roms.RomUtil.java

/**
 * Checks if there is enough Space on SDCard
 *
 * @param updateSize Size to Check//  w w w .  j a v  a 2s .c  om
 * @return {@code true} if the Update will fit on SDCard, {@code false} if not enough space on
 * SDCard. Will also return false, if the SDCard is not mounted as read/write
 */
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public boolean enoughSpaceOnSdCard(final long updateSize) {
    boolean ret = false;
    final String status = Environment.getExternalStorageState();
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        final File path = Environment.getExternalStorageDirectory();
        final StatFs stat = new StatFs(path.getPath());
        final long blockSize = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
                ? stat.getBlockSizeLong()
                : stat.getBlockSize();
        final long availableBlocks = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
                ? stat.getAvailableBlocksLong()
                : stat.getAvailableBlocks();

        ret = updateSize < availableBlocks * blockSize;
    }

    return ret;
}

From source file:com.github.chenxiaolong.dualbootpatcher.freespace.FreeSpaceFragment.java

private void refreshMounts() {
    mMounts.clear();/* ww w . j a v a2  s .c  o  m*/

    MountEntry[] entries;

    try {
        entries = FileUtils.getMounts();
    } catch (IOException e) {
        Log.e(TAG, "Failed to get mount entries", e);
        return;
    }

    for (MountEntry entry : entries) {
        MountInfo info = new MountInfo();
        info.mountpoint = entry.mnt_dir;
        info.fsname = entry.mnt_fsname;
        info.fstype = entry.mnt_type;

        // Ignore irrelevant filesystems
        if (SKIPPED_FSTYPES.contains(info.fstype) || SKIPPED_FSNAMES.contains(info.fsname)
                || info.mountpoint.startsWith("/mnt") || info.mountpoint.startsWith("/dev")
                || info.mountpoint.startsWith("/proc") || info.mountpoint.startsWith("/data/data")) {
            continue;
        }

        StatFs statFs;

        try {
            statFs = new StatFs(info.mountpoint);
        } catch (IllegalArgumentException e) {
            // Thrown if Os.statvfs() throws ErrnoException
            Log.e(TAG, "Exception during statfs of " + info.mountpoint + ": " + e.getMessage());
            continue;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            info.totalSpace = statFs.getBlockSizeLong() * statFs.getBlockCountLong();
            info.availSpace = statFs.getBlockSizeLong() * statFs.getAvailableBlocksLong();
        } else {
            info.totalSpace = statFs.getBlockSize() * statFs.getBlockCount();
            info.availSpace = statFs.getBlockSize() * statFs.getAvailableBlocks();
        }

        mMounts.add(info);
    }

    mAdapter.notifyDataSetChanged();
}

From source file:com.colorchen.qbase.utils.FileUtil.java

/**
 * ?SD?/* w w w . jav a 2s . com*/
 *
 * @return SD?
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getFreeSpace() {
    if (!isSDCardEnable()) {
        return "sdcard unable!";
    }
    StatFs stat = new StatFs(getSDCardPath());
    long blockSize, availableBlocks;
    availableBlocks = stat.getAvailableBlocksLong();
    blockSize = stat.getBlockSizeLong();
    return DataUtil.byte2FitSize(availableBlocks * blockSize);
}

From source file:com.colorchen.qbase.utils.FileUtil.java

/**
 * ????./*from w  w w .  ja  v a  2 s  .c om*/
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static long getDirSize(String path) {
    StatFs stat = new StatFs(path);
    long blockSize, availableBlocks;
    if (Build.VERSION.SDK_INT >= 18) {
        blockSize = stat.getBlockSizeLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();
    }
    return availableBlocks * blockSize;
}

From source file:com.colorchen.qbase.utils.FileUtil.java

/**
 * ???./*from  ww  w .  jav  a 2 s  . co m*/
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static long getSDCardAvailaleSize() {
    File path = getRootPath();
    StatFs stat = new StatFs(path.getPath());
    long blockSize, availableBlocks;
    if (Build.VERSION.SDK_INT >= 18) {
        blockSize = stat.getBlockSizeLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();
    }
    return availableBlocks * blockSize;
}

From source file:com.miz.functions.MizLib.java

@SuppressWarnings("deprecation")
public static long getFreeMemory() {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    if (hasJellyBeanMR2())
        return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
    else/*from   w  w w  .j a  v a 2s. c  o  m*/
        return stat.getAvailableBlocks() * stat.getBlockSize();
}