Fix free storage space check for all APIs

See https://stackoverflow.com/q/31171838
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstatvfs.html
This commit is contained in:
Stypox 2024-04-23 12:16:06 +02:00
parent 00770fc634
commit c3c39a7b24
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
3 changed files with 50 additions and 66 deletions

View file

@ -40,20 +40,6 @@ public class Utility {
UNKNOWN
}
/**
* Get amount of free system's memory.
* @return free memory (bytes)
*/
public static long getSystemFreeMemory() {
try {
final StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
return statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
} catch (final Exception e) {
// do nothing
}
return -1;
}
public static String formatBytes(long bytes) {
Locale locale = Locale.getDefault();
if (bytes < 1024) {