Example usage for android.os StatFs StatFs

List of usage examples for android.os StatFs StatFs

Introduction

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

Prototype

public StatFs(String path) 

Source Link

Document

Construct a new StatFs for looking at the stats of the filesystem at path .

Usage

From source file:com.android.mms.ui.MessageUtils.java

/** M:
 * Return the current storage status.//from   ww  w  . j  a va  2 s.  c  om
 */
public static String getStorageStatus(Context context) {
    /// M: we need count only
    final String[] PROJECTION = new String[] { BaseColumns._ID, Mms.MESSAGE_SIZE };
    final ContentResolver cr = context.getContentResolver();
    final Resources res = context.getResources();
    Cursor cursor = null;

    StringBuilder buffer = new StringBuilder();
    // Mms count
    cursor = cr.query(Mms.CONTENT_URI, PROJECTION, null, null, null);
    int mmsCount = 0;
    if (cursor != null) {
        mmsCount = cursor.getCount();
    }
    buffer.append(res.getString(R.string.storage_dialog_mms, mmsCount));
    buffer.append("\n");
    //Mms size
    long size = 0;
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                size += cursor.getInt(1);
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    buffer.append(res.getString(R.string.storage_dialog_mms_size) + getHumanReadableSize(size));
    buffer.append("\n");
    // Attachment size
    size = getAttachmentSize(context);
    Log.d(TAG, "mms attachment size = " + size);
    final String sizeTag = getHumanReadableSize(size);
    buffer.append(res.getString(R.string.storage_dialog_attachments) + sizeTag);
    buffer.append("\n");
    // Sms count
    cursor = cr.query(Sms.CONTENT_URI, PROJECTION, null, null, null);
    int smsCount = 0;
    if (cursor != null) {
        smsCount = cursor.getCount();
        cursor.close();
    }
    buffer.append(res.getString(R.string.storage_dialog_sms, smsCount));
    buffer.append("\n");
    // Database size
    final long dbsize = getDatabaseSize(context);
    buffer.append(res.getString(R.string.storage_dialog_database) + getHumanReadableSize(dbsize));
    buffer.append("\n");
    // Available space
    final StatFs datafs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
    final long availableSpace = (long) datafs.getAvailableBlocks() * datafs.getBlockSize();
    buffer.append(
            res.getString(R.string.storage_dialog_available_space) + getHumanReadableSize(availableSpace));
    return buffer.toString();
}

From source file:com.android.mms.ui.MessageUtils.java

public static long getAvailableBytesInFileSystemAtGivenRoot(String rootFilePath) {
    StatFs stat = new StatFs(rootFilePath);
    //        final long totalBlocks = stat.getBlockCount();
    // put a bit of margin (in case creating the file grows the system by a few blocks)
    final long availableBlocks = stat.getAvailableBlocks() - 128;

    // long mTotalSize = totalBlocks * stat.getBlockSize();
    long mAvailSize = availableBlocks * stat.getBlockSize();

    Log.i(TAG, "getAvailableBytesInFileSystemAtGivenRoot(): "
            + "available space (in bytes) in filesystem rooted at: " + rootFilePath + " is: " + mAvailSize);
    return mAvailSize;
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String GetDiskInfo(String sPath) {
    String sRet = "";
    StatFs statFS = new StatFs(sPath);

    long nBlockCount = statFS.getBlockCount();
    long nBlockSize = statFS.getBlockSize();
    long nBlocksAvail = statFS.getAvailableBlocks();
    // Free is often the same as Available, but can include reserved
    // blocks that are not available to normal applications.
    // long nBlocksFree = statFS.getFreeBlocks();

    sRet = sPath + ": " + (nBlockCount * nBlockSize) + " total, " + (nBlocksAvail * nBlockSize) + " available";

    return (sRet);
}

From source file:com.android.gallery3d.app.PhotoPage.java

/**
 * get available space which storage source video is in.
 *
 * @return the available sapce size, -1 means max storage size.
 *//*from w  w  w  .  j  a  va 2  s .  c o  m*/
private long getAvailableSpace(String path) {
    // Here just use one directory to stat fs.
    StatFs stat = new StatFs(path);
    long availableSize = stat.getAvailableBlocks() * (long) stat.getBlockSize();
    Log.i(TAG, "<getAvailableSpace> path " + path + ", availableSize(MB) "
            + (availableSize / STORAGE_CAPACITY_BASE / STORAGE_CAPACITY_BASE));
    return availableSize;
}

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  ww . jav a2 s  .  c  o  m*/
        return stat.getAvailableBlocks() * stat.getBlockSize();
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

private void showMessageInfo(final Context paramContext, String paramString1, String paramString2) {
      paramContext = new Dialog(paramContext);
      StatFs localStatFs = new StatFs("/system");
      int i = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int j = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      localStatFs = new StatFs("/data");
      int k = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int m = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      paramContext.setCancelable(true);//from  w  w  w .  j a  v a 2 s  .c  o m
      paramContext.setTitle(paramString1);
      paramContext.setContentView(2130968617);
      ((TextView) paramContext.findViewById(2131558571)).setText(paramString2);
      ((TextView) paramContext.findViewById(2131558564))
              .setText("System ROM (/system): " + i + "Mb (" + j + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558565);
      paramString1.setMax(i);
      paramString1.incrementProgressBy(i - j);
      ((TextView) paramContext.findViewById(2131558566))
              .setText("Internal SD (/data): " + k + "Mb (" + m + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558567);
      paramString1.setMax(k);
      paramString1.incrementProgressBy(i - j);
      ((Button) paramContext.findViewById(2131558569)).setOnClickListener(new View.OnClickListener() {
          public void onClick(View paramAnonymousView) {
              paramContext.dismiss();
          }
      });
      Utils.showDialog(paramContext);
  }

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

private static void showMessageInfoStatic(Context paramContext, String paramString1, String paramString2) {
      paramContext = new Dialog(paramContext);
      StatFs localStatFs = new StatFs("/system");
      int i = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int j = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      localStatFs = new StatFs("/data");
      int k = localStatFs.getBlockCount() * localStatFs.getBlockSize() / 1048576;
      int m = localStatFs.getAvailableBlocks() * localStatFs.getBlockSize() / 1048576;
      paramContext.setCancelable(true);//from  w w w  . java  2  s  .co  m
      paramContext.setTitle(paramString1);
      paramContext.setContentView(2130968617);
      ((TextView) paramContext.findViewById(2131558571)).setText(paramString2);
      ((TextView) paramContext.findViewById(2131558564))
              .setText("System ROM (/system): " + i + "Mb (" + j + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558565);
      paramString1.setMax(i);
      paramString1.incrementProgressBy(i - j);
      ((TextView) paramContext.findViewById(2131558566))
              .setText("Internal SD (/data): " + k + "Mb (" + m + "Mb free)");
      paramString1 = (ProgressBar) paramContext.findViewById(2131558567);
      paramString1.setMax(k);
      paramString1.incrementProgressBy(i - j);
      ((Button) paramContext.findViewById(2131558569)).setOnClickListener(new View.OnClickListener() {
          public void onClick(View paramAnonymousView) {
              this.val$dialog.dismiss();
          }
      });
      Utils.showDialog(paramContext);
  }