feat: add application password retention

This commit is contained in:
Andries Smit 2022-03-06 21:43:58 +01:00
parent f50881c1fc
commit 542aba6ea3
6 changed files with 21 additions and 2 deletions

View file

@ -168,7 +168,6 @@ class MainActivity : NoSplashAppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
protectionCheck.resetAuthorization()
if (!isProtectionCheckActive) { if (!isProtectionCheckActive) {
isProtectionCheckActive = true isProtectionCheckActive = true
protectionCheck.queryProtection(this, ProtectionCheck.Protection.APPLICATION, UIRunnable { isProtectionCheckActive = false }, protectionCheck.queryProtection(this, ProtectionCheck.Protection.APPLICATION, UIRunnable { isProtectionCheckActive = false },

View file

@ -6,6 +6,7 @@ import android.content.IntentFilter
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.wifi.WifiManager import android.net.wifi.WifiManager
import android.os.Build import android.os.Build
import androidx.lifecycle.ProcessLifecycleOwner
import com.uber.rxdogtag.RxDogTag import com.uber.rxdogtag.RxDogTag
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.DaggerApplication import dagger.android.DaggerApplication
@ -35,6 +36,7 @@ import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.ActivityMonitor import info.nightscout.androidaps.utils.ActivityMonitor
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.ProcessLifecycleListener
import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.locale.LocaleHelper
import info.nightscout.androidaps.utils.protection.PasswordCheck import info.nightscout.androidaps.utils.protection.PasswordCheck
@ -70,6 +72,7 @@ class MainApp : DaggerApplication() {
@Inject lateinit var passwordCheck: PasswordCheck @Inject lateinit var passwordCheck: PasswordCheck
@Inject lateinit var alarmSoundServiceHelper: AlarmSoundServiceHelper @Inject lateinit var alarmSoundServiceHelper: AlarmSoundServiceHelper
@Inject lateinit var notificationStore: NotificationStore @Inject lateinit var notificationStore: NotificationStore
@Inject lateinit var processLifecycleListener: ProcessLifecycleListener
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -77,6 +80,7 @@ class MainApp : DaggerApplication() {
RxDogTag.install() RxDogTag.install()
setRxErrorHandler() setRxErrorHandler()
LocaleHelper.update(this) LocaleHelper.update(this)
ProcessLifecycleOwner.get().lifecycle.addObserver(processLifecycleListener)
var gitRemote: String? = BuildConfig.REMOTE var gitRemote: String? = BuildConfig.REMOTE
var commitHash: String? = BuildConfig.HEAD var commitHash: String? = BuildConfig.HEAD

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.utils
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import javax.inject.Inject
class ProcessLifecycleListener @Inject constructor(private val protectionCheck: ProtectionCheck) : DefaultLifecycleObserver {
override fun onPause(owner: LifecycleOwner) {
protectionCheck.resetAuthorization()
}
}

View file

@ -86,6 +86,7 @@
android:inputType="number" android:inputType="number"
android:key="@string/key_protection_timeout" android:key="@string/key_protection_timeout"
android:title="@string/protection_timeout_title" android:title="@string/protection_timeout_title"
android:summary="@string/protection_timeout_summary"
app:defaultValue="0" app:defaultValue="0"
validate:maxNumber="180" validate:maxNumber="180"
validate:minNumber="0" validate:minNumber="0"

View file

@ -14,6 +14,7 @@ dependencies {
api "androidx.browser:browser:1.3.0" api "androidx.browser:browser:1.3.0"
api "androidx.activity:activity-ktx:${activity_version}" api "androidx.activity:activity-ktx:${activity_version}"
api "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" api "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
api "androidx.lifecycle:lifecycle-process:$lifecycle_version"
api 'androidx.cardview:cardview:1.0.0' api 'androidx.cardview:cardview:1.0.0'
api 'androidx.recyclerview:recyclerview:1.2.1' api 'androidx.recyclerview:recyclerview:1.2.1'
api 'androidx.gridlayout:gridlayout:1.0.0' api 'androidx.gridlayout:gridlayout:1.0.0'

View file

@ -12,7 +12,8 @@
<string name="application_pin">Application PIN</string> <string name="application_pin">Application PIN</string>
<string name="bolus_password">Bolus password</string> <string name="bolus_password">Bolus password</string>
<string name="bolus_pin">Bolus PIN</string> <string name="bolus_pin">Bolus PIN</string>
<string name="protection_timeout_title">Time before Bolus and Settings password / PIN expires (seconds)</string> <string name="protection_timeout_title">Password and PIN retention [s]</string>
<string name="protection_timeout_summary">Time before the password or PIN should be entered</string>
<string name="unlock_settings">Unlock settings</string> <string name="unlock_settings">Unlock settings</string>
<string name="biometric">Biometric</string> <string name="biometric">Biometric</string>
<string name="custom_password">Custom password</string> <string name="custom_password">Custom password</string>