Remove the cache size from internal size.

Because the system can automatically clear away cache data, we remove
usage of it from the list of app storage usage in Settings. This should
encourage developers to more aggressively use the unattributed cache,
rather than the attributed regular data folder.

This affects the following fields on the AppEntry: internalSize & str
and size & sizeStr (which are derived from the internal size).

Currently, ApplicationsState.AppEntry.internalSize, externalSize, and
size are only used in the Settings apps so this shouldn't have broader
implications.

Test: Manual verification of Other Apps page
Fixes: 131152171
Change-Id: I3eb2e28701490a543c633e9c95a280059bb99c21
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
index e02709e..5eaa163 100644
--- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
+++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
@@ -707,7 +707,9 @@
 
     private long getTotalInternalSize(PackageStats ps) {
         if (ps != null) {
-            return ps.codeSize + ps.dataSize;
+            // We subtract the cache size because the system can clear it automatically and
+            // |dataSize| is a superset of |cacheSize|.
+            return ps.codeSize + ps.dataSize - ps.cacheSize;
         }
         return SIZE_INVALID;
     }
@@ -715,7 +717,7 @@
     private long getTotalExternalSize(PackageStats ps) {
         if (ps != null) {
             // We also include the cache size here because for non-emulated
-            // we don't automtically clean cache files.
+            // we don't automatically clean cache files.
             return ps.externalCodeSize + ps.externalDataSize
                     + ps.externalCacheSize
                     + ps.externalMediaSize + ps.externalObbSize;
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java
index b27efd0..f8697a1 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ApplicationsStateRoboTest.java
@@ -191,8 +191,9 @@
         shadowContext.setSystemService(Context.STORAGE_STATS_SERVICE, mStorageStatsManager);
         StorageStats storageStats = new StorageStats();
         storageStats.codeBytes = 10;
-        storageStats.dataBytes = 20;
         storageStats.cacheBytes = 30;
+        // Data bytes are a superset of cache bytes.
+        storageStats.dataBytes = storageStats.cacheBytes + 20;
         when(mStorageStatsManager.queryStatsForPackage(any(UUID.class),
             anyString(), any(UserHandle.class))).thenReturn(storageStats);