Use the "fast track" storage calculation for all categories.

Bug: 34204877
Test: Settings Robo
Change-Id: I4a3e26e6e96e9b697c1019160c053b079076d3a2
This commit is contained in:
Daniel Nishi
2017-01-31 12:48:23 -08:00
parent 23eb4378d6
commit 7cec1bc53c
5 changed files with 57 additions and 106 deletions

View File

@@ -25,7 +25,6 @@ import static org.mockito.Mockito.when;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.UserHandle;
import android.os.storage.VolumeInfo;
import android.provider.DocumentsContract;
@@ -41,7 +40,6 @@ import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.SubSettings;
import com.android.settings.TestConfig;
import com.android.settings.applications.ManageApplications;
import com.android.settingslib.deviceinfo.StorageMeasurement;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
import org.junit.Before;
@@ -55,8 +53,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.HashMap;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageItemPreferenceControllerTest {
@@ -82,7 +78,7 @@ public class StorageItemPreferenceControllerTest {
mContext = RuntimeEnvironment.application;
// Note: null is passed as the Lifecycle because we are handling it outside of the normal
// Settings fragment lifecycle for test purposes.
mController = new StorageItemPreferenceController(mContext, null, mFragment, mVolume, mSvp);
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
mPreference = new StorageItemPreferenceAlternate(mContext);
// Inflate the preference and the widget.
@@ -205,23 +201,23 @@ public class StorageItemPreferenceControllerTest {
Mockito.eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
mController.displayPreference(screen);
StorageMeasurement.MeasurementDetails details = new StorageMeasurement.MeasurementDetails();
details.appsSize.put(0, KILOBYTE);
HashMap<String, Long> mediaSizes = new HashMap<>();
mediaSizes.put(Environment.DIRECTORY_PICTURES, KILOBYTE * 2);
mediaSizes.put(Environment.DIRECTORY_MOVIES, KILOBYTE * 3);
mediaSizes.put(Environment.DIRECTORY_MUSIC, KILOBYTE * 4);
mediaSizes.put(Environment.DIRECTORY_DOWNLOADS, KILOBYTE * 5);
details.mediaSize.put(0, mediaSizes);
mController.setSystemSize(KILOBYTE * 6);
mController.onDetailsChanged(details);
AppsAsyncLoader.AppsStorageResult result = new AppsAsyncLoader.AppsStorageResult();
StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
result.gamesSize = KILOBYTE * 8;
result.musicAppsSize = KILOBYTE * 4;
result.otherAppsSize = KILOBYTE * 9;
result.externalStats = new StorageStatsSource.ExternalStorageStats(
KILOBYTE * 50, // total
KILOBYTE * 10, // audio
KILOBYTE * 15, // video
KILOBYTE * 20); // image
result.gamesSize = KILOBYTE * 8;
result.otherAppsSize = KILOBYTE * 9;
mController.onLoadFinished(null, result);
assertThat(audio.getSummary().toString()).isEqualTo("4.00KB");
assertThat(image.getSummary().toString()).isEqualTo("5.00KB");
assertThat(audio.getSummary().toString()).isEqualTo("14.00KB"); // 4KB apps + 10KB files
assertThat(image.getSummary().toString()).isEqualTo("35.00KB"); // 15KB video + 20KB images
assertThat(games.getSummary().toString()).isEqualTo("8.00KB");
assertThat(apps.getSummary().toString()).isEqualTo("9.00KB");
assertThat(system.getSummary().toString()).isEqualTo("6.00KB");

View File

@@ -42,7 +42,7 @@ import java.util.ArrayList;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppAsyncLoaderTest {
public class StorageAsyncLoaderTest {
@Mock
private StorageStatsSource mSource;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -51,13 +51,13 @@ public class AppAsyncLoaderTest {
private PackageManagerWrapper mPackageManager;
ArrayList<ApplicationInfo> mInfo = new ArrayList<>();
private AppsAsyncLoader mLoader;
private StorageAsyncLoader mLoader;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mInfo = new ArrayList<>();
mLoader = new AppsAsyncLoader(mContext, 1, "id", mSource, mPackageManager);
mLoader = new StorageAsyncLoader(mContext, 1, "id", mSource, mPackageManager);
when(mPackageManager.getInstalledApplicationsAsUser(anyInt(), anyInt())).thenReturn(mInfo);
}
@@ -66,7 +66,7 @@ public class AppAsyncLoaderTest {
addPackage(1001, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
addPackage(1002, 0, 100, 1000, ApplicationInfo.CATEGORY_UNDEFINED);
AppsAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
StorageAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
assertThat(result.gamesSize).isEqualTo(0L);
assertThat(result.otherAppsSize).isEqualTo(1111L);
@@ -76,7 +76,7 @@ public class AppAsyncLoaderTest {
public void testGamesAreFiltered() throws Exception {
addPackage(1001, 0, 1, 10, ApplicationInfo.CATEGORY_GAME);
AppsAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
StorageAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
assertThat(result.gamesSize).isEqualTo(11L);
assertThat(result.otherAppsSize).isEqualTo(0);
@@ -87,7 +87,7 @@ public class AppAsyncLoaderTest {
addPackage(1001, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
addPackage(1001, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
AppsAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
StorageAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
assertThat(result.otherAppsSize).isEqualTo(11L);
}
@@ -96,7 +96,7 @@ public class AppAsyncLoaderTest {
public void testCacheIsIgnored() throws Exception {
addPackage(1001, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
AppsAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
StorageAsyncLoader.AppsStorageResult result = mLoader.loadInBackground();
assertThat(result.otherAppsSize).isEqualTo(11L);
}