Don't overly hide the Files preference.

This occurred this because the files preference was initialized during
displayPreference(), but the volume used to initialize it was not being
set until after the displayPreference() call. In this case, the files
preference would hide itself and never come back.

This fixes this by double-checking the Files visibility status whenever
we set the volume.

Change-Id: I0b1a7a9566e9caece39ec58706fbca034ef4c1c2
Fixes: 37790776
Test: Settings robotest
This commit is contained in:
Daniel Nishi
2017-05-01 11:30:14 -07:00
parent b2d85af91e
commit f7fa542eb6
2 changed files with 84 additions and 8 deletions

View File

@@ -391,4 +391,69 @@ public class StorageItemPreferenceControllerTest {
verify(screen).removePreference(files);
}
@Test
public void displayPreference_updateFilePreferenceToHideAfterSettingVolume() {
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(any(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(true);
mController.displayPreference(screen);
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
mController.setVolume(mVolume);
verify(screen).removePreference(files);
}
@Test
public void displayPreference_updateFilePreferenceToShowAfterSettingVolume() {
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);
// This will hide it initially.
mController.displayPreference(screen);
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(true);
// And we bring it back.
mController.setVolume(mVolume);
verify(screen).addPreference(files);
}
}