@capgo/background-geolocation 8.0.6 → 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
 
@@ -15,6 +15,7 @@ import android.media.MediaPlayer;
15
15
  import android.os.Binder;
16
16
  import android.os.Build;
17
17
  import android.os.IBinder;
18
+ import android.os.PowerManager;
18
19
  import androidx.localbroadcastmanager.content.LocalBroadcastManager;
19
20
  import com.getcapacitor.Logger;
20
21
 
@@ -39,6 +40,7 @@ public class BackgroundGeolocationService extends Service {
39
40
  private double[][] route;
40
41
  private double distanceThreshold;
41
42
  private boolean isOffRoute;
43
+ private PowerManager.WakeLock wakeLock;
42
44
 
43
45
  @Override
44
46
  public IBinder onBind(Intent intent) {
@@ -55,6 +57,7 @@ public class BackgroundGeolocationService extends Service {
55
57
  client.removeUpdates(locationCallback);
56
58
  }
57
59
  releaseMediaPlayer();
60
+ releaseWakeLock();
58
61
  stopSelf();
59
62
  return false;
60
63
  }
@@ -66,6 +69,7 @@ public class BackgroundGeolocationService extends Service {
66
69
  }
67
70
  super.onDestroy();
68
71
  releaseMediaPlayer();
72
+ releaseWakeLock();
69
73
  }
70
74
 
71
75
  private void releaseMediaPlayer() {
@@ -83,11 +87,41 @@ public class BackgroundGeolocationService extends Service {
83
87
  mediaPlayer = null;
84
88
  }
85
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
+
86
119
  // Handles requests from the activity.
87
120
  public class LocalBinder extends Binder {
88
121
 
89
122
  void start(final String id, final String notificationTitle, final String notificationMessage, float distanceFilter) {
90
123
  releaseMediaPlayer();
124
+ acquireWakeLock();
91
125
  client = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
92
126
  callbackId = id;
93
127
 
@@ -143,6 +177,7 @@ public class BackgroundGeolocationService extends Service {
143
177
  stopForeground(true);
144
178
  stopSelf();
145
179
  releaseMediaPlayer();
180
+ releaseWakeLock();
146
181
  return callbackId;
147
182
  }
148
183
 
@@ -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.6"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/background-geolocation",
3
- "version": "8.0.6",
3
+ "version": "8.0.7",
4
4
  "description": "Receive accurate geolocation updates even while the app is in the background.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",