Correct used size of Storage Settings.

Since StorageManager rounded the totalBytes of device storage but
they don't do that rounding for freeBytes.
So in some cases the freeBytes can be greater than totalBytes.

We propose to get totalBytes of device storage directly to calculate
correct privateUsedBytes.

Test: robotest
Bug: 281955532
Change-Id: I4f137c20e7c2f54f4e037d50e81b3176edc1a83a
This commit is contained in:
Edgar Wang
2023-05-31 18:42:11 +08:00
parent 0df79b1ccc
commit e52320e755
5 changed files with 28 additions and 6 deletions

View File

@@ -74,10 +74,14 @@ public class TopLevelStoragePreferenceController extends BasePreferenceControlle
return ThreadUtils.postOnBackgroundThread(() -> {
final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
getStorageManagerVolumeProvider());
storageCacheHelper.cacheUsedSize(info.totalBytes - info.freeBytes);
// TODO(b/288103116): replace with new API to get TotalBytes before rounding
// once support by StorageManager.
long usedBytes = Utils.getPrimaryStorageSize() - info.freeBytes;
storageCacheHelper.cacheUsedSize(usedBytes);
ThreadUtils.postOnMainThread(() -> {
preference.setSummary(
getSummary(info.totalBytes - info.freeBytes, info.totalBytes));
getSummary(usedBytes, info.totalBytes));
});
});
}