expo-location 16.5.4 → 16.5.5

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,17 +10,23 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 16.5.5 — 2024-02-29
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
13
17
  ## 16.5.4 — 2024-02-27
14
18
 
15
19
  ### 🎉 New features
16
20
 
17
21
  - [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))
22
+ - [Android] Enable foreground service by default when background location is enabled [#27359](https://github.com/expo/expo/pull/27359) by [@brentvatne](https://github.com/brentvatne))
18
23
 
19
24
  ## 16.5.3 — 2024-02-06
20
25
 
21
26
  ### 🐛 Bug fixes
22
27
 
23
28
  - [Android] Fixed: `NullPointerException: it must not be null`. ([#26688](https://github.com/expo/expo/pull/26688) by [@lukmccall](https://github.com/lukmccall))
29
+ - On `Android`, prevent location service from starting when permission is not in the manifest. ([#27355](https://github.com/expo/expo/pull/27355) by [@alanjhughes](https://github.com/alanjhughes))
24
30
 
25
31
  ## 16.5.2 — 2024-01-10
26
32
 
@@ -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.4'
6
+ version = '16.5.5'
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.4"
97
+ versionName "16.5.5"
98
98
  }
99
99
  }
100
100
 
@@ -57,4 +57,7 @@ internal class ConversionException(fromClass: Class<*>, toClass: Class<*>, messa
57
57
  CodedException("Couldn't cast from ${fromClass::class.simpleName} to ${toClass::class.java.simpleName}: $message")
58
58
 
59
59
  internal class ForegroundServiceStartNotAllowedException :
60
- CodedException("Couldn't start the foreground service. Foreground service cannot be started when the application is in the background.")
60
+ CodedException("Couldn't start the foreground service. Foreground service cannot be started when the application is in the background")
61
+
62
+ internal class ForegroundServicePermissionsException :
63
+ CodedException("Couldn't start the foreground service. Foreground service permissions were not found in the manifest")
@@ -273,6 +273,10 @@ class LocationModule : Module(), LifecycleEventListener, SensorEventListener, Ac
273
273
  throw ForegroundServiceStartNotAllowedException()
274
274
  }
275
275
 
276
+ if (!hasForegroundServicePermissions()) {
277
+ throw ForegroundServicePermissionsException()
278
+ }
279
+
276
280
  mTaskManager.registerTask(taskName, LocationTaskConsumer::class.java, options.toMutableMap())
277
281
  return@AsyncFunction
278
282
  }
@@ -722,8 +726,22 @@ class LocationModule : Module(), LifecycleEventListener, SensorEventListener, Ac
722
726
  val canAccessFineLocation = it.hasGrantedPermissions(Manifest.permission.ACCESS_FINE_LOCATION)
723
727
  val canAccessCoarseLocation = it.hasGrantedPermissions(Manifest.permission.ACCESS_COARSE_LOCATION)
724
728
  return !canAccessFineLocation && !canAccessCoarseLocation
725
- }
726
- return true
729
+ } ?: throw Exceptions.AppContextLost()
730
+ }
731
+
732
+ private fun hasForegroundServicePermissions(): Boolean {
733
+ appContext.permissions?.let {
734
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
735
+ val canAccessForegroundServiceLocation = it.hasGrantedPermissions(Manifest.permission.FOREGROUND_SERVICE_LOCATION)
736
+ val canAccessForegroundService = it.hasGrantedPermissions(Manifest.permission.FOREGROUND_SERVICE)
737
+ canAccessForegroundService && canAccessForegroundServiceLocation
738
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
739
+ val canAccessForegroundService = it.hasGrantedPermissions(Manifest.permission.FOREGROUND_SERVICE)
740
+ canAccessForegroundService
741
+ } else {
742
+ true
743
+ }
744
+ } ?: throw Exceptions.AppContextLost()
727
745
  }
728
746
 
729
747
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-location",
3
- "version": "16.5.4",
3
+ "version": "16.5.5",
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": "e94e2aac39cbb7f8788869cd6798bbdeadc58f42"
47
+ "gitHead": "01bef8630cd9fd913bb465afd010d6030a9ca38f"
48
48
  }
@@ -33,6 +33,12 @@ const withLocation = (config, { locationAlwaysAndWhenInUsePermission, locationAl
33
33
  LOCATION_USAGE;
34
34
  return config;
35
35
  });
36
+ // If the user has not specified a value for isAndroidForegroundServiceEnabled,
37
+ // we default to the value of isAndroidBackgroundLocationEnabled because we want
38
+ // to enable foreground by default if background location is enabled.
39
+ const enableAndroidForegroundService = typeof isAndroidForegroundServiceEnabled === 'undefined'
40
+ ? isAndroidBackgroundLocationEnabled
41
+ : isAndroidForegroundServiceEnabled;
36
42
  return config_plugins_1.AndroidConfig.Permissions.withPermissions(config, [
37
43
  // Note: these are already added in the library AndroidManifest.xml and so
38
44
  // are not required here, we may want to remove them in the future.
@@ -40,8 +46,8 @@ const withLocation = (config, { locationAlwaysAndWhenInUsePermission, locationAl
40
46
  'android.permission.ACCESS_FINE_LOCATION',
41
47
  // These permissions are optional, and not listed in the library AndroidManifest.xml
42
48
  isAndroidBackgroundLocationEnabled && 'android.permission.ACCESS_BACKGROUND_LOCATION',
43
- isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE',
44
- isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE_LOCATION',
49
+ enableAndroidForegroundService && 'android.permission.FOREGROUND_SERVICE',
50
+ enableAndroidForegroundService && 'android.permission.FOREGROUND_SERVICE_LOCATION',
45
51
  ].filter(Boolean));
46
52
  };
47
53
  exports.default = (0, config_plugins_1.createRunOncePlugin)(withLocation, pkg.name, pkg.version);
@@ -61,6 +61,14 @@ const withLocation: ConfigPlugin<
61
61
  return config;
62
62
  });
63
63
 
64
+ // If the user has not specified a value for isAndroidForegroundServiceEnabled,
65
+ // we default to the value of isAndroidBackgroundLocationEnabled because we want
66
+ // to enable foreground by default if background location is enabled.
67
+ const enableAndroidForegroundService =
68
+ typeof isAndroidForegroundServiceEnabled === 'undefined'
69
+ ? isAndroidBackgroundLocationEnabled
70
+ : isAndroidForegroundServiceEnabled;
71
+
64
72
  return AndroidConfig.Permissions.withPermissions(
65
73
  config,
66
74
  [
@@ -70,8 +78,8 @@ const withLocation: ConfigPlugin<
70
78
  'android.permission.ACCESS_FINE_LOCATION',
71
79
  // These permissions are optional, and not listed in the library AndroidManifest.xml
72
80
  isAndroidBackgroundLocationEnabled && 'android.permission.ACCESS_BACKGROUND_LOCATION',
73
- isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE',
74
- isAndroidForegroundServiceEnabled && 'android.permission.FOREGROUND_SERVICE_LOCATION',
81
+ enableAndroidForegroundService && 'android.permission.FOREGROUND_SERVICE',
82
+ enableAndroidForegroundService && 'android.permission.FOREGROUND_SERVICE_LOCATION',
75
83
  ].filter(Boolean) as string[]
76
84
  );
77
85
  };