Skip to content

Commit 2246760

Browse files
authored
Restore system-level password manager integration (#6794)
Task/Issue URL: https://app.asana.com/1/137249556945/project/608920331025315/task/1211346135005875?focus=true ### Description When `swipingTabs` FF is enabled, the integration between the web view and the system-level autofill service is not working. To fix it, we need to ensure the `RecyclerView` inside of the `ViewPager` is configured as being important for autofill. Logcat filter: `Applying autofill fix to ViewPager2` ### Steps to test this PR #### Feature flag enabled (default) - [x] Go to device settings and setup an autofill provider (can be Google Password Manager, 1Password, Bitwarden etc...) - [x] In your chosen password manager, add a credential for https://fill.dev - [x] In our app visit, https://fill.dev/form/login-simple and tap on the username field - [x] Verify you see `Applying autofill fix to ViewPager2` in the logs - [x] Verify you can autofill from the system autofill provider #### Feature flag disabled - [x] Visit feature flag inventory and disable `applyAutofillFix` - [x] Back button all the way out of the app (or swipe it away) as `BrowserActivity` needs recreated - [x] In our app visit, https://fill.dev/form/login-simple and tap on the username field - [x] Verify you **don't** see `Applying autofill fix to ViewPager2` in the logs Co-authored-by: Craig Russell <[email protected]>
1 parent 497269c commit 2246760

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import android.os.SystemClock
2929
import android.view.KeyEvent
3030
import android.view.MotionEvent
3131
import android.view.View
32+
import android.view.View.IMPORTANT_FOR_AUTOFILL_YES
3233
import android.widget.Toast
3334
import androidx.activity.OnBackPressedCallback
3435
import androidx.activity.result.ActivityResult
@@ -122,6 +123,7 @@ import kotlinx.coroutines.Job
122123
import kotlinx.coroutines.delay
123124
import kotlinx.coroutines.flow.collectLatest
124125
import kotlinx.coroutines.launch
126+
import kotlinx.coroutines.withContext
125127
import logcat.LogPriority.ERROR
126128
import logcat.LogPriority.INFO
127129
import logcat.LogPriority.VERBOSE
@@ -1096,6 +1098,8 @@ open class BrowserActivity : DuckDuckGoActivity() {
10961098
tabPager.registerOnPageChangeCallback(onTabPageChangeListener)
10971099
tabPager.setPageTransformer(MarginPageTransformer(resources.getDimension(com.duckduckgo.mobile.android.R.dimen.keyline_1).toPx().toInt()))
10981100

1101+
configureViewPagerForSystemAutofill(tabPager)
1102+
10991103
savedInstanceState?.getBundle(KEY_TAB_PAGER_STATE)?.let {
11001104
tabPagerAdapter.restore(it)
11011105
}
@@ -1105,6 +1109,25 @@ open class BrowserActivity : DuckDuckGoActivity() {
11051109
tabPager.isVisible = swipingTabsFeature.isEnabled
11061110
}
11071111

1112+
private fun configureViewPagerForSystemAutofill(viewPager: ViewPager2) {
1113+
lifecycleScope.launch {
1114+
val applyAutofillFix = withContext(dispatcherProvider.io()) {
1115+
swipingTabsFeature.applyAutofillFixEnabled()
1116+
}
1117+
1118+
// Configure the internal RecyclerView - wait for layout to complete
1119+
if (applyAutofillFix) {
1120+
logcat(VERBOSE) { "Applying autofill fix to ViewPager2" }
1121+
1122+
viewPager.post {
1123+
(viewPager.getChildAt(0) as? androidx.recyclerview.widget.RecyclerView)?.let {
1124+
it.importantForAutofill = IMPORTANT_FOR_AUTOFILL_YES
1125+
}
1126+
}
1127+
}
1128+
}
1129+
}
1130+
11081131
private val Intent.launchedFromRecents: Boolean
11091132
get() = (flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
11101133

common/common-ui/src/main/java/com/duckduckgo/common/ui/tabs/SwipingTabsFeature.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ interface SwipingTabsFeature {
3535
@Toggle.DefaultValue(DefaultFeatureValue.FALSE)
3636
@InternalAlwaysEnabled
3737
fun enabledForUsers(): Toggle
38+
39+
@Toggle.DefaultValue(DefaultFeatureValue.TRUE)
40+
fun applyAutofillFix(): Toggle
3841
}

common/common-ui/src/main/java/com/duckduckgo/common/ui/tabs/SwipingTabsFeatureProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ import javax.inject.Inject
2222

2323
@SingleInstanceIn(AppScope::class)
2424
class SwipingTabsFeatureProvider @Inject constructor(
25-
swipingTabsFeature: SwipingTabsFeature,
25+
private val swipingTabsFeature: SwipingTabsFeature,
2626
) {
2727
val isEnabled: Boolean by lazy {
2828
swipingTabsFeature.self().isEnabled() && swipingTabsFeature.enabledForUsers().isEnabled()
2929
}
30+
31+
fun applyAutofillFixEnabled(): Boolean {
32+
return swipingTabsFeature.applyAutofillFix().isEnabled()
33+
}
3034
}

0 commit comments

Comments
 (0)