From d330d890bc66fa7aa9f2224376472b48c0d49e9a Mon Sep 17 00:00:00 2001 From: Tomek Zebrowski Date: Thu, 7 Sep 2023 10:17:14 +0200 Subject: [PATCH] feat: --- automotive/src/main/AndroidManifest.xml | 9 +++++++ .../main/java/org/obd/graphs/aa/CarScreen.kt | 27 +++++++++++++++++++ .../main/java/org/obd/graphs/aa/CarService.kt | 1 + 3 files changed, 37 insertions(+) diff --git a/automotive/src/main/AndroidManifest.xml b/automotive/src/main/AndroidManifest.xml index 9d4f2032..f7382ab7 100644 --- a/automotive/src/main/AndroidManifest.xml +++ b/automotive/src/main/AndroidManifest.xml @@ -24,7 +24,16 @@ android:exported="true"> + + + + + + + + + \ No newline at end of file diff --git a/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt index f4c57872..981ca683 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt @@ -9,6 +9,8 @@ import android.util.Log import androidx.car.app.CarContext import androidx.car.app.Screen import androidx.car.app.model.* +import androidx.car.app.navigation.NavigationManager +import androidx.car.app.navigation.NavigationManagerCallback import androidx.car.app.navigation.model.NavigationTemplate import androidx.core.graphics.drawable.IconCompat import androidx.lifecycle.DefaultLifecycleObserver @@ -20,6 +22,7 @@ import org.obd.graphs.renderer.DynamicSelectorMode import org.obd.graphs.renderer.Fps import org.obd.graphs.renderer.ScreenSettings + private const val LOG_KEY = "CarScreen" private const val VIRTUAL_SCREEN_1_SETTINGS_CHANGED = "pref.aa.pids.profile_1.event.changed" private const val VIRTUAL_SCREEN_2_SETTINGS_CHANGED = "pref.aa.pids.profile_2.event.changed" @@ -138,6 +141,7 @@ internal class CarScreen( surfaceController.renderFrame() fps.stop() invalidate() + navigationManager().navigationEnded() } DATA_LOGGER_CONNECTED_EVENT -> { @@ -145,6 +149,7 @@ internal class CarScreen( renderingThread.start() fps.start() invalidate() + navigationManager().navigationStarted() } DATA_LOGGER_STOPPING_EVENT -> { @@ -303,6 +308,7 @@ internal class CarScreen( } init { + lifecycle.addObserver(this) dataLogger.observe(this) { metricsCollector.append(it) @@ -314,5 +320,26 @@ internal class CarScreen( } else { Log.i(LOG_KEY, "Data logger is not running.") } + + navigationManager().setNavigationManagerCallback( + object : NavigationManagerCallback { + override fun onStopNavigation() { + + try { + renderingThread.stop() + surfaceController.renderFrame() + fps.stop() + invalidate() + }catch (e: Throwable){ + Log.e(LOG_KEY,"Failed to stop DL threads",e) + } + } + + override fun onAutoDriveEnabled() { + + } + }) } + + private fun navigationManager() = carContext.getCarService(NavigationManager::class.java) } \ No newline at end of file diff --git a/automotive/src/main/java/org/obd/graphs/aa/CarService.kt b/automotive/src/main/java/org/obd/graphs/aa/CarService.kt index 3cfcfa40..7b9a86dc 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/CarService.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/CarService.kt @@ -10,6 +10,7 @@ import androidx.car.app.validation.HostValidator internal class CarService : CarAppService() { override fun onCreateSession(): Session = CarSession() override fun createHostValidator(): HostValidator { + return if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) { HostValidator.ALLOW_ALL_HOSTS_VALIDATOR } else {