AntennaPod/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java

43 lines
1.2 KiB
Java
Raw Normal View History

2014-10-11 17:43:07 +02:00
package de.danoeh.antennapod.core.util;
import android.os.StatFs;
2022-11-06 14:32:47 +01:00
import de.danoeh.antennapod.storage.preferences.UserPreferences;
2014-10-11 17:43:07 +02:00
import java.io.File;
/**
* Utility functions for handling storage errors
*/
public class StorageUtils {
private StorageUtils(){}
2014-10-11 17:43:07 +02:00
/**
* Get the number of free bytes that are available on the external storage.
*/
public static long getFreeSpaceAvailable() {
2015-12-31 14:17:12 +01:00
File dataFolder = UserPreferences.getDataFolder(null);
if (dataFolder != null) {
return getFreeSpaceAvailable(dataFolder.getAbsolutePath());
} else {
return 0;
}
}
/**
* Get the number of free bytes that are available on the external storage.
*/
public static long getFreeSpaceAvailable(String path) {
StatFs stat = new StatFs(path);
long availableBlocks = stat.getAvailableBlocksLong();
long blockSize = stat.getBlockSizeLong();
2014-10-11 17:43:07 +02:00
return availableBlocks * blockSize;
}
public static long getTotalSpaceAvailable(String path) {
StatFs stat = new StatFs(path);
long blockCount = stat.getBlockCountLong();
long blockSize = stat.getBlockSizeLong();
return blockCount * blockSize;
}
2014-10-11 17:43:07 +02:00
}