From 629c4609f9cad765031ee7299e0bbba9845c9afc Mon Sep 17 00:00:00 2001 From: Craig Russell Date: Fri, 24 Jan 2025 16:18:40 +0000 Subject: [PATCH] Add WebView compatibility check before launching GPM in dev settings (#5527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task/Issue URL: https://app.asana.com/0/488551667048375/1209200821186635/f ### Description ### Steps to test this PR QA optional but if you want to…. - [ ] Install `internal` build on a device/emulator with old `WebView` - [ ] Access `Settings->Autofill Dev Settings` - [ ] Tap on `Launch Google Passwords (import flow)` - [ ] Verify you see a toast saying `WebView` isn’t compatible - [ ] Repeat this on a device/emulator with a compatible, modern `WebView` and ensure the flow can be launched Fixes https://github.com/duckduckgo/Android/issues/5499 Co-authored-by: Craig Russell <1336281+CDRussell@users.noreply.github.com> --- .../AutofillInternalSettingsActivity.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt b/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt index d39e5856570f..59dcbf2c337b 100644 --- a/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt +++ b/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt @@ -29,6 +29,9 @@ import androidx.lifecycle.Lifecycle.State.STARTED import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.duckduckgo.anvil.annotations.InjectWith +import com.duckduckgo.app.browser.api.WebViewCapabilityChecker +import com.duckduckgo.app.browser.api.WebViewCapabilityChecker.WebViewCapability.DocumentStartJavaScript +import com.duckduckgo.app.browser.api.WebViewCapabilityChecker.WebViewCapability.WebMessageListener import com.duckduckgo.app.tabs.BrowserNav import com.duckduckgo.autofill.api.AutofillFeature import com.duckduckgo.autofill.api.AutofillScreens.AutofillSettingsScreen @@ -134,6 +137,9 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() { @Inject lateinit var autofillImportPasswordConfigStore: AutofillImportPasswordConfigStore + @Inject + lateinit var webViewCapabilityChecker: WebViewCapabilityChecker + private var passwordImportWatcher = ConflatedJob() // used to output duration of import @@ -289,8 +295,17 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() { } } binding.importPasswordsLaunchGooglePasswordCustomFlow.setClickListener { - val intent = globalActivityStarter.startIntent(this, AutofillImportViaGooglePasswordManagerScreen) - importGooglePasswordsFlowLauncher.launch(intent) + lifecycleScope.launch { + val webViewWebMessageSupport = webViewCapabilityChecker.isSupported(WebMessageListener) + val webViewDocumentStartJavascript = webViewCapabilityChecker.isSupported(DocumentStartJavaScript) + if (webViewDocumentStartJavascript && webViewWebMessageSupport) { + val intent = + globalActivityStarter.startIntent(this@AutofillInternalSettingsActivity, AutofillImportViaGooglePasswordManagerScreen) + importGooglePasswordsFlowLauncher.launch(intent) + } else { + Toast.makeText(this@AutofillInternalSettingsActivity, "WebView version not supported", Toast.LENGTH_SHORT).show() + } + } } binding.importPasswordsImportCsv.setClickListener {