Merge "Close the load screen faster on pre-quota devices." into oc-mr1-dev

am: f42b529143

Change-Id: I3a8888fe8e555876ed058c29a91f1e9f17d82324
This commit is contained in:
Daniel Nishi
2017-09-14 18:07:16 +00:00
committed by android-build-merger
2 changed files with 128 additions and 16 deletions

View File

@@ -105,9 +105,7 @@ public class StorageDashboardFragment extends DashboardFragment
public void onViewCreated(View v, Bundle savedInstanceState) {
super.onViewCreated(v, savedInstanceState);
initializeCacheProvider();
if (mAppsResult == null || mStorageInfo == null) {
setLoading(true, false);
}
maybeSetLoading(isQuotaSupported());
}
@Override
@@ -125,21 +123,23 @@ public class StorageDashboardFragment extends DashboardFragment
}
private void onReceivedSizes() {
if (mStorageInfo == null || mAppsResult == null) {
return;
if (mStorageInfo != null) {
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
mPreferenceController.setVolume(mVolume);
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {
SecondaryUserController userController = (SecondaryUserController) controller;
userController.setTotalSize(mStorageInfo.totalBytes);
}
}
}
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
mPreferenceController.setVolume(mVolume);
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
AbstractPreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {
SecondaryUserController userController = (SecondaryUserController) controller;
userController.setTotalSize(mStorageInfo.totalBytes);
}
if (mAppsResult == null) {
return;
}
mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
@@ -272,11 +272,21 @@ public class StorageDashboardFragment extends DashboardFragment
return mStorageInfo;
}
@VisibleForTesting
public void setPrivateStorageInfo(PrivateStorageInfo info) {
mStorageInfo = info;
}
@VisibleForTesting
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
return mAppsResult;
}
@VisibleForTesting
public void setAppsStorageResult(SparseArray<StorageAsyncLoader.AppsStorageResult> info) {
mAppsResult = info;
}
@VisibleForTesting
public void initializeCachedValues() {
PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
@@ -290,6 +300,16 @@ public class StorageDashboardFragment extends DashboardFragment
mAppsResult = loaderResult;
}
@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)) {
setLoading(true /* loading */, false /* animate */);
}
}
private void initializeCacheProvider() {
mCachedStorageValuesHelper =
new CachedStorageValuesHelper(getContext(), UserHandle.myUserId());
@@ -304,6 +324,11 @@ public class StorageDashboardFragment extends DashboardFragment
}
}
private boolean isQuotaSupported() {
final StorageStatsManager stats = getActivity().getSystemService(StorageStatsManager.class);
return stats.isQuotaSupported(mVolume.fsUuid);
}
/**
* IconLoaderCallbacks exists because StorageDashboardFragment already implements
* LoaderCallbacks for a different type.