Skip to content

Commit

Permalink
PM-14411: Allow accessibility autofill to run when app is already in …
Browse files Browse the repository at this point in the history
…background (#4255)
  • Loading branch information
david-livefront authored Nov 8, 2024
1 parent fe84feb commit 016d0f8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -47,7 +47,7 @@ class AccessibilityCompletionManagerImpl(
)
mainScope.launch {
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
activity.finish()
}
activity.finishAndRemoveTask()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -68,7 +68,7 @@ class AccessibilityCompletionManagerTest {

verify(exactly = 1) {
activity.intent
activity.finish()
activity.finishAndRemoveTask()
}
}

Expand All @@ -87,7 +87,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}

Expand All @@ -111,7 +111,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}

Expand All @@ -135,7 +135,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}

Expand All @@ -162,7 +162,7 @@ class AccessibilityCompletionManagerTest {
verify(exactly = 1) {
activity.intent
mockIntent.getAutofillSelectionDataOrNull()
activity.finish()
activity.finishAndRemoveTask()
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ class AccessibilityCompletionManagerTest {
cipherView = cipherView,
uri = uri,
)
activity.finish()
activity.finishAndRemoveTask()
}
coVerify(exactly = 1) {
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
Expand Down

0 comments on commit 016d0f8

Please sign in to comment.