diff --git a/lib/src/main/java/com/github/orangegangsters/lollipin/lib/interfaces/ILockCallback.java b/lib/src/main/java/com/github/orangegangsters/lollipin/lib/interfaces/ILockCallback.java new file mode 100644 index 00000000..09e0f3ff --- /dev/null +++ b/lib/src/main/java/com/github/orangegangsters/lollipin/lib/interfaces/ILockCallback.java @@ -0,0 +1,8 @@ +package com.github.orangegangsters.lollipin.lib.interfaces; + +public interface ILockCallback { + + boolean onCheckPasscode(String inputPasscode); + + boolean onSetPasscode(String passcode); +} diff --git a/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLock.java b/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLock.java index 6078666d..1ef56046 100644 --- a/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLock.java +++ b/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLock.java @@ -2,6 +2,8 @@ import android.app.Activity; +import com.github.orangegangsters.lollipin.lib.interfaces.ILockCallback; + import java.util.HashSet; public abstract class AppLock { @@ -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 */ @@ -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. */ diff --git a/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLockImpl.java b/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLockImpl.java index a2b9d46e..24ef85d3 100644 --- a/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLockImpl.java +++ b/lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLockImpl.java @@ -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; @@ -97,6 +98,11 @@ public class AppLockImpl 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} * @@ -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(); @@ -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();