Fix "division by zero" crash after USB mass storage disconnects

File.java will return the total size in bytes of the partition
containing the path, and if the path does not exist,
it will return 0.

Change-Id: I134d4ec787b475e38bb37b4386bafcc419971c1e
This commit is contained in:
Xinghan Yue
2015-12-28 17:59:44 +01:00
committed by Zoran Jovanovic
parent b913bf926e
commit b997bd989e

View File

@@ -74,7 +74,9 @@ public class StorageVolumePreference extends Preference {
final String used = Formatter.formatFileSize(context, usedBytes);
final String total = Formatter.formatFileSize(context, totalBytes);
setSummary(context.getString(R.string.storage_volume_summary, used, total));
mUsedPercent = (int) ((usedBytes * 100) / totalBytes);
if (totalBytes > 0) {
mUsedPercent = (int) ((usedBytes * 100) / totalBytes);
}
if (freeBytes < mStorageManager.getStorageLowBytes(path)) {
mColor = StorageSettings.COLOR_WARNING;