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

Commit c429e68e authored by Roman Birg's avatar Roman Birg
Browse files

CryptKeeper improvements



- Status text was used enough to warrant it being a field variable
  instead of looking for the view every time

- Display proper text after changing pattern sizes (to input a pattern,
  not a password)

- Disable changing pattern sizes while validaing pattern

REFS: LETTUCE-557, LETTUCE-352 
Change-Id: Ib4ecf04a58da8d1648d514d9650d69c33d9587a7
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 83b4a995
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
            android:text="@string/lock_pattern_size_3"
            android:textColor="@color/text_color_white"
            android:layout_weight="1"
            android:onClick="onPatternButtonClick"
            style="?android:attr/borderlessButtonStyle"/>

    <Button
@@ -39,7 +38,6 @@
            android:text="@string/lock_pattern_size_4"
            android:textColor="@color/text_color_white"
            android:layout_weight="1"
            android:onClick="onPatternButtonClick"
            style="?android:attr/borderlessButtonStyle"/>

    <Button
@@ -52,7 +50,6 @@
            android:text="@string/lock_pattern_size_5"
            android:textColor="@color/text_color_white"
            android:layout_weight="1"
            android:onClick="onPatternButtonClick"
            style="?android:attr/borderlessButtonStyle"/>

    <Button
@@ -65,7 +62,6 @@
            android:text="@string/lock_pattern_size_6"
            android:textColor="@color/text_color_white"
            android:layout_weight="1"
            android:onClick="onPatternButtonClick"
            style="?android:attr/borderlessButtonStyle"/>


+56 −28
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
import android.media.AudioManager;
import android.os.AsyncTask;
@@ -69,6 +70,7 @@ import com.android.internal.widget.LockPatternView.Cell;

import static com.android.internal.widget.LockPatternView.DisplayMode;

import java.util.ArrayList;
import java.util.List;

/**
@@ -85,7 +87,7 @@ import java.util.List;
 * </pre>
 */
public class CryptKeeper extends Activity implements TextView.OnEditorActionListener,
        OnKeyListener, OnTouchListener, TextWatcher {
        OnKeyListener, OnTouchListener, TextWatcher, OnClickListener {
    private static final String TAG = "CryptKeeper";

    private static final String DECRYPT_STATE = "trigger_restart_framework";
@@ -125,6 +127,15 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
    PowerManager.WakeLock mWakeLock;
    private EditText mPasswordEntry;
    private LockPatternView mLockPatternView;
    private TextView mStatusText;
    private List<Button> mLockPatternButtons = new ArrayList<>();
    private static final int[] LOCK_BUTTON_IDS = new int[] {
            R.id.lock_pattern_size_3,
            R.id.lock_pattern_size_4,
            R.id.lock_pattern_size_5,
            R.id.lock_pattern_size_6
    };

    /** Number of calls to {@link #notifyUser()} to ignore before notifying. */
    private int mNotificationCountdown = 0;
    /** Number of calls to {@link #notifyUser()} before we release the wakelock */
@@ -204,8 +215,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
                    mLockPatternView.removeCallbacks(mClearPatternRunnable);
                    mLockPatternView.postDelayed(mClearPatternRunnable, RIGHT_PATTERN_CLEAR_TIMEOUT_MS);
                }
                final TextView status = (TextView) findViewById(R.id.status);
                status.setText(R.string.starting_android);
                mStatusText.setText(R.string.starting_android);
                hide(R.id.passwordEntry);
                hide(R.id.switch_ime_button);
                hide(R.id.lockPattern);
@@ -230,8 +240,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
    }

    private void beginAttempt() {
        final TextView status = (TextView) findViewById(R.id.status);
        status.setText(R.string.checking_decryption);
        mStatusText.setText(R.string.checking_decryption);
    }

    private void handleBadAttempt(Integer failedAttempts) {
@@ -247,14 +256,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
            // at this point.
            cooldown();
        } else {
            final TextView status = (TextView) findViewById(R.id.status);

            int remainingAttempts = MAX_FAILED_ATTEMPTS - failedAttempts;
            if (remainingAttempts < COOL_DOWN_ATTEMPTS) {
                CharSequence warningTemplate = getText(R.string.crypt_keeper_warn_wipe);
                CharSequence warning = TextUtils.expandTemplate(warningTemplate,
                        Integer.toString(remainingAttempts));
                status.setText(warning);
                mStatusText.setText(warning);
            } else {
                int passwordType = StorageManager.CRYPT_TYPE_PASSWORD;
                try {
@@ -265,17 +272,18 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
                }

                if (passwordType == StorageManager.CRYPT_TYPE_PIN) {
                    status.setText(R.string.cryptkeeper_wrong_pin);
                    mStatusText.setText(R.string.cryptkeeper_wrong_pin);
                } else if (passwordType == StorageManager.CRYPT_TYPE_PATTERN) {
                    status.setText(R.string.cryptkeeper_wrong_pattern);
                    mStatusText.setText(R.string.cryptkeeper_wrong_pattern);
                } else {
                    status.setText(R.string.cryptkeeper_wrong_password);
                    mStatusText.setText(R.string.cryptkeeper_wrong_password);
                }
            }

            if (mLockPatternView != null) {
                mLockPatternView.setDisplayMode(DisplayMode.Wrong);
                mLockPatternView.setEnabled(true);
                setPatternButtonsEnabled(true);
            }

            // Reenable the password entry
@@ -518,8 +526,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
                        setContentView(R.layout.crypt_keeper_password_entry);
                        mStatusString = R.string.enter_password;
                    }
                    final TextView status = (TextView) findViewById(R.id.status);
                    status.setText(mStatusString);
                    mStatusText.setText(mStatusString);

                    final TextView ownerInfo = (TextView) findViewById(R.id.owner_info);
                    ownerInfo.setText(owner_info);
@@ -576,6 +583,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
        }
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        mStatusText = (TextView) findViewById(R.id.status);
    }

    /**
     * Start encrypting the device.
     */
@@ -674,9 +687,8 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
            // Will happen if no time etc - show percentage
        }

        final TextView tv = (TextView) findViewById(R.id.status);
        if (tv != null) {
            tv.setText(TextUtils.expandTemplate(status, progress));
        if (mStatusText != null) {
            mStatusText.setText(TextUtils.expandTemplate(status, progress));
        }

        // Check the progress every 1 seconds
@@ -693,16 +705,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
            mPasswordEntry.setEnabled(false);
        }

        final ViewGroup sizes = (ViewGroup) findViewById(R.id.status);
        if (mLockPatternView != null) {
            mLockPatternView.setEnabled(false);
            if (sizes != null) {
                sizes.setEnabled(false);
            }
            setPatternButtonsEnabled(false);
        }

        final TextView status = (TextView) findViewById(R.id.status);
        status.setText(R.string.crypt_keeper_force_power_cycle);
        mStatusText.setText(R.string.crypt_keeper_force_power_cycle);
    }

    /**
@@ -728,11 +736,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList

        @Override
        public void onPatternStart() {
            setPatternButtonsEnabled(false);
            mLockPatternView.removeCallbacks(mClearPatternRunnable);
        }

        @Override
        public void onPatternCleared() {
            setPatternButtonsEnabled(true);
        }

        @Override
@@ -764,10 +774,18 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
            mPasswordEntry.addTextChangedListener(this);
        }

         mLockPatternButtons.clear();
        // Pattern case
        mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern);
        if (mLockPatternView != null) {
            mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener);
            for (int id : LOCK_BUTTON_IDS) {
                Button btn = (Button) findViewById(id);
                if (btn != null) {
                    btn.setOnClickListener(this);
                    mLockPatternButtons.add(btn);
                }
            }
        }

        // Disable the Emergency call button if the device has no voice telephone capability
@@ -1040,7 +1058,11 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
        return;
    }

    public void onPatternButtonClick(View v) {
    @Override
    public void onClick(View v) {
        if (mLockPatternView == null || !mLockPatternView.isEnabled()) {
            return;
        }
        byte size;
        switch (v.getId()) {
            default:
@@ -1057,11 +1079,17 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
                size = 6;
                break;
        }
        if (mLockPatternView != null) {
        setContentView(R.layout.crypt_keeper_pattern_entry);
        passwordEntryInit();

        mStatusText.setText(mStatusString = R.string.enter_pattern);
        mLockPatternView.setLockPatternSize(size);
        mLockPatternView.postInvalidate();
    }

    private void setPatternButtonsEnabled(boolean enabled) {
        for (Button btn : mLockPatternButtons) {
            btn.setEnabled(enabled);
        }
    }
}