Example usage for android.os StatFs getBlockSizeLong

List of usage examples for android.os StatFs getBlockSizeLong

Introduction

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

Prototype

public long getBlockSizeLong() 

Source Link

Document

The size, in bytes, of a block on the file system.

Usage

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/*from ww  w  .  j a v  a2  s  .  co  m*/
 * @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: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   ww w.jav a 2s  .  c o m*/
        return (long) statFs.getBlockSize() * (long) statFs.getAvailableBlocks();
    }
}

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

public Long getTotalBytes() {
    StatFs statFs = new StatFs((mFile.getPath()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return statFs.getBlockSizeLong() * statFs.getBlockCountLong();
    } else {//  w w  w. ja  v a  2 s .  com
        return (long) statFs.getBlockSize() * (long) statFs.getBlockCount();
    }
}

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 a  v  a  2  s.  c om
    return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}

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

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

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

    final long blockCount = VersionUtil.IS_JELLY_BEAN_MR2()
            ? statFs.getBlockCountLong() * statFs.getBlockSizeLong()
            : statFs.getBlockCount() * statFs.getBlockSize();

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

}

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.androchill.call411.MainActivity.java

private Phone getHardwareSpecs() {
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    PhoneBuilder pb = new PhoneBuilder();
    pb.setModelNumber(Build.MODEL);/*from  w ww.  j  a  v a  2 s. c  om*/
    pb.setManufacturer(Build.MANUFACTURER);

    Process p = null;
    String board_platform = "No data available";
    try {
        p = new ProcessBuilder("/system/bin/getprop", "ro.chipname").redirectErrorStream(true).start();
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = "";
        while ((line = br.readLine()) != null) {
            board_platform = line;
        }
        p.destroy();
    } catch (IOException e) {
        e.printStackTrace();
        board_platform = "No data available";
    }

    pb.setProcessor(board_platform);
    ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(mInfo);
    pb.setRam((int) (mInfo.totalMem / 1048576L));
    pb.setBatteryCapacity(getBatteryCapacity());
    pb.setTalkTime(-1);
    pb.setDimensions("No data available");

    WindowManager mWindowManager = getWindowManager();
    Display mDisplay = mWindowManager.getDefaultDisplay();
    Point mPoint = new Point();
    mDisplay.getSize(mPoint);
    pb.setScreenResolution(mPoint.x + " x " + mPoint.y + " pixels");

    DisplayMetrics mDisplayMetrics = new DisplayMetrics();
    mDisplay.getMetrics(mDisplayMetrics);
    int mDensity = mDisplayMetrics.densityDpi;
    pb.setScreenSize(
            Math.sqrt(Math.pow(mPoint.x / (double) mDensity, 2) + Math.pow(mPoint.y / (double) mDensity, 2)));

    Camera camera = Camera.open(0);
    android.hardware.Camera.Parameters params = camera.getParameters();
    List sizes = params.getSupportedPictureSizes();
    Camera.Size result = null;

    ArrayList<Integer> arrayListForWidth = new ArrayList<Integer>();
    ArrayList<Integer> arrayListForHeight = new ArrayList<Integer>();

    for (int i = 0; i < sizes.size(); i++) {
        result = (Camera.Size) sizes.get(i);
        arrayListForWidth.add(result.width);
        arrayListForHeight.add(result.height);
    }
    if (arrayListForWidth.size() != 0 && arrayListForHeight.size() != 0) {
        pb.setCameraMegapixels(
                Collections.max(arrayListForHeight) * Collections.max(arrayListForWidth) / (double) 1000000);
    } else {
        pb.setCameraMegapixels(-1);
    }
    camera.release();

    pb.setPrice(-1);
    pb.setWeight(-1);
    pb.setSystem("Android " + Build.VERSION.RELEASE);

    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    StatFs statInternal = new StatFs(Environment.getRootDirectory().getAbsolutePath());
    double storageSize = ((stat.getBlockSizeLong() * stat.getBlockCountLong())
            + (statInternal.getBlockSizeLong() * statInternal.getBlockCountLong())) / 1073741824L;
    pb.setStorageOptions(storageSize + " GB");
    TelephonyManager telephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE));
    String operatorName = telephonyManager.getNetworkOperatorName();
    if (operatorName.length() == 0)
        operatorName = "No data available";
    pb.setCarrier(operatorName);
    pb.setNetworkFrequencies("No data available");
    pb.setImage(null);
    return pb.createPhone();
}

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

private void refreshMounts() {
    mMounts.clear();/*from  w  ww  . j av a 2s .  co 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

/**
 * ????./*from   www.j  a  v  a2  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

/**
 * ???.//ww w.ja va2s . 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;
}