Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f42b5291 authored by Daniel Nishi's avatar Daniel Nishi Committed by Android (Google) Code Review
Browse files

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

parents bc6dc5c2 b05a346f
Loading
Loading
Loading
Loading
+41 −16
Original line number Diff line number Diff line
@@ -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,10 +123,7 @@ 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);
@@ -141,6 +136,11 @@ public class StorageDashboardFragment extends DashboardFragment
                    userController.setTotalSize(mStorageInfo.totalBytes);
                }
            }
        }

        if (mAppsResult == null) {
            return;
        }

        mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
        updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
@@ -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.
+87 −0
Original line number Diff line number Diff line
@@ -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 =