Loading src/com/android/settings/applications/AppStorageSettings.java +11 −1 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class AppStorageSettings extends AppInfoWithHeader private static final String KEY_CLEAR_URI = "clear_uri_button"; private static final String KEY_CACHE_CLEARED = "cache_cleared"; private static final String KEY_DATA_CLEARED = "data_cleared"; // Views related to cache info private Preference mCacheSize; Loading @@ -115,6 +116,7 @@ public class AppStorageSettings extends AppInfoWithHeader private boolean mCanClearData = true; private boolean mCacheCleared; private boolean mDataCleared; private AppStorageSizesController mSizeController; Loading @@ -130,6 +132,8 @@ public class AppStorageSettings extends AppInfoWithHeader super.onCreate(savedInstanceState); if (savedInstanceState != null) { mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false); mDataCleared = savedInstanceState.getBoolean(KEY_DATA_CLEARED, false); mCacheCleared = mCacheCleared || mDataCleared; } addPreferencesFromResource(R.xml.app_storage_settings); Loading @@ -147,6 +151,7 @@ public class AppStorageSettings extends AppInfoWithHeader public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared); outState.putBoolean(KEY_DATA_CLEARED, mDataCleared); } private void setupViews() { Loading Loading @@ -527,6 +532,9 @@ public class AppStorageSettings extends AppInfoWithHeader if (mCacheCleared) { mSizeController.setCacheCleared(true); } if (mDataCleared) { mSizeController.setDataCleared(true); } mSizeController.updateUi(getContext()); Loading @@ -538,7 +546,7 @@ public class AppStorageSettings extends AppInfoWithHeader long dataSize = result.getDataBytes(); long cacheSize = result.getCacheBytes(); if (dataSize <= 0 || !mCanClearData) { if (dataSize <= 0 || !mCanClearData || mDataCleared) { mClearDataButton.setEnabled(false); } else { mClearDataButton.setEnabled(true); Loading @@ -564,6 +572,8 @@ public class AppStorageSettings extends AppInfoWithHeader } switch (msg.what) { case MSG_CLEAR_USER_DATA: mDataCleared = true; mCacheCleared = true; processClearMsg(msg); break; case MSG_CLEAR_CACHE: Loading src/com/android/settings/applications/AppStorageSizesController.java +12 −2 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ public class AppStorageSizesController { private StorageStatsSource.AppStorageStats mLastResult; private boolean mLastResultFailed; private boolean mCachedCleared; private boolean mDataCleared; private long mLastCodeSize = -1; private long mLastDataSize = -1; private long mLastCacheSize = -1; Loading Loading @@ -69,7 +70,7 @@ public class AppStorageSizesController { mTotalSize.setSummary(errorRes); } else { long codeSize = mLastResult.getCodeBytes(); long dataSize = mLastResult.getDataBytes(); long dataSize = mDataCleared ? 0 : mLastResult.getDataBytes(); if (mLastCodeSize != codeSize) { mLastCodeSize = codeSize; mAppSize.setSummary(getSizeStr(context, codeSize)); Loading @@ -78,7 +79,7 @@ public class AppStorageSizesController { mLastDataSize = dataSize; mDataSize.setSummary(getSizeStr(context, dataSize)); } long cacheSize = mCachedCleared ? 0 : mLastResult.getCacheBytes(); long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes(); if (mLastCacheSize != cacheSize) { mLastCacheSize = cacheSize; mCacheSize.setSummary(getSizeStr(context, cacheSize)); Loading Loading @@ -110,6 +111,15 @@ public class AppStorageSizesController { mCachedCleared = isCleared; } /** * Sets if we have cleared data and should zero the data bytes. * When the data is cleared, the directory are recreated. Directories have some size, but are * empty. We zero this out to best match user expectations. */ public void setDataCleared(boolean isCleared) { mDataCleared = isCleared; } /** * Returns the last result calculated, if it exists. If it does not, returns null. */ Loading tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -110,4 +110,22 @@ public class AppStorageSizesControllerTest { assertThat(mDataPreference.getSummary()).isEqualTo("100B"); assertThat(mTotalPreference.getSummary()).isEqualTo("101B"); } @Test public void fakeDataFlagSetsDataAndCacheToZero() { 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.setDataCleared(true); mController.updateUi(mContext); assertThat(mAppPreference.getSummary()).isEqualTo("1.00B"); assertThat(mCachePreference.getSummary()).isEqualTo("0.00B"); assertThat(mDataPreference.getSummary()).isEqualTo("0.00B"); assertThat(mTotalPreference.getSummary()).isEqualTo("1.00B"); } } Loading
src/com/android/settings/applications/AppStorageSettings.java +11 −1 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class AppStorageSettings extends AppInfoWithHeader private static final String KEY_CLEAR_URI = "clear_uri_button"; private static final String KEY_CACHE_CLEARED = "cache_cleared"; private static final String KEY_DATA_CLEARED = "data_cleared"; // Views related to cache info private Preference mCacheSize; Loading @@ -115,6 +116,7 @@ public class AppStorageSettings extends AppInfoWithHeader private boolean mCanClearData = true; private boolean mCacheCleared; private boolean mDataCleared; private AppStorageSizesController mSizeController; Loading @@ -130,6 +132,8 @@ public class AppStorageSettings extends AppInfoWithHeader super.onCreate(savedInstanceState); if (savedInstanceState != null) { mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false); mDataCleared = savedInstanceState.getBoolean(KEY_DATA_CLEARED, false); mCacheCleared = mCacheCleared || mDataCleared; } addPreferencesFromResource(R.xml.app_storage_settings); Loading @@ -147,6 +151,7 @@ public class AppStorageSettings extends AppInfoWithHeader public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared); outState.putBoolean(KEY_DATA_CLEARED, mDataCleared); } private void setupViews() { Loading Loading @@ -527,6 +532,9 @@ public class AppStorageSettings extends AppInfoWithHeader if (mCacheCleared) { mSizeController.setCacheCleared(true); } if (mDataCleared) { mSizeController.setDataCleared(true); } mSizeController.updateUi(getContext()); Loading @@ -538,7 +546,7 @@ public class AppStorageSettings extends AppInfoWithHeader long dataSize = result.getDataBytes(); long cacheSize = result.getCacheBytes(); if (dataSize <= 0 || !mCanClearData) { if (dataSize <= 0 || !mCanClearData || mDataCleared) { mClearDataButton.setEnabled(false); } else { mClearDataButton.setEnabled(true); Loading @@ -564,6 +572,8 @@ public class AppStorageSettings extends AppInfoWithHeader } switch (msg.what) { case MSG_CLEAR_USER_DATA: mDataCleared = true; mCacheCleared = true; processClearMsg(msg); break; case MSG_CLEAR_CACHE: Loading
src/com/android/settings/applications/AppStorageSizesController.java +12 −2 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ public class AppStorageSizesController { private StorageStatsSource.AppStorageStats mLastResult; private boolean mLastResultFailed; private boolean mCachedCleared; private boolean mDataCleared; private long mLastCodeSize = -1; private long mLastDataSize = -1; private long mLastCacheSize = -1; Loading Loading @@ -69,7 +70,7 @@ public class AppStorageSizesController { mTotalSize.setSummary(errorRes); } else { long codeSize = mLastResult.getCodeBytes(); long dataSize = mLastResult.getDataBytes(); long dataSize = mDataCleared ? 0 : mLastResult.getDataBytes(); if (mLastCodeSize != codeSize) { mLastCodeSize = codeSize; mAppSize.setSummary(getSizeStr(context, codeSize)); Loading @@ -78,7 +79,7 @@ public class AppStorageSizesController { mLastDataSize = dataSize; mDataSize.setSummary(getSizeStr(context, dataSize)); } long cacheSize = mCachedCleared ? 0 : mLastResult.getCacheBytes(); long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes(); if (mLastCacheSize != cacheSize) { mLastCacheSize = cacheSize; mCacheSize.setSummary(getSizeStr(context, cacheSize)); Loading Loading @@ -110,6 +111,15 @@ public class AppStorageSizesController { mCachedCleared = isCleared; } /** * Sets if we have cleared data and should zero the data bytes. * When the data is cleared, the directory are recreated. Directories have some size, but are * empty. We zero this out to best match user expectations. */ public void setDataCleared(boolean isCleared) { mDataCleared = isCleared; } /** * Returns the last result calculated, if it exists. If it does not, returns null. */ Loading
tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -110,4 +110,22 @@ public class AppStorageSizesControllerTest { assertThat(mDataPreference.getSummary()).isEqualTo("100B"); assertThat(mTotalPreference.getSummary()).isEqualTo("101B"); } @Test public void fakeDataFlagSetsDataAndCacheToZero() { 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.setDataCleared(true); mController.updateUi(mContext); assertThat(mAppPreference.getSummary()).isEqualTo("1.00B"); assertThat(mCachePreference.getSummary()).isEqualTo("0.00B"); assertThat(mDataPreference.getSummary()).isEqualTo("0.00B"); assertThat(mTotalPreference.getSummary()).isEqualTo("1.00B"); } }