Colota - Android GPS Location tracker
fix: only start condition monitors when matching profiles exist
Max Dietrichb22f7be964f8
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 e494e41a..66fb1a62 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@@ -43,14 +43,19 @@ class ConditionMonitor(// Unregister first to prevent duplicate observers on repeated start() callsstop()- registerChargingMonitor()- startCarConnectionMonitor()+ val needed = profileManager.getNeededConditionTypes()- // Read initial charging state- val charging = readCurrentChargingState()- profileManager.onChargingStateChanged(charging)+ if (ProfileConstants.CONDITION_CHARGING in needed) {+ registerChargingMonitor()+ val charging = readCurrentChargingState()+ profileManager.onChargingStateChanged(charging)+ }++ if (ProfileConstants.CONDITION_ANDROID_AUTO in needed) {+ startCarConnectionMonitor()+ }- AppLogger.d(TAG, "Condition monitors started - charging: $charging")+ AppLogger.d(TAG, "Condition monitors started for: ${needed.ifEmpty { setOf("none") }}")}fun stop() {@@ -91,18 +96,22 @@ class ConditionMonitor(}private fun startCarConnectionMonitor() {- val connection = CarConnection(context)- carConnection = connection-- val observer = Observer<Int> { connectionType ->- val connected = connectionType != CarConnection.CONNECTION_TYPE_NOT_CONNECTED- AppLogger.d(TAG, "CarConnection type: $connectionType (connected: $connected)")- profileManager.onCarModeStateChanged(connected)- }- carConnectionObserver = observer+ try {+ val connection = CarConnection(context)+ carConnection = connection++ val observer = Observer<Int> { connectionType ->+ val connected = connectionType != CarConnection.CONNECTION_TYPE_NOT_CONNECTED+ AppLogger.d(TAG, "CarConnection type: $connectionType (connected: $connected)")+ profileManager.onCarModeStateChanged(connected)+ }+ carConnectionObserver = observer- mainHandler.post {- connection.type.observeForever(observer)+ mainHandler.post {+ connection.type.observeForever(observer)+ }+ } catch (e: Exception) {+ AppLogger.w(TAG, "CarConnection unavailable: ${e.message}")}}diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/ProfileManager.kt b/apps/mobile/android/app/src/main/java/com/colota/service/ProfileManager.ktindex 045587c9..e2facbe0 100644--- a/apps/mobile/android/app/src/main/java/com/colota/service/ProfileManager.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/service/ProfileManager.kt@@ -76,6 +76,9 @@ class ProfileManager(fun getActiveProfileName(): String? = activeProfile?.name+ fun getNeededConditionTypes(): Set<String> =+ profileHelper.getEnabledProfiles().map { it.conditionType }.toSet()+/*** Re-evaluates all enabled profiles against current conditions.* Must handle concurrent calls from location updates, broadcasts, and service actions.