From 514faf05615be63736b580715a6dfcc61ebf2b02 Mon Sep 17 00:00:00 2001 From: Tomek Zebrowski Date: Wed, 23 Oct 2024 09:41:02 +0200 Subject: [PATCH] feat: AA auto-connection enhancements * feat: Rework AA auto connectivity * feat: Remove query dependency from CarScreen * feat: Change log level --- app/build.gradle | 4 +-- .../org/obd/graphs/aa/screen/CarScreen.kt | 28 ++++++------------- .../aa/screen/iot/IotTemplateCarScreen.kt | 12 +++++++- .../aa/screen/nav/NavTemplateCarScreen.kt | 6 +++- .../graphs/aa/screen/nav/RoutinesScreen.kt | 7 ++--- .../screen/nav/SurfaceRendererController.kt | 2 +- .../aa/screen/nav/SurfaceRendererScreen.kt | 12 ++++++-- .../graphs/bl/datalogger/DataLoggerService.kt | 9 ++++-- .../renderer/trip/TripInfoSurfaceRenderer.kt | 1 + 9 files changed, 47 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2c3a2eed..c6bde0d4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,7 +58,7 @@ android { dimension "version" resValue "string", "DEFAULT_PROFILE", "profile_8" applicationId "org.obd.graphs.my.giulia.aa" - versionCode 140 + versionCode 147 } giuliaPerformanceMonitor { @@ -72,7 +72,7 @@ android { dimension "version" resValue "string", "DEFAULT_PROFILE", "profile_3" applicationId "org.obd.graphs.my.giulia" - versionCode 60 + versionCode 61 } } diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/CarScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/CarScreen.kt index 0829e689..4b59b016 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/CarScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/CarScreen.kt @@ -36,9 +36,6 @@ import org.obd.graphs.aa.toast import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.datalogger.WorkflowStatus import org.obd.graphs.bl.datalogger.dataLogger -import org.obd.graphs.bl.datalogger.dataLoggerPreferences -import org.obd.graphs.bl.query.Query -import org.obd.graphs.bl.query.QueryStrategyType import org.obd.graphs.renderer.Fps import org.obd.graphs.sendBroadcastEvent @@ -58,9 +55,10 @@ internal abstract class CarScreen( ) : Screen(carContext), DefaultLifecycleObserver { open fun getFeatureDescription(): List = emptyList() + abstract fun actionStartDataLogging() - protected val query = Query.instance() protected open fun gotoScreen(newScreen: Int) {} + protected open fun updateLastVisitedScreen(newScreen: Int) { settings.setLastVisitedScreen(newScreen) } @@ -90,16 +88,6 @@ internal abstract class CarScreen( cancelRenderingTask() } - protected open fun actionStartDataLogging() { - if (dataLoggerPreferences.instance.individualQueryStrategyEnabled) { - query.setStrategy(QueryStrategyType.INDIVIDUAL_QUERY_FOR_EACH_VIEW) - query.update(metricsCollector.getMetrics().map { p -> p.source.command.pid.id }.toSet()) - } else { - query.setStrategy(QueryStrategyType.SHARED_QUERY) - } - dataLogger.start(query) - } - protected open fun getHorizontalActionStrip( preferencesEnabled: Boolean = true, exitEnabled: Boolean = true, @@ -171,15 +159,15 @@ internal abstract class CarScreen( private fun onConnectionStateUpdated(connectionState: Int) { when (connectionState) { CarConnection.CONNECTION_TYPE_PROJECTION -> { - if (settings.isAutomaticConnectEnabled() && !dataLogger.isRunning()) { - query.setStrategy(QueryStrategyType.SHARED_QUERY) - dataLogger.start(query) - } - if (settings.isLoadLastVisitedScreenEnabled()) { - Log.i(LOG_TAG,"Loading last visited screen") + Log.i(LOG_TAG,"Load last visited screen flag is enabled. Loading last visited screen....") gotoScreen(settings.getLastVisitedScreen()) } + + if (settings.isAutomaticConnectEnabled() && !dataLogger.isRunning()) { + Log.i(LOG_TAG,"Auto connection enabled. Auto start data logging.....") + actionStartDataLogging() + } } } } diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt index 96d3c944..55109bd4 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt @@ -37,6 +37,7 @@ import org.obd.graphs.aa.toast import org.obd.graphs.bl.collector.Metric import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.datalogger.* +import org.obd.graphs.bl.query.Query import org.obd.graphs.bl.query.QueryStrategyType import org.obd.graphs.profile.PROFILE_CHANGED_EVENT import org.obd.graphs.renderer.DynamicSelectorMode @@ -49,6 +50,7 @@ internal class IotTemplateCarScreen( ) : CarScreen(carContext, settings, metricsCollector) { private val valueDrawable = ValueDrawable(carContext) + private val query = Query.instance(QueryStrategyType.INDIVIDUAL_QUERY_FOR_EACH_VIEW) private var broadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -175,6 +177,15 @@ internal class IotTemplateCarScreen( } } + override fun actionStartDataLogging() { + if (dataLoggerPreferences.instance.individualQueryStrategyEnabled) { + query.setStrategy(QueryStrategyType.INDIVIDUAL_QUERY_FOR_EACH_VIEW) + query.update(metricsCollector.getMetrics().map { p -> p.source.command.pid.id }.toSet()) + } else { + query.setStrategy(QueryStrategyType.SHARED_QUERY) + } + dataLogger.start(query) + } override fun renderAction() { invalidate() } @@ -238,7 +249,6 @@ internal class IotTemplateCarScreen( metricsCollector.applyFilter(settings.getSelectedPIDs()) if (dataLoggerPreferences.instance.individualQueryStrategyEnabled) { - query.setStrategy(QueryStrategyType.INDIVIDUAL_QUERY_FOR_EACH_VIEW) query.update(metricsCollector.getMetrics().map { p-> p.source.command.pid.id }.toSet()) dataLogger.updateQuery(query) } diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/NavTemplateCarScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/NavTemplateCarScreen.kt index a05812f7..f2f409bb 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/NavTemplateCarScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/NavTemplateCarScreen.kt @@ -154,7 +154,7 @@ internal class NavTemplateCarScreen( try { renderingThread.start() fps.start() - sendBroadcastEvent(AA_REFRESH_EVENT) +// sendBroadcastEvent(AA_REFRESH_EVENT) navigationManager().navigationStarted() toast.show(carContext, R.string.main_activity_toast_connection_established) invalidate() @@ -233,6 +233,10 @@ internal class NavTemplateCarScreen( } } + override fun actionStartDataLogging() { + surfaceRendererScreen.actionStartDataLogging() + } + override fun onCarConfigurationChanged() { super.onCarConfigurationChanged() surfaceRendererScreen.onCarConfigurationChanged() diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/RoutinesScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/RoutinesScreen.kt index f44656a5..3eec072f 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/RoutinesScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/RoutinesScreen.kt @@ -53,6 +53,7 @@ internal class RoutinesScreen( private var routineExecuting = false private var routineId = -1L private var routineExecutionSuccessfully = false + private val query: Query = Query.instance(QueryStrategyType.ROUTINES_QUERY) private var broadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -160,9 +161,7 @@ internal class RoutinesScreen( } override fun actionStartDataLogging(){ - dataLogger.start(query.apply{ - setStrategy(QueryStrategyType.ROUTINES_QUERY) - }) + dataLogger.start(query) } @@ -258,12 +257,10 @@ internal class RoutinesScreen( }) } else { builder.addAction(createAction(carContext, R.drawable.actions_connect, mapColor(settings.getColorTheme().actionsBtnConnectColor)) { - query.setStrategy(QueryStrategyType.ROUTINES_QUERY) dataLogger.start(query) }) } - builder = builder.addAction(createAction(carContext, R.drawable.action_exit, CarColor.RED) { try { actionStopDataLogging() diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererController.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererController.kt index 3cf3b2f0..8658eb43 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererController.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererController.kt @@ -127,7 +127,7 @@ class SurfaceRendererController( fun allocateSurfaceRenderer(surfaceRendererType: SurfaceRendererType = settings.getSurfaceRendererType()) { - + Log.i(LOG_KEY, "Allocating Surface renderer, type=$surfaceRendererType") surfaceRenderer.recycle() surfaceRenderer = SurfaceRenderer.allocate(carContext, settings, metricsCollector, fps, surfaceRendererType = surfaceRendererType) diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt index 1deb057a..b0cbb616 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/nav/SurfaceRendererScreen.kt @@ -16,6 +16,7 @@ import org.obd.graphs.aa.screen.* import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.datalogger.dataLogger import org.obd.graphs.bl.datalogger.dataLoggerPreferences +import org.obd.graphs.bl.query.Query import org.obd.graphs.bl.query.QueryStrategyType import org.obd.graphs.profile.PROFILE_CHANGED_EVENT import org.obd.graphs.profile.PROFILE_RESET_EVENT @@ -38,6 +39,8 @@ internal class SurfaceRendererScreen( private val parent: NavTemplateCarScreen ) : CarScreen(carContext, settings, metricsCollector, fps) { + private val query = Query.instance() + private var screenId = GIULIA_SCREEN_ID private val surfaceRendererController = SurfaceRendererController(carContext, settings, metricsCollector, fps, query) @@ -140,7 +143,7 @@ internal class SurfaceRendererScreen( fun switchSurfaceRenderer(newScreen: Int) { screenId = newScreen - Log.i(LOG_TAG, "Switch to new surface renderer screen: $screenId") + Log.i(LOG_TAG, "Switch to new surface renderer screen: $screenId and updating query...") when (screenId){ GIULIA_SCREEN_ID -> { @@ -165,6 +168,7 @@ internal class SurfaceRendererScreen( } TRIP_INFO_SCREEN_ID -> { + dataLogger.updateQuery(query = query.apply { setStrategy(QueryStrategyType.TRIP_INFO_QUERY) }) @@ -176,6 +180,7 @@ internal class SurfaceRendererScreen( } override fun actionStartDataLogging(){ + Log.i(LOG_TAG, "Action start data logging") when (screenId) { GIULIA_SCREEN_ID -> { if (dataLoggerPreferences.instance.individualQueryStrategyEnabled) { @@ -261,6 +266,7 @@ internal class SurfaceRendererScreen( } private fun updateQuery() { + if (isSurfaceRendererScreen(screenId)) { if (screenId == DRAG_RACING_SCREEN_ID) { Log.i(LOG_TAG, "Updating query for DRAG_RACING_SCREEN_ID screen") @@ -289,7 +295,7 @@ internal class SurfaceRendererScreen( dataLogger.updateQuery(query) } else { - Log.i(LOG_TAG, "Updating query for default query") + Log.i(LOG_TAG, "Updating query to SHARED_QUERY strategy") query.setStrategy(QueryStrategyType.SHARED_QUERY) val query = query.getIDs() @@ -300,6 +306,8 @@ internal class SurfaceRendererScreen( metricsCollector.applyFilter(enabled = intersection, order = settings.getPIDsSortOrder()) } + } else { + Log.i(LOG_TAG, "Do not update the query. Its not surface renderer screen.") } } diff --git a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt index a85edd87..c56bd888 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt @@ -83,8 +83,13 @@ internal class DataLoggerService : JobIntentService(), DataLogger { } override fun updateQuery(query: Query) { - enqueueWork(UPDATE_QUERY) { - it.putExtra(QUERY, query) + Log.i(LOG_TAG,"Updating query for strategy=${query.getStrategy()}. PIDs=${query.getIDs()}") + if (isRunning()) { + enqueueWork(UPDATE_QUERY) { + it.putExtra(QUERY, query) + } + } else { + Log.w(LOG_TAG,"No workflow is currently running. Query won't be updated.") } } diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt index 64425d80..321a15eb 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoSurfaceRenderer.kt @@ -100,6 +100,7 @@ internal class TripInfoSurfaceRenderer( } init { + Log.i(LOG_TAG,"Init Trip Info Surface renderer") applyMetricsFilter(Query.instance(QueryStrategyType.TRIP_INFO_QUERY)) } } \ No newline at end of file