Log SecurityException in LocationProvider instead of swallowing silently

A revoked location permission was previously caught and sent as null
with zero logging, making it indistinguishable from "no fix yet" and
impossible to diagnose.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-03-05 11:55:57 +01:00
commit cd51c1a843

View file

@ -5,6 +5,7 @@ import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.location.Location import android.location.Location
import android.os.Looper import android.os.Looper
import android.util.Log
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationCallback import com.google.android.gms.location.LocationCallback
@ -21,6 +22,10 @@ import kotlinx.coroutines.flow.callbackFlow
*/ */
class LocationProvider(private val context: Context) { class LocationProvider(private val context: Context) {
companion object {
private const val TAG = "LocationProvider"
}
private val fusedLocationClient: FusedLocationProviderClient = private val fusedLocationClient: FusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(context) LocationServices.getFusedLocationProviderClient(context)
@ -61,6 +66,7 @@ class LocationProvider(private val context: Context) {
location?.let { trySend(it) } location?.let { trySend(it) }
} }
} catch (e: SecurityException) { } catch (e: SecurityException) {
Log.w(TAG, "Location permission revoked at runtime", e)
trySend(null) trySend(null)
} }