Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 9f03d5cd authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Location: Fix potential dead-lock

parent c8086471
Loading
Loading
Loading
Loading
+26 −24
Original line number Diff line number Diff line
@@ -82,14 +82,19 @@ class UnifiedLocationProvider(private val context: Context, private val changeLi
            }
        }
        requests.add(request)
        lifecycleScope.launchWhenStarted {
            updateConnection()
        }
    }

    fun removeRequest(request: LocationRequestHelper) {
        Log.d(TAG, "unified network: removeRequest $request")
        requests.remove(request)

        lifecycleScope.launchWhenStarted {
            updateConnection()
        }
    }

    fun getLastLocation(): Location? {
        if (lastLocation == null) {
@@ -98,9 +103,7 @@ class UnifiedLocationProvider(private val context: Context, private val changeLi
        return lastLocation
    }

    @Synchronized
    private fun updateConnection() {
        lifecycleScope.launchWhenStarted {
    private suspend fun updateConnection() {
        activeRequestMutex.withLock {
            if (activeRequestIds.isNotEmpty() && requests.isEmpty()) {
                Log.d(TAG, "unified network: no longer requesting location update")
@@ -123,7 +126,6 @@ class UnifiedLocationProvider(private val context: Context, private val changeLi
            }
        }
    }
    }

    override fun getLifecycle(): Lifecycle = lifecycle