aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-05-01 16:41:52 -0700
committerAllan Wang <me@allanwang.ca>2019-05-01 16:41:52 -0700
commit984a4a7bf1d08c0d3143ea6d3ea637d7e674f0c2 (patch)
tree1eaddf006bef618f134bf197762896d21267e952 /app/src/main/kotlin/com
parent58f4f9298b09081b3c937227828824849057a835 (diff)
downloadfrost-984a4a7bf1d08c0d3143ea6d3ea637d7e674f0c2.tar.gz
frost-984a4a7bf1d08c0d3143ea6d3ea637d7e674f0c2.tar.bz2
frost-984a4a7bf1d08c0d3143ea6d3ea637d7e674f0c2.zip
Add security settings for biometrics
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt45
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt11
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt2
6 files changed, 63 insertions, 5 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
index c3089c7a..bc20aa2d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
@@ -45,6 +45,7 @@ import com.pitchedapps.frost.settings.getDebugPrefs
import com.pitchedapps.frost.settings.getExperimentalPrefs
import com.pitchedapps.frost.settings.getFeedPrefs
import com.pitchedapps.frost.settings.getNotificationPrefs
+import com.pitchedapps.frost.settings.getSecurityPrefs
import com.pitchedapps.frost.settings.sendDebug
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
@@ -146,6 +147,11 @@ class SettingsActivity : KPrefActivity() {
iicon = GoogleMaterial.Icon.gmd_notifications
}
+ subItems(R.string.security, getSecurityPrefs()) {
+ descRes = R.string.security_desc
+ iicon = GoogleMaterial.Icon.gmd_lock
+ }
+
// subItems(R.string.network, getNetworkPrefs()) {
// descRes = R.string.network_desc
// iicon = GoogleMaterial.Icon.gmd_network_cell
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
index e0ae6de5..1ee06464 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
@@ -52,7 +52,7 @@ import java.io.File
*/
fun SettingsActivity.getDebugPrefs(): KPrefAdapterBuilder.() -> Unit = {
- plainText(R.string.experimental_disclaimer) {
+ plainText(R.string.disclaimer) {
descRes = R.string.debug_disclaimer_info
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt
index e0d314a8..41a60594 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt
@@ -30,7 +30,7 @@ import com.pitchedapps.frost.utils.Showcase
*/
fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = {
- plainText(R.string.experimental_disclaimer) {
+ plainText(R.string.disclaimer) {
descRes = R.string.experimental_disclaimer_info
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt
new file mode 100644
index 00000000..afd7c4e1
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.pitchedapps.frost.settings
+
+import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
+import com.pitchedapps.frost.R
+import com.pitchedapps.frost.activities.SettingsActivity
+import com.pitchedapps.frost.utils.BiometricUtils
+import com.pitchedapps.frost.utils.Prefs
+import kotlinx.coroutines.launch
+
+/**
+ * Created by Allan Wang on 20179-05-01.
+ */
+fun SettingsActivity.getSecurityPrefs(): KPrefAdapterBuilder.() -> Unit = {
+
+ plainText(R.string.disclaimer) {
+ descRes = R.string.security_disclaimer_info
+ }
+
+ checkbox(R.string.enable_biometrics, Prefs::biometricsEnabled, {
+ launch {
+ BiometricUtils.authenticate(this@getSecurityPrefs, force = true).await()
+ Prefs.biometricsEnabled = it
+ reloadByTitle(R.string.enable_biometrics)
+ }
+ }) {
+ descRes = R.string.enable_biometrics_desc
+ enabler = { BiometricUtils.isSupported(this@getSecurityPrefs) }
+ }
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt
index 476e490d..9a9f4082 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt
@@ -26,6 +26,10 @@ object BiometricUtils {
@Volatile
private var pool: ExecutorService? = null
+ private var lastUnlockTime = -1L
+
+ private const val UNLOCK_TIME_INTERVAL = 15 * 60 * 1000
+
/**
* Checks if biometric authentication is possible
* Currently, this means checking for enrolled fingerprints
@@ -41,12 +45,12 @@ object BiometricUtils {
pool ?: Executors.newSingleThreadExecutor().also { pool = it }
private fun shouldPrompt(context: Context): Boolean {
- return true
+ return Prefs.biometricsEnabled && System.currentTimeMillis() - lastUnlockTime > UNLOCK_TIME_INTERVAL
}
- fun authenticate(activity: FragmentActivity): BiometricDeferred {
+ fun authenticate(activity: FragmentActivity, force: Boolean = false): BiometricDeferred {
val deferred: BiometricDeferred = CompletableDeferred()
- if (!shouldPrompt(activity)) {
+ if (!force && !shouldPrompt(activity)) {
deferred.complete(null)
return deferred
}
@@ -66,6 +70,7 @@ object BiometricUtils {
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
+ lastUnlockTime = System.currentTimeMillis()
deferred.complete(result.cryptoObject)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
index 391d422a..7656a081 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -156,6 +156,8 @@ object Prefs : KPref() {
var analytics: Boolean by kpref("analytics", true)
+ var biometricsEnabled: Boolean by kpref("biometrics_enabled", false)
+
var overlayEnabled: Boolean by kpref("overlay_enabled", true)
var overlayFullScreenSwipe: Boolean by kpref("overlay_full_screen_swipe", true)