From 6107ffc310b76e3516c42b23a5ba4e7d57018bf7 Mon Sep 17 00:00:00 2001 From: Liam Meier Date: Fri, 3 Feb 2023 17:42:00 -0500 Subject: [PATCH 1/3] Surface center, radius, and location for geofences & places (#267) * Surface center, radius, and location for geofences & places * rely on geofence's geometry for center and radius, add test --- .../java/io/radar/sdk/model/RadarGeofence.kt | 21 ++++++++++++++++--- .../java/io/radar/sdk/model/RadarPlace.kt | 1 + sdk/src/test/java/io/radar/sdk/RadarTest.kt | 8 +++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/model/RadarGeofence.kt b/sdk/src/main/java/io/radar/sdk/model/RadarGeofence.kt index aff14fb8..43ecb942 100644 --- a/sdk/src/main/java/io/radar/sdk/model/RadarGeofence.kt +++ b/sdk/src/main/java/io/radar/sdk/model/RadarGeofence.kt @@ -35,11 +35,13 @@ class RadarGeofence( */ val metadata: JSONObject?, + /** * The geometry of the geofence. */ - val geometry: RadarGeofenceGeometry? -) { + val geometry: RadarGeofenceGeometry?, + + ) { internal companion object { private const val FIELD_ID = "_id" @@ -48,9 +50,9 @@ class RadarGeofence( private const val FIELD_EXTERNAL_ID = "externalId" private const val FIELD_METADATA = "metadata" private const val FIELD_TYPE = "type" + private const val FIELD_GEOMETRY = "geometry" private const val FIELD_GEOMETRY_RADIUS = "geometryRadius" private const val FIELD_GEOMETRY_CENTER = "geometryCenter" - private const val FIELD_GEOMETRY = "geometry" private const val FIELD_COORDINATES = "coordinates" private const val TYPE_CIRCLE = "circle" @@ -139,6 +141,19 @@ class RadarGeofence( obj.putOpt(FIELD_EXTERNAL_ID, this.externalId) obj.putOpt(FIELD_DESCRIPTION, this.description) obj.putOpt(FIELD_METADATA, this.metadata) + this.geometry?.let { geometry -> + when (geometry) { + is RadarCircleGeometry -> { + obj.putOpt(FIELD_GEOMETRY_CENTER, geometry.center.toJson()) + obj.putOpt(FIELD_GEOMETRY_RADIUS, geometry.radius) + } + is RadarPolygonGeometry -> { + obj.putOpt(FIELD_GEOMETRY_CENTER, geometry.center.toJson()) + obj.putOpt(FIELD_GEOMETRY_RADIUS, geometry.radius) + } + } + } + return obj } diff --git a/sdk/src/main/java/io/radar/sdk/model/RadarPlace.kt b/sdk/src/main/java/io/radar/sdk/model/RadarPlace.kt index 2fce54e2..690e3a91 100644 --- a/sdk/src/main/java/io/radar/sdk/model/RadarPlace.kt +++ b/sdk/src/main/java/io/radar/sdk/model/RadarPlace.kt @@ -125,6 +125,7 @@ class RadarPlace( obj.putOpt(FIELD_CHAIN, this.chain?.toJson()) obj.putOpt(FIELD_GROUP, this.group) obj.putOpt(FIELD_METADATA, this.metadata) + obj.putOpt(FIELD_LOCATION, this.location.toJson()) return obj } diff --git a/sdk/src/test/java/io/radar/sdk/RadarTest.kt b/sdk/src/test/java/io/radar/sdk/RadarTest.kt index 59e3e961..18b76f98 100644 --- a/sdk/src/test/java/io/radar/sdk/RadarTest.kt +++ b/sdk/src/test/java/io/radar/sdk/RadarTest.kt @@ -1022,6 +1022,14 @@ class RadarTest { assertEquals(Radar.RadarStatus.SUCCESS, callbackStatus) assertEquals(mockLocation, callbackLocation) assertGeofencesOk(callbackGeofences) + + // test that a geofence.toJson has a radius and geometryCenter + val geofence = callbackGeofences!!.first() + val geofenceJson = geofence.toJson() + assertNotNull(geofenceJson) + assertTrue(geofenceJson.has("geometryRadius")) + assertTrue(geofenceJson.has("geometryCenter")) + } @Test From b8343d2f114b7cab7b357a3253c4631e1c2bbc53 Mon Sep 17 00:00:00 2001 From: Liam Meier Date: Fri, 3 Feb 2023 17:54:38 -0500 Subject: [PATCH 2/3] Bump version --- sdk/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 3f79f8d1..bf70ab74 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.5.9' + radarVersion = '3.5.10' } String buildNumber = ".${System.currentTimeMillis()}" From 9f9ed5a98bdd9016f80e443ca6fa1a0f9e10caf4 Mon Sep 17 00:00:00 2001 From: David Goodfellow <61531269+david-goodfellow@users.noreply.github.com> Date: Sat, 11 Feb 2023 15:20:16 -0500 Subject: [PATCH 3/3] RAD-5747 Anonymous config call in `trackOnce` (#266) * add config call for anonymous before track * add boolean for track usage * usage enum not bool * resume usage * move config track usage call later in the call stack * move config track usage call later in the call stack * use anon val * bump version * 3.5.11 version bump --------- Co-authored-by: Jason R Tibbetts <708510+jrtibbetts@users.noreply.github.com> Co-authored-by: Nick Patrick Co-authored-by: Tim Julien --- sdk/build.gradle | 2 +- sdk/src/main/java/io/radar/sdk/Radar.kt | 3 ++- .../io/radar/sdk/RadarActivityLifecycleCallbacks.kt | 3 ++- sdk/src/main/java/io/radar/sdk/RadarApiClient.kt | 10 +++++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index bf70ab74..880bdfd9 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.5.10' + radarVersion = '3.5.11' } String buildNumber = ".${System.currentTimeMillis()}" diff --git a/sdk/src/main/java/io/radar/sdk/Radar.kt b/sdk/src/main/java/io/radar/sdk/Radar.kt index ba0682a8..23623236 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -454,7 +454,8 @@ object Radar { val application = this.context as? Application application?.registerActivityLifecycleCallbacks(RadarActivityLifecycleCallbacks()) - this.apiClient.getConfig(object : RadarApiClient.RadarGetConfigApiCallback { + val usage = "initialize" + this.apiClient.getConfig(usage, object : RadarApiClient.RadarGetConfigApiCallback { override fun onComplete(config: RadarConfig) { locationManager.updateTrackingFromMeta(config.meta) RadarSettings.setFeatureSettings(context, config.featureSettings) diff --git a/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt b/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt index 50a9f428..0771f731 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt @@ -41,7 +41,8 @@ internal class RadarActivityLifecycleCallbacks : Application.ActivityLifecycleCa try { val updated = RadarSettings.updateSessionId(activity.applicationContext) if (updated) { - Radar.apiClient.getConfig(object : RadarApiClient.RadarGetConfigApiCallback { + val usage = "resume" + Radar.apiClient.getConfig(usage, object : RadarApiClient.RadarGetConfigApiCallback { override fun onComplete(config: RadarConfig) { Radar.locationManager.updateTrackingFromMeta(config.meta) RadarSettings.setFeatureSettings(activity.applicationContext, config.featureSettings) diff --git a/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt b/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt index 63280fa6..85089ed0 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( ) } - internal fun getConfig(callback: RadarGetConfigApiCallback? = null) { + internal fun getConfig(usage: String? = null, callback: RadarGetConfigApiCallback? = null) { val publishableKey = RadarSettings.getPublishableKey(context) ?: return val queryParams = StringBuilder() @@ -102,6 +102,9 @@ internal class RadarApiClient( queryParams.append("&sessionId=${RadarSettings.getSessionId(context)}") queryParams.append("&locationAuthorization=${RadarUtils.getLocationAuthorization(context)}") queryParams.append("&locationAccuracyAuthorization=${RadarUtils.getLocationAccuracyAuthorization(context)}") + if (usage != null) { + queryParams.append("&usage=${usage}") + } val host = RadarSettings.getHost(context) val uri = Uri.parse(host).buildUpon() @@ -272,6 +275,11 @@ internal class RadarApiClient( return } + if (anonymous) { + val usage = "track" + this.getConfig(usage) + } + val host = RadarSettings.getHost(context) val uri = Uri.parse(host).buildUpon() .appendEncodedPath("v1/track")