PM-14411: Allow accessibility autofill to run when app is already in background (#4255)

This commit is contained in:
David Perez 2024-11-08 15:30:14 -06:00 committed by GitHub
parent fe84feb184
commit 016d0f889c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 13 deletions

View file

@ -190,12 +190,14 @@ class MainViewModel @Inject constructor(
private fun handleAccessibilitySelectionReceive(
action: MainAction.Internal.AccessibilitySelectionReceive,
) {
specialCircumstanceManager.specialCircumstance = null
sendEvent(MainEvent.CompleteAccessibilityAutofill(cipherView = action.cipherView))
}
private fun handleAutofillSelectionReceive(
action: MainAction.Internal.AutofillSelectionReceive,
) {
specialCircumstanceManager.specialCircumstance = null
sendEvent(MainEvent.CompleteAutofill(cipherView = action.cipherView))
}

View file

@ -26,18 +26,18 @@ class AccessibilityCompletionManagerImpl(
.intent
?.getAutofillSelectionDataOrNull()
?: run {
activity.finish()
activity.finishAndRemoveTask()
return
}
if (autofillSelectionData.framework != AutofillSelectionData.Framework.ACCESSIBILITY) {
activity.finish()
activity.finishAndRemoveTask()
return
}
val uri = autofillSelectionData
.uri
?.toUriOrNull()
?: run {
activity.finish()
activity.finishAndRemoveTask()
return
}
@ -47,7 +47,7 @@ class AccessibilityCompletionManagerImpl(
)
mainScope.launch {
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
activity.finish()
}
activity.finishAndRemoveTask()
}
}

View file

@ -38,7 +38,7 @@ fun createAutofillSelectionIntent(
.apply {
// This helps prevent a crash when using the accessibility framework
if (framework == AutofillSelectionData.Framework.ACCESSIBILITY) {
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
}
putExtra(
AUTOFILL_BUNDLE_KEY,

View file

@ -44,7 +44,7 @@ class BitwardenAutofillTileService : TileService() {
}
accessibilityAutofillManager.accessibilityAction = AccessibilityAction.AttemptParseUri
val intent = Intent(applicationContext, AccessibilityActivity::class.java)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
if (isBuildVersionBelow(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) {
@Suppress("DEPRECATION")
startActivityAndCollapse(intent)

View file

@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test
class AccessibilityCompletionManagerTest {
private val activity: Activity = mockk {
every { finish() } just runs
every { finishAndRemoveTask() } just runs
}
private val accessibilityAutofillManager: AccessibilityAutofillManager = mockk()
private val totpManager: AutofillTotpManager = mockk()
@ -68,7 +68,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
activity.finish()
activity.finishAndRemoveTask()
}
}
@ -87,7 +87,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}
@ -111,7 +111,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}
@ -135,7 +135,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}
@ -162,7 +162,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}
@ -201,7 +201,7 @@ class AccessibilityCompletionManagerTest {
cipherView = cipherView,
uri = uri,
)
activity.finish()
activity.finishAndRemoveTask()
}
coVerify(exactly = 1) {
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)