Example usage for android.os StatFs getAvailableBlocks

List of usage examples for android.os StatFs getAvailableBlocks

Introduction

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

Prototype

@Deprecated
public int getAvailableBlocks() 

Source Link

Usage

From source file:org.uguess.android.sysinfo.SiragonManager.java

/**
 * This checks the built-in app2sd storage info supported since Froyo
 *///from w  w  w.jav  a2s. c  o m
private String[] getSystemA2SDStorageInfo() {
    Activity ctx = getActivity();
    final PackageManager pm = ctx.getPackageManager();
    List<ApplicationInfo> allApps = pm.getInstalledApplications(0);

    long total = 0;
    long free = 0;

    for (int i = 0, size = allApps.size(); i < size; i++) {
        ApplicationInfo info = allApps.get(i);

        if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
            String src = info.sourceDir;

            if (src != null) {
                File srcFile = new File(src);

                if (srcFile.canRead()) {
                    try {
                        StatFs stat = new StatFs(srcFile.getAbsolutePath());
                        long blockSize = stat.getBlockSize();

                        total += stat.getBlockCount() * blockSize;
                        free += stat.getAvailableBlocks() * blockSize;
                    } catch (Exception e) {
                        Log.e(SiragonManager.class.getName(), "Cannot access path: " //$NON-NLS-1$
                                + srcFile.getAbsolutePath(), e);
                    }
                }
            }
        }
    }

    if (total > 0) {
        String[] info = new String[2];
        info[0] = Formatter.formatFileSize(ctx, total);
        info[1] = Formatter.formatFileSize(ctx, free);

        return info;
    }

    return null;
}

From source file:org.uguess.android.sysinfo.SiragonManager.java

private String[] getStorageInfo(File path) {
    if (path != null) {
        try {/* ww  w .  j a  v  a  2  s.c  o  m*/
            Activity ctx = getActivity();

            StatFs stat = new StatFs(path.getAbsolutePath());
            long blockSize = stat.getBlockSize();

            String[] info = new String[2];
            info[0] = Formatter.formatFileSize(ctx, stat.getBlockCount() * blockSize);
            info[1] = Formatter.formatFileSize(ctx, stat.getAvailableBlocks() * blockSize);

            return info;
        } catch (Exception e) {
            Log.e(SiragonManager.class.getName(), "Cannot access path: " //$NON-NLS-1$
                    + path.getAbsolutePath(), e);
        }
    }

    return null;
}

From source file:cm.aptoide.pt.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    AptoideThemePicker.setAptoideTheme(this);
    super.onCreate(savedInstanceState);

    serviceDownloadManagerIntent = new Intent(this, ServiceDownloadManager.class);
    startService(serviceDownloadManagerIntent);
    mContext = this;

    File sdcard_file = new File(SDCARD);
    if (!sdcard_file.exists() || !sdcard_file.canWrite()) {
        View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
        Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
        final AlertDialog noSDDialog = dialogBuilder.create();
        noSDDialog.setTitle(getText(R.string.remote_in_noSD_title));
        noSDDialog.setIcon(android.R.drawable.ic_dialog_alert);
        TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
        message.setText(getText(R.string.remote_in_noSD));
        noSDDialog.setCancelable(false);
        noSDDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(android.R.string.ok),
                new Dialog.OnClickListener() {
                    @Override//from   w w w .j  a va 2s .c  o  m
                    public void onClick(DialogInterface arg0, int arg1) {
                        finish();
                    }
                });
        noSDDialog.show();
    } else {
        StatFs stat = new StatFs(sdcard_file.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        long availableBlocks = stat.getAvailableBlocks();

        long total = (blockSize * totalBlocks) / 1024 / 1024;
        long avail = (blockSize * availableBlocks) / 1024 / 1024;
        Log.d("Aptoide", "* * * * * * * * * *");
        Log.d("Aptoide", "Total: " + total + " Mb");
        Log.d("Aptoide", "Available: " + avail + " Mb");

        if (avail < 10) {
            Log.d("Aptoide", "No space left on SDCARD...");
            Log.d("Aptoide", "* * * * * * * * * *");
            View simpleView = LayoutInflater.from(this).inflate(R.layout.dialog_simple_layout, null);
            Builder dialogBuilder = new AlertDialog.Builder(this).setView(simpleView);
            final AlertDialog noSpaceDialog = dialogBuilder.create();
            noSpaceDialog.setIcon(android.R.drawable.ic_dialog_alert);
            TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
            message.setText(getText(R.string.remote_in_noSDspace));
            noSpaceDialog.setButton(Dialog.BUTTON_NEUTRAL, getText(android.R.string.ok),
                    new Dialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            finish();
                        }
                    });
            noSpaceDialog.show();
        } else {

            SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit();

            if (!sPref.contains("matureChkBox")) {

                editor.putBoolean("matureChkBox", ApplicationAptoide.MATURECONTENTSWITCHVALUE);
                SharedPreferences sPrefOld = getSharedPreferences("aptoide_prefs", MODE_PRIVATE);
                if (sPrefOld.getString("app_rating", "none").equals("Mature")) {
                    editor.putBoolean("matureChkBox", false);
                }

            }

            if (!sPref.contains("version")) {

                ApplicationAptoide.setRestartLauncher(true);
                try {
                    editor.putInt("version",
                            getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
                } catch (NameNotFoundException e) {
                    e.printStackTrace();
                }

            }

            if (sPref.getString("myId", null) == null) {
                String rand_id = UUID.randomUUID().toString();
                editor.putString("myId", rand_id);
            }

            if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) {
                DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);
                editor.putInt("scW", dm.widthPixels);
                editor.putInt("scH", dm.heightPixels);
            }
            editor.commit();
            File file = new File(LOCAL_PATH + "/apks");
            if (!file.exists()) {
                file.mkdirs();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {

                    // Note the L that tells the compiler to interpret the
                    // number as a Long
                    final long MAXFILEAGE = 2678400000L; // 1 month in
                    // milliseconds

                    // Get file handle to the directory. In this case the
                    // application files dir
                    File dir = new File(LOCAL_PATH + "/apks");

                    // Optain list of files in the directory.
                    // listFiles() returns a list of File objects to each
                    // file found.
                    File[] files = dir.listFiles();

                    // Loop through all files
                    for (File f : files) {

                        // Get the last modified date. Miliseconds since
                        // 1970
                        long lastmodified = f.lastModified();

                        // Do stuff here to deal with the file..
                        // For instance delete files older than 1 month
                        if (lastmodified + MAXFILEAGE < System.currentTimeMillis()) {
                            f.delete();
                        }
                    }
                }
            }).start();
            db = Database.getInstance();

            Intent i = new Intent(mContext, MainService.class);
            startService(i);
            bindService(i, conn, Context.BIND_AUTO_CREATE);
            order = Order.values()[PreferenceManager.getDefaultSharedPreferences(mContext).getInt("order_list",
                    0)];

            registerReceiver(updatesReceiver, new IntentFilter("update"));
            registerReceiver(statusReceiver, new IntentFilter("status"));
            registerReceiver(loginReceiver, new IntentFilter("login"));
            registerReceiver(storePasswordReceiver, new IntentFilter("401"));
            registerReceiver(redrawInstalledReceiver, new IntentFilter("pt.caixamagica.aptoide.REDRAW"));
            if (!ApplicationAptoide.MULTIPLESTORES) {
                registerReceiver(parseFailedReceiver, new IntentFilter("PARSE_FAILED"));
            }

            registerReceiver(newRepoReceiver, new IntentFilter("pt.caixamagica.aptoide.NEWREPO"));
            registered = true;

            categoriesStrings = new HashMap<String, Integer>();

            //            categoriesStrings.put("Applications", R.string.applications);

            boolean serversFileIsEmpty = true;

            if (sPref.getBoolean("firstrun", true)) {
                // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
                // shortcutIntent.setClassName("cm.aptoide.pt",
                // "cm.aptoide.pt.Start");
                // final Intent intent = new Intent();
                // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
                // shortcutIntent);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                // getString(R.string.app_name));
                // Parcelable iconResource =
                // Intent.ShortcutIconResource.fromContext(this,
                // R.drawable.ic_launcher);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                // iconResource);
                // intent.putExtra("duplicate", false);
                // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                // sendBroadcast(intent);

                if (new File(LOCAL_PATH + "/servers.xml").exists()
                        && ApplicationAptoide.DEFAULTSTORENAME == null) {
                    try {

                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();

                        MyappHandler handler = new MyappHandler();

                        sp.parse(new File(LOCAL_PATH + "/servers.xml"), handler);
                        ArrayList<String> server = handler.getServers();
                        if (server.isEmpty()) {
                            serversFileIsEmpty = true;
                        } else {
                            getIntent().putExtra("newrepo", server);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                editor.putBoolean("firstrun", false);
                editor.putBoolean("orderByCategory", true);
                editor.commit();
            }

            if (getIntent().hasExtra("newrepo")) {
                ArrayList<String> repos = (ArrayList<String>) getIntent().getSerializableExtra("newrepo");
                for (final String uri2 : repos) {
                    View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout,
                            null);
                    Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                    final AlertDialog addNewRepoDialog = dialogBuilder.create();
                    addNewRepoDialog.setTitle(getString(R.string.add_store));
                    addNewRepoDialog.setIcon(android.R.drawable.ic_menu_add);

                    TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                    message.setText((getString(R.string.newrepo_alrt) + uri2 + " ?"));

                    addNewRepoDialog.setCancelable(false);
                    addNewRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    dialogAddStore(uri2, null, null);
                                }
                            });
                    addNewRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int arg1) {
                                    dialog.cancel();
                                }
                            });
                    addNewRepoDialog.show();
                }
            } else if (db.getStores(false).getCount() == 0 && ApplicationAptoide.DEFAULTSTORENAME == null
                    && serversFileIsEmpty) {
                View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
                Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                final AlertDialog addAppsRepoDialog = dialogBuilder.create();
                addAppsRepoDialog.setTitle(getString(R.string.add_store));
                addAppsRepoDialog.setIcon(android.R.drawable.ic_menu_add);
                TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                message.setText(getString(R.string.myrepo_alrt) + "\n" + "http://apps.store.aptoide.com/");
                addAppsRepoDialog.setCancelable(false);
                addAppsRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                dialogAddStore("http://apps.store.aptoide.com", null, null);
                            }
                        });
                addAppsRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                            }
                        });
                addAppsRepoDialog.show();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        getUpdateParameters();
                        if (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode < Integer
                                .parseInt(updateParams.get("versionCode"))) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    requestUpdateSelf();
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }

        featuredView = LayoutInflater.from(mContext).inflate(R.layout.page_featured, null);
        availableView = LayoutInflater.from(mContext).inflate(R.layout.page_available, null);
        updateView = LayoutInflater.from(mContext).inflate(R.layout.page_updates, null);
        banner = (LinearLayout) availableView.findViewById(R.id.banner);
        breadcrumbs = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.breadcrumb_container, null);
        installedView = new ListView(mContext);
        updatesListView = (ListView) updateView.findViewById(R.id.updates_list);

        availableListView = (ListView) availableView.findViewById(R.id.available_list);
        joinStores = (CheckBox) availableView.findViewById(R.id.join_stores);

        availableAdapter = new AvailableListAdapter(mContext, null,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        installedAdapter = new InstalledAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER,
                db);
        updatesAdapter = new UpdatesAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        pb = (TextView) availableView.findViewById(R.id.loading_pb);
        addStoreButton = availableView.findViewById(R.id.add_store);

        bannerStoreAvatar = (ImageView) banner.findViewById(R.id.banner_store_avatar);
        bannerStoreName = (TextView) banner.findViewById(R.id.banner_store_name);
        bannerStoreDescription = (AutoScaleTextView) banner.findViewById(R.id.banner_store_description);
    }
}

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:org.brandroid.openmanager.activities.OpenExplorer.java

public void handleRefreshMedia(final String path, boolean keepChecking, final int retries) {
    if (!keepChecking || retries <= 0) {
        refreshBookmarks();/*  w w w .  ja v a  2s . c  o m*/
        return;
    }
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            Logger.LogDebug("Check " + retries + " for " + path);
            try {
                StatFs sf = new StatFs(path);
                if (sf.getBlockCount() == 0)
                    throw new Exception("No blocks");
                showToast(getResources().getString(R.string.s_alert_new_media) + " " + getVolumeName(path)
                        + " @ "
                        + DialogHandler.formatSize((long) sf.getBlockSize() * (long) sf.getAvailableBlocks()));
                refreshBookmarks();
                if (mLastPath.getPath().equals(path))
                    goHome();
            } catch (Throwable e) {
                Logger.LogWarning("Couldn't read " + path);
                handleRefreshMedia(path, true, retries - 1); // retry again in 1/2 second
            }
        }
    }, 1000);
}

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  .ja v  a2 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) {
              this.val$dialog.dismiss();
          }
      });
      Utils.showDialog(paramContext);
  }

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);// w  w w.  j a  va2  s. c om
      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);
  }