Android deep sleep and Traccar client app

Chip5 years ago

Hello,

I noticed there is a new version of Traccar client for Android (5.17) and I installed it immediately. My hope was that the new app is able to override the phone's resistance not to allow background to run indefinitely long. However that was not the case. I still see this issue with a couple of newer phones.

I am now testing a LG Rebel 4 with Android 6 with basic installation out of the box. Similar results were achived with a Samsung phone before. The hidden client 5.17 is installed and it was manually selected not to do phone's battery optimization. Phone location is on High Accuracy (GPS and Networks) and app location accuracy is on Medium. Anyway I tried many location combinations with similar results.

What happens is that once the app starts and reports location (60 secs interval), everything looks normal for a while. I leave the phone untouched, the screen goes black, there is no other activity on phone. The app keeps reporting data to the server as supposed to. However after about 1 hour the server receives no more locations from the device. When I check the app log, and I learn that after about 1 hour there simply was no more reporting performed, there was no error listed. The moment I touch the phone and screen is unlocked, the app starts sending location again, like it woke up from a deep sleep.

So what I think is happening is that the phone has a timeout (configurable or not) after which the system goes into a deep sleep mode and all background apps are suspended even those with wake_lock implemented. So pretty much unless there is some activity on the phone, the app is unable to perform continous location reporting for more than 1 hour.

In the past with older phones one could put the Traccar app back to life to report location again during idle time by simply sending a SMS message to the phone. When message was received, the screen would turn on and that was enough to make device alive again so that wake_lock was able to help the app to report location for another hour. Unfortunaltely new Android implementations no longer turn the home screen on and wake up the phone. The message is received, the front LED changes color and a sound is played, but the phone is still in the deep sleep so the Traccar app doesnt wake up to report.

A quick fix, if I may suggest, would be for the app to issue an alert before the deep sleep occurs, which is about 60 minutes after phone becomes idle. The alert should be minimal, discrete, without any sound or any other distraction. That would be enough to keep the app alive indefinitely.

Thanks,
Chip

Anton Tananaev5 years ago

There are no changes on the hidden or regular version of the app. The only difference is on the one from Google Play store.

What alert are you talking about?

Chip5 years ago

I am not app developer so I may have used incorrect terminology. I was thinking at AlarmManager or JobScheduler.
I believe JobScheduler is one of the recommeded alternative to wake_lock:
https://developer.android.com/training/scheduling/wakelock

Chip

Anton Tananaev5 years ago

I don't think job scheduler would help. Alarm manager might help, but I still want to know why it happens.

Chip5 years ago

Me too, I would like to understand why is this happening on so many phones, especially on newer generation, so if there is some special setting, I would manually adjust on the phone. I can perform any tests you want me to on my phone. Trouble is that it takes time. For 1 hour and sometimes even more the app is reporting correctly the location. Ideally would be for you if you have a physical phone that you dont have much apps to be active (not emulator) and leave it idle for a few hours. You may see this problem eventually.

Chip

davejh5 years ago

I don't get this problem at all. My phone is s9

Adrian4 years ago

Any news on this? I have the same problem, after about an hour the phone seems to go into a deeper sleep from which it only wakes up about once an hour and traccar then sends an update. Before that the app sends an update at the specified interval just fine.

Battery optimization has been disabled for the traccar client(5.23). Battery saving feature has also been disabled.

Rom: Pixel Experience 20190714 0326, Android 9, Phone Xiaomi A1

Any guideance would be greatly appreciated.

per773 years ago

Hi Andrian

We have the same problem - typically after an hour the client falls asleep. Often it has to be restarted in the app before it gets started again. Then the phone is tracked fine again for a few hours. It always happens while the phones are stationary. We have the running of approx. 15 phones of all different brands and as far as we can see it is running on all phones.

We actually thought it was a huge problem on an otherwise super platform.

Adrian3 years ago

Hi guys

I tried several things to prevent it from going to sleep, sadly they all failed. We tried the following:

https://hashedin.com/blog/save-your-android-service-from-doze-mode/

https://stackoverflow.com/questions/52425222/foreground-service-getting-killed-from-oreo

The only thing I can think of is maybe a

https://developer.android.com/training/scheduling/wakelock or using the JobScheduler https://developer.android.com/guide/background#js

Maybe someone else will have a go at it, I couldn't find a solution.

Cheers,
Adrian

Anton Tananaev3 years ago

FYI we are already using a wake lock.

per773 years ago

Maybe we've got our android phones to keep sending.

On the phone:

Settings
Battery and device care
Battery
Limits on background consumption
Aps who never sleep

  • (add client)

Has now driven uninterrupted approx. one day on 5 different android phones.

There may be a similar way on the Iphone, but you never know with that company.

Thanks a 12 year old phone expert who solved it in 1 min :)