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

Commit 41d99408 authored by Oleksandr Peletskyi's avatar Oleksandr Peletskyi
Browse files

Block "Screen lock" menu if password is managed.

"Screen lock" menu item is completely disabled in case, if
PASSWORD_QUALITY_MANAGED is set.

BUG: 25549437
Change-Id: I1958157946d29c013465e995af2226e061d5c726
parent 664f94e0
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -17,15 +17,16 @@
package com.android.settings;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.View;

import com.android.settingslib.RestrictedPreference;

/**
 * A preference with a Gear on the side
 */
public class GearPreference extends Preference implements View.OnClickListener {
public class GearPreference extends RestrictedPreference implements View.OnClickListener {

    private OnGearClickListener mOnGearClickListener;

@@ -42,7 +43,9 @@ public class GearPreference extends Preference implements View.OnClickListener {
    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
        holder.findViewById(R.id.settings_button).setOnClickListener(this);
        final View gear = holder.findViewById(R.id.settings_button);
        gear.setOnClickListener(this);
        gear.setEnabled(true);  // Make gear available even if the preference itself is disabled.
    }

    @Override
+38 −30
Original line number Diff line number Diff line
@@ -228,6 +228,15 @@ public class SecuritySettings extends SettingsPreferenceFragment
        final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, MY_USER_ID);
        addPreferencesFromResource(resid);

        final EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet(
                getActivity(), MY_USER_ID);
        if (admin != null && mDPM.getPasswordQuality(admin.component) ==
                DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
            final GearPreference unlockSetOrChangePref =
                    (GearPreference) getPreferenceScreen().findPreference(KEY_UNLOCK_SET_OR_CHANGE);
            unlockSetOrChangePref.setDisabledByAdmin(admin);
        }

        mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
        if (mProfileChallengeUserId != UserHandle.USER_NULL
                && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
@@ -742,59 +751,58 @@ public class SecuritySettings extends SettingsPreferenceFragment
        @Override
        public List<SearchIndexableResource> getXmlResourcesToIndex(
                Context context, boolean enabled) {
            final List<SearchIndexableResource> index = new ArrayList<SearchIndexableResource>();

            List<SearchIndexableResource> result = new ArrayList<SearchIndexableResource>();
            final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
            final EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet(
                    context, MY_USER_ID);
            final DevicePolicyManager dpm = (DevicePolicyManager)
                    context.getSystemService(Context.DEVICE_POLICY_SERVICE);
            final UserManager um = UserManager.get(context);

            LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
            if (admin == null || dpm.getPasswordQuality(admin.component) !=
                    DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
                // Add options for lock/unlock screen
            int resId = getResIdForLockUnlockScreen(context, lockPatternUtils, MY_USER_ID);

            SearchIndexableResource sir = new SearchIndexableResource(context);
            sir.xmlResId = resId;
            result.add(sir);
                final int resId = getResIdForLockUnlockScreen(context, lockPatternUtils,
                        MY_USER_ID);
                index.add(getSearchResource(context, resId));
            }

            final UserManager um = UserManager.get(context);
            final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
            if (profileUserId != UserHandle.USER_NULL
                    && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) {
                sir = new SearchIndexableResource(context);
                sir.xmlResId = getResIdForLockUnlockScreen(
                        context, lockPatternUtils, profileUserId);
                result.add(sir);
                index.add(getSearchResource(context, getResIdForLockUnlockScreen(context,
                        lockPatternUtils, profileUserId)));
            }

            if (um.isAdminUser()) {
                DevicePolicyManager dpm = (DevicePolicyManager)
                        context.getSystemService(Context.DEVICE_POLICY_SERVICE);

                switch (dpm.getStorageEncryptionStatus()) {
                    case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
                        // The device is currently encrypted.
                        resId = R.xml.security_settings_encrypted;
                        index.add(getSearchResource(context, R.xml.security_settings_encrypted));
                        break;
                    case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
                        // This device supports encryption but isn't encrypted.
                        resId = R.xml.security_settings_unencrypted;
                        index.add(getSearchResource(context, R.xml.security_settings_unencrypted));
                        break;
                }

                sir = new SearchIndexableResource(context);
                sir.xmlResId = resId;
                result.add(sir);
            }

            sir = new SearchIndexableResource(context);
            sir.xmlResId = SecuritySubSettings.getResIdForLockUnlockSubScreen(context,
                    lockPatternUtils);
            final SearchIndexableResource sir = getSearchResource(context,
                    SecuritySubSettings.getResIdForLockUnlockSubScreen(context, lockPatternUtils));
            sir.className = SecuritySubSettings.class.getName();
            result.add(sir);
            index.add(sir);

            // Append the rest of the settings
            sir = new SearchIndexableResource(context);
            sir.xmlResId = R.xml.security_settings_misc;
            result.add(sir);
            index.add(getSearchResource(context, R.xml.security_settings_misc));

            return result;
            return index;
        }

        private SearchIndexableResource getSearchResource(Context context, int xmlResId) {
            final SearchIndexableResource sir = new SearchIndexableResource(context);
            sir.xmlResId = xmlResId;
            return sir;
        }

        @Override