Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-14411: Allow accessibility autofill to run when app is already in โ€ฆ #4267

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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