@@ -24,6 +24,7 @@ import com.mapbox.navigation.core.trip.session.NavigationSession
2424import com.mapbox.navigation.core.trip.session.NavigationSessionState
2525import com.mapbox.navigation.core.trip.session.NavigationSessionStateObserver
2626import com.mapbox.navigation.core.trip.session.TripSession
27+ import com.mapbox.navigation.utils.internal.logI
2728import com.mapbox.navigation.utils.internal.logW
2829import com.mapbox.turf.TurfConstants.UNIT_METRES
2930import com.mapbox.turf.TurfMeasurement
@@ -193,6 +194,7 @@ internal class BillingController(
193194
194195 private companion object {
195196 private const val logCategory = " BillingController"
197+ private const val BILLING_EXPLANATION_CATEGORY = " BillingExplanation"
196198 private const val MAX_WAYPOINTS_DISTANCE_DIFF_METERS = 100.0
197199 }
198200
@@ -215,18 +217,23 @@ internal class BillingController(
215217 is NavigationSessionState .Idle -> {
216218 getRunningOrPausedSessionSkuId()?.let {
217219 billingService.pauseBillingSession(it)
220+ logI(BILLING_EXPLANATION_CATEGORY ) {
221+ " ${it.publicName} has been paused because Nav SDK is in Idle state"
222+ }
218223 }
219224 }
220225 is NavigationSessionState .FreeDrive -> {
221226 resumeOrBeginBillingSession(
222227 SessionSKUIdentifier .NAV2_SES_FDTRIP ,
223- validity = TimeUnit .HOURS .toMillis(1 ) // validity of 1hr
228+ validity = TimeUnit .HOURS .toMillis(1 ), // validity of 1hr
229+ " Nav SDK is in free drive state"
224230 )
225231 }
226232 is NavigationSessionState .ActiveGuidance -> {
227233 resumeOrBeginBillingSession(
228234 SessionSKUIdentifier .NAV2_SES_TRIP ,
229- validity = 0 // default validity, 12hrs
235+ validity = 0 , // default validity, 12hrs
236+ " Nav SDK is in Active Guidance state"
230237 )
231238 }
232239 }
@@ -247,7 +254,8 @@ internal class BillingController(
247254 }
248255 beginBillingSession(
249256 SessionSKUIdentifier .NAV2_SES_TRIP ,
250- validity = 0 // default validity, 12hrs
257+ validity = 0 , // default validity, 12hrs
258+ " Nav SDK switched to the next route leg"
251259 )
252260 }
253261
@@ -292,10 +300,17 @@ internal class BillingController(
292300 ) == BillingSessionStatus .SESSION_PAUSED
293301 beginBillingSession(
294302 SessionSKUIdentifier .NAV2_SES_TRIP ,
295- validity = 0 // default validity, 12hrs
303+ validity = 0 , // default validity, 12hrs
304+ " destination has been changed. " +
305+ " Old waypoints: $currentRemainingWaypoints ," +
306+ " new waypoints: $newWaypoints "
296307 )
297308 if (wasSessionPaused) {
298309 billingService.pauseBillingSession(SessionSKUIdentifier .NAV2_SES_TRIP )
310+ logI(BILLING_EXPLANATION_CATEGORY ) {
311+ " ${runningSessionSkuId.publicName} has been paused because " +
312+ " it used to be paused before destinations update"
313+ }
299314 }
300315 }
301316 }
@@ -317,6 +332,9 @@ internal class BillingController(
317332 arrivalProgressObserver.unregisterObserver(arrivalObserver)
318333 getRunningOrPausedSessionSkuId()?.let {
319334 billingService.stopBillingSession(it)
335+ logI(BILLING_EXPLANATION_CATEGORY ) {
336+ " ${it.publicName} has been stopped because Nav SDK is destroyed"
337+ }
320338 }
321339 }
322340
@@ -325,7 +343,8 @@ internal class BillingController(
325343 */
326344 private fun resumeOrBeginBillingSession (
327345 skuId : SessionSKUIdentifier ,
328- validity : Long
346+ validity : Long ,
347+ reason : String
329348 ) {
330349 val runningSessionSkuId = getRunningOrPausedSessionSkuId()
331350 if (runningSessionSkuId == skuId) {
@@ -336,11 +355,18 @@ internal class BillingController(
336355 " Session resumption failed, starting a new one instead." ,
337356 logCategory
338357 )
339- beginBillingSession(skuId, validity)
358+ logI(BILLING_EXPLANATION_CATEGORY ) {
359+ " Failed to resume ${skuId.publicName} (${it.message} )."
360+ }
361+ beginBillingSession(skuId, validity, reason)
362+ } else {
363+ logI(BILLING_EXPLANATION_CATEGORY ) {
364+ " ${skuId.publicName} has ben resumed because $reason "
365+ }
340366 }
341367 }
342368 } else {
343- beginBillingSession(skuId, validity)
369+ beginBillingSession(skuId, validity, reason )
344370 }
345371 }
346372
@@ -349,11 +375,15 @@ internal class BillingController(
349375 */
350376 private fun beginBillingSession (
351377 skuId : SessionSKUIdentifier ,
352- validity : Long
378+ validity : Long ,
379+ reason : String
353380 ) {
354381 val runningSessionSkuId = getRunningOrPausedSessionSkuId()
355382 if (runningSessionSkuId != null ) {
356383 billingService.stopBillingSession(runningSessionSkuId)
384+ logI(BILLING_EXPLANATION_CATEGORY ) {
385+ " ${runningSessionSkuId.publicName} has been stopped because $reason "
386+ }
357387 }
358388 billingService.beginBillingSession(
359389 accessToken,
@@ -364,6 +394,9 @@ internal class BillingController(
364394 },
365395 validity
366396 )
397+ logI(BILLING_EXPLANATION_CATEGORY ) {
398+ " ${skuId.publicName} has been started because $reason "
399+ }
367400 }
368401
369402 private fun getRunningOrPausedSessionSkuId (): SessionSKUIdentifier ? {
@@ -454,3 +487,8 @@ internal class BillingController(
454487 }
455488 }
456489}
490+
491+ private val SessionSKUIdentifier .publicName get() = when (this ) {
492+ SessionSKUIdentifier .NAV2_SES_TRIP -> " Active Guidance Trip Session"
493+ SessionSKUIdentifier .NAV2_SES_FDTRIP -> " Free Drive Trip Session"
494+ }
0 commit comments