Home | History | Annotate | Download | only in storage
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 package com.android.settings.deviceinfo.storage;
     17 
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
     21 
     22 import static org.mockito.Matchers.any;
     23 import static org.mockito.Matchers.anyString;
     24 import static org.mockito.Matchers.eq;
     25 import static org.mockito.Mockito.mock;
     26 import static org.mockito.Mockito.spy;
     27 import static org.mockito.Mockito.times;
     28 import static org.mockito.Mockito.verify;
     29 import static org.mockito.Mockito.when;
     30 
     31 import android.app.Fragment;
     32 import android.content.Context;
     33 import android.content.Intent;
     34 import android.graphics.drawable.Drawable;
     35 import android.os.UserHandle;
     36 import android.os.storage.VolumeInfo;
     37 import android.support.v7.preference.PreferenceScreen;
     38 import android.util.SparseArray;
     39 import android.view.LayoutInflater;
     40 import android.view.View;
     41 import android.widget.LinearLayout;
     42 
     43 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     44 import com.android.settings.R;
     45 import com.android.settings.SettingsActivity;
     46 import com.android.settings.SettingsRobolectricTestRunner;
     47 import com.android.settings.SubSettings;
     48 import com.android.settings.TestConfig;
     49 import com.android.settings.applications.ManageApplications;
     50 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
     51 import com.android.settings.deviceinfo.PrivateVolumeSettings;
     52 import com.android.settings.deviceinfo.StorageItemPreference;
     53 import com.android.settings.testutils.FakeFeatureFactory;
     54 import com.android.settings.testutils.shadow.SettingsShadowResources;
     55 import com.android.settingslib.applications.StorageStatsSource;
     56 import com.android.settingslib.deviceinfo.StorageVolumeProvider;
     57 
     58 import org.junit.After;
     59 import org.junit.Before;
     60 import org.junit.Test;
     61 import org.junit.runner.RunWith;
     62 import org.mockito.Answers;
     63 import org.mockito.ArgumentCaptor;
     64 import org.mockito.Mock;
     65 import org.mockito.MockitoAnnotations;
     66 import org.robolectric.RuntimeEnvironment;
     67 import org.robolectric.annotation.Config;
     68 
     69 @RunWith(SettingsRobolectricTestRunner.class)
     70 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     71 public class StorageItemPreferenceControllerTest {
     72     private Context mContext;
     73     private VolumeInfo mVolume;
     74     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     75     private Fragment mFragment;
     76     @Mock
     77     private StorageVolumeProvider mSvp;
     78     private StorageItemPreferenceController mController;
     79     private StorageItemPreference mPreference;
     80     private FakeFeatureFactory mFakeFeatureFactory;
     81     private MetricsFeatureProvider mMetricsFeatureProvider;
     82 
     83     @Before
     84     public void setUp() throws Exception {
     85         MockitoAnnotations.initMocks(this);
     86         SettingsShadowResources.overrideResource("android:string/fileSizeSuffix", "%1$s %2$s");
     87         SettingsShadowResources.overrideResource("android:string/gigabyteShort", "GB");
     88         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
     89         FakeFeatureFactory.setupForTest(mContext);
     90         mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
     91         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
     92         mVolume = spy(new VolumeInfo("id", 0, null, "id"));
     93         // Note: null is passed as the Lifecycle because we are handling it outside of the normal
     94         //       Settings fragment lifecycle for test purposes.
     95         mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
     96         mPreference = new StorageItemPreference(mContext);
     97 
     98         // Inflate the preference and the widget.
     99         LayoutInflater inflater = LayoutInflater.from(mContext);
    100         final View view = inflater.inflate(
    101                 mPreference.getLayoutResource(), new LinearLayout(mContext), false);
    102     }
    103 
    104     @After
    105     public void tearDown() {
    106         SettingsShadowResources.reset();
    107     }
    108 
    109     @Test
    110     public void testUpdateStateWithInitialState() {
    111         assertThat(mPreference.getSummary().toString()).isEqualTo(
    112                 mContext.getString(R.string.memory_calculating_size));
    113     }
    114 
    115     @Test
    116     public void testClickPhotos() {
    117         mPreference.setKey("pref_photos_videos");
    118         mController.handlePreferenceTreeClick(mPreference);
    119 
    120         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
    121         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
    122                 any(UserHandle.class));
    123 
    124         Intent intent = argumentCaptor.getValue();
    125         assertThat(intent.getType()).isEqualTo("image/*");
    126         assertThat(intent.getAction()).isEqualTo(android.content.Intent.ACTION_VIEW);
    127         assertThat(intent.getBooleanExtra(Intent.EXTRA_FROM_STORAGE, false)).isTrue();
    128     }
    129 
    130     @Test
    131     public void testClickAudio() {
    132         mPreference.setKey("pref_music_audio");
    133         mController.handlePreferenceTreeClick(mPreference);
    134 
    135         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
    136         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
    137                 any(UserHandle.class));
    138         Intent intent = argumentCaptor.getValue();
    139 
    140         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
    141         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
    142         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
    143                 ManageApplications.class.getName());
    144         assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS).getInt(
    145                 ManageApplications.EXTRA_STORAGE_TYPE, 0)).isEqualTo(
    146                 ManageApplications.STORAGE_TYPE_MUSIC);
    147     }
    148 
    149     @Test
    150     public void handlePreferenceTreeClick_tappingAudioWhileUninitializedDoesntCrash() {
    151         mController.setVolume(null);
    152 
    153         mPreference.setKey("pref_music_audio");
    154         mController.handlePreferenceTreeClick(mPreference);
    155     }
    156 
    157     @Test
    158     public void testClickApps() {
    159         mPreference.setKey("pref_other_apps");
    160         mController.handlePreferenceTreeClick(mPreference);
    161 
    162         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
    163         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
    164                 any(UserHandle.class));
    165 
    166         Intent intent = argumentCaptor.getValue();
    167         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
    168         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
    169         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
    170                 ManageApplications.class.getName());
    171         assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
    172                 .isEqualTo(R.string.apps_storage);
    173     }
    174 
    175     @Test
    176     public void handlePreferenceTreeClick_tappingAppsWhileUninitializedDoesntCrash() {
    177         mController.setVolume(null);
    178 
    179         mPreference.setKey("pref_other_apps");
    180         mController.handlePreferenceTreeClick(mPreference);
    181     }
    182 
    183     @Test
    184     public void testClickFiles() {
    185         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
    186         mPreference.setKey("pref_files");
    187         mController.handlePreferenceTreeClick(mPreference);
    188 
    189         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
    190         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
    191                 any(UserHandle.class));
    192 
    193         Intent intent = argumentCaptor.getValue();
    194         Intent browseIntent = mVolume.buildBrowseIntent();
    195         assertThat(intent.getAction()).isEqualTo(browseIntent.getAction());
    196         assertThat(intent.getData()).isEqualTo(browseIntent.getData());
    197         verify(mMetricsFeatureProvider, times(1)).action(
    198                 any(Context.class), eq(MetricsEvent.STORAGE_FILES));
    199     }
    200 
    201     @Test
    202     public void testClickGames() {
    203         mPreference.setKey("pref_games");
    204         mController.handlePreferenceTreeClick(mPreference);
    205 
    206         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
    207         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
    208                 any(UserHandle.class));
    209 
    210         Intent intent = argumentCaptor.getValue();
    211         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
    212         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
    213         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
    214                 ManageApplications.class.getName());
    215         assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
    216                 .isEqualTo(R.string.game_storage_settings);
    217     }
    218 
    219     @Test
    220     public void testClickMovies() {
    221         mPreference.setKey("pref_movies");
    222         mController.handlePreferenceTreeClick(mPreference);
    223 
    224         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
    225         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
    226                 any(UserHandle.class));
    227 
    228         Intent intent = argumentCaptor.getValue();
    229         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
    230         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
    231         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
    232                 ManageApplications.class.getName());
    233         assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
    234                 .isEqualTo(R.string.storage_movies_tv);
    235     }
    236 
    237     @Test
    238     public void testClickSystem() {
    239         mPreference.setKey("pref_system");
    240         assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
    241 
    242         verify(mFragment.getFragmentManager().beginTransaction()).add(
    243                 any(PrivateVolumeSettings.SystemInfoFragment.class), anyString());
    244     }
    245 
    246     @Test
    247     public void testMeasurementCompletedUpdatesPreferences() {
    248         StorageItemPreference audio = new StorageItemPreference(mContext);
    249         StorageItemPreference image = new StorageItemPreference(mContext);
    250         StorageItemPreference games = new StorageItemPreference(mContext);
    251         StorageItemPreference movies = new StorageItemPreference(mContext);
    252         StorageItemPreference apps = new StorageItemPreference(mContext);
    253         StorageItemPreference system = new StorageItemPreference(mContext);
    254         StorageItemPreference files = new StorageItemPreference(mContext);
    255         PreferenceScreen screen = mock(PreferenceScreen.class);
    256         when(screen.findPreference(
    257                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    258         when(screen.findPreference(
    259                 eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    260         when(screen.findPreference(
    261                 eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    262         when(screen.findPreference(
    263                 eq(StorageItemPreferenceController.MOVIES_KEY))).thenReturn(movies);
    264         when(screen.findPreference(
    265                 eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    266         when(screen.findPreference(
    267                 eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    268         when(screen.findPreference(
    269                 eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    270         mController.displayPreference(screen);
    271 
    272         mController.setUsedSize(MEGABYTE_IN_BYTES * 970); // There should 870MB attributed.
    273         StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
    274         result.gamesSize = MEGABYTE_IN_BYTES * 80;
    275         result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
    276         result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
    277         result.otherAppsSize = MEGABYTE_IN_BYTES * 90;
    278         result.externalStats =
    279                 new StorageStatsSource.ExternalStorageStats(
    280                         MEGABYTE_IN_BYTES * 500, // total
    281                         MEGABYTE_IN_BYTES * 100, // audio
    282                         MEGABYTE_IN_BYTES * 150, // video
    283                         MEGABYTE_IN_BYTES * 200, 0); // image
    284 
    285         SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
    286         results.put(0, result);
    287         mController.onLoadFinished(results, 0);
    288 
    289         assertThat(audio.getSummary().toString()).isEqualTo("0.14GB");
    290         assertThat(image.getSummary().toString()).isEqualTo("0.35GB");
    291         assertThat(games.getSummary().toString()).isEqualTo("0.08GB");
    292         assertThat(movies.getSummary().toString()).isEqualTo("0.16GB");
    293         assertThat(apps.getSummary().toString()).isEqualTo("0.09GB");
    294         assertThat(files.getSummary().toString()).isEqualTo("0.05GB");
    295     }
    296 
    297     @Test
    298     public void settingUserIdAppliesNewIcons() {
    299         StorageItemPreference audio = spy(new StorageItemPreference(mContext));
    300         audio.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    301         StorageItemPreference video = spy(new StorageItemPreference(mContext));
    302         video.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    303         StorageItemPreference image = spy(new StorageItemPreference(mContext));
    304         image.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    305         StorageItemPreference games = spy(new StorageItemPreference(mContext));
    306         games.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    307         StorageItemPreference apps = spy(new StorageItemPreference(mContext));
    308         apps.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    309         StorageItemPreference system = spy(new StorageItemPreference(mContext));
    310         system.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    311         StorageItemPreference files = spy(new StorageItemPreference(mContext));
    312         files.setIcon(R.drawable.ic_photo_library_vd_theme_24);
    313         PreferenceScreen screen = mock(PreferenceScreen.class);
    314         when(screen.findPreference(
    315                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
    316         when(screen.findPreference(
    317                 eq(StorageItemPreferenceController.MOVIES_KEY))).thenReturn(video);
    318         when(screen.findPreference(
    319                 eq(StorageItemPreferenceController.PHOTO_KEY))).thenReturn(image);
    320         when(screen.findPreference(
    321                 eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    322         when(screen.findPreference(
    323                 eq(StorageItemPreferenceController.OTHER_APPS_KEY))).thenReturn(apps);
    324         when(screen.findPreference(
    325                 eq(StorageItemPreferenceController.SYSTEM_KEY))).thenReturn(system);
    326         when(screen.findPreference(
    327                 eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
    328         mController.displayPreference(screen);
    329 
    330         mController.setUserId(new UserHandle(10));
    331 
    332         verify(audio, times(2)).setIcon(any(Drawable.class));
    333         verify(video, times(2)).setIcon(any(Drawable.class));
    334         verify(image, times(2)).setIcon(any(Drawable.class));
    335         verify(games, times(2)).setIcon(any(Drawable.class));
    336         verify(apps, times(2)).setIcon(any(Drawable.class));
    337         verify(system, times(2)).setIcon(any(Drawable.class));
    338         verify(files, times(2)).setIcon(any(Drawable.class));
    339     }
    340 
    341     @Test
    342     public void displayPreference_dontHideFilePreferenceWhenEmulatedInternalStorageUsed() {
    343         StorageItemPreference audio = new StorageItemPreference(mContext);
    344         StorageItemPreference image = new StorageItemPreference(mContext);
    345         StorageItemPreference games = new StorageItemPreference(mContext);
    346         StorageItemPreference apps = new StorageItemPreference(mContext);
    347         StorageItemPreference system = new StorageItemPreference(mContext);
    348         StorageItemPreference files = new StorageItemPreference(mContext);
    349         PreferenceScreen screen = mock(PreferenceScreen.class);
    350         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
    351                 .thenReturn(audio);
    352         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
    353                 .thenReturn(image);
    354         when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    355         when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
    356                 .thenReturn(apps);
    357         when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
    358                 .thenReturn(system);
    359         when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
    360                 .thenReturn(files);
    361 
    362         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
    363         when(mVolume.isMountedReadable()).thenReturn(true);
    364 
    365         mController.displayPreference(screen);
    366 
    367         verify(screen, times(0)).removePreference(files);
    368     }
    369 
    370     @Test
    371     public void displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable() {
    372         StorageItemPreference audio = new StorageItemPreference(mContext);
    373         StorageItemPreference image = new StorageItemPreference(mContext);
    374         StorageItemPreference games = new StorageItemPreference(mContext);
    375         StorageItemPreference apps = new StorageItemPreference(mContext);
    376         StorageItemPreference system = new StorageItemPreference(mContext);
    377         StorageItemPreference files = new StorageItemPreference(mContext);
    378         PreferenceScreen screen = mock(PreferenceScreen.class);
    379         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
    380                 .thenReturn(audio);
    381         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
    382                 .thenReturn(image);
    383         when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    384         when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
    385                 .thenReturn(apps);
    386         when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
    387                 .thenReturn(system);
    388         when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
    389                 .thenReturn(files);
    390 
    391         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
    392         when(mVolume.isMountedReadable()).thenReturn(false);
    393 
    394         mController.displayPreference(screen);
    395 
    396         verify(screen).removePreference(files);
    397     }
    398 
    399     @Test
    400     public void displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage() {
    401         StorageItemPreference audio = new StorageItemPreference(mContext);
    402         StorageItemPreference image = new StorageItemPreference(mContext);
    403         StorageItemPreference games = new StorageItemPreference(mContext);
    404         StorageItemPreference apps = new StorageItemPreference(mContext);
    405         StorageItemPreference system = new StorageItemPreference(mContext);
    406         StorageItemPreference files = new StorageItemPreference(mContext);
    407         PreferenceScreen screen = mock(PreferenceScreen.class);
    408         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
    409                 .thenReturn(audio);
    410         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
    411                 .thenReturn(image);
    412         when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    413         when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
    414                 .thenReturn(apps);
    415         when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
    416                 .thenReturn(system);
    417         when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
    418                 .thenReturn(files);
    419 
    420         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
    421 
    422         mController.displayPreference(screen);
    423 
    424         verify(screen).removePreference(files);
    425     }
    426 
    427     @Test
    428     public void displayPreference_updateFilePreferenceToHideAfterSettingVolume() {
    429         StorageItemPreference audio = new StorageItemPreference(mContext);
    430         StorageItemPreference image = new StorageItemPreference(mContext);
    431         StorageItemPreference games = new StorageItemPreference(mContext);
    432         StorageItemPreference apps = new StorageItemPreference(mContext);
    433         StorageItemPreference system = new StorageItemPreference(mContext);
    434         StorageItemPreference files = new StorageItemPreference(mContext);
    435         PreferenceScreen screen = mock(PreferenceScreen.class);
    436         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
    437                 .thenReturn(audio);
    438         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
    439                 .thenReturn(image);
    440         when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    441         when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
    442                 .thenReturn(apps);
    443         when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
    444                 .thenReturn(system);
    445         when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
    446                 .thenReturn(files);
    447 
    448         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
    449         when(mVolume.isMountedReadable()).thenReturn(true);
    450 
    451         mController.displayPreference(screen);
    452         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
    453         mController.setVolume(mVolume);
    454 
    455         verify(screen).removePreference(files);
    456     }
    457 
    458 
    459     @Test
    460     public void displayPreference_updateFilePreferenceToShowAfterSettingVolume() {
    461         StorageItemPreference audio = new StorageItemPreference(mContext);
    462         StorageItemPreference image = new StorageItemPreference(mContext);
    463         StorageItemPreference games = new StorageItemPreference(mContext);
    464         StorageItemPreference apps = new StorageItemPreference(mContext);
    465         StorageItemPreference system = new StorageItemPreference(mContext);
    466         StorageItemPreference files = new StorageItemPreference(mContext);
    467         PreferenceScreen screen = mock(PreferenceScreen.class);
    468         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
    469                 .thenReturn(audio);
    470         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
    471                 .thenReturn(image);
    472         when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
    473         when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
    474                 .thenReturn(apps);
    475         when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
    476                 .thenReturn(system);
    477         when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
    478                 .thenReturn(files);
    479 
    480         // This will hide it initially.
    481         mController.displayPreference(screen);
    482 
    483         when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
    484         when(mVolume.isMountedReadable()).thenReturn(true);
    485 
    486         // And we bring it back.
    487         mController.setVolume(mVolume);
    488 
    489         verify(screen).addPreference(files);
    490     }
    491 }
    492