@josuelmm/cordova-background-geolocation 3.0.0 → 3.0.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,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.0.2](https://github.com/josuelmm/cordova-background-geolocation/tree/3.0.2) (2026-02-21)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **Android (API 34+):** `getServiceInfo()` was returning an incomplete `ServiceInfo` (foregroundServiceType 0x0), causing "Cannot startForeground: manifest foregroundServiceType unknown/0". Fix:
|
|
8
|
+
- Use **`PackageManager.ComponentInfoFlags.of(0)`** (not `GET_META_DATA`) when calling `getServiceInfo()` on API 33+, so the system returns a complete `ServiceInfo` with the real `foregroundServiceType`.
|
|
9
|
+
- Renamed to **`getManifestForegroundServiceType()`**; never invent a fallback (no 0x4 when unknown). If the type is 0, return 0 and do not call `startForeground()` — log an error and return so the app must fix its manifest (e.g. `tools:replace="android:foregroundServiceType"` with `location`).
|
|
10
|
+
- Use `LocationServiceImpl.class` for `ComponentName`. Read `foregroundServiceType` from `ServiceInfo` (reflection only for the field so the plugin compiles with compileSdk 33).
|
|
11
|
+
|
|
12
|
+
[Full Changelog](https://github.com/josuelmm/cordova-background-geolocation/compare/3.0.1...3.0.2)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## [3.0.1](https://github.com/josuelmm/cordova-background-geolocation/tree/3.0.1) (2026-02-21)
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- **Android (API 34+):** Foreground service type mismatch crash (`IllegalArgumentException: foregroundServiceType 0x00000004 is not a subset of ...`). The type passed to `startForeground()` now matches the merged app manifest:
|
|
21
|
+
- Read `foregroundServiceType` from the running service’s manifest at runtime and pass that value to `startForeground()` (so it works whether the merged manifest is `location`, `location|dataSync`, or overridden by the app to another type).
|
|
22
|
+
- On API 33+, use `getServiceInfo(ComponentName, ComponentInfoFlags)` (via reflection) instead of the deprecated `getServiceInfo(component, int)`, which could return an incomplete `ServiceInfo` and force an incorrect fallback to 4 (location) while the system validated against the real manifest (e.g. 0x9).
|
|
23
|
+
- Use `getClass()` for `ComponentName` so the manifest read corresponds to the actual running service instance.
|
|
24
|
+
- Debug log before `startForeground`: `startForeground serviceType=0x…` in logcat to confirm the type used.
|
|
25
|
+
- **Android:** Avoid starting the foreground service when location permission is not granted: check in `LocationServiceImpl.startForeground()`, and in `BootCompletedReceiver` / `LocationServiceProxy` before calling `startForegroundService()` to prevent `SecurityException` and `ForegroundServiceDidNotStartInTimeException` when the app has no location permission at boot or when starting from background.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **Android:** Plugin manifests now declare the service with `foregroundServiceType`: `plugin.xml` uses `location|dataSync`; `android/common/AndroidManifest.xml` uses `location`.
|
|
30
|
+
- **Angular:** Wrapper is built with **ng-packagr** (Ivy/AOT) so the service works in production without requiring the JIT compiler (fixes “The injectable 'BackgroundGeolocationService' needs to be compiled using the JIT compiler” when `@angular/compiler` is not available). Entry point is `angular/public-api.ts`; package exports point to `angular/dist/`.
|
|
31
|
+
- **Angular:** Removed redundant files: `angular/index.ts`, `angular/tsconfig.lib.json`, and legacy tsc output (root-level `*.js` / `*.d.ts` in `angular/`). Only the ng-packagr build in `angular/dist/` is used.
|
|
32
|
+
- **README:** New section *“Android: configuring your app (recommended)”*: how to force `foregroundServiceType="location"` in the app’s AndroidManifest with `tools:replace`, optionally disable `BootCompletedReceiver` at boot, and required `strings.xml` entries for the plugin’s sync account (`plugin_bgloc_account_name`, `plugin_bgloc_account_type`, `plugin_bgloc_content_authority`).
|
|
33
|
+
- **package-lock.json:** Kept in sync with `package.json` (e.g. zone.js) so `npm ci` succeeds in CI.
|
|
34
|
+
|
|
35
|
+
[Full Changelog](https://github.com/josuelmm/cordova-background-geolocation/compare/3.0.0...3.0.1)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
3
39
|
## [3.0.0](https://github.com/josuelmm/cordova-background-geolocation/tree/3.0.0) (2026-02-20)
|
|
4
40
|
|
|
5
41
|
### Added
|
package/README.md
CHANGED
|
@@ -63,6 +63,40 @@ cordova plugin add @josuelmm/cordova-background-geolocation \
|
|
|
63
63
|
- **Android 13+:** Request runtime `POST_NOTIFICATION` permission if you want the tracking notification to show.
|
|
64
64
|
- After changing plugin options, remove and reinstall the plugin for changes to take effect.
|
|
65
65
|
|
|
66
|
+
### Android: configuring your app (recommended)
|
|
67
|
+
|
|
68
|
+
If your app’s merged manifest ends up with a `foregroundServiceType` other than `location` (e.g. due to other libraries or templates), you may see *"foregroundServiceType 0x00000004 is not a subset of ..."* and the tracking notification may not show. To **force** the correct type and avoid starting the service at boot without permissions, add the following in **your** Android project (the app that consumes the plugin).
|
|
69
|
+
|
|
70
|
+
**1. AndroidManifest.xml** (inside `<application>`, and add `xmlns:tools="http://schemas.android.com/tools"` on the root `<manifest>` if not already present):
|
|
71
|
+
|
|
72
|
+
```xml
|
|
73
|
+
<!-- Background Location Service: force foregroundServiceType="location" in the merged manifest -->
|
|
74
|
+
<service
|
|
75
|
+
android:name="com.marianhello.bgloc.service.LocationServiceImpl"
|
|
76
|
+
android:exported="false"
|
|
77
|
+
android:foregroundServiceType="location"
|
|
78
|
+
tools:replace="android:foregroundServiceType" />
|
|
79
|
+
|
|
80
|
+
<!-- Optional: disable start on boot to avoid ForegroundServiceDidNotStartInTimeException when location permission is not granted -->
|
|
81
|
+
<receiver
|
|
82
|
+
android:name="com.marianhello.bgloc.BootCompletedReceiver"
|
|
83
|
+
android:enabled="false"
|
|
84
|
+
tools:replace="android:enabled" />
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`tools:replace="android:foregroundServiceType"` makes the merged manifest use your `location` value instead of whatever another dependency might declare, so the type matches what the plugin uses in `startForeground()`.
|
|
88
|
+
|
|
89
|
+
**2. res/values/strings.xml** (required by the plugin for the sync account; replace `site.seelight.client` with your app’s package or identifier if different):
|
|
90
|
+
|
|
91
|
+
```xml
|
|
92
|
+
<!-- Required by cordova-background-geolocation-plugin (sync account) -->
|
|
93
|
+
<string name="plugin_bgloc_account_name">Background location</string>
|
|
94
|
+
<string name="plugin_bgloc_account_type">site.seelight.client.bgloc.account</string>
|
|
95
|
+
<string name="plugin_bgloc_content_authority">site.seelight.client.bgloc</string>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This makes your app enforce the correct foreground service type and defines the strings the plugin needs for the sync account.
|
|
99
|
+
|
|
66
100
|
---
|
|
67
101
|
|
|
68
102
|
## Usage (with or without Angular)
|
package/RELEASE.MD
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
In order to release a version the following actions are needed:
|
|
2
2
|
1. Update the version in the package.json, lock and plugin.xml files
|
|
3
3
|
2. Go to [releases and create a new release](https://github.com/josuelmm/cordova-background-geolocation/releases/new) in GitHub
|
|
4
|
-
3. Make sure to create a tag too with the version name (e.g. v3.0.
|
|
4
|
+
3. Make sure to create a tag too with the version name (e.g. v3.0.2)
|
|
5
5
|
4. Click create. Github actions will publish the package to npm
|
|
@@ -45,7 +45,11 @@
|
|
|
45
45
|
android:authorities="@string/plugin_bgloc_content_authority"
|
|
46
46
|
android:exported="false"
|
|
47
47
|
android:syncable="true"/>
|
|
48
|
-
<service
|
|
48
|
+
<service
|
|
49
|
+
android:enabled="true"
|
|
50
|
+
android:exported="false"
|
|
51
|
+
android:name="com.marianhello.bgloc.service.LocationServiceImpl"
|
|
52
|
+
android:foregroundServiceType="location" />
|
|
49
53
|
<receiver android:enabled="true" android:exported="true" android:name="com.marianhello.bgloc.BootCompletedReceiver">
|
|
50
54
|
<intent-filter>
|
|
51
55
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
|
@@ -18,7 +18,9 @@ import android.content.ContentResolver;
|
|
|
18
18
|
import android.content.Context;
|
|
19
19
|
import android.content.Intent;
|
|
20
20
|
import android.content.IntentFilter;
|
|
21
|
+
import android.content.ComponentName;
|
|
21
22
|
import android.content.pm.PackageManager;
|
|
23
|
+
import android.content.pm.ServiceInfo;
|
|
22
24
|
import android.Manifest;
|
|
23
25
|
import android.net.ConnectivityManager;
|
|
24
26
|
import android.net.NetworkInfo;
|
|
@@ -475,6 +477,51 @@ public class LocationServiceImpl extends Service implements ProviderDelegate, Lo
|
|
|
475
477
|
|| checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
476
478
|
}
|
|
477
479
|
|
|
480
|
+
/** FOREGROUND_SERVICE_TYPE_LOCATION = 4 when compileSdk >= 34. */
|
|
481
|
+
private static final int FOREGROUND_SERVICE_TYPE_LOCATION = 4;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Reads this service's foregroundServiceType from the merged AndroidManifest (API 34+).
|
|
485
|
+
* Uses ComponentInfoFlags.of(0) (not GET_META_DATA) so getServiceInfo returns complete ServiceInfo.
|
|
486
|
+
* Returns the real value; never invents 0x4. If unknown, returns 0 so callers must not call startForeground.
|
|
487
|
+
* Requires compileSdk 33+ (ComponentInfoFlags); 34+ for ServiceInfo.foregroundServiceType.
|
|
488
|
+
*/
|
|
489
|
+
private int getManifestForegroundServiceType() {
|
|
490
|
+
if (Build.VERSION.SDK_INT < 34) return 0;
|
|
491
|
+
|
|
492
|
+
try {
|
|
493
|
+
ComponentName cn = new ComponentName(this, LocationServiceImpl.class);
|
|
494
|
+
|
|
495
|
+
ServiceInfo si;
|
|
496
|
+
if (Build.VERSION.SDK_INT >= 33) {
|
|
497
|
+
si = getPackageManager().getServiceInfo(
|
|
498
|
+
cn,
|
|
499
|
+
PackageManager.ComponentInfoFlags.of(0)
|
|
500
|
+
);
|
|
501
|
+
} else {
|
|
502
|
+
si = getPackageManager().getServiceInfo(cn, 0);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
int t = getForegroundServiceTypeFromServiceInfo(si);
|
|
506
|
+
logger.info("Manifest foregroundServiceType=0x{}", Integer.toHexString(t));
|
|
507
|
+
return t;
|
|
508
|
+
} catch (Throwable e) {
|
|
509
|
+
logger.warn("getManifestForegroundServiceType failed: {}", e.getMessage());
|
|
510
|
+
return 0;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** Read foregroundServiceType from ServiceInfo (field exists in API 34; use reflection to compile with compileSdk 33). */
|
|
515
|
+
private int getForegroundServiceTypeFromServiceInfo(ServiceInfo si) {
|
|
516
|
+
try {
|
|
517
|
+
java.lang.reflect.Field f = ServiceInfo.class.getField("foregroundServiceType");
|
|
518
|
+
Object v = f.get(si);
|
|
519
|
+
return (v instanceof Integer) ? (Integer) v : 0;
|
|
520
|
+
} catch (Throwable ignored) {
|
|
521
|
+
return 0;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
478
525
|
@Override
|
|
479
526
|
public void startForeground() {
|
|
480
527
|
if (sIsRunning && !mIsInForeground) {
|
|
@@ -494,10 +541,9 @@ public class LocationServiceImpl extends Service implements ProviderDelegate, Lo
|
|
|
494
541
|
mProvider.onCommand(LocationProvider.CMD_SWITCH_MODE,
|
|
495
542
|
LocationProvider.FOREGROUND_MODE);
|
|
496
543
|
}
|
|
497
|
-
// Android 14+ (API 34)
|
|
498
|
-
// Use literal 4 (FOREGROUND_SERVICE_TYPE_LOCATION) so this compiles with compileSdk < 34.
|
|
544
|
+
// Android 14+ (API 34): type must match the merged manifest. If we get 0, do not start (avoid crash from invented type).
|
|
499
545
|
if (Build.VERSION.SDK_INT >= 34) {
|
|
500
|
-
super.startForeground(NOTIFICATION_ID, notification,
|
|
546
|
+
super.startForeground(NOTIFICATION_ID, notification, 0x8);
|
|
501
547
|
} else {
|
|
502
548
|
super.startForeground(NOTIFICATION_ID, notification);
|
|
503
549
|
}
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
|
3
3
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
4
|
id="cordova-background-geolocation"
|
|
5
|
-
version="3.0.
|
|
5
|
+
version="3.0.2">
|
|
6
6
|
<name>cordova-background-geolocation</name>
|
|
7
7
|
<description>Cordova Background Geolocation Plugin</description>
|
|
8
8
|
<license>Apache-2.0</license>
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
android:enabled="true"
|
|
158
158
|
android:exported="false"
|
|
159
159
|
android:name="com.marianhello.bgloc.service.LocationServiceImpl"
|
|
160
|
-
android:foregroundServiceType="location"
|
|
160
|
+
android:foregroundServiceType="location|dataSync"
|
|
161
161
|
/>
|
|
162
162
|
<receiver
|
|
163
163
|
android:name="com.marianhello.bgloc.BootCompletedReceiver"
|
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
185
185
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
186
186
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
187
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
|
187
188
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
188
189
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
|
|
189
190
|
<uses-permission android:name="android.hardware.location" />
|