use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ModuleLicensesPreferenceControllerTest method displayPreference_includeOnlyModulesWithLicenseFile.
@Test
public void displayPreference_includeOnlyModulesWithLicenseFile() throws PackageManager.NameNotFoundException, IOException {
Context context = mock(Context.class);
ModuleLicensesPreferenceController controller = new ModuleLicensesPreferenceController(context, PREFERENCE_KEY);
PackageManager packageManager = mock(PackageManager.class);
when(context.getPackageManager()).thenReturn(packageManager);
PreferenceScreen screen = mock(PreferenceScreen.class);
PreferenceGroup group = spy(new MockPreferenceGroup(RuntimeEnvironment.application, null));
when(screen.findPreference(PREFERENCE_KEY)).thenReturn(group);
when(group.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(packageManager.getInstalledModules(0)).thenReturn(Arrays.asList(mModuleTwo, mModuleOne));
PackageInfo packageInfo = new PackageInfo();
ApplicationInfo applicationInfo = new ApplicationInfo();
packageInfo.applicationInfo = applicationInfo;
when(packageManager.getPackageInfo(MODULE_1_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
Resources resources = mock(Resources.class);
when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
AssetManager manager = mock(AssetManager.class);
when(resources.getAssets()).thenReturn(manager);
when(manager.list("")).thenReturn(new String[] { GZIPPED_LICENSE_FILE_NAME });
PackageInfo packageInfo2 = new PackageInfo();
ApplicationInfo applicationInfo2 = new ApplicationInfo();
packageInfo2.applicationInfo = applicationInfo2;
when(packageManager.getPackageInfo(MODULE_2_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo2);
Resources resources2 = mock(Resources.class);
when(packageManager.getResourcesForApplication(applicationInfo2)).thenReturn(resources2);
AssetManager manager2 = mock(AssetManager.class);
when(resources2.getAssets()).thenReturn(manager2);
when(manager2.list("")).thenReturn(new String[] {});
controller.displayPreference(screen);
assertThat(group.getPreferenceCount()).isEqualTo(1);
assertThat(group.getPreference(0).getTitle()).isEqualTo(MODULE_1_NAME);
}
use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class UserSettingsTest method updateUserList_cannotSwitchUser_shouldNotBeSelectableForGuest.
@Test
public void updateUserList_cannotSwitchUser_shouldNotBeSelectableForGuest() {
final RestrictedPreference addUser = spy(new RestrictedPreference(mContext));
final PreferenceGroup userListCategory = spy(new PreferenceCategory(mContext));
mUserCapabilities.mIsGuest = false;
mUserCapabilities.mCanAddGuest = true;
mUserCapabilities.mDisallowAddUser = false;
mUserCapabilities.mDisallowSwitchUser = false;
mUserCapabilities.mUserSwitcherEnabled = true;
mFragment.mUserListCategory = userListCategory;
mFragment.mAddUser = addUser;
when(mUserManager.canSwitchUsers()).thenReturn(false);
doReturn(mMockPreferenceManager).when(mFragment).getPreferenceManager();
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
doReturn(mMockPreferenceManager).when(userListCategory).getPreferenceManager();
mFragment.updateUserList();
final Preference guest = userListCategory.findPreference(KEY_USER_GUEST);
assertThat(guest.isSelectable()).isFalse();
}
use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SecondaryUserController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
if (mStoragePreference == null) {
mStoragePreference = new StorageItemPreference(screen.getContext());
PreferenceGroup group = screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
mStoragePreference.setTitle(mUser.name);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
if (mSize != SIZE_NOT_SET) {
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
}
group.setVisible(true);
group.addPreference(mStoragePreference);
maybeSetIcon();
}
}
use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ModuleLicensesPreferenceController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
PackageManager packageManager = mContext.getPackageManager();
List<ModuleInfo> modules = packageManager.getInstalledModules(0);
PreferenceGroup group = screen.findPreference(getPreferenceKey());
modules.stream().sorted(Comparator.comparing(o -> o.getName().toString())).filter(new Predicate(mContext)).forEach(module -> group.addPreference(new ModuleLicensePreference(group.getContext(), module)));
}
Aggregations