mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +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(
|
data class FillableFields(
|
||||||
val usernameField: AccessibilityNodeInfo?,
|
val usernameField: AccessibilityNodeInfo?,
|
||||||
val passwordFields: List<AccessibilityNodeInfo>,
|
val passwordFields: List<AccessibilityNodeInfo>,
|
||||||
)
|
) {
|
||||||
|
val hasFields: Boolean = usernameField != null && passwordFields.isNotEmpty()
|
||||||
|
}
|
||||||
|
|
|
@ -35,12 +35,10 @@ class BitwardenAccessibilityProcessorImpl(
|
||||||
if (!powerManager.isInteractive) return
|
if (!powerManager.isInteractive) return
|
||||||
// We skip if the system package
|
// We skip if the system package
|
||||||
if (eventNode.isSystemPackage) return
|
if (eventNode.isSystemPackage) return
|
||||||
// We skip any package that is a launcher or unsupported
|
// We skip any package that is unsupported
|
||||||
if (eventNode.shouldSkipPackage ||
|
if (eventNode.shouldSkipPackage) return
|
||||||
launcherPackageNameManager.launcherPackages.any { it == eventNode.packageName }
|
// We skip any package that is a launcher
|
||||||
) {
|
if (launcherPackageNameManager.launcherPackages.any { it == eventNode.packageName }) {
|
||||||
// Clear the action since this event needs to be ignored completely
|
|
||||||
accessibilityAutofillManager.accessibilityAction = null
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +63,11 @@ class BitwardenAccessibilityProcessorImpl(
|
||||||
private fun handleAttemptParseUri(rootNode: AccessibilityNodeInfo) {
|
private fun handleAttemptParseUri(rootNode: AccessibilityNodeInfo) {
|
||||||
accessibilityParser
|
accessibilityParser
|
||||||
.parseForUriOrPackageName(rootNode = rootNode)
|
.parseForUriOrPackageName(rootNode = rootNode)
|
||||||
|
?.takeIf {
|
||||||
|
accessibilityParser
|
||||||
|
.parseForFillableFields(rootNode = rootNode, uri = it)
|
||||||
|
.hasFields
|
||||||
|
}
|
||||||
?.let { uri ->
|
?.let { uri ->
|
||||||
context.startActivity(
|
context.startActivity(
|
||||||
createAutofillSelectionIntent(
|
createAutofillSelectionIntent(
|
||||||
|
|
|
@ -8,9 +8,9 @@ import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
||||||
*/
|
*/
|
||||||
@OmitFromCoverage
|
@OmitFromCoverage
|
||||||
class ExitManagerImpl(
|
class ExitManagerImpl(
|
||||||
val activity: Activity,
|
private val activity: Activity,
|
||||||
) : ExitManager {
|
) : ExitManager {
|
||||||
override fun exitApplication() {
|
override fun exitApplication() {
|
||||||
activity.finish()
|
activity.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -850,7 +850,7 @@ class VaultItemListingViewModel @Inject constructor(
|
||||||
|
|
||||||
private fun handleBackClick() {
|
private fun handleBackClick() {
|
||||||
sendEvent(
|
sendEvent(
|
||||||
event = if (state.isTotp) {
|
event = if (state.isTotp || state.isAutofill) {
|
||||||
VaultItemListingEvent.ExitApp
|
VaultItemListingEvent.ExitApp
|
||||||
} else {
|
} else {
|
||||||
VaultItemListingEvent.NavigateBack
|
VaultItemListingEvent.NavigateBack
|
||||||
|
|
|
@ -129,7 +129,6 @@ class BitwardenAccessibilityProcessorTest {
|
||||||
every { source } returns node
|
every { source } returns node
|
||||||
}
|
}
|
||||||
every { powerManager.isInteractive } returns true
|
every { powerManager.isInteractive } returns true
|
||||||
every { accessibilityAutofillManager.accessibilityAction = null } just runs
|
|
||||||
|
|
||||||
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { null }
|
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { null }
|
||||||
|
|
||||||
|
@ -137,7 +136,6 @@ class BitwardenAccessibilityProcessorTest {
|
||||||
powerManager.isInteractive
|
powerManager.isInteractive
|
||||||
node.isSystemPackage
|
node.isSystemPackage
|
||||||
node.shouldSkipPackage
|
node.shouldSkipPackage
|
||||||
accessibilityAutofillManager.accessibilityAction = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +152,6 @@ class BitwardenAccessibilityProcessorTest {
|
||||||
}
|
}
|
||||||
every { launcherPackageNameManager.launcherPackages } returns listOf(testPackageName)
|
every { launcherPackageNameManager.launcherPackages } returns listOf(testPackageName)
|
||||||
every { powerManager.isInteractive } returns true
|
every { powerManager.isInteractive } returns true
|
||||||
every { accessibilityAutofillManager.accessibilityAction = null } just runs
|
|
||||||
|
|
||||||
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { null }
|
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { null }
|
||||||
|
|
||||||
|
@ -163,7 +160,6 @@ class BitwardenAccessibilityProcessorTest {
|
||||||
node.isSystemPackage
|
node.isSystemPackage
|
||||||
node.shouldSkipPackage
|
node.shouldSkipPackage
|
||||||
launcherPackageNameManager.launcherPackages
|
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")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
fun `processAccessibilityEvent with AttemptParseUri and a valid uri should start the main activity`() {
|
fun `processAccessibilityEvent with AttemptParseUri and a valid uri should start the main activity`() {
|
||||||
|
@ -296,7 +345,11 @@ class BitwardenAccessibilityProcessorTest {
|
||||||
uri = any(),
|
uri = any(),
|
||||||
)
|
)
|
||||||
} returns mockk()
|
} 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 }
|
bitwardenAccessibilityProcessor.processAccessibilityEvent(event = event) { rootNode }
|
||||||
|
|
||||||
|
@ -308,6 +361,7 @@ class BitwardenAccessibilityProcessorTest {
|
||||||
accessibilityAutofillManager.accessibilityAction
|
accessibilityAutofillManager.accessibilityAction
|
||||||
accessibilityAutofillManager.accessibilityAction = null
|
accessibilityAutofillManager.accessibilityAction = null
|
||||||
accessibilityParser.parseForUriOrPackageName(rootNode = node)
|
accessibilityParser.parseForUriOrPackageName(rootNode = node)
|
||||||
|
accessibilityParser.parseForFillableFields(rootNode = node, uri = uri)
|
||||||
createAutofillSelectionIntent(
|
createAutofillSelectionIntent(
|
||||||
context = context,
|
context = context,
|
||||||
framework = AutofillSelectionData.Framework.ACCESSIBILITY,
|
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
|
@Test
|
||||||
fun `BackClick should emit NavigateBack`() = runTest {
|
fun `BackClick should emit NavigateBack`() = runTest {
|
||||||
val viewModel = createVaultItemListingViewModel()
|
val viewModel = createVaultItemListingViewModel()
|
||||||
|
|
Loading…
Reference in a new issue