|
1 | 1 | package org.wordpress.passcodelock; |
2 | 2 |
|
| 3 | +import android.annotation.TargetApi; |
3 | 4 | import android.app.Application; |
| 5 | +import android.os.Build; |
4 | 6 |
|
| 7 | +/** |
| 8 | + * Interface for AppLock implementations. |
| 9 | + * |
| 10 | + * There are situations where the AppLock should not be required within an app. Methods for tracking |
| 11 | + * exempt {@link android.app.Activity}'s are provided and sub-class implementations are expected to |
| 12 | + * comply with requested exemptions. |
| 13 | + * @see #isExemptActivity(String) |
| 14 | + * @see #setExemptActivities(String[]) |
| 15 | + * @see #getExemptActivities() |
| 16 | + * |
| 17 | + * Applications can request a one-time delay in locking the app. This can be useful for activities |
| 18 | + * that launch external applications with the expectation that the user will return to the calling |
| 19 | + * application shortly. |
| 20 | + */ |
| 21 | +@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) |
5 | 22 | public abstract class AbstractAppLock implements Application.ActivityLifecycleCallbacks { |
6 | | - public static final int DEFAULT_TIMEOUT = 2; //2 seconds |
7 | | - public static final int EXTENDED_TIMEOUT = 60; //60 seconds |
| 23 | + public static final String FINGERPRINT_VERIFICATION_BYPASS = "fingerprint-bypass__"; |
| 24 | + public static final int DEFAULT_TIMEOUT_S = 2; |
| 25 | + public static final int EXTENDED_TIMEOUT_S = 60; |
8 | 26 |
|
9 | | - protected static final String FINGERPRINT_VERIFICATION_BYPASS = "fingerprint-bypass__"; |
| 27 | + private int mLockTimeout = DEFAULT_TIMEOUT_S; |
| 28 | + private String[] mExemptActivities; |
10 | 29 |
|
11 | | - protected int lockTimeOut = DEFAULT_TIMEOUT; |
12 | | - protected String[] appLockDisabledActivities = new String[0]; |
| 30 | + public boolean isExemptActivity(String name) { |
| 31 | + if (name == null) return false; |
| 32 | + for (String activityName : getExemptActivities()) { |
| 33 | + if (name.equals(activityName)) return true; |
| 34 | + } |
| 35 | + return false; |
| 36 | + } |
| 37 | + |
| 38 | + public void setExemptActivities(String[] exemptActivities) { |
| 39 | + mExemptActivities = exemptActivities; |
| 40 | + } |
| 41 | + |
| 42 | + public String[] getExemptActivities() { |
| 43 | + if (mExemptActivities == null) setExemptActivities(new String[0]); |
| 44 | + return mExemptActivities; |
| 45 | + } |
13 | 46 |
|
14 | | - /* |
15 | | - * There are situations where an activity will start a different application with an intent. |
16 | | - * In these situations call this method right before leaving the app. |
17 | | - */ |
18 | 47 | public void setOneTimeTimeout(int timeout) { |
19 | | - this.lockTimeOut = timeout; |
| 48 | + mLockTimeout = timeout; |
| 49 | + } |
| 50 | + |
| 51 | + public int getTimeout() { |
| 52 | + return mLockTimeout; |
20 | 53 | } |
21 | 54 |
|
22 | | - /* |
23 | | - * There are situations where we don't want call the AppLock on activities (sharing items to out app for example). |
24 | | - */ |
25 | | - public void setDisabledActivities( String[] disabledActs ) { |
26 | | - this.appLockDisabledActivities = disabledActs; |
| 55 | + protected boolean isFingerprintPassword(String password) { |
| 56 | + return FINGERPRINT_VERIFICATION_BYPASS.equals(password); |
27 | 57 | } |
28 | | - |
| 58 | + |
29 | 59 | public abstract void enable(); |
30 | 60 | public abstract void disable(); |
31 | 61 | public abstract void forcePasswordLock(); |
32 | | - public abstract boolean verifyPassword( String password ); |
| 62 | + public abstract boolean verifyPassword(String password); |
33 | 63 | public abstract boolean isPasswordLocked(); |
34 | 64 | public abstract boolean setPassword(String password); |
35 | 65 | } |
0 commit comments