Storage Settings shift profile selection tab position
In this change, Storage Settings main UI is composed by 3 fragments. StorageDashboardFragment only shows when there is only personal profile for current user. ProfileSelectStorageFragment (controls preferences above profile tab) and StorageDashboardNoHeaderFragment (controls preferences below profile tab) only show when current user has installed work profile. Bug: 174964885 Test: atest com.android.settings.deviceinfo atest com.android.settings.deviceinfo.storage make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo.storage Change-Id: I50dea2fbcae39a1488e648f3ca615f54840e19d5
This commit is contained in:
@@ -43,7 +43,6 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.deviceinfo.storage.AutomaticStorageManagementSwitchPreferenceController;
|
||||
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
|
||||
import com.android.settings.deviceinfo.storage.DiskInitFragment;
|
||||
@@ -69,8 +68,20 @@ import com.android.settingslib.search.SearchIndexable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Storage Settings main UI is composed by 3 fragments:
|
||||
*
|
||||
* StorageDashboardFragment only shows when there is only personal profile for current user.
|
||||
*
|
||||
* ProfileSelectStorageFragment (controls preferences above profile tab) and
|
||||
* StorageCategoryFragment (controls preferences below profile tab) only show when current
|
||||
* user has installed work profile.
|
||||
*
|
||||
* ProfileSelectStorageFragment and StorageCategoryFragment have many similar or the same
|
||||
* code as StorageDashboardFragment. Remember to sync code between these fragments when you have to
|
||||
* change Storage Settings.
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class StorageDashboardFragment extends DashboardFragment
|
||||
implements
|
||||
@@ -104,7 +115,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
private final StorageEventListener mStorageEventListener = new StorageEventListener() {
|
||||
@Override
|
||||
public void onVolumeStateChanged(VolumeInfo volumeInfo, int oldState, int newState) {
|
||||
if (!isInteresting(volumeInfo)) {
|
||||
if (!StorageUtils.isStorageSettingsInterestedVolume(volumeInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -146,7 +157,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
|
||||
@Override
|
||||
public void onVolumeRecordChanged(VolumeRecord volumeRecord) {
|
||||
if (isVolumeRecordMissed(volumeRecord)) {
|
||||
if (StorageUtils.isVolumeRecordMissed(mStorageManager, volumeRecord)) {
|
||||
// VolumeRecord is a metadata of VolumeInfo, if a VolumeInfo is missing
|
||||
// (e.g., internal SD card is removed.) show the missing storage to users,
|
||||
// users can insert the SD card or manually forget the storage from the device.
|
||||
@@ -159,7 +170,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
// Find mapped VolumeInfo and replace with existing one for something changed.
|
||||
// (e.g., Renamed.)
|
||||
final VolumeInfo mappedVolumeInfo =
|
||||
mStorageManager.findVolumeByUuid(volumeRecord.getFsUuid());
|
||||
mStorageManager.findVolumeByUuid(volumeRecord.getFsUuid());
|
||||
if (mappedVolumeInfo == null) {
|
||||
return;
|
||||
}
|
||||
@@ -190,7 +201,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
|
||||
@Override
|
||||
public void onDiskScanned(DiskInfo disk, int volumeCount) {
|
||||
if (!isDiskUnsupported(disk)) {
|
||||
if (!StorageUtils.isDiskUnsupported(disk)) {
|
||||
return;
|
||||
}
|
||||
final StorageEntry storageEntry = new StorageEntry(disk);
|
||||
@@ -213,33 +224,6 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
}
|
||||
};
|
||||
|
||||
private static boolean isInteresting(VolumeInfo volumeInfo) {
|
||||
switch (volumeInfo.getType()) {
|
||||
case VolumeInfo.TYPE_PRIVATE:
|
||||
case VolumeInfo.TYPE_PUBLIC:
|
||||
case VolumeInfo.TYPE_STUB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* VolumeRecord is a metadata of VolumeInfo, this is the case where a VolumeInfo is missing.
|
||||
* (e.g., internal SD card is removed.)
|
||||
*/
|
||||
private boolean isVolumeRecordMissed(VolumeRecord volumeRecord) {
|
||||
return volumeRecord.getType() == VolumeInfo.TYPE_PRIVATE
|
||||
&& mStorageManager.findVolumeByUuid(volumeRecord.getFsUuid()) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A unsupported disk is the disk of problem format, android is not able to mount automatically.
|
||||
*/
|
||||
private static boolean isDiskUnsupported(DiskInfo disk) {
|
||||
return disk.volumeCount == 0 && disk.size > 0;
|
||||
}
|
||||
|
||||
private void refreshUi() {
|
||||
mStorageSelectionController.setStorageEntries(mStorageEntries);
|
||||
mStorageSelectionController.setSelectedStorageEntry(mSelectedStorageEntry);
|
||||
@@ -297,9 +281,8 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
// These member variables are initialized befoer super.onAttach for
|
||||
// createPreferenceControllers to work correctly.
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
mIsWorkProfile = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE)
|
||||
== ProfileSelectFragment.ProfileType.WORK;
|
||||
mUserId = Utils.getCurrentUserId(mUserManager, mIsWorkProfile);
|
||||
mIsWorkProfile = false;
|
||||
mUserId = UserHandle.myUserId();
|
||||
|
||||
super.onAttach(context);
|
||||
use(AutomaticStorageManagementSwitchPreferenceController.class).setFragmentManager(
|
||||
@@ -334,8 +317,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
initializeCacheProvider();
|
||||
maybeSetLoading(isQuotaSupported());
|
||||
|
||||
final Activity activity = getActivity();
|
||||
EntityHeaderController.newInstance(activity, this /*fragment*/,
|
||||
EntityHeaderController.newInstance(getActivity(), this /*fragment*/,
|
||||
null /* header view */)
|
||||
.setRecyclerView(getListView(), getSettingsLifecycle());
|
||||
}
|
||||
@@ -345,18 +327,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
super.onResume();
|
||||
|
||||
mStorageEntries.clear();
|
||||
mStorageEntries.addAll(mStorageManager.getVolumes().stream()
|
||||
.filter(volumeInfo -> isInteresting(volumeInfo))
|
||||
.map(volumeInfo -> new StorageEntry(getContext(), volumeInfo))
|
||||
.collect(Collectors.toList()));
|
||||
mStorageEntries.addAll(mStorageManager.getDisks().stream()
|
||||
.filter(disk -> isDiskUnsupported(disk))
|
||||
.map(disk -> new StorageEntry(disk))
|
||||
.collect(Collectors.toList()));
|
||||
mStorageEntries.addAll(mStorageManager.getVolumeRecords().stream()
|
||||
.filter(volumeRecord -> isVolumeRecordMissed(volumeRecord))
|
||||
.map(volumeRecord -> new StorageEntry(volumeRecord))
|
||||
.collect(Collectors.toList()));
|
||||
mStorageEntries.addAll(StorageUtils.getAllStorageEntries(getContext(), mStorageManager));
|
||||
refreshUi();
|
||||
mStorageManager.registerListener(mStorageEventListener);
|
||||
}
|
||||
@@ -381,19 +352,18 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
private void onReceivedSizes() {
|
||||
boolean stopLoading = false;
|
||||
if (mStorageInfo != null) {
|
||||
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
|
||||
final long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
|
||||
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
|
||||
mPreferenceController.setUsedSize(privateUsedBytes);
|
||||
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
|
||||
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
|
||||
AbstractPreferenceController controller = mSecondaryUsers.get(i);
|
||||
final AbstractPreferenceController controller = mSecondaryUsers.get(i);
|
||||
if (controller instanceof SecondaryUserController) {
|
||||
SecondaryUserController userController = (SecondaryUserController) controller;
|
||||
userController.setTotalSize(mStorageInfo.totalBytes);
|
||||
}
|
||||
}
|
||||
stopLoading = true;
|
||||
|
||||
}
|
||||
|
||||
if (mAppsResult != null) {
|
||||
@@ -428,7 +398,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
StorageManager sm = context.getSystemService(StorageManager.class);
|
||||
final StorageManager sm = context.getSystemService(StorageManager.class);
|
||||
mPreferenceController = new StorageItemPreferenceController(context, this,
|
||||
null /* volume */, new StorageManagerVolumeProvider(sm), mIsWorkProfile);
|
||||
controllers.add(mPreferenceController);
|
||||
@@ -440,18 +410,13 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void setVolume(VolumeInfo info) {
|
||||
mSelectedStorageEntry = new StorageEntry(getContext(), info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the secondary user controller sizes.
|
||||
*/
|
||||
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
|
||||
for (int i = 0, size = controllers.size(); i < size; i++) {
|
||||
AbstractPreferenceController controller = controllers.get(i);
|
||||
final AbstractPreferenceController controller = controllers.get(i);
|
||||
if (controller instanceof StorageAsyncLoader.ResultHandler) {
|
||||
StorageAsyncLoader.ResultHandler userController =
|
||||
(StorageAsyncLoader.ResultHandler) controller;
|
||||
@@ -552,9 +517,9 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void initializeCachedValues() {
|
||||
PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
||||
SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult =
|
||||
void initializeCachedValues() {
|
||||
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult =
|
||||
mCachedStorageValuesHelper.getCachedAppsStorageResult();
|
||||
if (info == null || loaderResult == null) {
|
||||
return;
|
||||
@@ -564,12 +529,15 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
mAppsResult = loaderResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate loading UI and animation if it's necessary.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void maybeSetLoading(boolean isQuotaSupported) {
|
||||
// If we have fast stats, we load until both have loaded.
|
||||
// If we have slow stats, we load when we get the total volume sizes.
|
||||
if ((isQuotaSupported && (mStorageInfo == null || mAppsResult == null)) ||
|
||||
(!isQuotaSupported && mStorageInfo == null)) {
|
||||
if ((isQuotaSupported && (mStorageInfo == null || mAppsResult == null))
|
||||
|| (!isQuotaSupported && mStorageInfo == null)) {
|
||||
setLoading(true /* loading */, false /* animate */);
|
||||
}
|
||||
}
|
||||
@@ -622,6 +590,10 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* VolumeSizeCallbacks exists because StorageCategoryFragment already implements
|
||||
* LoaderCallbacks for a different type.
|
||||
*/
|
||||
public final class VolumeSizeCallbacks
|
||||
implements LoaderManager.LoaderCallbacks<PrivateStorageInfo> {
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user