From 0b48e9ea60560f7eeb9b243d71c402241c517764 Mon Sep 17 00:00:00 2001 From: Chiping Yeh Date: Mon, 3 Nov 2025 13:17:08 -0500 Subject: [PATCH 1/7] Add new WebView snippet for native implementation --- .../com/example/identity/WebViewClientImpl.kt | 10 ++++ .../identity/credentialmanager/WebView.kt | 50 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt create mode 100644 identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt diff --git a/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt b/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt new file mode 100644 index 000000000..b9212cfb0 --- /dev/null +++ b/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt @@ -0,0 +1,10 @@ +package com.example.identity + +import android.webkit.WebView +import android.webkit.WebViewClient + +class WebViewClientImpl : WebViewClient() { + override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { + return false + } +} \ No newline at end of file diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt new file mode 100644 index 000000000..1ca06f1ef --- /dev/null +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt @@ -0,0 +1,50 @@ +package com.example.identity.credentialmanager + +import android.os.Bundle +import android.util.Log +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.ui.viewinterop.AndroidView +import androidx.webkit.WebSettingsCompat +import androidx.webkit.WebViewFeature +import android.webkit.WebView +import com.example.identity.WebViewClientImpl + + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + val url = "https://passkeys-codelab.glitch.me/" + AndroidView( + factory = { context -> + WebView(context).apply { + settings.javaScriptEnabled = true + + webViewClient = WebViewClientImpl() + } + }, + update = { webView -> + run { + webView.loadUrl(url) + if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_AUTHENTICATION)) { + WebSettingsCompat.setWebAuthenticationSupport( + webView.settings, + WebSettingsCompat.WEB_AUTHENTICATION_SUPPORT_FOR_APP, + ) + // Check if getWebauthenticationSupport may have been disabled by the WebView. + Log.e( + "WebViewPasskeyDemo", + "getWebAuthenticationSupport result: " + WebSettingsCompat.getWebAuthenticationSupport( + webView.settings + ), + ) + } else { + Log.e("WebViewPasskeyDemo", "WebView does not support passkeys.") + } + } + }, + ) + } + } +} From 1a62da7f405725ca5f0fc9c575aa444e41ccf4d3 Mon Sep 17 00:00:00 2001 From: Chiping Yeh Date: Mon, 3 Nov 2025 13:20:34 -0500 Subject: [PATCH 2/7] Add DAC delineators --- .../main/java/com/example/identity/credentialmanager/WebView.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt index 1ca06f1ef..42a992834 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt @@ -11,6 +11,7 @@ import android.webkit.WebView import com.example.identity.WebViewClientImpl +// [START android_identity_webview_main_activity] class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -48,3 +49,4 @@ class MainActivity : ComponentActivity() { } } } +// [END android_identity_webview_main_activity] From 881ada8a66261372a40a1a035deb39d68f196d4a Mon Sep 17 00:00:00 2001 From: Chiping Yeh Date: Mon, 3 Nov 2025 13:29:30 -0500 Subject: [PATCH 3/7] Run spotless --- .../com/example/identity/WebViewClientImpl.kt | 18 +++++++++++++++++- .../identity/credentialmanager/WebView.kt | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt b/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt index b9212cfb0..d55115e16 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.identity import android.webkit.WebView @@ -7,4 +23,4 @@ class WebViewClientImpl : WebViewClient() { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { return false } -} \ No newline at end of file +} diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt index 42a992834..dc9c12da6 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt @@ -1,16 +1,31 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.identity.credentialmanager import android.os.Bundle import android.util.Log +import android.webkit.WebView import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.ui.viewinterop.AndroidView import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature -import android.webkit.WebView import com.example.identity.WebViewClientImpl - // [START android_identity_webview_main_activity] class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { From d2c47816a37ba58f29d9278ab61942e23660f54e Mon Sep 17 00:00:00 2001 From: Chiping Yeh Date: Mon, 3 Nov 2025 13:47:39 -0500 Subject: [PATCH 4/7] Move WebViewClientImpl to correct folder --- .../com/example/identity/WebViewClientImpl.kt | 26 ------------------- .../identity/credentialmanager/WebView.kt | 2 +- .../credentialmanager/WebViewClientImpl.kt | 10 +++++++ 3 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt create mode 100644 identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt diff --git a/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt b/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt deleted file mode 100644 index d55115e16..000000000 --- a/identity/credentialmanager/src/main/java/com/example/identity/WebViewClientImpl.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2025 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.identity - -import android.webkit.WebView -import android.webkit.WebViewClient - -class WebViewClientImpl : WebViewClient() { - override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { - return false - } -} diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt index dc9c12da6..cb2ec6a68 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt @@ -24,7 +24,7 @@ import androidx.activity.compose.setContent import androidx.compose.ui.viewinterop.AndroidView import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature -import com.example.identity.WebViewClientImpl +import com.example.identity.credentialmanager.WebViewClientImpl // [START android_identity_webview_main_activity] class MainActivity : ComponentActivity() { diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt new file mode 100644 index 000000000..818b5ac52 --- /dev/null +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt @@ -0,0 +1,10 @@ +package com.example.identity.credentialmanager + +import android.webkit.WebView +import android.webkit.WebViewClient + +class WebViewClientImpl : WebViewClient() { + override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { + return false + } +} \ No newline at end of file From b5961aa3d04e0e8ad0007cc24e72c8c6aebdfd5a Mon Sep 17 00:00:00 2001 From: cy245 <2625507+cy245@users.noreply.github.com> Date: Mon, 3 Nov 2025 18:50:35 +0000 Subject: [PATCH 5/7] Apply Spotless --- .../credentialmanager/WebViewClientImpl.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt index 818b5ac52..4bc690ae8 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebViewClientImpl.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.identity.credentialmanager import android.webkit.WebView @@ -7,4 +23,4 @@ class WebViewClientImpl : WebViewClient() { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { return false } -} \ No newline at end of file +} From 62b39b621a9aa33d21d606e1a8e1df1f077ff49f Mon Sep 17 00:00:00 2001 From: Chiping Yeh Date: Mon, 3 Nov 2025 14:47:23 -0500 Subject: [PATCH 6/7] Update WebView file --- .../java/com/example/identity/credentialmanager/WebView.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt index cb2ec6a68..d3a37ebb0 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt @@ -24,10 +24,9 @@ import androidx.activity.compose.setContent import androidx.compose.ui.viewinterop.AndroidView import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature -import com.example.identity.credentialmanager.WebViewClientImpl // [START android_identity_webview_main_activity] -class MainActivity : ComponentActivity() { +class WebViewMainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { From 90429d7e2515b259310b0dc0bffbd6610083e193 Mon Sep 17 00:00:00 2001 From: Chiping Yeh Date: Mon, 3 Nov 2025 16:10:38 -0500 Subject: [PATCH 7/7] Rename duplicate activity name --- .../main/java/com/example/identity/credentialmanager/WebView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt index d3a37ebb0..30e1e1f58 100644 --- a/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt +++ b/identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/WebView.kt @@ -26,7 +26,7 @@ import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature // [START android_identity_webview_main_activity] -class WebViewMainActivity : ComponentActivity() { +class WebViewActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent {