From 752b01e19b9f5ccc30fc32864eba0bf44bec923a Mon Sep 17 00:00:00 2001 From: York Wei <49313072+york-wei@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:49:31 -0500 Subject: [PATCH] Include cross-platform info in requests (#340) --- sdk/build.gradle | 2 +- sdk/src/main/java/io/radar/sdk/RadarApiClient.kt | 15 ++++++++++++++- sdk/src/main/java/io/radar/sdk/RadarSettings.kt | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 6523f01d1..46fb3f8e2 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -10,7 +10,7 @@ apply plugin: "org.jetbrains.dokka" apply plugin: 'io.radar.mvnpublish' ext { - radarVersion = '3.9.4' + radarVersion = '3.9.5' } String buildNumber = ".${System.currentTimeMillis()}" diff --git a/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt b/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt index f4b33642a..2f7c02ed8 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt @@ -94,7 +94,7 @@ internal class RadarApiClient( } private fun headers(publishableKey: String): Map { - return mapOf( + val headers = mutableMapOf( "Authorization" to publishableKey, "Content-Type" to "application/json", "X-Radar-Config" to "true", @@ -104,6 +104,13 @@ internal class RadarApiClient( "X-Radar-Device-Type" to RadarUtils.deviceType, "X-Radar-SDK-Version" to RadarUtils.sdkVersion ) + if (RadarSettings.isXPlatform(context)) { + headers["X-Radar-X-Platform-SDK-Type"] = RadarSettings.getXPlatformSDKType(context) + headers["X-Radar-X-Platform-SDK-Version"] = RadarSettings.getXPlatformSDKVersion(context) + } else { + headers["X-Radar-X-Platform-SDK-Type"] = "Native" + } + return headers } internal fun getConfig(usage: String? = null, verified: Boolean = false, callback: RadarGetConfigApiCallback? = null) { @@ -298,6 +305,12 @@ internal class RadarApiClient( params.putOpt("country", RadarUtils.country) params.putOpt("timeZoneOffset", RadarUtils.timeZoneOffset) params.putOpt("source", Radar.stringForSource(source)) + if (RadarSettings.isXPlatform(context)) { + params.putOpt("xPlatformType", RadarSettings.getXPlatformSDKType(context)) + params.putOpt("xPlatformSDKVersion", RadarSettings.getXPlatformSDKVersion(context)) + } else { + params.putOpt("xPlatformType", "Native") + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { val mocked = location.isFromMockProvider params.putOpt("mocked", mocked) diff --git a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt index 6737b1efa..022cbf6f5 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt @@ -37,6 +37,8 @@ internal object RadarSettings { private const val KEY_LAST_APP_OPEN_TIME = "last_app_open_time" private const val KEY_SHARING = "sharing" private const val KEY_GOOGLE_PLAY_PROJECT_NUMBER = "google_play_project_number" + private const val KEY_X_PLATFORM_SDK_TYPE = "x_platform_sdk_type" + private const val KEY_X_PLATFORM_SDK_VERSION = "x_platform_sdk_version" private const val KEY_OLD_UPDATE_INTERVAL = "dwell_delay" private const val KEY_OLD_UPDATE_INTERVAL_RESPONSIVE = 60000 @@ -382,4 +384,17 @@ internal object RadarSettings { getSharedPreferences(context).edit { putLong(KEY_GOOGLE_PLAY_PROJECT_NUMBER, googlePlayProjectNumber) } } + internal fun isXPlatform(context: Context): Boolean { + return getSharedPreferences(context).contains(KEY_X_PLATFORM_SDK_TYPE) && + getSharedPreferences(context).contains(KEY_X_PLATFORM_SDK_VERSION) + } + + internal fun getXPlatformSDKType(context: Context): String? { + return getSharedPreferences(context).getString(KEY_X_PLATFORM_SDK_TYPE, null); + } + + internal fun getXPlatformSDKVersion(context: Context): String? { + return getSharedPreferences(context).getString(KEY_X_PLATFORM_SDK_VERSION, null); + } + } \ No newline at end of file