From b997bd989ec68c657a0263f459545dbea50d6de3 Mon Sep 17 00:00:00 2001 From: Xinghan Yue Date: Mon, 28 Dec 2015 17:59:44 +0100 Subject: [PATCH] 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 --- .../android/settings/deviceinfo/StorageVolumePreference.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreference.java b/src/com/android/settings/deviceinfo/StorageVolumePreference.java index 3511b91d15c..04e0ffce36e 100644 --- a/src/com/android/settings/deviceinfo/StorageVolumePreference.java +++ b/src/com/android/settings/deviceinfo/StorageVolumePreference.java @@ -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;