From a2f013dacbc12b441345bc5beae11dcf1eb7171d Mon Sep 17 00:00:00 2001 From: Shibin George Date: Tue, 9 Apr 2019 16:46:20 +0530 Subject: [PATCH] Gracefully handle the case where private volume may be unmountable If sdcard was removed while format(as phone storage) was under progress, blkid can fail to identify the UUID of the private volume. The PrivateStorageInfo.getTotalSize() API assumes UUID to be always valid which could simply be not the case. Avoid calling getTotalSize() on private volume when its state is unmountable. Bug: 130203877 Test: 1) Insert sdcard as "portable" storage. 2) Format it as "phone" storage. 3) Remove the sdcard while format is in progress. 4) Insert sdcard again -> blkid may fail to id the sdcard. In such case, the fsUuid of the private-volume will be reported as "". 5) Open "Storage Settings". Settings app crashes: FATAL EXCEPTION: main Process: com.android.settings, PID: 3700 ... Caused by: java.lang.IllegalArgumentException: Invalid UUID string: at java.util.UUID.fromString(UUID.java:194) at android.os.storage.StorageManager.convert(StorageManager.java:2139) at android.app.usage.StorageStatsManager.getTotalBytes(StorageStatsManager.java:121) at com.android.settingslib.deviceinfo.PrivateStorageInfo.getTotalSize(PrivateStorageInfo.java:64) However, with this CL, "Storage Settings" can be opened and the private volume's state is correctly reflected as "Corrupted". User can choose to format the volume again. Copyright (c) 2019 Qualcomm Innovation Center, Inc. All Rights Reserved. Change-Id: I764603b5806f43f0c6d398f9d6803646774cd912 --- .../settings/deviceinfo/StorageSettings.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java index a24f82b3535..e791168de06 100644 --- a/src/com/android/settings/deviceinfo/StorageSettings.java +++ b/src/com/android/settings/deviceinfo/StorageSettings.java @@ -150,8 +150,6 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index mInternalCategory.addPreference(mInternalSummary); - int privateCount = 0; - final StorageManagerVolumeProvider smvp = new StorageManagerVolumeProvider(mStorageManager); final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(smvp); final long privateTotalBytes = info.totalBytes; @@ -162,10 +160,16 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index for (VolumeInfo vol : volumes) { if (vol.getType() == VolumeInfo.TYPE_PRIVATE) { - final long volumeTotalBytes = PrivateStorageInfo.getTotalSize(vol, - sTotalInternalStorage); - mInternalCategory.addPreference( - new StorageVolumePreference(context, vol, volumeTotalBytes)); + + if (vol.getState() == VolumeInfo.STATE_UNMOUNTABLE) { + mInternalCategory.addPreference( + new StorageVolumePreference(context, vol, 0)); + } else { + final long volumeTotalBytes = PrivateStorageInfo.getTotalSize(vol, + sTotalInternalStorage); + mInternalCategory.addPreference( + new StorageVolumePreference(context, vol, volumeTotalBytes)); + } } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC || vol.getType() == VolumeInfo.TYPE_STUB) { mExternalCategory.addPreference(