Snap for 8429531 from c94c92f0b3 to tm-qpr1-release

Change-Id: I31a97213b656a60930315680aca237ebae2ac1ba
This commit is contained in:
Android Build Coastguard Worker
2022-04-09 05:14:07 +00:00
15 changed files with 82 additions and 43 deletions

View File

@@ -150,7 +150,10 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
@Override @Override
protected void onPostExecute(Boolean succeeded) { protected void onPostExecute(Boolean succeeded) {
mProgressDialog.dismiss(); if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
if (succeeded) { if (succeeded) {
Toast.makeText(mContext, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT) Toast.makeText(mContext, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
.show(); .show();
@@ -189,6 +192,12 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
} }
} }
// Should dismiss the progress dialog firstly if it is showing
// Or not the progress dialog maybe not dismissed in fast clicking.
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
mProgressDialog = getProgressDialog(mActivity); mProgressDialog = getProgressDialog(mActivity);
mProgressDialog.show(); mProgressDialog.show();

View File

@@ -110,7 +110,7 @@ public class StorageCategoryFragment extends DashboardFragment
if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) { if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) {
StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize(); StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize();
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo()); mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
mPreferenceController.setUsedSize(cachedData.usedSize); mPreferenceController.setUsedSize(cachedData.totalUsedSize);
mPreferenceController.setTotalSize(cachedData.totalSize); mPreferenceController.setTotalSize(cachedData.totalSize);
} }
if (mSelectedStorageEntry.isPrivate()) { if (mSelectedStorageEntry.isPrivate()) {
@@ -215,7 +215,8 @@ public class StorageCategoryFragment extends DashboardFragment
mPreferenceController.setUsedSize(privateUsedBytes); mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes); mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
// Cache total size infor and used size info // Cache total size infor and used size info
mStorageCacheHelper.cacheTotalSizeAndUsedSize(mStorageInfo.totalBytes, privateUsedBytes); mStorageCacheHelper
.cacheTotalSizeAndTotalUsedSize(mStorageInfo.totalBytes, privateUsedBytes);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) { for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
final AbstractPreferenceController controller = mSecondaryUsers.get(i); final AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) { if (controller instanceof SecondaryUserController) {

View File

@@ -240,7 +240,7 @@ public class StorageDashboardFragment extends DashboardFragment
if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) { if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) {
StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize(); StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize();
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo()); mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
mPreferenceController.setUsedSize(cachedData.usedSize); mPreferenceController.setUsedSize(cachedData.totalUsedSize);
mPreferenceController.setTotalSize(cachedData.totalSize); mPreferenceController.setTotalSize(cachedData.totalSize);
} }
@@ -388,7 +388,8 @@ public class StorageDashboardFragment extends DashboardFragment
mPreferenceController.setUsedSize(privateUsedBytes); mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes); mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
// Cache total size and used size // Cache total size and used size
mStorageCacheHelper.cacheTotalSizeAndUsedSize(mStorageInfo.totalBytes, privateUsedBytes); mStorageCacheHelper
.cacheTotalSizeAndTotalUsedSize(mStorageInfo.totalBytes, privateUsedBytes);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) { for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
final AbstractPreferenceController controller = mSecondaryUsers.get(i); final AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) { if (controller instanceof SecondaryUserController) {

View File

@@ -46,7 +46,6 @@ public class SecondaryUserController extends AbstractPreferenceController implem
// PreferenceGroupKey to try to add our preference onto. // PreferenceGroupKey to try to add our preference onto.
private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users"; private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
private static final String PREFERENCE_KEY_BASE = "pref_user_"; private static final String PREFERENCE_KEY_BASE = "pref_user_";
private static final int USER_PROFILE_INSERTION_LOCATION = 6;
private static final int SIZE_NOT_SET = -1; private static final int SIZE_NOT_SET = -1;
private @NonNull private @NonNull
@@ -58,6 +57,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
private long mSize; private long mSize;
private long mTotalSizeBytes; private long mTotalSizeBytes;
private boolean mIsVisible; private boolean mIsVisible;
private StorageCacheHelper mStorageCacheHelper;
/** /**
* Adds the appropriate controllers to a controller list for handling all secondary users on * Adds the appropriate controllers to a controller list for handling all secondary users on
@@ -110,6 +110,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
super(context); super(context);
mUser = info; mUser = info;
mSize = SIZE_NOT_SET; mSize = SIZE_NOT_SET;
mStorageCacheHelper = new StorageCacheHelper(context, info.id);
} }
@Override @Override
@@ -120,9 +121,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
mPreferenceGroup = screen.findPreference(TARGET_PREFERENCE_GROUP_KEY); mPreferenceGroup = screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
mStoragePreference.setTitle(mUser.name); mStoragePreference.setTitle(mUser.name);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id); mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
if (mSize != SIZE_NOT_SET) { setSize(mStorageCacheHelper.retrieveUsedSize(), false /* animate */);
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
}
mPreferenceGroup.setVisible(mIsVisible); mPreferenceGroup.setVisible(mIsVisible);
mPreferenceGroup.addPreference(mStoragePreference); mPreferenceGroup.addPreference(mStoragePreference);
@@ -153,10 +152,10 @@ public class SecondaryUserController extends AbstractPreferenceController implem
* *
* @param size Size in bytes. * @param size Size in bytes.
*/ */
public void setSize(long size) { public void setSize(long size, boolean animate) {
mSize = size; mSize = size;
if (mStoragePreference != null) { if (mStoragePreference != null) {
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes); mStoragePreference.setStorageSize(mSize, mTotalSizeBytes, animate);
} }
} }
@@ -184,11 +183,14 @@ public class SecondaryUserController extends AbstractPreferenceController implem
@Override @Override
public void handleResult(SparseArray<StorageAsyncLoader.StorageResult> stats) { public void handleResult(SparseArray<StorageAsyncLoader.StorageResult> stats) {
if (stats == null) { if (stats == null) {
setSize(mStorageCacheHelper.retrieveUsedSize(), false /* animate */);
return; return;
} }
final StorageAsyncLoader.StorageResult result = stats.get(getUser().id); final StorageAsyncLoader.StorageResult result = stats.get(getUser().id);
if (result != null) { if (result != null) {
setSize(result.externalStats.totalBytes); setSize(result.externalStats.totalBytes, true /* animate */);
// TODO(b/171758224): Update the source of size info
mStorageCacheHelper.cacheUsedSize(result.externalStats.totalBytes);
} }
} }

View File

@@ -26,7 +26,7 @@ public class StorageCacheHelper {
private static final String SHARED_PREFERENCE_NAME = "StorageCache"; private static final String SHARED_PREFERENCE_NAME = "StorageCache";
private static final String TOTAL_SIZE_KEY = "total_size_key"; private static final String TOTAL_SIZE_KEY = "total_size_key";
private static final String USED_SIZE_KEY = "used_size_key"; private static final String TOTAL_USED_SIZE_KEY = "total_used_size_key";
private static final String IMAGES_SIZE_KEY = "images_size_key"; private static final String IMAGES_SIZE_KEY = "images_size_key";
private static final String VIDEOS_SIZE_KEY = "videos_size_key"; private static final String VIDEOS_SIZE_KEY = "videos_size_key";
private static final String AUDIO_SIZE_KEY = "audio_size_key"; private static final String AUDIO_SIZE_KEY = "audio_size_key";
@@ -35,6 +35,7 @@ public class StorageCacheHelper {
private static final String DOCUMENTS_AND_OTHER_SIZE_KEY = "documents_and_other_size_key"; private static final String DOCUMENTS_AND_OTHER_SIZE_KEY = "documents_and_other_size_key";
private static final String TRASH_SIZE_KEY = "trash_size_key"; private static final String TRASH_SIZE_KEY = "trash_size_key";
private static final String SYSTEM_SIZE_KEY = "system_size_key"; private static final String SYSTEM_SIZE_KEY = "system_size_key";
private static final String USED_SIZE_KEY = "used_size_key";
private final SharedPreferences mSharedPreferences; private final SharedPreferences mSharedPreferences;
@@ -69,23 +70,37 @@ public class StorageCacheHelper {
} }
/** /**
* Cache total size and used size * Cache total size and total used size
*/ */
public void cacheTotalSizeAndUsedSize(long totalSize, long usedSize) { public void cacheTotalSizeAndTotalUsedSize(long totalSize, long totalUsedSize) {
mSharedPreferences mSharedPreferences
.edit() .edit()
.putLong(TOTAL_SIZE_KEY, totalSize) .putLong(TOTAL_SIZE_KEY, totalSize)
.putLong(USED_SIZE_KEY, usedSize) .putLong(TOTAL_USED_SIZE_KEY, totalUsedSize)
.apply(); .apply();
} }
/**
* Cache used size info when a user is treated as a secondary user.
*/
public void cacheUsedSize(long usedSize) {
mSharedPreferences.edit().putLong(USED_SIZE_KEY, usedSize).apply();
}
/**
* Returns used size for secondary user.
*/
public long retrieveUsedSize() {
return mSharedPreferences.getLong(USED_SIZE_KEY, 0);
}
/** /**
* Returns a cached data about all file size information. * Returns a cached data about all file size information.
*/ */
public StorageCache retrieveCachedSize() { public StorageCache retrieveCachedSize() {
StorageCache result = new StorageCache(); StorageCache result = new StorageCache();
result.totalSize = mSharedPreferences.getLong(TOTAL_SIZE_KEY, 0); result.totalSize = mSharedPreferences.getLong(TOTAL_SIZE_KEY, 0);
result.usedSize = mSharedPreferences.getLong(USED_SIZE_KEY, 0); result.totalUsedSize = mSharedPreferences.getLong(TOTAL_USED_SIZE_KEY, 0);
result.imagesSize = mSharedPreferences.getLong(IMAGES_SIZE_KEY, 0); result.imagesSize = mSharedPreferences.getLong(IMAGES_SIZE_KEY, 0);
result.videosSize = mSharedPreferences.getLong(VIDEOS_SIZE_KEY, 0); result.videosSize = mSharedPreferences.getLong(VIDEOS_SIZE_KEY, 0);
result.audioSize = mSharedPreferences.getLong(AUDIO_SIZE_KEY, 0); result.audioSize = mSharedPreferences.getLong(AUDIO_SIZE_KEY, 0);
@@ -102,7 +117,7 @@ public class StorageCacheHelper {
*/ */
public static class StorageCache { public static class StorageCache {
public long totalSize; public long totalSize;
public long usedSize; public long totalUsedSize;
public long gamesSize; public long gamesSize;
public long allAppsExceptGamesSize; public long allAppsExceptGamesSize;
public long audioSize; public long audioSize;

View File

@@ -78,7 +78,7 @@ public class StorageUsageProgressBarPreferenceController extends BasePreferenceC
if (mStorageEntry != null && mStorageEntry.isMounted() && mStorageEntry.isPrivate()) { if (mStorageEntry != null && mStorageEntry.isMounted() && mStorageEntry.isPrivate()) {
StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize(); StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize();
mTotalBytes = cachedData.totalSize; mTotalBytes = cachedData.totalSize;
mUsedBytes = cachedData.usedSize; mUsedBytes = cachedData.totalUsedSize;
mIsUpdateStateFromSelectedStorageEntry = true; mIsUpdateStateFromSelectedStorageEntry = true;
updateState(mUsageProgressBarPreference); updateState(mUsageProgressBarPreference);
} }

View File

@@ -115,6 +115,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
mCustomizeButton.setOnClickListener(v -> item.onCustomizeClicked()); mCustomizeButton.setOnClickListener(v -> item.onCustomizeClicked());
mCustomizeButton.setVisibility( mCustomizeButton.setVisibility(
item.allowCustomization() && mEnabled ? View.VISIBLE : View.GONE); item.allowCustomization() && mEnabled ? View.VISIBLE : View.GONE);
mCustomizeButton.setSelected(false);
itemView.setOnClickListener(v -> { itemView.setOnClickListener(v -> {
item.onItemClicked(); item.onItemClicked();

View File

@@ -74,15 +74,11 @@ public class AvailableVirtualKeyboardFragment extends DashboardFragment
final Context newUserAwareContext; final Context newUserAwareContext;
switch (profileType) { switch (profileType) {
case ProfileSelectFragment.ProfileType.WORK: { case ProfileSelectFragment.ProfileType.WORK: {
final UserHandle workUser; // If the user is a managed profile user, use currentUserId directly. Or get the
if (currentUserId == UserHandle.MIN_SECONDARY_USER_ID) { // managed profile userId instead.
newUserId = currentUserId; newUserId = userManager.isManagedProfile()
workUser = UserHandle.of(currentUserId); ? currentUserId : Utils.getManagedProfileId(userManager, currentUserId);
} else { newUserAwareContext = context.createContextAsUser(UserHandle.of(newUserId), 0);
newUserId = Utils.getManagedProfileId(userManager, currentUserId);
workUser = Utils.getManagedProfile(userManager);
}
newUserAwareContext = context.createContextAsUser(workUser, 0);
break; break;
} }
case ProfileSelectFragment.ProfileType.PERSONAL: { case ProfileSelectFragment.ProfileType.PERSONAL: {

View File

@@ -73,6 +73,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
UserHandle userHandle = UserHandle.getUserHandleForUid(uid); UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
mContextAsUser = createContextAsUser(userHandle, 0); mContextAsUser = createContextAsUser(userHandle, 0);
setTitle(R.string.app_locale_picker_title);
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker( mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(

View File

@@ -36,6 +36,7 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.add_a_language);
final LocalePickerWithRegion selector = LocalePickerWithRegion.createLanguagePicker( final LocalePickerWithRegion selector = LocalePickerWithRegion.createLanguagePicker(
this, LocalePickerWithRegionActivity.this, false /* translate only */); this, LocalePickerWithRegionActivity.this, false /* translate only */);

View File

@@ -141,7 +141,8 @@ public class SelectableSubscriptions implements Callable<List<SubscriptionAnnota
protected List<SubscriptionInfo> getSubInfoList(Context context, protected List<SubscriptionInfo> getSubInfoList(Context context,
Function<SubscriptionManager, List<SubscriptionInfo>> convertor) { Function<SubscriptionManager, List<SubscriptionInfo>> convertor) {
SubscriptionManager subManager = getSubscriptionManager(context); SubscriptionManager subManager = getSubscriptionManager(context);
return (subManager == null) ? Collections.emptyList() : convertor.apply(subManager); List<SubscriptionInfo> result = (subManager == null) ? null : convertor.apply(subManager);
return (result == null) ? Collections.emptyList() : result;
} }
protected SubscriptionManager getSubscriptionManager(Context context) { protected SubscriptionManager getSubscriptionManager(Context context) {

View File

@@ -38,7 +38,7 @@ import com.android.settingslib.RestrictedLockUtils;
/** Combined Biometrics Safety Source for Safety Center. */ /** Combined Biometrics Safety Source for Safety Center. */
public final class BiometricsSafetySource { public final class BiometricsSafetySource {
public static final String SAFETY_SOURCE_ID = "Biometrics"; public static final String SAFETY_SOURCE_ID = "AndroidBiometrics";
private BiometricsSafetySource() { private BiometricsSafetySource() {
} }

View File

@@ -37,7 +37,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
/** Lock Screen Safety Source for Safety Center. */ /** Lock Screen Safety Source for Safety Center. */
public final class LockScreenSafetySource { public final class LockScreenSafetySource {
public static final String SAFETY_SOURCE_ID = "LockScreen"; public static final String SAFETY_SOURCE_ID = "AndroidLockScreen";
public static final String NO_SCREEN_LOCK_ISSUE_ID = "NoScreenLockIssue"; public static final String NO_SCREEN_LOCK_ISSUE_ID = "NoScreenLockIssue";
public static final String NO_SCREEN_LOCK_ISSUE_TYPE_ID = "NoScreenLockIssueType"; public static final String NO_SCREEN_LOCK_ISSUE_TYPE_ID = "NoScreenLockIssueType";
public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction"; public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction";

View File

@@ -97,7 +97,7 @@ public class SecondaryUserControllerTest {
public void controllerUpdatesSummaryOfNewPreference() { public void controllerUpdatesSummaryOfNewPreference() {
mPrimaryUser.name = TEST_NAME; mPrimaryUser.name = TEST_NAME;
mController.displayPreference(mScreen); 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); final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mGroup).addPreference(argumentCaptor.capture()); verify(mGroup).addPreference(argumentCaptor.capture());
@@ -114,7 +114,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos); when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers = final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */); false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1); assertThat(controllers).hasSize(1);
// We should have the NoSecondaryUserController. // We should have the NoSecondaryUserController.
@@ -134,7 +134,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos); when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers = final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */); false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1); assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isTrue(); assertThat(controllers.get(0) instanceof SecondaryUserController).isTrue();
@@ -153,7 +153,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos); when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers = final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */); false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1); assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isTrue(); assertThat(controllers.get(0) instanceof SecondaryUserController).isTrue();
@@ -172,7 +172,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos); when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers = final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
true /* isWorkProfileOnly */); true /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1); assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse(); assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse();
@@ -190,14 +190,14 @@ public class SecondaryUserControllerTest {
final List<AbstractPreferenceController> controllers = final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */); false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1); assertThat(controllers).hasSize(1);
assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse(); assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse();
} }
@Test @Test
public void controllerUpdatesPreferenceOnAcceptingResult() { public void handleResult_noStatsResult_shouldShowCachedData() {
mPrimaryUser.name = TEST_NAME; mPrimaryUser.name = TEST_NAME;
mPrimaryUser.id = 10; mPrimaryUser.id = 10;
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -211,8 +211,11 @@ public class SecondaryUserControllerTest {
MEGABYTE_IN_BYTES * 10, MEGABYTE_IN_BYTES * 10,
MEGABYTE_IN_BYTES * 10, 0); MEGABYTE_IN_BYTES * 10, 0);
result.put(10, userResult); result.put(10, userResult);
// Cache size info at first time
mController.handleResult(result); mController.handleResult(result);
// Retrieve cache size info if stats result is null
mController.handleResult(null);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class); final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mGroup).addPreference(argumentCaptor.capture()); verify(mGroup).addPreference(argumentCaptor.capture());
final Preference preference = argumentCaptor.getValue(); final Preference preference = argumentCaptor.getValue();
@@ -233,7 +236,7 @@ public class SecondaryUserControllerTest {
when(mUserManager.getUsers()).thenReturn(userInfos); when(mUserManager.getUsers()).thenReturn(userInfos);
final List<AbstractPreferenceController> controllers = final List<AbstractPreferenceController> controllers =
SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager,
false /* isWorkProfileOnly */); false /* isWorkProfileOnly */);
assertThat(controllers).hasSize(1); assertThat(controllers).hasSize(1);
// We should have the NoSecondaryUserController. // 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_TRASH_SIZE = 500L;
private static final long FAKE_SYSTEM_SIZE = 2300L; private static final long FAKE_SYSTEM_SIZE = 2300L;
private static final long FAKE_TOTAL_SIZE = 256000L; 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 Context mContext;
private StorageCacheHelper mHelper; private StorageCacheHelper mHelper;
@@ -74,12 +75,19 @@ public class StorageCacheHelperTest {
@Test @Test
public void cacheTotalSizeAndUsedSize_shouldSaveToSharedPreference() { 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(); StorageCacheHelper.StorageCache storageCache = mHelper.retrieveCachedSize();
assertThat(storageCache.totalSize).isEqualTo(FAKE_TOTAL_SIZE); 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() { private StorageCacheHelper.StorageCache getFakeStorageCache() {