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

Commit c0fdfafc authored by baked's avatar baked
Browse files

Add double tap sleep feature to secure lockscreens.



In its current state double tap works on the status bar on unsecure
lockscreens this adds the feature to pin, password, and pattern
lockscreens.

 - pin and password: double tap the text entry view.
 - pattern: double tap anywhere on the pattern view.

Patch Set 3:
 - add to slide lockscreen(glowpad): double tap glow pad to sleep
 - update commit message

Change-Id: I70eeae4acaa61b44feab661082bcfdbac7b9dfc3
Signed-off-by: default avatarbaked <travp624@gmail.com>
parent fc01f930
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -20,12 +20,15 @@ import android.content.Context;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.CountDownTimer;
import android.os.CountDownTimer;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.SystemClock;
import android.provider.Settings;
import android.provider.Settings;
import android.text.Editable;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.HapticFeedbackConstants;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.View;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.EditorInfo;
@@ -49,6 +52,8 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
    protected boolean mEnableHaptics;
    protected boolean mEnableHaptics;
    private boolean mQuickUnlock;
    private boolean mQuickUnlock;


    private GestureDetector mDoubleTapGesture;

    // To avoid accidental lockout due to events while the device in in the pocket, ignore
    // To avoid accidental lockout due to events while the device in in the pocket, ignore
    // any passwords with length less than or equal to this length.
    // any passwords with length less than or equal to this length.
    protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3;
    protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3;
@@ -103,9 +108,30 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
    protected void onFinishInflate() {
    protected void onFinishInflate() {
        mLockPatternUtils = new LockPatternUtils(mContext);
        mLockPatternUtils = new LockPatternUtils(mContext);


        mDoubleTapGesture = new GestureDetector(mContext,
                new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                if (pm != null) pm.goToSleep(e.getEventTime());
                return true;
            }
        });

        mPasswordEntry = (TextView) findViewById(getPasswordTextViewId());
        mPasswordEntry = (TextView) findViewById(getPasswordTextViewId());
        mPasswordEntry.setOnEditorActionListener(this);
        mPasswordEntry.setOnEditorActionListener(this);
        mPasswordEntry.addTextChangedListener(this);
        mPasswordEntry.addTextChangedListener(this);

        if (Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.DOUBLE_TAP_SLEEP_GESTURE, 0) == 1) {
            mPasswordEntry.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return mDoubleTapGesture.onTouchEvent(event);
                }
            });
        }

        mQuickUnlock = (Settings.System.getInt(mContext.getContentResolver(),
        mQuickUnlock = (Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.LOCKSCREEN_QUICK_UNLOCK_CONTROL, 0) == 1);
                Settings.System.LOCKSCREEN_QUICK_UNLOCK_CONTROL, 0) == 1);


+25 −0
Original line number Original line Diff line number Diff line
@@ -25,11 +25,14 @@ import android.content.Context;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.CountDownTimer;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.widget.Button;
import android.widget.Button;
@@ -88,6 +91,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
    private View mEcaView;
    private View mEcaView;
    private Drawable mBouncerFrame;
    private Drawable mBouncerFrame;


    private GestureDetector mDoubleTapGesture;

    enum FooterMode {
    enum FooterMode {
        Normal,
        Normal,
        ForgotLockPattern,
        ForgotLockPattern,
@@ -116,6 +121,16 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        mLockPatternUtils = mLockPatternUtils == null
        mLockPatternUtils = mLockPatternUtils == null
                ? new LockPatternUtils(mContext) : mLockPatternUtils;
                ? new LockPatternUtils(mContext) : mLockPatternUtils;


        mDoubleTapGesture = new GestureDetector(mContext,
                new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                if (pm != null) pm.goToSleep(e.getEventTime());
                return true;
            }
        });

        mLockPatternView = (LockPatternView) findViewById(R.id.lockPatternView);
        mLockPatternView = (LockPatternView) findViewById(R.id.lockPatternView);
        mLockPatternView.setSaveEnabled(false);
        mLockPatternView.setSaveEnabled(false);
        mLockPatternView.setFocusable(false);
        mLockPatternView.setFocusable(false);
@@ -133,6 +148,16 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit


        mLockPatternView.setLockPatternSize(mLockPatternUtils.getLockPatternSize());
        mLockPatternView.setLockPatternSize(mLockPatternUtils.getLockPatternSize());


        if (Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.DOUBLE_TAP_SLEEP_GESTURE, 0) == 1) {
            mLockPatternView.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return mDoubleTapGesture.onTouchEvent(event);
                }
            });
        }

        mForgotPatternButton = (Button) findViewById(R.id.forgot_password_button);
        mForgotPatternButton = (Button) findViewById(R.id.forgot_password_button);
        // note: some configurations don't have an emergency call area
        // note: some configurations don't have an emergency call area
        if (mForgotPatternButton != null) {
        if (mForgotPatternButton != null) {
+23 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,8 @@ import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.util.Slog;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout;


@@ -77,6 +79,7 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
    private String[] mStoredTargets;
    private String[] mStoredTargets;
    private int mTargetOffset;
    private int mTargetOffset;
    private boolean mIsScreenLarge;
    private boolean mIsScreenLarge;
    private GestureDetector mDoubleTapGesture;


    OnTriggerListener mOnTriggerListener = new OnTriggerListener() {
    OnTriggerListener mOnTriggerListener = new OnTriggerListener() {


@@ -206,6 +209,26 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
        mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this);
        mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this);
        View bouncerFrameView = findViewById(R.id.keyguard_selector_view_frame);
        View bouncerFrameView = findViewById(R.id.keyguard_selector_view_frame);
        mBouncerFrame = bouncerFrameView.getBackground();
        mBouncerFrame = bouncerFrameView.getBackground();

        mDoubleTapGesture = new GestureDetector(mContext,
                new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                if (pm != null) pm.goToSleep(e.getEventTime());
                return true;
            }
        });

        if (Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.DOUBLE_TAP_SLEEP_GESTURE, 0) == 1) {
            mGlowPadView.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return mDoubleTapGesture.onTouchEvent(event);
                }
            });
        }
    }
    }


    public void setCarrierArea(View carrierArea) {
    public void setCarrierArea(View carrierArea) {