Search in sources :

Example 41 with StorageItemPreference

use of com.android.settings.deviceinfo.StorageItemPreference in project android_packages_apps_Settings by omnirom.

the class StorageItemPreferenceControllerTest method displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable.

@Test
public void displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable() {
    StorageItemPreference audio = new StorageItemPreference(mContext);
    StorageItemPreference image = new StorageItemPreference(mContext);
    StorageItemPreference games = new StorageItemPreference(mContext);
    StorageItemPreference apps = new StorageItemPreference(mContext);
    StorageItemPreference system = new StorageItemPreference(mContext);
    StorageItemPreference files = new StorageItemPreference(mContext);
    PreferenceScreen screen = mock(PreferenceScreen.class);
    when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
    when(mVolume.isMountedReadable()).thenReturn(false);
    mController.displayPreference(screen);
    verify(screen).removePreference(files);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) VolumeInfo(android.os.storage.VolumeInfo) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference) Test(org.junit.Test)

Example 42 with StorageItemPreference

use of com.android.settings.deviceinfo.StorageItemPreference in project android_packages_apps_Settings by omnirom.

the class StorageItemPreferenceControllerTest method testMeasurementCompletedUpdatesPreferences.

@Test
public void testMeasurementCompletedUpdatesPreferences() {
    StorageItemPreference audio = new StorageItemPreference(mContext);
    StorageItemPreference image = new StorageItemPreference(mContext);
    StorageItemPreference games = new StorageItemPreference(mContext);
    StorageItemPreference movies = new StorageItemPreference(mContext);
    StorageItemPreference apps = new StorageItemPreference(mContext);
    StorageItemPreference system = new StorageItemPreference(mContext);
    StorageItemPreference files = new StorageItemPreference(mContext);
    PreferenceScreen screen = mock(PreferenceScreen.class);
    when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    when(screen.findPreference(eq(StorageItemPreferenceController.MOVIES_KEY))).thenReturn(movies);
    when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    mController.displayPreference(screen);
    // There should 870MB attributed.
    mController.setUsedSize(MEGABYTE_IN_BYTES * 970);
    StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
    result.gamesSize = MEGABYTE_IN_BYTES * 80;
    result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
    result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
    result.otherAppsSize = MEGABYTE_IN_BYTES * 90;
    result.externalStats = new StorageStatsSource.ExternalStorageStats(// total
    MEGABYTE_IN_BYTES * 500, // audio
    MEGABYTE_IN_BYTES * 100, // video
    MEGABYTE_IN_BYTES * 150, MEGABYTE_IN_BYTES * 200, // image
    0);
    SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
    results.put(0, result);
    mController.onLoadFinished(results, 0);
    assertThat(audio.getSummary().toString()).isEqualTo("0.14 GB");
    assertThat(image.getSummary().toString()).isEqualTo("0.35 GB");
    assertThat(games.getSummary().toString()).isEqualTo("0.08 GB");
    assertThat(movies.getSummary().toString()).isEqualTo("0.16 GB");
    assertThat(apps.getSummary().toString()).isEqualTo("0.09 GB");
    assertThat(files.getSummary().toString()).isEqualTo("0.05 GB");
}
Also used : SparseArray(android.util.SparseArray) PreferenceScreen(android.support.v7.preference.PreferenceScreen) StorageStatsSource(com.android.settingslib.applications.StorageStatsSource) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference) Test(org.junit.Test)

Example 43 with StorageItemPreference

use of com.android.settings.deviceinfo.StorageItemPreference in project android_packages_apps_Settings by omnirom.

the class StorageItemPreferenceControllerTest method displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage.

@Test
public void displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage() {
    StorageItemPreference audio = new StorageItemPreference(mContext);
    StorageItemPreference image = new StorageItemPreference(mContext);
    StorageItemPreference games = new StorageItemPreference(mContext);
    StorageItemPreference apps = new StorageItemPreference(mContext);
    StorageItemPreference system = new StorageItemPreference(mContext);
    StorageItemPreference files = new StorageItemPreference(mContext);
    PreferenceScreen screen = mock(PreferenceScreen.class);
    when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(null);
    mController.displayPreference(screen);
    verify(screen).removePreference(files);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) VolumeInfo(android.os.storage.VolumeInfo) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference) Test(org.junit.Test)

Example 44 with StorageItemPreference

use of com.android.settings.deviceinfo.StorageItemPreference in project android_packages_apps_Settings by omnirom.

the class UserProfileController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    mStoragePreference = new StorageItemPreference(screen.getContext());
    mStoragePreference.setOrder(mPreferenceOrder);
    mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
    mStoragePreference.setTitle(mUser.name);
    screen.addPreference(mStoragePreference);
}
Also used : StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference)

Example 45 with StorageItemPreference

use of com.android.settings.deviceinfo.StorageItemPreference in project android_packages_apps_Settings by DirtyUnicorns.

the class StorageItemPreferenceControllerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application.getApplicationContext());
    FakeFeatureFactory.setupForTest(mContext);
    mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
    mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
    mVolume = spy(new VolumeInfo("id", 0, null, "id"));
    // 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, mFragment, mVolume, mSvp);
    mPreference = new StorageItemPreference(mContext);
    // Inflate the preference and the widget.
    LayoutInflater inflater = LayoutInflater.from(mContext);
    final View view = inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
}
Also used : LayoutInflater(android.view.LayoutInflater) VolumeInfo(android.os.storage.VolumeInfo) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference) View(android.view.View) LinearLayout(android.widget.LinearLayout) Before(org.junit.Before)

Aggregations

StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)70 Test (org.junit.Test)49 VolumeInfo (android.os.storage.VolumeInfo)42 PreferenceScreen (android.support.v7.preference.PreferenceScreen)42 Drawable (android.graphics.drawable.Drawable)7 UserHandle (android.os.UserHandle)7 SparseArray (android.util.SparseArray)7 LayoutInflater (android.view.LayoutInflater)7 LinearLayout (android.widget.LinearLayout)7 PreferenceScreen (androidx.preference.PreferenceScreen)7 StorageStatsSource (com.android.settingslib.applications.StorageStatsSource)7 Before (org.junit.Before)7 PreferenceGroup (android.support.v7.preference.PreferenceGroup)6 View (android.view.View)6 PreferenceGroup (androidx.preference.PreferenceGroup)1