expo-location 16.5.2 → 16.5.4

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 CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 16.5.4 — 2024-02-27
14
+
15
+ ### 🎉 New features
16
+
17
+ - [Android] Make foreground service permission opt-in with `isAndroidForegroundServiceEnabled` config plugin option [#27265](https://github.com/expo/expo/pull/27265) by [@brentvatne](https://github.com/brentvatne))
18
+
19
+ ## 16.5.3 — 2024-02-06
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - [Android] Fixed: `NullPointerException: it must not be null`. ([#26688](https://github.com/expo/expo/pull/26688) by [@lukmccall](https://github.com/lukmccall))
24
+
13
25
  ## 16.5.2 — 2024-01-10
14
26
 
15
27
  ### 🎉 New features
package/README.md CHANGED
@@ -51,13 +51,14 @@ This module requires the permissions for approximate and exact device location.
51
51
  <!-- Added permissions -->
52
52
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
53
53
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
54
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
55
54
 
56
55
  <!-- Optional permissions -->
56
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
57
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
57
58
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
58
59
  ```
59
60
 
60
- > **Note:** on Android, you have to [submit your app for review and request access to use the background location permission](https://support.google.com/googleplay/android-developer/answer/9799150?hl=en).
61
+ > **Note:** on Android, you have to [submit your app for review and request access to use the background location permission](https://support.google.com/googleplay/android-developer/answer/9799150?hl=en) or [foreground location permissions](https://support.google.com/googleplay/android-developer/answer/13392821?hl=en).
61
62
 
62
63
  # Contributing
63
64
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '16.5.2'
6
+ version = '16.5.4'
7
7
 
8
8
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
9
  if (expoModulesCorePlugin.exists()) {
@@ -94,7 +94,7 @@ android {
94
94
  namespace "expo.modules.location"
95
95
  defaultConfig {
96
96
  versionCode 29
97
- versionName "16.5.2"
97
+ versionName "16.5.4"
98
98
  }
99
99
  }
100
100
 
@@ -1,8 +1,6 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
2
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
3
3
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
4
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
5
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
6
4
 
7
5
  <application>
8
6
  <service
@@ -14,6 +14,9 @@ internal class LocationBackgroundUnauthorizedException :
14
14
  internal class LocationRequestRejectedException(cause: Exception) :
15
15
  CodedException("Location request has been rejected: " + cause.message)
16
16
 
17
+ internal class CurrentLocationIsUnavailableException :
18
+ CodedException("Current location is unavailable. Make sure that location services are enabled")
19
+
17
20
  internal class LocationRequestCancelledException :
18
21
  CodedException("Location request has been cancelled")
19
22
 
@@ -69,8 +69,13 @@ class LocationHelpers {
69
69
  fun requestSingleLocation(locationProvider: FusedLocationProviderClient, locationRequest: CurrentLocationRequest, promise: Promise) {
70
70
  try {
71
71
  locationProvider.getCurrentLocation(locationRequest, null)
72
- .addOnSuccessListener {
73
- promise.resolve(LocationResponse(it))
72
+ .addOnSuccessListener { location: Location? ->
73
+ if (location == null) {
74
+ promise.reject(CurrentLocationIsUnavailableException())
75
+ return@addOnSuccessListener
76
+ }
77
+
78
+ promise.resolve(LocationResponse(location))
74
79
  }
75
80
  .addOnFailureListener {
76
81
  promise.reject(LocationRequestRejectedException(it))
@@ -166,7 +171,8 @@ class LocationHelpers {
166
171
  }
167
172
 
168
173
  fun isAnyProviderAvailable(context: Context?): Boolean {
169
- val locationManager = context?.getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return false
174
+ val locationManager = context?.getSystemService(Context.LOCATION_SERVICE) as? LocationManager
175
+ ?: return false
170
176
  return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
171
177
  }
172
178
 
@@ -177,7 +183,8 @@ class LocationHelpers {
177
183
  contextPermissions,
178
184
  object : Promise {
179
185
  override fun resolve(value: Any?) {
180
- val result = value as? Bundle ?: throw ConversionException(Any::class.java, Bundle::class.java, "value returned by the permission promise is not a Bundle")
186
+ val result = value as? Bundle
187
+ ?: throw ConversionException(Any::class.java, Bundle::class.java, "value returned by the permission promise is not a Bundle")
181
188
  continuation.resume(PermissionRequestResponse(result))
182
189
  }
183
190
 
@@ -197,7 +204,10 @@ class LocationHelpers {
197
204
  contextPermissions,
198
205
  object : Promise {
199
206
  override fun resolve(value: Any?) {
200
- it.resume(value as? Bundle ?: throw ConversionException(Any::class.java, Bundle::class.java, "value returned by the permission promise is not a Bundle"))
207
+ it.resume(
208
+ value as? Bundle
209
+ ?: throw ConversionException(Any::class.java, Bundle::class.java, "value returned by the permission promise is not a Bundle")
210
+ )
201
211
  }
202
212
 
203
213
  override fun reject(code: String, message: String?, cause: Throwable?) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-location",
3
- "version": "16.5.2",
3
+ "version": "16.5.4",
4
4
  "description": "Allows reading geolocation information from the device. Your app can poll for the current location or subscribe to location update events.",
5
5
  "main": "build/Location.js",
6
6
  "types": "build/Location.d.ts",
@@ -44,5 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "expo": "*"
46
46
  },
47
- "gitHead": "ca014bf2516c7644ef303f4c21fdd68de4d99f76"
47
+ "gitHead": "e94e2aac39cbb7f8788869cd6798bbdeadc58f42"
48
48
  }
@@ -5,5 +5,6 @@ declare const _default: ConfigPlugin<void | {
5
5
  locationWhenInUsePermission?: string | undefined;
6
6
  isIosBackgroundLocationEnabled?: boolean | undefined;
7
7
  isAndroidBackgroundLocationEnabled?: boolean | undefined;
8
+ isAndroidForegroundServiceEnabled?: boolean | undefined;
8
9
  }>;
9
10
  export default _default;
@@ -14,7 +14,7 @@ const withBackgroundLocation = (config) => {
14
14
  return config;
15
15
  });
16
16
  };
17
- const withLocation = (config, { locationAlwaysAndWhenInUsePermission, locationAlwaysPermission, locationWhenInUsePermission, isIosBackgroundLocationEnabled, isAndroidBackgroundLocationEnabled, } = {}) => {
17
+ const withLocation = (config, { locationAlwaysAndWhenInUsePermission, locationAlwaysPermission, locationWhenInUsePermission, isIosBackgroundLocationEnabled, isAndroidBackgroundLocationEnabled, isAndroidForegroundServiceEnabled, } = {}) => {
18
18
  if (isIosBackgroundLocationEnabled) {
19
19
  config = withBackgroundLocation(config);
20
20
  }
@@ -34,11 +34,14 @@ const withLocation = (config, { locationAlwaysAndWhenInUsePermission, locationAl
34
34
  return config;
35
35
  });
36
36
  return config_plugins_1.AndroidConfig.Permissions.withPermissions(config, [
37
+ // Note: these are already added in the library AndroidManifest.xml and so
38
+ // are not required here, we may want to remove them in the future.
37
39
  'android.permission.ACCESS_COARSE_LOCATION',
38
40
  'android.permission.ACCESS_FINE_LOCATION',
39
- 'android.permission.FOREGROUND_SERVICE',
40
- // Optional
41
+ // These permissions are optional, and not listed in the library AndroidManifest.xml
41
42
  isAndroidBackgroundLocationEnabled && 'android.permission.ACCESS_BACKGROUND_LOCATION',
43
+ isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE',
44
+ isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE_LOCATION',
42
45
  ].filter(Boolean));
43
46
  };
44
47
  exports.default = (0, config_plugins_1.createRunOncePlugin)(withLocation, pkg.name, pkg.version);
@@ -27,6 +27,7 @@ const withLocation: ConfigPlugin<
27
27
  locationWhenInUsePermission?: string;
28
28
  isIosBackgroundLocationEnabled?: boolean;
29
29
  isAndroidBackgroundLocationEnabled?: boolean;
30
+ isAndroidForegroundServiceEnabled?: boolean;
30
31
  } | void
31
32
  > = (
32
33
  config,
@@ -36,6 +37,7 @@ const withLocation: ConfigPlugin<
36
37
  locationWhenInUsePermission,
37
38
  isIosBackgroundLocationEnabled,
38
39
  isAndroidBackgroundLocationEnabled,
40
+ isAndroidForegroundServiceEnabled,
39
41
  } = {}
40
42
  ) => {
41
43
  if (isIosBackgroundLocationEnabled) {
@@ -62,11 +64,14 @@ const withLocation: ConfigPlugin<
62
64
  return AndroidConfig.Permissions.withPermissions(
63
65
  config,
64
66
  [
67
+ // Note: these are already added in the library AndroidManifest.xml and so
68
+ // are not required here, we may want to remove them in the future.
65
69
  'android.permission.ACCESS_COARSE_LOCATION',
66
70
  'android.permission.ACCESS_FINE_LOCATION',
67
- 'android.permission.FOREGROUND_SERVICE',
68
- // Optional
71
+ // These permissions are optional, and not listed in the library AndroidManifest.xml
69
72
  isAndroidBackgroundLocationEnabled && 'android.permission.ACCESS_BACKGROUND_LOCATION',
73
+ isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE',
74
+ isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE_LOCATION',
70
75
  ].filter(Boolean) as string[]
71
76
  );
72
77
  };