@josuelmm/cordova-background-geolocation 4.2.3 → 4.5.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.
Files changed (103) hide show
  1. package/.npmignore +11 -0
  2. package/CHANGELOG.md +261 -0
  3. package/README.md +306 -115
  4. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +34 -0
  5. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +61 -1
  6. package/android/common/src/main/AndroidManifest.xml +1 -1
  7. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +20 -3
  8. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +87 -1
  9. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +94 -0
  10. package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
  11. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +6 -0
  12. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +5 -1
  13. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +32 -1
  14. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +12 -2
  15. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +33 -2
  16. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +15 -1
  17. package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +48 -1
  18. package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +105 -6
  19. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +336 -250
  20. package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +69 -19
  21. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +246 -21
  22. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +5 -2
  23. package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +46 -13
  24. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +23 -1
  25. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +208 -70
  26. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +132 -5
  27. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +20 -0
  28. package/ios/common/BackgroundGeolocation/MAURConfig.h +7 -0
  29. package/ios/common/BackgroundGeolocation/MAURConfig.m +37 -2
  30. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +3 -0
  31. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +3 -1
  32. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +10 -1
  33. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +15 -1
  34. package/ios/common/BackgroundGeolocation/MAURLocation.h +12 -0
  35. package/ios/common/BackgroundGeolocation/MAURLocation.m +33 -4
  36. package/ios/common/BackgroundGeolocation/MAURLocationContract.h +4 -0
  37. package/ios/common/BackgroundGeolocation/MAURLocationContract.m +5 -1
  38. package/ios/common/BackgroundGeolocation/MAURLocationManager.m +19 -1
  39. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +9 -0
  40. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +59 -1
  41. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +10 -1
  42. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +54 -4
  43. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +12 -0
  44. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +125 -5
  45. package/package.json +31 -1
  46. package/plugin.xml +3 -10
  47. package/www/BackgroundGeolocation.d.ts +143 -3
  48. package/www/BackgroundGeolocation.js +11 -4
  49. package/CLAUDE.md +0 -56
  50. package/HISTORY.md +0 -871
  51. package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +0 -220
  52. package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +0 -45
  53. package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +0 -570
  54. package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +0 -76
  55. package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +0 -437
  56. package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +0 -95
  57. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +0 -159
  58. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +0 -161
  59. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +0 -247
  60. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +0 -200
  61. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +0 -457
  62. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +0 -96
  63. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +0 -225
  64. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +0 -46
  65. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +0 -14
  66. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +0 -50
  67. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +0 -17
  68. package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +0 -92
  69. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +0 -107
  70. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +0 -5
  71. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +0 -82
  72. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +0 -128
  73. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +0 -191
  74. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +0 -37
  75. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +0 -216
  76. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +0 -223
  77. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +0 -50
  78. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +0 -180
  79. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +0 -16
  80. package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +0 -2
  81. package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +0 -21
  82. package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +0 -135
  83. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +0 -80
  84. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +0 -147
  85. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +0 -30
  86. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +0 -42
  87. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +0 -99
  88. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +0 -327
  89. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +0 -44
  90. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +0 -94
  91. package/ios/common/BackgroundGeolocationTests/Info.plist +0 -24
  92. package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +0 -185
  93. package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +0 -161
  94. package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +0 -102
  95. package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +0 -216
  96. package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +0 -55
  97. package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +0 -43
  98. package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +0 -102
  99. package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +0 -41
  100. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +0 -240
  101. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +0 -84
  102. package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +0 -144
  103. package/ios/common/scripts/xcode-refactor.js +0 -184
@@ -153,7 +153,7 @@ export interface ConfigureOptions {
153
153
  * Platform: Android
154
154
  * Provider: all
155
155
  *
156
- * @default 60000
156
+ * @default 600000
157
157
  * @see {@link https://bit.ly/1x00RUu|Android docs}
158
158
  */
159
159
  interval?: number;
@@ -510,6 +510,81 @@ export interface ConfigureOptions {
510
510
  */
511
511
  mockLocationPolicy?: 'allow' | 'flag' | 'drop';
512
512
 
513
+ /**
514
+ * v4.4 — Stamp device battery percentage (0-100) and charging state on every location
515
+ * sent to the backend. Default `true`. Set `false` to opt out.
516
+ *
517
+ * - With `bodyTemplate`/`postTemplate`, use placeholders `'@battery'` and `'@isCharging'`.
518
+ * - Default JSON includes `battery` and `isCharging` keys automatically.
519
+ *
520
+ * Android: read via `BatteryManager` sticky broadcast (no permission required).
521
+ * iOS: read via `UIDevice.batteryLevel` (free).
522
+ *
523
+ * Platform: Android, iOS
524
+ * @since 4.4.0
525
+ */
526
+ includeBattery?: boolean;
527
+
528
+ /**
529
+ * v4.5.1 — WakeLock policy (Android only). Controls whether the service holds a
530
+ * `PARTIAL_WAKE_LOCK` while tracking. Default `'posting'`.
531
+ *
532
+ * - `'none'` — never acquire a wake lock. Best battery, but the device may
533
+ * sleep mid-POST. Recommended only with `httpMode: 'batch'`.
534
+ * - `'posting'` — acquire a 30 s wake lock on every fix while writing to SQLite
535
+ * and posting. Default. Good battery / reliability trade-off.
536
+ * - `'always'` — keep CPU awake the whole time the service is running. Most
537
+ * reliable, worst battery. Use only for fleet/emergency apps.
538
+ *
539
+ * @platform Android
540
+ * @since 4.5.1
541
+ */
542
+ wakeLockMode?: 'none' | 'posting' | 'always';
543
+
544
+ /**
545
+ * v4.5.1 — Stationary detection knobs (Android `DISTANCE_FILTER_PROVIDER`).
546
+ * Override the previously hard-coded constants. All values in milliseconds.
547
+ *
548
+ * - `stationaryTimeout` (default 300_000) — time of no movement before declaring stationary.
549
+ * - `stationaryPollInterval` (default 180_000) — lazy poll while stationary.
550
+ * - `stationaryPollFast` (default 60_000) — aggressive poll near boundary.
551
+ *
552
+ * @platform Android
553
+ * @since 4.5.1
554
+ */
555
+ stationaryTimeout?: number;
556
+ stationaryPollInterval?: number;
557
+ stationaryPollFast?: number;
558
+
559
+ /**
560
+ * v4.5.2 — Activity-recognition confidence threshold (0-100). Transitions below this
561
+ * confidence are ignored, preventing jittery STILL/ACTIVE flips that cause spurious
562
+ * GPS start/stop bursts. Only used by `ACTIVITY_PROVIDER`.
563
+ *
564
+ * iOS confidence is normalized from CMMotionActivityConfidence (Low/Medium/High →
565
+ * 20/40/80) so the threshold means the same thing on both platforms.
566
+ *
567
+ * Platform: Android, iOS
568
+ * Provider: ACTIVITY
569
+ * @default 50
570
+ * @since 4.5.2
571
+ */
572
+ activityConfidenceThreshold?: number;
573
+
574
+ /**
575
+ * v4.5.2 — Maximum accepted horizontal accuracy in meters. Fixes whose reported
576
+ * accuracy is worse than this value are dropped before reaching the JS layer
577
+ * (and before being persisted / posted / synced).
578
+ *
579
+ * Use to filter out indoor GPS noise on Android (`accuracy > 100 m`) or initial
580
+ * coarse network fixes on iOS. `null` / unset disables the filter.
581
+ *
582
+ * Platform: Android, iOS
583
+ * Provider: all
584
+ * @since 4.5.2
585
+ */
586
+ maxAcceptedAccuracy?: number;
587
+
513
588
  /**
514
589
  * v4.0 Phase 6 — Driver insights configuration. Enables a GPS-based state machine
515
590
  * that emits `moving`, `stopped`, `tripStart`, `tripEnd`, `speeding` and
@@ -643,6 +718,31 @@ export interface Location {
643
718
  * True if location was simulated by software (e.g. Simulator). (iOS 15+)
644
719
  */
645
720
  simulated?: boolean;
721
+
722
+ /**
723
+ * v4.3 — Driving events anexados a este fix por el detector interno.
724
+ *
725
+ * Solo presente cuando un evento se disparó al mismo tiempo que esta location y
726
+ * `drivingEvents.enabled` está activo. Cada elemento es `{ type, time, ...payload }`,
727
+ * donde `payload` depende del tipo:
728
+ * - hardBrake / rapidAcceleration / sharpTurn → `value: number`
729
+ * - speeding → `speedKmh: number, limitKmh: number`
730
+ * - tripEnd → `distance: number, durationMs: number`
731
+ * - possibleCrash → `value: number, source: 'gps' | 'sensor'`
732
+ * - providerChange → `provider: string`
733
+ * - moving / stopped / tripStart / phoneUsageWhileDriving → solo type+time.
734
+ *
735
+ * Desde v4.5.0, `events` se persiste en la cola de sync y sobrevive a POST fallidos.
736
+ *
737
+ * @since 4.3.0
738
+ */
739
+ events?: Array<{ type: string; time: number; [key: string]: any }>;
740
+
741
+ /** v4.4 — Device battery percentage (0-100) at the time of the fix. Disabled with
742
+ * `includeBattery: false` in ConfigureOptions. @since 4.4.0 */
743
+ battery?: number;
744
+ /** v4.4 — Whether the device is charging at the time of the fix. @since 4.4.0 */
745
+ isCharging?: boolean;
646
746
  }
647
747
 
648
748
  export interface StationaryLocation extends Location {
@@ -972,6 +1072,39 @@ export interface BackgroundGeolocationPlugin {
972
1072
  fail?: (error: BackgroundGeolocationError) => void
973
1073
  ): Promise<void>;
974
1074
 
1075
+ /**
1076
+ * v4.5 — Request `ACCESS_BACKGROUND_LOCATION` runtime permission (Android 10+).
1077
+ * On Android < 10 resolves immediately as `{ granted: true, notRequired: true }`.
1078
+ * On iOS resolves as `{ granted: true, notRequired: true }` (Apple does not surface
1079
+ * a separate background permission — the standard "Always" authorization covers it).
1080
+ * @since 4.5.0
1081
+ */
1082
+ requestBackgroundLocationPermission(
1083
+ success?: (result: { granted: boolean; denied?: string[]; notRequired?: boolean }) => void,
1084
+ fail?: (error: BackgroundGeolocationError) => void
1085
+ ): Promise<{ granted: boolean; denied?: string[]; notRequired?: boolean }>;
1086
+
1087
+ /**
1088
+ * v4.5 — Request `ACTIVITY_RECOGNITION` runtime permission (Android 10+).
1089
+ * Required by `ActivityLocationProvider`. iOS / Android < 10 resolve `granted: true, notRequired`.
1090
+ * @since 4.5.0
1091
+ */
1092
+ requestActivityRecognitionPermission(
1093
+ success?: (result: { granted: boolean; denied?: string[]; notRequired?: boolean }) => void,
1094
+ fail?: (error: BackgroundGeolocationError) => void
1095
+ ): Promise<{ granted: boolean; denied?: string[]; notRequired?: boolean }>;
1096
+
1097
+ /**
1098
+ * v4.5 — Request `POST_NOTIFICATIONS` runtime permission (Android 13+).
1099
+ * Without it the foreground-service notification is invisible. iOS / Android < 13
1100
+ * resolve `granted: true, notRequired`.
1101
+ * @since 4.5.0
1102
+ */
1103
+ requestNotificationPermission(
1104
+ success?: (result: { granted: boolean; denied?: string[]; notRequired?: boolean }) => void,
1105
+ fail?: (error: BackgroundGeolocationError) => void
1106
+ ): Promise<{ granted: boolean; denied?: string[]; notRequired?: boolean }>;
1107
+
975
1108
  /**
976
1109
  * Show app settings to allow change of app location permissions.
977
1110
  *
@@ -1245,13 +1378,20 @@ export interface BackgroundGeolocationPlugin {
1245
1378
  ): Promise<void>;
1246
1379
 
1247
1380
  /**
1248
- * A special task that gets executed when the app is terminated, but
1249
- * the plugin was configured to continue running in the background
1381
+ * **Android only.** A special task that gets executed when the app is terminated,
1382
+ * but the plugin was configured to continue running in the background
1250
1383
  * (option <code>stopOnTerminate: false</code>).
1251
1384
  *
1252
1385
  * In this scenario the Activity was killed by the system and all registered
1253
1386
  * event listeners will not be triggered until the app is relaunched.
1254
1387
  *
1388
+ * **iOS:** Apple does not support running JS in a killed-app scenario the same
1389
+ * way; on iOS this method is a no-op. Use `significantLocationChanges` and the
1390
+ * normal `BackgroundGeolocation.on(...)` listeners with the standard background
1391
+ * location mode instead.
1392
+ *
1393
+ * Platform: Android
1394
+ *
1255
1395
  * @example
1256
1396
  * BackgroundGeolocation.headlessTask(function(event) {
1257
1397
  *
@@ -3,10 +3,6 @@
3
3
 
4
4
  This is fork of christocracy cordova-plugin-background-geolocation plugin
5
5
  https://github.com/christocracy/cordova-plugin-background-geolocation
6
-
7
- Differences to original version:
8
-
9
- 1. new method isLocationEnabled
10
6
  */
11
7
 
12
8
  var exec = require('cordova/exec');
@@ -250,6 +246,17 @@ var BackgroundGeolocation = {
250
246
  return execWithPromise(success, failure, 'triggerSOS', [payload || {}]);
251
247
  },
252
248
 
249
+ // v4.5 — runtime permission helpers (Android). Resolve with { granted: bool, denied?: string[] }.
250
+ requestBackgroundLocationPermission: function (success, failure) {
251
+ return execWithPromise(success, failure, 'requestBackgroundLocationPermission');
252
+ },
253
+ requestActivityRecognitionPermission: function (success, failure) {
254
+ return execWithPromise(success, failure, 'requestActivityRecognitionPermission');
255
+ },
256
+ requestNotificationPermission: function (success, failure) {
257
+ return execWithPromise(success, failure, 'requestNotificationPermission');
258
+ },
259
+
253
260
  startTask: function (success, failure) {
254
261
  return execWithPromise(success,
255
262
  failure,
package/CLAUDE.md DELETED
@@ -1,56 +0,0 @@
1
- # Global Instructions
2
-
3
- ## Ejecución
4
- Pensar antes de actuar.
5
- Ejecutar herramienta primero.
6
- Leer archivos existentes antes de escribir código.
7
- Abrir solo archivos relevantes.
8
- Usar rg antes de abrir muchos archivos.
9
- No releer archivos ya leídos, salvo cambio posible.
10
- Leer por rangos, no completo.
11
- Omitir archivos mayores de 100 KB, salvo necesidad explícita.
12
- Ignorar vendor, node_modules, dist, build, storage/logs y binarios.
13
- Preferir editar antes que reescribir completo.
14
- Hacer diffs mínimos.
15
- No tocar código no relacionado.
16
- No refactorizar sin pedirlo.
17
- No cambiar arquitectura sin permiso.
18
- Preguntar antes de instalar paquetes.
19
- Preguntar antes de borrar archivos.
20
- Preguntar antes de migraciones destructivas.
21
-
22
- ## Validación
23
- Probar código antes de darlo por terminado.
24
- Validar con comando específico.
25
- No ejecutar tests pesados sin pedirlo.
26
- Reportar solo errores reales.
27
- Ejecutar /cost en sesiones largas.
28
- Iniciar nueva sesión si tarea cambia.
29
-
30
- ## Respuesta
31
- Mostrar resultado y parar.
32
- Salida concisa.
33
- Razonamiento exhaustivo interno.
34
- Cero relleno.
35
- Sin introducciones aduladoras.
36
- Sin cierres superfluos.
37
- Frases de 3 a 6 palabras.
38
- Sin artículos innecesarios.
39
- Solo bugs y cambios.
40
- Sin explicación extra.
41
- No repetir input.
42
- Respetar formato definido.
43
- No asumir datos.
44
- Preguntar solo si hay bloqueo real.
45
- Reportar solo archivos modificados.
46
-
47
- ## Formato por defecto
48
- Cambios:
49
- - archivo: resumen corto
50
-
51
- Validación:
52
- - comando ejecutado
53
- - resultado
54
-
55
- Pendiente:
56
- - solo si falta dato