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

Commit f928337

Browse files
committed
Rename CredentialStorage to PasscodeDataStorage. Implement RealmPasscodeDataStorage in separate module.
1 parent 0fa0468 commit f928337

File tree

17 files changed

+330
-43
lines changed

17 files changed

+330
-43
lines changed

app/src/main/java/com/github/orangegangsters/lollipin/CustomApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
*/
1212
public class CustomApplication extends Application {
1313

14-
@SuppressWarnings("unchecked")
1514
@Override
1615
public void onCreate() {
1716
super.onCreate();
1817

19-
LockManager<CustomPinActivity> lockManager = LockManager.getInstance();
18+
LockManager lockManager = LockManager.getInstance();
2019
lockManager.enableAppLock(this, CustomPinActivity.class);
2120
lockManager.getAppLock().setLogoId(R.drawable.security_lock);
2221
}

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ buildscript {
77
}
88
dependencies {
99
classpath 'com.android.tools.build:gradle:2.3.1'
10+
classpath "io.realm:realm-gradle-plugin:3.1.4"
1011
}
1112
}
1213

lib/src/main/java/com/github/orangegangsters/lollipin/lib/interfaces/CredentialStorage.java renamed to lib/src/main/java/com/github/orangegangsters/lollipin/lib/interfaces/PasscodeDataStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import com.github.orangegangsters.lollipin.lib.enums.Algorithm;
77

8-
public interface CredentialStorage {
8+
public interface PasscodeDataStorage {
99

1010
int readAttemptsCount();
1111

lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLock.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import android.support.annotation.Nullable;
77

88
import com.github.orangegangsters.lollipin.lib.interfaces.ConfigurationStorage;
9-
import com.github.orangegangsters.lollipin.lib.interfaces.CredentialStorage;
9+
import com.github.orangegangsters.lollipin.lib.interfaces.PasscodeDataStorage;
1010

1111
import java.util.HashSet;
1212

@@ -235,7 +235,7 @@ public static class Builder {
235235
private final Class<? extends AppLockActivity> mActivityClass;
236236

237237
private ConfigurationStorage mConfigurationStorage;
238-
private CredentialStorage mCredentialStorage;
238+
private PasscodeDataStorage mPasscodeDataStorage;
239239

240240
public Builder(Context context, Class<? extends AppLockActivity> activityClass) {
241241
mContext = context;
@@ -263,12 +263,12 @@ public Builder setConfigurationStorage(@Nullable ConfigurationStorage configurat
263263
}
264264

265265
@Nullable
266-
CredentialStorage getCredentialStorage() {
267-
return mCredentialStorage;
266+
PasscodeDataStorage getPasscodeDataStorage() {
267+
return mPasscodeDataStorage;
268268
}
269269

270-
public Builder setCredentialStorage(@Nullable CredentialStorage credentialStorage) {
271-
mCredentialStorage = credentialStorage;
270+
public Builder setPasscodeDataStorage(@Nullable PasscodeDataStorage passcodeDataStorage) {
271+
mPasscodeDataStorage = passcodeDataStorage;
272272
return this;
273273
}
274274

lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/AppLockImpl.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
import com.github.orangegangsters.lollipin.lib.encryption.SaltGenerator;
1313
import com.github.orangegangsters.lollipin.lib.enums.Algorithm;
1414
import com.github.orangegangsters.lollipin.lib.interfaces.ConfigurationStorage;
15-
import com.github.orangegangsters.lollipin.lib.interfaces.CredentialStorage;
15+
import com.github.orangegangsters.lollipin.lib.interfaces.PasscodeDataStorage;
1616
import com.github.orangegangsters.lollipin.lib.interfaces.LifeCycleInterface;
1717
import com.github.orangegangsters.lollipin.lib.storage.DefaultPreferencesConfigurationStorage;
18-
import com.github.orangegangsters.lollipin.lib.storage.DefaultPreferencesCredentialStorage;
18+
import com.github.orangegangsters.lollipin.lib.storage.DefaultPreferencesPasscodeDataStorage;
1919

2020
public class AppLockImpl extends AppLock implements LifeCycleInterface {
2121

2222
public static final String TAG = "AppLockImpl";
2323

24-
private final CredentialStorage mCredentialStorage;
24+
private final PasscodeDataStorage mPasscodeDataStorage;
2525
private final ConfigurationStorage mConfigurationStorage;
2626

2727
/**
@@ -53,14 +53,14 @@ public static AppLockImpl getInstance(Context context, Class<? extends AppLockAc
5353

5454
AppLockImpl(Context context, Class<? extends AppLockActivity> activityClass) {
5555
mActivityClass = activityClass;
56-
mCredentialStorage = new DefaultPreferencesCredentialStorage(context);
56+
mPasscodeDataStorage = new DefaultPreferencesPasscodeDataStorage(context);
5757
mConfigurationStorage = new DefaultPreferencesConfigurationStorage(context);
5858
}
5959

6060
AppLockImpl(Builder builder) {
6161
mActivityClass = builder.getActivityClass();
6262
mConfigurationStorage = getConfigurationStorageOrDefault(builder);
63-
mCredentialStorage = getCredentialStorageOrDefault(builder);
63+
mPasscodeDataStorage = getPasscodeDataStorageOrDefault(builder);
6464
}
6565

6666
private static ConfigurationStorage getConfigurationStorageOrDefault(Builder builder) {
@@ -72,10 +72,10 @@ private static ConfigurationStorage getConfigurationStorageOrDefault(Builder bui
7272
}
7373
}
7474

75-
private static CredentialStorage getCredentialStorageOrDefault(Builder builder) {
76-
CredentialStorage storage = builder.getCredentialStorage();
75+
private static PasscodeDataStorage getPasscodeDataStorageOrDefault(Builder builder) {
76+
PasscodeDataStorage storage = builder.getPasscodeDataStorage();
7777
if (storage == null) {
78-
return new DefaultPreferencesCredentialStorage(builder.getContext());
78+
return new DefaultPreferencesPasscodeDataStorage(builder.getContext());
7979
} else {
8080
return storage;
8181
}
@@ -92,7 +92,7 @@ public void setTimeout(long timeout) {
9292
}
9393

9494
public String getSalt() {
95-
String salt = mCredentialStorage.readSalt();
95+
String salt = mPasscodeDataStorage.readSalt();
9696
if (salt == null) {
9797
salt = SaltGenerator.generate();
9898
setSalt(salt);
@@ -101,7 +101,7 @@ public String getSalt() {
101101
}
102102

103103
private void setSalt(String salt) {
104-
mCredentialStorage.writeSalt(salt);
104+
mPasscodeDataStorage.writeSalt(salt);
105105
}
106106

107107
@Override
@@ -166,7 +166,7 @@ public void disableAndRemoveConfiguration() {
166166
PinCompatActivity.clearListeners();
167167
PinFragmentActivity.clearListeners();
168168
mConfigurationStorage.clear();
169-
mCredentialStorage.clear();
169+
mPasscodeDataStorage.clear();
170170
}
171171

172172
@Override
@@ -191,32 +191,32 @@ public void setLastActiveMillis() {
191191

192192
@Override
193193
public int getAttemptsCount() {
194-
return mCredentialStorage.readAttemptsCount();
194+
return mPasscodeDataStorage.readAttemptsCount();
195195
}
196196

197197
@Override
198198
public int incrementAttemptsCountAndGet() {
199-
int attempts = mCredentialStorage.readAttemptsCount() + 1;
200-
mCredentialStorage.writeAttemptsCount(attempts);
199+
int attempts = mPasscodeDataStorage.readAttemptsCount() + 1;
200+
mPasscodeDataStorage.writeAttemptsCount(attempts);
201201
return attempts;
202202
}
203203

204204
@Override
205205
public void resetAttemptsCount() {
206-
mCredentialStorage.writeAttemptsCount(0);
206+
mPasscodeDataStorage.writeAttemptsCount(0);
207207
}
208208

209209
@Override
210210
public boolean checkPasscode(String passcode) {
211-
Algorithm algorithm = mCredentialStorage.readCurrentAlgorithm();
211+
Algorithm algorithm = mPasscodeDataStorage.readCurrentAlgorithm();
212212

213213
String salt = getSalt();
214214
passcode = salt + passcode + salt;
215215
passcode = Encryptor.getSHA(passcode, algorithm);
216216
String storedPasscode = "";
217217

218218
if (isPasscodeSet()) {
219-
storedPasscode = mCredentialStorage.readPasscode();
219+
storedPasscode = mPasscodeDataStorage.readPasscode();
220220
}
221221

222222
return storedPasscode.equalsIgnoreCase(passcode);
@@ -226,12 +226,12 @@ public boolean checkPasscode(String passcode) {
226226
public boolean setPasscode(String passcode) {
227227
String salt = getSalt();
228228
if (passcode == null) {
229-
mCredentialStorage.clearPasscode();
229+
mPasscodeDataStorage.clearPasscode();
230230
this.disable();
231231
} else {
232232
setAlgorithm(Algorithm.SHA256);
233233
passcode = Encryptor.getSHA(salt + passcode + salt, Algorithm.SHA256);
234-
mCredentialStorage.writePasscode(passcode);
234+
mPasscodeDataStorage.writePasscode(passcode);
235235
this.enable();
236236
}
237237
return true;
@@ -241,12 +241,12 @@ public boolean setPasscode(String passcode) {
241241
* Set the algorithm used in {@link #setPasscode(String)}
242242
*/
243243
private void setAlgorithm(Algorithm algorithm) {
244-
mCredentialStorage.writeCurrentAlgorithm(algorithm);
244+
mPasscodeDataStorage.writeCurrentAlgorithm(algorithm);
245245
}
246246

247247
@Override
248248
public boolean isPasscodeSet() {
249-
return mCredentialStorage.hasPasscode();
249+
return mPasscodeDataStorage.hasPasscode();
250250
}
251251

252252
@Override

lib/src/main/java/com/github/orangegangsters/lollipin/lib/managers/LockManager.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
* the actual app calling the library.
1313
* You must get this static instance by calling {@link #getInstance()}
1414
*/
15-
public class LockManager<T extends AppLockActivity> {
15+
public class LockManager {
1616

1717
/**
1818
* The static singleton instance
1919
*/
20-
private static LockManager mInstance;
20+
private static final LockManager INSTANCE = new LockManager();
2121
/**
2222
* The static singleton instance of {@link com.github.orangegangsters.lollipin.lib.managers.AppLock}
2323
*/
@@ -27,19 +27,14 @@ public class LockManager<T extends AppLockActivity> {
2727
* Used to retrieve the static instance
2828
*/
2929
public static LockManager getInstance() {
30-
synchronized (LockManager.class) {
31-
if (mInstance == null) {
32-
mInstance = new LockManager<>();
33-
}
34-
}
35-
return mInstance;
30+
return INSTANCE;
3631
}
3732

3833
/**
3934
* You must call that into your custom {@link android.app.Application} to enable the
4035
* {@link com.github.orangegangsters.lollipin.lib.PinActivity}
4136
*/
42-
public void enableAppLock(Context context, Class<T> activityClass) {
37+
public void enableAppLock(Context context, Class<? extends AppLockActivity> activityClass) {
4338
if (mAppLocker != null) {
4439
mAppLocker.disable();
4540
}

lib/src/main/java/com/github/orangegangsters/lollipin/lib/storage/DefaultPreferencesCredentialStorage.java renamed to lib/src/main/java/com/github/orangegangsters/lollipin/lib/storage/DefaultPreferencesPasscodeDataStorage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import android.support.annotation.Nullable;
88

99
import com.github.orangegangsters.lollipin.lib.enums.Algorithm;
10-
import com.github.orangegangsters.lollipin.lib.interfaces.CredentialStorage;
10+
import com.github.orangegangsters.lollipin.lib.interfaces.PasscodeDataStorage;
1111

12-
public class DefaultPreferencesCredentialStorage implements CredentialStorage {
12+
public class DefaultPreferencesPasscodeDataStorage implements PasscodeDataStorage {
1313

1414
private static final String ATTEMPTS_COUNT_PREFERENCE_KEY = "ATTEMPTS_COUNT_PREFERENCE_KEY";
1515
/**
@@ -27,7 +27,7 @@ public class DefaultPreferencesCredentialStorage implements CredentialStorage {
2727

2828
private final SharedPreferences mPreferences;
2929

30-
public DefaultPreferencesCredentialStorage(Context context) {
30+
public DefaultPreferencesPasscodeDataStorage(Context context) {
3131
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
3232
}
3333

realm-storage/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

realm-storage/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'realm-android'
3+
4+
android {
5+
compileSdkVersion 26
6+
buildToolsVersion "26.0.1"
7+
8+
defaultConfig {
9+
minSdkVersion 14
10+
targetSdkVersion 26
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
compile fileTree(dir: 'libs', include: ['*.jar'])
25+
compile project(":lib")
26+
}

realm-storage/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Users\ahluh\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)