diff --git a/sdk/build.gradle b/sdk/build.gradle index e624fdfcd..f7ae41fe3 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.6' + radarVersion = '3.9.7' } 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 462566711..9c2f7da9d 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -535,15 +535,9 @@ object Radar { } val usage = "initialize" this.apiClient.getConfig(usage, false, object : RadarApiClient.RadarGetConfigApiCallback { - override fun onComplete(config: RadarConfig) { + override fun onComplete(status: RadarStatus, config: RadarConfig) { locationManager.updateTrackingFromMeta(config?.meta) RadarSettings.setFeatureSettings(context, config?.meta.featureSettings) - if (config?.googlePlayProjectNumber != null) { - RadarSettings.setGooglePlayProjectNumber( - context, - config?.googlePlayProjectNumber - ) - } } }) diff --git a/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt b/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt index 80763c64b..accef3215 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarActivityLifecycleCallbacks.kt @@ -50,7 +50,7 @@ internal class RadarActivityLifecycleCallbacks( if (updated) { val usage = "resume" Radar.apiClient.getConfig(usage, false, object : RadarApiClient.RadarGetConfigApiCallback { - override fun onComplete(config: RadarConfig) { + override fun onComplete(status: Radar.RadarStatus, config: RadarConfig) { Radar.locationManager.updateTrackingFromMeta(config.meta) RadarSettings.setFeatureSettings(activity.applicationContext, config.meta.featureSettings) } diff --git a/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt b/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt index 2f7c02ed8..27f096c27 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarApiClient.kt @@ -34,7 +34,7 @@ internal class RadarApiClient( } interface RadarGetConfigApiCallback { - fun onComplete(config: RadarConfig) + fun onComplete(status: RadarStatus, config: RadarConfig) } interface RadarTripApiCallback { @@ -138,7 +138,7 @@ internal class RadarApiClient( if (status == RadarStatus.SUCCESS) { Radar.flushLogs() } - callback?.onComplete(RadarConfig.fromJson(res)) + callback?.onComplete(status, RadarConfig.fromJson(res)) } }, false, true, verified) } diff --git a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt index 022cbf6f5..d0a564414 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt @@ -36,7 +36,6 @@ internal object RadarSettings { private const val KEY_VERIFIED_HOST = "verified_host" 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" @@ -376,14 +375,6 @@ internal object RadarSettings { getSharedPreferences(context).edit { putBoolean(KEY_SHARING, sharing) } } - internal fun getGooglePlayProjectNumber(context: Context): Long { - return getSharedPreferences(context).getLong(KEY_GOOGLE_PLAY_PROJECT_NUMBER, 0) - } - - internal fun setGooglePlayProjectNumber(context: Context, googlePlayProjectNumber: Long) { - 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) diff --git a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt index 52c18f8ec..624caa58d 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt @@ -40,267 +40,307 @@ internal class RadarVerificationManager( fun trackVerified(beacons: Boolean = false, callback: Radar.RadarTrackCallback? = null) { val verificationManager = this - val googlePlayProjectNumber = RadarSettings.getGooglePlayProjectNumber(this.context) - - Radar.locationManager.getLocation( - RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, - Radar.RadarLocationSource.FOREGROUND_LOCATION, - object : - Radar.RadarLocationCallback { - override fun onComplete( - status: Radar.RadarStatus, - location: Location?, - stopped: Boolean - ) { - if (status != Radar.RadarStatus.SUCCESS || location == null) { - Radar.handler.post { - callback?.onComplete(status) - } - - return + val usage = "trackVerified" + Radar.apiClient.getConfig(usage, true, object : RadarApiClient.RadarGetConfigApiCallback { + override fun onComplete(status: Radar.RadarStatus, config: RadarConfig) { + val googlePlayProjectNumber = config.googlePlayProjectNumber + + if (status != Radar.RadarStatus.SUCCESS) { + Radar.handler.post { + callback?.onComplete(status) } - val requestHash = verificationManager.getRequestHash(location) - - verificationManager.getIntegrityToken( - googlePlayProjectNumber, - requestHash - ) { integrityToken, integrityException -> - val callTrackApi = { beacons: Array? -> - Radar.apiClient.track( - location, - RadarState.getStopped(verificationManager.context), - RadarActivityLifecycleCallbacks.foreground, - Radar.RadarLocationSource.FOREGROUND_LOCATION, - false, - beacons, - true, - integrityToken, - integrityException, - false, - callback = object : RadarApiClient.RadarTrackApiCallback { - override fun onComplete( - status: Radar.RadarStatus, - res: JSONObject?, - events: Array?, - user: RadarUser?, - nearbyGeofences: Array?, - config: RadarConfig?, - token: String? - ) { - if (status == Radar.RadarStatus.SUCCESS) { - Radar.locationManager.updateTrackingFromMeta(config?.meta) - } - Radar.handler.post { - callback?.onComplete(status, location, events, user) - } - } - }) - } + return + } - if (beacons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Radar.apiClient.searchBeacons( - location, - 1000, - 10, - object : RadarApiClient.RadarSearchBeaconsApiCallback { - override fun onComplete( - status: Radar.RadarStatus, - res: JSONObject?, - beacons: Array?, - uuids: Array?, - uids: Array? - ) { - if (!uuids.isNullOrEmpty() || !uids.isNullOrEmpty()) { - Radar.beaconManager.startMonitoringBeaconUUIDs( - uuids, - uids - ) - - Radar.beaconManager.rangeBeaconUUIDs( - uuids, - uids, - false, - object : Radar.RadarBeaconCallback { - override fun onComplete( - status: Radar.RadarStatus, - beacons: Array? - ) { - if (status != Radar.RadarStatus.SUCCESS || beacons == null) { - callTrackApi(null) - - return - } - - callTrackApi(beacons) - } - }) - } else if (beacons != null) { - Radar.beaconManager.startMonitoringBeacons(beacons) - - Radar.beaconManager.rangeBeacons( - beacons, - false, - object : Radar.RadarBeaconCallback { - override fun onComplete( - status: Radar.RadarStatus, - beacons: Array? - ) { - if (status != Radar.RadarStatus.SUCCESS || beacons == null) { - callTrackApi(null) - - return - } - - callTrackApi(beacons) - } - }) - } else { - callTrackApi(arrayOf()) - } - } - }, - false - ) - } else { - callTrackApi(null) + Radar.locationManager.getLocation( + RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM, + Radar.RadarLocationSource.FOREGROUND_LOCATION, + object : + Radar.RadarLocationCallback { + override fun onComplete( + status: Radar.RadarStatus, + location: Location?, + stopped: Boolean + ) { + if (status != Radar.RadarStatus.SUCCESS || location == null) { + Radar.handler.post { + callback?.onComplete(status) + } + + return + } + + val requestHash = verificationManager.getRequestHash(location) + + verificationManager.getIntegrityToken( + googlePlayProjectNumber, + requestHash + ) { integrityToken, integrityException -> + val callTrackApi = { beacons: Array? -> + Radar.apiClient.track( + location, + RadarState.getStopped(verificationManager.context), + RadarActivityLifecycleCallbacks.foreground, + Radar.RadarLocationSource.FOREGROUND_LOCATION, + false, + beacons, + true, + integrityToken, + integrityException, + false, + callback = object : RadarApiClient.RadarTrackApiCallback { + override fun onComplete( + status: Radar.RadarStatus, + res: JSONObject?, + events: Array?, + user: RadarUser?, + nearbyGeofences: Array?, + config: RadarConfig?, + token: String? + ) { + if (status == Radar.RadarStatus.SUCCESS) { + Radar.locationManager.updateTrackingFromMeta( + config?.meta + ) + } + Radar.handler.post { + callback?.onComplete( + status, + location, + events, + user + ) + } + } + }) + } + + if (beacons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Radar.apiClient.searchBeacons( + location, + 1000, + 10, + object : RadarApiClient.RadarSearchBeaconsApiCallback { + override fun onComplete( + status: Radar.RadarStatus, + res: JSONObject?, + beacons: Array?, + uuids: Array?, + uids: Array? + ) { + if (!uuids.isNullOrEmpty() || !uids.isNullOrEmpty()) { + Radar.beaconManager.startMonitoringBeaconUUIDs( + uuids, + uids + ) + + Radar.beaconManager.rangeBeaconUUIDs( + uuids, + uids, + false, + object : Radar.RadarBeaconCallback { + override fun onComplete( + status: Radar.RadarStatus, + beacons: Array? + ) { + if (status != Radar.RadarStatus.SUCCESS || beacons == null) { + callTrackApi(null) + + return + } + + callTrackApi(beacons) + } + }) + } else if (beacons != null) { + Radar.beaconManager.startMonitoringBeacons( + beacons + ) + + Radar.beaconManager.rangeBeacons( + beacons, + false, + object : Radar.RadarBeaconCallback { + override fun onComplete( + status: Radar.RadarStatus, + beacons: Array? + ) { + if (status != Radar.RadarStatus.SUCCESS || beacons == null) { + callTrackApi(null) + + return + } + + callTrackApi(beacons) + } + }) + } else { + callTrackApi(arrayOf()) + } + } + }, + false + ) + } else { + callTrackApi(null) + } + } } - } - } - }) + }) + } + }) } fun trackVerifiedToken(beacons: Boolean = false, callback: Radar.RadarTrackTokenCallback? = null) { val verificationManager = this - val googlePlayProjectNumber = RadarSettings.getGooglePlayProjectNumber(this.context) - - Radar.locationManager.getLocation( - RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH, - Radar.RadarLocationSource.FOREGROUND_LOCATION, - object : - Radar.RadarLocationCallback { - override fun onComplete( - status: Radar.RadarStatus, - location: Location?, - stopped: Boolean - ) { - if (status != Radar.RadarStatus.SUCCESS || location == null) { - Radar.handler.post { - callback?.onComplete(status) - } + val usage = "trackVerifiedToken" + Radar.apiClient.getConfig(usage, true, object : RadarApiClient.RadarGetConfigApiCallback { + override fun onComplete(status: Radar.RadarStatus, config: RadarConfig) { + val googlePlayProjectNumber = config.googlePlayProjectNumber - return + if (status != Radar.RadarStatus.SUCCESS) { + Radar.handler.post { + callback?.onComplete(status) } - val requestHash = verificationManager.getRequestHash(location) - - verificationManager.getIntegrityToken( - googlePlayProjectNumber, - requestHash - ) { integrityToken, integrityException -> - val callTrackApi = { beacons: Array? -> - Radar.apiClient.track( - location, - RadarState.getStopped(verificationManager.context), - RadarActivityLifecycleCallbacks.foreground, - Radar.RadarLocationSource.FOREGROUND_LOCATION, - false, - beacons, - true, - integrityToken, - integrityException, - true, - object : RadarApiClient.RadarTrackApiCallback { - override fun onComplete( - status: Radar.RadarStatus, - res: JSONObject?, - events: Array?, - user: RadarUser?, - nearbyGeofences: Array?, - config: RadarConfig?, - token: String? - ) { - if (status == Radar.RadarStatus.SUCCESS) { - Radar.locationManager.updateTrackingFromMeta(config?.meta) - } - Radar.handler.post { - callback?.onComplete(status, token) - } - } - }) - } + return - if (beacons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Radar.apiClient.searchBeacons( - location, - 1000, - 10, - object : RadarApiClient.RadarSearchBeaconsApiCallback { - override fun onComplete( - status: Radar.RadarStatus, - res: JSONObject?, - beacons: Array?, - uuids: Array?, - uids: Array? - ) { - if (!uuids.isNullOrEmpty() || !uids.isNullOrEmpty()) { - Radar.beaconManager.startMonitoringBeaconUUIDs( - uuids, - uids - ) - - Radar.beaconManager.rangeBeaconUUIDs( - uuids, - uids, - false, - object : Radar.RadarBeaconCallback { - override fun onComplete( - status: Radar.RadarStatus, - beacons: Array? - ) { - if (status != Radar.RadarStatus.SUCCESS || beacons == null) { - callTrackApi(null) - - return - } - - callTrackApi(beacons) - } - }) - } else if (beacons != null) { - Radar.beaconManager.startMonitoringBeacons(beacons) - - Radar.beaconManager.rangeBeacons( - beacons, - false, - object : Radar.RadarBeaconCallback { - override fun onComplete( - status: Radar.RadarStatus, - beacons: Array? - ) { - if (status != Radar.RadarStatus.SUCCESS || beacons == null) { - callTrackApi(null) - - return - } - - callTrackApi(beacons) - } - }) - } else { - callTrackApi(arrayOf()) - } - } - }, - false - ) - } else { - callTrackApi(null) - } - } } - }) + + Radar.locationManager.getLocation( + RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH, + Radar.RadarLocationSource.FOREGROUND_LOCATION, + object : + Radar.RadarLocationCallback { + override fun onComplete( + status: Radar.RadarStatus, + location: Location?, + stopped: Boolean + ) { + if (status != Radar.RadarStatus.SUCCESS || location == null) { + Radar.handler.post { + callback?.onComplete(status) + } + + return + } + + val requestHash = verificationManager.getRequestHash(location) + + verificationManager.getIntegrityToken( + googlePlayProjectNumber, + requestHash + ) { integrityToken, integrityException -> + val callTrackApi = { beacons: Array? -> + Radar.apiClient.track( + location, + RadarState.getStopped(verificationManager.context), + RadarActivityLifecycleCallbacks.foreground, + Radar.RadarLocationSource.FOREGROUND_LOCATION, + false, + beacons, + true, + integrityToken, + integrityException, + true, + object : RadarApiClient.RadarTrackApiCallback { + override fun onComplete( + status: Radar.RadarStatus, + res: JSONObject?, + events: Array?, + user: RadarUser?, + nearbyGeofences: Array?, + config: RadarConfig?, + token: String? + ) { + if (status == Radar.RadarStatus.SUCCESS) { + Radar.locationManager.updateTrackingFromMeta( + config?.meta + ) + } + Radar.handler.post { + callback?.onComplete(status, token) + } + } + }) + } + + if (beacons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Radar.apiClient.searchBeacons( + location, + 1000, + 10, + object : RadarApiClient.RadarSearchBeaconsApiCallback { + override fun onComplete( + status: Radar.RadarStatus, + res: JSONObject?, + beacons: Array?, + uuids: Array?, + uids: Array? + ) { + if (!uuids.isNullOrEmpty() || !uids.isNullOrEmpty()) { + Radar.beaconManager.startMonitoringBeaconUUIDs( + uuids, + uids + ) + + Radar.beaconManager.rangeBeaconUUIDs( + uuids, + uids, + false, + object : Radar.RadarBeaconCallback { + override fun onComplete( + status: Radar.RadarStatus, + beacons: Array? + ) { + if (status != Radar.RadarStatus.SUCCESS || beacons == null) { + callTrackApi(null) + + return + } + + callTrackApi(beacons) + } + }) + } else if (beacons != null) { + Radar.beaconManager.startMonitoringBeacons( + beacons + ) + + Radar.beaconManager.rangeBeacons( + beacons, + false, + object : Radar.RadarBeaconCallback { + override fun onComplete( + status: Radar.RadarStatus, + beacons: Array? + ) { + if (status != Radar.RadarStatus.SUCCESS || beacons == null) { + callTrackApi(null) + + return + } + + callTrackApi(beacons) + } + }) + } else { + callTrackApi(arrayOf()) + } + } + }, + false + ) + } else { + callTrackApi(null) + } + } + } + }) + } + }) } fun startTrackingVerified(token: Boolean, interval: Int, beacons: Boolean) {