Skip to content

Commit

Permalink
MOBILE-1859: Add additional information into the user-agent header (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
GytisBarakauskas authored Jan 10, 2023
1 parent 2570891 commit a3b45fc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.kevin.common.extensions.applySystemInsetsPadding
import eu.kevin.common.extensions.dp
import eu.kevin.common.extensions.getColorFromAttr
import eu.kevin.common.extensions.hideKeyboard
import eu.kevin.common.helpers.WebFrameHeadersHelper
import eu.kevin.common.managers.KeyboardManager

internal class AccountLinkingView(context: Context) :
Expand Down Expand Up @@ -69,8 +70,13 @@ internal class AccountLinkingView(context: Context) :
with(requireBinding().accountLinkWebView) {
setBackgroundColor(context.getColorFromAttr(android.R.attr.colorBackground))
applySystemInsetsMargin(bottom = true)
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
with(settings) {
javaScriptEnabled = true
domStorageEnabled = true
userAgentString = WebFrameHeadersHelper.appendTelemetryInfoToUserAgent(
originalUserAgent = userAgentString
)
}
webViewClient = object : WebViewClientCompat() {
override fun shouldOverrideUrlLoading(
view: WebView,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package eu.kevin.common.helpers

import eu.kevin.common.BuildConfig

object WebFrameHeadersHelper {

private const val KEVIN_SDK_VERSION_KEY = "KevinAndroidSdk"

fun appendTelemetryInfoToUserAgent(originalUserAgent: String): String {
return originalUserAgent
.addUserAgentDataField(key = KEVIN_SDK_VERSION_KEY, value = BuildConfig.KEVIN_SDK_VERSION)
}

private fun String.addUserAgentDataField(key: String, value: String): String {
return this.plus(" $key/$value")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import eu.kevin.common.extensions.getColorFromAttr
import eu.kevin.common.extensions.getCurrentLocale
import eu.kevin.common.extensions.toHexColor
import eu.kevin.core.plugin.Kevin
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

object WebFrameHelper {

@OptIn(ExperimentalSerializationApi::class)
fun getStyleAndLanguageQueryParameters(context: Context): String {
return ""
.appendQueryParameter("lang", getActiveLocaleCode(context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import eu.kevin.common.extensions.removeWhiteSpaces
import eu.kevin.common.extensions.setDebounceClickListener
import eu.kevin.common.extensions.setOnDoneActionListener
import eu.kevin.common.extensions.setOnNextActionListener
import eu.kevin.common.helpers.WebFrameHeadersHelper
import eu.kevin.common.managers.KeyboardManager
import eu.kevin.inapppayments.KevinPaymentsPlugin
import eu.kevin.inapppayments.R
Expand Down Expand Up @@ -138,8 +139,13 @@ internal class CardPaymentView(context: Context) :
private fun configureWebView() {
with(requireBinding().webView) {
applySystemInsetsMargin(bottom = true)
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
with(settings) {
javaScriptEnabled = true
domStorageEnabled = true
userAgentString = WebFrameHeadersHelper.appendTelemetryInfoToUserAgent(
originalUserAgent = userAgentString
)
}
addJavascriptInterface(
object {
@JavascriptInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import eu.kevin.common.extensions.applySystemInsetsPadding
import eu.kevin.common.extensions.dp
import eu.kevin.common.extensions.getColorFromAttr
import eu.kevin.common.extensions.hideKeyboard
import eu.kevin.common.helpers.WebFrameHeadersHelper
import eu.kevin.common.managers.KeyboardManager
import eu.kevin.inapppayments.KevinPaymentsPlugin
import eu.kevin.inapppayments.databinding.KevinFragmentPaymentConfirmationBinding
Expand Down Expand Up @@ -67,8 +68,13 @@ internal class PaymentConfirmationView(context: Context) :
with(requireBinding().confirmationWebView) {
setBackgroundColor(context.getColorFromAttr(android.R.attr.colorBackground))
applySystemInsetsMargin(bottom = true)
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
with(settings) {
javaScriptEnabled = true
domStorageEnabled = true
userAgentString = WebFrameHeadersHelper.appendTelemetryInfoToUserAgent(
originalUserAgent = userAgentString
)
}
webViewClient = object : WebViewClientCompat() {
override fun shouldOverrideUrlLoading(
view: WebView,
Expand Down

0 comments on commit a3b45fc

Please sign in to comment.