Skip to content

Commit

Permalink
Add encrypted shared prefs config to properties
Browse files Browse the repository at this point in the history
- Remove encrypted shared prefs from SyncConfiguration
  • Loading branch information
qiarie committed Feb 2, 2021
1 parent aadfe4c commit 5bf7f75
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 26 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Dristhi](opensrp-app/res/drawable-mdpi/login_logo.png)](https://smartregister.atlassian.net/wiki/dashboard.action)


# Table of Contents
# Table of Contents

* [Introduction](#introduction)
* [Features](#features)
Expand Down Expand Up @@ -75,7 +75,7 @@ This section will provide a brief description on how to build and install the ap
* Install VirtualBox
* Download Genymotion & Install it
* Sign in to the genymotion app
* Create a new Genymotion Virtual Device
* Create a new Genymotion Virtual Device
* **Preferrable & Stable Choice** - API 22(Android 5.1.0), Screen size of around 800 X 1280, 1024 MB Memory --> eg. Google Nexus 7, Google Nexus 5

## How to install
Expand Down Expand Up @@ -173,7 +173,7 @@ This app provides the following networking capabilities:
Class | Represents
----- | --------------
`OpensrpSSLHelper` | SSL Connection helper
`OpenSRPImageLoader` | Asynchronous image downloder
`OpenSRPImageLoader` | Asynchronous image downloader
`HttpAgent` | Synchronous networking class with username\password ([Basic Auth](https://tools.ietf.org/html/rfc2617)) access support
`ConnectivityChangeReceiver` | Network status detection by a broadcast receiver
`GZipEncodingHttpClient` | GZip encoding and decoding capabilities
Expand Down Expand Up @@ -221,7 +221,7 @@ Class | Represents
`ServiceProvided` | It represents a service that was provided to a patient
`TimelineEvent` | It represents an event within a patient's life eg. birth

The domain object classes can be found in `org.smartregister.domain`. There are several domains namely: global domain, form and database domain.
The domain object classes can be found in `org.smartregister.domain`. There are several domains namely: global domain, form and database domain.


## 5. Sync
Expand All @@ -233,7 +233,7 @@ This app provides the following sync capabilities:

The sync classes can be found in `org.smartregister.sync`

## 6. Utitiles
## 6. Utilities

This app provides the following utilities:

Expand Down Expand Up @@ -304,7 +304,7 @@ You can quickly bootstrap view generation that take the format of a `Register` o
that implements basic register functionality such as searching, listing, sorting and counting number of records on the generic base view whilst reading a `cursor` object.

For views that display a generic List of items but require heavier customization, using the `org.smartregister.view.fragment.BaseListFragment<T>` allows you to render any generic list while providing a context
aware background executor and error handling that only requires provisioning or `Callable` function to act as a data source.
aware background executor and error handling that only requires provisioning or `Callable` function to act as a data source.
Check the Sample app's `ReportFragment` that consumes a `Retrofit` response and renders a list of objects.

## Configurability
Expand All @@ -318,3 +318,4 @@ By placing a file named `app.properties` in your implementation assets folder (S
| `system.toaster.centered` | Boolean | false | Position toaster(s) at the center of the view(s) |
| `disable.location.picker.view` | Boolean | false | Disables LocationPicker View |
| `location.picker.tag.shown` | Boolean | false | Hides/Shows the location tag in the location picker tree view |
| `encrypt.shared.preferences` | Boolean | false | Enable/disables encrypting SharedPreferences |
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public static class PROPERTY {
public static final String SYSTEM_TOASTER_CENTERED = "system.toaster.centered";
public static final String DISABLE_LOCATION_PICKER_VIEW = "disable.location.picker.view";
public static final String LOCATION_PICKER_TAG_SHOWN = "location.picker.tag.shown";

public static final String ENCRYPT_SHARED_PREFERENCES = "encrypt.shared.preferences";
}

public interface FORCED_LOGOUT {
Expand Down
5 changes: 1 addition & 4 deletions opensrp-app/src/main/java/org/smartregister/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,8 @@ public AllSharedPreferences allSharedPreferences() {
}

private SharedPreferences createSharedPreferences(android.content.Context context) {
SyncConfiguration syncConfiguration = CoreLibrary.getInstance().getSyncConfiguration();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& syncConfiguration != null
&& syncConfiguration.encryptSharedPreferences()) {
&& Utils.getBooleanProperty(AllConstants.PROPERTY.ENCRYPT_SHARED_PREFERENCES)) {

return createEncryptedSharedPreferences(context);
} else {
Expand Down
9 changes: 4 additions & 5 deletions opensrp-app/src/main/java/org/smartregister/CoreLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ private static void upgradeSharedPreferences() {
Map<String, ?> entries = existingPrefs.getAll();
existingPrefs.edit().clear().apply();

// check the version of SharedPreferences in place (encrypted vs unencrypted)
if (instance.getSyncConfiguration() != null
&& instance.getSyncConfiguration().encryptSharedPreferences()
&& !existingPrefs.contains(ENCRYPTED_PREFS_KEY_KEYSET)
&& !existingPrefs.contains(ENCRYPTED_PREFS_VALUE_KEYSET)) {
// check the version of SharedPreferences (encrypted vs unencrypted)
if (Utils.getBooleanProperty(AllConstants.PROPERTY.ENCRYPT_SHARED_PREFERENCES)
&& !entries.containsKey(ENCRYPTED_PREFS_KEY_KEYSET)
&& !entries.containsKey(ENCRYPTED_PREFS_VALUE_KEYSET)) {

// create the new instance
SharedPreferences newPrefs = instance.context().allSharedPreferences().getPreferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,4 @@ public int getMaxAuthenticationRetries() {
}

public abstract Class<? extends BaseLoginActivity> getAuthenticationActivity();

/**
* Configure whether the app should encrypt SharedPreferences
*
* @return true/false -- {@link Boolean}
*/
public boolean encryptSharedPreferences() {
return false;
}
}
3 changes: 2 additions & 1 deletion sample/src/main/assets/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ DRISHTI_BASE_URL=
PORT=-1
SHOULD_VERIFY_CERTIFICATE=false
SYNC_DOWNLOAD_BATCH_SIZE=10
system.toaster.centered=false
system.toaster.centered=false
encrypt.shared.preferences=false

0 comments on commit 5bf7f75

Please sign in to comment.