Loading src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java +11 −1 Original line number Diff line number Diff line Loading @@ -105,7 +105,17 @@ public class StorageAsyncLoader continue; } long blamedSize = stats.getDataBytes() - stats.getCacheBytes(); final long dataSize = stats.getDataBytes(); final long cacheQuota = mStatsManager.getCacheQuotaBytes(mUuid, app.uid); final long cacheBytes = stats.getCacheBytes(); long blamedSize = dataSize; // Technically, we could overages as freeable on the storage settings screen. // If the app is using more cache than its quota, we would accidentally subtract the // overage from the system size (because it shows up as unused) during our attribution. // Thus, we cap the attribution at the quota size. if (cacheQuota < cacheBytes) { blamedSize = blamedSize - cacheBytes + cacheQuota; } // This isn't quite right because it slams the first user by user id with the whole code // size, but this ensures that we count all apps seen once. Loading tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java +18 −4 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; import android.net.TrafficStats; import android.os.UserHandle; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; Loading @@ -55,6 +56,7 @@ public class StorageAsyncLoaderTest { private static final int SECONDARY_USER_ID = 10; private static final String PACKAGE_NAME_1 = "com.blah.test"; private static final String PACKAGE_NAME_2 = "com.blah.test2"; private static final long DEFAULT_QUOTA = 64 * TrafficStats.MB_IN_BYTES; @Mock private StorageStatsSource mSource; Loading @@ -81,6 +83,7 @@ public class StorageAsyncLoaderTest { mUsers = new ArrayList<>(); mUsers.add(info); when(mUserManager.getUsers()).thenReturn(mUsers); when(mSource.getCacheQuotaBytes(anyString(), anyInt())).thenReturn(DEFAULT_QUOTA); } @Test Loading Loading @@ -120,13 +123,13 @@ public class StorageAsyncLoaderTest { } @Test public void testCacheIsIgnored() throws Exception { public void testCacheIsNotIgnored() throws Exception { addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED); SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); assertThat(result.size()).isEqualTo(1); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L); } @Test Loading Loading @@ -155,7 +158,7 @@ public class StorageAsyncLoaderTest { SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); assertThat(result.size()).isEqualTo(1); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L); } @Test Loading Loading @@ -207,12 +210,23 @@ public class StorageAsyncLoaderTest { assertThat(result.get(SECONDARY_USER_ID).videoAppsSize).isEqualTo(10L); } @Test public void testCacheOveragesAreCountedAsFree() throws Exception { addPackage(PACKAGE_NAME_1, DEFAULT_QUOTA + 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED); SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); assertThat(result.size()).isEqualTo(1); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(DEFAULT_QUOTA + 11); } private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize, long dataSize, int category) throws Exception { StorageStatsSource.AppStorageStats storageStats = mock(StorageStatsSource.AppStorageStats.class); when(storageStats.getCodeBytes()).thenReturn(codeSize); when(storageStats.getDataBytes()).thenReturn(dataSize); when(storageStats.getDataBytes()).thenReturn(dataSize + cacheSize); when(storageStats.getCacheBytes()).thenReturn(cacheSize); when(mSource.getStatsForPackage(anyString(), eq(packageName), any(UserHandle.class))) .thenReturn(storageStats); Loading Loading
src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java +11 −1 Original line number Diff line number Diff line Loading @@ -105,7 +105,17 @@ public class StorageAsyncLoader continue; } long blamedSize = stats.getDataBytes() - stats.getCacheBytes(); final long dataSize = stats.getDataBytes(); final long cacheQuota = mStatsManager.getCacheQuotaBytes(mUuid, app.uid); final long cacheBytes = stats.getCacheBytes(); long blamedSize = dataSize; // Technically, we could overages as freeable on the storage settings screen. // If the app is using more cache than its quota, we would accidentally subtract the // overage from the system size (because it shows up as unused) during our attribution. // Thus, we cap the attribution at the quota size. if (cacheQuota < cacheBytes) { blamedSize = blamedSize - cacheBytes + cacheQuota; } // This isn't quite right because it slams the first user by user id with the whole code // size, but this ensures that we count all apps seen once. Loading
tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java +18 −4 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; import android.net.TrafficStats; import android.os.UserHandle; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; Loading @@ -55,6 +56,7 @@ public class StorageAsyncLoaderTest { private static final int SECONDARY_USER_ID = 10; private static final String PACKAGE_NAME_1 = "com.blah.test"; private static final String PACKAGE_NAME_2 = "com.blah.test2"; private static final long DEFAULT_QUOTA = 64 * TrafficStats.MB_IN_BYTES; @Mock private StorageStatsSource mSource; Loading @@ -81,6 +83,7 @@ public class StorageAsyncLoaderTest { mUsers = new ArrayList<>(); mUsers.add(info); when(mUserManager.getUsers()).thenReturn(mUsers); when(mSource.getCacheQuotaBytes(anyString(), anyInt())).thenReturn(DEFAULT_QUOTA); } @Test Loading Loading @@ -120,13 +123,13 @@ public class StorageAsyncLoaderTest { } @Test public void testCacheIsIgnored() throws Exception { public void testCacheIsNotIgnored() throws Exception { addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED); SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); assertThat(result.size()).isEqualTo(1); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L); } @Test Loading Loading @@ -155,7 +158,7 @@ public class StorageAsyncLoaderTest { SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); assertThat(result.size()).isEqualTo(1); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(11L); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L); } @Test Loading Loading @@ -207,12 +210,23 @@ public class StorageAsyncLoaderTest { assertThat(result.get(SECONDARY_USER_ID).videoAppsSize).isEqualTo(10L); } @Test public void testCacheOveragesAreCountedAsFree() throws Exception { addPackage(PACKAGE_NAME_1, DEFAULT_QUOTA + 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED); SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); assertThat(result.size()).isEqualTo(1); assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(DEFAULT_QUOTA + 11); } private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize, long dataSize, int category) throws Exception { StorageStatsSource.AppStorageStats storageStats = mock(StorageStatsSource.AppStorageStats.class); when(storageStats.getCodeBytes()).thenReturn(codeSize); when(storageStats.getDataBytes()).thenReturn(dataSize); when(storageStats.getDataBytes()).thenReturn(dataSize + cacheSize); when(storageStats.getCacheBytes()).thenReturn(cacheSize); when(mSource.getStatsForPackage(anyString(), eq(packageName), any(UserHandle.class))) .thenReturn(storageStats); Loading