Merge "Add cache mechanism for secondary users in Storage" into tm-dev am: 34eecaad79

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17182074

Change-Id: If51dbd3ab6723ff8bc15035118a3bf11d05c8312
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Mill Chen
2022-04-08 06:13:01 +00:00
committed by Automerger Merge Worker
7 changed files with 60 additions and 30 deletions

View File

@@ -97,7 +97,7 @@ public class SecondaryUserControllerTest {
public void controllerUpdatesSummaryOfNewPreference() {
mPrimaryUser.name = TEST_NAME;
mController.displayPreference(mScreen);
mController.setSize(MEGABYTE_IN_BYTES * 10);
mController.setSize(MEGABYTE_IN_BYTES * 10, false /* animate */);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mGroup).addPreference(argumentCaptor.capture());
@@ -114,7 +114,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */);
false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1);
// We should have the NoSecondaryUserController.
@@ -134,7 +134,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */);
false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isTrue();
@@ -153,7 +153,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */);
false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isTrue();
@@ -172,7 +172,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
true /* isWorkProfileOnly */);
true /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse();
@@ -190,14 +190,14 @@ public class SecondaryUserControllerTest {
final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */);
false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse();
}
@Test
public void controllerUpdatesPreferenceOnAcceptingResult() {
public void handleResult_noStatsResult_shouldShowCachedData() {
mPrimaryUser.name = TEST_NAME;
mPrimaryUser.id = 10;
mController.displayPreference(mScreen);
@@ -211,8 +211,11 @@ public class SecondaryUserControllerTest {
MEGABYTE_IN_BYTES * 10,
MEGABYTE_IN_BYTES * 10, 0);
result.put(10, userResult);
// Cache size info at first time
mController.handleResult(result);
// Retrieve cache size info if stats result is null
mController.handleResult(null);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mGroup).addPreference(argumentCaptor.capture());
final Preference preference = argumentCaptor.getValue();
@@ -233,7 +236,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */);
false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1);
// We should have the NoSecondaryUserController.

View File

@@ -39,7 +39,8 @@ public class StorageCacheHelperTest {
private static final long FAKE_TRASH_SIZE = 500L;
private static final long FAKE_SYSTEM_SIZE = 2300L;
private static final long FAKE_TOTAL_SIZE = 256000L;
private static final long FAKE_USED_SIZE = 50000L;
private static final long FAKE_TOTAL_USED_SIZE = 50000L;
private static final long FAKE_USED_SIZE = 6500L;
private Context mContext;
private StorageCacheHelper mHelper;
@@ -74,12 +75,19 @@ public class StorageCacheHelperTest {
@Test
public void cacheTotalSizeAndUsedSize_shouldSaveToSharedPreference() {
mHelper.cacheTotalSizeAndUsedSize(FAKE_TOTAL_SIZE, FAKE_USED_SIZE);
mHelper.cacheTotalSizeAndTotalUsedSize(FAKE_TOTAL_SIZE, FAKE_TOTAL_USED_SIZE);
StorageCacheHelper.StorageCache storageCache = mHelper.retrieveCachedSize();
assertThat(storageCache.totalSize).isEqualTo(FAKE_TOTAL_SIZE);
assertThat(storageCache.usedSize).isEqualTo(FAKE_USED_SIZE);
assertThat(storageCache.totalUsedSize).isEqualTo(FAKE_TOTAL_USED_SIZE);
}
@Test
public void cacheUsedSize_shouldSaveToSharedPreference() {
mHelper.cacheUsedSize(FAKE_USED_SIZE);
assertThat(mHelper.retrieveUsedSize()).isEqualTo(FAKE_USED_SIZE);
}
private StorageCacheHelper.StorageCache getFakeStorageCache() {