Skip to content

Commit

Permalink
Include cross-platform info in requests (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
york-wei authored Feb 14, 2024
1 parent fca4d38 commit 752b01e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
Expand Down
15 changes: 14 additions & 1 deletion sdk/src/main/java/io/radar/sdk/RadarApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal class RadarApiClient(
}

private fun headers(publishableKey: String): Map<String, String> {
return mapOf(
val headers = mutableMapOf(
"Authorization" to publishableKey,
"Content-Type" to "application/json",
"X-Radar-Config" to "true",
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions sdk/src/main/java/io/radar/sdk/RadarSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

}

0 comments on commit 752b01e

Please sign in to comment.