Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Billing explanation logs #7747

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/unreleased/features/7710.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added billing explanation logs. Now Navigation SDK explains in the logs why certain Active Guidance or Free Drive Trip session started/stopped/paused/resumed. Billing explanations have `[BillingExplanation]` prefix in the logcat.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.mapbox.navigation.core.trip.session.NavigationSession
import com.mapbox.navigation.core.trip.session.NavigationSessionState
import com.mapbox.navigation.core.trip.session.NavigationSessionStateObserver
import com.mapbox.navigation.core.trip.session.TripSession
import com.mapbox.navigation.utils.internal.logI
import com.mapbox.navigation.utils.internal.logW
import com.mapbox.turf.TurfConstants.UNIT_METRES
import com.mapbox.turf.TurfMeasurement
Expand Down Expand Up @@ -193,6 +194,7 @@ internal class BillingController(

private companion object {
private const val logCategory = "BillingController"
private const val BILLING_EXPLANATION_CATEGORY = "BillingExplanation"
private const val MAX_WAYPOINTS_DISTANCE_DIFF_METERS = 100.0
}

Expand All @@ -215,18 +217,23 @@ internal class BillingController(
is NavigationSessionState.Idle -> {
getRunningOrPausedSessionSkuId()?.let {
billingService.pauseBillingSession(it)
logI(BILLING_EXPLANATION_CATEGORY) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VysotskiVadim I think we can test it, and check that we print correct reason to logs.

Copy link
Contributor Author

@VysotskiVadim VysotskiVadim Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, we can!
Let's not announce this feature in public documentation until unit tests are in place.

"${it.publicName} has been paused because Nav SDK is in Idle state"
}
}
}
is NavigationSessionState.FreeDrive -> {
resumeOrBeginBillingSession(
SessionSKUIdentifier.NAV2_SES_FDTRIP,
validity = TimeUnit.HOURS.toMillis(1) // validity of 1hr
validity = TimeUnit.HOURS.toMillis(1), // validity of 1hr
"Nav SDK is in free drive state"
)
}
is NavigationSessionState.ActiveGuidance -> {
resumeOrBeginBillingSession(
SessionSKUIdentifier.NAV2_SES_TRIP,
validity = 0 // default validity, 12hrs
validity = 0, // default validity, 12hrs
"Nav SDK is in Active Guidance state"
)
}
}
Expand All @@ -247,7 +254,8 @@ internal class BillingController(
}
beginBillingSession(
SessionSKUIdentifier.NAV2_SES_TRIP,
validity = 0 // default validity, 12hrs
validity = 0, // default validity, 12hrs
"Nav SDK switched to the next route leg"
)
}

Expand Down Expand Up @@ -292,10 +300,17 @@ internal class BillingController(
) == BillingSessionStatus.SESSION_PAUSED
beginBillingSession(
SessionSKUIdentifier.NAV2_SES_TRIP,
validity = 0 // default validity, 12hrs
validity = 0, // default validity, 12hrs
"destination has been changed. " +
"Old waypoints: $currentRemainingWaypoints," +
"new waypoints: $newWaypoints"
)
if (wasSessionPaused) {
billingService.pauseBillingSession(SessionSKUIdentifier.NAV2_SES_TRIP)
logI(BILLING_EXPLANATION_CATEGORY) {
"${runningSessionSkuId.publicName} has been paused because " +
"it used to be paused before destinations update"
}
}
}
}
Expand All @@ -317,6 +332,9 @@ internal class BillingController(
arrivalProgressObserver.unregisterObserver(arrivalObserver)
getRunningOrPausedSessionSkuId()?.let {
billingService.stopBillingSession(it)
logI(BILLING_EXPLANATION_CATEGORY) {
"${it.publicName} has been stopped because Nav SDK is destroyed"
}
}
}

Expand All @@ -325,7 +343,8 @@ internal class BillingController(
*/
private fun resumeOrBeginBillingSession(
skuId: SessionSKUIdentifier,
validity: Long
validity: Long,
reason: String
) {
val runningSessionSkuId = getRunningOrPausedSessionSkuId()
if (runningSessionSkuId == skuId) {
Expand All @@ -336,11 +355,18 @@ internal class BillingController(
"Session resumption failed, starting a new one instead.",
logCategory
)
beginBillingSession(skuId, validity)
logI(BILLING_EXPLANATION_CATEGORY) {
"Failed to resume ${skuId.publicName}(${it.message})."
}
beginBillingSession(skuId, validity, reason)
} else {
logI(BILLING_EXPLANATION_CATEGORY) {
"${skuId.publicName} has ben resumed because $reason"
}
}
}
} else {
beginBillingSession(skuId, validity)
beginBillingSession(skuId, validity, reason)
}
}

Expand All @@ -349,11 +375,15 @@ internal class BillingController(
*/
private fun beginBillingSession(
skuId: SessionSKUIdentifier,
validity: Long
validity: Long,
reason: String
) {
val runningSessionSkuId = getRunningOrPausedSessionSkuId()
if (runningSessionSkuId != null) {
billingService.stopBillingSession(runningSessionSkuId)
logI(BILLING_EXPLANATION_CATEGORY) {
"${runningSessionSkuId.publicName} has been stopped because $reason"
}
}
billingService.beginBillingSession(
accessToken,
Expand All @@ -364,6 +394,9 @@ internal class BillingController(
},
validity
)
logI(BILLING_EXPLANATION_CATEGORY) {
"${skuId.publicName} has been started because $reason"
}
}

private fun getRunningOrPausedSessionSkuId(): SessionSKUIdentifier? {
Expand Down Expand Up @@ -454,3 +487,8 @@ internal class BillingController(
}
}
}

private val SessionSKUIdentifier.publicName get() = when (this) {
SessionSKUIdentifier.NAV2_SES_TRIP -> "Active Guidance Trip Session"
SessionSKUIdentifier.NAV2_SES_FDTRIP -> "Free Drive Trip Session"
}
Loading