Skip to content

Commit

Permalink
Copilot and MapboxNavigationApp debug logs (#7227)
Browse files Browse the repository at this point in the history
* Copilot and MapboxNavigationApp debug logs

* Add HistoryRecordingSessionState logs

GitOrigin-RevId: 223c56b0114a1ba33c822eaf072a4df8e5ccae09
  • Loading branch information
DzmitryFomchyn authored and Copybara committed Jan 30, 2025
1 parent 44489fb commit d1b03d5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.mapbox.navigation.copilot

import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
import com.mapbox.navigation.base.options.EventsAppMetadata
import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.copilot.MapboxCopilot.push
import com.mapbox.navigation.copilot.MapboxCopilot.start
import com.mapbox.navigation.copilot.MapboxCopilot.stop
import com.mapbox.navigation.copilot.MapboxCopilotImpl.Companion.LOG_CATEGORY
import com.mapbox.navigation.copilot.internal.PushStatusObserver
import com.mapbox.navigation.core.DeveloperMetadata
import com.mapbox.navigation.core.DeveloperMetadataObserver
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.internal.SdkInfoProvider
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver
import com.mapbox.navigation.utils.internal.logD
import java.util.concurrent.CopyOnWriteArraySet

/**
Expand Down Expand Up @@ -58,13 +63,15 @@ object MapboxCopilot : MapboxNavigationObserver {
* Starts Copilot.
*/
fun start() {
logD("MapboxCopilot started")
MapboxNavigationApp.registerObserver(this)
}

/**
* Stops Copilot.
*/
fun stop() {
logD("MapboxCopilot stopped")
MapboxNavigationApp.unregisterObserver(this)
}

Expand All @@ -85,8 +92,13 @@ object MapboxCopilot : MapboxNavigationObserver {
*/
override fun onAttached(mapboxNavigation: MapboxNavigation) {
if (copilot != null) {
logD("MapboxNavigation is attached, copilot instance is already instantiated")
return
}
logD(
"MapboxNavigation is attached, instantiate new copilot instance. " +
"Copilot options: ${mapboxNavigation.navigationOptions.copilotOptions}",
)
copilot = MapboxCopilotImpl(mapboxNavigation).also { it.start() }
}

Expand All @@ -97,7 +109,10 @@ object MapboxCopilot : MapboxNavigationObserver {
* @param mapboxNavigation instance that is being detached
*/
override fun onDetached(mapboxNavigation: MapboxNavigation) {
logD("MapboxNavigation is detached, stopping copilot")
copilot?.stop()
copilot = null
}

private fun logD(msg: String) = logD(msg, LOG_CATEGORY)
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ internal class MapboxCopilotImpl(
return
}
field = value

logD("HistoryRecordingSessionState: $field")

if (field is ActiveGuidance) {
filterOutActiveGuidance(SEARCH_RESULTS_EVENT_NAME)
filterOutActiveGuidance(SEARCH_RESULT_USED_EVENT_NAME)
Expand Down Expand Up @@ -217,7 +220,7 @@ internal class MapboxCopilotImpl(
val lng = userFeedback.location.longitude()
val feedbackId = userFeedback.feedbackId
val feedbackType = userFeedback.feedback.feedbackType
val feedbackSubType = userFeedback.feedback.feedbackSubTypes?.toHashSet().orEmpty()
val feedbackSubType = userFeedback.feedback.feedbackSubTypes.toHashSet()
val feedbackEvent = NavFeedbackSubmitted(
feedbackId,
feedbackType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ internal class HistoryUploadWorker(
private suspend fun uploadHistoryFile(
uploadOptions: UploadOptions,
): Boolean = suspendCancellableCoroutine { cont ->
logD("start history file upload")

val uploadService = HttpServiceProvider.getInstance()
val uploadId = uploadService.upload(uploadOptions) { uploadStatus ->
when (uploadStatus.state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mapbox.navigation.copilot
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
import com.mapbox.navigation.copilot.CopilotTestUtils.prepareLifecycleOwnerMockk
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.testing.LoggingFrontendTestRule
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
Expand All @@ -11,11 +12,15 @@ import io.mockk.mockkConstructor
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.After
import org.junit.Rule
import org.junit.Test

@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
class MapboxCopilotTest {

@get:Rule
val logRule = LoggingFrontendTestRule()

private val mockedMapboxNavigation = mockk<MapboxNavigation>(relaxed = true)

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import java.util.concurrent.CopyOnWriteArrayList
@UiThread
object MapboxNavigationProvider {

private const val LOG_CATEGORY = "MapboxNavigationProvider"

@Volatile
private var mapboxNavigation: MapboxNavigation? = null

Expand All @@ -30,6 +32,7 @@ object MapboxNavigationProvider {
*/
@JvmStatic
fun create(navigationOptions: NavigationOptions): MapboxNavigation {
logD("create()")
mapboxNavigation?.onDestroy()
mapboxNavigation = MapboxNavigation(
navigationOptions,
Expand Down Expand Up @@ -60,6 +63,8 @@ object MapboxNavigationProvider {
*/
@JvmStatic
fun destroy() {
logD("destroy()")

mapboxNavigation?.let { navigation ->
navigation.onDestroy()
observers.forEach { it.onDetached(navigation) }
Expand All @@ -84,4 +89,6 @@ object MapboxNavigationProvider {
observers.remove(observer)
mapboxNavigation?.let { observer.onDetached(it) }
}

private fun logD(msg: String) = com.mapbox.navigation.utils.internal.logD(msg, LOG_CATEGORY)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.lifecycle.LifecycleOwner
import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.MapboxNavigationProvider
import kotlin.jvm.Throws
import com.mapbox.navigation.utils.internal.logD
import kotlin.reflect.KClass

/**
Expand Down Expand Up @@ -63,6 +63,8 @@ import kotlin.reflect.KClass
*/
object MapboxNavigationApp {

private const val LOG_CATEGORY = "MapboxNavigationApp"

// The singleton MapboxNavigationApp is not good for unit testing.
// See the unit tests in MapboxNavigationAppDelegateTest
private val mapboxNavigationAppDelegate by lazy { MapboxNavigationAppDelegate() }
Expand Down Expand Up @@ -93,6 +95,7 @@ object MapboxNavigationApp {
@UiThread
@JvmStatic
fun setup(navigationOptions: NavigationOptions): MapboxNavigationApp = apply {
logD("setup()")
mapboxNavigationAppDelegate.setup { navigationOptions }
}

Expand All @@ -106,6 +109,7 @@ object MapboxNavigationApp {
@UiThread
@JvmStatic
fun setup(navigationOptionsProvider: NavigationOptionsProvider): MapboxNavigationApp = apply {
logD("setup()")
mapboxNavigationAppDelegate.setup(navigationOptionsProvider)
}

Expand All @@ -115,6 +119,7 @@ object MapboxNavigationApp {
*/
@JvmStatic
fun attachAllActivities(application: Application): MapboxNavigationApp = apply {
logD("attachAllActivities()")
mapboxNavigationAppDelegate.attachAllActivities(application)
}

Expand All @@ -125,6 +130,7 @@ object MapboxNavigationApp {
@UiThread
@JvmStatic
fun disable(): MapboxNavigationApp = apply {
logD("disable()")
mapboxNavigationAppDelegate.disable()
}

Expand All @@ -140,6 +146,7 @@ object MapboxNavigationApp {
@UiThread
@JvmStatic
fun attach(lifecycleOwner: LifecycleOwner): MapboxNavigationApp = apply {
logD("attach()")
mapboxNavigationAppDelegate.attach(lifecycleOwner)
}

Expand All @@ -155,6 +162,7 @@ object MapboxNavigationApp {
@UiThread
@JvmStatic
fun detach(lifecycleOwner: LifecycleOwner): MapboxNavigationApp = apply {
logD("detach()")
mapboxNavigationAppDelegate.detach(lifecycleOwner)
}

Expand Down Expand Up @@ -231,4 +239,6 @@ object MapboxNavigationApp {
*/
@JvmStatic
fun current(): MapboxNavigation? = mapboxNavigationAppDelegate.current()

private fun logD(msg: String) = logD(msg, LOG_CATEGORY)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mapbox.navigation.core

import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver
import com.mapbox.navigation.testing.LoggingFrontendTestRule
import io.mockk.mockk
import io.mockk.verify
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
Expand All @@ -14,6 +16,9 @@ import org.robolectric.annotation.Config
@Config(shadows = [ShadowReachabilityFactory::class])
internal class MapboxNavigationProviderTest : MapboxNavigationBaseTest() {

@get:Rule
val logRule = LoggingFrontendTestRule()

private val observer = mockk<MapboxNavigationObserver>(relaxed = true)

@Before
Expand Down

0 comments on commit d1b03d5

Please sign in to comment.