react-native-background-geolocation 4.4.1 → 4.4.2

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
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.4.2 — 2021-10-29
4
+ * [Fixed][Android] Android 12 behaviour changes mean that foreground-services remain running. When an Android app is terminated, the app process does not terminate (since the foreground-service is active) and `RNBackgroundGeolocationModule` remains in memory. Given that, the plugin cannot rely on registering its event-listeners in the `RNBackgroundGeolocationModule` constructor, but must perform that task when `.ready()` is called. This also requires resetting `mReady = false` when the `MainActivity` is destroyed, so that the next time `.ready()` is called, the event-listeners are re-registered.
5
+ * [Fixed][Android] When `.ready()` is called __`reset: false`__, the `success` callback was not invoked with the current `State`. This bug was introduced in previous `v4.4.1`.
6
+
3
7
  ## 4.4.1 — 2021-10-29
4
8
  * [Added] Added a `Subscription` interface to Typescript API. Added helpful docs to Subscription for new event-handler subscriptions.
5
9
 
@@ -90,13 +90,14 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
90
90
 
91
91
  public RNBackgroundGeolocationModule(ReactApplicationContext reactContext) {
92
92
  super(reactContext);
93
+ reactContext.addLifecycleEventListener(this);
93
94
 
94
95
  TSConfig config = TSConfig.getInstance(getReactApplicationContext());
95
96
  config.useCLLocationAccuracy(true);
96
97
 
97
98
  config.updateWithBuilder()
98
- .setHeadlessJobService(getClass().getPackage().getName() + "." + JOB_SERVICE_CLASS)
99
- .commit();
99
+ .setHeadlessJobService(getClass().getPackage().getName() + "." + JOB_SERVICE_CLASS)
100
+ .commit();
100
101
 
101
102
  // These are the only events which can be subscribed to.
102
103
  mEvents.add(BackgroundGeolocation.EVENT_LOCATION);
@@ -113,9 +114,18 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
113
114
  mEvents.add(BackgroundGeolocation.EVENT_ENABLEDCHANGE);
114
115
  mEvents.add(BackgroundGeolocation.EVENT_NOTIFICATIONACTION);
115
116
  mEvents.add(TSAuthorization.NAME);
117
+ }
116
118
 
117
- reactContext.addLifecycleEventListener(this);
119
+ @Override
120
+ public void initialize() {
121
+ // do nothing
122
+ }
123
+ @Override
124
+ public String getName() {
125
+ return "RNBackgroundGeolocation";
126
+ }
118
127
 
128
+ private void registerEvents() {
119
129
  BackgroundGeolocation adapter = getAdapter();
120
130
  adapter.onLocation(new LocationCallback());
121
131
  adapter.onMotionChange(new MotionChangeCallback());
@@ -133,16 +143,6 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
133
143
  HttpService.getInstance(getReactApplicationContext()).onAuthorization(new AuthorizationCallback());
134
144
  }
135
145
 
136
- @Override
137
- public void initialize() {
138
- // do nothing
139
- }
140
- @Override
141
- public String getName() {
142
- return "RNBackgroundGeolocation";
143
- }
144
-
145
-
146
146
  /**
147
147
  * location event callback
148
148
  */
@@ -340,6 +340,7 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
340
340
  @Override
341
341
  public void onHostDestroy() {
342
342
  mInitialized = false;
343
+ mReady = false;
343
344
  removeAllListeners();
344
345
  getAdapter().onActivityDestroy();
345
346
  }
@@ -374,10 +375,13 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
374
375
  setConfig(params, success, failure);
375
376
  } else {
376
377
  TSLog.logger.warn(TSLog.warn("#ready already called. Ignored config since reset: false"));
378
+ success.invoke(getState());
377
379
  }
378
380
  return;
379
381
  }
380
382
  mReady = true;
383
+ registerEvents();
384
+
381
385
  if (config.isFirstBoot()) {
382
386
  config.updateWithJSONObject(mapToJson(setHeadlessJobService(params)));
383
387
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-background-geolocation",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
4
4
  "description": "The most sophisticated cross-platform background location-tracking & geofencing module with battery-conscious motion-detection intelligence",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"