Display total storage for Internal shared storage.

Prior to this change, Settings was using
volume.getPath().getTotalBytes() to calculate the total, which includes
the user-accessible storage, but not the internal partitions. As such,
the total displayed was often missing many GBs (for example, in a 32GB
device, it could display "12.09GB of 25.01GB used".

This change fix this problem by using the total size and creating a
"System" section containing the "missing" storage.

BUG: 24128505

Change-Id: Ic35cd7c8406eff16ac1d97c4b4c233ecde64a6e1

** Cherrypicked from master - DO NOT MERGE **
This commit is contained in:
Felipe Leme
2016-05-11 13:58:41 -07:00
parent e8fce6d433
commit ff162a3c23
4 changed files with 81 additions and 15 deletions

View File

@@ -84,13 +84,17 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
private static final String TAG_RENAME = "rename";
private static final String TAG_OTHER_INFO = "otherInfo";
private static final String TAG_SYSTEM_INFO = "systemInfo";
private static final String TAG_USER_INFO = "userInfo";
private static final String TAG_CONFIRM_CLEAR_CACHE = "confirmClearCache";
private static final String EXTRA_VOLUME_SIZE = "volume_size";
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
private static final int[] ITEMS_NO_SHOW_SHARED = new int[] {
R.string.storage_detail_apps,
R.string.storage_detail_system,
};
private static final int[] ITEMS_SHOW_SHARED = new int[] {
@@ -98,7 +102,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
R.string.storage_detail_images,
R.string.storage_detail_videos,
R.string.storage_detail_audio,
R.string.storage_detail_other
R.string.storage_detail_system,
R.string.storage_detail_other,
};
private static final int DELETION_HELPER_SETTINGS = 1;
@@ -110,6 +115,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
private String mVolumeId;
private VolumeInfo mVolume;
private VolumeInfo mSharedVolume;
private long mTotalSize;
private long mSystemSize;
private StorageMeasurement mMeasure;
@@ -152,6 +159,14 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
mVolumeId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
mVolume = mStorageManager.findVolumeById(mVolumeId);
final long sharedDataSize = mVolume.getPath().getTotalSpace();
mTotalSize = getArguments().getLong(EXTRA_VOLUME_SIZE, 0);
mSystemSize = mTotalSize - sharedDataSize;
if (mTotalSize <= 0) {
mTotalSize = sharedDataSize;
mSystemSize = 0;
}
// Find the emulated shared storage layered above this private volume
mSharedVolume = mStorageManager.findEmulatedForPrivate(mVolume);
@@ -240,17 +255,15 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
addPreference(screen, mExplore);
}
final File file = mVolume.getPath();
final long totalBytes = file.getTotalSpace();
final long freeBytes = file.getFreeSpace();
final long usedBytes = totalBytes - freeBytes;
final long freeBytes = mVolume.getPath().getFreeSpace();
final long usedBytes = mTotalSize - freeBytes;
final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
result.value, result.units));
mSummary.setSummary(getString(R.string.storage_volume_used,
Formatter.formatFileSize(context, totalBytes)));
mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
Formatter.formatFileSize(context, mTotalSize)));
mSummary.setPercent((int) ((usedBytes * 100) / mTotalSize));
mMeasure.forceMeasure();
mNeedsUpdate = false;
@@ -285,6 +298,10 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
}
private void addItem(PreferenceGroup group, int titleRes, CharSequence title, int userId) {
if (titleRes == R.string.storage_detail_system && mSystemSize <= 0) {
Log.w(TAG, "Skipping System storage because its size is " + mSystemSize);
return;
}
StorageItemPreference item;
if (mItemPoolIndex < mItemPreferencePool.size()) {
item = mItemPreferencePool.get(mItemPoolIndex);
@@ -317,6 +334,10 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
return pref;
}
static void setVolumeSize(Bundle args, long size) {
args.putLong(EXTRA_VOLUME_SIZE, size);
}
@Override
public void onResume() {
super.onResume();
@@ -471,6 +492,11 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
intent.addCategory(Intent.CATEGORY_DEFAULT);
} break;
case R.string.storage_detail_system: {
SystemInfoFragment.show(this);
return true;
}
case R.string.storage_detail_other: {
OtherInfoFragment.show(this, mStorageManager.getBestVolumeDescription(mVolume),
mSharedVolume);
@@ -541,6 +567,9 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
itemTitleId = 0;
}
switch (itemTitleId) {
case R.string.storage_detail_system: {
updatePreference(item, mSystemSize);
} break;
case R.string.storage_detail_apps: {
updatePreference(item, details.appsSize.get(userId));
} break;
@@ -577,7 +606,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
}
private void updatePreference(StorageItemPreference pref, long size) {
pref.setStorageSize(size, mVolume.getPath().getTotalSpace());
pref.setStorageSize(size, mTotalSize);
}
private boolean isProfileOf(UserInfo user, UserInfo profile) {
@@ -668,6 +697,24 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
}
}
public static class SystemInfoFragment extends DialogFragment {
public static void show(Fragment parent) {
if (!parent.isAdded()) return;
final SystemInfoFragment dialog = new SystemInfoFragment();
dialog.setTargetFragment(parent, 0);
dialog.show(parent.getFragmentManager(), TAG_SYSTEM_INFO);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setMessage(R.string.storage_detail_dialog_system)
.setPositiveButton(android.R.string.ok, null)
.create();
}
}
public static class OtherInfoFragment extends DialogFragment {
public static void show(Fragment parent, String title, VolumeInfo sharedVol) {
if (!parent.isAdded()) return;