Merge "Fake data to be 0B after clearing." into oc-dev
This commit is contained in:
@@ -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;
|
||||
@@ -115,6 +116,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
||||
|
||||
private boolean mCanClearData = true;
|
||||
private boolean mCacheCleared;
|
||||
private boolean mDataCleared;
|
||||
|
||||
private AppStorageSizesController mSizeController;
|
||||
|
||||
@@ -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);
|
||||
@@ -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() {
|
||||
@@ -527,6 +532,9 @@ public class AppStorageSettings extends AppInfoWithHeader
|
||||
if (mCacheCleared) {
|
||||
mSizeController.setCacheCleared(true);
|
||||
}
|
||||
if (mDataCleared) {
|
||||
mSizeController.setDataCleared(true);
|
||||
}
|
||||
|
||||
mSizeController.updateUi(getContext());
|
||||
|
||||
@@ -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);
|
||||
@@ -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:
|
||||
|
@@ -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;
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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.
|
||||
*/
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user