OSDN Git Service

Improved storage accounting:
authorFelipe Leme <felipeal@google.com>
Tue, 30 Aug 2016 22:06:24 +0000 (15:06 -0700)
committerFelipe Leme <felipeal@google.com>
Tue, 13 Sep 2016 17:49:34 +0000 (10:49 -0700)
- Removed duplicated entry for DIRECTORY_MOVIES.
- Added DIRECTORY_DOWNLOADS to Other.
- Added unaccounted data to Other.
- Changed Other description so it mention non-visible items.

Often sub-directories of /data are populated with data that Settings
doesn't have control of (for example, on /data/ramdump), so they're more
suitable to be displayed in the "Other" section.

BUG: 31091863
Fixes: 30952263

Change-Id: Ibf54f9dd96456575109e2e281f3780da84f70d92

res/values/strings.xml
src/com/android/settings/deviceinfo/PrivateVolumeSettings.java

index 1bd5283..f5d53ce 100644 (file)
 
     <!-- Body of dialog informing user about other files on a storage device [CHAR LIMIT=NONE]-->
     <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>
+\n\nTo see the visible 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>
+    <string name="storage_detail_dialog_system">System includes files that Android can\u2019t display 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.
index 94b1937..efb1e0f 100644 (file)
@@ -72,8 +72,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Objects;
 
-import static com.android.settings.deviceinfo.StorageSettings.TAG;
-
 /**
  * Panel showing summary and actions for a {@link VolumeInfo#TYPE_PRIVATE}
  * storage volume.
@@ -82,6 +80,9 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
     // TODO: disable unmount when providing over MTP/PTP
     // TODO: warn when mounted read-only
 
+    private static final String TAG = "PrivateVolumeSettings";
+    private static final boolean LOGV = false;
+
     private static final String TAG_RENAME = "rename";
     private static final String TAG_OTHER_INFO = "otherInfo";
     private static final String TAG_SYSTEM_INFO = "systemInfo";
@@ -164,6 +165,9 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
         final long sharedDataSize = mVolume.getPath().getTotalSpace();
         mTotalSize = getArguments().getLong(EXTRA_VOLUME_SIZE, 0);
         mSystemSize = mTotalSize - sharedDataSize;
+        if (LOGV) Log.v(TAG,
+                "onCreate() mTotalSize: " + mTotalSize + " sharedDataSize: " + sharedDataSize);
+
         if (mTotalSize <= 0) {
             mTotalSize = sharedDataSize;
             mSystemSize = 0;
@@ -260,6 +264,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
         final long freeBytes = mVolume.getPath().getFreeSpace();
         final long usedBytes = mTotalSize - freeBytes;
 
+        if (LOGV) Log.v(TAG, "update() freeBytes: " + freeBytes + " usedBytes: " + usedBytes);
+
         final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
         mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
                 result.value, result.units));
@@ -554,6 +560,11 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
     };
 
     private void updateDetails(MeasurementDetails details) {
+        StorageItemPreference otherItem = null;
+        long accountedSize = 0;
+        long totalMiscSize = 0;
+        long totalDownloadsSize = 0;
+
         for (int i = 0; i < mItemPoolIndex; ++i) {
             StorageItemPreference item = mItemPreferencePool.get(i);
             final int userId = item.userHandle;
@@ -566,20 +577,31 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
             switch (itemTitleId) {
                 case R.string.storage_detail_system: {
                     updatePreference(item, mSystemSize);
+                    accountedSize += mSystemSize;
+                    if (LOGV) Log.v(TAG, "mSystemSize: " + mSystemSize
+                            + " accountedSize: " + accountedSize);
                 } break;
                 case R.string.storage_detail_apps: {
                     updatePreference(item, details.appsSize.get(userId));
+                    accountedSize += details.appsSize.get(userId);
+                    if (LOGV) Log.v(TAG, "appsSize: " + details.appsSize.get(userId)
+                            + " accountedSize: " + accountedSize);
                 } break;
                 case R.string.storage_detail_images: {
                     final long imagesSize = totalValues(details, userId,
-                            Environment.DIRECTORY_DCIM, Environment.DIRECTORY_MOVIES,
-                            Environment.DIRECTORY_PICTURES);
+                            Environment.DIRECTORY_DCIM, Environment.DIRECTORY_PICTURES);
                     updatePreference(item, imagesSize);
+                    accountedSize += imagesSize;
+                    if (LOGV) Log.v(TAG, "imagesSize: " + imagesSize
+                            + " accountedSize: " + accountedSize);
                 } break;
                 case R.string.storage_detail_videos: {
                     final long videosSize = totalValues(details, userId,
                             Environment.DIRECTORY_MOVIES);
                     updatePreference(item, videosSize);
+                    accountedSize += videosSize;
+                    if (LOGV) Log.v(TAG, "videosSize: " + videosSize
+                            + " accountedSize: " + accountedSize);
                 } break;
                 case R.string.storage_detail_audio: {
                     final long audioSize = totalValues(details, userId,
@@ -587,19 +609,54 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
                             Environment.DIRECTORY_ALARMS, Environment.DIRECTORY_NOTIFICATIONS,
                             Environment.DIRECTORY_RINGTONES, Environment.DIRECTORY_PODCASTS);
                     updatePreference(item, audioSize);
+                    accountedSize += audioSize;
+                    if (LOGV) Log.v(TAG, "audioSize: " + audioSize
+                            + " accountedSize: " + accountedSize);
                 } break;
                 case R.string.storage_detail_other: {
-                    updatePreference(item, details.miscSize.get(userId));
+                    final long downloadsSize = totalValues(details, userId,
+                            Environment.DIRECTORY_DOWNLOADS);
+                    final long miscSize = details.miscSize.get(userId);
+                    totalDownloadsSize += downloadsSize;
+                    totalMiscSize += miscSize;
+                    accountedSize += miscSize + downloadsSize;
+
+                    if (LOGV)
+                        Log.v(TAG, "miscSize for " + userId + ": " + miscSize + "(total: "
+                                + totalMiscSize + ") \ndownloadsSize: " + downloadsSize + "(total: "
+                                + totalDownloadsSize + ") accountedSize: " + accountedSize);
+
+                    // Cannot display 'Other' until all known items are accounted for.
+                    otherItem = item;
                 } break;
                 case R.string.storage_detail_cached: {
                     updatePreference(item, details.cacheSize);
+                    accountedSize += details.cacheSize;
+                    if (LOGV)
+                        Log.v(TAG, "cacheSize: " + details.cacheSize + " accountedSize: "
+                                + accountedSize);
                 } break;
                 case 0: {
                     final long userSize = details.usersSize.get(userId);
                     updatePreference(item, userSize);
+                    accountedSize += userSize;
+                    if (LOGV) Log.v(TAG, "userSize: " + userSize
+                            + " accountedSize: " + accountedSize);
                 } break;
             }
         }
+        if (otherItem != null) {
+            final long usedSize = mTotalSize - details.availSize;
+            final long unaccountedSize = usedSize - accountedSize;
+            final long otherSize = totalMiscSize + totalDownloadsSize + unaccountedSize;
+            if (LOGV)
+                Log.v(TAG, "Other items: \n\tmTotalSize: " + mTotalSize + " availSize: "
+                        + details.availSize + " usedSize: " + usedSize + "\n\taccountedSize: "
+                        + accountedSize + " unaccountedSize size: " + unaccountedSize
+                        + "\n\ttotalMiscSize: " + totalMiscSize + " totalDownloadsSize: "
+                        + totalDownloadsSize + "\n\tdetails: " + details);
+            updatePreference(otherItem, otherSize);
+        }
     }
 
     private void updatePreference(StorageItemPreference pref, long size) {