List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:com.error.hunter.ListenService.java
private void generateBugReport(ActivityManager.ProcessErrorStateInfo entry) { String condition;/*from www . jav a 2 s . c o m*/ badProcess = entry.processName; String build = Build.DISPLAY; String fingerprint = Build.FINGERPRINT; String serial = Build.SERIAL; String product = Build.PRODUCT; String model = Build.MODEL; File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); @SuppressWarnings("deprecation") long blockSize = stat.getBlockSize(); @SuppressWarnings("deprecation") long availableBlocks = stat.getAvailableBlocks(); String memory = Formatter.formatFileSize(this, availableBlocks * blockSize).toString(); MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long availableMegs = mi.availMem / 1048576L; strBuf.append("Problem detected in: ").append(badProcess); if (entry.tag != null) { strBuf.append(" (").append(entry.tag).append(")"); } strBuf.append("\nDevice product: " + product); strBuf.append("\nDevice model: " + model); strBuf.append("\nDevice build: " + build); strBuf.append("\nDevice fingerprint: " + fingerprint); strBuf.append("\nDevice SN: " + serial); strBuf.append("\nDevice available RAM (MB): " + availableMegs); strBuf.append("\nDevice free phisical memory: " + memory + "\n"); strBuf.append(getNetworkInfo()); strBuf.append("\n"); ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> procInfos = actvityManager.getRunningServices(1000); Iterator<RunningServiceInfo> taskIter = procInfos.iterator(); RunningServiceInfo info; while (taskIter.hasNext()) { info = taskIter.next(); if (info.process.equals(badProcess)) { strBuf.append("\nService " + info.service + " crash count: " + info.crashCount + " active since: " + info.activeSince + " process: " + info.process); } } strBuf.append("\n"); //android.os.Debug.MemoryInfo[] miPid = activityManager.getProcessMemoryInfo(new int[]{entry.pid}); //String memoryProc = miPid[0].toString(); //strBuf.append("\nRAM used by process (Process: " + entry.processName + " PID: " + entry.pid +"): " + memoryProc + "MB\n"); switch (entry.condition) { case ActivityManager.ProcessErrorStateInfo.CRASHED: condition = "CRASHED"; getDeviceProcessInfo(badProcess, entry.stackTrace); writeLogsToFile(condition, badProcess); break; case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING: condition = "ANR"; getDeviceProcessInfo(badProcess, ""); writeLogsToFile(condition, badProcess); break; default: condition = "<unknown>"; getDeviceProcessInfo(badProcess, entry.stackTrace); writeLogsToFile(condition, badProcess); break; } }
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:com.colorchen.qbase.utils.FileUtil.java
/** * ?SD?//w ww .jav a 2 s . c o m * * @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.raspi.chatapp.util.storage.file.LocalStorageProvider.java
@Override public Cursor queryRoots(final String[] projection) throws FileNotFoundException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (getContext() == null || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { return null; }/*from w w w. j av a 2 s .co m*/ // Create a cursor with either the requested fields, or the default projection if "projection" is null. final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION); // Add Home directory File homeDir = Environment.getExternalStorageDirectory(); if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.home)); row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD); row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher); // These columns are optional row.add(Root.COLUMN_SUMMARY, homeDir.getAbsolutePath()); row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(homeDir.getAbsolutePath()).getAvailableBytes()); // Root.COLUMN_MIME_TYPE is another optional column and useful if you have multiple roots with different // types of mime types (roots that don't match the requested mime type are automatically hidden) } // Add SD card directory File sdCard = new File("/storage/extSdCard"); String storageState = EnvironmentCompat.getStorageState(sdCard); if (TextUtils.equals(storageState, Environment.MEDIA_MOUNTED) || TextUtils.equals(storageState, Environment.MEDIA_MOUNTED_READ_ONLY)) { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, sdCard.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, sdCard.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.sd_card)); // Always assume SD Card is read-only row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY); row.add(Root.COLUMN_ICON, R.drawable.ic_sd_card); row.add(Root.COLUMN_SUMMARY, sdCard.getAbsolutePath()); row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(sdCard.getAbsolutePath()).getAvailableBytes()); } return result; } else return null; }
From source file:com.fallahpoor.infocenter.fragments.StorageFragment.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private String getExternalFree() { long size;/*from www. j a v a2s .co m*/ StatFs extStorageStatFs; String extStoragePath = getExternalStoragePath(); if (extStoragePath == null || !(new File(extStoragePath).exists())) { return getString(R.string.sto_sub_item_ext_storage_not_available); } extStorageStatFs = new StatFs(new File(extStoragePath).getAbsolutePath()); if (mIsApiAtLeast18) { size = extStorageStatFs.getAvailableBytes(); } else { size = (long) extStorageStatFs.getAvailableBlocks() * (long) extStorageStatFs.getBlockSize(); } return Utils.getFormattedSize(size); }
From source file:com.squareup.picasso3.Utils.java
static long calculateDiskCacheSize(File dir) { long size = MIN_DISK_CACHE_SIZE; try {/*from w ww. jav a 2 s . co m*/ StatFs statFs = new StatFs(dir.getAbsolutePath()); //noinspection deprecation long blockCount = SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockCount() : statFs.getBlockCountLong(); //noinspection deprecation long blockSize = SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockSize() : statFs.getBlockSizeLong(); long available = blockCount * blockSize; // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE); }
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.chenxiaolong.dualbootpatcher.freespace.FreeSpaceFragment.java
private void refreshMounts() { mMounts.clear();//from w w w.j a va2 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(); }
From source file:cordova.plugins.Diagnostic_External_Storage.java
/** * Given a path return the number of free bytes in the filesystem containing the path. * * @param path to the file system// w w w . j a v a 2 s.c o m * @return free space in bytes */ protected long getFreeSpaceInBytes(String path) { try { StatFs stat = new StatFs(path); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } catch (IllegalArgumentException e) { // The path was invalid. Just return 0 free bytes. return 0; } }
From source file:count.ly.messaging.CrashDetails.java
/** * Returns the current device disk space. *//*w w w . j a v a2s . co 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); } }