@capgo/background-geolocation 8.0.5 → 8.0.7
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.
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
<!-- Android SDK 33+ requires the POST_NOTIFICATIONS runtime permission to
|
|
17
17
|
display the foreground service notification. -->
|
|
18
18
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
19
|
+
<!-- See https://github.com/Cap-go/capacitor-background-geolocation/issues/12 for more details-->
|
|
20
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
19
21
|
<uses-feature android:name="android.hardware.location.gps" />
|
|
20
22
|
</manifest>
|
|
21
23
|
|
|
@@ -5,6 +5,7 @@ import android.app.PendingIntent;
|
|
|
5
5
|
import android.app.Service;
|
|
6
6
|
import android.content.Context;
|
|
7
7
|
import android.content.Intent;
|
|
8
|
+
import android.content.pm.ServiceInfo;
|
|
8
9
|
import android.content.res.AssetFileDescriptor;
|
|
9
10
|
import android.content.res.AssetManager;
|
|
10
11
|
import android.graphics.Color;
|
|
@@ -14,6 +15,7 @@ import android.media.MediaPlayer;
|
|
|
14
15
|
import android.os.Binder;
|
|
15
16
|
import android.os.Build;
|
|
16
17
|
import android.os.IBinder;
|
|
18
|
+
import android.os.PowerManager;
|
|
17
19
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
18
20
|
import com.getcapacitor.Logger;
|
|
19
21
|
|
|
@@ -38,6 +40,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
38
40
|
private double[][] route;
|
|
39
41
|
private double distanceThreshold;
|
|
40
42
|
private boolean isOffRoute;
|
|
43
|
+
private PowerManager.WakeLock wakeLock;
|
|
41
44
|
|
|
42
45
|
@Override
|
|
43
46
|
public IBinder onBind(Intent intent) {
|
|
@@ -54,6 +57,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
54
57
|
client.removeUpdates(locationCallback);
|
|
55
58
|
}
|
|
56
59
|
releaseMediaPlayer();
|
|
60
|
+
releaseWakeLock();
|
|
57
61
|
stopSelf();
|
|
58
62
|
return false;
|
|
59
63
|
}
|
|
@@ -65,6 +69,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
65
69
|
}
|
|
66
70
|
super.onDestroy();
|
|
67
71
|
releaseMediaPlayer();
|
|
72
|
+
releaseWakeLock();
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
private void releaseMediaPlayer() {
|
|
@@ -82,11 +87,41 @@ public class BackgroundGeolocationService extends Service {
|
|
|
82
87
|
mediaPlayer = null;
|
|
83
88
|
}
|
|
84
89
|
|
|
90
|
+
private void acquireWakeLock() {
|
|
91
|
+
if (wakeLock != null && wakeLock.isHeld()) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
96
|
+
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BackgroundGeolocation::LocationWakeLock");
|
|
97
|
+
wakeLock.acquire();
|
|
98
|
+
Logger.info("Wake lock acquired");
|
|
99
|
+
} catch (Exception e) {
|
|
100
|
+
Logger.error("Error acquiring wake lock", e);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private void releaseWakeLock() {
|
|
105
|
+
if (wakeLock == null) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
if (wakeLock.isHeld()) {
|
|
110
|
+
wakeLock.release();
|
|
111
|
+
Logger.info("Wake lock released");
|
|
112
|
+
}
|
|
113
|
+
} catch (Exception e) {
|
|
114
|
+
Logger.error("Error releasing wake lock", e);
|
|
115
|
+
}
|
|
116
|
+
wakeLock = null;
|
|
117
|
+
}
|
|
118
|
+
|
|
85
119
|
// Handles requests from the activity.
|
|
86
120
|
public class LocalBinder extends Binder {
|
|
87
121
|
|
|
88
122
|
void start(final String id, final String notificationTitle, final String notificationMessage, float distanceFilter) {
|
|
89
123
|
releaseMediaPlayer();
|
|
124
|
+
acquireWakeLock();
|
|
90
125
|
client = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
|
91
126
|
callbackId = id;
|
|
92
127
|
|
|
@@ -122,8 +157,16 @@ public class BackgroundGeolocationService extends Service {
|
|
|
122
157
|
try {
|
|
123
158
|
// This method has been known to fail due to weird
|
|
124
159
|
// permission bugs, so we prevent any exceptions from
|
|
125
|
-
// crashing the app.
|
|
126
|
-
|
|
160
|
+
// crashing the app.
|
|
161
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
162
|
+
startForeground(
|
|
163
|
+
NOTIFICATION_ID,
|
|
164
|
+
createBackgroundNotification(notificationTitle, notificationMessage),
|
|
165
|
+
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
startForeground(NOTIFICATION_ID, createBackgroundNotification(notificationTitle, notificationMessage));
|
|
169
|
+
}
|
|
127
170
|
} catch (Exception exception) {
|
|
128
171
|
Logger.error("Failed to foreground service", exception);
|
|
129
172
|
}
|
|
@@ -134,6 +177,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
134
177
|
stopForeground(true);
|
|
135
178
|
stopSelf();
|
|
136
179
|
releaseMediaPlayer();
|
|
180
|
+
releaseWakeLock();
|
|
137
181
|
return callbackId;
|
|
138
182
|
}
|
|
139
183
|
|
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.7"
|
|
42
42
|
public let identifier = "BackgroundGeolocationPlugin"
|
|
43
43
|
public let jsName = "BackgroundGeolocation"
|
|
44
44
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED