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.56k stars 427 forks source link

Location is not Tracked when killed by swiping it from app switcher - Android #376

Closed Josh2941 closed 5 years ago

Josh2941 commented 6 years ago

Location is not Tracked when killed by swiping it from AppSwitcher in Android in some models(Lenovo, Huawei, MI). And there is no option to enable location services from inside app.

This was tested using your demo app from Google Play.

Your Environment

Expected Behavior

Location should be tracked even if the app is killed by user on swiping from app switcher. App should prompt to enable location or enable programatically in lenovo.

Actual Behavior

Location is not tracked after the app is killed by swiping it from app switcher. No option to enable location services from the app in lenovo.

Steps to Reproduce

  1. Start the app
  2. Kill it using AppSwitcher by swiping it.

Context

Track location even when killed.

Debug logs

No logs

christocracy commented 6 years ago

On the same Lenovo device:

Josh2941 commented 6 years ago

The scenario which you are suggesting will stop the music player, but for location, we will be able to track it. I already have a working code of mine for tracking location where it doesn't stop even if we terminate it. Your application has more features which will take time for me to develop it. That's why I am just expecting this fix in yours. Try PendingIntent version of requestLocationUpdates using Google API's FusedLocationProvider. It will work even if you terminate the app.

I had some doubts regarding this PendingIntent version of requestLocationUpdates using Google API's FusedLocationProvider which I have posted it StackOverflow. Please help if you have any idea about it. Here is the link -> https://stackoverflow.com/questions/47903703/background-location-updates-using-google-api-fused-location-provider-not-accur

christocracy commented 6 years ago

Try terminating music player on other devices: music is not supposed to stop player when player’s foreground activity is terminated, since the player is running as a foreground service, just as the background geolocation plugin does.

The plugin has been using the PendingIntent version of FusedLocationProvider for the last three years with over 1600 other paying customers.

Josh2941 commented 6 years ago

Oh, but my code works for me even if I terminate it. I tested it in different devices and all of it worked fine. Have any Idea about why its not working with this plugin?

christocracy commented 6 years ago

Show me logs from $ adb logcat after terminating your app.

Josh2941 commented 6 years ago

This the log after terminating the app.

01-04 19:58:37.923 3237-3237/? D/LenovoAppIconTheme: ApplicationPackageManager;getLenovoDrawable;calling from :: com.android.systemui, packageName = com.transistorsoft.backgroundgeolocation.react 01-04 19:58:37.928 3237-3237/? D/LenovoAppIconTheme: ExtraResources;getIconOriginalName;<2130903040>com.transistorsoft.backgroundgeolocation.react:mipmap/ic_launcher 01-04 19:58:37.929 2507-10771/? D/LenovoAppIconTheme: AppIconThemeServices;getThemeIconInfo;inPackageName = com.transistorsoft.backgroundgeolocation.react,inResoucePath = mipmap/ic_launcher.png 01-04 19:58:39.652 2507-2521/? I/ActivityManager: Killing 25084:com.transistorsoft.backgroundgeolocation.react/u0a125 (adj 0): recenttask 01-04 19:58:39.655 2507-2521/? W/ActivityManager: Scheduling restart of crashed service com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService in 1000ms 01-04 19:58:39.657 2507-2521/? I/WindowManager: Destroying surface Surface(name=com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.backgroundgeolocation.react.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2047 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1455 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2651 com.android.server.wm.WindowManagerService.removeWindowLocked:2609 com.android.server.wm.WindowManagerService.removeWindowLocked:2478 com.android.server.wm.AppWindowToken.removeAllWindows:530 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:326 01-04 19:58:39.868 21087-21127/? V/UserExperience: TaskStackCollector.uploadS82Data() pkg: com.transistorsoft.backgroundgeolocation.react, versionCode: 210, useTime: 24567 01-04 19:58:40.678 2507-2580/? I/ActivityManager: Start proc 25913:com.transistorsoft.backgroundgeolocation.react/u0a125 for service com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService 01-04 19:58:40.784 25913-25913/? V/fb-UnpackingSoSource: locked dso store /data/user/0/com.transistorsoft.backgroundgeolocation.react/lib-main 01-04 19:58:40.784 25913-25913/? I/fb-UnpackingSoSource: dso store is up-to-date: /data/user/0/com.transistorsoft.backgroundgeolocation.react/lib-main 01-04 19:58:40.785 25913-25913/? V/fb-UnpackingSoSource: releasing dso store lock for /data/user/0/com.transistorsoft.backgroundgeolocation.react/lib-main 01-04 20:00:00.361 2507-3124/? V/AlarmManager: sending alarm Alarm{1002482 type 0 when 1515076158130 com.transistorsoft.backgroundgeolocation.react}

christocracy commented 6 years ago
01-04 19:58:39.655 2507-2521/? W/ActivityManager: Scheduling restart of crashed service com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService in 1000ms

If you use foregroundService: true, the background-service won't terminate when the foreground-activity is terminated.

Show me the config you're providing the plugin.

Josh2941 commented 6 years ago

I tested that too. Even if it is set true its getting terminated. I am getting the log above which you are talking about. Please find it below.

01-04 20:04:40.112 26905-26982/? I/TSLocationManager: [c.t.l.settings.Settings print] 
                                                      ╔═════════════════════════════════════════════
                                                      ║ BackgroundGeolocation Settings
                                                      ╠═════════════════════════════════════════════
                                                      {
                                                        "isMoving": false,
                                                        "enabled": true,
                                                        "odometer": 0.119303145,
                                                        "schedulerEnabled": false,
                                                        "trackingMode": "location",
                                                        "distanceFilter": 0,
                                                        "desiredAccuracy": 0,
                                                        "desiredOdometerAccuracy": 100,
                                                        "locationUpdateInterval": 60000,
                                                        "fastestLocationUpdateInterval": 30000,
                                                        "locationTimeout": 60,
                                                        "deferTime": 0,
                                                        "disableElasticity": false,
                                                        "elasticityMultiplier": 1,
                                                        "activityRecognitionInterval": 10000,
                                                        "minimumActivityRecognitionConfidence": 75,
                                                        "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
                                                        "disableStopDetection": false,
                                                        "stationaryRadius": 25,
                                                        "stopTimeout": 5,
                                                        "stopOnStationary": false,
                                                        "url": "http:\/\/tracker.transistorsoft.com\/locations\/growsmart",
                                                        "method": "POST",
                                                        "autoSync": true,
                                                        "autoSyncThreshold": 0,
                                                        "batchSync": false,
                                                        "maxBatchSize": -1,
                                                        "params": {
                                                          "device": {
                                                            "version": "7.0",
                                                            "manufacturer": "LENOVO",
                                                            "framework": "ReactNative",
                                                            "platform": "Android",
                                                            "model": "Lenovo K33a42",
                                                            "uuid": "91917b68f724cxxx"
                                                          }
                                                        },
                                                        "headers": {},
                                                        "extras": {},
                                                        "httpRootProperty": "location",
                                                        "locationTemplate": "",
                                                        "geofenceTemplate": "",
                                                        "persist": true,
                                                        "maxDaysToPersist": 1,
                                                        "maxRecordsToPersist": -1,
                                                        "locationsOrderDirection": "ASC",
                                                        "httpTimeout": 60000,
                                                        "geofenceProximityRadius": 1000,
                                                        "geofenceInitialTriggerEntry": true,
                                                        "stopOnTerminate": false,
                                                        "startOnBoot": true,
                                                        "heartbeatInterval": 60,
                                                        "foregroundService": true,
                                                        "notificationPriority": 0,
                                                        "notificationTitle": "",
                                                        "notificationText": "Location Service activated",
                                                        "notificationColor": "",
                                                        "notificationIcon": "",
                                                        "notificationSmallIcon": "",
                                                        "notificationLargeIcon": "",
                                                        "forceReloadOnLocationChange": false,
                                                        "forceReloadOnMotionChange": false,
                                                        "forceReloadOnGeofence": false,
                                                        "forceReloadOnBoot": false,
                                                        "forceReloadOnHeartbeat": false,
                                                        "forceReloadOnSchedule": false,
                                                        "stopAfterElapsedMinutes": 0,
                                                        "schedule": [],
                                                        "configureUrl": "",
                                                        "configureInterval": -1,
                                                        "debug": true,
                                                        "logLevel": 5,
                                                        "logMaxDays": 3
                                                      }╚═════════════════════════════════════════════
01-04 20:04:40.576 3237-3237/? D/StatusBar: onNotificationPosted: StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE))
01-04 20:04:40.577 3237-3237/? D/StatusBar: updateNotification(StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE)))
01-04 20:04:40.579 3237-3237/? D/StatusBar: No peeking: unimportant notification: 0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125
01-04 20:04:40.579 3237-3237/? D/StatusBar: reusing notification for key: 0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125
01-04 20:04:45.967 3237-3237/? D/LenovoAppIconTheme: ApplicationPackageManager;getLenovoDrawable;calling from :: com.android.systemui, packageName = com.transistorsoft.backgroundgeolocation.react
01-04 20:04:45.968 3237-3237/? D/LenovoAppIconTheme: ExtraResources;getIconOriginalName;<2130903040>com.transistorsoft.backgroundgeolocation.react:mipmap/ic_launcher
01-04 20:04:45.969 2507-10774/? D/LenovoAppIconTheme: AppIconThemeServices;getThemeIconInfo;inPackageName = com.transistorsoft.backgroundgeolocation.react,inResoucePath = mipmap/ic_launcher.png
01-04 20:04:47.498 2507-3876/? I/ActivityManager: Killing 26905:com.transistorsoft.backgroundgeolocation.react/u0a125 (adj 200): recenttask
01-04 20:04:47.508 2507-3876/? W/ActivityManager: Scheduling restart of crashed service com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService in 1000ms
01-04 20:04:47.510 2507-3876/? I/WindowManager: Destroying surface Surface(name=com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.backgroundgeolocation.react.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2047 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1455 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2651 com.android.server.wm.WindowManagerService.removeWindowLocked:2609 com.android.server.wm.WindowManagerService.removeWindowLocked:2478 com.android.server.wm.AppWindowToken.removeAllWindows:530 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:326 
01-04 20:04:47.568 3237-3237/? D/StatusBar: onNotificationRemoved: StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE))
01-04 20:04:47.601 3237-3237/? D/LenovoTickerView: no ticker view for com.transistorsoft.backgroundgeolocation.react, id = 9942585
01-04 20:04:47.705 21087-21127/? V/UserExperience: TaskStackCollector.uploadS82Data() pkg: com.transistorsoft.backgroundgeolocation.react, versionCode: 210, useTime: 9921
01-04 20:04:48.530 2507-2580/? I/ActivityManager: Start proc 27062:com.transistorsoft.backgroundgeolocation.react/u0a125 for service com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService
01-04 20:04:48.585 3237-3237/? D/StatusBar: onNotificationPosted: StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE))
01-04 20:04:48.585 3237-3237/? D/PhoneStatusBar: addNotification key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125
01-04 20:04:48.586 3237-3237/? D/StatusBar: createNotificationViews(notification=StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE))
01-04 20:04:48.635 27062-27062/? V/fb-UnpackingSoSource: locked dso store /data/user/0/com.transistorsoft.backgroundgeolocation.react/lib-main
01-04 20:04:48.636 27062-27062/? I/fb-UnpackingSoSource: dso store is up-to-date: /data/user/0/com.transistorsoft.backgroundgeolocation.react/lib-main
01-04 20:04:48.636 27062-27062/? V/fb-UnpackingSoSource: releasing dso store lock for /data/user/0/com.transistorsoft.backgroundgeolocation.react/lib-main
01-04 20:04:48.650 3237-3237/? D/StatusBar: No peeking: unimportant notification: 0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10125
christocracy commented 6 years ago

Here's what I see on my Nexus 4 (4.4.4) and Pixel (8.1.0) when I terminate foreground-activity using foregroundService: true

01-04 09:46:31.845  5290  5290 D ReactNative: ReactInstanceManager.detachViewFromInstance()
01-04 09:46:31.858  5290  5290 D TSLocationManager: [c.t.l.a.BackgroundGeolocation e]
01-04 09:46:31.858  5290  5290 D TSLocationManager:   🔴  Cleared callbacks
01-04 09:46:31.880  5290  5290 I TSLocationManager: [c.t.l.a.BackgroundGeolocation onActivityDestroy]
01-04 09:46:31.880  5290  5290 I TSLocationManager: ╔═════════════════════════════════════════════
01-04 09:46:31.880  5290  5290 I TSLocationManager: ║ MainActivity was destroyed
01-04 09:46:31.880  5290  5290 I TSLocationManager: ╠═════════════════════════════════════════════
01-04 09:46:31.880  5290  5290 I TSLocationManager: ╟─ stopOnTerminate: false
01-04 09:46:31.880  5290  5290 I TSLocationManager: ╟─ enabled: true
01-04 09:46:31.898  5290  5290 I TSLocationManager: [c.t.l.l.TSLocationManager stopWatchPosition]
01-04 09:46:31.898  5290  5290 I TSLocationManager:   🔴  watchPosition: OFF
01-04 09:46:31.915  5290  5290 D TSLocationManager: [c.t.l.a.BackgroundGeolocation e]
01-04 09:46:31.915  5290  5290 D TSLocationManager:   🔴  Cleared callbacks
christocracy commented 6 years ago

And when I terminate on my Lenovo A6000

I/ActivityManager( 2881): Force stopping com.transistorsoft.backgroundgeolocation.react appid=10120 user=0: from pid 4000
I/ActivityManager( 2881): Killing 9986:com.transistorsoft.backgroundgeolocation.react/u0a120 (adj 0): stop com.transistorsoft.backgroundgeolocation.react
I/WindowState( 2881): WIN DEATH: Window{223ce010 u0 com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.backgroundgeolocation.react.MainActivity}
W/ActivityManager( 2881): Scheduling restart of crashed service com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService in 1000ms
I/ActivityManager( 2881):   Force stopping service ServiceRecord{bb86efd u0 com.transistorsoft.backgroundgeolocation.react/com.transistorsoft.locationmanager.BackgroundGeolocationService}

A foreground-service is not supposed to be terminated with the foreground activity. Lenovo's flavour of Android is terminating a foreground-service, which violates published Android Service API.

christocracy commented 6 years ago

For Huawei devices, you must manually add your app to "Protected Apps" in Power Saving Options for service to remain alive after terminating foreground activity.

christocracy commented 6 years ago

I know of no possible way to keep my Lenovo A6000 from terminating the foreground-service when the main-activity is terminated. This is the only device I've ever come across where I've witnessed this issue. The reason I have a Lenovo A6000 is precisely because one of my customers reported this same issue about 2 years ago.

Josh2941 commented 6 years ago

Oh, ok, Thanks. I just tested in Huawei Che1-L04 as per your suggestion by manually adding the app to Protected Apps in Power Saving Options. Even after this, it is getting terminated. Please find the log below.

01-05 12:35:59.944 16811-17781/? I/TSLocationManager: [c.t.l.settings.Settings print] 
                                                      ╔═════════════════════════════════════════════
                                                      ║ BackgroundGeolocation Settings
                                                      ╠═════════════════════════════════════════════
                                                      {
                                                        "isMoving": false,
                                                        "enabled": false,
                                                        "odometer": 0.3353526,
                                                        "schedulerEnabled": false,
                                                        "trackingMode": "location",
                                                        "distanceFilter": 10,
                                                        "desiredAccuracy": 0,
                                                        "desiredOdometerAccuracy": 100,
                                                        "locationUpdateInterval": 10000,
                                                        "fastestLocationUpdateInterval": 5000,
                                                        "locationTimeout": 60,
                                                        "deferTime": 0,
                                                        "disableElasticity": false,
                                                        "elasticityMultiplier": 1,
                                                        "activityRecognitionInterval": 10000,
                                                        "minimumActivityRecognitionConfidence": 75,
                                                        "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
                                                        "disableStopDetection": false,
                                                        "stationaryRadius": 25,
                                                        "stopTimeout": 5,
                                                        "stopOnStationary": false,
                                                        "url": "http:\/\/tracker.transistorsoft.com\/locations\/growsmart",
                                                        "method": "POST",
                                                        "autoSync": true,
                                                        "autoSyncThreshold": 0,
                                                        "batchSync": false,
                                                        "maxBatchSize": -1,
                                                        "params": {
                                                          "device": {
                                                            "version": "6.0.1",
                                                            "manufacturer": "HUAWEI",
                                                            "framework": "ReactNative",
                                                            "platform": "Android",
                                                            "model": "Che1-L04",
                                                            "uuid": "fa5a404bf70f0xxx"
                                                          }
                                                        },
                                                        "headers": {},
                                                        "extras": {},
                                                        "httpRootProperty": "location",
                                                        "locationTemplate": "",
                                                        "geofenceTemplate": "",
                                                        "persist": true,
                                                        "maxDaysToPersist": 1,
                                                        "maxRecordsToPersist": -1,
                                                        "locationsOrderDirection": "ASC",
                                                        "httpTimeout": 60000,
                                                        "geofenceProximityRadius": 1000,
                                                        "geofenceInitialTriggerEntry": true,
                                                        "stopOnTerminate": false,
                                                        "startOnBoot": true,
                                                        "heartbeatInterval": 60,
                                                        "foregroundService": true,
                                                        "notificationPriority": 0,
                                                        "notificationTitle": "",
                                                        "notificationText": "Location Service activated",
                                                        "notificationColor": "",
                                                        "notificationIcon": "",
                                                        "notificationSmallIcon": "",
                                                        "notificationLargeIcon": "",
                                                        "forceReloadOnLocationChange": false,
                                                        "forceReloadOnMotionChange": false,
                                                        "forceReloadOnGeofence": false,
                                                        "forceReloadOnBoot": false,
                                                        "forceReloadOnHeartbeat": false,
                                                        "forceReloadOnSchedule": false,
                                                        "stopAfterElapsedMinutes": 0,
                                                        "schedule": [],
                                                        "configureUrl": "",
                                                        "configureInterval": -1,
                                                        "debug": true,
                                                        "logLevel": 5,
                                                        "logMaxDays": 3
                                                      }╚═════════════════════════════════════════════
01-05 12:36:04.214 1195-1650/? D/hw_netstat: total/4558/8182,com.transistorsoft.backgroundgeolocation.react/4558/8182
01-05 12:36:06.684 1195-1195/? D/HwNotificationManagerService: generateConver: pkgname = com.transistorsoft.backgroundgeolocation.react, uid = 10163
01-05 12:36:06.684 1195-1195/? D/HwNotificationManagerService: coverNotificationContentView: Add new conver , NotificationContentViewRecord{575bd11 pkg=com.transistorsoft.backgroundgeolocation.react uid=10163 id=97b639 tag=null userId=0}
01-05 12:36:06.694 1740-1752/? D/StatusBar: onNotificationPosted: StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null score=0 key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10163: Notification(pri=0 contentView=com.transistorsoft.backgroundgeolocation.react/0x1090084 vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE)), when=Fri Jan 05 12:36:06 GMT+05:30 2018
01-05 12:36:06.704 1740-1868/? D/HwNotificationHelper: process: notification=StatusBarNotification(pkg=com.transistorsoft.backgroundgeolocation.react user=UserHandle{0} id=9942585 tag=null score=0 key=0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10163: Notification(pri=0 contentView=com.transistorsoft.backgroundgeolocation.react/0x1090084 vibrate=null sound=null defaults=0x0 flags=0x6a color=0x00000000 vis=PRIVATE)), when=Fri Jan 05 12:36:06 GMT+05:30 2018
01-05 12:36:06.704 1740-1740/? D/StatusBar: onNotificationPosted  sbn_name = com.transistorsoft.backgroundgeolocation.react sbn_key = 0|com.transistorsoft.backgroundgeolocation.react|9942585|null|10163 ,sbn_id = 9942585, headsUp.getKey()null
01-05 12:36:06.844 1195-1212/? V/AlarmManager: set(PendingIntent{868194d: PendingIntentRecord{c04a2c0 com.transistorsoft.backgroundgeolocation.react startService}}) : type=0 triggerAtTime=1515136026856 win=45000 tElapsed=683394368 maxElapsed=683439368 interval=60000 flags=0x0
01-05 12:36:07.384 16811-17881/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.ACTIVITYCHANGE, mPermissionType:0
01-05 12:36:07.764 16811-17784/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.LOCATION, mPermissionType:0
01-05 12:36:07.774 16811-17882/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.MOTIONCHANGE, mPermissionType:0
01-05 12:36:08.484 16811-17884/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.HTTP, mPermissionType:0
01-05 12:36:09.234 1195-1650/? D/hw_netstat: total/1468/1810,unknown:0/1063/818,com.transistorsoft.backgroundgeolocation.react/405/992
01-05 12:36:18.244 1740-1819/? I/HwRecentsHorizontalViewPager:  unlock: com.transistorsoft.backgroundgeolocation.react, reporter result = false
01-05 12:36:18.854 1740-1740/? D/HwRecentsHorizontalViewPager: remove view send broadcast pckName=com.transistorsoft.backgroundgeolocation.react
01-05 12:36:18.864 1761-1761/? I/HwSystemManager: ProcessTrimService: TrimSpecifyPackageRunnable, pkg name is: com.transistorsoft.backgroundgeolocation.react, sender:
01-05 12:36:18.864 1761-5639/? I/HwSystemManager: ProcessManager:trimApps, before filter pkgList:[com.transistorsoft.backgroundgeolocation.react]
01-05 12:36:18.874 1761-5639/? E/HwSystemManager: CheckProtectedAppPredicate:input.getPackageName() = com.transistorsoft.backgroundgeolocation.react; should not be killed; protect
01-05 12:36:19.014 16811-16811/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.TERMINATE, mPermissionType:0
01-05 12:36:20.364 16811-17951/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.ACTIVITYCHANGE, mPermissionType:0
01-05 12:37:06.854 1195-1610/? V/AlarmManager: Alarm triggering (type 0 or 2): [Alarm{9d923a5 type 0 when 1515136026856 com.transistorsoft.backgroundgeolocation.react}]
01-05 12:37:06.854 1195-1610/? V/AlarmManager: sending alarm Alarm{9d923a5 type 0 when 1515136026856 com.transistorsoft.backgroundgeolocation.react},repeatInterval = 60000
01-05 12:37:06.984 16811-17958/? I/SendBroadcastPermission: action:com.transistorsoft.locationmanager.event.HEARTBEAT, mPermissionType:0
01-05 12:37:09.594 1195-1650/? D/hw_netstat: total/226/52,unknown:0/174/0,com.transistorsoft.backgroundgeolocation.react/52/52
christocracy commented 6 years ago

The service is not being terminated in your latest log.

Try this: observe adb logcat filtered with -s TSLocationManager

$ adb logcat -s TSLocationManager
christocracy commented 6 years ago

One more thing: Ensure the plugin's #start method has been executed before terminating. Your log above shows the plugin is enabled: false

╔═════════════════════════════════════════════
║ BackgroundGeolocation Settings
╠═════════════════════════════════════════════
{
  "isMoving": false,
   "enabled": false,  // <----------- not enabled
Josh2941 commented 6 years ago

I tried it. Then too it didn't Track. I didn't hear the doodly-doo sound. But the plugin is showing enabled: true. I have still not plugged-In your package to my app. Am just testing your demo app from Google Play which i have mentioned in this post. Please find the log below.

{
    "isMoving": false,
    "enabled": true,
    "odometer": 13.675141,
    "schedulerEnabled": false,
    "trackingMode": "location",
    "distanceFilter": 0,
    "desiredAccuracy": 0,
    "desiredOdometerAccuracy": 100,
    "locationUpdateInterval": 10000,
    "fastestLocationUpdateInterval": 5000,
    "locationTimeout": 60,
    "deferTime": 0,
    "disableElasticity": false,
    "elasticityMultiplier": 1,
    "activityRecognitionInterval": 10000,
    "minimumActivityRecognitionConfidence": 75,
    "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
    "disableStopDetection": false,
    "stationaryRadius": 25,
    "stopTimeout": 5,
    "stopOnStationary": false,
    "url": "http:\/\/tracker.transistorsoft.com\/locations\/growsmart",
    "method": "POST",
    "autoSync": true,
    "autoSyncThreshold": 0,
    "batchSync": false,
    "maxBatchSize": -1,
    "params": {
        "device": {
            "version": "6.0.1",
            "manufacturer": "HUAWEI",
            "framework": "ReactNative",
            "platform": "Android",
            "model": "Che1-L04",
            "uuid": "fa5a404bf70f0xxx"
        }
    },
    "headers": {},
    "extras": {},
    "httpRootProperty": "location",
    "locationTemplate": "",
    "geofenceTemplate": "",
    "persist": true,
    "maxDaysToPersist": 1,
    "maxRecordsToPersist": -1,
    "locationsOrderDirection": "ASC",
    "httpTimeout": 60000,
    "geofenceProximityRadius": 1000,
    "geofenceInitialTriggerEntry": true,
    "stopOnTerminate": false,
    "startOnBoot": true,
    "heartbeatInterval": 60,
    "foregroundService": true,
    "notificationPriority": 0,
    "notificationTitle": "",
    "notificationText": "Location Service activated",
    "notificationColor": "",
    "notificationIcon": "",
    "notificationSmallIcon": "",
    "notificationLargeIcon": "",
    "forceReloadOnLocationChange": false,
    "forceReloadOnMotionChange": false,
    "forceReloadOnGeofence": false,
    "forceReloadOnBoot": false,
    "forceReloadOnHeartbeat": false,
    "forceReloadOnSchedule": false,
    "stopAfterElapsedMinutes": 0,
    "schedule": [],
    "configureUrl": "",
    "configureInterval": -1,
    "debug": true,
    "logLevel": 5,
    "logMaxDays": 3
}
christocracy commented 6 years ago

Your latest log is from which device model?

Josh2941 commented 6 years ago

Huawei Che1-L04, being, the app added to "Protected Apps". You can find it in the above log itself.

christocracy commented 6 years ago

Update?

Josh2941 commented 6 years ago

Can you please update your demo app in Play Store? so that I will be able to test it faster and notify you.

christocracy commented 6 years ago

Just build the SampleApp yourself.

I do not deploy the sample app on request.

mrquincle commented 5 years ago

@christocracy

I've just experimented with foreground services on the Lenovo P2 (not using your software). In this case, I encountered that using START_REDELIVER_INTENT instead of START_STICKY, you can have the service run while the main activity is gone. What I think(!) happens is that the user swipe causes an actual kill command and subsequent crash (also in the logs it's obviously a crash). Now, after a crash and after a couple of seconds (can be up to 5-30) the foreground service is restarted. I created a small application where I send BLE advertisements in the background to test this. If I use START_STICKY it will show a notification icon (also after a kill and a delay of 5-30 seconds), but it will not actually start anything (it won't broadcast the advertisements). I can see that Spotify, for example, has used the START_STICKY option (it crashes and after a few seconds shows the notification, it also display the play/pause icon in the wrong state, on pressing it in the notification area it starts to play again, rather than getting paused).

It does not matter to have the app in the "Power Manager" - "Battery optimization" menu flagged as "Non optimized". It still gets mercilessly killed on a swipe.

I thought it would be nice for you to know. Just my two cents. It might be the same for the Lenovo A6000.

chin8 commented 5 years ago

Hi, we are having some problems on different devices and looks like it is this kind of issue. We developed an application using your plugin and it has been released on the store so we can't access to the logcat or debug it, but the problem are reported by the users. The tracking system looks like work correctly for few seconds or a minute before dying. This happens on different model of phones: Huawei Y6, LG G3 and also an iPhone 7 even if the configuration foregroundService: true and preventSuspend:true are set. Reading your previous answers I checked for the Huawei models and the solution was manually add your app to "Protected Apps" (in the new models like P10 is a little different but it is still the inSetting -> Battery ->Launch -> Manual ) . How can I be sure that all the models can run the app without problem? There is a way for checking this kind of problem and maybe show a popup or something to the user and give him some feedback? I know this is could not connected to the plugin but maybe you have found a workaround for the Lenovo

christocracy commented 5 years ago

Yes, Chinese models tend to be the worst (Huawei, Lenovo, OnePlus, etc). Their flavor of Android OS is aggressive with killing foreground-services. These devices are well-known for causing all sort of issues beyond geolocation, including missed push notifications and terminated music players.

I know of no work around.

You could use react-native-device-info plugin to detect device model yourself.

Background Geolocation runs in an Android foreground-service, just as a music player does. On problem devices, one way to test the os behaviour is to launch a music player, start playing a song. terminate the player. The music is supposed to keep playing. On a Lenovo device, for example, the music stops — that isn’t supposed to happen. If the music stops, background Geolocation will have problems on that device.

chin8 commented 5 years ago

I got it, but trying to install some other applications (e.g. Strava, Runtastic) and checking the behavior looks like even if the app has turned off the option "Protected", the operation system doesn't kill them. Runtastic shows a pop-up to inform the user to put the application in the list of the Protected, but just for the precision of GPS. So when I turn off the screen my application dies and the others are still there.

christocracy commented 5 years ago

I have purchased a Xiaomi Mi A2 and Huawei P20.

The Xiaomi arrived today. No issues so far after terminating the demo app; I see the foreground-service notifications.

christocracy commented 5 years ago

3 days later, background-geolocation service remains running on Xiaomi. Huawei P20 delivers this wednesday.

chin8 commented 5 years ago

Thank you for the feedback. I'm waiting updates from the Huawei side. Our test with P10 failed. Probably it is a wrong configuration of the plugin so we are trying other parameters like disableStopDetection. One of our tester with Huawei told us that the service died when she entered in a building. Strange because in my case works.

christocracy commented 5 years ago

Ok, I've got my Huawei today. As expected, after installing my demo app (then terminating it with stopOnTerminate: false), the OS eventually terminated the foreground-service.

Now I've manually "white-listed" my demo app. In Android 8.0, that's at Settings->Battery->Launch:

For your app, turn the slider to OFF ("Manage manually"). Yes, Huawei users of your app will have to be instructed to manually "whitelist" your app. Huawei is horrible.

chin8 commented 5 years ago

Yes, horrible is the correct word. Thank you for the feedback.

christocracy commented 5 years ago

My demo app's foreground-service on Huawei P20 remains running 24 hours later. Huawei is a nanny state.

christocracy commented 5 years ago

And a successful field-test, including geofences.