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:
@@ -104,9 +104,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
|
||||||
@@ -124,21 +122,23 @@ 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;
|
||||||
|
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;
|
if (mAppsResult == null) {
|
||||||
mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
|
mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
|
||||||
@@ -271,11 +271,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();
|
||||||
@@ -289,6 +299,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());
|
||||||
@@ -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
|
* 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