diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-11-25 07:33:40 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-11-25 07:33:40 +0000 |
commit | 2f40c62572be0fffa04fe6cf105ece937389e287 (patch) | |
tree | 68b4d3c3fbc15fbc5c0f877264853aab23e4c4fa /app/src/main | |
parent | 4df37b50588addf54723b575edfaccea6f34c440 (diff) | |
parent | 2af855260ce842e62ca0462823a7466d13c2eecd (diff) |
Merge branch '6055-location_provider_network_not_exist' into 'main'
6055: handle missing location providers.
See merge request e/os/advanced-privacy!107
Diffstat (limited to 'app/src/main')
-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) } |