• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

修訂b22b85b593f63d38d29718ecd37e6a260011584e (tree)
時間2017-06-23 11:08:48
作者Daniel Nishi <dhnishi@goog...>
CommiterDaniel Nishi

Log Message

Count cache in storage categories.

This makes the System size more consistent because cache is not
attributed to the system (when the cache is under quota).

Change-Id: I680e70daf5e98b9a205023a218dfd1dcc8ee8334
Fixes: 62623731
Test: Settings Unit Test

Change Summary

差異

--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -105,7 +105,17 @@ public class StorageAsyncLoader
105105 continue;
106106 }
107107
108- long blamedSize = stats.getDataBytes() - stats.getCacheBytes();
108+ final long dataSize = stats.getDataBytes();
109+ final long cacheQuota = mStatsManager.getCacheQuotaBytes(mUuid, app.uid);
110+ final long cacheBytes = stats.getCacheBytes();
111+ long blamedSize = dataSize;
112+ // Technically, we could overages as freeable on the storage settings screen.
113+ // If the app is using more cache than its quota, we would accidentally subtract the
114+ // overage from the system size (because it shows up as unused) during our attribution.
115+ // Thus, we cap the attribution at the quota size.
116+ if (cacheQuota < cacheBytes) {
117+ blamedSize = blamedSize - cacheBytes + cacheQuota;
118+ }
109119
110120 // This isn't quite right because it slams the first user by user id with the whole code
111121 // size, but this ensures that we count all apps seen once.
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -29,6 +29,7 @@ import android.content.Context;
2929 import android.content.pm.ApplicationInfo;
3030 import android.content.pm.PackageManager.NameNotFoundException;
3131 import android.content.pm.UserInfo;
32+import android.net.TrafficStats;
3233 import android.os.UserHandle;
3334 import android.support.test.filters.SmallTest;
3435 import android.support.test.runner.AndroidJUnit4;
@@ -55,6 +56,7 @@ public class StorageAsyncLoaderTest {
5556 private static final int SECONDARY_USER_ID = 10;
5657 private static final String PACKAGE_NAME_1 = "com.blah.test";
5758 private static final String PACKAGE_NAME_2 = "com.blah.test2";
59+ private static final long DEFAULT_QUOTA = 64 * TrafficStats.MB_IN_BYTES;
5860
5961 @Mock
6062 private StorageStatsSource mSource;
@@ -81,6 +83,7 @@ public class StorageAsyncLoaderTest {
8183 mUsers = new ArrayList<>();
8284 mUsers.add(info);
8385 when(mUserManager.getUsers()).thenReturn(mUsers);
86+ when(mSource.getCacheQuotaBytes(anyString(), anyInt())).thenReturn(DEFAULT_QUOTA);
8487 }
8588
8689 @Test
@@ -120,13 +123,13 @@ public class StorageAsyncLoaderTest {
120123 }
121124
122125 @Test
123- public void testCacheIsIgnored() throws Exception {
126+ public void testCacheIsNotIgnored() throws Exception {
124127 addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
125128
126129 SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
127130
128131 assertThat(result.size()).isEqualTo(1);
129- assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L);
132+ assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L);
130133 }
131134
132135 @Test
@@ -155,7 +158,7 @@ public class StorageAsyncLoaderTest {
155158 SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
156159
157160 assertThat(result.size()).isEqualTo(1);
158- assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L);
161+ assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L);
159162 }
160163
161164 @Test
@@ -207,12 +210,23 @@ public class StorageAsyncLoaderTest {
207210 assertThat(result.get(SECONDARY_USER_ID).videoAppsSize).isEqualTo(10L);
208211 }
209212
213+ @Test
214+ public void testCacheOveragesAreCountedAsFree() throws Exception {
215+ addPackage(PACKAGE_NAME_1, DEFAULT_QUOTA + 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
216+
217+ SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
218+
219+ assertThat(result.size()).isEqualTo(1);
220+ assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(DEFAULT_QUOTA + 11);
221+ }
222+
210223 private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,
211224 long dataSize, int category) throws Exception {
212225 StorageStatsSource.AppStorageStats storageStats =
213226 mock(StorageStatsSource.AppStorageStats.class);
214227 when(storageStats.getCodeBytes()).thenReturn(codeSize);
215- when(storageStats.getDataBytes()).thenReturn(dataSize);
228+ when(storageStats.getDataBytes()).thenReturn(dataSize + cacheSize);
229+ when(storageStats.getCacheBytes()).thenReturn(cacheSize);
216230 when(mSource.getStatsForPackage(anyString(), eq(packageName), any(UserHandle.class)))
217231 .thenReturn(storageStats);
218232