mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 08:55:48 +03:00
PM-14411: Autofill logic to work better with QuickTile (#4300)
This commit is contained in:
parent
911c9e4704
commit
0967234ad8
6 changed files with 91 additions and 15 deletions
|
@ -8,4 +8,6 @@ import android.view.accessibility.AccessibilityNodeInfo
|
|||
data class FillableFields(
|
||||
val usernameField: AccessibilityNodeInfo?,
|
||||
val passwordFields: List<AccessibilityNodeInfo>,
|
||||
)
|
||||
) {
|
||||
val hasFields: Boolean = usernameField != null && passwordFields.isNotEmpty()
|
||||
}
|
||||
|
|
|
@ -35,12 +35,10 @@ class BitwardenAccessibilityProcessorImpl(
|
|||
if (!powerManager.isInteractive) return
|
||||
// We skip if the system package
|
||||
if (eventNode.isSystemPackage) return
|
||||
// We skip any package that is a launcher or unsupported
|
||||
if (eventNode.shouldSkipPackage ||
|
||||
launcherPackageNameManager.launcherPackages.any { it == eventNode.packageName }
|
||||
) {
|
||||
// Clear the action since this event needs to be ignored completely
|
||||
accessibilityAutofillManager.accessibilityAction = null
|
||||
// We skip any package that is unsupported
|
||||
if (eventNode.shouldSkipPackage) return
|
||||
// We skip any package that is a launcher
|
||||
if (launcherPackageNameManager.launcherPackages.any { it == eventNode.packageName }) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -65,6 +63,11 @@ class BitwardenAccessibilityProcessorImpl(
|
|||
private fun handleAttemptParseUri(rootNode: AccessibilityNodeInfo) {
|
||||
accessibilityParser
|
||||
.parseForUriOrPackageName(rootNode = rootNode)
|
||||
?.takeIf {
|
||||
accessibilityParser
|
||||
.parseForFillableFields(rootNode = rootNode, uri = it)
|
||||
.hasFields
|
||||
}
|
||||
?.let { uri ->
|
||||
context.startActivity(
|
||||
createAutofillSelectionIntent(
|
||||
|
|
|
@ -8,9 +8,9 @@ import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
|||
*/
|
||||
@OmitFromCoverage
|
||||
class ExitManagerImpl(
|
||||
val activity: Activity,
|
||||
private val activity: Activity,
|
||||
) : ExitManager {
|
||||
override fun exitApplication() {
|
||||
activity.finish()
|
||||
activity.finishAndRemoveTask()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -850,7 +850,7 @@ class VaultItemListingViewModel @Inject constructor(
|
|||
|
||||
private fun handleBackClick() {
|
||||
sendEvent(
|
||||
event = if (state.isTotp) {
|
||||
event = if (state.isTotp || state.isAutofill) {
|
||||
VaultItemListingEvent.ExitApp
|
||||
} else {
|
||||
VaultItemListingEvent.NavigateBack
|
||||
|
|
|
@ -129,7 +129,6 @@ class BitwardenAccessibilityProcessorTest {
|
|||
every { source } returns node
|
||||
}
|
||||
every { powerManager.isInteractive } returns true
|
||||
every { accessibilityAutofillManager.accessibilityAction = null } just runs
|
||||
|
||||
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { null }
|
||||
|
||||
|
@ -137,7 +136,6 @@ class BitwardenAccessibilityProcessorTest {
|
|||
powerManager.isInteractive
|
||||
node.isSystemPackage
|
||||
node.shouldSkipPackage
|
||||
accessibilityAutofillManager.accessibilityAction = null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +152,6 @@ class BitwardenAccessibilityProcessorTest {
|
|||
}
|
||||
every { launcherPackageNameManager.launcherPackages } returns listOf(testPackageName)
|
||||
every { powerManager.isInteractive } returns true
|
||||
every { accessibilityAutofillManager.accessibilityAction = null } just runs
|
||||
|
||||
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { null }
|
||||
|
||||
|
@ -163,7 +160,6 @@ class BitwardenAccessibilityProcessorTest {
|
|||
node.isSystemPackage
|
||||
node.shouldSkipPackage
|
||||
launcherPackageNameManager.launcherPackages
|
||||
accessibilityAutofillManager.accessibilityAction = null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,6 +262,59 @@ class BitwardenAccessibilityProcessorTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `processAccessibilityEvent with AttemptParseUri and a valid uri but no fields to fill display toast`() {
|
||||
val testPackageName = "com.android.chrome"
|
||||
val rootNode = mockk<AccessibilityNodeInfo> {
|
||||
every { packageName } returns testPackageName
|
||||
}
|
||||
val node = mockk<AccessibilityNodeInfo> {
|
||||
every { isSystemPackage } returns false
|
||||
every { shouldSkipPackage } returns false
|
||||
every { packageName } returns testPackageName
|
||||
}
|
||||
val event = mockk<AccessibilityEvent> {
|
||||
every { source } returns node
|
||||
every { packageName } returns testPackageName
|
||||
}
|
||||
every { powerManager.isInteractive } returns true
|
||||
every { launcherPackageNameManager.launcherPackages } returns emptyList()
|
||||
every {
|
||||
accessibilityAutofillManager.accessibilityAction
|
||||
} returns AccessibilityAction.AttemptParseUri
|
||||
every { accessibilityAutofillManager.accessibilityAction = null } just runs
|
||||
every {
|
||||
createAutofillSelectionIntent(
|
||||
context = context,
|
||||
framework = AutofillSelectionData.Framework.ACCESSIBILITY,
|
||||
type = AutofillSelectionData.Type.LOGIN,
|
||||
uri = any(),
|
||||
)
|
||||
} returns mockk()
|
||||
val uri = mockk<Uri>()
|
||||
every { accessibilityParser.parseForUriOrPackageName(rootNode = node) } returns uri
|
||||
every {
|
||||
accessibilityParser.parseForFillableFields(rootNode = node, uri = uri)
|
||||
} returns mockk { every { hasFields } returns false }
|
||||
|
||||
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { rootNode }
|
||||
|
||||
verify(exactly = 1) {
|
||||
powerManager.isInteractive
|
||||
node.isSystemPackage
|
||||
node.shouldSkipPackage
|
||||
launcherPackageNameManager.launcherPackages
|
||||
accessibilityAutofillManager.accessibilityAction
|
||||
accessibilityAutofillManager.accessibilityAction = null
|
||||
accessibilityParser.parseForUriOrPackageName(rootNode = node)
|
||||
accessibilityParser.parseForFillableFields(rootNode = node, uri = uri)
|
||||
Toast
|
||||
.makeText(context, R.string.autofill_tile_uri_not_found, Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `processAccessibilityEvent with AttemptParseUri and a valid uri should start the main activity`() {
|
||||
|
@ -296,7 +345,11 @@ class BitwardenAccessibilityProcessorTest {
|
|||
uri = any(),
|
||||
)
|
||||
} returns mockk()
|
||||
every { accessibilityParser.parseForUriOrPackageName(rootNode = node) } returns mockk()
|
||||
val uri = mockk<Uri>()
|
||||
every { accessibilityParser.parseForUriOrPackageName(rootNode = node) } returns uri
|
||||
every {
|
||||
accessibilityParser.parseForFillableFields(rootNode = node, uri = uri)
|
||||
} returns mockk { every { hasFields } returns true }
|
||||
|
||||
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { rootNode }
|
||||
|
||||
|
@ -308,6 +361,7 @@ class BitwardenAccessibilityProcessorTest {
|
|||
accessibilityAutofillManager.accessibilityAction
|
||||
accessibilityAutofillManager.accessibilityAction = null
|
||||
accessibilityParser.parseForUriOrPackageName(rootNode = node)
|
||||
accessibilityParser.parseForFillableFields(rootNode = node, uri = uri)
|
||||
createAutofillSelectionIntent(
|
||||
context = context,
|
||||
framework = AutofillSelectionData.Framework.ACCESSIBILITY,
|
||||
|
|
|
@ -281,6 +281,23 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BackClick with AutofillSelectionData should emit ExitApp`() = runTest {
|
||||
specialCircumstanceManager.specialCircumstance = SpecialCircumstance.AutofillSelection(
|
||||
autofillSelectionData = AutofillSelectionData(
|
||||
framework = AutofillSelectionData.Framework.ACCESSIBILITY,
|
||||
type = AutofillSelectionData.Type.LOGIN,
|
||||
uri = null,
|
||||
),
|
||||
shouldFinishWhenComplete = false,
|
||||
)
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(VaultItemListingsAction.BackClick)
|
||||
assertEquals(VaultItemListingEvent.ExitApp, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BackClick should emit NavigateBack`() = runTest {
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
|
|
Loading…
Reference in a new issue