Colota - Android GPS Location tracker
Add dedicated car mode broadcasts for reliable Android Auto detection
Max Dietrich5bc761b0ba21
diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/ConditionMonitor.kt b/apps/mobile/android/app/src/main/java/com/colota/service/ConditionMonitor.ktindex 288ce31f..fa45ddbb 100644--- a/apps/mobile/android/app/src/main/java/com/colota/service/ConditionMonitor.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/service/ConditionMonitor.kt@@ -93,15 +93,30 @@ class ConditionMonitor(private fun registerCarModeMonitor() {carModeReceiver = object : BroadcastReceiver() {override fun onReceive(context: Context, intent: Intent) {- if (intent.action == Intent.ACTION_CONFIGURATION_CHANGED) {- val isCarMode = readCurrentCarModeState()- if (BuildConfig.DEBUG) Log.d(TAG, "Configuration changed — carMode: $isCarMode")- profileManager.onCarModeStateChanged(isCarMode)+ when (intent.action) {+ UiModeManager.ACTION_ENTER_CAR_MODE -> {+ if (BuildConfig.DEBUG) Log.d(TAG, "Car mode entered")+ profileManager.onCarModeStateChanged(true)+ }+ UiModeManager.ACTION_EXIT_CAR_MODE -> {+ if (BuildConfig.DEBUG) Log.d(TAG, "Car mode exited")+ profileManager.onCarModeStateChanged(false)+ }+ Intent.ACTION_CONFIGURATION_CHANGED -> {+ val isCarMode = readCurrentCarModeState()+ if (BuildConfig.DEBUG) Log.d(TAG, "Configuration changed - carMode: $isCarMode")+ profileManager.onCarModeStateChanged(isCarMode)+ }}}}- context.registerReceiver(carModeReceiver, IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), Context.RECEIVER_NOT_EXPORTED)+ val filter = IntentFilter().apply {+ addAction(UiModeManager.ACTION_ENTER_CAR_MODE)+ addAction(UiModeManager.ACTION_EXIT_CAR_MODE)+ addAction(Intent.ACTION_CONFIGURATION_CHANGED)+ }+ context.registerReceiver(carModeReceiver, filter, Context.RECEIVER_NOT_EXPORTED)}private fun readCurrentChargingState(): Boolean {