Skip to content

Commit

Permalink
minor updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehedi authored and iamMehedi committed Aug 9, 2017
1 parent 76ecc34 commit cae5ce9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
.idea/markdown-navigator.xml
.idea/modules.xml




# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
Expand All @@ -27,6 +24,4 @@ build/
local.properties

# Intellij
*.iml


*.iml
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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 *;
#}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -89,7 +89,7 @@ protected boolean recover(Exception e, KeyStore keyStore, List<String> 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);
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions securedpreferencestore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit cae5ce9

Please sign in to comment.