Merge "Don't shows Files when storage is adopted." into oc-dev
This commit is contained in:
@@ -214,6 +214,15 @@ public class StorageItemPreferenceController extends PreferenceController {
|
||||
mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY);
|
||||
mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_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) {
|
||||
|
@@ -84,7 +84,7 @@ public class StorageItemPreferenceControllerTest {
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
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
|
||||
// Settings fragment lifecycle for test purposes.
|
||||
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
|
||||
@@ -305,4 +305,90 @@ public class StorageItemPreferenceControllerTest {
|
||||
verify(system, 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user