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
This commit is contained in:
Shibin George
2019-04-09 16:46:20 +05:30
committed by Fan Zhang
parent 8b3cde0fb1
commit a2f013dacb

View File

@@ -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(