Merge pull request #143 from smuething/move-protection-to-core

Move protection to core
This commit is contained in:
bartsopers 2020-08-18 20:00:57 +02:00 committed by GitHub
commit 6c3e7a8f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 19 additions and 13 deletions

View file

@ -1383,7 +1383,6 @@
<string name="authorizationfailed">Authorization failed</string>
<string name="overview_show_absinsulin">Absolute insulin</string>
<string name="master_password_summary">Master password is used for backup encryption and to override security in application. Remember it or store on a safe place.</string>
<string name="passwords_dont_match">Passwords don\'t match</string>
<string name="current_master_password">Current master password</string>
<string name="statuslights">Status lights</string>
<string name="statuslights_copy_ns">Copy settings from NS</string>

View file

@ -44,6 +44,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.preference:preference-ktx:1.1.1"
implementation 'androidx.biometric:biometric:1.0.1'
implementation "androidx.activity:activity:${activityVersion}"
implementation "androidx.activity:activity-ktx:${activityVersion}"
implementation 'com.google.android.material:material:1.1.0'
@ -65,6 +66,9 @@ dependencies {
implementation "io.reactivex.rxjava2:rxandroid:${rxandroid_version}"
implementation 'org.apache.commons:commons-lang3:3.10'
//CryptoUtil
implementation 'com.madgag.spongycastle:core:1.58.0.0'
// Graphview cannot be upgraded
implementation "com.jjoe64:graphview:4.0.1"

View file

@ -3,7 +3,7 @@ package info.nightscout.androidaps.utils.protection
import androidx.biometric.BiometricConstants
import androidx.biometric.BiometricPrompt
import androidx.fragment.app.FragmentActivity
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.extensions.runOnUiThread
import java.util.concurrent.Executors

View file

@ -7,7 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.widget.EditText
import androidx.annotation.StringRes
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.CryptoUtil
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.AlertDialogHelper

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.utils.protection
import androidx.fragment.app.FragmentActivity
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
import javax.inject.Singleton
@ -42,10 +42,10 @@ class ProtectionCheck @Inject constructor(
fun isLocked(protection: Protection): Boolean {
return when (ProtectionType.values()[sp.getInt(protectionTypeResourceIDs[protection.ordinal], ProtectionType.NONE.ordinal)]) {
ProtectionType.NONE -> false
ProtectionType.BIOMETRIC -> true
ProtectionType.MASTER_PASSWORD -> sp.getString(R.string.key_master_password, "") != ""
ProtectionType.CUSTOM_PASSWORD -> sp.getString(passwordsResourceIDs[protection.ordinal], "") != ""
ProtectionType.NONE -> false
ProtectionType.BIOMETRIC -> true
ProtectionType.MASTER_PASSWORD -> sp.getString(R.string.key_master_password, "") != ""
ProtectionType.CUSTOM_PASSWORD -> sp.getString(passwordsResourceIDs[protection.ordinal], "") != ""
}
}
@ -53,13 +53,13 @@ class ProtectionCheck @Inject constructor(
fun queryProtection(activity: FragmentActivity, protection: Protection,
ok: Runnable?, cancel: Runnable? = null, fail: Runnable? = null) {
when (ProtectionType.values()[sp.getInt(protectionTypeResourceIDs[protection.ordinal], ProtectionType.NONE.ordinal)]) {
ProtectionType.NONE ->
ProtectionType.NONE ->
ok?.run()
ProtectionType.BIOMETRIC ->
ProtectionType.BIOMETRIC ->
BiometricCheck.biometricPrompt(activity, titleResourceIDs[protection.ordinal], ok, cancel, fail, passwordCheck)
ProtectionType.MASTER_PASSWORD ->
ProtectionType.MASTER_PASSWORD ->
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
ProtectionType.CUSTOM_PASSWORD ->
ProtectionType.CUSTOM_PASSWORD ->
passwordCheck.queryPassword(activity, titleResourceIDs[protection.ordinal], passwordsResourceIDs[protection.ordinal], { ok?.run() }, { cancel?.run() }, { fail?.run() })
}
}

View file

@ -127,6 +127,10 @@
<string name="shortminute">m</string>
<string name="shortday">d</string>
<!-- Protection-->
<string name="wrongpassword">Wrong password</string>
<string name="passwords_dont_match">Passwords don\'t match</string>
<!-- Profile-->
<string name="basalprofilenotaligned">Basal values not aligned to hours: %1$s</string>
<string name="minimalbasalvaluereplaced">Basal value replaced by minimal supported value: %1$s</string>

View file

@ -67,7 +67,6 @@
<string name="updatingbasalrates">Updating basal rates</string>
<string name="settingtempbasal">Setting temp basal</string>
<string name="waitingfortimesynchronization">Waiting for time synchronization (%1$d sec)</string>
<string name="wrongpassword">Wrong password</string>
<string name="wrongpumppassword">Wrong pump password!</string>
<string name="danar_history_alarm">Alarms</string>
<string name="danar_history_basalhours">Basal Hours</string>