@capgo/background-geolocation 8.0.7 → 8.0.8
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.
|
@@ -14,7 +14,9 @@ import android.location.LocationManager;
|
|
|
14
14
|
import android.media.MediaPlayer;
|
|
15
15
|
import android.os.Binder;
|
|
16
16
|
import android.os.Build;
|
|
17
|
+
import android.os.Handler;
|
|
17
18
|
import android.os.IBinder;
|
|
19
|
+
import android.os.Looper;
|
|
18
20
|
import android.os.PowerManager;
|
|
19
21
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
20
22
|
import com.getcapacitor.Logger;
|
|
@@ -40,6 +42,11 @@ public class BackgroundGeolocationService extends Service {
|
|
|
40
42
|
private double[][] route;
|
|
41
43
|
private double distanceThreshold;
|
|
42
44
|
private boolean isOffRoute;
|
|
45
|
+
|
|
46
|
+
private Handler watchdogHandler = new Handler(Looper.getMainLooper());
|
|
47
|
+
private Runnable watchdogRunnable;
|
|
48
|
+
private Runnable restartRunnable;
|
|
49
|
+
private float currentDistanceFilter;
|
|
43
50
|
private PowerManager.WakeLock wakeLock;
|
|
44
51
|
|
|
45
52
|
@Override
|
|
@@ -58,6 +65,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
58
65
|
}
|
|
59
66
|
releaseMediaPlayer();
|
|
60
67
|
releaseWakeLock();
|
|
68
|
+
stopWatchdog();
|
|
61
69
|
stopSelf();
|
|
62
70
|
return false;
|
|
63
71
|
}
|
|
@@ -70,6 +78,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
70
78
|
super.onDestroy();
|
|
71
79
|
releaseMediaPlayer();
|
|
72
80
|
releaseWakeLock();
|
|
81
|
+
stopWatchdog();
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
private void releaseMediaPlayer() {
|
|
@@ -116,6 +125,46 @@ public class BackgroundGeolocationService extends Service {
|
|
|
116
125
|
wakeLock = null;
|
|
117
126
|
}
|
|
118
127
|
|
|
128
|
+
private void restartLocationUpdates() {
|
|
129
|
+
Logger.debug("Location watchdog timed out, restarting updates");
|
|
130
|
+
if (client == null || locationCallback == null) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
client.removeUpdates(locationCallback);
|
|
134
|
+
if (restartRunnable != null) {
|
|
135
|
+
watchdogHandler.removeCallbacks(restartRunnable);
|
|
136
|
+
}
|
|
137
|
+
restartRunnable = () -> {
|
|
138
|
+
if (client == null || locationCallback == null) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
client.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, currentDistanceFilter, locationCallback);
|
|
143
|
+
} catch (SecurityException ignore) {
|
|
144
|
+
// Permission issues are handled in the start() method
|
|
145
|
+
}
|
|
146
|
+
startWatchdog();
|
|
147
|
+
};
|
|
148
|
+
watchdogHandler.postDelayed(restartRunnable, 10000);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private void startWatchdog() {
|
|
152
|
+
stopWatchdog();
|
|
153
|
+
if (watchdogRunnable == null) {
|
|
154
|
+
watchdogRunnable = this::restartLocationUpdates;
|
|
155
|
+
}
|
|
156
|
+
watchdogHandler.postDelayed(watchdogRunnable, 60000);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private void stopWatchdog() {
|
|
160
|
+
if (watchdogRunnable != null) {
|
|
161
|
+
watchdogHandler.removeCallbacks(watchdogRunnable);
|
|
162
|
+
}
|
|
163
|
+
if (restartRunnable != null) {
|
|
164
|
+
watchdogHandler.removeCallbacks(restartRunnable);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
119
168
|
// Handles requests from the activity.
|
|
120
169
|
public class LocalBinder extends Binder {
|
|
121
170
|
|
|
@@ -124,8 +173,10 @@ public class BackgroundGeolocationService extends Service {
|
|
|
124
173
|
acquireWakeLock();
|
|
125
174
|
client = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
|
126
175
|
callbackId = id;
|
|
176
|
+
currentDistanceFilter = distanceFilter;
|
|
127
177
|
|
|
128
178
|
locationCallback = (location) -> {
|
|
179
|
+
startWatchdog();
|
|
129
180
|
if (mediaPlayer != null) {
|
|
130
181
|
double[] point = { location.getLongitude(), location.getLatitude() };
|
|
131
182
|
var offRoute = distancePointToRoute(point) > distanceThreshold;
|
|
@@ -173,6 +224,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
173
224
|
}
|
|
174
225
|
|
|
175
226
|
String stop() {
|
|
227
|
+
stopWatchdog();
|
|
176
228
|
client.removeUpdates(locationCallback);
|
|
177
229
|
stopForeground(true);
|
|
178
230
|
stopSelf();
|
package/ios/Sources/CapgoBackgroundGeolocationPlugin/CapgoCapacitorBackgroundGeolocationPlugin.swift
CHANGED
|
@@ -38,7 +38,7 @@ func formatLocation(_ location: CLLocation) -> PluginCallResultData {
|
|
|
38
38
|
@objc(BackgroundGeolocation)
|
|
39
39
|
// swiftlint:disable:next type_body_length
|
|
40
40
|
public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBridgedPlugin {
|
|
41
|
-
private let pluginVersion: String = "8.0.
|
|
41
|
+
private let pluginVersion: String = "8.0.8"
|
|
42
42
|
public let identifier = "BackgroundGeolocationPlugin"
|
|
43
43
|
public let jsName = "BackgroundGeolocation"
|
|
44
44
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED