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_CLEAR_URI = "clear_uri_button";
|
||||||
|
|
||||||
private static final String KEY_CACHE_CLEARED = "cache_cleared";
|
private static final String KEY_CACHE_CLEARED = "cache_cleared";
|
||||||
|
private static final String KEY_DATA_CLEARED = "data_cleared";
|
||||||
|
|
||||||
// Views related to cache info
|
// Views related to cache info
|
||||||
private Preference mCacheSize;
|
private Preference mCacheSize;
|
||||||
@@ -115,6 +116,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
|
|
||||||
private boolean mCanClearData = true;
|
private boolean mCanClearData = true;
|
||||||
private boolean mCacheCleared;
|
private boolean mCacheCleared;
|
||||||
|
private boolean mDataCleared;
|
||||||
|
|
||||||
private AppStorageSizesController mSizeController;
|
private AppStorageSizesController mSizeController;
|
||||||
|
|
||||||
@@ -130,6 +132,8 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false);
|
mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false);
|
||||||
|
mDataCleared = savedInstanceState.getBoolean(KEY_DATA_CLEARED, false);
|
||||||
|
mCacheCleared = mCacheCleared || mDataCleared;
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.app_storage_settings);
|
addPreferencesFromResource(R.xml.app_storage_settings);
|
||||||
@@ -147,6 +151,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared);
|
outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared);
|
||||||
|
outState.putBoolean(KEY_DATA_CLEARED, mDataCleared);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupViews() {
|
private void setupViews() {
|
||||||
@@ -527,6 +532,9 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
if (mCacheCleared) {
|
if (mCacheCleared) {
|
||||||
mSizeController.setCacheCleared(true);
|
mSizeController.setCacheCleared(true);
|
||||||
}
|
}
|
||||||
|
if (mDataCleared) {
|
||||||
|
mSizeController.setDataCleared(true);
|
||||||
|
}
|
||||||
|
|
||||||
mSizeController.updateUi(getContext());
|
mSizeController.updateUi(getContext());
|
||||||
|
|
||||||
@@ -538,7 +546,7 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
long dataSize = result.getDataBytes();
|
long dataSize = result.getDataBytes();
|
||||||
long cacheSize = result.getCacheBytes();
|
long cacheSize = result.getCacheBytes();
|
||||||
|
|
||||||
if (dataSize <= 0 || !mCanClearData) {
|
if (dataSize <= 0 || !mCanClearData || mDataCleared) {
|
||||||
mClearDataButton.setEnabled(false);
|
mClearDataButton.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
mClearDataButton.setEnabled(true);
|
mClearDataButton.setEnabled(true);
|
||||||
@@ -564,6 +572,8 @@ public class AppStorageSettings extends AppInfoWithHeader
|
|||||||
}
|
}
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MSG_CLEAR_USER_DATA:
|
case MSG_CLEAR_USER_DATA:
|
||||||
|
mDataCleared = true;
|
||||||
|
mCacheCleared = true;
|
||||||
processClearMsg(msg);
|
processClearMsg(msg);
|
||||||
break;
|
break;
|
||||||
case MSG_CLEAR_CACHE:
|
case MSG_CLEAR_CACHE:
|
||||||
|
@@ -40,6 +40,7 @@ public class AppStorageSizesController {
|
|||||||
private StorageStatsSource.AppStorageStats mLastResult;
|
private StorageStatsSource.AppStorageStats mLastResult;
|
||||||
private boolean mLastResultFailed;
|
private boolean mLastResultFailed;
|
||||||
private boolean mCachedCleared;
|
private boolean mCachedCleared;
|
||||||
|
private boolean mDataCleared;
|
||||||
private long mLastCodeSize = -1;
|
private long mLastCodeSize = -1;
|
||||||
private long mLastDataSize = -1;
|
private long mLastDataSize = -1;
|
||||||
private long mLastCacheSize = -1;
|
private long mLastCacheSize = -1;
|
||||||
@@ -69,7 +70,7 @@ public class AppStorageSizesController {
|
|||||||
mTotalSize.setSummary(errorRes);
|
mTotalSize.setSummary(errorRes);
|
||||||
} else {
|
} else {
|
||||||
long codeSize = mLastResult.getCodeBytes();
|
long codeSize = mLastResult.getCodeBytes();
|
||||||
long dataSize = mLastResult.getDataBytes();
|
long dataSize = mDataCleared ? 0 : mLastResult.getDataBytes();
|
||||||
if (mLastCodeSize != codeSize) {
|
if (mLastCodeSize != codeSize) {
|
||||||
mLastCodeSize = codeSize;
|
mLastCodeSize = codeSize;
|
||||||
mAppSize.setSummary(getSizeStr(context, codeSize));
|
mAppSize.setSummary(getSizeStr(context, codeSize));
|
||||||
@@ -78,7 +79,7 @@ public class AppStorageSizesController {
|
|||||||
mLastDataSize = dataSize;
|
mLastDataSize = dataSize;
|
||||||
mDataSize.setSummary(getSizeStr(context, dataSize));
|
mDataSize.setSummary(getSizeStr(context, dataSize));
|
||||||
}
|
}
|
||||||
long cacheSize = mCachedCleared ? 0 : mLastResult.getCacheBytes();
|
long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes();
|
||||||
if (mLastCacheSize != cacheSize) {
|
if (mLastCacheSize != cacheSize) {
|
||||||
mLastCacheSize = cacheSize;
|
mLastCacheSize = cacheSize;
|
||||||
mCacheSize.setSummary(getSizeStr(context, cacheSize));
|
mCacheSize.setSummary(getSizeStr(context, cacheSize));
|
||||||
@@ -110,6 +111,15 @@ public class AppStorageSizesController {
|
|||||||
mCachedCleared = isCleared;
|
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.
|
* 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(mDataPreference.getSummary()).isEqualTo("100B");
|
||||||
assertThat(mTotalPreference.getSummary()).isEqualTo("101B");
|
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