Loading src/com/android/settings/applications/AppStorageSettings.java +18 −1 Original line number Diff line number Diff line Loading @@ -101,6 +101,8 @@ public class AppStorageSettings extends AppInfoWithHeader private static final String KEY_URI_CATEGORY = "uri_category"; private static final String KEY_CLEAR_URI = "clear_uri_button"; private static final String KEY_CACHE_CLEARED = "cache_cleared"; // Views related to cache info private Preference mCacheSize; private Button mClearDataButton; Loading @@ -115,6 +117,7 @@ public class AppStorageSettings extends AppInfoWithHeader private PreferenceCategory mUri; private boolean mCanClearData = true; private boolean mCacheCleared; private AppStorageStats mLastResult; private AppStorageSizesController mSizeController; Loading @@ -133,6 +136,9 @@ public class AppStorageSettings extends AppInfoWithHeader @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false); } addPreferencesFromResource(R.xml.app_storage_settings); setupViews(); Loading @@ -145,6 +151,12 @@ public class AppStorageSettings extends AppInfoWithHeader updateSize(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared); } private void setupViews() { mComputingStr = getActivity().getText(R.string.computing_size); mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value); Loading Loading @@ -523,6 +535,10 @@ public class AppStorageSettings extends AppInfoWithHeader } private void updateUiWithSize(AppStorageStats result) { if (mCacheCleared) { mSizeController.setCacheCleared(true); } mSizeController.updateUi(getContext()); if (result == null) { Loading @@ -539,7 +555,7 @@ public class AppStorageSettings extends AppInfoWithHeader mClearDataButton.setEnabled(true); mClearDataButton.setOnClickListener(this); } if (cacheSize <= 0) { if (cacheSize <= 0 || mCacheCleared) { mClearCacheButton.setEnabled(false); } else { mClearCacheButton.setEnabled(true); Loading @@ -562,6 +578,7 @@ public class AppStorageSettings extends AppInfoWithHeader processClearMsg(msg); break; case MSG_CLEAR_CACHE: mCacheCleared = true; // Refresh size info updateSize(); break; Loading src/com/android/settings/applications/AppStorageSizesController.java +11 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ public class AppStorageSizesController { @Nullable private StorageStatsSource.AppStorageStats mLastResult; private boolean mLastResultFailed; private boolean mCachedCleared; private long mLastCodeSize = -1; private long mLastDataSize = -1; private long mLastCacheSize = -1; Loading Loading @@ -77,7 +78,7 @@ public class AppStorageSizesController { mLastDataSize = dataSize; mDataSize.setSummary(getSizeStr(context, dataSize)); } long cacheSize = mLastResult.getCacheBytes(); long cacheSize = mCachedCleared ? 0 : mLastResult.getCacheBytes(); if (mLastCacheSize != cacheSize) { mLastCacheSize = cacheSize; mCacheSize.setSummary(getSizeStr(context, cacheSize)); Loading @@ -100,6 +101,15 @@ public class AppStorageSizesController { mLastResultFailed = result == null; } /** * Sets if we have cleared the cache and should zero the cache bytes. * When the cache is cleared, the cache directories are recreated. These directories have * some size, but are empty. We zero this out to best match user expectations. */ public void setCacheCleared(boolean isCleared) { mCachedCleared = isCleared; } private String getSizeStr(Context context, long size) { return Formatter.formatFileSize(context, size); } Loading tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -92,4 +92,22 @@ public class AppStorageSizesControllerTest { assertThat(mDataPreference.getSummary()).isEqualTo("100B"); assertThat(mTotalPreference.getSummary()).isEqualTo("111B"); } @Test public void fakeCacheFlagSetsCacheToZero() { AppStorageStats result = mock(AppStorageStats.class); when(result.getCodeBytes()).thenReturn(1L); when(result.getCacheBytes()).thenReturn(10L); when(result.getDataBytes()).thenReturn(100L); when(result.getTotalBytes()).thenReturn(111L); mController.setResult(result); mController.setCacheCleared(true); mController.updateUi(mContext); assertThat(mAppPreference.getSummary()).isEqualTo("1.00B"); assertThat(mCachePreference.getSummary()).isEqualTo("0.00B"); assertThat(mDataPreference.getSummary()).isEqualTo("100B"); assertThat(mTotalPreference.getSummary()).isEqualTo("101B"); } } Loading
src/com/android/settings/applications/AppStorageSettings.java +18 −1 Original line number Diff line number Diff line Loading @@ -101,6 +101,8 @@ public class AppStorageSettings extends AppInfoWithHeader private static final String KEY_URI_CATEGORY = "uri_category"; private static final String KEY_CLEAR_URI = "clear_uri_button"; private static final String KEY_CACHE_CLEARED = "cache_cleared"; // Views related to cache info private Preference mCacheSize; private Button mClearDataButton; Loading @@ -115,6 +117,7 @@ public class AppStorageSettings extends AppInfoWithHeader private PreferenceCategory mUri; private boolean mCanClearData = true; private boolean mCacheCleared; private AppStorageStats mLastResult; private AppStorageSizesController mSizeController; Loading @@ -133,6 +136,9 @@ public class AppStorageSettings extends AppInfoWithHeader @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false); } addPreferencesFromResource(R.xml.app_storage_settings); setupViews(); Loading @@ -145,6 +151,12 @@ public class AppStorageSettings extends AppInfoWithHeader updateSize(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared); } private void setupViews() { mComputingStr = getActivity().getText(R.string.computing_size); mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value); Loading Loading @@ -523,6 +535,10 @@ public class AppStorageSettings extends AppInfoWithHeader } private void updateUiWithSize(AppStorageStats result) { if (mCacheCleared) { mSizeController.setCacheCleared(true); } mSizeController.updateUi(getContext()); if (result == null) { Loading @@ -539,7 +555,7 @@ public class AppStorageSettings extends AppInfoWithHeader mClearDataButton.setEnabled(true); mClearDataButton.setOnClickListener(this); } if (cacheSize <= 0) { if (cacheSize <= 0 || mCacheCleared) { mClearCacheButton.setEnabled(false); } else { mClearCacheButton.setEnabled(true); Loading @@ -562,6 +578,7 @@ public class AppStorageSettings extends AppInfoWithHeader processClearMsg(msg); break; case MSG_CLEAR_CACHE: mCacheCleared = true; // Refresh size info updateSize(); break; Loading
src/com/android/settings/applications/AppStorageSizesController.java +11 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ public class AppStorageSizesController { @Nullable private StorageStatsSource.AppStorageStats mLastResult; private boolean mLastResultFailed; private boolean mCachedCleared; private long mLastCodeSize = -1; private long mLastDataSize = -1; private long mLastCacheSize = -1; Loading Loading @@ -77,7 +78,7 @@ public class AppStorageSizesController { mLastDataSize = dataSize; mDataSize.setSummary(getSizeStr(context, dataSize)); } long cacheSize = mLastResult.getCacheBytes(); long cacheSize = mCachedCleared ? 0 : mLastResult.getCacheBytes(); if (mLastCacheSize != cacheSize) { mLastCacheSize = cacheSize; mCacheSize.setSummary(getSizeStr(context, cacheSize)); Loading @@ -100,6 +101,15 @@ public class AppStorageSizesController { mLastResultFailed = result == null; } /** * Sets if we have cleared the cache and should zero the cache bytes. * When the cache is cleared, the cache directories are recreated. These directories have * some size, but are empty. We zero this out to best match user expectations. */ public void setCacheCleared(boolean isCleared) { mCachedCleared = isCleared; } private String getSizeStr(Context context, long size) { return Formatter.formatFileSize(context, size); } Loading
tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -92,4 +92,22 @@ public class AppStorageSizesControllerTest { assertThat(mDataPreference.getSummary()).isEqualTo("100B"); assertThat(mTotalPreference.getSummary()).isEqualTo("111B"); } @Test public void fakeCacheFlagSetsCacheToZero() { AppStorageStats result = mock(AppStorageStats.class); when(result.getCodeBytes()).thenReturn(1L); when(result.getCacheBytes()).thenReturn(10L); when(result.getDataBytes()).thenReturn(100L); when(result.getTotalBytes()).thenReturn(111L); mController.setResult(result); mController.setCacheCleared(true); mController.updateUi(mContext); assertThat(mAppPreference.getSummary()).isEqualTo("1.00B"); assertThat(mCachePreference.getSummary()).isEqualTo("0.00B"); assertThat(mDataPreference.getSummary()).isEqualTo("100B"); assertThat(mTotalPreference.getSummary()).isEqualTo("101B"); } }