Skip to content

Commit

Permalink
Merge branch 'release-2.5.9'
Browse files Browse the repository at this point in the history
* release-2.5.9: (24 commits)
  Update versionCode and versionName
  Update translations from POEditor
  Add Russian translation from POEditor
  Fix incorrect hourly schedules for the second day day after schedule creation
  Allow hourly repetition schedules every 5 and 10 hours
  Update gradle plugin and kotlin versions to 3.2.1 and 1.2.71
  CI: use api 28 image to avoid re-download of build-tools
  Add 5 min delay option
  ids.xml: Remove inner values
  Update Gradle plugin and Gradle versions to 3.2.0 and 4.6
  build.gradle: Make global buildscript dependency versions ext variables
  build.gradle: Update Kotlin version to 1.2.70
  build.gradle: substitute library version repetitions for ext variables
  build.gradle: Don't specify buildToolsVersion
  build: use 'implementation' instead of 'compile' for secure preference dependency
  PreferenceUtils: add missing apply()
  Initialize default preferences on application startup
  Add secure window preference
  EncryptionProvider: ditch GSON serialization for simpler base64 encoding
  Refactor security classes
  ...
  • Loading branch information
AlvaroBrey committed Oct 17, 2018
2 parents 0bca126 + d342e78 commit 55e9660
Show file tree
Hide file tree
Showing 30 changed files with 1,041 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: circleci/android:api-27-alpha
image: circleci/android:api-28-alpha

before_script:
- export GRADLE_USER_HOME="$(pwd)/.gradle"
Expand Down
42 changes: 22 additions & 20 deletions Calendula/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ task copyTestClasses(type: Copy) {

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 16
minSdkVersion 18
targetSdkVersion 26
versionCode 39
versionName "2.5.8"
versionCode 40
versionName "2.5.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
applicationId "es.usc.citius.servando.calendula"
multiDexEnabled true
Expand Down Expand Up @@ -174,12 +173,12 @@ dependencies {

// Memory leak debugging
// 1.5.2 held back because of a bug with gradle 3.0
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
alphaImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
betaImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
androidTestImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$libVersions.leakcanary"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$libVersions.leakcanary"
alphaImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$libVersions.leakcanary"
betaImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$libVersions.leakcanary"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$libVersions.leakcanary"
androidTestImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$libVersions.leakcanary"

/********** SUPPORT **********/
// Multidex support
Expand Down Expand Up @@ -210,18 +209,18 @@ dependencies {
testImplementation 'junit:junit:4.12'

// Mockito
testImplementation "org.mockito:mockito-inline:2.13.0"
androidTestImplementation "org.mockito:mockito-android:2.13.0"
testImplementation "org.mockito:mockito-inline:$libVersions.mockito"
androidTestImplementation "org.mockito:mockito-android:$libVersions.mockito"

// Support testing
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$libVersions.android.espresso"
androidTestImplementation "com.android.support.test.espresso:espresso-core:$libVersions.android.espresso"
androidTestImplementation "com.android.support.test:rules:$libVersions.android.test"
androidTestImplementation "com.android.support.test:runner:$libVersions.android.test"

// Roboelectric
testImplementation "org.robolectric:robolectric:3.8"
testImplementation "org.robolectric:shadows-multidex:3.8"
testImplementation "org.robolectric:robolectric:$libVersions.robolectric"
testImplementation "org.robolectric:shadows-multidex:$libVersions.robolectric"

/********** UTILITIES **********/
// HTML parsing
Expand Down Expand Up @@ -256,8 +255,8 @@ dependencies {
implementation 'joda-time:joda-time:2.9.7'

// View/resource binding
kapt 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.jakewharton:butterknife:8.8.1'
kapt "com.jakewharton:butterknife-compiler:$libVersions.butterknife"
implementation "com.jakewharton:butterknife:$libVersions.butterknife"

/********** VIEWS AND VIEW UTILITIES **********/
// About page with libraries
Expand Down Expand Up @@ -317,6 +316,9 @@ dependencies {
implementation 'com.mikepenz:fastadapter-extensions:2.1.0@aar'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// Secured preferences
implementation 'online.devliving:securedpreferencestore:0.7.3'


}

4 changes: 3 additions & 1 deletion Calendula/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.usc.citius.servando.calendula">
package="es.usc.citius.servando.calendula"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
Expand All @@ -37,6 +38,7 @@
<application
android:name=".CalendulaApp"
android:allowBackup="true"
tools:replace="allowBackup"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.WindowManager;

import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;
Expand All @@ -45,6 +47,8 @@
import es.usc.citius.servando.calendula.pinlock.UnlockStateManager;
import es.usc.citius.servando.calendula.util.LogUtil;
import es.usc.citius.servando.calendula.util.PermissionUtils;
import es.usc.citius.servando.calendula.util.PreferenceKeys;
import es.usc.citius.servando.calendula.util.PreferenceUtils;
import es.usc.citius.servando.calendula.util.ScreenUtils;


Expand All @@ -65,6 +69,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set FLAG secure if the secure_window preference is enabled
if (PreferenceUtils.getBoolean(PreferenceKeys.SECURE_WINDOW, false)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
}
}

protected CalendulaActivity setupToolbar(@Nullable String title, @ColorInt int color, @ColorInt int iconColor) {
// set up the toolbar
toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

public void showDelayDialog() {
//TODO allow custom delay values
final int[] values = this.getResources().getIntArray(R.array.delays_array_values);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.notification_delay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ public void createSchedule(final Schedule s, List<ScheduleItem> items, Medicine
DailyAgenda.instance().addItem(patient, item, false);
}
} else {
for (DateTime time : s.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(patient, s, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(patient, s);
}
// save and fire event
DB.schedules().saveAndFireEvent(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import com.j256.ormlite.misc.TransactionManager;

import org.greenrobot.eventbus.Subscribe;
import org.joda.time.DateTime;
import org.joda.time.LocalTime;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -125,10 +123,7 @@ public Object call() throws Exception {
DailyAgenda.instance().addItem(patient, item, false);
}
} else {
for (DateTime time : s.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(patient, s, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(patient, s);
}
// save and fire event
DB.schedules().saveAndFireEvent(s);
Expand Down Expand Up @@ -193,10 +188,7 @@ public Object call() throws Exception {
}
} else {
DB.dailyScheduleItems().removeAllFrom(s);
for (DateTime time : s.hourlyItemsToday()) {
LocalTime timeToday = time.toLocalTime();
DailyAgenda.instance().addItem(patient, s, timeToday);
}
DailyAgenda.instance().generateItemsForHourlySchedule(patient, s);
}

// save and fire event
Expand All @@ -216,6 +208,7 @@ public Object call() throws Exception {
}
}


public void saveSchedule() {

if (!validateBeforeSave()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package es.usc.citius.servando.calendula.fragments;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.ContextWrapper;
Expand Down Expand Up @@ -337,7 +338,7 @@ void setupStartEndDatePickers(View rootView) {
@Override
public Resources getResources() {
Resources r = super.getResources();
if(wrappedResources == null) {
if (wrappedResources == null) {
wrappedResources = new Resources(r.getAssets(), r.getDisplayMetrics(), r.getConfiguration()) {
@NonNull
@Override
Expand Down Expand Up @@ -546,27 +547,22 @@ void showIntervalPickerDIalog() {
}

void showHourlyPickerDIalog() {
/*NumberPickerBuilder npb =
new NumberPickerBuilder().setDecimalVisibility(NumberPicker.INVISIBLE)
.setMinNumber(1)
.setMaxNumber(24)
.setPlusMinusVisibility(NumberPicker.INVISIBLE)
.setFragmentManager(getActivity().getSupportFragmentManager())
.setTargetFragment(this)
.setReference(REF_DIALOG_HOURLY_INTERVAL)
.setStyleResId(R.style.BetterPickersDialogFragment_Calendula);
npb.show();*/

AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setTitle(getString(R.string.dialog_interval_title));
final String[] types = {"2", "3", "4", "6", "8", "12"};
b.setItems(types, new DialogInterface.OnClickListener() {

final int[] hourlyRepValues = getContext().getResources().getIntArray(R.array.hourly_repetition_values);
// final String[] hourlyRepDisplay = getContext().getResources().getStringArray(R.array.hourly_repetition_display);

b.setItems(R.array.hourly_repetition_display, new DialogInterface.OnClickListener() {

@SuppressLint("SetTextI18n")
//the int is put into a button with just the value, no need for localization
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
int result = Integer.valueOf(types[which]);
hourlyIntervalEditText.setText("" + result);
final int result = hourlyRepValues[which];
hourlyIntervalEditText.setText(Integer.toString(result));
schedule.rule().setFrequency(Frequency.HOURLY);
schedule.rule().setInterval(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import com.evernote.android.job.JobManager;
import com.mikepenz.iconics.Iconics;
Expand All @@ -47,6 +48,8 @@
import es.usc.citius.servando.calendula.util.PreferenceKeys;
import es.usc.citius.servando.calendula.util.PreferenceUtils;
import es.usc.citius.servando.calendula.util.PresentationsTypeface;
import es.usc.citius.servando.calendula.util.security.SecuredVault;
import es.usc.citius.servando.calendula.util.security.SecurityProvider;


public class BaseModule extends CalendulaModule {
Expand Down Expand Up @@ -95,6 +98,11 @@ public void setupUpdateDailyAgendaAlarm(Context ctx) {
protected void onApplicationStartup(Context ctx) {
PreferenceUtils.init(ctx);

// initialize secured vault
if (!Build.FINGERPRINT.equals("robolectric")) {
SecurityProvider.init(ctx);
}

// initialize SQLite engine
initializeDatabase(ctx);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Calendula - An assistant for personal medication management.
* Copyright (C) 2016 CITIUS - USC
*
* Calendula is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/

package es.usc.citius.servando.calendula.persistence.typeSerializers;

import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.field.types.BaseDataType;
import com.j256.ormlite.support.DatabaseResults;

import java.nio.charset.Charset;
import java.sql.SQLException;

import es.usc.citius.servando.calendula.util.security.SecurityProvider;

public class SecureStringPersister extends BaseDataType {

private static final SecureStringPersister singleton = new SecureStringPersister();
private static Charset UTF8 = Charset.forName("UTF-8");

public SecureStringPersister() {
super(SqlType.STRING, new Class<?>[]{String.class});
}

public static SecureStringPersister getSingleton() {
return singleton;
}

@Override
public Object parseDefaultString(FieldType fieldType, String defaultStr) throws SQLException {
return defaultStr;
}

@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
return results.getString(columnPos);
}

@Override
public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) throws SQLException {
if (sqlArg == null) {
return null;
}
if (((String) sqlArg).isEmpty()) {
return "";
}
return SecurityProvider.getEncryptionProvider().decrypt((String) sqlArg);
}

@Override
public Object javaToSqlArg(FieldType fieldType, Object javaObject) throws SQLException {
if (javaObject == null) {
return null;
}
if (((String) javaObject).isEmpty()) {
return "";
}
return SecurityProvider.getEncryptionProvider().encrypt((String) javaObject);
}
}
Loading

0 comments on commit 55e9660

Please sign in to comment.