From 6f92b661a4c3d4a064d536fd466918b44fdacef1 Mon Sep 17 00:00:00 2001 From: Daniel Nishi Date: Wed, 31 May 2017 10:59:04 -0700 Subject: [PATCH] Fix a bug where cache was double-counted. Cache was being counted as cache and also as data in the app info page. This is due to a faulty assumption I made that getDataBytes() and getCacheBytes() measured distinct areas of storage (in actuality, getCacheBytes() is a subset of getDataBytes()). This improper assumption also led to the unit test being incorrect. Change-Id: I4144d50800f82feaecb7a0a8dff26be3e4f14da8 Fixes: 62182151 Test: Settings robotest & manual --- .../applications/AppStorageSettings.java | 2 +- .../applications/AppStorageSizesController.java | 3 ++- .../AppStorageSizesControllerTest.java | 16 +++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/com/android/settings/applications/AppStorageSettings.java b/src/com/android/settings/applications/AppStorageSettings.java index 5ad5e48cea2..e21ab7e12fb 100644 --- a/src/com/android/settings/applications/AppStorageSettings.java +++ b/src/com/android/settings/applications/AppStorageSettings.java @@ -543,8 +543,8 @@ public class AppStorageSettings extends AppInfoWithHeader mClearCacheButton.setEnabled(false); } else { long codeSize = result.getCodeBytes(); - long dataSize = result.getDataBytes(); long cacheSize = result.getCacheBytes(); + long dataSize = result.getDataBytes() - cacheSize; if (dataSize <= 0 || !mCanClearData || mDataCleared) { mClearDataButton.setEnabled(false); diff --git a/src/com/android/settings/applications/AppStorageSizesController.java b/src/com/android/settings/applications/AppStorageSizesController.java index 45ece6ed4f7..3626fabaf7b 100644 --- a/src/com/android/settings/applications/AppStorageSizesController.java +++ b/src/com/android/settings/applications/AppStorageSizesController.java @@ -70,7 +70,8 @@ public class AppStorageSizesController { mTotalSize.setSummary(errorRes); } else { long codeSize = mLastResult.getCodeBytes(); - long dataSize = mDataCleared ? 0 : mLastResult.getDataBytes(); + long dataSize = + mDataCleared ? 0 : mLastResult.getDataBytes() - mLastResult.getCacheBytes(); if (mLastCodeSize != codeSize) { mLastCodeSize = codeSize; mAppSize.setSummary(getSizeStr(context, codeSize)); diff --git a/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java index 36d78c1c9b3..e302edd9f75 100644 --- a/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java @@ -14,11 +14,9 @@ import com.android.settings.TestConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import org.robolectric.shadows.ShadowApplication; import com.android.settings.R; import com.android.settingslib.applications.StorageStatsSource.AppStorageStats; @@ -82,15 +80,15 @@ public class AppStorageSizesControllerTest { when(result.getCodeBytes()).thenReturn(1L); when(result.getCacheBytes()).thenReturn(10L); when(result.getDataBytes()).thenReturn(100L); - when(result.getTotalBytes()).thenReturn(111L); + when(result.getTotalBytes()).thenReturn(101L); mController.setResult(result); mController.updateUi(mContext); assertThat(mAppPreference.getSummary()).isEqualTo("1.00B"); assertThat(mCachePreference.getSummary()).isEqualTo("10.00B"); - assertThat(mDataPreference.getSummary()).isEqualTo("100B"); - assertThat(mTotalPreference.getSummary()).isEqualTo("111B"); + assertThat(mDataPreference.getSummary()).isEqualTo("90.00B"); + assertThat(mTotalPreference.getSummary()).isEqualTo("101B"); } @Test @@ -99,7 +97,7 @@ public class AppStorageSizesControllerTest { when(result.getCodeBytes()).thenReturn(1L); when(result.getCacheBytes()).thenReturn(10L); when(result.getDataBytes()).thenReturn(100L); - when(result.getTotalBytes()).thenReturn(111L); + when(result.getTotalBytes()).thenReturn(101L); mController.setResult(result); mController.setCacheCleared(true); @@ -107,8 +105,8 @@ public class AppStorageSizesControllerTest { assertThat(mAppPreference.getSummary()).isEqualTo("1.00B"); assertThat(mCachePreference.getSummary()).isEqualTo("0.00B"); - assertThat(mDataPreference.getSummary()).isEqualTo("100B"); - assertThat(mTotalPreference.getSummary()).isEqualTo("101B"); + assertThat(mDataPreference.getSummary()).isEqualTo("90.00B"); + assertThat(mTotalPreference.getSummary()).isEqualTo("91.00B"); } @Test @@ -117,7 +115,7 @@ public class AppStorageSizesControllerTest { when(result.getCodeBytes()).thenReturn(1L); when(result.getCacheBytes()).thenReturn(10L); when(result.getDataBytes()).thenReturn(100L); - when(result.getTotalBytes()).thenReturn(111L); + when(result.getTotalBytes()).thenReturn(101L); mController.setResult(result); mController.setDataCleared(true);