@josuelmm/cordova-background-geolocation 3.2.0 → 4.2.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 (51) hide show
  1. package/.npmignore +4 -0
  2. package/CHANGELOG.md +290 -0
  3. package/CLAUDE.md +56 -0
  4. package/HISTORY.md +125 -0
  5. package/README.md +189 -4
  6. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +90 -0
  7. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +310 -1
  8. package/android/common/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +127 -0
  9. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +27 -11
  10. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +268 -0
  11. package/android/common/src/main/java/com/marianhello/bgloc/HttpPostService.java +86 -26
  12. package/android/common/src/main/java/com/marianhello/bgloc/PluginDelegate.java +26 -0
  13. package/android/common/src/main/java/com/marianhello/bgloc/PostLocationTask.java +42 -5
  14. package/android/common/src/main/java/com/marianhello/bgloc/driving/DrivingEventsDetector.java +265 -0
  15. package/android/common/src/main/java/com/marianhello/bgloc/http/UrlTemplateResolver.java +115 -0
  16. package/android/common/src/main/java/com/marianhello/bgloc/oem/BatteryOemHelper.java +214 -0
  17. package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +13 -9
  18. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +29 -40
  19. package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +14 -34
  20. package/android/common/src/main/java/com/marianhello/bgloc/sensor/SensorFusionDetector.java +199 -0
  21. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +305 -6
  22. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +14 -2
  23. package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +50 -3
  24. package/android/dependencies.gradle +0 -3
  25. package/angular/background-geolocation-events.ts +21 -0
  26. package/angular/background-geolocation.service.ts +63 -0
  27. package/angular/dist/background-geolocation-events.d.ts +18 -1
  28. package/angular/dist/background-geolocation.service.d.ts +36 -0
  29. package/angular/dist/esm2022/background-geolocation-events.mjs +22 -1
  30. package/angular/dist/esm2022/background-geolocation.service.mjs +35 -1
  31. package/angular/dist/fesm2022/josuelmm-cordova-background-geolocation.mjs +55 -0
  32. package/angular/dist/fesm2022/josuelmm-cordova-background-geolocation.mjs.map +1 -1
  33. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +312 -1
  34. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +22 -0
  35. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +400 -15
  36. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +12 -0
  37. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +83 -5
  38. package/ios/common/BackgroundGeolocation/MAURConfig.h +15 -0
  39. package/ios/common/BackgroundGeolocation/MAURConfig.m +100 -3
  40. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +29 -2
  41. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +4 -0
  42. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +97 -44
  43. package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.h +41 -0
  44. package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.m +137 -0
  45. package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.h +31 -0
  46. package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.m +107 -0
  47. package/package.json +41 -1
  48. package/plugin.xml +19 -8
  49. package/www/BackgroundGeolocation.d.ts +517 -3
  50. package/www/BackgroundGeolocation.js +54 -1
  51. package/RELEASE.MD +0 -16
@@ -3,7 +3,7 @@
3
3
  // Definitions by: Mauron85 (@mauron85), Norbert Györög (@djereg)
4
4
  // Definitions: https://github.com/josuelmm/cordova-background-geolocation/blob/master/www/BackgroundGeolocation.d.ts
5
5
 
6
- export type Event = 'location' | 'stationary' | 'activity' | 'start' | 'stop' | 'error' | 'authorization' | 'foreground' | 'background' | 'abort_requested' | 'http_authorization';
6
+ export type Event = 'location' | 'stationary' | 'activity' | 'start' | 'stop' | 'error' | 'authorization' | 'foreground' | 'background' | 'abort_requested' | 'http_authorization' | 'heartbeat' | 'syncStart' | 'syncProgress' | 'syncSuccess' | 'syncError' | 'tripStart' | 'tripEnd' | 'moving' | 'stopped' | 'speeding' | 'providerChange' | 'sos' | 'hardBrake' | 'rapidAcceleration' | 'sharpTurn' | 'possibleCrash' | 'phoneUsageWhileDriving';
7
7
 
8
8
  /** Event names enum (compatibility with @awesome-cordova-plugins style). Use e.g. BackgroundGeolocation.on(BackgroundGeolocationEvents.location, cb). */
9
9
  export enum BackgroundGeolocationEvents {
@@ -18,6 +18,27 @@ export enum BackgroundGeolocationEvents {
18
18
  activity = 'activity',
19
19
  stationary = 'stationary',
20
20
  location = 'location',
21
+ // v3.5 Phase 4 — diagnostics & sync events
22
+ heartbeat = 'heartbeat',
23
+ syncStart = 'syncStart',
24
+ syncProgress = 'syncProgress',
25
+ syncSuccess = 'syncSuccess',
26
+ syncError = 'syncError',
27
+ // v4.0 Phase 6 — driver insights
28
+ tripStart = 'tripStart',
29
+ tripEnd = 'tripEnd',
30
+ moving = 'moving',
31
+ stopped = 'stopped',
32
+ speeding = 'speeding',
33
+ providerChange = 'providerChange',
34
+ sos = 'sos',
35
+ // v4.1 — GPS-derived sensor-like events
36
+ hardBrake = 'hardBrake',
37
+ rapidAcceleration = 'rapidAcceleration',
38
+ sharpTurn = 'sharpTurn',
39
+ possibleCrash = 'possibleCrash',
40
+ // v4.2 — sensor fusion
41
+ phoneUsageWhileDriving = 'phoneUsageWhileDriving',
21
42
  }
22
43
 
23
44
  type HeadlessTaskEventName = 'location' | 'stationary' | 'activity';
@@ -363,6 +384,67 @@ export interface ConfigureOptions {
363
384
  */
364
385
  httpHeaders?: any;
365
386
 
387
+ /**
388
+ * Alias of `httpHeaders` introduced for the v3.3 backend-agnostic transport.
389
+ * If both are provided, `headers` takes precedence.
390
+ *
391
+ * Platform: Android, iOS
392
+ * @since 3.3.0
393
+ */
394
+ headers?: { [key: string]: string };
395
+
396
+ /**
397
+ * HTTP method used to post each location to `url`. Default `POST`.
398
+ * Use `GET` together with URL templating for backends that expect query-string transport.
399
+ *
400
+ * Platform: Android, iOS
401
+ * @since 3.3.0
402
+ */
403
+ httpMethod?: 'POST' | 'GET' | 'PUT' | 'PATCH';
404
+
405
+ /**
406
+ * HTTP method used by the sync queue when posting failed locations to `syncUrl`. Default `POST`.
407
+ *
408
+ * Platform: Android, iOS
409
+ * @since 3.3.0
410
+ */
411
+ syncHttpMethod?: 'POST' | 'GET' | 'PUT' | 'PATCH';
412
+
413
+ /**
414
+ * How real-time locations are delivered to `url`.
415
+ * - `batch` (default): one HTTP request with an array of locations.
416
+ * - `single`: one HTTP request per location.
417
+ * `single` is required when `httpMethod` is `GET` (no body).
418
+ *
419
+ * Platform: Android, iOS
420
+ * @since 3.3.0
421
+ */
422
+ httpMode?: 'batch' | 'single';
423
+
424
+ /**
425
+ * How sync-queue locations are delivered to `syncUrl`. Default `batch`.
426
+ *
427
+ * Platform: Android, iOS
428
+ * @since 3.3.0
429
+ */
430
+ syncMode?: 'batch' | 'single';
431
+
432
+ /**
433
+ * Static placeholder values used by URL/body templating. The plugin replaces
434
+ * `{key}` occurrences in `url`, `syncUrl` and string values inside `bodyTemplate`/`postTemplate`.
435
+ *
436
+ * Built-in placeholders resolved from each location:
437
+ * `{latitude}`, `{longitude}`, `{lat}`, `{lon}`, `{time}`, `{timestamp}`, `{timestamp_iso}`,
438
+ * `{speed}`, `{altitude}`, `{bearing}`, `{accuracy}`, `{provider}`.
439
+ * Any extra keys in `queryParams` are also available (e.g. `{device_id}`, `{token}`).
440
+ *
441
+ * Placeholders not found are left as-is so partial templates keep working.
442
+ *
443
+ * Platform: Android, iOS
444
+ * @since 3.3.0
445
+ */
446
+ queryParams?: { [key: string]: string | number };
447
+
366
448
  /**
367
449
  * Limit maximum number of locations stored into db.
368
450
  *
@@ -380,6 +462,107 @@ export interface ConfigureOptions {
380
462
  * Provider: all
381
463
  */
382
464
  postTemplate?: any;
465
+
466
+ /**
467
+ * Alias of `postTemplate` introduced for the v3.3 backend-agnostic transport.
468
+ * If both are provided, `bodyTemplate` takes precedence.
469
+ *
470
+ * Platform: Android, iOS
471
+ * @since 3.3.0
472
+ */
473
+ bodyTemplate?: any;
474
+
475
+ /**
476
+ * iOS 11+ only. When `true`, iOS shows the blue status bar / pill while the app uses
477
+ * location in the background. Apple recommends `true` for user transparency in apps that
478
+ * track continuously. Default: system default (`false`).
479
+ *
480
+ * Platform: iOS
481
+ * @since 3.4.0
482
+ */
483
+ showsBackgroundLocationIndicator?: boolean;
484
+
485
+ /**
486
+ * Interval in milliseconds at which the plugin emits a `heartbeat` event with the latest
487
+ * known location. Useful to confirm the service is alive without waiting for a fresh fix.
488
+ * `0` (default) disables the heartbeat.
489
+ *
490
+ * Native emission is implemented end-to-end (Android `ScheduledExecutorService`, iOS `NSTimer`).
491
+ * On the first ticks before any GPS fix is received the event arrives with no location payload.
492
+ *
493
+ * Platform: Android, iOS
494
+ * @since 3.5.0
495
+ */
496
+ heartbeatInterval?: number;
497
+
498
+ /**
499
+ * Policy applied to locations flagged as mocked (Android `isFromMockProvider` /
500
+ * iOS `simulated`). Detection has always existed; the policy controls what to do with
501
+ * those samples:
502
+ * - `'allow'` (default): keep them as regular locations.
503
+ * - `'flag'`: deliver them but tag with `mocked: true` so the app/server can filter.
504
+ * - `'drop'`: discard them silently before persisting / posting.
505
+ *
506
+ * Recommended for Traccar/anti-fraud: `'flag'` — keeps history, lets the server decide.
507
+ *
508
+ * Platform: Android, iOS
509
+ * @since 3.5.0
510
+ */
511
+ mockLocationPolicy?: 'allow' | 'flag' | 'drop';
512
+
513
+ /**
514
+ * v4.0 Phase 6 — Driver insights configuration. Enables a GPS-based state machine
515
+ * that emits `moving`, `stopped`, `tripStart`, `tripEnd`, `speeding` and
516
+ * `providerChange` events without additional sensors.
517
+ *
518
+ * v4.1 adds GPS-derived hardBrake, rapidAcceleration, sharpTurn and possibleCrash
519
+ * (no sensors required). v4.2 adds real sensor fusion (`sensorFusion: true`)
520
+ * to refine `possibleCrash` at low speed via accelerometer impact and to detect
521
+ * `phoneUsageWhileDriving`.
522
+ *
523
+ * Platform: Android, iOS
524
+ * @since 4.0.0
525
+ */
526
+ drivingEvents?: {
527
+ /** Master switch. When `false` (default) no driver-insight events are emitted. */
528
+ enabled?: boolean;
529
+ /** Speed limit in km/h for the `speeding` event. `0` disables. Default 0. */
530
+ speedLimit?: number;
531
+ /** m/s threshold below which the user is considered stopped. Default 1.0. */
532
+ minMovingSpeed?: number;
533
+ /** ms of continuous below-threshold speed needed to confirm "stopped". Default 60000. */
534
+ stoppedDuration?: number;
535
+ /** m/s threshold to start counting a trip. Default 3.0 (~10.8 km/h). */
536
+ minTripSpeed?: number;
537
+ /** ms of continuous above-threshold speed needed to confirm `tripStart`. Default 30000. */
538
+ minTripDuration?: number;
539
+
540
+ // v4.1 — GPS-derived sensor-like driving events. Set 0 to disable each one.
541
+ /** Deceleration threshold (m/s², positive value). Triggers `hardBrake` when |Δspeed/Δt| ≥ this during an active trip. Default 3.5. */
542
+ hardBrakeMps2?: number;
543
+ /** Acceleration threshold (m/s²) for `rapidAcceleration` during a trip. Default 3.5. */
544
+ rapidAccelMps2?: number;
545
+ /** Bearing change rate (deg/s) for `sharpTurn`. Requires speed ≥ 5 m/s. Default 30. */
546
+ sharpTurnDegPerSec?: number;
547
+ /** Velocity drop in km/h within `crashWindowMs` while tripActive — triggers `possibleCrash`. Default 25. */
548
+ crashImpactKmh?: number;
549
+ /** Window in ms used to evaluate the crash impact. Default 2000. */
550
+ crashWindowMs?: number;
551
+
552
+ // v4.2 — Real sensor fusion (accelerometer + gyroscope).
553
+ /** Enable real sensor fusion. When `true` and `enabled` is `true`, the plugin samples
554
+ * linear acceleration + gyroscope while a trip is active and emits high-confidence
555
+ * `possibleCrash` and `phoneUsageWhileDriving`. Adds modest battery cost. Default false. */
556
+ sensorFusion?: boolean;
557
+ /** Crash impact threshold in g (1g = 9.81 m/s²). Triggers `possibleCrash` from the sensor pipeline. Default 3.0. */
558
+ crashImpactG?: number;
559
+ /** Cooldown ms between successive sensor-driven crash detections. Default 10000. */
560
+ sensorCrashCooldownMs?: number;
561
+ /** Sustained device-jitter window (ms) needed to fire `phoneUsageWhileDriving`. Default 4000. */
562
+ phoneUsageWindowMs?: number;
563
+ /** Cooldown ms between successive `phoneUsageWhileDriving` events. Default 60000. */
564
+ phoneUsageCooldownMs?: number;
565
+ };
383
566
  }
384
567
 
385
568
  export interface LocationOptions {
@@ -518,6 +701,59 @@ export interface ServiceStatus {
518
701
  authorization: AuthorizationStatus;
519
702
  }
520
703
 
704
+ /**
705
+ * Extended diagnostics returned by `getDiagnostics()`.
706
+ * Helps explain why tracking may not be running in production.
707
+ *
708
+ * @since 3.5.0
709
+ */
710
+ export interface Diagnostics {
711
+ // ---- common ----
712
+ /** TRUE if the native service is currently running. */
713
+ isRunning: boolean;
714
+ /** TRUE if the OS-level location services are enabled. */
715
+ locationServicesEnabled: boolean;
716
+ /** Configured `startOnBoot` flag. */
717
+ startOnBoot?: boolean;
718
+ /** Number of locations queued for sync (`getPendingSyncCount`). */
719
+ pendingSyncCount?: number;
720
+ /** UTC ms of the last received location, or `null` if none yet. */
721
+ lastLocationAt?: number | null;
722
+
723
+ // ---- Android ----
724
+ /** Android: TRUE if `ACCESS_FINE_LOCATION` is granted. */
725
+ fineLocationGranted?: boolean;
726
+ /** Android: TRUE if `ACCESS_COARSE_LOCATION` is granted. */
727
+ coarseLocationGranted?: boolean;
728
+ /** Android 10+: TRUE if `ACCESS_BACKGROUND_LOCATION` is granted. Always `true` on Android <10. */
729
+ backgroundLocationGranted?: boolean;
730
+ /** Android 13+: TRUE if `POST_NOTIFICATIONS` is granted. Always `true` on Android <13. */
731
+ notificationPermissionGranted?: boolean;
732
+ /** Android 10+: TRUE if `ACTIVITY_RECOGNITION` is granted. Always `true` on Android <10. */
733
+ activityRecognitionGranted?: boolean;
734
+ /** Android: TRUE if the app is on the battery optimisation whitelist. */
735
+ batteryOptimizationIgnored?: boolean;
736
+ /** Android: device manufacturer (`Build.MANUFACTURER`). Helps detect aggressive OEMs. */
737
+ manufacturer?: string;
738
+ /** Android: declared `foregroundServiceType` of the location service (numeric, e.g. 8 = LOCATION). */
739
+ foregroundServiceType?: number;
740
+
741
+ // ---- iOS ----
742
+ /** iOS 14+: TRUE if the user granted Precise Location ("on" in Settings). */
743
+ preciseLocationEnabled?: boolean;
744
+ /**
745
+ * iOS: status of system-wide Background App Refresh.
746
+ * One of `available | denied | restricted`.
747
+ */
748
+ backgroundRefreshStatus?: 'available' | 'denied' | 'restricted';
749
+ /** iOS: TRUE if Low Power Mode is currently enabled (system-wide). */
750
+ lowPowerModeEnabled?: boolean;
751
+ /** iOS: status of the Motion & Fitness permission. */
752
+ motionPermissionStatus?: 'authorized' | 'denied' | 'restricted' | 'notDetermined';
753
+ /** iOS: human-readable label of the current `CLAuthorizationStatus`. */
754
+ authorizationStatusText?: string;
755
+ }
756
+
521
757
  export interface LogEntry {
522
758
  /** ID of log entry as stored in db. */
523
759
  id: number;
@@ -642,6 +878,100 @@ export interface BackgroundGeolocationPlugin {
642
878
  fail?: (error: BackgroundGeolocationError) => void
643
879
  ): Promise<ServiceStatus>;
644
880
 
881
+ /**
882
+ * Extended diagnostics. Returns permissions, battery optimisation state,
883
+ * last fix age, pending sync count, OEM info and (on iOS) precise location /
884
+ * background refresh / low power flags.
885
+ *
886
+ * Use this to diagnose "tracking is not running" issues in production:
887
+ * a missing `ACCESS_BACKGROUND_LOCATION` on Android 10+, an OEM that killed
888
+ * the foreground service, or `preciseLocationEnabled: false` on iOS will all
889
+ * surface here.
890
+ *
891
+ * Platform: Android, iOS
892
+ * @since 3.5.0
893
+ */
894
+ getDiagnostics(
895
+ success?: (diagnostics: Diagnostics) => void,
896
+ fail?: (error: BackgroundGeolocationError) => void
897
+ ): Promise<Diagnostics>;
898
+
899
+ /**
900
+ * Android: returns `true` if the app is on the battery optimisation whitelist
901
+ * (Settings → Battery → "Don't optimize"). On iOS resolves to `true` (concept
902
+ * does not apply; iOS already restricts background activity by other means).
903
+ *
904
+ * @since 3.6.0
905
+ */
906
+ isIgnoringBatteryOptimizations(
907
+ success?: (whitelisted: boolean) => void,
908
+ fail?: (error: BackgroundGeolocationError) => void
909
+ ): Promise<boolean>;
910
+
911
+ /**
912
+ * Android: opens the system dialog to add the app to the battery optimisation
913
+ * whitelist. The user must accept; the app cannot grant this on its own.
914
+ * Resolves with the up-to-date whitelist state. iOS: resolves `true`.
915
+ *
916
+ * @since 3.6.0
917
+ */
918
+ requestIgnoreBatteryOptimizations(
919
+ success?: (whitelisted: boolean) => void,
920
+ fail?: (error: BackgroundGeolocationError) => void
921
+ ): Promise<boolean>;
922
+
923
+ /**
924
+ * Android: opens the battery-related settings screen for this app. iOS: no-op.
925
+ *
926
+ * @since 3.6.0
927
+ */
928
+ openBatterySettings(
929
+ success?: () => void,
930
+ fail?: (error: BackgroundGeolocationError) => void
931
+ ): Promise<void>;
932
+
933
+ /**
934
+ * Android only: opens the OEM-specific "auto-start" / "background activity"
935
+ * settings screen on Xiaomi MIUI, Huawei EMUI, Oppo ColorOS, Vivo FunTouch,
936
+ * Samsung One UI. Falls back to the standard app-info screen when the OEM
937
+ * is unknown. Resolves with `{ opened: boolean, manufacturer: string, screen: string }`.
938
+ * iOS: resolves `{ opened: false, manufacturer: 'apple', screen: '' }`.
939
+ *
940
+ * @since 3.6.0
941
+ */
942
+ openAutoStartSettings(
943
+ success?: (info: { opened: boolean; manufacturer: string; screen: string }) => void,
944
+ fail?: (error: BackgroundGeolocationError) => void
945
+ ): Promise<{ opened: boolean; manufacturer: string; screen: string }>;
946
+
947
+ /**
948
+ * Returns OEM-specific guidance for the user. The `steps` array contains
949
+ * short instructions like "Settings → Apps → [your app] → Battery → Sin restricciones".
950
+ * Use to render an actionable help screen when `getDiagnostics()` shows the
951
+ * service is being killed by the OEM.
952
+ *
953
+ * @since 3.6.0
954
+ */
955
+ getManufacturerHelp(
956
+ success?: (info: { manufacturer: string; steps: string[] }) => void,
957
+ fail?: (error: BackgroundGeolocationError) => void
958
+ ): Promise<{ manufacturer: string; steps: string[] }>;
959
+
960
+ /**
961
+ * v4.0 Phase 6 — Trigger an SOS event from JS. The plugin emits an `sos` JS event
962
+ * with the latest known location plus the provided payload (anything serialisable).
963
+ * The host app is responsible for the actual SOS workflow (notify contacts, push,
964
+ * alarm UI). This method just guarantees a single emission carrying the most recent
965
+ * fix the plugin knows about.
966
+ *
967
+ * @since 4.0.0
968
+ */
969
+ triggerSOS(
970
+ payload?: { [key: string]: any },
971
+ success?: () => void,
972
+ fail?: (error: BackgroundGeolocationError) => void
973
+ ): Promise<void>;
974
+
645
975
  /**
646
976
  * Show app settings to allow change of app location permissions.
647
977
  *
@@ -1075,13 +1405,197 @@ export interface BackgroundGeolocationPlugin {
1075
1405
  callback?: () => void
1076
1406
  ): Subscribable<void>;
1077
1407
 
1408
+ /**
1409
+ * Register heartbeat listener.
1410
+ *
1411
+ * Triggered every `heartbeatInterval` ms while the service is running.
1412
+ * The `location` argument is the latest known fix; it may be `undefined` on
1413
+ * the very first ticks if no GPS fix has been received yet.
1414
+ *
1415
+ * @since 3.5.0
1416
+ */
1417
+ on(
1418
+ eventName: 'heartbeat',
1419
+ callback?: (location?: Location) => void
1420
+ ): Subscribable<Location | void>;
1421
+
1422
+ /**
1423
+ * Register sync-start listener.
1424
+ *
1425
+ * Triggered when a batch upload to `syncUrl` begins.
1426
+ *
1427
+ * @since 3.5.0
1428
+ */
1429
+ on(
1430
+ eventName: 'syncStart',
1431
+ callback?: () => void
1432
+ ): Subscribable<void>;
1433
+
1434
+ /**
1435
+ * Register sync-progress listener.
1436
+ *
1437
+ * Triggered with a 0..100 percentage while a sync upload is in flight.
1438
+ *
1439
+ * @since 3.5.0
1440
+ */
1441
+ on(
1442
+ eventName: 'syncProgress',
1443
+ callback?: (progress: number) => void
1444
+ ): Subscribable<number>;
1445
+
1446
+ /**
1447
+ * Register sync-success listener.
1448
+ *
1449
+ * Payload: `{ sent: number }` — locations included in the successful upload.
1450
+ *
1451
+ * @since 3.5.0
1452
+ */
1453
+ on(
1454
+ eventName: 'syncSuccess',
1455
+ callback?: (data: { sent: number }) => void
1456
+ ): Subscribable<{ sent: number }>;
1457
+
1458
+ /**
1459
+ * Register sync-error listener.
1460
+ *
1461
+ * Payload: `{ httpStatus: number; message: string }` — non-2xx response or IO/network failure.
1462
+ *
1463
+ * @since 3.5.0
1464
+ */
1465
+ on(
1466
+ eventName: 'syncError',
1467
+ callback?: (data: { httpStatus: number; message: string }) => void
1468
+ ): Subscribable<{ httpStatus: number; message: string }>;
1469
+
1470
+ /**
1471
+ * v4.0 Phase 6 — Trip starts (state goes from "stopped" to "moving" with sustained
1472
+ * speed >= `drivingEvents.minTripSpeed` for `minTripDuration`).
1473
+ * @since 4.0.0
1474
+ */
1475
+ on(
1476
+ eventName: 'tripStart',
1477
+ callback?: (location: Location) => void
1478
+ ): Subscribable<Location>;
1479
+
1480
+ /**
1481
+ * v4.0 Phase 6 — Trip ends (sustained speed near zero for `drivingEvents.stoppedDuration`).
1482
+ * Payload includes basic trip stats: distance (m) and duration (ms).
1483
+ * @since 4.0.0
1484
+ */
1485
+ on(
1486
+ eventName: 'tripEnd',
1487
+ callback?: (data: { location: Location; distance: number; durationMs: number }) => void
1488
+ ): Subscribable<{ location: Location; distance: number; durationMs: number }>;
1489
+
1490
+ /**
1491
+ * v4.0 Phase 6 — User started moving (speed crossed above `minMovingSpeed`).
1492
+ * @since 4.0.0
1493
+ */
1494
+ on(
1495
+ eventName: 'moving',
1496
+ callback?: (location: Location) => void
1497
+ ): Subscribable<Location>;
1498
+
1499
+ /**
1500
+ * v4.0 Phase 6 — User stopped (speed below threshold for `stoppedDuration`).
1501
+ * @since 4.0.0
1502
+ */
1503
+ on(
1504
+ eventName: 'stopped',
1505
+ callback?: (location: Location) => void
1506
+ ): Subscribable<Location>;
1507
+
1508
+ /**
1509
+ * v4.0 Phase 6 — Speed crossed above `drivingEvents.speedLimit` (km/h).
1510
+ * Fires once when crossing; further fixes above the limit do not refire until the
1511
+ * speed drops back below the limit and crosses again.
1512
+ * @since 4.0.0
1513
+ */
1514
+ on(
1515
+ eventName: 'speeding',
1516
+ callback?: (data: { location: Location; speedKmh: number; limitKmh: number }) => void
1517
+ ): Subscribable<{ location: Location; speedKmh: number; limitKmh: number }>;
1518
+
1519
+ /**
1520
+ * v4.0 Phase 6 — Native location provider changed (GPS ↔ Network ↔ Fused).
1521
+ * Useful to react to GPS being turned off or losing signal indoors.
1522
+ * @since 4.0.0
1523
+ */
1524
+ on(
1525
+ eventName: 'providerChange',
1526
+ callback?: (data: { provider: string }) => void
1527
+ ): Subscribable<{ provider: string }>;
1528
+
1529
+ /**
1530
+ * v4.0 Phase 6 — `triggerSOS()` was invoked. Payload is the user-supplied object
1531
+ * plus the latest known `location` (may be `undefined` if no fix yet).
1532
+ * @since 4.0.0
1533
+ */
1534
+ on(
1535
+ eventName: 'sos',
1536
+ callback?: (data: { location?: Location; [key: string]: any }) => void
1537
+ ): Subscribable<{ location?: Location; [key: string]: any }>;
1538
+
1539
+ /**
1540
+ * v4.1 — GPS-derived hard brake. Payload `{ location, value }` where `value` is the
1541
+ * computed deceleration in m/s² (negative number, more negative = harder brake).
1542
+ * @since 4.1.0
1543
+ */
1544
+ on(
1545
+ eventName: 'hardBrake',
1546
+ callback?: (data: { location: Location; value: number }) => void
1547
+ ): Subscribable<{ location: Location; value: number }>;
1548
+
1549
+ /**
1550
+ * v4.1 — GPS-derived rapid acceleration (m/s²). Positive value.
1551
+ * @since 4.1.0
1552
+ */
1553
+ on(
1554
+ eventName: 'rapidAcceleration',
1555
+ callback?: (data: { location: Location; value: number }) => void
1556
+ ): Subscribable<{ location: Location; value: number }>;
1557
+
1558
+ /**
1559
+ * v4.1 — GPS-derived sharp turn. `value` is the bearing-change rate in deg/s.
1560
+ * Only fires when speed ≥ 5 m/s to avoid GPS jitter at low speeds.
1561
+ * @since 4.1.0
1562
+ */
1563
+ on(
1564
+ eventName: 'sharpTurn',
1565
+ callback?: (data: { location: Location; value: number }) => void
1566
+ ): Subscribable<{ location: Location; value: number }>;
1567
+
1568
+ /**
1569
+ * v4.1+ — Heuristic possible-crash detection. `value` is the velocity drop in km/h
1570
+ * (when `source === 'gps'`) or the impact magnitude in g (when `source === 'sensor'`).
1571
+ * v4.2 adds the `source` field to distinguish the GPS heuristic from the accelerometer
1572
+ * pipeline (`drivingEvents.sensorFusion`). App should ALWAYS confirm with the user
1573
+ * before notifying contacts — false positives are possible.
1574
+ * @since 4.1.0
1575
+ */
1576
+ on(
1577
+ eventName: 'possibleCrash',
1578
+ callback?: (data: { location: Location; value: number; source: 'gps' | 'sensor' }) => void
1579
+ ): Subscribable<{ location: Location; value: number; source: 'gps' | 'sensor' }>;
1580
+
1581
+ /**
1582
+ * v4.2 — Sustained device interaction during an active trip with the screen on.
1583
+ * Conservative heuristic combining accelerometer/gyroscope jitter; meant to power
1584
+ * "stop using your phone while driving" UX. Disabled unless `drivingEvents.sensorFusion === true`.
1585
+ * @since 4.2.0
1586
+ */
1587
+ on(
1588
+ eventName: 'phoneUsageWhileDriving',
1589
+ callback?: (location?: Location) => void
1590
+ ): Subscribable<Location | void>;
1591
+
1078
1592
  /**
1079
1593
  * Register event listener (accepts BackgroundGeolocationEvents enum for compatibility).
1080
1594
  */
1081
1595
  on(
1082
1596
  eventName: BackgroundGeolocationEvents,
1083
- callback?: (data: Location | StationaryLocation | Activity | BackgroundGeolocationError | AuthorizationStatus | void) => void
1084
- ): Subscribable<Location | StationaryLocation | Activity | BackgroundGeolocationError | AuthorizationStatus | void>;
1597
+ callback?: (data: Location | StationaryLocation | Activity | BackgroundGeolocationError | AuthorizationStatus | number | { sent: number } | { httpStatus: number; message: string } | void) => void
1598
+ ): Subscribable<Location | StationaryLocation | Activity | BackgroundGeolocationError | AuthorizationStatus | number | { sent: number } | { httpStatus: number; message: string } | void>;
1085
1599
 
1086
1600
  }
1087
1601
 
@@ -57,7 +57,28 @@ var BackgroundGeolocation = {
57
57
  'foreground',
58
58
  'background',
59
59
  'abort_requested',
60
- 'http_authorization'
60
+ 'http_authorization',
61
+ // v3.5 Phase 4
62
+ 'heartbeat',
63
+ 'syncStart',
64
+ 'syncProgress',
65
+ 'syncSuccess',
66
+ 'syncError',
67
+ // v4.0 Phase 6 — driver insights
68
+ 'tripStart',
69
+ 'tripEnd',
70
+ 'moving',
71
+ 'stopped',
72
+ 'speeding',
73
+ 'providerChange',
74
+ 'sos',
75
+ // v4.1 — GPS-derived sensor-like events
76
+ 'hardBrake',
77
+ 'rapidAcceleration',
78
+ 'sharpTurn',
79
+ 'possibleCrash',
80
+ // v4.2 — sensor fusion
81
+ 'phoneUsageWhileDriving'
61
82
  ],
62
83
 
63
84
  DISTANCE_FILTER_PROVIDER: 0,
@@ -197,6 +218,38 @@ var BackgroundGeolocation = {
197
218
  'checkStatus')
198
219
  },
199
220
 
221
+ getDiagnostics: function (success, failure) {
222
+ return execWithPromise(success,
223
+ failure,
224
+ 'getDiagnostics')
225
+ },
226
+
227
+ // v3.6 Phase 5 — Battery / OEM helpers (Android only; on iOS these resolve as no-ops)
228
+ isIgnoringBatteryOptimizations: function (success, failure) {
229
+ return execWithPromise(success, failure, 'isIgnoringBatteryOptimizations');
230
+ },
231
+
232
+ requestIgnoreBatteryOptimizations: function (success, failure) {
233
+ return execWithPromise(success, failure, 'requestIgnoreBatteryOptimizations');
234
+ },
235
+
236
+ openBatterySettings: function (success, failure) {
237
+ return execWithPromise(success, failure, 'openBatterySettings');
238
+ },
239
+
240
+ openAutoStartSettings: function (success, failure) {
241
+ return execWithPromise(success, failure, 'openAutoStartSettings');
242
+ },
243
+
244
+ getManufacturerHelp: function (success, failure) {
245
+ return execWithPromise(success, failure, 'getManufacturerHelp');
246
+ },
247
+
248
+ // v4.0 Phase 6 — Driver insights
249
+ triggerSOS: function (payload, success, failure) {
250
+ return execWithPromise(success, failure, 'triggerSOS', [payload || {}]);
251
+ },
252
+
200
253
  startTask: function (success, failure) {
201
254
  return execWithPromise(success,
202
255
  failure,
package/RELEASE.MD DELETED
@@ -1,16 +0,0 @@
1
- In order to release a version the following actions are needed:
2
-
3
- 1. **Version and docs**
4
- - Set the new version (e.g. `3.2.0`) in:
5
- - `package.json` (`version` field)
6
- - `plugin.xml` (root `<plugin>` attribute `version`)
7
- - Add a release entry in `CHANGELOG.md` (date, Added/Fixed/Changed/Documentation).
8
- - Update `README.md` if needed (e.g. "New in X.Y.Z", example version strings).
9
-
10
- 2. **Lock file**
11
- - Run `npm install` so `package-lock.json` stays in sync with `package.json`.
12
-
13
- 3. **Git tag and release**
14
- - Go to [Releases → Create a new release](https://github.com/josuelmm/cordova-background-geolocation/releases/new).
15
- - Create a tag with the version name (e.g. `v3.2.0`).
16
- - Publish the release. GitHub Actions will publish the package to npm.