Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Attempts count is saved in storage now
Browse files Browse the repository at this point in the history
  • Loading branch information
hluhovskyi committed Oct 25, 2017
1 parent 3acff56 commit 0fa0468
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

public interface CredentialStorage {

int readAttemptsCount();

void writeAttemptsCount(int attempts);

@Nullable
String readSalt();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public interface KeyboardButtonClickedListener {
* Called before {@link #onRippleAnimationEnd()}.
* @param keyboardButtonEnum The organized enum of the clicked button
*/
public void onKeyboardClick(KeyboardButtonEnum keyboardButtonEnum);
void onKeyboardClick(KeyboardButtonEnum keyboardButtonEnum);

/**
* Receive the end of a {@link com.andexert.library.RippleView} animation using a
* {@link com.andexert.library.RippleAnimationListener} to determine the end.
* Called after {@link #onKeyboardClick(com.github.orangegangsters.lollipin.lib.enums.KeyboardButtonEnum)}.
*/
public void onRippleAnimationEnd();
void onRippleAnimationEnd();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public interface LifeCycleInterface {
/**
* Called in {@link android.app.Activity#onResume()}
*/
public void onActivityResumed(Activity activity);
void onActivityResumed(Activity activity);

/**
* Called in {@link android.app.Activity#onPause()}
*/
public void onActivityPaused(Activity activity);
void onActivityPaused(Activity activity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public void removeIgnoredActivity(Class<? extends Activity> clazz) {
*/
public abstract void setLastActiveMillis();

public abstract int getAttemptsCount();

public abstract int incrementAttemptsCountAndGet();

public abstract void resetAttemptsCount();

/**
* Set the passcode (store his SHA1 into {@link android.content.SharedPreferences}) using the
* {@link com.github.orangegangsters.lollipin.lib.encryption.Encryptor} class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ public abstract class AppLockActivity extends PinActivity implements KeyboardBut

protected LockManager mLockManager;


protected FingerprintManager mFingerprintManager;
protected FingerprintUiHelper mFingerprintUiHelper;

protected int mType = AppLock.UNLOCK_PIN;
protected int mAttempts = 1;
protected int mAttempts = 0;
protected String mPinCode;

protected String mOldPinCode;
Expand Down Expand Up @@ -96,10 +95,7 @@ protected void onPause() {
* Init completely the layout, depending of the extra {@link com.github.orangegangsters.lollipin.lib.managers.AppLock#EXTRA_TYPE}
*/
private void initLayout(Intent intent) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
//Animate if greater than 2.3.3
overridePendingTransition(R.anim.nothing, R.anim.nothing);
}
overridePendingTransition(R.anim.nothing, R.anim.nothing);

Bundle extras = intent.getExtras();
if (extras != null) {
Expand All @@ -112,6 +108,7 @@ private void initLayout(Intent intent) {

enableAppLockerIfDoesNotExist();
mLockManager.getAppLock().setPinChallengeCancelled(false);
mAttempts = mLockManager.getAppLock().getAttemptsCount();

mStepTextView = (TextView) this.findViewById(R.id.pin_code_step_textview);
mPinCodeRoundView = (PinCodeRoundView) this.findViewById(R.id.pin_code_round_view);
Expand Down Expand Up @@ -144,8 +141,8 @@ private void initLayoutForFingerprint() {
mFingerprintManager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);
mFingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(mFingerprintManager).build(mFingerprintImageView, mFingerprintTextView, this);
try {
if (mFingerprintManager.isHardwareDetected() && mFingerprintUiHelper.isFingerprintAuthAvailable()
&& mLockManager.getAppLock().isFingerprintAuthEnabled()) {
if (mFingerprintManager.isHardwareDetected() && mFingerprintUiHelper.isFingerprintAuthAvailable()
&& mLockManager.getAppLock().isFingerprintAuthEnabled()) {
mFingerprintImageView.setVisibility(View.VISIBLE);
mFingerprintTextView.setVisibility(View.VISIBLE);
mFingerprintUiHelper.startListening();
Expand Down Expand Up @@ -218,7 +215,7 @@ public String getForgotText() {
return getString(R.string.pin_code_forgot_text);
}

private void setForgotTextVisibility(){
private void setForgotTextVisibility() {
mForgotTextView.setVisibility(mLockManager.getAppLock().shouldShowForgot(mType) ? View.VISIBLE : View.GONE);
}

Expand All @@ -239,10 +236,7 @@ public void finish() {
}
}

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
//Animate if greater than 2.3.3
overridePendingTransition(R.anim.nothing, R.anim.slide_down);
}
overridePendingTransition(R.anim.nothing, R.anim.slide_down);
}

/**
Expand Down Expand Up @@ -388,8 +382,10 @@ public List<Integer> getBackableTypes() {
* Run a shake animation when the password is not valid.
*/
protected void onPinCodeError() {
onPinFailure(mAttempts++);
Thread thread = new Thread() {
mAttempts = mLockManager.getAppLock().incrementAttemptsCountAndGet();
onPinFailure(mAttempts);
Runnable thread = new Runnable() {
@Override
public void run() {
mPinCode = "";
mPinCodeRoundView.refresh(mPinCode.length());
Expand All @@ -403,8 +399,9 @@ public void run() {

protected void onPinCodeSuccess() {
isCodeSuccessful = true;
onPinSuccess(mAttempts);
mAttempts = 1;
onPinSuccess(mAttempts + 1);
mAttempts = 0;
mLockManager.getAppLock().resetAttemptsCount();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ public void setLastActiveMillis() {
mConfigurationStorage.writeLastActiveMillis(System.currentTimeMillis());
}

@Override
public int getAttemptsCount() {
return mCredentialStorage.readAttemptsCount();
}

@Override
public int incrementAttemptsCountAndGet() {
int attempts = mCredentialStorage.readAttemptsCount() + 1;
mCredentialStorage.writeAttemptsCount(attempts);
return attempts;
}

@Override
public void resetAttemptsCount() {
mCredentialStorage.writeAttemptsCount(0);
}

@Override
public boolean checkPasscode(String passcode) {
Algorithm algorithm = mCredentialStorage.readCurrentAlgorithm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class DefaultPreferencesCredentialStorage implements CredentialStorage {

private static final String ATTEMPTS_COUNT_PREFERENCE_KEY = "ATTEMPTS_COUNT_PREFERENCE_KEY";
/**
* The {@link android.content.SharedPreferences} key used to store the dynamically generated password salt
*/
Expand All @@ -30,6 +31,18 @@ public DefaultPreferencesCredentialStorage(Context context) {
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}

@Override
public int readAttemptsCount() {
return mPreferences.getInt(ATTEMPTS_COUNT_PREFERENCE_KEY, 0);
}

@Override
public void writeAttemptsCount(int attempts) {
mPreferences.edit()
.putInt(ATTEMPTS_COUNT_PREFERENCE_KEY, attempts)
.apply();
}

@Override
@Nullable
public String readSalt() {
Expand Down

This file was deleted.

0 comments on commit 0fa0468

Please sign in to comment.