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
protected void onPostExecute(Boolean succeeded) {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
if (succeeded) {
Toast.makeText(mContext, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
.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.show();

View File

@@ -110,7 +110,7 @@ public class StorageCategoryFragment extends DashboardFragment
if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) {
StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize();
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
mPreferenceController.setUsedSize(cachedData.usedSize);
mPreferenceController.setUsedSize(cachedData.totalUsedSize);
mPreferenceController.setTotalSize(cachedData.totalSize);
}
if (mSelectedStorageEntry.isPrivate()) {
@@ -215,7 +215,8 @@ public class StorageCategoryFragment extends DashboardFragment
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
// 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++) {
final AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {

View File

@@ -240,7 +240,7 @@ public class StorageDashboardFragment extends DashboardFragment
if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) {
StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize();
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
mPreferenceController.setUsedSize(cachedData.usedSize);
mPreferenceController.setUsedSize(cachedData.totalUsedSize);
mPreferenceController.setTotalSize(cachedData.totalSize);
}
@@ -388,7 +388,8 @@ public class StorageDashboardFragment extends DashboardFragment
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
// 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++) {
final AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {

View File

@@ -46,7 +46,6 @@ public class SecondaryUserController extends AbstractPreferenceController implem
// PreferenceGroupKey to try to add our preference onto.
private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
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 @NonNull
@@ -58,6 +57,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
private long mSize;
private long mTotalSizeBytes;
private boolean mIsVisible;
private StorageCacheHelper mStorageCacheHelper;
/**
* 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);
mUser = info;
mSize = SIZE_NOT_SET;
mStorageCacheHelper = new StorageCacheHelper(context, info.id);
}
@Override
@@ -120,9 +121,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
mPreferenceGroup = screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
mStoragePreference.setTitle(mUser.name);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
if (mSize != SIZE_NOT_SET) {
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
}
setSize(mStorageCacheHelper.retrieveUsedSize(), false /* animate */);
mPreferenceGroup.setVisible(mIsVisible);
mPreferenceGroup.addPreference(mStoragePreference);
@@ -153,10 +152,10 @@ public class SecondaryUserController extends AbstractPreferenceController implem
*
* @param size Size in bytes.
*/
public void setSize(long size) {
public void setSize(long size, boolean animate) {
mSize = size;
if (mStoragePreference != null) {
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes, animate);
}
}
@@ -184,11 +183,14 @@ public class SecondaryUserController extends AbstractPreferenceController implem
@Override
public void handleResult(SparseArray<StorageAsyncLoader.StorageResult> stats) {
if (stats == null) {
setSize(mStorageCacheHelper.retrieveUsedSize(), false /* animate */);
return;
}
final StorageAsyncLoader.StorageResult result = stats.get(getUser().id);
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 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 VIDEOS_SIZE_KEY = "videos_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 TRASH_SIZE_KEY = "trash_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;
@@ -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
.edit()
.putLong(TOTAL_SIZE_KEY, totalSize)
.putLong(USED_SIZE_KEY, usedSize)
.putLong(TOTAL_USED_SIZE_KEY, totalUsedSize)
.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.
*/
public StorageCache retrieveCachedSize() {
StorageCache result = new StorageCache();
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.videosSize = mSharedPreferences.getLong(VIDEOS_SIZE_KEY, 0);
result.audioSize = mSharedPreferences.getLong(AUDIO_SIZE_KEY, 0);
@@ -102,7 +117,7 @@ public class StorageCacheHelper {
*/
public static class StorageCache {
public long totalSize;
public long usedSize;
public long totalUsedSize;
public long gamesSize;
public long allAppsExceptGamesSize;
public long audioSize;

View File

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

View File

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

View File

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

View File

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

View File

@@ -36,6 +36,7 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.add_a_language);
final LocalePickerWithRegion selector = LocalePickerWithRegion.createLanguagePicker(
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,
Function<SubscriptionManager, List<SubscriptionInfo>> convertor) {
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) {

View File

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

View File

@@ -37,7 +37,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
/** Lock Screen Safety Source for Safety Center. */
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_TYPE_ID = "NoScreenLockIssueType";
public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction";

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());
@@ -197,7 +197,7 @@ public class SecondaryUserControllerTest {
}
@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();

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() {