diff --git a/.gitignore b/.gitignore
index 2f543dd..7419d78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,9 +12,6 @@
.idea/markdown-navigator.xml
.idea/modules.xml
-
-
-
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
@@ -27,6 +24,4 @@ build/
local.properties
# Intellij
-*.iml
-
-
+*.iml
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 495ab19..f39950d 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,11 @@ compile 'online.devliving:securedpreferencestore:latest_version'
```
## Usage
-Before you use the store it is imperative that you call `SecuredPreferenceStore.init(getApplicationContext());` before first use (perhaps in your `Application` or launch `Activity`) otherwise you will get an `IllegalStateException` thrown when trying to use the store.
+Before using the store for the first time you must initialize it
+```
+SecuredPreferenceStore.init(getApplicationContext(), new DefaultRecoveryHandler());
+```
+perhaps in `onCreate` of your `Application` class or launcher `Activity`.
You can use the secured preference store just like the way you use the default `SharedPreferences`
```java
@@ -92,4 +96,4 @@ A default recovery handler called `DefaultRecoveryHandler` is included in the li
See the License for the specific language governing permissions and
limitations under the License.
- Copyright 2016 Mehedi Hasan Khan
+ Copyright 2017 Mehedi Hasan Khan
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..9effd2c
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /Volumes/DataVolume/Work/SDK/Android/Development/adt-bundle/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/app/src/main/java/devliving/online/securedpreferencestoresample/MainActivity.java b/app/src/main/java/devliving/online/securedpreferencestoresample/MainActivity.java
index 1809f25..d1bf462 100644
--- a/app/src/main/java/devliving/online/securedpreferencestoresample/MainActivity.java
+++ b/app/src/main/java/devliving/online/securedpreferencestoresample/MainActivity.java
@@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
saveButton = (Button) findViewById(R.id.save);
try {
- SecuredPreferenceStore.init(getApplicationContext());
+ SecuredPreferenceStore.init(getApplicationContext(), new DefaultRecoveryHandler());
setupStore();
} catch (Exception e) {
@@ -89,7 +89,7 @@ protected boolean recover(Exception e, KeyStore keyStore, List keyAliase
}
void reloadData() {
- SecuredPreferenceStore prefStore = SecuredPreferenceStore.getSharedInstance(getApplicationContext());
+ SecuredPreferenceStore prefStore = SecuredPreferenceStore.getSharedInstance();
String textShort = prefStore.getString(TEXT_1, null);
String textLong = prefStore.getString(TEXT_2, null);
@@ -105,7 +105,7 @@ void reloadData() {
}
void saveData() {
- SecuredPreferenceStore prefStore = SecuredPreferenceStore.getSharedInstance(getApplicationContext());
+ SecuredPreferenceStore prefStore = SecuredPreferenceStore.getSharedInstance();
prefStore.edit().putString(TEXT_1, text1.length() > 0 ? text1.getText().toString() : null).apply();
prefStore.edit().putString(TEXT_2, text2.length() > 0 ? text2.getText().toString() : null).apply();
diff --git a/securedpreferencestore/build.gradle b/securedpreferencestore/build.gradle
index c6c939d..89e1e89 100644
--- a/securedpreferencestore/build.gradle
+++ b/securedpreferencestore/build.gradle
@@ -2,15 +2,15 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.jfrog.bintray"
-version = "0.4.1"
+version = "0.5.0"
android {
compileSdkVersion 25
- buildToolsVersion '25.0.2'
+ buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 18
targetSdkVersion 25
- versionCode 7
+ versionCode 8
versionName version
}
buildTypes {
diff --git a/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java b/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java
index 072e633..4228c4d 100644
--- a/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java
+++ b/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java
@@ -62,9 +62,8 @@ synchronized public static SecuredPreferenceStore getSharedInstance() {
}
/**
- * Must call this before using the store, otherwise the encryption manager will not be setup.
- * This method allows getSharedInstance() to be called without having to handle the exceptions each time.
- * Call this when first setting up the store in Application or your launching Activity and handle errors accordingly.
+ * Must be called once before using the SecuredPreferenceStore to initialize the shared instance.
+ * You may call it in @code{onCreate} method of your application class or launcher activity
*
* @throws IOException
* @throws CertificateException
@@ -78,10 +77,14 @@ synchronized public static SecuredPreferenceStore getSharedInstance() {
*/
public static void init( Context appContext,
RecoveryHandler recoveryHandler ) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableEntryException, InvalidAlgorithmParameterException, NoSuchPaddingException, InvalidKeyException, NoSuchProviderException {
- mRecoveryHandler = recoveryHandler;
- if ( mInstance == null ) {
- mInstance = new SecuredPreferenceStore(appContext);
+
+ if(mInstance != null){
+ Log.w("SECURED-PREFERENCE", "init called when there already is a non-null instance of the class");
+ return;
}
+
+ setRecoveryHandler(recoveryHandler);
+ mInstance = new SecuredPreferenceStore(appContext);
}
public EncryptionManager getEncryptionManager() {