expo-location 58.0.13 → 58.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/AndroidManifest.xml +4 -0
  4. package/android/src/main/java/expo/modules/location/next/LocationModuleNext.kt +189 -10
  5. package/android/src/main/java/expo/modules/location/next/LocationPermissions.kt +65 -0
  6. package/android/src/main/java/expo/modules/location/next/LocationRecords.kt +91 -2
  7. package/android/src/main/java/expo/modules/location/next/LocationTaskConsumer.kt +205 -0
  8. package/android/src/main/java/expo/modules/location/next/WatchPosition.kt +8 -6
  9. package/android/src/main/java/expo/modules/location/next/locationForegroundService/BackgroundSessionOptions.kt +62 -0
  10. package/android/src/main/java/expo/modules/location/next/locationForegroundService/BackgroundSessionTypes.kt +32 -0
  11. package/android/src/main/java/expo/modules/location/next/locationForegroundService/ForegroundServiceExceptions.kt +53 -0
  12. package/android/src/main/java/expo/modules/location/next/locationForegroundService/LocationForegroundService.kt +142 -0
  13. package/android/src/main/java/expo/modules/location/next/locationForegroundService/ServiceNotification.kt +64 -0
  14. package/android/src/main/java/expo/modules/location/next/locationProviders/AndroidLocationProvider.kt +115 -7
  15. package/android/src/main/java/expo/modules/location/next/locationProviders/FallbackLocationProvider.kt +12 -3
  16. package/android/src/main/java/expo/modules/location/next/locationProviders/GmsLocationProvider.kt +79 -0
  17. package/android/src/main/java/expo/modules/location/next/locationProviders/LocationProvider.kt +48 -0
  18. package/ios/Providers/LocationsStreamer.swift +10 -4
  19. package/ios/next/LocationModuleNext.swift +4 -0
  20. package/ios/next/LocationNextExceptions.swift +0 -8
  21. package/ios/next/LocationUpdatesHandle/LocationUpdatesHandle.swift +6 -2
  22. package/ios/next/Position/LocationUpdateDiagnostics.swift +0 -3
  23. package/ios/next/Position/PositionUpdatesCompatibilitySource.swift +9 -1
  24. package/ios/next/Position/PositionUpdatesLiveSource.swift +5 -0
  25. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14-sources.jar +0 -0
  26. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14-sources.jar.md5 +1 -0
  27. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14-sources.jar.sha1 +1 -0
  28. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14-sources.jar.sha256 +1 -0
  29. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14-sources.jar.sha512 +1 -0
  30. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.aar +0 -0
  31. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.aar.md5 +1 -0
  32. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.aar.sha1 +1 -0
  33. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.aar.sha256 +1 -0
  34. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.aar.sha512 +1 -0
  35. package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.13/expo.modules.location-58.0.13.module → 58.0.14/expo.modules.location-58.0.14.module} +22 -22
  36. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.module.md5 +1 -0
  37. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.module.sha1 +1 -0
  38. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.module.sha256 +1 -0
  39. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.module.sha512 +1 -0
  40. package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.13/expo.modules.location-58.0.13.pom → 58.0.14/expo.modules.location-58.0.14.pom} +1 -1
  41. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.pom.md5 +1 -0
  42. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.pom.sha1 +1 -0
  43. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.pom.sha256 +1 -0
  44. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.14/expo.modules.location-58.0.14.pom.sha512 +1 -0
  45. package/package.json +2 -2
  46. package/plugin/build/withLocation.js +2 -0
  47. package/plugin/build/withLocation.js.map +1 -1
  48. package/plugin/src/withLocation.ts +2 -0
  49. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar +0 -0
  50. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.md5 +0 -1
  51. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha1 +0 -1
  52. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha256 +0 -1
  53. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha512 +0 -1
  54. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar +0 -0
  55. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.md5 +0 -1
  56. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha1 +0 -1
  57. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha256 +0 -1
  58. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha512 +0 -1
  59. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.md5 +0 -1
  60. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha1 +0 -1
  61. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha256 +0 -1
  62. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha512 +0 -1
  63. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.md5 +0 -1
  64. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha1 +0 -1
  65. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha256 +0 -1
  66. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha512 +0 -1
@@ -3,6 +3,7 @@ package expo.modules.location.next.locationProviders
3
3
  import android.Manifest
4
4
  import android.annotation.SuppressLint
5
5
  import android.app.Activity
6
+ import android.app.PendingIntent
6
7
  import android.content.BroadcastReceiver
7
8
  import android.content.Context
8
9
  import android.content.Intent
@@ -15,10 +16,17 @@ import android.os.CancellationSignal
15
16
  import android.os.Looper
16
17
  import android.os.SystemClock
17
18
  import android.provider.Settings
19
+ import android.util.Log
18
20
  import androidx.core.content.ContextCompat
21
+ import androidx.core.content.IntentCompat
19
22
  import androidx.core.location.LocationListenerCompat
20
23
  import androidx.core.location.LocationManagerCompat
21
24
  import androidx.core.location.LocationRequestCompat
25
+ import expo.modules.interfaces.taskManager.TaskConsumer
26
+ import expo.modules.interfaces.taskManager.TaskManagerInterface
27
+ import expo.modules.interfaces.taskManager.TaskManagerUtilsInterface
28
+ import expo.modules.location.next.BatchedPositions
29
+ import expo.modules.location.next.LocationTaskConsumer
22
30
  import expo.modules.location.next.Position
23
31
  import expo.modules.location.next.SETTINGS_REQUEST_CODE
24
32
  import expo.modules.location.next.toPosition
@@ -27,15 +35,18 @@ import kotlinx.coroutines.withTimeoutOrNull
27
35
  import kotlin.coroutines.resume
28
36
  import kotlin.time.Duration
29
37
 
30
- private fun getValidSystemProviders(context: Context, locationManager: LocationManager): List<String> {
38
+ private fun getPermittedSystemProviders(context: Context, locationManager: LocationManager, enabledOnly: Boolean): List<String> {
31
39
  val fineGranted = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
32
- val enabledProviders = locationManager.getProviders(true)
40
+ val providers = locationManager.getProviders(enabledOnly)
33
41
  // Avoid GPS_PROVIDER, when only coarse permissions are given.
34
- return enabledProviders.filter {
42
+ return providers.filter {
35
43
  it != LocationManager.GPS_PROVIDER || fineGranted
36
44
  }
37
45
  }
38
46
 
47
+ private fun getValidSystemProviders(context: Context, locationManager: LocationManager): List<String> =
48
+ getPermittedSystemProviders(context, locationManager, enabledOnly = true)
49
+
39
50
  private fun downgradeSystemProvider(provider: String) = when (provider) {
40
51
  LocationManager.FUSED_PROVIDER -> LocationManager.GPS_PROVIDER
41
52
  LocationManager.GPS_PROVIDER -> LocationManager.NETWORK_PROVIDER
@@ -51,9 +62,9 @@ fun LocationPriority.toQuality(): Int {
51
62
  }
52
63
  }
53
64
 
54
- fun resolveSystemProviderName(locationPriority: LocationPriority, context: Context, locationManager: LocationManager): String? {
65
+ private fun desiredSystemProvider(locationPriority: LocationPriority): String {
55
66
  // Pick the desired provider based on LocationPriority options
56
- val desiredProvider = when (locationPriority) {
67
+ return when (locationPriority) {
57
68
  LocationPriority.HIGH_ACCURACY, LocationPriority.BALANCED_POWER_ACCURACY -> {
58
69
  if (Build.VERSION.SDK_INT >= 31) {
59
70
  LocationManager.FUSED_PROVIDER
@@ -64,16 +75,20 @@ fun resolveSystemProviderName(locationPriority: LocationPriority, context: Conte
64
75
  LocationPriority.LOW_POWER -> LocationManager.NETWORK_PROVIDER
65
76
  LocationPriority.PASSIVE -> LocationManager.PASSIVE_PROVIDER
66
77
  }
67
- val validProviders = getValidSystemProviders(context, locationManager)
78
+ }
68
79
 
80
+ private fun resolveProviderFrom(locationPriority: LocationPriority, validProviders: List<String>): String? {
69
81
  // Downgrade provider if it is not valid.
70
- var provider: String? = desiredProvider
82
+ var provider: String? = desiredSystemProvider(locationPriority)
71
83
  while (provider != null && provider !in validProviders) {
72
84
  provider = downgradeSystemProvider(provider)
73
85
  }
74
86
  return provider
75
87
  }
76
88
 
89
+ fun resolveSystemProviderName(locationPriority: LocationPriority, context: Context, locationManager: LocationManager): String? =
90
+ resolveProviderFrom(locationPriority, getValidSystemProviders(context, locationManager))
91
+
77
92
  class AndroidLocationProvider(private val context: Context) : LocationProvider {
78
93
  val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
79
94
 
@@ -122,6 +137,17 @@ class AndroidLocationProvider(private val context: Context) : LocationProvider {
122
137
  return ProviderResult.Available(AndroidPositionUpdatesSession(context, locationManager))
123
138
  }
124
139
 
140
+ override fun getLocationTaskConsumerClass(): ProviderResult<Class<out TaskConsumer>> {
141
+ return ProviderResult.Available(AndroidLocationTaskConsumer::class.java)
142
+ }
143
+
144
+ override fun getRegisteredTaskConsumerClass(taskManager: TaskManagerInterface, taskName: String): ProviderResult<Class<out TaskConsumer>> {
145
+ if (!taskManager.taskHasConsumerOfClass(taskName, AndroidLocationTaskConsumer::class.java)) {
146
+ return ProviderResult.Unavailable
147
+ }
148
+ return ProviderResult.Available(AndroidLocationTaskConsumer::class.java)
149
+ }
150
+
125
151
  // On plain android we can only move user to settings.
126
152
  override suspend fun enableLocationServices(activity: Activity): ProviderResult<EnableLocationServicesResult> {
127
153
  val enableServicesResult = runCatching {
@@ -228,3 +254,85 @@ private class AndroidPositionUpdatesSession(
228
254
  }
229
255
  }
230
256
  }
257
+
258
+ class AndroidLocationTaskConsumer(
259
+ context: Context,
260
+ taskManagerUtils: TaskManagerUtilsInterface?
261
+ ) : LocationTaskConsumer(context, taskManagerUtils) {
262
+ private val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager
263
+
264
+ @SuppressLint("MissingPermission")
265
+ override fun requestLocationUpdates(pendingIntent: PendingIntent, options: BackgroundUpdatesParameters, updateExisting: Boolean): Boolean {
266
+ val locationManager = locationManager ?: return false
267
+ val provider = runCatching {
268
+ val systemProviders = getPermittedSystemProviders(
269
+ context,
270
+ locationManager,
271
+ enabledOnly = false
272
+ )
273
+ resolveProviderFrom(options.priority, systemProviders)
274
+ }.getOrNull() ?: return false
275
+
276
+ return runCatching {
277
+ if (Build.VERSION.SDK_INT >= 31) {
278
+ val request = LocationRequestCompat.Builder(options.interval.inWholeMilliseconds)
279
+ .setQuality(options.priority.toQuality())
280
+ .setMaxUpdateDelayMillis(options.maxUpdateDelay.inWholeMilliseconds)
281
+ .setMinUpdateDistanceMeters(options.minUpdateDistance)
282
+ .build()
283
+ .toLocationRequest()
284
+ locationManager.requestLocationUpdates(provider, request, pendingIntent)
285
+ } else {
286
+ locationManager.requestLocationUpdates(
287
+ provider,
288
+ options.interval.inWholeMilliseconds,
289
+ options.minUpdateDistance,
290
+ pendingIntent
291
+ )
292
+ }
293
+ true
294
+ }.onFailure {
295
+ reportRequestFailed(it)
296
+ Log.w("ExpoLocation", "Could not request background location updates from \"$provider\"", it)
297
+ }.getOrDefault(false)
298
+ }
299
+
300
+ @SuppressLint("MissingPermission")
301
+ override fun stopLocationUpdates(pendingIntent: PendingIntent) {
302
+ try {
303
+ locationManager?.removeUpdates(pendingIntent)
304
+ pendingIntent.cancel()
305
+ } catch (e: Exception) {
306
+ Log.w("ExpoLocation", "Could not stop background location updates", e)
307
+ }
308
+ }
309
+
310
+ override fun decodeBatchedPositions(intent: Intent?): BatchedPositions {
311
+ if (intent == null) {
312
+ return BatchedPositions(null, "Received a location broadcast without an intent.")
313
+ }
314
+ return runCatching { decodeIntent(intent) }.getOrElse {
315
+ Log.w("ExpoLocation", "Could not decode a location broadcast", it)
316
+ BatchedPositions(null, "Could not read the location update sent by the system.")
317
+ }
318
+ }
319
+
320
+ private fun decodeIntent(intent: Intent): BatchedPositions {
321
+ if (Build.VERSION.SDK_INT >= 31) {
322
+ val batch = IntentCompat
323
+ .getParcelableArrayExtra(intent, LocationManager.KEY_LOCATIONS, Location::class.java)
324
+ ?.filterIsInstance<Location>()
325
+ ?.takeIf { it.isNotEmpty() }
326
+ if (batch != null) {
327
+ return BatchedPositions(batch.map { it.toPosition() }, null)
328
+ }
329
+ }
330
+
331
+ val location = IntentCompat.getParcelableExtra(intent, LocationManager.KEY_LOCATION_CHANGED, Location::class.java)
332
+ if (location != null) {
333
+ return BatchedPositions(listOf(location.toPosition()), null)
334
+ }
335
+
336
+ return BatchedPositions(null, null)
337
+ }
338
+ }
@@ -1,6 +1,8 @@
1
1
  package expo.modules.location.next.locationProviders
2
2
 
3
3
  import android.app.Activity
4
+ import expo.modules.interfaces.taskManager.TaskConsumer
5
+ import expo.modules.interfaces.taskManager.TaskManagerInterface
4
6
  import expo.modules.location.next.Position
5
7
 
6
8
  class FallbackLocationProvider(val locationProviders: List<LocationProvider>) : LocationProvider {
@@ -19,14 +21,21 @@ class FallbackLocationProvider(val locationProviders: List<LocationProvider>) :
19
21
  return firstAvailable { it.watchPosition() }
20
22
  }
21
23
 
24
+ override fun getLocationTaskConsumerClass(): ProviderResult<Class<out TaskConsumer>> {
25
+ return firstAvailable { it.getLocationTaskConsumerClass() }
26
+ }
27
+
28
+ override fun getRegisteredTaskConsumerClass(taskManager: TaskManagerInterface, taskName: String): ProviderResult<Class<out TaskConsumer>> {
29
+ return firstAvailable { it.getRegisteredTaskConsumerClass(taskManager, taskName) }
30
+ }
31
+
22
32
  private inline fun <T> firstAvailable(providerOperation: (LocationProvider) -> ProviderResult<T>): ProviderResult<T> {
23
33
  var outcome: ProviderResult<T> = ProviderResult.Unsupported
24
34
  for (locationProvider in locationProviders) {
25
- val thisOutcome = providerOperation(locationProvider)
26
- when (thisOutcome) {
35
+ when (val thisOutcome = providerOperation(locationProvider)) {
27
36
  is ProviderResult.Available -> return thisOutcome
28
37
  ProviderResult.Unavailable -> outcome = ProviderResult.Unavailable
29
- // Note that the operation is only unsupported if it is unsupported for all of the providers
38
+ // Note that the operation is only unsupported if it is unsupported for all the providers
30
39
  ProviderResult.Unsupported -> continue
31
40
  }
32
41
  }
@@ -2,6 +2,9 @@ package expo.modules.location.next.locationProviders
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import android.app.Activity
5
+ import android.app.PendingIntent
6
+ import android.content.Context
7
+ import android.content.Intent
5
8
  import android.location.Location
6
9
  import android.os.Looper
7
10
  import android.util.Log
@@ -12,10 +15,16 @@ import com.google.android.gms.location.LocationAvailability
12
15
  import com.google.android.gms.location.LocationCallback
13
16
  import com.google.android.gms.location.LocationRequest
14
17
  import com.google.android.gms.location.LocationResult
18
+ import com.google.android.gms.location.LocationServices
15
19
  import com.google.android.gms.location.LocationSettingsRequest
16
20
  import com.google.android.gms.location.Priority
17
21
  import com.google.android.gms.location.SettingsClient
18
22
  import com.google.android.gms.tasks.Task
23
+ import expo.modules.interfaces.taskManager.TaskConsumer
24
+ import expo.modules.interfaces.taskManager.TaskManagerInterface
25
+ import expo.modules.interfaces.taskManager.TaskManagerUtilsInterface
26
+ import expo.modules.location.next.BatchedPositions
27
+ import expo.modules.location.next.LocationTaskConsumer
19
28
  import expo.modules.location.next.Position
20
29
  import expo.modules.location.next.SETTINGS_REQUEST_CODE
21
30
  import expo.modules.location.next.toPosition
@@ -121,6 +130,20 @@ class GmsLocationProvider(
121
130
  return ProviderResult.Unavailable
122
131
  }
123
132
  }
133
+
134
+ override fun getLocationTaskConsumerClass(): ProviderResult<Class<out TaskConsumer>> {
135
+ if (!isServiceAvailable()) {
136
+ return ProviderResult.Unavailable
137
+ }
138
+ return ProviderResult.Available(GmsLocationTaskConsumer::class.java)
139
+ }
140
+
141
+ override fun getRegisteredTaskConsumerClass(taskManager: TaskManagerInterface, taskName: String): ProviderResult<Class<out TaskConsumer>> {
142
+ if (!taskManager.taskHasConsumerOfClass(taskName, GmsLocationTaskConsumer::class.java)) {
143
+ return ProviderResult.Unavailable
144
+ }
145
+ return ProviderResult.Available(GmsLocationTaskConsumer::class.java)
146
+ }
124
147
  }
125
148
 
126
149
  private class GmsPositionUpdatesSession(
@@ -186,3 +209,59 @@ private class GmsPositionUpdatesSession(
186
209
  var available = false
187
210
  override fun canDeliverUpdates(): Boolean = available
188
211
  }
212
+
213
+ class GmsLocationTaskConsumer(context: Context, taskManagerUtils: TaskManagerUtilsInterface?) : LocationTaskConsumer(
214
+ context,
215
+ taskManagerUtils
216
+ ) {
217
+ private val fusedLocationProvider: FusedLocationProviderClient by lazy {
218
+ LocationServices.getFusedLocationProviderClient(context)
219
+ }
220
+
221
+ @SuppressLint("MissingPermission")
222
+ override fun requestLocationUpdates(pendingIntent: PendingIntent, options: BackgroundUpdatesParameters, updateExisting: Boolean): Boolean {
223
+ try {
224
+ val request = LocationRequest.Builder(
225
+ options.priority.toGmsPriority(),
226
+ options.interval.inWholeMilliseconds
227
+ ).setMaxUpdateDelayMillis(options.maxUpdateDelay.inWholeMilliseconds)
228
+ .setMinUpdateDistanceMeters(options.minUpdateDistance)
229
+ .build()
230
+
231
+ fusedLocationProvider
232
+ .requestLocationUpdates(request, pendingIntent)
233
+ .addOnFailureListener {
234
+ reportRequestFailed(it)
235
+ }
236
+ return true
237
+ } catch (e: Exception) {
238
+ reportRequestFailed(e)
239
+ return false
240
+ }
241
+ }
242
+
243
+ override fun stopLocationUpdates(pendingIntent: PendingIntent) {
244
+ runCatching {
245
+ fusedLocationProvider
246
+ .removeLocationUpdates(pendingIntent)
247
+ }
248
+ }
249
+
250
+ override fun decodeBatchedPositions(intent: Intent?): BatchedPositions {
251
+ if (intent == null) {
252
+ return BatchedPositions(null, "Received a location broadcast without an intent.")
253
+ }
254
+
255
+ val positions = LocationResult.extractResult(intent)?.locations?.takeIf { it.isNotEmpty() }
256
+ if (positions != null) {
257
+ return BatchedPositions(positions.map { it.toPosition() }, null)
258
+ }
259
+
260
+ val availability = LocationAvailability.extractLocationAvailability(intent)
261
+ if (availability != null && !availability.isLocationAvailable) {
262
+ return BatchedPositions(null, "Location is currently unavailable.")
263
+ }
264
+
265
+ return BatchedPositions(null, null)
266
+ }
267
+ }
@@ -1,9 +1,13 @@
1
1
  package expo.modules.location.next.locationProviders
2
2
 
3
3
  import android.app.Activity
4
+ import expo.modules.interfaces.taskManager.TaskConsumer
5
+ import expo.modules.interfaces.taskManager.TaskManagerInterface
4
6
  import expo.modules.kotlin.exception.CodedException
7
+ import expo.modules.location.next.LocationProfile
5
8
  import expo.modules.location.next.Position
6
9
  import kotlin.time.Duration
10
+ import kotlin.time.Duration.Companion.milliseconds
7
11
 
8
12
  enum class LocationPriority {
9
13
  HIGH_ACCURACY,
@@ -18,6 +22,45 @@ data class WatchPositionParameters(
18
22
  val maxUpdateDelay: Duration
19
23
  )
20
24
 
25
+ data class BackgroundUpdatesParameters(
26
+ val priority: LocationPriority,
27
+ val interval: Duration,
28
+ val maxUpdateDelay: Duration,
29
+ val minUpdateDistance: Float
30
+ ) {
31
+ fun toMap(): Map<String, Any> = mapOf(
32
+ KEY_PRIORITY to priority.name,
33
+ KEY_INTERVAL to interval.inWholeMilliseconds.toInt(),
34
+ KEY_MAX_UPDATE_DELAY to maxUpdateDelay.inWholeMilliseconds.toInt(),
35
+ KEY_MIN_UPDATE_DISTANCE to minUpdateDistance.toDouble()
36
+ )
37
+
38
+ companion object {
39
+ const val KEY_PRIORITY = "priority"
40
+ const val KEY_INTERVAL = "interval"
41
+ const val KEY_MAX_UPDATE_DELAY = "maxUpdateDelay"
42
+ const val KEY_MIN_UPDATE_DISTANCE = "minUpdateDistance"
43
+ }
44
+ }
45
+
46
+ fun Map<String, Any?>.toBackgroundUpdatesParameters(): BackgroundUpdatesParameters {
47
+ val fallback = LocationProfile.DEFAULT.toBackgroundUpdatesParameters()
48
+
49
+ val priority = (this[BackgroundUpdatesParameters.KEY_PRIORITY] as? String)
50
+ ?.let { name -> LocationPriority.entries.firstOrNull { it.name == name } }
51
+ ?: fallback.priority
52
+
53
+ return BackgroundUpdatesParameters(
54
+ priority = priority,
55
+ interval = (this[BackgroundUpdatesParameters.KEY_INTERVAL] as? Number)?.toLong()?.milliseconds
56
+ ?: fallback.interval,
57
+ maxUpdateDelay = (this[BackgroundUpdatesParameters.KEY_MAX_UPDATE_DELAY] as? Number)?.toLong()?.milliseconds
58
+ ?: fallback.maxUpdateDelay,
59
+ minUpdateDistance = (this[BackgroundUpdatesParameters.KEY_MIN_UPDATE_DISTANCE] as? Number)?.toFloat()
60
+ ?: fallback.minUpdateDistance
61
+ )
62
+ }
63
+
21
64
  sealed interface WatchUpdate {
22
65
  data class Fix(val position: Position) : WatchUpdate
23
66
  data class Failure(val cause: Throwable) : WatchUpdate
@@ -72,6 +115,11 @@ interface LocationProvider {
72
115
  // When returning EnableLocationServicesResult.ResolutionPending this call has to result in OnActivityResult
73
116
  // being called with payload.requestCode == SETTINGS_REQUEST_CODE
74
117
  suspend fun enableLocationServices(activity: Activity): ProviderResult<EnableLocationServicesResult> = ProviderResult.Unsupported
118
+
119
+ // This class must have (Context, TaskManagerUtilsInterface?) constructor as it will be constructed like this by TaskManager.
120
+ fun getLocationTaskConsumerClass(): ProviderResult<Class<out TaskConsumer>> = ProviderResult.Unsupported
121
+
122
+ fun getRegisteredTaskConsumerClass(taskManager: TaskManagerInterface, taskName: String): ProviderResult<Class<out TaskConsumer>> = ProviderResult.Unsupported
75
123
  }
76
124
 
77
125
  class OperationUnavailableException(functionName: String) : CodedException("$functionName is currently unavailable")
@@ -51,11 +51,17 @@ internal class LocationsStreamer: BaseStreamer {
51
51
  // Ignore `locationUnknown` (code 0) as it might be a temporary issue.
52
52
  // The location manager will keep trying to obtain the location.
53
53
  // It's a common error on simulator when there is no default location set in the scheme.
54
- guard let clError = error as? CLError, clError.code != .locationUnknown else {
54
+ switch error {
55
+ case CLError.locationUnknown:
55
56
  return
57
+ case CLError.denied where manager.authorizationStatus == .authorizedWhenInUse && CLLocationManager.locationServicesEnabled():
58
+ // The system sends CLError.denied when an app with whenInUse permission moves to the background.
59
+ // Updates resume on their own once the app returns to the foreground, so this error is ignored.
60
+ return
61
+ default:
62
+ continuation?.finish(throwing: Exceptions.LocationUnavailable().causedBy(error))
63
+ locationsStream = nil
64
+ continuation = nil
56
65
  }
57
- continuation?.finish(throwing: Exceptions.LocationUnavailable().causedBy(error))
58
- locationsStream = nil
59
- continuation = nil
60
66
  }
61
67
  }
@@ -28,6 +28,10 @@ public final class LocationModuleNext: Module {
28
28
  try permissions.requestBackgroundPermissions(options: options ?? PermissionsRequestOptions(), promise)
29
29
  }
30
30
 
31
+ Function("hasLocationServicesEnabled") { () -> Bool in
32
+ CLLocationManager.locationServicesEnabled()
33
+ }
34
+
31
35
  AsyncFunction("getPosition") { (options: GetPositionOptions?) -> Position? in
32
36
  guard CLLocationManager.locationServicesEnabled() else {
33
37
  throw LocationServicesDisabledGlobally()
@@ -36,14 +36,6 @@ final class LocationAuthorizationRestricted: Exception, @unchecked Sendable {
36
36
  }
37
37
  }
38
38
 
39
- final class LocationServiceSessionRequired: Exception, @unchecked Sendable {
40
- override var reason: String {
41
- "Location updates stopped because this app sets 'CLRequireExplicitServiceSession' in its " +
42
- "Info.plist, which makes the system refuse updates unless the app holds a CLServiceSession. " +
43
- "'expo-location' does not create one. Remove that key from your Info.plist, or manage the session " +
44
- "yourself and use CoreLocation directly"
45
- }
46
- }
47
39
 
48
40
  final class LocationUpdatesEndedUnexpectedly: Exception, @unchecked Sendable {
49
41
  override var reason: String {
@@ -36,11 +36,15 @@ final class LocationUpdatesHandle: SharedObject {
36
36
  }
37
37
 
38
38
  func stop() throws {
39
- try taskManager().unregisterTask(withName: taskName, consumerClass: LocationUpdatesTaskConsumer.self)
39
+ let taskManager = try taskManager()
40
+ guard taskManager.task(withName: taskName, hasConsumerOf: LocationUpdatesTaskConsumer.self) else {
41
+ return
42
+ }
43
+ taskManager.unregisterTask(withName: taskName, consumerClass: LocationUpdatesTaskConsumer.self)
40
44
  }
41
45
 
42
46
  func hasStarted() throws -> Bool {
43
- return try taskManager().hasRegisteredTask(withName: taskName)
47
+ return try taskManager().task(withName: taskName, hasConsumerOf: LocationUpdatesTaskConsumer.self)
44
48
  }
45
49
 
46
50
  private func taskManager() throws -> EXTaskManagerInterface {
@@ -19,9 +19,6 @@ struct LocationUpdateDiagnostics {
19
19
  if authorizationDenied {
20
20
  return LocationAuthorizationDenied()
21
21
  }
22
- if serviceSessionRequired {
23
- return LocationServiceSessionRequired()
24
- }
25
22
  return nil
26
23
  }
27
24
  }
@@ -1,7 +1,9 @@
1
1
  import CoreLocation
2
2
 
3
3
  final class PositionUpdatesCompatibilitySource: NSObject, CLLocationManagerDelegate {
4
- private lazy var manager = CLLocationManager()
4
+ var makeManager: () -> CLLocationManager = { CLLocationManager() }
5
+ var isLocationServicesEnabled: () -> Bool = CLLocationManager.locationServicesEnabled
6
+ private lazy var manager = makeManager()
5
7
  private var continuation: AsyncThrowingStream<CLLocation?, Error>.Continuation?
6
8
 
7
9
  func updates(for profile: Profile, allowsBackgroundUpdates: Bool = false) -> PositionUpdatesSource {
@@ -34,6 +36,12 @@ final class PositionUpdatesCompatibilitySource: NSObject, CLLocationManagerDeleg
34
36
  switch error {
35
37
  case CLError.locationUnknown:
36
38
  return
39
+ case CLError.denied where !isLocationServicesEnabled():
40
+ continuation?.finish(throwing: LocationServicesDisabledGlobally())
41
+ case CLError.denied where manager.authorizationStatus == .authorizedWhenInUse:
42
+ // The system sends CLError.denied when an app with whenInUse permission moves to the background.
43
+ // Updates resume on their own once the app returns to the foreground, so this error is ignored.
44
+ return
37
45
  case CLError.denied:
38
46
  continuation?.finish(throwing: LocationAuthorizationDenied())
39
47
  default:
@@ -12,6 +12,11 @@ final class PositionUpdatesLiveSource {
12
12
  guard !Task.isCancelled else {
13
13
  break
14
14
  }
15
+ // Drop once iOS 17 support ends: from iOS 18 CLLocationUpdate reports this itself through authorizationDeniedGlobally.
16
+ if #unavailable(iOS 18.0), !CLLocationManager.locationServicesEnabled() {
17
+ continuation.finish(throwing: LocationServicesDisabledGlobally())
18
+ return
19
+ }
15
20
  if #available(iOS 18.0, *), let failure = LocationUpdateDiagnostics(update).unrecoverableFailure() {
16
21
  continuation.finish(throwing: failure)
17
22
  return
@@ -0,0 +1 @@
1
+ 2ed2a869a5e37c5a5edde898652dc3d443031b72cb760096bc7cead5c679a093
@@ -0,0 +1 @@
1
+ 754bf7d78dcdcd4a001ab127cc0d13faf1ce088882f97768477ca3a598949a74b1082c286124209d9d153d217f05962c1b7dd5af020d676b0528cec7acd8324b
@@ -0,0 +1 @@
1
+ a0354ad035132a71b1b850e7f5553c0f56a3e605b192597a006baccfaa0e68ee
@@ -0,0 +1 @@
1
+ 580c04137e6b5489d24dc4f2dcf4c41953c968f7f01ad752e40990279392293f2e78993306620b3733e1c502e98df07b4d60e1785519d54c6209aa266c59846c
@@ -3,7 +3,7 @@
3
3
  "component": {
4
4
  "group": "host.exp.exponent",
5
5
  "module": "expo.modules.location",
6
- "version": "58.0.13",
6
+ "version": "58.0.14",
7
7
  "attributes": {
8
8
  "org.gradle.status": "release"
9
9
  }
@@ -33,13 +33,13 @@
33
33
  ],
34
34
  "files": [
35
35
  {
36
- "name": "expo.modules.location-58.0.13.aar",
37
- "url": "expo.modules.location-58.0.13.aar",
38
- "size": 450277,
39
- "sha512": "1d52e7849fe29a33c686fca271fd5b2696ebbb050617ee2d081e3aeae4c4c4a0826fb6b4b8eef4c790ad72aa5d49701cc96c92caacec3e484a3a4930dc45a5c8",
40
- "sha256": "30515d0f37957d667880e577c9bc247dfd4e84c9058574413e850893e83c3406",
41
- "sha1": "9784711dc85345dfb3100c08a4061f4121806394",
42
- "md5": "fd583896233d35b7c90515551e9751c6"
36
+ "name": "expo.modules.location-58.0.14.aar",
37
+ "url": "expo.modules.location-58.0.14.aar",
38
+ "size": 579757,
39
+ "sha512": "580c04137e6b5489d24dc4f2dcf4c41953c968f7f01ad752e40990279392293f2e78993306620b3733e1c502e98df07b4d60e1785519d54c6209aa266c59846c",
40
+ "sha256": "a0354ad035132a71b1b850e7f5553c0f56a3e605b192597a006baccfaa0e68ee",
41
+ "sha1": "b46740b9cf9cf3992d5296612cd1fdd7dbacf6af",
42
+ "md5": "c5ffbaf9ab0ba003130b9c197242fbb9"
43
43
  }
44
44
  ]
45
45
  },
@@ -90,13 +90,13 @@
90
90
  ],
91
91
  "files": [
92
92
  {
93
- "name": "expo.modules.location-58.0.13.aar",
94
- "url": "expo.modules.location-58.0.13.aar",
95
- "size": 450277,
96
- "sha512": "1d52e7849fe29a33c686fca271fd5b2696ebbb050617ee2d081e3aeae4c4c4a0826fb6b4b8eef4c790ad72aa5d49701cc96c92caacec3e484a3a4930dc45a5c8",
97
- "sha256": "30515d0f37957d667880e577c9bc247dfd4e84c9058574413e850893e83c3406",
98
- "sha1": "9784711dc85345dfb3100c08a4061f4121806394",
99
- "md5": "fd583896233d35b7c90515551e9751c6"
93
+ "name": "expo.modules.location-58.0.14.aar",
94
+ "url": "expo.modules.location-58.0.14.aar",
95
+ "size": 579757,
96
+ "sha512": "580c04137e6b5489d24dc4f2dcf4c41953c968f7f01ad752e40990279392293f2e78993306620b3733e1c502e98df07b4d60e1785519d54c6209aa266c59846c",
97
+ "sha256": "a0354ad035132a71b1b850e7f5553c0f56a3e605b192597a006baccfaa0e68ee",
98
+ "sha1": "b46740b9cf9cf3992d5296612cd1fdd7dbacf6af",
99
+ "md5": "c5ffbaf9ab0ba003130b9c197242fbb9"
100
100
  }
101
101
  ]
102
102
  },
@@ -110,13 +110,13 @@
110
110
  },
111
111
  "files": [
112
112
  {
113
- "name": "expo.modules.location-58.0.13-sources.jar",
114
- "url": "expo.modules.location-58.0.13-sources.jar",
115
- "size": 39982,
116
- "sha512": "a0bb6a2c55e0c88b6c92553b3a5b05b5b24c604ade8388a46fd758221a2a8b4fb5f2ffb2ad7f3977794932f541aff21f9a5be896510654a963137bbd00ca11e4",
117
- "sha256": "36352dc221d755d69fb9a847a78836e1e359ad0443743aaa7f5f2648ddf76f87",
118
- "sha1": "2376a0dbedbda141dd71a8de6daa7d6c7cbbe4ab",
119
- "md5": "b6131ece5f5a18998ce0571f54242774"
113
+ "name": "expo.modules.location-58.0.14-sources.jar",
114
+ "url": "expo.modules.location-58.0.14-sources.jar",
115
+ "size": 52474,
116
+ "sha512": "754bf7d78dcdcd4a001ab127cc0d13faf1ce088882f97768477ca3a598949a74b1082c286124209d9d153d217f05962c1b7dd5af020d676b0528cec7acd8324b",
117
+ "sha256": "2ed2a869a5e37c5a5edde898652dc3d443031b72cb760096bc7cead5c679a093",
118
+ "sha1": "5e51ba05092c52103172e9c7012ecb1bc3b64b65",
119
+ "md5": "58ae38f7654193dabccf9c31829dea9f"
120
120
  }
121
121
  ]
122
122
  }
@@ -0,0 +1 @@
1
+ f10b8dc1525af7ca7fad1f3bd990ec8cee27e8a65e75d0356f4f69722481204b
@@ -0,0 +1 @@
1
+ 339e86d287dadc8b784bc9530030059a2ce539915d6840e095b49ff160384d75a549297e5f13fc71811506321a6b99bf9c9b90cf25f3d462c00d6fba4237c925
@@ -9,7 +9,7 @@
9
9
  <modelVersion>4.0.0</modelVersion>
10
10
  <groupId>host.exp.exponent</groupId>
11
11
  <artifactId>expo.modules.location</artifactId>
12
- <version>58.0.13</version>
12
+ <version>58.0.14</version>
13
13
  <packaging>aar</packaging>
14
14
  <name>expo.modules.location</name>
15
15
  <url>https://github.com/expo/expo</url>
@@ -0,0 +1 @@
1
+ 5de8a214eecac78df9d1939a91be60dd889b2851dfed6360cc2ed8e581b3c262