Merge "Display total storage for Internal shared storage." into nyc-mr1-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index eb88210..e4d5bcc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -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>
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index cdb0a02..41ae5fe 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -84,13 +84,17 @@
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 @@
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 @@
private String mVolumeId;
private VolumeInfo mVolume;
private VolumeInfo mSharedVolume;
+ private long mTotalSize;
+ private long mSystemSize;
private StorageMeasurement mMeasure;
@@ -152,6 +159,14 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
}
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 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;
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index 5ae3986..8f0e91b 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -42,6 +42,7 @@
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.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 @@
private PreferenceCategory mExternalCategory;
private StorageSummaryPreference mInternalSummary;
+ private static long sTotalInternalStorage;
@Override
protected int getMetricsCategory() {
@@ -108,6 +109,8 @@
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 @@
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 @@
// 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 @@
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,7 +497,11 @@
continue;
}
privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
- privateTotalBytes += path.getTotalSpace();
+ 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),
diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreference.java b/src/com/android/settings/deviceinfo/StorageVolumePreference.java
index dba636c..2ef42fa 100644
--- a/src/com/android/settings/deviceinfo/StorageVolumePreference.java
+++ b/src/com/android/settings/deviceinfo/StorageVolumePreference.java
@@ -46,7 +46,8 @@
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 @@
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);