diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt index 2910f26..0ff2edb 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt @@ -174,25 +174,34 @@ class FakeLocationStateUseCase( } private fun requestLocationUpdates() { + val networkProvider = LocationManager.NETWORK_PROVIDER + .takeIf { it in locationManager.allProviders } + val gpsProvider = LocationManager.GPS_PROVIDER + .takeIf { it in locationManager.allProviders } + try { - locationManager.requestLocationUpdates( - LocationManager.NETWORK_PROVIDER, - 1000L, - 0f, - localListener - ) - locationManager.requestLocationUpdates( - LocationManager.GPS_PROVIDER, - 1000L, - 0f, - localListener - - ) - - locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) - ?: locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)?.let { - localListener.onLocationChanged(it) - } + networkProvider?.let { + locationManager.requestLocationUpdates( + it, + 1000L, + 0f, + localListener + ) + } + gpsProvider?.let { + locationManager.requestLocationUpdates( + it, + 1000L, + 0f, + localListener + ) + } + + networkProvider?.let { locationManager.getLastKnownLocation(it) } + ?: gpsProvider?.let { locationManager.getLastKnownLocation(it) } + ?.let { + localListener.onLocationChanged(it) + } } catch (se: SecurityException) { Log.e(TAG, "Missing permission", se) } |