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

am: 598386ebab

Change-Id: I775f8b438eb6452bdbb2422efe4a56661c2ae7ed
This commit is contained in:
Daniel Nishi
2017-09-15 06:48:39 +00:00
committed by android-build-merger
2 changed files with 128 additions and 16 deletions

View File

@@ -104,9 +104,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
@@ -124,21 +122,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());
@@ -271,11 +271,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();
@@ -289,6 +299,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());
@@ -303,6 +323,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.

View File

@@ -18,7 +18,11 @@ package com.android.settings.deviceinfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -26,6 +30,7 @@ import android.app.Activity;
import android.os.storage.StorageManager;
import android.provider.SearchIndexableResource;
import android.util.SparseArray;
import android.view.View;
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
@@ -33,6 +38,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.drawer.CategoryKey;
import android.support.v7.widget.RecyclerView;
import org.junit.Before;
import org.junit.Test;
@@ -114,6 +120,87 @@ public class StorageDashboardFragmentTest {
assertThat(mFragment.getAppsStorageResult()).isNull();
}
@Test
public void test_loadWhenQuotaOffIfVolumeInfoNotLoaded() {
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
mFragment = spy(mFragment);
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
mFragment.maybeSetLoading(false);
verify(mFragment).setLoading(true, false);
}
@Test
public void test_dontLoadWhenQuotaOffIfVolumeInfoNotLoaded() {
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
mFragment = spy(mFragment);
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
mFragment.setPrivateStorageInfo(info);
mFragment.maybeSetLoading(false);
verify(mFragment, never()).setLoading(true, false);
}
@Test
public void test_loadWhenQuotaOnAndVolumeInfoLoadedButAppsMissing() {
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
mFragment = spy(mFragment);
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
mFragment.setPrivateStorageInfo(info);
mFragment.maybeSetLoading(true);
verify(mFragment).setLoading(true, false);
}
@Test
public void test_loadWhenQuotaOnAndAppsLoadedButVolumeInfoMissing() {
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
mFragment = spy(mFragment);
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
mFragment.setAppsStorageResult(new SparseArray<>());
mFragment.maybeSetLoading(true);
verify(mFragment).setLoading(true, false);
}
@Test
public void test_dontLoadWhenQuotaOnAndAllLoaded() {
View fakeView = mock(View.class, RETURNS_DEEP_STUBS);
RecyclerView fakeRecyclerView = mock(RecyclerView.class, RETURNS_DEEP_STUBS);
when(fakeView.findViewById(anyInt())).thenReturn(fakeView);
mFragment = spy(mFragment);
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
mFragment.setAppsStorageResult(new SparseArray<>());
PrivateStorageInfo storageInfo = new PrivateStorageInfo(0, 0);
mFragment.setPrivateStorageInfo(storageInfo);
mFragment.maybeSetLoading(true);
verify(mFragment, never()).setLoading(true, false);
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =