From dee5dfd187174ac9c156c1b672abb3ddcea3707d Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 13 Jun 2022 12:02:21 +0200 Subject: [PATCH] Add synchronized annotations to protect from concurrent access to callbacks --- .../im/vector/app/features/location/LocationTracker.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt index 63508f30d7..cdf13a7004 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt @@ -122,7 +122,9 @@ class LocationTracker @Inject constructor( fun stop() { Timber.d("stop()") locationManager?.removeUpdates(this) - callbacks.clear() + synchronized(this) { + callbacks.clear() + } debouncer.cancelAll() hasLocationFromGPSProvider = false hasLocationFromFusedProvider = false @@ -136,12 +138,14 @@ class LocationTracker @Inject constructor( lastLocation?.let { locationData -> onLocationUpdate(locationData) } } + @Synchronized fun addCallback(callback: Callback) { if (!callbacks.contains(callback)) { callbacks.add(callback) } } + @Synchronized fun removeCallback(callback: Callback) { callbacks.remove(callback) if (callbacks.size == 0) { @@ -211,6 +215,7 @@ class LocationTracker @Inject constructor( } } + @Synchronized private fun onNoLocationProviderAvailable() { callbacks.forEach { try { @@ -221,6 +226,7 @@ class LocationTracker @Inject constructor( } } + @Synchronized private fun onLocationUpdate(locationData: LocationData) { callbacks.forEach { try {