aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill
diff options
context:
space:
mode:
authorAditya Wasan <adityawasan55@gmail.com>2020-07-01 00:00:02 +0530
committerGitHub <noreply@github.com>2020-07-01 00:00:02 +0530
commit82a9a6125473dbffa6a76f33c6ff83b4a1bd69b3 (patch)
tree965c887adfb0c5603f6e8f9dbcbd04d4d1011904 /app/src/main/java/com/zeapo/pwdstore/autofill
parente11ef1ca1d504bcccf73e75c3782cce2c8fc4bec (diff)
downloadHardenedPass-82a9a6125473dbffa6a76f33c6ff83b4a1bd69b3.tar.gz
HardenedPass-82a9a6125473dbffa6a76f33c6ff83b4a1bd69b3.zip
Use PreferenceKeys file to manage SharedPreferences keys. (#891)
* Use PreferenceKeys file to manage SharedPreferences keys. Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Use PreferenceKeys in all files Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Divide PreferenceKeys into multiple regions Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix build error Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Use PreferenceKeys in more files Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Reformat code Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix build error Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix merge issues Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt11
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillHelper.kt3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/PublicSuffixListCache.kt3
3 files changed, 10 insertions, 7 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
index a58bde69..177233a8 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
@@ -31,6 +31,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.model.PasswordEntry
import com.zeapo.pwdstore.utils.PasswordRepository
+import com.zeapo.pwdstore.utils.PreferenceKeys
import com.zeapo.pwdstore.utils.splitLines
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -228,7 +229,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
// if autofill_always checked, show dialog even if no matches (automatic
// or otherwise)
- if (items.isEmpty() && !settings!!.getBoolean("autofill_always", false)) {
+ if (items.isEmpty() && !settings!!.getBoolean(PreferenceKeys.AUTOFILL_ALWAYS, false)) {
return
}
showSelectPasswordDialog(packageName, appName, isWeb)
@@ -268,7 +269,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
var settingsURL = webViewURL
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
- val defValue = if (settings!!.getBoolean("autofill_default", true)) "/first" else "/never"
+ val defValue = if (settings!!.getBoolean(PreferenceKeys.AUTOFILL_DEFAULT, true)) "/first" else "/never"
val prefs: SharedPreferences = getSharedPreferences("autofill_web", Context.MODE_PRIVATE)
var preference: String
@@ -305,7 +306,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
private fun setAppMatchingPasswords(appName: String, packageName: String) {
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
- val defValue = if (settings!!.getBoolean("autofill_default", true)) "/first" else "/never"
+ val defValue = if (settings!!.getBoolean(PreferenceKeys.AUTOFILL_DEFAULT, true)) "/first" else "/never"
val prefs: SharedPreferences = getSharedPreferences("autofill", Context.MODE_PRIVATE)
val preference: String?
@@ -414,7 +415,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
// make it optional (or make height a setting for the same effect)
val itemNames = arrayOfNulls<CharSequence>(items.size + 2)
val passwordDirectory = PasswordRepository.getRepositoryDirectory(applicationContext).toString()
- val autofillFullPath = settings!!.getBoolean("autofill_full_path", false)
+ val autofillFullPath = settings!!.getBoolean(PreferenceKeys.AUTOFILL_FULL_PATH, false)
for (i in items.indices) {
if (autofillFullPath) {
itemNames[i] = items[i].path.replace(".gpg", "")
@@ -518,7 +519,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
// save password entry for pasting the username as well
if (entry?.hasUsername() == true) {
lastPassword = entry
- val ttl = Integer.parseInt(settings!!.getString("general_show_time", "45")!!)
+ val ttl = Integer.parseInt(settings!!.getString(PreferenceKeys.GENERAL_SHOW_TIME, "45")!!)
withContext(Dispatchers.Main) { Toast.makeText(applicationContext, getString(R.string.autofill_toast_username, ttl), Toast.LENGTH_LONG).show() }
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillHelper.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillHelper.kt
index 2a8443ba..838b7a05 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillHelper.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillHelper.kt
@@ -22,6 +22,7 @@ import com.github.ajalt.timberkt.e
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.model.PasswordEntry
import com.zeapo.pwdstore.utils.PasswordRepository
+import com.zeapo.pwdstore.utils.PreferenceKeys
import java.io.File
import java.security.MessageDigest
@@ -39,7 +40,7 @@ private fun ByteArray.base64(): String {
private fun Context.getDefaultUsername(): String? {
return PreferenceManager
.getDefaultSharedPreferences(this)
- .getString("oreo_autofill_default_username", null)
+ .getString(PreferenceKeys.OREO_AUTOFILL_DEFAULT_USERNAME, null)
}
private fun stableHash(array: Collection<ByteArray>): String {
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/PublicSuffixListCache.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/PublicSuffixListCache.kt
index f1ce6bce..349f0a1b 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/PublicSuffixListCache.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/PublicSuffixListCache.kt
@@ -7,6 +7,7 @@ package com.zeapo.pwdstore.autofill.oreo
import android.content.Context
import android.util.Patterns
import androidx.preference.PreferenceManager
+import com.zeapo.pwdstore.utils.PreferenceKeys
import kotlinx.coroutines.runBlocking
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
@@ -67,7 +68,7 @@ fun getSuffixPlusUpToOne(domain: String, suffix: String): String? {
fun getCustomSuffixes(context: Context): Sequence<String> {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
- return prefs.getString("oreo_autofill_custom_public_suffixes", "")!!
+ return prefs.getString(PreferenceKeys.OREO_AUTOFILL_CUSTOM_PUBLIC_SUFFIXES, "")!!
.splitToSequence('\n')
.filter { it.isNotBlank() && it.first() != '.' && it.last() != '.' }
}