diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java index eff487b9348..30d159bbb04 100644 --- a/src/com/android/settings/ResetNetworkConfirm.java +++ b/src/com/android/settings/ResetNetworkConfirm.java @@ -150,7 +150,10 @@ public class ResetNetworkConfirm extends InstrumentedFragment { @Override protected void onPostExecute(Boolean succeeded) { - mProgressDialog.dismiss(); + 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(); diff --git a/src/com/android/settings/deviceinfo/StorageCategoryFragment.java b/src/com/android/settings/deviceinfo/StorageCategoryFragment.java index e02497271c0..fe545b592e4 100644 --- a/src/com/android/settings/deviceinfo/StorageCategoryFragment.java +++ b/src/com/android/settings/deviceinfo/StorageCategoryFragment.java @@ -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) { diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java index 07ac4e53021..77d4072956d 100644 --- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java +++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java @@ -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) { diff --git a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java index 84cafd40797..9a280bfa4e2 100644 --- a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java +++ b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java @@ -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 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); } } diff --git a/src/com/android/settings/deviceinfo/storage/StorageCacheHelper.java b/src/com/android/settings/deviceinfo/storage/StorageCacheHelper.java index a868c9f3f6e..e6da454f2f1 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageCacheHelper.java +++ b/src/com/android/settings/deviceinfo/storage/StorageCacheHelper.java @@ -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; diff --git a/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java index 872fa8a462b..be2a64abf58 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java @@ -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); } diff --git a/src/com/android/settings/dream/DreamAdapter.java b/src/com/android/settings/dream/DreamAdapter.java index ea64e8dd1d8..8494088ba12 100644 --- a/src/com/android/settings/dream/DreamAdapter.java +++ b/src/com/android/settings/dream/DreamAdapter.java @@ -115,6 +115,7 @@ public class DreamAdapter extends RecyclerView.Adapter mCustomizeButton.setOnClickListener(v -> item.onCustomizeClicked()); mCustomizeButton.setVisibility( item.allowCustomization() && mEnabled ? View.VISIBLE : View.GONE); + mCustomizeButton.setSelected(false); itemView.setOnClickListener(v -> { item.onItemClicked(); diff --git a/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java b/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java index 94415a1d9d9..d0f5887dbc2 100644 --- a/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java +++ b/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java @@ -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: { diff --git a/src/com/android/settings/localepicker/AppLocalePickerActivity.java b/src/com/android/settings/localepicker/AppLocalePickerActivity.java index 9a8aed2abf3..4f23ae802c9 100644 --- a/src/com/android/settings/localepicker/AppLocalePickerActivity.java +++ b/src/com/android/settings/localepicker/AppLocalePickerActivity.java @@ -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( diff --git a/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java b/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java index bcc55e3a2db..a8c93c17944 100644 --- a/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java +++ b/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java @@ -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 */); diff --git a/src/com/android/settings/network/helper/SelectableSubscriptions.java b/src/com/android/settings/network/helper/SelectableSubscriptions.java index 45d842b29b9..8e8f405e1fb 100644 --- a/src/com/android/settings/network/helper/SelectableSubscriptions.java +++ b/src/com/android/settings/network/helper/SelectableSubscriptions.java @@ -141,7 +141,8 @@ public class SelectableSubscriptions implements Callable getSubInfoList(Context context, Function> convertor) { SubscriptionManager subManager = getSubscriptionManager(context); - return (subManager == null) ? Collections.emptyList() : convertor.apply(subManager); + List result = (subManager == null) ? null : convertor.apply(subManager); + return (result == null) ? Collections.emptyList() : result; } protected SubscriptionManager getSubscriptionManager(Context context) { diff --git a/src/com/android/settings/safetycenter/BiometricsSafetySource.java b/src/com/android/settings/safetycenter/BiometricsSafetySource.java index cb3ad3502a5..738268cde6e 100644 --- a/src/com/android/settings/safetycenter/BiometricsSafetySource.java +++ b/src/com/android/settings/safetycenter/BiometricsSafetySource.java @@ -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() { } diff --git a/src/com/android/settings/safetycenter/LockScreenSafetySource.java b/src/com/android/settings/safetycenter/LockScreenSafetySource.java index 80a132350e0..6295268886b 100644 --- a/src/com/android/settings/safetycenter/LockScreenSafetySource.java +++ b/src/com/android/settings/safetycenter/LockScreenSafetySource.java @@ -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"; diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java index ad811dcceac..eb8f5f40535 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java @@ -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 argumentCaptor = ArgumentCaptor.forClass(Preference.class); verify(mGroup).addPreference(argumentCaptor.capture()); @@ -114,7 +114,7 @@ public class SecondaryUserControllerTest { when(mUserManager.getUsers()).thenReturn(userInfos); final List 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 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 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 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 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 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 controllers = SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager, - false /* isWorkProfileOnly */); + false /* isWorkProfileOnly */); assertThat(controllers).hasSize(1); // We should have the NoSecondaryUserController. diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageCacheHelperTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageCacheHelperTest.java index 1956b09a95d..9e20e78c03a 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageCacheHelperTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageCacheHelperTest.java @@ -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() {