Search in sources :

Example 16 with PreferenceGroup

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);
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) PackageManager(android.content.pm.PackageManager) PreferenceScreen(androidx.preference.PreferenceScreen) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) PreferenceGroup(androidx.preference.PreferenceGroup) Resources(android.content.res.Resources) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 17 with PreferenceGroup

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();
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) Test(org.junit.Test)

Example 18 with PreferenceGroup

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();
    }
}
Also used : PreferenceGroup(androidx.preference.PreferenceGroup) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference)

Example 19 with PreferenceGroup

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)));
}
Also used : PreferenceGroup(androidx.preference.PreferenceGroup) Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) List(java.util.List) PackageManager(android.content.pm.PackageManager) BasePreferenceController(com.android.settings.core.BasePreferenceController) ModuleInfo(android.content.pm.ModuleInfo) IOException(java.io.IOException) Comparator(java.util.Comparator) ArrayUtils(com.android.internal.util.ArrayUtils) PackageManager(android.content.pm.PackageManager) ModuleInfo(android.content.pm.ModuleInfo) PreferenceGroup(androidx.preference.PreferenceGroup)

Aggregations

PreferenceGroup (androidx.preference.PreferenceGroup)19 PreferenceScreen (androidx.preference.PreferenceScreen)11 Preference (androidx.preference.Preference)10 Context (android.content.Context)8 PackageManager (android.content.pm.PackageManager)5 Test (org.junit.Test)5 Resources (android.content.res.Resources)4 Intent (android.content.Intent)3 ResolveInfo (android.content.pm.ResolveInfo)3 PreferenceCategory (androidx.preference.PreferenceCategory)3 PreferenceManager (androidx.preference.PreferenceManager)3 ArrayList (java.util.ArrayList)3 ContentResolver (android.content.ContentResolver)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageInfo (android.content.pm.PackageInfo)2 AssetManager (android.content.res.AssetManager)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 ListPreference (androidx.preference.ListPreference)2 SwitchPreference (androidx.preference.SwitchPreference)2 RestrictedPreference (com.android.settingslib.RestrictedPreference)2