Search in sources :

Example 1 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class UserSettingsTest method updateUserList_cannotSwitchUser_shouldDisableAddUser.

@Test
public void updateUserList_cannotSwitchUser_shouldDisableAddUser() {
    Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
    final RestrictedPreference addUser = spy(new RestrictedPreference(mContext));
    final PreferenceGroup userListCategory = spy(new PreferenceCategory(mContext));
    mUserCapabilities.mCanAddUser = true;
    mUserCapabilities.mDisallowAddUser = false;
    mUserCapabilities.mUserSwitcherEnabled = true;
    mFragment.mUserListCategory = userListCategory;
    mFragment.mAddUser = addUser;
    when(mUserManager.canSwitchUsers()).thenReturn(false);
    when(mUserManager.canAddMoreUsers()).thenReturn(true);
    doReturn(mMockPreferenceManager).when(mFragment).getPreferenceManager();
    doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
    doReturn(mMockPreferenceManager).when(userListCategory).getPreferenceManager();
    mFragment.updateUserList();
    assertThat(addUser.isEnabled()).isFalse();
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceGroup(androidx.preference.PreferenceGroup) Test(org.junit.Test)

Example 2 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ApnSettings method fillList.

private void fillList() {
    final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId() : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    final Uri simApnUri = Uri.withAppendedPath(Telephony.Carriers.SIM_APN_URI, String.valueOf(subId));
    StringBuilder where = new StringBuilder("NOT (type='ia' AND (apn=\"\" OR apn IS NULL)) AND " + "user_visible!=0");
    if (mHideImsApn) {
        where.append(" AND NOT (type='ims')");
    }
    Cursor cursor = getContentResolver().query(simApnUri, CARRIERS_PROJECTION, where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER);
    if (cursor != null) {
        PreferenceGroup apnPrefList = (PreferenceGroup) findPreference("apn_list");
        apnPrefList.removeAll();
        ArrayList<ApnPreference> apnList = new ArrayList<ApnPreference>();
        ArrayList<ApnPreference> mmsApnList = new ArrayList<ApnPreference>();
        mSelectedKey = getSelectedApnKey();
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String name = cursor.getString(NAME_INDEX);
            String apn = cursor.getString(APN_INDEX);
            String key = cursor.getString(ID_INDEX);
            String type = cursor.getString(TYPES_INDEX);
            int edited = cursor.getInt(EDITED_INDEX);
            mMvnoType = cursor.getString(MVNO_TYPE_INDEX);
            mMvnoMatchData = cursor.getString(MVNO_MATCH_DATA_INDEX);
            ApnPreference pref = new ApnPreference(getPrefContext());
            pref.setKey(key);
            pref.setTitle(name);
            pref.setPersistent(false);
            pref.setOnPreferenceChangeListener(this);
            pref.setSubId(subId);
            if (mHidePresetApnDetails && edited == Telephony.Carriers.UNEDITED) {
                pref.setHideDetails();
            } else {
                pref.setSummary(apn);
            }
            boolean selectable = ((type == null) || !type.equals("mms"));
            pref.setSelectable(selectable);
            if (selectable) {
                if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
                    pref.setChecked();
                }
                apnList.add(pref);
            } else {
                mmsApnList.add(pref);
            }
            cursor.moveToNext();
        }
        cursor.close();
        for (Preference preference : apnList) {
            apnPrefList.addPreference(preference);
        }
        for (Preference preference : mmsApnList) {
            apnPrefList.addPreference(preference);
        }
    }
}
Also used : Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) PreferenceGroup(androidx.preference.PreferenceGroup) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 3 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountTypePreferenceLoader method updatePreferenceIntents.

/**
 * Recursively filters through the preference list provided by GoogleLoginService.
 *
 * This method removes all the invalid intent from the list, adds account name as extra into the
 * intent, and hack the location settings to start it as a fragment.
 */
public void updatePreferenceIntents(PreferenceGroup prefs, final String acccountType, Account account) {
    final PackageManager pm = mFragment.getActivity().getPackageManager();
    for (int i = 0; i < prefs.getPreferenceCount(); ) {
        Preference pref = prefs.getPreference(i);
        if (pref instanceof PreferenceGroup) {
            updatePreferenceIntents((PreferenceGroup) pref, acccountType, account);
        }
        Intent intent = pref.getIntent();
        if (intent != null) {
            // preference click event here directly.
            if (TextUtils.equals(intent.getAction(), android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
                // The OnPreferenceClickListener overrides the click event completely. No intent
                // will get fired.
                pref.setOnPreferenceClickListener(new FragmentStarter(LocationSettings.class.getName(), R.string.location_settings_title));
            } else {
                ResolveInfo ri = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY, mUserHandle.getIdentifier());
                if (ri == null) {
                    prefs.removePreference(pref);
                    continue;
                }
                intent.putExtra(ACCOUNT_KEY, account);
                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent prefIntent = preference.getIntent();
                        /*
                                 * Check the intent to see if it resolves to a exported=false
                                 * activity that doesn't share a uid with the authenticator.
                                 *
                                 * Otherwise the intent is considered unsafe in that it will be
                                 * exploiting the fact that settings has system privileges.
                                 */
                        if (isSafeIntent(pm, prefIntent, acccountType)) {
                            mFragment.getActivity().startActivityAsUser(prefIntent, mUserHandle);
                        } else {
                            Log.e(TAG, "Refusing to launch authenticator intent because" + "it exploits Settings permissions: " + prefIntent);
                        }
                        return true;
                    }
                });
            }
        }
        i++;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) PackageManager(android.content.pm.PackageManager) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) Intent(android.content.Intent)

Example 4 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class About method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.about_rom);
    PreferenceScreen prefSet = getPreferenceScreen();
    ContentResolver resolver = getContentResolver();
    mSiteUrl = findPreference("rr_website");
    mSourceUrl = findPreference("rr_source");
    mFacebookUrl = findPreference("rr_facebook");
    mDonateUrl = findPreference("rr_donate");
    mTelegramUrl = findPreference("rr_tg");
    PreferenceGroup devsGroup = (PreferenceGroup) findPreference("devs");
    ArrayList<Preference> devs = new ArrayList<Preference>();
    for (int i = 0; i < devsGroup.getPreferenceCount(); i++) {
        devs.add(devsGroup.getPreference(i));
    }
    devsGroup.removeAll();
    devsGroup.setOrderingAsAdded(false);
    Collections.shuffle(devs);
    for (int i = 0; i < devs.size(); i++) {
        Preference p = devs.get(i);
        p.setOrder(i);
        devsGroup.addPreference(p);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) SwitchPreference(androidx.preference.SwitchPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) ArrayList(java.util.ArrayList) PreferenceGroup(androidx.preference.PreferenceGroup) ContentResolver(android.content.ContentResolver)

Example 5 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CreateShortcutPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    if (!(preference instanceof PreferenceGroup)) {
        return;
    }
    final PreferenceGroup group = (PreferenceGroup) preference;
    group.removeAll();
    final List<ResolveInfo> shortcuts = queryShortcuts();
    final Context uiContext = preference.getContext();
    if (shortcuts.isEmpty()) {
        return;
    }
    PreferenceCategory category = new PreferenceCategory(uiContext);
    group.addPreference(category);
    int bucket = 0;
    for (ResolveInfo info : shortcuts) {
        // Priority is not consecutive (aka, jumped), add a divider between prefs.
        final int currentBucket = info.priority / 10;
        boolean needDivider = currentBucket != bucket;
        bucket = currentBucket;
        if (needDivider) {
            // add a new Category
            category = new PreferenceCategory(uiContext);
            group.addPreference(category);
        }
        final Preference pref = new Preference(uiContext);
        pref.setTitle(info.loadLabel(mPackageManager));
        pref.setKey(info.activityInfo.getComponentName().flattenToString());
        pref.setOnPreferenceClickListener(clickTarget -> {
            if (mHost == null) {
                return false;
            }
            final Intent shortcutIntent = createResultIntent(buildShortcutIntent(info), info, clickTarget.getTitle());
            mHost.setResult(Activity.RESULT_OK, shortcutIntent);
            logCreateShortcut(info);
            mHost.finish();
            return true;
        });
        category.addPreference(pref);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Context(android.content.Context) PreferenceCategory(androidx.preference.PreferenceCategory) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) Intent(android.content.Intent)

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