aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-04-16 12:20:45 +0200
committerGitHub <noreply@github.com>2020-04-16 12:20:45 +0200
commite4aa673537f198034755ed1113754fbbe05b0138 (patch)
treeb2f6ca4f45dc02259b0a39cfab9ffdf2f61adc74 /app/src/main/java/com/zeapo/pwdstore/autofill
parent2a6326ec0ea04ceade7e56749b4cd09f810a34a7 (diff)
downloadHardenedPass-e4aa673537f198034755ed1113754fbbe05b0138.tar.gz
HardenedPass-e4aa673537f198034755ed1113754fbbe05b0138.zip
Reduce build warnings (#712)
* Add annotations to and reformat SearchableRepositoryViewModel.kt * Address build warnings other than meaningful deprecations * Deal with warnings in UserPreference.kt
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt11
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillHelper.kt7
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillStrategy.kt2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillDecryptActivity.kt2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt2
7 files changed, 23 insertions, 8 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt
index 934c5395..c3186db5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt
@@ -47,20 +47,23 @@ class AutofillActivity : AppCompatActivity() {
finish() // go back to the password field app
when (requestCode) {
REQUEST_CODE_DECRYPT_AND_VERIFY -> if (resultCode == RESULT_OK) {
- AutofillService.instance?.setResultData(data!!) // report the result to service
+ require(data != null)
+ AutofillService.instance?.setResultData(data) // report the result to service
}
REQUEST_CODE_PICK -> if (resultCode == RESULT_OK) {
- AutofillService.instance?.setPickedPassword(data!!.getStringExtra("path"))
+ require(data != null)
+ AutofillService.instance?.setPickedPassword(data.getStringExtra("path")!!)
}
REQUEST_CODE_PICK_MATCH_WITH -> if (resultCode == RESULT_OK) {
+ require(data != null)
// need to not only decrypt the picked password, but also
// update the "match with" preference
val extras = intent.extras ?: return
val packageName = extras.getString("packageName")
val isWeb = extras.getBoolean("isWeb")
- val path = data!!.getStringExtra("path")
- AutofillService.instance?.setPickedPassword(data.getStringExtra("path"))
+ val path = data.getStringExtra("path")
+ AutofillService.instance?.setPickedPassword(data.getStringExtra("path")!!)
val prefs: SharedPreferences
prefs = if (!isWeb) {
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
index a958fbe8..a2d82097 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
@@ -66,7 +66,9 @@ class AutofillFragment : DialogFragment() {
?: "com.android.browser")
}
try {
- builder.setIcon(callingActivity.packageManager.getApplicationIcon(iconPackageName))
+ if (iconPackageName != null) {
+ builder.setIcon(callingActivity.packageManager.getApplicationIcon(iconPackageName))
+ }
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
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 47822e0f..59077ac8 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
@@ -4,6 +4,7 @@
*/
package com.zeapo.pwdstore.autofill.oreo
+import android.annotation.SuppressLint
import android.app.assist.AssistStructure
import android.content.Context
import android.content.IntentSender
@@ -47,6 +48,12 @@ private fun stableHash(array: Collection<ByteArray>): String {
* returns all of them in sorted order and separated with `;`.
*/
fun computeCertificatesHash(context: Context, appPackage: String): String {
+ // The warning does not apply since 1) we are specifically hashing **all** signatures and 2) it
+ // no longer applies to Android 4.4+.
+ // Even though there is a new way to get the certificates as of Android Pie, we need to keep
+ // hashes comparable between versions and hence default to using the deprecated API.
+ @SuppressLint("PackageManagerGetSignatures")
+ @Suppress("DEPRECATION")
val signaturesOld =
context.packageManager.getPackageInfo(appPackage, PackageManager.GET_SIGNATURES).signatures
val stableHashOld = stableHash(signaturesOld.map { it.toByteArray() })
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt
index e6e16ef0..d300090c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt
@@ -157,6 +157,9 @@ class AutofillMatcher {
for (prefs in listOf(context.autofillAppMatches, context.autofillWebMatches)) {
for ((key, value) in prefs.all) {
if (!key.startsWith(PREFERENCE_PREFIX_MATCHES)) continue
+ // We know that preferences starting with `PREFERENCE_PREFIX_MATCHES` were
+ // created with `putStringSet`.
+ @Suppress("UNCHECKED_CAST")
val oldMatches = value as? Set<String>
if (oldMatches == null) {
w { "Failed to read matches for $key" }
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillStrategy.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillStrategy.kt
index 07a38862..6f3b4ff5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillStrategy.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillStrategy.kt
@@ -60,7 +60,7 @@ val autofillStrategy = strategy {
}
}
currentPassword {
- takeSingle { alreadyMatched ->
+ takeSingle { _ ->
hasAutocompleteHintCurrentPassword && isFocused
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillDecryptActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillDecryptActivity.kt
index 2c44ee42..35b1eee9 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillDecryptActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillDecryptActivity.kt
@@ -188,7 +188,7 @@ class AutofillDecryptActivity : Activity(), CoroutineScope {
}
OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> {
val pendingIntent: PendingIntent =
- result.getParcelableExtra(OpenPgpApi.RESULT_INTENT)
+ result.getParcelableExtra(OpenPgpApi.RESULT_INTENT)!!
try {
val intentToResume = withContext(Dispatchers.Main) {
suspendCoroutine<Intent> { cont ->
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt
index 384bcad5..209892a7 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt
@@ -101,7 +101,7 @@ class AutofillSaveActivity : Activity() {
putExtras(
bundleOf(
"REPO_PATH" to repo.absolutePath,
- "FILE_PATH" to repo.resolve(intent.getStringExtra(EXTRA_FOLDER_NAME)).absolutePath,
+ "FILE_PATH" to repo.resolve(intent.getStringExtra(EXTRA_FOLDER_NAME)!!).absolutePath,
"OPERATION" to "ENCRYPT",
"SUGGESTED_NAME" to intent.getStringExtra(EXTRA_NAME),
"SUGGESTED_PASS" to intent.getStringExtra(EXTRA_PASSWORD),