diff --git a/res/values/strings.xml b/res/values/strings.xml index eb882102a20..e4d5bccf9af 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2562,6 +2562,8 @@ Cached data Other + + System Explore ^1 @@ -2569,6 +2571,10 @@ 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 ^1, tap Explore. + + System includes files used internally by the Android operating system. +\n\nThese files can\u2019t be viewed individually. + ^1 may have saved photos, music, movies, apps, or other data that is taking up ^2 of storage. \n\nTo view details, switch to ^1. diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java index cdb0a0223a9..41ae5feaa78 100644 --- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java +++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java @@ -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; diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java index 5ae3986049e..8f0e91b2363 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; 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,7 +497,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index 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 dba636c69cb..2ef42fa7b33 100644 --- a/src/com/android/settings/deviceinfo/StorageVolumePreference.java +++ b/src/com/android/settings/deviceinfo/StorageVolumePreference.java @@ -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);