transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.54k stars 424 forks source link

Recognition Service Stops in the Background #2002

Closed donmiguel closed 3 weeks ago

donmiguel commented 3 weeks ago

Your Environment

Expected Behavior

The app should run configured as headless in the background to track movements.

Actual Behavior

After a certain time, when the screen is locked, the tracking stops.

Steps to Reproduce

  1. Use the advanced demo app from the GitHub repo.
  2. Paste the provided configuration into the demo app.
  3. Start the app and start moving.
  4. After some time, when the screen is locked, the tracking stops.
  5. After unlocking the screen and switching to the app, the tracking restarts.

Context

Debug logs

Last logs entries ``` 04-18 15:00:01.163 DEBUG [AbstractService a] 🎾 start [ActivityRecognitionService startId: 1, eventCount: 1] 04-18 15:00:01.166 DEBUG [ActivityRecognitionService a] 🚘 ️DetectedActivity [type=IN_VEHICLE, confidence=96] 04-18 15:00:01.176 DEBUG [AbstractService a] βš™οΈοΈŽ FINISH [ActivityRecognitionService startId: 1, eventCount: 0, sticky: false] 04-18 15:00:01.303 DEBUG [AbstractService a] 🎾 start [ActivityRecognitionService startId: 2, eventCount: 1] 04-18 15:00:01.305 DEBUG [ActivityRecognitionService a] *** wasMoving: true, nowMoving: true, startedMoving: false, justStopped; false 04-18 15:00:01.306 DEBUG [HeadlessTask onHeadlessEvent] πŸ’€ event: activitychange 04-18 15:00:01.307 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 39 04-18 15:00:01.311 INFO [ActivityRecognitionService a] ╔═════════════════════════════════════════════ β•‘ Motion Transition Result ╠═════════════════════════════════════════════ β•Ÿβ”€ 🎾 ENTER: in_vehicle β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• 04-18 15:00:01.311 DEBUG [AbstractService a] βš™οΈοΈŽ FINISH [ActivityRecognitionService startId: 2, eventCount: 0, sticky: false] 04-18 15:00:01.327 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 39 04-18 15:00:01.516 DEBUG [AbstractService f] βš™οΈοΈŽ ActivityRecognitionService.stopSelfResult(2): true 04-18 15:00:01.517 DEBUG [AbstractService onDestroy] πŸ”΄ ActivityRecognitionService stopped 04-18 15:00:03.631 DEBUG [AbstractService a] 🎾 start [TrackingService startId: 34, eventCount: 1] 04-18 15:00:03.632 DEBUG [TrackingService c] ╔═════════════════════════════════════════════ β•‘ TrackingService: LocationResult ╠═════════════════════════════════════════════ β•Ÿβ”€ πŸ“ Location[fused 47******,10****** hAcc=4 et=+6d0h25m57s351ms alt=544.0 vel=12.029285 bear=317.0 vAcc=5 sAcc=0 bAcc=0 {Bundle[mParcelledData.dataSize=412]}] β•Ÿβ”€ Age: 43ms, time: 1713445203588 04-18 15:00:03.633 DEBUG [TSLocationManager onLocationResult] ╔═════════════════════════════════════════════ β•‘ Process LocationResult ╠═════════════════════════════════════════════ 04-18 15:00:03.634 DEBUG [TSLocationManager d] Distance from last location: 36.260777, apparent speed: 12.115194 04-18 15:00:03.634 DEBUG [TSLocationManager a] Median accuracy: 4.0 04-18 15:00:03.635 DEBUG [TSLocationManager c] Odometer: 48759.13 04-18 15:00:03.643 INFO [TSScheduleManager cancelOneShot] ⏰ Cancel OneShot: MOTION_ACTIVITY_CHECK 04-18 15:00:03.659 INFO [TSScheduleManager oneShot] ⏰ Scheduled OneShot: MOTION_ACTIVITY_CHECK in 62993ms (jobID: -18513055) 04-18 15:00:03.664 DEBUG [AbstractService a] βš™οΈοΈŽ FINISH [TrackingService startId: 34, eventCount: 0, sticky: true] 04-18 15:00:03.676 DEBUG [HeadlessTask onHeadlessEvent] πŸ’€ event: location 04-18 15:00:03.679 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 40 04-18 15:00:03.683 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 40 04-18 15:00:03.694 INFO [SQLiteLocationDAO persist] βœ… INSERT: 4829b1f4-a021-4637-9531-88962d698607 ```
christocracy commented 3 weeks ago

πŸ”΄ ActivityRecognitionService stopped

this is normal and expected. You are merely misunderstanding this log-entry’s meaning. It only means that the Service assigned to handle events has completed its work and stopped, as it’s supposed to. The plug-in has registered a PendingIntent with the ActivityTransitionService (provided by play-services), which will continue to relaunch the plug-in’s ActivityRecognitionService when another event occurs.

After some time, when the screen is locked, the tracking stops.

β€œAfter some time” as in stopTimeout: 5.

read the wiki here at this GitHub repo β€œPhilosophy of Operation”. Also read the api docs Config.stopTimeout.

christocracy commented 3 weeks ago

You can confirm that the ActivityRecognitionService remains actively tracking motion events by observing the logs while physically shaking your device vigorously to simulate walking. It sometimes helps to shake for a bit (eg 15s) then place it down flat for a few seconds, pick up and shake again.

donmiguel commented 3 weeks ago

Thanks for clarifying and pointing to the docs. I get that after the stopTimeout expires and I am not moving the plugin enters the stationary state. However, in my case, the app stops tracking while I am moving. Location authorization is set to always.

christocracy commented 3 weeks ago

Huawai P20

This is one of the worst-performing devices on earth. I own one.

see https://dontkillmyapp.com

donmiguel commented 3 weeks ago

I agree. Tests with a Pixel device are looking better.