Search in sources :

Example 1 with OnPreferenceClickListener

use of androidx.preference.Preference.OnPreferenceClickListener 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 2 with OnPreferenceClickListener

use of androidx.preference.Preference.OnPreferenceClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModeScheduleRuleSettings method onCreateInternal.

@Override
protected void onCreateInternal() {
    final PreferenceScreen root = getPreferenceScreen();
    mDays = root.findPreference(KEY_DAYS);
    mDays.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showDaysDialog();
            return true;
        }
    });
    final FragmentManager mgr = getFragmentManager();
    mStart = new TimePickerPreference(getPrefContext(), mgr);
    mStart.setKey(KEY_START_TIME);
    mStart.setTitle(R.string.zen_mode_start_time);
    mStart.setCallback(new TimePickerPreference.Callback() {

        @Override
        public boolean onSetTime(final int hour, final int minute) {
            if (mDisableListeners)
                return true;
            if (!ZenModeConfig.isValidHour(hour))
                return false;
            if (!ZenModeConfig.isValidMinute(minute))
                return false;
            if (hour == mSchedule.startHour && minute == mSchedule.startMinute) {
                return true;
            }
            if (DEBUG)
                Log.d(TAG, "onPrefChange start h=" + hour + " m=" + minute);
            mSchedule.startHour = hour;
            mSchedule.startMinute = minute;
            updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
            return true;
        }
    });
    root.addPreference(mStart);
    mStart.setDependency(mDays.getKey());
    mEnd = new TimePickerPreference(getPrefContext(), mgr);
    mEnd.setKey(KEY_END_TIME);
    mEnd.setTitle(R.string.zen_mode_end_time);
    mEnd.setCallback(new TimePickerPreference.Callback() {

        @Override
        public boolean onSetTime(final int hour, final int minute) {
            if (mDisableListeners)
                return true;
            if (!ZenModeConfig.isValidHour(hour))
                return false;
            if (!ZenModeConfig.isValidMinute(minute))
                return false;
            if (hour == mSchedule.endHour && minute == mSchedule.endMinute) {
                return true;
            }
            if (DEBUG)
                Log.d(TAG, "onPrefChange end h=" + hour + " m=" + minute);
            mSchedule.endHour = hour;
            mSchedule.endMinute = minute;
            updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
            return true;
        }
    });
    root.addPreference(mEnd);
    mEnd.setDependency(mDays.getKey());
    mExitAtAlarm = (SwitchPreference) root.findPreference(KEY_EXIT_AT_ALARM);
    mExitAtAlarm.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            mSchedule.exitAtAlarm = (Boolean) o;
            updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
            return true;
        }
    });
}
Also used : OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) FragmentManager(androidx.fragment.app.FragmentManager) PreferenceScreen(androidx.preference.PreferenceScreen) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference)

Example 3 with OnPreferenceClickListener

use of androidx.preference.Preference.OnPreferenceClickListener in project android_packages_apps_Settings by omnirom.

the class InteractAcrossProfilesSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    final ArrayList<Pair<ApplicationInfo, UserHandle>> crossProfileApps = collectConfigurableApps(mPackageManager, mUserManager, mCrossProfileApps);
    final Context prefContext = getPrefContext();
    for (final Pair<ApplicationInfo, UserHandle> appData : crossProfileApps) {
        final ApplicationInfo appInfo = appData.first;
        final UserHandle user = appData.second;
        final String packageName = appInfo.packageName;
        final CharSequence label = appInfo.loadLabel(mPackageManager);
        final Preference pref = new AppPreference(prefContext);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(appInfo, user.getIdentifier()));
        pref.setTitle(mPackageManager.getUserBadgedLabel(label, user));
        pref.setSummary(InteractAcrossProfilesDetails.getPreferenceSummary(prefContext, packageName));
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppInfoBase.startAppInfoFragment(InteractAcrossProfilesDetails.class, R.string.interact_across_profiles_title, packageName, appInfo.uid, InteractAcrossProfilesSettings.this, /* source */
                -1, /* request */
                getMetricsCategory());
                return true;
            }
        });
        screen.addPreference(pref);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Pair(android.util.Pair)

Example 4 with OnPreferenceClickListener

use of androidx.preference.Preference.OnPreferenceClickListener in project android_packages_apps_Settings by omnirom.

the class PictureInPictureSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    // Clear the prefs
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    // Fetch the set of applications for each profile which have at least one activity that
    // declare that they support picture-in-picture
    final ArrayList<Pair<ApplicationInfo, Integer>> pipApps = collectPipApps(UserHandle.myUserId());
    Collections.sort(pipApps, new AppComparator(mPackageManager));
    // Rebuild the list of prefs
    final Context prefContext = getPrefContext();
    for (final Pair<ApplicationInfo, Integer> appData : pipApps) {
        final ApplicationInfo appInfo = appData.first;
        final int userId = appData.second;
        final UserHandle user = UserHandle.of(userId);
        final String packageName = appInfo.packageName;
        final CharSequence label = appInfo.loadLabel(mPackageManager);
        final Preference pref = new AppPreference(prefContext);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(appInfo, userId));
        pref.setTitle(mPackageManager.getUserBadgedLabel(label, user));
        pref.setSummary(PictureInPictureDetails.getPreferenceSummary(prefContext, appInfo.uid, packageName));
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppInfoBase.startAppInfoFragment(PictureInPictureDetails.class, R.string.picture_in_picture_app_detail_title, packageName, appInfo.uid, PictureInPictureSettings.this, -1, getMetricsCategory());
                return true;
            }
        });
        screen.addPreference(pref);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Pair(android.util.Pair)

Example 5 with OnPreferenceClickListener

use of androidx.preference.Preference.OnPreferenceClickListener in project android_packages_apps_Settings by omnirom.

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)

Aggregations

Preference (androidx.preference.Preference)8 OnPreferenceClickListener (androidx.preference.Preference.OnPreferenceClickListener)8 PreferenceScreen (androidx.preference.PreferenceScreen)5 Context (android.content.Context)3 ApplicationInfo (android.content.pm.ApplicationInfo)3 UserHandle (android.os.UserHandle)3 Pair (android.util.Pair)3 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 FragmentManager (androidx.fragment.app.FragmentManager)2 PreferenceGroup (androidx.preference.PreferenceGroup)2 SwitchPreference (androidx.preference.SwitchPreference)2 AppPreference (com.android.settingslib.widget.AppPreference)2 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)1 RestrictedPreference (com.android.settingslib.RestrictedPreference)1 AppPreference (com.android.settingslib.widget.apppreference.AppPreference)1