Example usage for android.os StatFs getBlockCountLong

List of usage examples for android.os StatFs getBlockCountLong

Introduction

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

Prototype

public long getBlockCountLong() 

Source Link

Document

The total number of blocks on the file system.

Usage

From source file:count.ly.messaging.CrashDetails.java

/**
 * Returns the current device disk space.
 *//*from  ww  w . ja v a  2  s.c o  m*/
static String getDiskTotal() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCount() * statFs.getBlockSize());
        return Long.toString(total / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        return Long.toString(total / 1048576L);
    }
}

From source file:ly.count.android.sdk.CrashDetails.java

/**
 * Returns the current device disk space.
 *///from  www.j  a v a  2  s  .c o m
@TargetApi(18)
static String getDiskTotal() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = ((long) statFs.getBlockCount() * (long) statFs.getBlockSize());
        return Long.toString(total / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        return Long.toString(total / 1048576L);
    }
}

From source file:count.ly.messaging.CrashDetails.java

/**
 * Returns the current device disk space.
 *//*from w  w w  .j  av  a 2s .c o m*/
static String getDiskCurrent() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCount() * statFs.getBlockSize());
        long free = (statFs.getAvailableBlocks() * statFs.getBlockSize());
        return Long.toString((total - free) / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        long free = (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong());
        return Long.toString((total - free) / 1048576L);
    }
}

From source file:ly.count.android.sdk.CrashDetails.java

/**
 * Returns the current device disk space.
 *//*w  w  w  .j a  v a  2 s . c  o m*/
@TargetApi(18)
static String getDiskCurrent() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = ((long) statFs.getBlockCount() * (long) statFs.getBlockSize());
        long free = ((long) statFs.getAvailableBlocks() * (long) statFs.getBlockSize());
        return Long.toString((total - free) / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        long free = (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong());
        return Long.toString((total - free) / 1048576L);
    }
}

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: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 . c o m
        return (long) statFs.getBlockSize() * (long) statFs.getBlockCount();
    }
}

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  w  w. ja  v a  2 s. co m*/
    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  ww  w.ja v a2  s  .  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();
}