Query storage size instead of calculate size of installed APP

From android S, Storage Settings show files of images/videos/audios
category instead of installed APP of each category. So it's
necessary to change the way to calculate size information.

This change also
- StorageItemPreference shows changing storage size units instead
  of fixed GB. It helps UX for categories of only small size files.
- Query media provider for size of Documents and others.
- Query media provider for size of Trash.

Bug: 170918505
Bug: 177892478
Bug: 179871408
Bug: 184379946
Bug: 186077224
Bug: 187128447
Test: atest com.android.settings.deviceinfo
      atest com.android.settings.deviceinfo.storage
      make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo
      make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo.storage
      manual visual
      Click each file category to count files size is the same as
      displayed in Storage Settings.
Change-Id: I37c7b3a4b5860323cb55581b23a90f583f4af216
This commit is contained in:
Arc Wang
2021-05-17 15:52:51 +08:00
parent 24f2dda922
commit 044c91cc70
13 changed files with 279 additions and 286 deletions

View File

@@ -17,7 +17,8 @@
package com.android.settings.deviceinfo;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.widget.ProgressBar;
@@ -25,7 +26,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.utils.FileSizeFormatter;
public class StorageItemPreference extends Preference {
public int userHandle;
@@ -49,12 +49,8 @@ public class StorageItemPreference extends Preference {
public void setStorageSize(long size, long total) {
mStorageSize = size;
setSummary(
FileSizeFormatter.formatFileSize(
getContext(),
size,
getGigabyteSuffix(getContext().getResources()),
FileSizeFormatter.GIGABYTE_IN_BYTES));
setSummary(getStorageSummary(size));
if (total == 0) {
mProgressPercent = 0;
} else {
@@ -82,7 +78,10 @@ public class StorageItemPreference extends Preference {
super.onBindViewHolder(view);
}
private static int getGigabyteSuffix(Resources res) {
return res.getIdentifier("gigabyteShort", "string", "android");
private String getStorageSummary(long bytes) {
final Formatter.BytesResult result = Formatter.formatBytes(getContext().getResources(),
bytes, Formatter.FLAG_SHORTER);
return TextUtils.expandTemplate(getContext().getText(R.string.storage_size_large),
result.value, result.units).toString();
}
}