summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com>2022-11-21 23:10:30 +0100
committerGuillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com>2022-11-21 23:11:13 +0100
commit2af855260ce842e62ca0462823a7466d13c2eecd (patch)
tree3d5971d33aa80f7cdf7b4c81716942c8452ce2ee
parent84bdb74c79a41c90d4d374bf5eb963191de3e7b3 (diff)
6055: handle missing location providers.
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt45
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)
}