Merge "Don't shows Files when storage is adopted." into oc-dev

This commit is contained in:
Daniel Nishi
2017-04-25 22:30:29 +00:00
committed by Android (Google) Code Review
2 changed files with 96 additions and 1 deletions

View File

@@ -214,6 +214,15 @@ public class StorageItemPreferenceController extends PreferenceController {
mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY); mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY);
mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_KEY); mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_KEY);
mFilePreference = (StorageItemPreference) screen.findPreference(FILES_KEY); mFilePreference = (StorageItemPreference) screen.findPreference(FILES_KEY);
final VolumeInfo sharedVolume = mSvp.findEmulatedForPrivate(mVolume);
// If we don't have a shared volume for our internal storage (or the shared volume isn't
// mounted as readable for whatever reason), we should hide the File preference.
final boolean hideFilePreference =
(sharedVolume == null) || !sharedVolume.isMountedReadable();
if (hideFilePreference) {
screen.removePreference(mFilePreference);
}
} }
public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) { public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {

View File

@@ -84,7 +84,7 @@ public class StorageItemPreferenceControllerTest {
FakeFeatureFactory.setupForTest(mContext); FakeFeatureFactory.setupForTest(mContext);
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider(); mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
mVolume = new VolumeInfo("id", 0, null, "id"); mVolume = spy(new VolumeInfo("id", 0, null, "id"));
// Note: null is passed as the Lifecycle because we are handling it outside of the normal // Note: null is passed as the Lifecycle because we are handling it outside of the normal
// Settings fragment lifecycle for test purposes. // Settings fragment lifecycle for test purposes.
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp); mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
@@ -305,4 +305,90 @@ public class StorageItemPreferenceControllerTest {
verify(system, times(2)).setIcon(any(Drawable.class)); verify(system, times(2)).setIcon(any(Drawable.class));
verify(files, times(2)).setIcon(any(Drawable.class)); verify(files, times(2)).setIcon(any(Drawable.class));
} }
@Test
public void displayPreference_dontHideFilePreferenceWhenEmulatedInternalStorageUsed() {
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);
verify(screen, times(0)).removePreference(files);
}
@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(any(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(false);
mController.displayPreference(screen);
verify(screen).removePreference(files);
}
@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(any(VolumeInfo.class))).thenReturn(null);
mController.displayPreference(screen);
verify(screen).removePreference(files);
}
} }