expo-location 58.0.13 → 58.0.15
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.
- package/CHANGELOG.md +21 -0
- package/android/build.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/expo/modules/location/next/LocationModuleNext.kt +189 -10
- package/android/src/main/java/expo/modules/location/next/LocationPermissions.kt +65 -0
- package/android/src/main/java/expo/modules/location/next/LocationRecords.kt +91 -2
- package/android/src/main/java/expo/modules/location/next/LocationTaskConsumer.kt +205 -0
- package/android/src/main/java/expo/modules/location/next/WatchPosition.kt +8 -6
- package/android/src/main/java/expo/modules/location/next/locationForegroundService/BackgroundSessionOptions.kt +62 -0
- package/android/src/main/java/expo/modules/location/next/locationForegroundService/BackgroundSessionTypes.kt +32 -0
- package/android/src/main/java/expo/modules/location/next/locationForegroundService/ForegroundServiceExceptions.kt +53 -0
- package/android/src/main/java/expo/modules/location/next/locationForegroundService/LocationForegroundService.kt +142 -0
- package/android/src/main/java/expo/modules/location/next/locationForegroundService/ServiceNotification.kt +64 -0
- package/android/src/main/java/expo/modules/location/next/locationProviders/AndroidLocationProvider.kt +115 -7
- package/android/src/main/java/expo/modules/location/next/locationProviders/FallbackLocationProvider.kt +12 -3
- package/android/src/main/java/expo/modules/location/next/locationProviders/GmsLocationProvider.kt +79 -0
- package/android/src/main/java/expo/modules/location/next/locationProviders/LocationProvider.kt +48 -0
- package/android/src/main/java/expo/modules/location/taskConsumers/LocationTaskConsumer.kt +6 -0
- package/build/next/index.d.ts +1 -1
- package/build/next/index.js.map +1 -1
- package/build/next/js/LocationProvider.d.ts +35 -0
- package/build/next/js/LocationProvider.js +35 -6
- package/build/next/js/LocationProvider.js.map +1 -1
- package/build/next/js/LocationUpdatesHandle.d.ts +45 -7
- package/build/next/js/LocationUpdatesHandle.js +43 -7
- package/build/next/js/LocationUpdatesHandle.js.map +1 -1
- package/build/next/js/Permissions.d.ts +63 -0
- package/build/next/js/Permissions.js +63 -6
- package/build/next/js/Permissions.js.map +1 -1
- package/build/next/js/PositionWatchHandle.d.ts +78 -0
- package/build/next/js/PositionWatchHandle.js +78 -11
- package/build/next/js/PositionWatchHandle.js.map +1 -1
- package/build/next/js/getPosition.d.ts +26 -1
- package/build/next/js/getPosition.js +26 -2
- package/build/next/js/getPosition.js.map +1 -1
- package/build/next/js/locationServices.d.ts +29 -0
- package/build/next/js/locationServices.js +29 -3
- package/build/next/js/locationServices.js.map +1 -1
- package/build/next/types/LocationTask.types.d.ts +20 -0
- package/build/next/types/LocationTask.types.js +5 -0
- package/build/next/types/LocationTask.types.js.map +1 -0
- package/build/next/types/Permissions.types.d.ts +68 -0
- package/build/next/types/Permissions.types.js +51 -9
- package/build/next/types/Permissions.types.js.map +1 -1
- package/build/next/types/Position.types.d.ts +203 -2
- package/build/next/types/Position.types.js +51 -7
- package/build/next/types/Position.types.js.map +1 -1
- package/build/next/types/index.d.ts +1 -0
- package/build/next/types/index.js +1 -0
- package/build/next/types/index.js.map +1 -1
- package/ios/Providers/LocationsStreamer.swift +10 -4
- package/ios/TaskConsumers/EXGeofencingTaskConsumer.m +16 -1
- package/ios/next/LocationModuleNext.swift +4 -0
- package/ios/next/LocationNextExceptions.swift +0 -8
- package/ios/next/LocationUpdatesHandle/LocationUpdatesHandle.swift +6 -2
- package/ios/next/Position/LocationUpdateDiagnostics.swift +0 -3
- package/ios/next/Position/PositionUpdatesCompatibilitySource.swift +9 -1
- package/ios/next/Position/PositionUpdatesLiveSource.swift +5 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15-sources.jar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15-sources.jar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15-sources.jar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15-sources.jar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15-sources.jar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.aar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.aar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.aar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.aar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.13/expo.modules.location-58.0.13.module → 58.0.15/expo.modules.location-58.0.15.module} +22 -22
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.module.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.module.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.module.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.module.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.13/expo.modules.location-58.0.13.pom → 58.0.15/expo.modules.location-58.0.15.pom} +1 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.pom.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.pom.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.pom.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.15/expo.modules.location-58.0.15.pom.sha512 +1 -0
- package/package.json +2 -2
- package/plugin/build/withLocation.js +2 -0
- package/plugin/build/withLocation.js.map +1 -1
- package/plugin/src/withLocation.ts +2 -0
- package/src/next/index.ts +1 -0
- package/src/next/js/LocationProvider.ts +35 -0
- package/src/next/js/LocationUpdatesHandle.ts +45 -8
- package/src/next/js/Permissions.ts +63 -0
- package/src/next/js/PositionWatchHandle.ts +78 -0
- package/src/next/js/getPosition.ts +29 -2
- package/src/next/js/locationServices.ts +29 -0
- package/src/next/types/LocationTask.types.ts +22 -0
- package/src/next/types/Permissions.types.ts +68 -0
- package/src/next/types/Position.types.ts +203 -2
- package/src/next/types/index.ts +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha256 +0 -1
- 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
|
|
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
|
|
40
|
+
val providers = locationManager.getProviders(enabledOnly)
|
|
33
41
|
// Avoid GPS_PROVIDER, when only coarse permissions are given.
|
|
34
|
-
return
|
|
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
|
|
65
|
+
private fun desiredSystemProvider(locationPriority: LocationPriority): String {
|
|
55
66
|
// Pick the desired provider based on LocationPriority options
|
|
56
|
-
|
|
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
|
-
|
|
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? =
|
|
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
|
|
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
|
}
|
package/android/src/main/java/expo/modules/location/next/locationProviders/GmsLocationProvider.kt
CHANGED
|
@@ -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
|
+
}
|
package/android/src/main/java/expo/modules/location/next/locationProviders/LocationProvider.kt
CHANGED
|
@@ -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")
|
|
@@ -222,6 +222,12 @@ class LocationTaskConsumer(context: Context, taskManagerUtils: TaskManagerUtilsI
|
|
|
222
222
|
mService?.let {
|
|
223
223
|
it.setParentContext(context)
|
|
224
224
|
it.startForeground(serviceOptions)
|
|
225
|
+
// The task was unregistered while this bind was pending: didUnregister() found no
|
|
226
|
+
// service to stop. Stop it now. startForeground() above is still required, since the
|
|
227
|
+
// service was started with startForegroundService().
|
|
228
|
+
if (mTask == null) {
|
|
229
|
+
stopForegroundService()
|
|
230
|
+
}
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
|
package/build/next/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * as Location from './Location';
|
|
2
2
|
export { useForegroundLocationPermissions, useBackgroundLocationPermissions, useLocationServices, PositionWatchHandle, LocationProvider, LocationUpdatesHandle, defineLocationTask, } from './js';
|
|
3
|
-
export { LocationProfile, LocationAccuracy, LocationScope, RequestPermissionsAccuracyOption, type Coordinates, type Position, type PositionUpdate, type PositionWatchError, type PositionWatchStatus, type WatchPositionParams, type GetPositionOptions, type LocationPermissionResponse, type RequestPermissionsOptions, type LocationProviderRefType, } from './types';
|
|
3
|
+
export { LocationProfile, LocationAccuracy, LocationScope, RequestPermissionsAccuracyOption, type Coordinates, type Position, type PositionUpdate, type PositionWatchError, type PositionWatchStatus, type WatchPositionParams, type GetPositionOptions, type LocationTaskOptions, type LocationPermissionResponse, type RequestPermissionsOptions, type LocationProviderRefType, } from './types';
|
package/build/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["next/index.ts"],"sourcesContent":[null],"names":["Location","useForegroundLocationPermissions","useBackgroundLocationPermissions","useLocationServices","PositionWatchHandle","LocationProvider","LocationUpdatesHandle","defineLocationTask","LocationProfile","LocationAccuracy","LocationScope","RequestPermissionsAccuracyOption"],"mappings":"AAAA,OAAO,KAAKA,QAAQ,MAAM,aAAa;AAEvC,SACEC,gCAAgC,EAChCC,gCAAgC,EAChCC,mBAAmB,EACnBC,mBAAmB,EACnBC,gBAAgB,EAChBC,qBAAqB,EACrBC,kBAAkB,QACb,OAAO;AAEd,SACEC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,EACbC,gCAAgC,
|
|
1
|
+
{"version":3,"sources":["next/index.ts"],"sourcesContent":[null],"names":["Location","useForegroundLocationPermissions","useBackgroundLocationPermissions","useLocationServices","PositionWatchHandle","LocationProvider","LocationUpdatesHandle","defineLocationTask","LocationProfile","LocationAccuracy","LocationScope","RequestPermissionsAccuracyOption"],"mappings":"AAAA,OAAO,KAAKA,QAAQ,MAAM,aAAa;AAEvC,SACEC,gCAAgC,EAChCC,gCAAgC,EAChCC,mBAAmB,EACnBC,mBAAmB,EACnBC,gBAAgB,EAChBC,qBAAqB,EACrBC,kBAAkB,QACb,OAAO;AAEd,SACEC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,EACbC,gCAAgC,QAY3B,UAAU"}
|
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
import type { SharedRef } from 'expo';
|
|
2
2
|
import type { LocationProviderRefType } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* The backends that can serve positions on Android. The default tries Google Play services first
|
|
5
|
+
* and falls back to the Android framework, so most apps never need this. Pass the result to
|
|
6
|
+
* `setLocationProvider`.
|
|
7
|
+
*
|
|
8
|
+
* @platform android
|
|
9
|
+
*/
|
|
3
10
|
export declare class LocationProvider {
|
|
11
|
+
/**
|
|
12
|
+
* The fused location provider from Google Play services.
|
|
13
|
+
*
|
|
14
|
+
* @platform android
|
|
15
|
+
*/
|
|
4
16
|
static Gms(): SharedRef<LocationProviderRefType>;
|
|
17
|
+
/**
|
|
18
|
+
* The Android framework `LocationManager`, available without Google Play services.
|
|
19
|
+
*
|
|
20
|
+
* @platform android
|
|
21
|
+
*/
|
|
5
22
|
static Android(): SharedRef<LocationProviderRefType>;
|
|
23
|
+
/**
|
|
24
|
+
* Tries the providers in order and uses the first one that can serve the request.
|
|
25
|
+
*
|
|
26
|
+
* @param providers The providers to try, most preferred first.
|
|
27
|
+
* @platform android
|
|
28
|
+
*/
|
|
6
29
|
static Fallback(providers: SharedRef<LocationProviderRefType>[]): SharedRef<LocationProviderRefType>;
|
|
7
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Selects the provider that serves all later location requests.
|
|
33
|
+
*
|
|
34
|
+
* @param provider A provider from `LocationProvider`.
|
|
35
|
+
* @platform android
|
|
36
|
+
*/
|
|
8
37
|
export declare function setLocationProvider(provider: SharedRef<LocationProviderRefType>): void;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the name of the provider currently serving positions: `GMS`, `Android`, or the chain of a
|
|
40
|
+
* fallback, such as the default `Fallback: GMS -> Android`.
|
|
41
|
+
*
|
|
42
|
+
* @platform android
|
|
43
|
+
*/
|
|
9
44
|
export declare function getSelectedLocationProviderName(): string;
|
|
@@ -1,19 +1,48 @@
|
|
|
1
1
|
import { NativeLocationModuleNext, NativeLocationProvider } from '../native';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The backends that can serve positions on Android. The default tries Google Play services first
|
|
4
|
+
* and falls back to the Android framework, so most apps never need this. Pass the result to
|
|
5
|
+
* `setLocationProvider`.
|
|
6
|
+
*
|
|
7
|
+
* @platform android
|
|
8
|
+
*/ export class LocationProvider {
|
|
9
|
+
/**
|
|
10
|
+
* The fused location provider from Google Play services.
|
|
11
|
+
*
|
|
12
|
+
* @platform android
|
|
13
|
+
*/ static Gms() {
|
|
4
14
|
return NativeLocationProvider.Gms();
|
|
5
15
|
}
|
|
6
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The Android framework `LocationManager`, available without Google Play services.
|
|
18
|
+
*
|
|
19
|
+
* @platform android
|
|
20
|
+
*/ static Android() {
|
|
7
21
|
return NativeLocationProvider.Android();
|
|
8
22
|
}
|
|
9
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Tries the providers in order and uses the first one that can serve the request.
|
|
25
|
+
*
|
|
26
|
+
* @param providers The providers to try, most preferred first.
|
|
27
|
+
* @platform android
|
|
28
|
+
*/ static Fallback(providers) {
|
|
10
29
|
return NativeLocationProvider.Fallback(providers);
|
|
11
30
|
}
|
|
12
31
|
}
|
|
13
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Selects the provider that serves all later location requests.
|
|
34
|
+
*
|
|
35
|
+
* @param provider A provider from `LocationProvider`.
|
|
36
|
+
* @platform android
|
|
37
|
+
*/ export function setLocationProvider(provider) {
|
|
14
38
|
NativeLocationModuleNext.setLocationProvider(provider);
|
|
15
39
|
}
|
|
16
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Gets the name of the provider currently serving positions: `GMS`, `Android`, or the chain of a
|
|
42
|
+
* fallback, such as the default `Fallback: GMS -> Android`.
|
|
43
|
+
*
|
|
44
|
+
* @platform android
|
|
45
|
+
*/ export function getSelectedLocationProviderName() {
|
|
17
46
|
return NativeLocationModuleNext.getSelectedLocationProviderName();
|
|
18
47
|
}
|
|
19
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["next/js/LocationProvider.ts"],"sourcesContent":[null],"names":["NativeLocationModuleNext","NativeLocationProvider","LocationProvider","Gms","Android","Fallback","providers","setLocationProvider","provider","getSelectedLocationProviderName"],"mappings":"AAEA,SAASA,wBAAwB,EAAEC,sBAAsB,QAAQ,YAAY;AAG7E,OAAO,MAAMC;IACX,OAAOC,MAA0C;QAC/C,OAAOF,uBAAuBE,GAAG;IACnC;IAEA,OAAOC,UAA8C;QACnD,OAAOH,uBAAuBG,OAAO;IACvC;IAEA,OAAOC,SACLC,SAA+C,EACX;QACpC,OAAOL,uBAAuBI,QAAQ,CAACC;IACzC;AACF;AAEA,OAAO,SAASC,oBAAoBC,QAA4C;IAC9ER,yBAAyBO,mBAAmB,CAACC;AAC/C;AAEA,OAAO,SAASC;IACd,OAAOT,yBAAyBS,+BAA+B;AACjE"}
|
|
1
|
+
{"version":3,"sources":["next/js/LocationProvider.ts"],"sourcesContent":[null],"names":["NativeLocationModuleNext","NativeLocationProvider","LocationProvider","Gms","Android","Fallback","providers","setLocationProvider","provider","getSelectedLocationProviderName"],"mappings":"AAEA,SAASA,wBAAwB,EAAEC,sBAAsB,QAAQ,YAAY;AAG7E;;;;;;CAMC,GACD,OAAO,MAAMC;IACX;;;;GAIC,GACD,OAAOC,MAA0C;QAC/C,OAAOF,uBAAuBE,GAAG;IACnC;IAEA;;;;GAIC,GACD,OAAOC,UAA8C;QACnD,OAAOH,uBAAuBG,OAAO;IACvC;IAEA;;;;;GAKC,GACD,OAAOC,SACLC,SAA+C,EACX;QACpC,OAAOL,uBAAuBI,QAAQ,CAACC;IACzC;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,QAA4C;IAC9ER,yBAAyBO,mBAAmB,CAACC;AAC/C;AAEA;;;;;CAKC,GACD,OAAO,SAASC;IACd,OAAOT,yBAAyBS,+BAA+B;AACjE"}
|
|
@@ -1,15 +1,53 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { LocationProfile, LocationTaskOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Starts and stops the delivery of positions to the task defined with `defineLocationTask`.
|
|
4
|
+
* The delivery is registered with the system, so it outlives the JS context: it survives the app
|
|
5
|
+
* moving to the background and, with the background permission, the app being terminated.
|
|
6
|
+
*
|
|
7
|
+
* On Android, positions keep arriving after the app process ended. Requires the background
|
|
8
|
+
* permission.
|
|
9
|
+
*
|
|
10
|
+
* On iOS, positions come from `CLLocationUpdate.liveUpdates`. Requires the `location` background
|
|
11
|
+
* mode and the foreground permission.
|
|
12
|
+
*
|
|
13
|
+
* See [Receive positions in the background](#receive-positions-in-the-background).
|
|
14
|
+
*/
|
|
3
15
|
export declare class LocationUpdatesHandle {
|
|
4
16
|
private readonly nativeHandle;
|
|
17
|
+
/**
|
|
18
|
+
* @param taskName The task that receives the positions. Must match the name passed to
|
|
19
|
+
* `defineLocationTask`; both default to the same name.
|
|
20
|
+
*/
|
|
5
21
|
constructor(taskName?: string);
|
|
22
|
+
/**
|
|
23
|
+
* Stages the profile for the next `start()`. It has no effect on a delivery that is already
|
|
24
|
+
* running; call `stop()` and `start()` again to apply it.
|
|
25
|
+
*
|
|
26
|
+
* @return The same handle, for chaining.
|
|
27
|
+
*/
|
|
6
28
|
withProfile(profile: LocationProfile): this;
|
|
29
|
+
/**
|
|
30
|
+
* Registers the delivery with the system and starts sending positions to the task.
|
|
31
|
+
* @throws When location services are off or the required permission is missing: the background
|
|
32
|
+
* permission on Android, the foreground permission on iOS, where the `location` background mode
|
|
33
|
+
* is also required.
|
|
34
|
+
*/
|
|
7
35
|
start(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Unregisters the delivery. Positions stop arriving and the app is no longer relaunched for them.
|
|
38
|
+
*/
|
|
8
39
|
stop(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Checks whether the delivery is registered with the system. It stays registered across app
|
|
42
|
+
* restarts, so check it on launch before calling `start()` again.
|
|
43
|
+
*/
|
|
9
44
|
hasStarted(): Promise<boolean>;
|
|
10
45
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Defines the task that receives the positions started with `LocationUpdatesHandle`.
|
|
48
|
+
* Wraps `TaskManager.defineTask`, so call it in the global scope of a module imported at startup.
|
|
49
|
+
* See [Receive positions in the background](#receive-positions-in-the-background).
|
|
50
|
+
*
|
|
51
|
+
* @param options The task name and the callbacks for positions and errors.
|
|
52
|
+
*/
|
|
53
|
+
export declare function defineLocationTask({ taskName, onPosition, onError, }: LocationTaskOptions): void;
|
|
@@ -1,25 +1,61 @@
|
|
|
1
1
|
import { NativeLocationUpdatesHandle } from '../native';
|
|
2
2
|
const DEFAULT_LOCATION_TASK_NAME = 'expo-location-background-location';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Starts and stops the delivery of positions to the task defined with `defineLocationTask`.
|
|
5
|
+
* The delivery is registered with the system, so it outlives the JS context: it survives the app
|
|
6
|
+
* moving to the background and, with the background permission, the app being terminated.
|
|
7
|
+
*
|
|
8
|
+
* On Android, positions keep arriving after the app process ended. Requires the background
|
|
9
|
+
* permission.
|
|
10
|
+
*
|
|
11
|
+
* On iOS, positions come from `CLLocationUpdate.liveUpdates`. Requires the `location` background
|
|
12
|
+
* mode and the foreground permission.
|
|
13
|
+
*
|
|
14
|
+
* See [Receive positions in the background](#receive-positions-in-the-background).
|
|
15
|
+
*/ export class LocationUpdatesHandle {
|
|
4
16
|
nativeHandle;
|
|
5
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param taskName The task that receives the positions. Must match the name passed to
|
|
19
|
+
* `defineLocationTask`; both default to the same name.
|
|
20
|
+
*/ constructor(taskName = DEFAULT_LOCATION_TASK_NAME){
|
|
6
21
|
this.nativeHandle = new NativeLocationUpdatesHandle(taskName);
|
|
7
22
|
}
|
|
8
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Stages the profile for the next `start()`. It has no effect on a delivery that is already
|
|
25
|
+
* running; call `stop()` and `start()` again to apply it.
|
|
26
|
+
*
|
|
27
|
+
* @return The same handle, for chaining.
|
|
28
|
+
*/ withProfile(profile) {
|
|
9
29
|
this.nativeHandle.withProfile(profile);
|
|
10
30
|
return this;
|
|
11
31
|
}
|
|
12
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Registers the delivery with the system and starts sending positions to the task.
|
|
34
|
+
* @throws When location services are off or the required permission is missing: the background
|
|
35
|
+
* permission on Android, the foreground permission on iOS, where the `location` background mode
|
|
36
|
+
* is also required.
|
|
37
|
+
*/ start() {
|
|
13
38
|
return this.nativeHandle.start();
|
|
14
39
|
}
|
|
15
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Unregisters the delivery. Positions stop arriving and the app is no longer relaunched for them.
|
|
42
|
+
*/ stop() {
|
|
16
43
|
return this.nativeHandle.stop();
|
|
17
44
|
}
|
|
18
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Checks whether the delivery is registered with the system. It stays registered across app
|
|
47
|
+
* restarts, so check it on launch before calling `start()` again.
|
|
48
|
+
*/ hasStarted() {
|
|
19
49
|
return this.nativeHandle.hasStarted();
|
|
20
50
|
}
|
|
21
51
|
}
|
|
22
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Defines the task that receives the positions started with `LocationUpdatesHandle`.
|
|
54
|
+
* Wraps `TaskManager.defineTask`, so call it in the global scope of a module imported at startup.
|
|
55
|
+
* See [Receive positions in the background](#receive-positions-in-the-background).
|
|
56
|
+
*
|
|
57
|
+
* @param options The task name and the callbacks for positions and errors.
|
|
58
|
+
*/ export function defineLocationTask({ taskName = DEFAULT_LOCATION_TASK_NAME, onPosition, onError }) {
|
|
23
59
|
requireTaskManager().defineTask(taskName, async ({ data, error })=>{
|
|
24
60
|
if (error) {
|
|
25
61
|
onError?.(error);
|