Loading src/com/android/settings/deviceinfo/StorageDashboardFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public class StorageDashboardFragment extends DashboardFragment @Override public void onResume() { super.onResume(); getLoaderManager().initLoader(STORAGE_JOB_ID, Bundle.EMPTY, this); getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this); getLoaderManager().initLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks()); } Loading src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java +9 −2 Original line number Diff line number Diff line Loading @@ -79,8 +79,15 @@ public class StorageAsyncLoader UserHandle myUser = UserHandle.of(userId); for (int i = 0, size = applicationInfos.size(); i < size; i++) { ApplicationInfo app = applicationInfos.get(i); StorageStatsSource.AppStorageStats stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser); StorageStatsSource.AppStorageStats stats; try { stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser); } catch (IllegalStateException e) { // This may happen if the package was removed during our calculation. Log.w("App unexpectedly not found", e); continue; } long attributedAppSizeInBytes = stats.getDataBytes(); // This matches how the package manager calculates sizes -- by zeroing out code sizes of Loading tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,20 @@ public class StorageAsyncLoaderTest { assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0); } @Test public void testRemovedPackageDoesNotCrash() throws Exception { ApplicationInfo info = new ApplicationInfo(); info.packageName = PACKAGE_NAME_1; info.category = ApplicationInfo.CATEGORY_UNDEFINED; mInfo.add(info); when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class))) .thenThrow(new IllegalStateException()); SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); // Should not crash. } private ApplicationInfo addPackage( String packageName, long cacheSize, long codeSize, long dataSize, int category) { StorageStatsSource.AppStorageStats storageStats = Loading Loading
src/com/android/settings/deviceinfo/StorageDashboardFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public class StorageDashboardFragment extends DashboardFragment @Override public void onResume() { super.onResume(); getLoaderManager().initLoader(STORAGE_JOB_ID, Bundle.EMPTY, this); getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this); getLoaderManager().initLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks()); } Loading
src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java +9 −2 Original line number Diff line number Diff line Loading @@ -79,8 +79,15 @@ public class StorageAsyncLoader UserHandle myUser = UserHandle.of(userId); for (int i = 0, size = applicationInfos.size(); i < size; i++) { ApplicationInfo app = applicationInfos.get(i); StorageStatsSource.AppStorageStats stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser); StorageStatsSource.AppStorageStats stats; try { stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser); } catch (IllegalStateException e) { // This may happen if the package was removed during our calculation. Log.w("App unexpectedly not found", e); continue; } long attributedAppSizeInBytes = stats.getDataBytes(); // This matches how the package manager calculates sizes -- by zeroing out code sizes of Loading
tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,20 @@ public class StorageAsyncLoaderTest { assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0); } @Test public void testRemovedPackageDoesNotCrash() throws Exception { ApplicationInfo info = new ApplicationInfo(); info.packageName = PACKAGE_NAME_1; info.category = ApplicationInfo.CATEGORY_UNDEFINED; mInfo.add(info); when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class))) .thenThrow(new IllegalStateException()); SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground(); // Should not crash. } private ApplicationInfo addPackage( String packageName, long cacheSize, long codeSize, long dataSize, int category) { StorageStatsSource.AppStorageStats storageStats = Loading