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:
@@ -2562,6 +2562,8 @@
|
||||
<string name="storage_detail_cached">Cached data</string>
|
||||
<!-- Item title describing storage used by other data [CHAR LIMIT=48]-->
|
||||
<string name="storage_detail_other">Other</string>
|
||||
<!-- Item title describing internal storage used by the Android System [CHAR LIMIT=48]-->
|
||||
<string name="storage_detail_system">System</string>
|
||||
<!-- Item title that will launch a file explorer [CHAR LIMIT=48]-->
|
||||
<string name="storage_detail_explore">Explore <xliff:g id="name" example="SD card">^1</xliff:g></string>
|
||||
|
||||
@@ -2569,6 +2571,10 @@
|
||||
<string name="storage_detail_dialog_other">Other includes shared files saved by apps, files downloaded from the Internet or Bluetooth, Android files, and so on.
|
||||
\n\nTo see the entire contents of this <xliff:g id="name" example="SD card">^1</xliff:g>, tap Explore.</string>
|
||||
|
||||
<!-- Body of dialog informing user about the storage used by the Android System [CHAR LIMIT=NONE]-->
|
||||
<string name="storage_detail_dialog_system">System includes files used internally by the Android operating system.
|
||||
\n\nThese files can\u2019t be viewed individually.</string>
|
||||
|
||||
<!-- Body of dialog informing user about other users on a storage device [CHAR LIMIT=NONE]-->
|
||||
<string name="storage_detail_dialog_user"><xliff:g id="user" example="Guest user">^1</xliff:g> may have saved photos, music, movies, apps, or other data that is taking up <xliff:g id="size" example="1.2 GB">^2</xliff:g> of storage.
|
||||
\n\nTo view details, switch to <xliff:g id="user" example="Guest user">^1</xliff:g>.</string>
|
||||
|
@@ -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;
|
||||
|
@@ -42,6 +42,7 @@ import android.text.format.Formatter;
|
||||
import android.text.format.Formatter.BytesResult;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
@@ -50,7 +51,6 @@ import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||
|
||||
@@ -88,6 +88,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
||||
private PreferenceCategory mExternalCategory;
|
||||
|
||||
private StorageSummaryPreference mInternalSummary;
|
||||
private static long sTotalInternalStorage;
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
@@ -108,6 +109,8 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
||||
mStorageManager = context.getSystemService(StorageManager.class);
|
||||
mStorageManager.registerListener(mStorageListener);
|
||||
|
||||
sTotalInternalStorage = mStorageManager.getPrimaryStorageSize();
|
||||
|
||||
addPreferencesFromResource(R.xml.device_info_storage);
|
||||
|
||||
mInternalCategory = (PreferenceCategory) findPreference("storage_internal");
|
||||
@@ -162,15 +165,16 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
||||
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||
final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
|
||||
mInternalCategory.addPreference(
|
||||
new StorageVolumePreference(context, vol, color));
|
||||
new StorageVolumePreference(context, vol, color, sTotalInternalStorage));
|
||||
if (vol.isMountedReadable()) {
|
||||
final File path = vol.getPath();
|
||||
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
|
||||
privateTotalBytes += path.getTotalSpace();
|
||||
privateTotalBytes += sTotalInternalStorage > 0
|
||||
? sTotalInternalStorage : path.getTotalSpace();
|
||||
}
|
||||
} else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
|
||||
mExternalCategory.addPreference(
|
||||
new StorageVolumePreference(context, vol, COLOR_PUBLIC));
|
||||
new StorageVolumePreference(context, vol, COLOR_PUBLIC, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +228,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
||||
// Only showing primary internal storage, so just shortcut
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
|
||||
PrivateVolumeSettings.setVolumeSize(args, sTotalInternalStorage);
|
||||
Intent intent = Utils.onBuildStartFragmentIntent(getActivity(),
|
||||
PrivateVolumeSettings.class.getName(), args, null, R.string.apps_storage, null,
|
||||
false);
|
||||
@@ -268,6 +273,7 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
||||
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||
PrivateVolumeSettings.setVolumeSize(args, sTotalInternalStorage);
|
||||
startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
|
||||
-1, 0, args);
|
||||
return true;
|
||||
@@ -491,8 +497,12 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
||||
continue;
|
||||
}
|
||||
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
|
||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
|
||||
privateTotalBytes = sTotalInternalStorage;
|
||||
} else {
|
||||
privateTotalBytes += path.getTotalSpace();
|
||||
}
|
||||
}
|
||||
mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
|
||||
Formatter.formatFileSize(mContext, privateUsedBytes),
|
||||
Formatter.formatFileSize(mContext, privateTotalBytes)));
|
||||
|
@@ -46,7 +46,8 @@ public class StorageVolumePreference extends Preference {
|
||||
private int mColor;
|
||||
private int mUsedPercent = -1;
|
||||
|
||||
public StorageVolumePreference(Context context, VolumeInfo volume, int color) {
|
||||
// TODO: ideally, VolumeInfo should have a total physical size.
|
||||
public StorageVolumePreference(Context context, VolumeInfo volume, int color, long totalBytes) {
|
||||
super(context);
|
||||
|
||||
mStorageManager = context.getSystemService(StorageManager.class);
|
||||
@@ -68,8 +69,10 @@ public class StorageVolumePreference extends Preference {
|
||||
if (volume.isMountedReadable()) {
|
||||
// TODO: move statfs() to background thread
|
||||
final File path = volume.getPath();
|
||||
if (totalBytes <= 0) {
|
||||
totalBytes = path.getTotalSpace();
|
||||
}
|
||||
final long freeBytes = path.getFreeSpace();
|
||||
final long totalBytes = path.getTotalSpace();
|
||||
final long usedBytes = totalBytes - freeBytes;
|
||||
|
||||
final String used = Formatter.formatFileSize(context, usedBytes);
|
||||
|
Reference in New Issue
Block a user