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

Add override callback for checkPasscode & setPasscode #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.orangegangsters.lollipin.lib.interfaces;

public interface ILockCallback {

boolean onCheckPasscode(String inputPasscode);

boolean onSetPasscode(String passcode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.app.Activity;

import com.github.orangegangsters.lollipin.lib.interfaces.ILockCallback;

import java.util.HashSet;

public abstract class AppLock {
Expand Down Expand Up @@ -102,6 +104,11 @@ public void removeIgnoredActivity(Class<?> clazz) {
*/
public abstract void setShouldShowForgot(boolean showForgot);

/**
* set callback to be called when passcode is checked or set.
*/
public abstract void setCallback(ILockCallback lockCallback);

/**
* Get whether the user backed out of the {@link AppLockActivity} previously
*/
Expand Down Expand Up @@ -170,6 +177,7 @@ public void removeIgnoredActivity(Class<?> clazz) {

/**
* Enable or disable fingerprint authentication on the PIN screen.
*
* @param enabled If true, enables the fingerprint reader if it is supported. If false, will
* hide the fingerprint reader icon on the PIN screen.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.github.orangegangsters.lollipin.lib.PinFragmentActivity;
import com.github.orangegangsters.lollipin.lib.encryption.Encryptor;
import com.github.orangegangsters.lollipin.lib.enums.Algorithm;
import com.github.orangegangsters.lollipin.lib.interfaces.ILockCallback;
import com.github.orangegangsters.lollipin.lib.interfaces.LifeCycleInterface;

import java.security.SecureRandom;
Expand Down Expand Up @@ -97,6 +98,11 @@ public class AppLockImpl<T extends AppLockActivity> extends AppLock implements L
*/
private static AppLockImpl mInstance;

/**
* custom callback for checking and setting passcode.
*/
private ILockCallback mLockCallback;

/**
* Static method that allows to get back the current static Instance of {@link AppLockImpl}
*
Expand Down Expand Up @@ -262,8 +268,16 @@ public void setLastActiveMillis() {
editor.apply();
}

@Override
public void setCallback(ILockCallback lockCallback) {
mLockCallback = lockCallback;
}

@Override
public boolean checkPasscode(String passcode) {
if (mLockCallback != null) {
return mLockCallback.onCheckPasscode(passcode);
}
Algorithm algorithm = Algorithm.getFromText(mSharedPreferences.getString(PASSWORD_ALGORITHM_PREFERENCE_KEY, ""));

String salt = getSalt();
Expand All @@ -284,6 +298,9 @@ public boolean checkPasscode(String passcode) {

@Override
public boolean setPasscode(String passcode) {
if (mLockCallback != null) {
return mLockCallback.onSetPasscode(passcode);
}
String salt = getSalt();
SharedPreferences.Editor editor = mSharedPreferences.edit();

Expand Down