Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea088af5 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Made changes to padlock support for preferences.

- Currently, if a preference is disabled by admin, we add a padlock and disable
the preference. And now if the preference is enabled in some other place, the
padlock is not removed. Updated RestrictedPreference to fix this
behavior.
- Made RestrictedPreferenceHelper and
RestrictedPreferenceHelper.onAttachedToHierarchy public so that preferences in
Settings can use these.
- Put a check for null to avoid NullPointerException.
- Removed a redundant statement.

Change-Id: Ie88a761dc38c58a680c62b3703d2081c67462079
parent 0c575969
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -79,6 +79,15 @@ public class RestrictedPreference extends Preference {
        mHelper.checkRestrictionAndSetDisabled(userRestriction, userId);
    }

    @Override
    public void setEnabled(boolean enabled) {
        if (enabled && isDisabledByAdmin()) {
            mHelper.setDisabledByAdmin(null);
            return;
        }
        super.setEnabled(enabled);
    }

    public void setDisabledByAdmin(EnforcedAdmin admin) {
        if (mHelper.setDisabledByAdmin(admin)) {
            notifyChanged();
+15 −15
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class RestrictedPreferenceHelper {
    private EnforcedAdmin mEnforcedAdmin;
    private String mAttrUserRestriction = null;

    RestrictedPreferenceHelper(Context context, Preference preference,
    public RestrictedPreferenceHelper(Context context, Preference preference,
            AttributeSet attrs) {
        mContext = context;
        mPreference = preference;
@@ -54,8 +54,7 @@ public class RestrictedPreferenceHelper {
        mRestrictedPadlockPadding = mContext.getResources().getDimensionPixelSize(
                R.dimen.restricted_lock_icon_padding);

        mAttrUserRestriction = attrs.getAttributeValue(
                R.styleable.RestrictedPreference_userRestriction);
        if (attrs != null) {
            final TypedArray attributes = context.obtainStyledAttributes(attrs,
                    R.styleable.RestrictedPreference);
            final TypedValue userRestriction =
@@ -70,6 +69,7 @@ public class RestrictedPreferenceHelper {
            }
            mAttrUserRestriction = data == null ? null : data.toString();
        }
    }

    /**
     * Modify PreferenceViewHolder to add padlock if restriction is disabled.
@@ -100,7 +100,7 @@ public class RestrictedPreferenceHelper {
    /**
     * Disable / enable if we have been passed the restriction in the xml.
     */
    protected void onAttachedToHierarchy() {
    public void onAttachedToHierarchy() {
        if (mAttrUserRestriction != null) {
            checkRestrictionAndSetDisabled(mAttrUserRestriction, UserHandle.myUserId());
        }
+9 −0
Original line number Diff line number Diff line
@@ -79,6 +79,15 @@ public class RestrictedSwitchPreference extends SwitchPreference {
        mHelper.checkRestrictionAndSetDisabled(userRestriction, userId);
    }

    @Override
    public void setEnabled(boolean enabled) {
        if (enabled && isDisabledByAdmin()) {
            mHelper.setDisabledByAdmin(null);
            return;
        }
        super.setEnabled(enabled);
    }

    public void setDisabledByAdmin(EnforcedAdmin admin) {
        if (mHelper.setDisabledByAdmin(admin)) {
            notifyChanged();