Skip to content

Commit

Permalink
feat: AA auto-connection enhancements
Browse files Browse the repository at this point in the history
* feat: Rework AA auto connectivity

* feat: Remove query dependency from CarScreen

* feat: Change log level
  • Loading branch information
tzebrowski authored Oct 23, 2024
1 parent f77c601 commit 514faf0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -72,7 +72,7 @@ android {
dimension "version"
resValue "string", "DEFAULT_PROFILE", "profile_3"
applicationId "org.obd.graphs.my.giulia"
versionCode 60
versionCode 61
}
}

Expand Down
28 changes: 8 additions & 20 deletions automotive/src/main/java/org/obd/graphs/aa/screen/CarScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -58,9 +55,10 @@ internal abstract class CarScreen(
) : Screen(carContext), DefaultLifecycleObserver {

open fun getFeatureDescription(): List<FeatureDescription> = emptyList()
abstract fun actionStartDataLogging()

protected val query = Query.instance()
protected open fun gotoScreen(newScreen: Int) {}

protected open fun updateLastVisitedScreen(newScreen: Int) {
settings.setLastVisitedScreen(newScreen)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?) {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -233,6 +233,10 @@ internal class NavTemplateCarScreen(
}
}

override fun actionStartDataLogging() {
surfaceRendererScreen.actionStartDataLogging()
}

override fun onCarConfigurationChanged() {
super.onCarConfigurationChanged()
surfaceRendererScreen.onCarConfigurationChanged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -160,9 +161,7 @@ internal class RoutinesScreen(
}

override fun actionStartDataLogging(){
dataLogger.start(query.apply{
setStrategy(QueryStrategyType.ROUTINES_QUERY)
})
dataLogger.start(query)
}


Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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 -> {
Expand All @@ -165,6 +168,7 @@ internal class SurfaceRendererScreen(
}

TRIP_INFO_SCREEN_ID -> {

dataLogger.updateQuery(query = query.apply {
setStrategy(QueryStrategyType.TRIP_INFO_QUERY)
})
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ internal class TripInfoSurfaceRenderer(
}

init {
Log.i(LOG_TAG,"Init Trip Info Surface renderer")
applyMetricsFilter(Query.instance(QueryStrategyType.TRIP_INFO_QUERY))
}
}

0 comments on commit 514faf0

Please sign in to comment.