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

Commit d725f70d authored by Michael Bestas's avatar Michael Bestas Committed by Michael Bestas
Browse files

Settings: Forward port pattern visibility settings (2/2)

Change-Id: Ic627953c5df854c442671a98b5da539b994da18b
parent c384940f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -27,6 +27,14 @@
        android:key="visiblepattern"
        android:title="@string/lockpattern_settings_enable_visible_pattern_title" />

    <SwitchPreference
        android:key="visible_error_pattern"
        android:title="@string/lockpattern_settings_enable_error_path_title"/>

    <SwitchPreference
        android:key="visibledots"
        android:title="@string/lockpattern_settings_enable_dots_title"/>

    <!-- available in pin/pattern/password -->
    <com.android.settings.display.TimeoutListPreference
        android:key="lock_after_timeout"
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.security.screenlock;

import android.app.admin.DevicePolicyManager;
import android.content.Context;

import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;

public abstract class AbstractPatternSwitchPreferenceController
        extends AbstractPreferenceController
        implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {

    private final String mKey;
    private final int mUserId;
    private final LockPatternUtils mLockPatternUtils;

    public AbstractPatternSwitchPreferenceController(Context context, String key,
            int userId, LockPatternUtils lockPatternUtils) {
        super(context);
        mKey = key;
        mUserId = userId;
        mLockPatternUtils = lockPatternUtils;
    }

    @Override
    public boolean isAvailable() {
        return isPatternLock();
    }

    @Override
    public String getPreferenceKey() {
        return mKey;
    }

    @Override
    public void updateState(Preference preference) {
        ((TwoStatePreference) preference).setChecked(isEnabled(mLockPatternUtils, mUserId));
    }

    private boolean isPatternLock() {
        return mLockPatternUtils.isSecure(mUserId)
                && mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId)
                == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        setEnabled(mLockPatternUtils, mUserId, (Boolean) newValue);
        return true;
    }

    protected abstract boolean isEnabled(LockPatternUtils utils, int userId);
    protected abstract void setEnabled(LockPatternUtils utils, int userId, boolean enabled);
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.security.screenlock;

import android.content.Context;

import com.android.internal.widget.LockPatternUtils;

public class PatternDotsVisiblePreferenceController
        extends AbstractPatternSwitchPreferenceController {
    private static final String PREF_KEY = "visibledots";

    public PatternDotsVisiblePreferenceController(Context context, int userId,
            LockPatternUtils lockPatternUtils) {
        super(context, PREF_KEY, userId, lockPatternUtils);
    }

    @Override
    protected boolean isEnabled(LockPatternUtils utils, int userId) {
        return utils.isVisibleDotsEnabled(userId);
    }

    @Override
    protected void setEnabled(LockPatternUtils utils, int userId, boolean enabled) {
        utils.setVisibleDotsEnabled(enabled, userId);
    }
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.security.screenlock;

import android.content.Context;

import com.android.internal.widget.LockPatternUtils;

public class PatternErrorVisiblePreferenceController
        extends AbstractPatternSwitchPreferenceController {
    private static final String PREF_KEY = "visible_error_pattern";

    public PatternErrorVisiblePreferenceController(Context context, int userId,
            LockPatternUtils lockPatternUtils) {
        super(context, PREF_KEY, userId, lockPatternUtils);
    }

    @Override
    protected boolean isEnabled(LockPatternUtils utils, int userId) {
        return utils.isShowErrorPath(userId);
    }

    @Override
    protected void setEnabled(LockPatternUtils utils, int userId, boolean enabled) {
        utils.setShowErrorPath(enabled, userId);
    }
}
+6 −37
Original line number Diff line number Diff line
@@ -16,56 +16,25 @@

package com.android.settings.security.screenlock;

import android.app.admin.DevicePolicyManager;
import android.content.Context;

import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;

public class PatternVisiblePreferenceController extends AbstractPreferenceController
        implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {

public class PatternVisiblePreferenceController extends AbstractPatternSwitchPreferenceController {
    private static final String PREF_KEY = "visiblepattern";

    private final int mUserId;
    private final LockPatternUtils mLockPatternUtils;

    public PatternVisiblePreferenceController(Context context, int userId,
            LockPatternUtils lockPatternUtils) {
        super(context);
        mUserId = userId;
        mLockPatternUtils = lockPatternUtils;
    }

    @Override
    public boolean isAvailable() {
        return isPatternLock();
        super(context, PREF_KEY, userId, lockPatternUtils);
    }

    @Override
    public String getPreferenceKey() {
        return PREF_KEY;
    }

    @Override
    public void updateState(Preference preference) {
        ((TwoStatePreference) preference).setChecked(
                mLockPatternUtils.isVisiblePatternEnabled(mUserId));
    }

    private boolean isPatternLock() {
        return mLockPatternUtils.isSecure(mUserId)
                && mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId)
                == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
    protected boolean isEnabled(LockPatternUtils utils, int userId) {
        return utils.isVisiblePatternEnabled(userId);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        mLockPatternUtils.setVisiblePatternEnabled((Boolean) newValue, mUserId);
        return true;
    protected void setEnabled(LockPatternUtils utils, int userId, boolean enabled) {
        utils.setVisiblePatternEnabled(enabled, userId);
    }
}
Loading