@@ -10,11 +10,11 @@ import android.os.Build
1010import android.os.Handler
1111import android.os.SystemClock
1212import androidx.annotation.RequiresApi
13+ import com.google.android.gms.tasks.Task
14+ import com.google.android.play.core.integrity.IntegrityManagerFactory
1315import com.google.android.play.core.integrity.StandardIntegrityManager
1416import com.google.android.play.core.integrity.StandardIntegrityManager.StandardIntegrityToken
1517import com.google.android.play.core.integrity.StandardIntegrityManager.StandardIntegrityTokenRequest
16- import com.google.android.gms.tasks.Task
17- import com.google.android.play.core.integrity.IntegrityManagerFactory
1818import io.radar.sdk.RadarUtils.hashSHA256
1919import io.radar.sdk.model.RadarBeacon
2020import io.radar.sdk.model.RadarConfig
@@ -73,9 +73,14 @@ internal class RadarVerificationManager(
7373 val verificationManager = this
7474 val lastTokenBeacons = beacons
7575
76+ val profiler = RadarProfiler ()
77+ profiler.start(" total" )
78+ profiler.start(" getConfig" )
79+
7680 val usage = " trackVerified"
7781 Radar .apiClient.getConfig(usage, true , object : RadarApiClient .RadarGetConfigApiCallback {
7882 override fun onComplete (status : Radar .RadarStatus , config : RadarConfig ? ) {
83+ profiler.end(" getConfig" )
7984 if (status != Radar .RadarStatus .SUCCESS || config == null ) {
8085 Radar .handler.post {
8186 if (status != Radar .RadarStatus .SUCCESS ) {
@@ -90,6 +95,8 @@ internal class RadarVerificationManager(
9095
9196 val googlePlayProjectNumber = config.googlePlayProjectNumber
9297
98+ profiler.start(" getLocation" )
99+
93100 Radar .locationManager.getLocation(
94101 desiredAccuracy,
95102 Radar .RadarLocationSource .FOREGROUND_LOCATION ,
@@ -100,6 +107,8 @@ internal class RadarVerificationManager(
100107 location : Location ? ,
101108 stopped : Boolean
102109 ) {
110+ profiler.end(" getLocation" )
111+
103112 if (status != Radar .RadarStatus .SUCCESS || location == null ) {
104113 Radar .handler.post {
105114 if (status != Radar .RadarStatus .SUCCESS ) {
@@ -112,13 +121,19 @@ internal class RadarVerificationManager(
112121 return
113122 }
114123
124+ profiler.start(" getIntegrityToken" )
125+
115126 val requestHash = verificationManager.getRequestHash(location)
116127
117128 verificationManager.getIntegrityToken(
118129 googlePlayProjectNumber,
119130 requestHash
120131 ) { integrityToken, integrityException ->
132+
133+ profiler.end(" getIntegrityToken" )
134+
121135 val callTrackApi = { beacons: Array <RadarBeacon >? ->
136+ profiler.start(" trackAPI" )
122137 Radar .apiClient.track(
123138 location,
124139 RadarState .getStopped(verificationManager.context),
@@ -144,6 +159,7 @@ internal class RadarVerificationManager(
144159 config : RadarConfig ? ,
145160 token : RadarVerifiedLocationToken ?
146161 ) {
162+ profiler.end(" trackAPI" )
147163 if (status == Radar .RadarStatus .SUCCESS ) {
148164 Radar .locationManager.updateTrackingFromMeta(
149165 config?.meta
@@ -154,6 +170,10 @@ internal class RadarVerificationManager(
154170 verificationManager.lastTokenElapsedRealtime = SystemClock .elapsedRealtime()
155171 verificationManager.lastTokenBeacons = lastTokenBeacons
156172 }
173+
174+ profiler.end(" total" )
175+ logger.i(" trackVerified | ${profiler.formatted()} " , Radar .RadarLogType .PROFILER )
176+
157177 Radar .handler.post {
158178 if (status != Radar .RadarStatus .SUCCESS ) {
159179 Radar .sendError(status)
@@ -166,6 +186,8 @@ internal class RadarVerificationManager(
166186 }
167187
168188 if (beacons && Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
189+
190+ profiler.start(" searchBeacons" )
169191 Radar .apiClient.searchBeacons(
170192 location,
171193 1000 ,
@@ -178,6 +200,7 @@ internal class RadarVerificationManager(
178200 uuids : Array <String >? ,
179201 uids : Array <String >?
180202 ) {
203+ profiler.end(" searchBeacons" )
181204 if (! uuids.isNullOrEmpty() || ! uids.isNullOrEmpty()) {
182205 Radar .beaconManager.startMonitoringBeaconUUIDs(
183206 uuids,
@@ -199,14 +222,15 @@ internal class RadarVerificationManager(
199222 return
200223 }
201224
225+ profiler.start(" trackAPI" )
202226 callTrackApi(beacons)
203227 }
204228 })
205229 } else if (beacons != null ) {
206230 Radar .beaconManager.startMonitoringBeacons(
207231 beacons
208232 )
209-
233+ profiler.start( " rangeBeacons " )
210234 Radar .beaconManager.rangeBeacons(
211235 beacons,
212236 false ,
@@ -215,6 +239,8 @@ internal class RadarVerificationManager(
215239 status : Radar .RadarStatus ,
216240 beacons : Array <RadarBeacon >?
217241 ) {
242+ profiler.end(" rangeBeacons" )
243+
218244 if (status != Radar .RadarStatus .SUCCESS || beacons == null ) {
219245 callTrackApi(null )
220246
0 commit comments