aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-07-03 12:54:06 +0530
committerGitHub <noreply@github.com>2020-07-03 09:24:06 +0200
commit25b426157417c97c61c3d2cc0d9fa556f337f22d (patch)
treef53331d7ee2d5b780ebf20a6ccdded53bda42005 /app/src/main/java/com/zeapo/pwdstore/autofill
parentff3d2fcce3f1d74bdb1e13e3634f1ea9a9f9f1e5 (diff)
downloadHardenedPass-25b426157417c97c61c3d2cc0d9fa556f337f22d.tar.gz
HardenedPass-25b426157417c97c61c3d2cc0d9fa556f337f22d.zip
Migrate to ActivityResultContracts (#910)
* Move git directory selection to ActivityResultContracts Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * global: replace all android.app.Activity references Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * res: resolve ObsoleteSdkInt lint warning Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * layout: silence some overdraw warnings Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * PasswordFragment: address deprecation Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * PasswordStore: start addressing deprecation warnings Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * autofill: silence deprecation warnings for legacy implementation I don't want to ever touch these files Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Reset scrollTarget after use Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Refresh password list after each swipe Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Convert if to when Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Migrate UserPreference to ActivityResultContracts Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Also validate result in git directory selection Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * AutofillSaveActivity: Switch to ActivityResultContracts Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * AutofillDecryptActivity: Switch to ActivityResultContracts Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * AutofillFilterActivity: Switch to ActivityResultContracts Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Improve deletion flow - Silently delete empty directory - Always refresh password list upon completion Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Uniform naming for activity result handlers Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: Fabian Henneke <FabianHenneke@users.noreply.github.com>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillDecryptActivity.kt38
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt25
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt86
8 files changed, 71 insertions, 83 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 87881968..a64cdced 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.kt
@@ -2,6 +2,7 @@
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
+@file:Suppress("Deprecation")
package com.zeapo.pwdstore.autofill
import android.app.PendingIntent
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 2410d53e..269e6624 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
@@ -2,6 +2,7 @@
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
+@file:Suppress("Deprecation")
package com.zeapo.pwdstore.autofill
import android.annotation.SuppressLint
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt
index 860d8459..e8bf5537 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.kt
@@ -2,6 +2,7 @@
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
+@file:Suppress("Deprecation")
package com.zeapo.pwdstore.autofill
import android.content.Context
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt
index 811ff7af..5752b055 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt
@@ -2,6 +2,7 @@
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
+@file:Suppress("Deprecation")
package com.zeapo.pwdstore.autofill
import android.content.Context
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 177233a8..bfb1c5d0 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
@@ -2,6 +2,7 @@
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
+@file:Suppress("Deprecation")
package com.zeapo.pwdstore.autofill
import android.accessibilityservice.AccessibilityService
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 d7d8daaf..c5e47544 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
@@ -4,7 +4,6 @@
*/
package com.zeapo.pwdstore.autofill.oreo.ui
-import android.app.Activity
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
@@ -13,7 +12,10 @@ import android.os.Build
import android.os.Bundle
import android.view.autofill.AutofillManager
import android.widget.Toast
+import androidx.activity.result.IntentSenderRequest
+import androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult
import androidx.annotation.RequiresApi
+import androidx.appcompat.app.AppCompatActivity
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.e
import com.zeapo.pwdstore.autofill.oreo.AutofillAction
@@ -44,13 +46,12 @@ import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
@RequiresApi(Build.VERSION_CODES.O)
-class AutofillDecryptActivity : Activity(), CoroutineScope {
+class AutofillDecryptActivity : AppCompatActivity(), CoroutineScope {
companion object {
private const val EXTRA_FILE_PATH = "com.zeapo.pwdstore.autofill.oreo.EXTRA_FILE_PATH"
private const val EXTRA_SEARCH_ACTION =
"com.zeapo.pwdstore.autofill.oreo.EXTRA_SEARCH_ACTION"
- private const val REQUEST_CODE_CONTINUE_AFTER_USER_INTERACTION = 1
private const val OPENPGP_PROVIDER = "org.sufficientlysecure.keychain"
private var decryptFileRequestCode = 1
@@ -194,14 +195,17 @@ class AutofillDecryptActivity : Activity(), CoroutineScope {
val intentToResume = withContext(Dispatchers.Main) {
suspendCoroutine<Intent> { cont ->
continueAfterUserInteraction = cont
- startIntentSenderForResult(
- pendingIntent.intentSender,
- REQUEST_CODE_CONTINUE_AFTER_USER_INTERACTION,
- null,
- 0,
- 0,
- 0
- )
+ registerForActivityResult(StartIntentSenderForResult()) { result ->
+ if (continueAfterUserInteraction != null) {
+ val data = result.data
+ if (resultCode == RESULT_OK && data != null) {
+ continueAfterUserInteraction?.resume(data)
+ } else {
+ continueAfterUserInteraction?.resumeWithException(Exception("OpenPgpApi ACTION_DECRYPT_VERIFY failed to continue after user interaction"))
+ }
+ continueAfterUserInteraction = null
+ }
+ }.launch(IntentSenderRequest.Builder(pendingIntent.intentSender).build())
}
}
decryptCredential(file, intentToResume)
@@ -230,16 +234,4 @@ class AutofillDecryptActivity : Activity(), CoroutineScope {
}
}
}
-
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- super.onActivityResult(requestCode, resultCode, data)
- if (requestCode == REQUEST_CODE_CONTINUE_AFTER_USER_INTERACTION && continueAfterUserInteraction != null) {
- if (resultCode == RESULT_OK && data != null) {
- continueAfterUserInteraction?.resume(data)
- } else {
- continueAfterUserInteraction?.resumeWithException(Exception("OpenPgpApi ACTION_DECRYPT_VERIFY failed to continue after user interaction"))
- }
- continueAfterUserInteraction = null
- }
- }
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt
index 1a969b51..7467b9c9 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt
@@ -14,6 +14,7 @@ import android.os.Bundle
import android.view.View
import android.view.autofill.AutofillManager
import android.widget.TextView
+import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.bold
@@ -44,7 +45,6 @@ class AutofillFilterView : AppCompatActivity() {
companion object {
private const val HEIGHT_PERCENTAGE = 0.9
private const val WIDTH_PERCENTAGE = 0.75
- private const val DECRYPT_FILL_REQUEST_CODE = 1
private const val EXTRA_FORM_ORIGIN_WEB =
"com.zeapo.pwdstore.autofill.oreo.ui.EXTRA_FORM_ORIGIN_WEB"
@@ -197,20 +197,15 @@ class AutofillFilterView : AppCompatActivity() {
item.file
)
// intent?.extras? is checked to be non-null in onCreate
- startActivityForResult(
- AutofillDecryptActivity.makeDecryptFileIntent(
- item.file,
- intent!!.extras!!,
- this
- ), DECRYPT_FILL_REQUEST_CODE
- )
- }
-
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- super.onActivityResult(requestCode, resultCode, data)
- if (requestCode == DECRYPT_FILL_REQUEST_CODE) {
- if (resultCode == RESULT_OK) setResult(RESULT_OK, data)
+ registerForActivityResult(StartActivityForResult()) { result ->
+ if (result.resultCode == RESULT_OK) {
+ setResult(RESULT_OK, result.data)
+ }
finish()
- }
+ }.launch(AutofillDecryptActivity.makeDecryptFileIntent(
+ item.file,
+ intent!!.extras!!,
+ this
+ ))
}
}
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 b5bd9e38..87359333 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
@@ -4,7 +4,6 @@
*/
package com.zeapo.pwdstore.autofill.oreo.ui
-import android.app.Activity
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
@@ -12,10 +11,11 @@ import android.content.IntentSender
import android.os.Build
import android.os.Bundle
import android.view.autofill.AutofillManager
+import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.annotation.RequiresApi
+import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import com.github.ajalt.timberkt.e
-import com.zeapo.pwdstore.PasswordStore
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.autofill.oreo.AutofillAction
import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
@@ -29,7 +29,7 @@ import com.zeapo.pwdstore.utils.commitChange
import java.io.File
@RequiresApi(Build.VERSION_CODES.O)
-class AutofillSaveActivity : Activity() {
+class AutofillSaveActivity : AppCompatActivity() {
companion object {
private const val EXTRA_FOLDER_NAME =
@@ -109,50 +109,46 @@ class AutofillSaveActivity : Activity() {
)
)
}
- startActivityForResult(saveIntent, PasswordStore.REQUEST_CODE_ENCRYPT)
- }
-
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- super.onActivityResult(requestCode, resultCode, data)
- if (requestCode == PasswordStore.REQUEST_CODE_ENCRYPT && resultCode == RESULT_OK && data != null) {
- val createdPath = data.getStringExtra("CREATED_FILE")!!
- formOrigin?.let {
- AutofillMatcher.addMatchFor(this, it, File(createdPath))
- }
- val longName = data.getStringExtra("LONG_NAME")!!
- val password = data.getStringExtra("PASSWORD")
- val result = if (password != null) {
- // Password was generated and should be filled into a form.
- val username = data.getStringExtra("USERNAME")
- val clientState =
- intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run {
- e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
- finish()
- return
+ registerForActivityResult(StartActivityForResult()) { result ->
+ val data = result.data
+ if (result.resultCode == RESULT_OK && data != null) {
+ val createdPath = data.getStringExtra("CREATED_FILE")!!
+ formOrigin?.let {
+ AutofillMatcher.addMatchFor(this, it, File(createdPath))
+ }
+ val longName = data.getStringExtra("LONG_NAME")!!
+ val password = data.getStringExtra("PASSWORD")
+ val resultIntent = if (password != null) {
+ // Password was generated and should be filled into a form.
+ val username = data.getStringExtra("USERNAME")
+ val clientState =
+ intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run {
+ e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
+ finish()
+ return@registerForActivityResult
+ }
+ val credentials = Credentials(username, password, null)
+ val fillInDataset = FillableForm.makeFillInDataset(
+ this,
+ credentials,
+ clientState,
+ AutofillAction.Generate
+ )
+ Intent().apply {
+ putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset)
}
- val credentials = Credentials(username, password, null)
- val fillInDataset = FillableForm.makeFillInDataset(
- this,
- credentials,
- clientState,
- AutofillAction.Generate
- )
- Intent().apply {
- putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset)
+ } else {
+ // Password was extracted from a form, there is nothing to fill.
+ Intent()
}
- } else {
- // Password was extracted from a form, there is nothing to fill.
- Intent()
+ // PasswordCreationActivity delegates committing the added file to PasswordStore. Since
+ // PasswordStore is not involved in an AutofillScenario, we have to commit the file ourselves.
+ commitChange(
+ getString(R.string.git_commit_add_text, longName),
+ finishWithResultOnEnd = resultIntent
+ )
+ // GitAsyncTask will finish the activity for us.
}
- // PasswordCreationActivity delegates committing the added file to PasswordStore. Since
- // PasswordStore is not involved in an AutofillScenario, we have to commit the file ourselves.
- commitChange(
- getString(R.string.git_commit_add_text, longName),
- finishWithResultOnEnd = result
- )
- // GitAsyncTask will finish the activity for us.
- } else {
- finish()
- }
+ }.launch(saveIntent)
}
}