Close the load screen faster on pre-quota devices.
Pre-quota devices can take an absurd time to load. By loading the screen once the volume sizes load, we can just show "calculating..." for a really long time instead of a loading screen. Change-Id: Id8ab0609c2bc19531d530c6bdf6bff89c5bfac96 Fixes: 64150148 Test: Settings Robotest
This commit is contained in:
@@ -105,9 +105,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
public void onViewCreated(View v, Bundle savedInstanceState) {
|
public void onViewCreated(View v, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(v, savedInstanceState);
|
super.onViewCreated(v, savedInstanceState);
|
||||||
initializeCacheProvider();
|
initializeCacheProvider();
|
||||||
if (mAppsResult == null || mStorageInfo == null) {
|
maybeSetLoading(isQuotaSupported());
|
||||||
setLoading(true, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,10 +123,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onReceivedSizes() {
|
private void onReceivedSizes() {
|
||||||
if (mStorageInfo == null || mAppsResult == null) {
|
if (mStorageInfo != null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
|
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
|
||||||
mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
|
mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
|
||||||
mPreferenceController.setVolume(mVolume);
|
mPreferenceController.setVolume(mVolume);
|
||||||
@@ -141,6 +136,11 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
userController.setTotalSize(mStorageInfo.totalBytes);
|
userController.setTotalSize(mStorageInfo.totalBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAppsResult == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
|
mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
|
||||||
updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
|
updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
|
||||||
@@ -272,11 +272,21 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
return mStorageInfo;
|
return mStorageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public void setPrivateStorageInfo(PrivateStorageInfo info) {
|
||||||
|
mStorageInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
|
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
|
||||||
return mAppsResult;
|
return mAppsResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public void setAppsStorageResult(SparseArray<StorageAsyncLoader.AppsStorageResult> info) {
|
||||||
|
mAppsResult = info;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void initializeCachedValues() {
|
public void initializeCachedValues() {
|
||||||
PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
||||||
@@ -290,6 +300,16 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
mAppsResult = loaderResult;
|
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() {
|
private void initializeCacheProvider() {
|
||||||
mCachedStorageValuesHelper =
|
mCachedStorageValuesHelper =
|
||||||
new CachedStorageValuesHelper(getContext(), UserHandle.myUserId());
|
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
|
* IconLoaderCallbacks exists because StorageDashboardFragment already implements
|
||||||
* LoaderCallbacks for a different type.
|
* LoaderCallbacks for a different type.
|
||||||
|
@@ -18,7 +18,11 @@ package com.android.settings.deviceinfo;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -26,6 +30,7 @@ import android.app.Activity;
|
|||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
|
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
|
||||||
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
|
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.settings.TestConfig;
|
||||||
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -114,6 +120,87 @@ public class StorageDashboardFragmentTest {
|
|||||||
assertThat(mFragment.getAppsStorageResult()).isNull();
|
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
|
@Test
|
||||||
public void testSearchIndexProvider_shouldIndexResource() {
|
public void testSearchIndexProvider_shouldIndexResource() {
|
||||||
final List<SearchIndexableResource> indexRes =
|
final List<SearchIndexableResource> indexRes =
|
||||||
|
Reference in New Issue
Block a user