mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 07:11:51 +03:00
PM-14411: Allow accessibility autofill to run when app is already in background (#4255)
This commit is contained in:
parent
fe84feb184
commit
016d0f889c
5 changed files with 15 additions and 13 deletions
|
@ -190,12 +190,14 @@ class MainViewModel @Inject constructor(
|
||||||
private fun handleAccessibilitySelectionReceive(
|
private fun handleAccessibilitySelectionReceive(
|
||||||
action: MainAction.Internal.AccessibilitySelectionReceive,
|
action: MainAction.Internal.AccessibilitySelectionReceive,
|
||||||
) {
|
) {
|
||||||
|
specialCircumstanceManager.specialCircumstance = null
|
||||||
sendEvent(MainEvent.CompleteAccessibilityAutofill(cipherView = action.cipherView))
|
sendEvent(MainEvent.CompleteAccessibilityAutofill(cipherView = action.cipherView))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleAutofillSelectionReceive(
|
private fun handleAutofillSelectionReceive(
|
||||||
action: MainAction.Internal.AutofillSelectionReceive,
|
action: MainAction.Internal.AutofillSelectionReceive,
|
||||||
) {
|
) {
|
||||||
|
specialCircumstanceManager.specialCircumstance = null
|
||||||
sendEvent(MainEvent.CompleteAutofill(cipherView = action.cipherView))
|
sendEvent(MainEvent.CompleteAutofill(cipherView = action.cipherView))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,18 +26,18 @@ class AccessibilityCompletionManagerImpl(
|
||||||
.intent
|
.intent
|
||||||
?.getAutofillSelectionDataOrNull()
|
?.getAutofillSelectionDataOrNull()
|
||||||
?: run {
|
?: run {
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (autofillSelectionData.framework != AutofillSelectionData.Framework.ACCESSIBILITY) {
|
if (autofillSelectionData.framework != AutofillSelectionData.Framework.ACCESSIBILITY) {
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val uri = autofillSelectionData
|
val uri = autofillSelectionData
|
||||||
.uri
|
.uri
|
||||||
?.toUriOrNull()
|
?.toUriOrNull()
|
||||||
?: run {
|
?: run {
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class AccessibilityCompletionManagerImpl(
|
||||||
)
|
)
|
||||||
mainScope.launch {
|
mainScope.launch {
|
||||||
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
|
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
|
||||||
activity.finish()
|
|
||||||
}
|
}
|
||||||
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ fun createAutofillSelectionIntent(
|
||||||
.apply {
|
.apply {
|
||||||
// This helps prevent a crash when using the accessibility framework
|
// This helps prevent a crash when using the accessibility framework
|
||||||
if (framework == AutofillSelectionData.Framework.ACCESSIBILITY) {
|
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(
|
putExtra(
|
||||||
AUTOFILL_BUNDLE_KEY,
|
AUTOFILL_BUNDLE_KEY,
|
||||||
|
|
|
@ -44,7 +44,7 @@ class BitwardenAutofillTileService : TileService() {
|
||||||
}
|
}
|
||||||
accessibilityAutofillManager.accessibilityAction = AccessibilityAction.AttemptParseUri
|
accessibilityAutofillManager.accessibilityAction = AccessibilityAction.AttemptParseUri
|
||||||
val intent = Intent(applicationContext, AccessibilityActivity::class.java)
|
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)) {
|
if (isBuildVersionBelow(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
startActivityAndCollapse(intent)
|
startActivityAndCollapse(intent)
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test
|
||||||
class AccessibilityCompletionManagerTest {
|
class AccessibilityCompletionManagerTest {
|
||||||
|
|
||||||
private val activity: Activity = mockk {
|
private val activity: Activity = mockk {
|
||||||
every { finish() } just runs
|
every { finishAndRemoveTask() } just runs
|
||||||
}
|
}
|
||||||
private val accessibilityAutofillManager: AccessibilityAutofillManager = mockk()
|
private val accessibilityAutofillManager: AccessibilityAutofillManager = mockk()
|
||||||
private val totpManager: AutofillTotpManager = mockk()
|
private val totpManager: AutofillTotpManager = mockk()
|
||||||
|
@ -68,7 +68,7 @@ class AccessibilityCompletionManagerTest {
|
||||||
|
|
||||||
verify(exactly = 1) {
|
verify(exactly = 1) {
|
||||||
activity.intent
|
activity.intent
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class AccessibilityCompletionManagerTest {
|
||||||
verify(exactly = 1) {
|
verify(exactly = 1) {
|
||||||
activity.intent
|
activity.intent
|
||||||
mockIntent.getAutofillSelectionDataOrNull()
|
mockIntent.getAutofillSelectionDataOrNull()
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ class AccessibilityCompletionManagerTest {
|
||||||
verify(exactly = 1) {
|
verify(exactly = 1) {
|
||||||
activity.intent
|
activity.intent
|
||||||
mockIntent.getAutofillSelectionDataOrNull()
|
mockIntent.getAutofillSelectionDataOrNull()
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class AccessibilityCompletionManagerTest {
|
||||||
verify(exactly = 1) {
|
verify(exactly = 1) {
|
||||||
activity.intent
|
activity.intent
|
||||||
mockIntent.getAutofillSelectionDataOrNull()
|
mockIntent.getAutofillSelectionDataOrNull()
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ class AccessibilityCompletionManagerTest {
|
||||||
verify(exactly = 1) {
|
verify(exactly = 1) {
|
||||||
activity.intent
|
activity.intent
|
||||||
mockIntent.getAutofillSelectionDataOrNull()
|
mockIntent.getAutofillSelectionDataOrNull()
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ class AccessibilityCompletionManagerTest {
|
||||||
cipherView = cipherView,
|
cipherView = cipherView,
|
||||||
uri = uri,
|
uri = uri,
|
||||||
)
|
)
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
coVerify(exactly = 1) {
|
coVerify(exactly = 1) {
|
||||||
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
|
totpManager.tryCopyTotpToClipboard(cipherView = cipherView)
|
||||||
|
|
Loading…
Reference in a new issue