From 4b64feb2ab212eb668e4aa4b673dc4435a456514 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 10 Jan 2025 12:03:02 -0500 Subject: [PATCH 1/9] make desiredAccuracy configurable, avoid double request, add clearVerifiedLocationToken() --- sdk/build.gradle | 2 +- sdk/src/main/java/io/radar/sdk/Radar.kt | 60 +++++++++- .../io/radar/sdk/RadarVerificationManager.kt | 111 ++++++++++-------- 3 files changed, 123 insertions(+), 50 deletions(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 78f88a30..481dd1fa 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.18.11' + radarVersion = '3.19.0' } 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 c8184931..f3c3e935 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -1096,6 +1096,38 @@ object Radar { @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @JvmStatic fun getVerifiedLocationToken(callback: RadarTrackVerifiedCallback? = null) { + getVerifiedLocationToken(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback) + } + + /** + * Returns the user's last verified location token if still valid, or requests a fresh token if not. + * + * Note that you must configure SSL pinning before calling this method. + * + * @see [](https://radar.com/documentation/fraud) + * + * @param[block] A block callback. + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun getVerifiedLocationToken(block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { + getVerifiedLocationToken(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, block) + } + + /** + * Returns the user's last verified location token if still valid, or requests a fresh token if not. + * + * Note that you must configure SSL pinning before calling this method. + * + * @see [](https://radar.com/documentation/fraud) + * + * @param[beacons] A boolean indicating whether to range beacons. + * @param[desiredAccuracy] The desired accuracy. + * @param[callback] An optional callback. + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun getVerifiedLocationToken(beacons: Boolean, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy, callback: RadarTrackVerifiedCallback? = null) { if (!initialized) { callback?.onComplete(RadarStatus.ERROR_PUBLISHABLE_KEY) @@ -1107,7 +1139,7 @@ object Radar { this.verificationManager = RadarVerificationManager(this.context, this.logger) } - this.verificationManager.getVerifiedLocationToken(callback) + this.verificationManager.getVerifiedLocationToken(beacons, desiredAccuracy, callback) } /** @@ -1117,18 +1149,40 @@ object Radar { * * @see [](https://radar.com/documentation/fraud) * + * @param[beacons] A boolean indicating whether to range beacons. + * @param[desiredAccuracy] The desired accuracy. * @param[block] A block callback. */ @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @JvmStatic - fun getVerifiedLocationToken(block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { - getVerifiedLocationToken(object : RadarTrackVerifiedCallback { + fun getVerifiedLocationToken(beacons: Boolean, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy, block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { + getVerifiedLocationToken(beacons, desiredAccuracy, object : RadarTrackVerifiedCallback { override fun onComplete(status: RadarStatus, token: RadarVerifiedLocationToken?) { block(status, token) } }) } + /** + * Clears the user's last verified location token. + * + * @see [](https://radar.com/documentation/fraud) + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun clearVerifiedLocationToken() { + if (!initialized) { + return + } + this.logger.i("clearVerifiedLocationToken()", RadarLogType.SDK_CALL) + + if (!this::verificationManager.isInitialized) { + this.verificationManager = RadarVerificationManager(this.context, this.logger) + } + + this.verificationManager.clearVerifiedLocationToken() + } + /** * Optionally sets the user's expected country and state for jurisdiction checks. * diff --git a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt index d70be597..593b0ef1 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt @@ -62,7 +62,7 @@ internal class RadarVerificationManager( } } - fun trackVerified(beacons: Boolean = false, callback: Radar.RadarTrackVerifiedCallback? = null) { + fun trackVerified(beacons: Boolean = false, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback: Radar.RadarTrackVerifiedCallback? = null) { val verificationManager = this val lastTokenBeacons = beacons @@ -84,7 +84,7 @@ internal class RadarVerificationManager( val googlePlayProjectNumber = config.googlePlayProjectNumber Radar.locationManager.getLocation( - RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH, + desiredAccuracy, Radar.RadarLocationSource.FOREGROUND_LOCATION, object : Radar.RadarLocationCallback { @@ -239,48 +239,54 @@ internal class RadarVerificationManager( return } - verificationManager.trackVerified(verificationManager.startedBeacons, object : Radar.RadarTrackVerifiedCallback { + verificationManager.trackVerified(this.startedBeacons, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH, object : Radar.RadarTrackVerifiedCallback { override fun onComplete( status: Radar.RadarStatus, token: RadarVerifiedLocationToken? ) { - var expiresIn = 0 - var minInterval: Int = verificationManager.startedInterval + verificationManager.scheduleNextInterval(token) + } + }) + } - token?.let { - expiresIn = it.expiresIn + fun scheduleNextInterval(token: RadarVerifiedLocationToken?) { + val verificationManager = this - // if expiresIn is shorter than interval, override interval - // re-request early to maximize the likelihood that a cached token is available - minInterval = minOf(it.expiresIn - 10, verificationManager.startedInterval) - } + var expiresIn = 0 + var minInterval: Int = verificationManager.startedInterval - // min interval is 10 seconds - if (minInterval < 10) { - minInterval = 10; - } + token?.let { + expiresIn = it.expiresIn - if (runnable == null) { - runnable = Runnable { - verificationManager.logger.d("Token request interval fired") + // if expiresIn is shorter than interval, override interval + // re-request early to maximize the likelihood that a cached token is available + minInterval = minOf(it.expiresIn - 10, verificationManager.startedInterval) + } - callTrackVerified() - } - } + // min interval is 10 seconds + if (minInterval < 10) { + minInterval = 10; + } - runnable?.let { - handler.removeCallbacks(it) + if (runnable == null) { + runnable = Runnable { + verificationManager.logger.d("Token request interval fired") - if (!verificationManager.started) { - return - } + callTrackVerified() + } + } - verificationManager.logger.d("Requesting token again in $minInterval seconds | minInterval = $minInterval; expiresIn = $expiresIn; interval = ${verificationManager.startedInterval}") + runnable?.let { + handler.removeCallbacks(it) - handler.postDelayed(it, minInterval * 1000L) - } + if (!verificationManager.started) { + return } - }) + + verificationManager.logger.d("Requesting token again in $minInterval seconds | minInterval = $minInterval; expiresIn = $expiresIn; interval = ${verificationManager.startedInterval}") + + handler.postDelayed(it, minInterval * 1000L) + } } fun startTrackingVerified(interval: Int, beacons: Boolean) { @@ -345,7 +351,11 @@ internal class RadarVerificationManager( Radar.locationManager.locationClient.requestLocationUpdates(RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH, 0, 0, RadarLocationReceiver.getVerifiedLocationPendingIntent(context)) } - callTrackVerified() + if (this.isLastTokenValid()) { + this.scheduleNextInterval(this.lastToken) + } else { + callTrackVerified() + } } fun stopTrackingVerified() { @@ -368,30 +378,39 @@ internal class RadarVerificationManager( } } - fun getVerifiedLocationToken(callback: Radar.RadarTrackVerifiedCallback? = null) { - val lastTokenElapsed = (SystemClock.elapsedRealtime() - this.lastTokenElapsedRealtime) / 1000 + fun getVerifiedLocationToken(beacons: Boolean, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy, callback: Radar.RadarTrackVerifiedCallback? = null) { + if (this.isLastTokenValid()) { + Radar.flushLogs() + + callback?.onComplete(Radar.RadarStatus.SUCCESS, this.lastToken) + + return + } + + this.trackVerified(beacons, desiredAccuracy, callback) + } - if (this.lastToken != null) { - this.lastToken?.let { - val lastDistanceToStateBorder = it.user.state?.distanceToBorder ?: -1.0 + fun clearVerifiedLocationToken() { + this.lastToken = null + } - if (lastTokenElapsed < it.expiresIn && it.passed && lastDistanceToStateBorder > 1609) { - Radar.logger.d("Last token valid | lastToken.expiresIn = ${it.expiresIn}; lastTokenElapsed = $lastTokenElapsed; lastToken.passed = ${it.passed}; lastDistanceToStateBorder = $lastDistanceToStateBorder") + fun isLastTokenValid(): Boolean { + val lastToken = this.lastToken ?: return false - Radar.flushLogs() + val lastTokenElapsed = (SystemClock.elapsedRealtime() - this.lastTokenElapsedRealtime) / 1000 + val lastDistanceToStateBorder = lastToken.user.state?.distanceToBorder ?: -1.0 - callback?.onComplete(Radar.RadarStatus.SUCCESS, it) + val lastTokenValid = lastTokenElapsed < lastToken.expiresIn && lastToken.passed && lastDistanceToStateBorder > 1609 - return - } + if (lastTokenValid) { + Radar.logger.d("Last token valid | lastToken.expiresIn = ${lastToken.expiresIn}; lastTokenElapsed = $lastTokenElapsed; lastToken.passed = ${lastToken.passed}; lastDistanceToStateBorder = $lastDistanceToStateBorder") - Radar.logger.d("Last token invalid | lastToken.expiresIn = ${it.expiresIn}; lastTokenElapsed = $lastTokenElapsed; lastToken.passed = ${it.passed}; lastDistanceToStateBorder = $lastDistanceToStateBorder") - } + Radar.flushLogs() } else { - Radar.logger.d("No last token") + Radar.logger.d("Last token invalid | lastToken.expiresIn = ${lastToken.expiresIn}; lastTokenElapsed = $lastTokenElapsed; lastToken.passed = ${lastToken.passed}; lastDistanceToStateBorder = $lastDistanceToStateBorder") } - this.trackVerified(this.lastTokenBeacons, callback) + return lastTokenValid } fun setExpectedJurisdiction(countryCode: String?, stateCode: String?) { From 2d9d15d17e82937daa4e4022e87cf618ac31ca19 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 10 Jan 2025 12:07:07 -0500 Subject: [PATCH 2/9] remove extra flushLogs() --- sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt index 593b0ef1..ab2bcd6c 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt @@ -404,8 +404,6 @@ internal class RadarVerificationManager( if (lastTokenValid) { Radar.logger.d("Last token valid | lastToken.expiresIn = ${lastToken.expiresIn}; lastTokenElapsed = $lastTokenElapsed; lastToken.passed = ${lastToken.passed}; lastDistanceToStateBorder = $lastDistanceToStateBorder") - - Radar.flushLogs() } else { Radar.logger.d("Last token invalid | lastToken.expiresIn = ${lastToken.expiresIn}; lastTokenElapsed = $lastTokenElapsed; lastToken.passed = ${lastToken.passed}; lastDistanceToStateBorder = $lastDistanceToStateBorder") } From 06386f9d3f7fab4bfe5cc1c1f89bdc061fc5cb97 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 10 Jan 2025 12:14:56 -0500 Subject: [PATCH 3/9] remove extra signatures --- sdk/src/main/java/io/radar/sdk/Radar.kt | 42 ++++--------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/Radar.kt b/sdk/src/main/java/io/radar/sdk/Radar.kt index f3c3e935..3482369a 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -1004,7 +1004,7 @@ object Radar { */ @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @JvmStatic - fun trackVerified(beacons: Boolean = false, callback: RadarTrackVerifiedCallback? = null) { + fun trackVerified(beacons: Boolean = false, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback: RadarTrackVerifiedCallback? = null) { if (!initialized) { callback?.onComplete(RadarStatus.ERROR_PUBLISHABLE_KEY) @@ -1016,7 +1016,7 @@ object Radar { this.verificationManager = RadarVerificationManager(this.context, this.logger) } - this.verificationManager.trackVerified(beacons, callback) + this.verificationManager.trackVerified(beacons, desiredAccuracy, callback) } /** @@ -1031,8 +1031,8 @@ object Radar { */ @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @JvmStatic - fun trackVerified(beacons: Boolean = false, block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { - trackVerified(beacons, object : RadarTrackVerifiedCallback { + fun trackVerified(beacons: Boolean = false, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { + trackVerified(beacons, desiredAccuracy, object : RadarTrackVerifiedCallback { override fun onComplete(status: RadarStatus, token: RadarVerifiedLocationToken?) { block(status, token) } @@ -1084,36 +1084,6 @@ object Radar { this.verificationManager.stopTrackingVerified() } - /** - * Returns the user's last verified location token if still valid, or requests a fresh token if not. - * - * Note that you must configure SSL pinning before calling this method. - * - * @see [](https://radar.com/documentation/fraud) - * - * @param[callback] An optional callback. - */ - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - @JvmStatic - fun getVerifiedLocationToken(callback: RadarTrackVerifiedCallback? = null) { - getVerifiedLocationToken(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback) - } - - /** - * Returns the user's last verified location token if still valid, or requests a fresh token if not. - * - * Note that you must configure SSL pinning before calling this method. - * - * @see [](https://radar.com/documentation/fraud) - * - * @param[block] A block callback. - */ - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - @JvmStatic - fun getVerifiedLocationToken(block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { - getVerifiedLocationToken(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, block) - } - /** * Returns the user's last verified location token if still valid, or requests a fresh token if not. * @@ -1127,7 +1097,7 @@ object Radar { */ @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @JvmStatic - fun getVerifiedLocationToken(beacons: Boolean, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy, callback: RadarTrackVerifiedCallback? = null) { + fun getVerifiedLocationToken(beacons: Boolean = false, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback: RadarTrackVerifiedCallback? = null) { if (!initialized) { callback?.onComplete(RadarStatus.ERROR_PUBLISHABLE_KEY) @@ -1155,7 +1125,7 @@ object Radar { */ @RequiresApi(Build.VERSION_CODES.LOLLIPOP) @JvmStatic - fun getVerifiedLocationToken(beacons: Boolean, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy, block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { + fun getVerifiedLocationToken(beacons: Boolean = false, desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { getVerifiedLocationToken(beacons, desiredAccuracy, object : RadarTrackVerifiedCallback { override fun onComplete(status: RadarStatus, token: RadarVerifiedLocationToken?) { block(status, token) From b697a765b9bfcc6b0e5ffe6552c2a4418288331c Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Mon, 13 Jan 2025 10:41:40 -0500 Subject: [PATCH 4/9] beta, no param signature --- sdk/build.gradle | 2 +- sdk/src/main/java/io/radar/sdk/Radar.kt | 60 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 481dd1fa..4ad826bb 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.19.0' + radarVersion = '3.19.0-beta.1' } 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 3482369a..fe03d027 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -992,6 +992,36 @@ object Radar { }) } + /** + * Tracks the user's location with device integrity information for location verification use cases. + * + * Note that you must configure SSL pinning before calling this method. + * + * @see [](https://radar.com/documentation/fraud) + * + * @param[callback] An optional callback. + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun trackVerified(callback: RadarTrackVerifiedCallback? = null) { + trackVerified(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback) + } + + /** + * Tracks the user's location with device integrity information for location verification use cases. + * + * Note that you must configure SSL pinning before calling this method. + * + * @see [](https://radar.com/documentation/fraud) + * + * @param[block] A block callback. + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun trackVerified(block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { + trackVerified(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, block) + } + /** * Tracks the user's location with device integrity information for location verification use cases. * @@ -1084,6 +1114,36 @@ object Radar { this.verificationManager.stopTrackingVerified() } + /** + * Returns the user's last verified location token if still valid, or requests a fresh token if not. + * + * Note that you must configure SSL pinning before calling this method. + * + * @see [](https://radar.com/documentation/fraud) + * + * @param[callback] An optional callback. + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun getVerifiedLocationToken(callback: RadarTrackVerifiedCallback? = null) { + getVerifiedLocationToken(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, callback) + } + + /** + * Returns the user's last verified location token if still valid, or requests a fresh token if not. + * + * Note that you must configure SSL pinning before calling this method. + * + * @see [](https://radar.com/documentation/fraud) + * + * @param[block] A block callback. + */ + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) + @JvmStatic + fun getVerifiedLocationToken(block: (status: RadarStatus, token: RadarVerifiedLocationToken?) -> Unit) { + getVerifiedLocationToken(false, RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, block) + } + /** * Returns the user's last verified location token if still valid, or requests a fresh token if not. * From d8f1ebe8f8252fbcccebf0ca951fe36aeb24a0df Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Mon, 13 Jan 2025 11:04:54 -0500 Subject: [PATCH 5/9] beta.3 --- sdk/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 4ad826bb..89046721 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.19.0-beta.1' + radarVersion = '3.19.0-beta.3' } String buildNumber = ".${System.currentTimeMillis()}" From 0e0046beb0e59a9b0d1f290d4503f94cd84ed131 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Mon, 13 Jan 2025 13:37:19 -0500 Subject: [PATCH 6/9] incorporate lastTokenElapsed into minInterval calculation --- .../io/radar/sdk/RadarVerificationManager.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt index ab2bcd6c..fdf9a250 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt @@ -244,23 +244,27 @@ internal class RadarVerificationManager( status: Radar.RadarStatus, token: RadarVerifiedLocationToken? ) { - verificationManager.scheduleNextInterval(token) + verificationManager.scheduleNextIntervalWithLastToken() } }) } - fun scheduleNextInterval(token: RadarVerifiedLocationToken?) { + fun scheduleNextIntervalWithLastToken() { val verificationManager = this var expiresIn = 0 var minInterval: Int = verificationManager.startedInterval - token?.let { + this.lastToken?.let { expiresIn = it.expiresIn + val lastTokenElapsed = (SystemClock.elapsedRealtime() - this.lastTokenElapsedRealtime).toInt() / 1000 + // if expiresIn is shorter than interval, override interval // re-request early to maximize the likelihood that a cached token is available - minInterval = minOf(it.expiresIn - 10, verificationManager.startedInterval) + minInterval = minOf(it.expiresIn - 10 - lastTokenElapsed, verificationManager.startedInterval) + + verificationManager.logger.d("Calculated next interval | minInterval = $minInterval; expiresIn = $expiresIn; lastTokenElapsed = $lastTokenElapsed; startedInterval = ${verificationManager.startedInterval}") } // min interval is 10 seconds @@ -283,7 +287,7 @@ internal class RadarVerificationManager( return } - verificationManager.logger.d("Requesting token again in $minInterval seconds | minInterval = $minInterval; expiresIn = $expiresIn; interval = ${verificationManager.startedInterval}") + verificationManager.logger.d("Requesting token again in $minInterval seconds") handler.postDelayed(it, minInterval * 1000L) } @@ -352,7 +356,7 @@ internal class RadarVerificationManager( } if (this.isLastTokenValid()) { - this.scheduleNextInterval(this.lastToken) + this.scheduleNextIntervalWithLastToken() } else { callTrackVerified() } From 416594552535e3063db902f7f4da29d8b6f490bd Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Mon, 13 Jan 2025 14:00:17 -0500 Subject: [PATCH 7/9] remove extra init --- .../java/io/radar/sdk/RadarVerificationManager.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt index fdf9a250..bac318fc 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt @@ -252,24 +252,23 @@ internal class RadarVerificationManager( fun scheduleNextIntervalWithLastToken() { val verificationManager = this - var expiresIn = 0 var minInterval: Int = verificationManager.startedInterval this.lastToken?.let { - expiresIn = it.expiresIn - val lastTokenElapsed = (SystemClock.elapsedRealtime() - this.lastTokenElapsedRealtime).toInt() / 1000 // if expiresIn is shorter than interval, override interval // re-request early to maximize the likelihood that a cached token is available - minInterval = minOf(it.expiresIn - 10 - lastTokenElapsed, verificationManager.startedInterval) + minInterval = minOf(it.expiresIn - lastTokenElapsed, verificationManager.startedInterval) verificationManager.logger.d("Calculated next interval | minInterval = $minInterval; expiresIn = $expiresIn; lastTokenElapsed = $lastTokenElapsed; startedInterval = ${verificationManager.startedInterval}") } + var interval = minInterval - 10 + // min interval is 10 seconds - if (minInterval < 10) { - minInterval = 10; + if (interval < 10) { + interval = 10 } if (runnable == null) { @@ -287,9 +286,9 @@ internal class RadarVerificationManager( return } - verificationManager.logger.d("Requesting token again in $minInterval seconds") + verificationManager.logger.d("Requesting token again in $interval seconds") - handler.postDelayed(it, minInterval * 1000L) + handler.postDelayed(it, interval * 1000L) } } From f2875ad638ae5e1a0ff3000fe5cd05f1c968c2f5 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Mon, 13 Jan 2025 14:00:40 -0500 Subject: [PATCH 8/9] remove extra init --- sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt index bac318fc..0fb201b8 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt @@ -261,7 +261,7 @@ internal class RadarVerificationManager( // re-request early to maximize the likelihood that a cached token is available minInterval = minOf(it.expiresIn - lastTokenElapsed, verificationManager.startedInterval) - verificationManager.logger.d("Calculated next interval | minInterval = $minInterval; expiresIn = $expiresIn; lastTokenElapsed = $lastTokenElapsed; startedInterval = ${verificationManager.startedInterval}") + verificationManager.logger.d("Calculated next interval | minInterval = $minInterval; expiresIn = ${it.expiresIn}; lastTokenElapsed = $lastTokenElapsed; startedInterval = ${verificationManager.startedInterval}") } var interval = minInterval - 10 From 161e4ca20f511141823b9ed9e7c2655a7bdb36fc Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Tue, 14 Jan 2025 06:44:51 -0500 Subject: [PATCH 9/9] bump version --- sdk/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 89046721..481dd1fa 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.19.0-beta.3' + radarVersion = '3.19.0' } String buildNumber = ".${System.currentTimeMillis()}"