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

Commit 68e6fa72 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Remove "forgot pattern" in pattern view

Bug: 17184958
Change-Id: I7ebb35a1b734286ded99352b3fa2b891386c581d
parent 038839e9
Loading
Loading
Loading
Loading
+12 −32
Original line number Original line Diff line number Diff line
@@ -40,20 +40,12 @@
        android:visibility="gone"
        android:visibility="gone"
        androidprv:allCaps="@bool/kg_use_all_caps" />
        androidprv:allCaps="@bool/kg_use_all_caps" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/eca_overlap"
        style="?android:attr/buttonBarStyle"
        android:orientation="horizontal"
        android:gravity="center"
        android:weightSum="2">

    <com.android.keyguard.EmergencyButton
    <com.android.keyguard.EmergencyButton
        android:id="@+id/emergency_call_button"
        android:id="@+id/emergency_call_button"
            android:layout_width="0dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_weight="1"
        android:layout_marginTop="@dimen/eca_overlap"
        android:drawableLeft="@drawable/lockscreen_emergency_button"
        android:drawableLeft="@drawable/lockscreen_emergency_button"
        android:text="@string/kg_emergency_call_label"
        android:text="@string/kg_emergency_call_label"
        style="?android:attr/buttonBarButtonStyle"
        style="?android:attr/buttonBarButtonStyle"
@@ -63,16 +55,4 @@
        android:drawablePadding="8dip"
        android:drawablePadding="8dip"
        android:textAllCaps="@bool/kg_use_all_caps" />
        android:textAllCaps="@bool/kg_use_all_caps" />


        <Button android:id="@+id/forgot_password_button"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            style="?android:attr/buttonBarButtonStyle"
            android:textSize="@dimen/kg_status_line_font_size"
            android:textColor="?android:attr/textColorSecondary"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:visibility="gone"
            android:textAllCaps="@bool/kg_use_all_caps" />
    </LinearLayout>

</com.android.keyguard.EmergencyCarrierArea>
</com.android.keyguard.EmergencyCarrierArea>
+0 −126
Original line number Original line Diff line number Diff line
@@ -15,38 +15,27 @@
 */
 */
package com.android.keyguard;
package com.android.keyguard;


import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
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.CountDownTimer;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.Interpolator;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout;


import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternView;
import com.android.internal.widget.LockPatternView;


import java.io.IOException;
import java.util.List;
import java.util.List;


public class KeyguardPatternView extends LinearLayout implements KeyguardSecurityView,
public class KeyguardPatternView extends LinearLayout implements KeyguardSecurityView,
@@ -70,9 +59,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
    private CountDownTimer mCountdownTimer = null;
    private CountDownTimer mCountdownTimer = null;
    private LockPatternUtils mLockPatternUtils;
    private LockPatternUtils mLockPatternUtils;
    private LockPatternView mLockPatternView;
    private LockPatternView mLockPatternView;
    private Button mForgotPatternButton;
    private KeyguardSecurityCallback mCallback;
    private KeyguardSecurityCallback mCallback;
    private boolean mEnableFallback;


    /**
    /**
     * Keeps track of the last time we poked the wake lock during dispatching of the touch event.
     * Keeps track of the last time we poked the wake lock during dispatching of the touch event.
@@ -144,20 +131,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        // vibrate mode will be the same for the life of this screen
        // vibrate mode will be the same for the life of this screen
        mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled());
        mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled());


        mForgotPatternButton = (Button) findViewById(R.id.forgot_password_button);
        // note: some configurations don't have an emergency call area
        if (mForgotPatternButton != null) {
            mForgotPatternButton.setText(R.string.kg_forgot_pattern_button_text);
            mForgotPatternButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mCallback.showBackupSecurity();
                }
            });
        }

        setFocusableInTouchMode(true);
        setFocusableInTouchMode(true);


        maybeEnableFallback(mContext);
        mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this);
        mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this);
        mEcaView = findViewById(R.id.keyguard_selector_fade_container);
        mEcaView = findViewById(R.id.keyguard_selector_fade_container);
        View bouncerFrameView = findViewById(R.id.keyguard_bouncer_frame);
        View bouncerFrameView = findViewById(R.id.keyguard_bouncer_frame);
@@ -169,24 +144,6 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        mHelpMessage = (KeyguardMessageArea) findViewById(R.id.keyguard_message_area);
        mHelpMessage = (KeyguardMessageArea) findViewById(R.id.keyguard_message_area);
    }
    }


    private void updateFooter(FooterMode mode) {
        if (mForgotPatternButton == null) return; // no ECA? no footer

        switch (mode) {
            case Normal:
                if (DEBUG) Log.d(TAG, "mode normal");
                mForgotPatternButton.setVisibility(View.GONE);
                break;
            case ForgotLockPattern:
                if (DEBUG) Log.d(TAG, "mode ForgotLockPattern");
                mForgotPatternButton.setVisibility(View.VISIBLE);
                break;
            case VerifyUnlocked:
                if (DEBUG) Log.d(TAG, "mode VerifyUnlocked");
                mForgotPatternButton.setVisibility(View.GONE);
        }
    }

    @Override
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
    public boolean onTouchEvent(MotionEvent ev) {
        boolean result = super.onTouchEvent(ev);
        boolean result = super.onTouchEvent(ev);
@@ -217,18 +174,6 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        } else {
        } else {
            displayDefaultSecurityMessage();
            displayDefaultSecurityMessage();
        }
        }

        // the footer depends on how many total attempts the user has failed
        if (mCallback.isVerifyUnlockOnly()) {
            updateFooter(FooterMode.VerifyUnlocked);
        } else if (mEnableFallback &&
                (mKeyguardUpdateMonitor.getFailedUnlockAttempts()
                        >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) {
            updateFooter(FooterMode.ForgotLockPattern);
        } else {
            updateFooter(FooterMode.Normal);
        }

    }
    }


    private void displayDefaultSecurityMessage() {
    private void displayDefaultSecurityMessage() {
@@ -291,68 +236,10 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        }
        }
    }
    }


    private void maybeEnableFallback(Context context) {
        // Ask the account manager if we have an account that can be used as a
        // fallback in case the user forgets his pattern.
        AccountAnalyzer accountAnalyzer = new AccountAnalyzer(AccountManager.get(context));
        accountAnalyzer.start();
    }

    private class AccountAnalyzer implements AccountManagerCallback<Bundle> {
        private final AccountManager mAccountManager;
        private final Account[] mAccounts;
        private int mAccountIndex;

        private AccountAnalyzer(AccountManager accountManager) {
            mAccountManager = accountManager;
            mAccounts = accountManager.getAccountsByTypeAsUser("com.google",
                    new UserHandle(mLockPatternUtils.getCurrentUser()));
        }

        private void next() {
            // if we are ready to enable the fallback or if we depleted the list of accounts
            // then finish and get out
            if (mEnableFallback || mAccountIndex >= mAccounts.length) {
                return;
            }

            // lookup the confirmCredentials intent for the current account
            mAccountManager.confirmCredentialsAsUser(mAccounts[mAccountIndex], null, null, this,
                    null, new UserHandle(mLockPatternUtils.getCurrentUser()));
        }

        public void start() {
            mEnableFallback = false;
            mAccountIndex = 0;
            next();
        }

        public void run(AccountManagerFuture<Bundle> future) {
            try {
                Bundle result = future.getResult();
                if (result.getParcelable(AccountManager.KEY_INTENT) != null) {
                    mEnableFallback = true;
                }
            } catch (OperationCanceledException e) {
                // just skip the account if we are unable to query it
            } catch (IOException e) {
                // just skip the account if we are unable to query it
            } catch (AuthenticatorException e) {
                // just skip the account if we are unable to query it
            } finally {
                mAccountIndex++;
                next();
            }
        }
    }

    private void handleAttemptLockout(long elapsedRealtimeDeadline) {
    private void handleAttemptLockout(long elapsedRealtimeDeadline) {
        mLockPatternView.clearPattern();
        mLockPatternView.clearPattern();
        mLockPatternView.setEnabled(false);
        mLockPatternView.setEnabled(false);
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        if (mEnableFallback) {
            updateFooter(FooterMode.ForgotLockPattern);
        }


        mCountdownTimer = new CountDownTimer(elapsedRealtimeDeadline - elapsedRealtime, 1000) {
        mCountdownTimer = new CountDownTimer(elapsedRealtimeDeadline - elapsedRealtime, 1000) {


@@ -367,12 +254,6 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
            public void onFinish() {
            public void onFinish() {
                mLockPatternView.setEnabled(true);
                mLockPatternView.setEnabled(true);
                displayDefaultSecurityMessage();
                displayDefaultSecurityMessage();
                // TODO mUnlockIcon.setVisibility(View.VISIBLE);
                if (mEnableFallback) {
                    updateFooter(FooterMode.ForgotLockPattern);
                } else {
                    updateFooter(FooterMode.Normal);
                }
            }
            }


        }.start();
        }.start();
@@ -489,13 +370,6 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
            // Also animate the Emergency call
            // Also animate the Emergency call
            mAppearAnimationUtils.createAnimation(mEcaView, delay, duration, startTranslationY,
            mAppearAnimationUtils.createAnimation(mEcaView, delay, duration, startTranslationY,
            interpolator, null);
            interpolator, null);

            // And the forgot pattern button
            if (mForgotPatternButton != null
                    && mForgotPatternButton.getVisibility() == View.VISIBLE) {
                mAppearAnimationUtils.createAnimation(mForgotPatternButton, delay, duration,
                        startTranslationY, interpolator, null);
            }
        }
        }
        animator.start();
        animator.start();
        mLockPatternView.invalidate();
        mLockPatternView.invalidate();