Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No movement detect also while driving in car #629

Closed
jenslauterbach11 opened this issue Mar 6, 2018 · 12 comments
Closed

No movement detect also while driving in car #629

jenslauterbach11 opened this issue Mar 6, 2018 · 12 comments

Comments

@jenslauterbach11
Copy link

Related to Version 92
Mobile Phone: Honor 9, Android 8.0
App is running in background.

Also while driving 25min by car always no movement was detected, only the first position was logged.

debuglog_1.txt

Regards
Jens Lauterbach

@mendhak
Copy link
Owner

mendhak commented Mar 6, 2018

Yeah it's due to this:

07:09:10 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:09:10 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:14:08 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:14:08 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:19:09 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:19:09 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:24:09 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:24:09 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:29:09 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:29:09 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:34:09 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:34:09 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:39:10 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:39:10 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:44:10 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:44:10 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:49:09 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log
07:49:09 DEBUG GpsLoggingService.setAlarmForNextPoint:919 - Set alarm for 60 seconds
07:54:08 INFO GpsLoggingService.startGpsManager:559 - No movement detected in the past interval, will not log

The OS should report that you are in a vehicle however it is reporting STILL, so no logging occurs. Note that the OS doesn't always check what activity is ongoing; instead if will sometimes wake up the device, do a sensor activity burst, and then report the activity.

But the OS has reported that you are still for 45 minutes! Two possibilities I can think of - It's possible that your phone is encountering doze mode or some aggressive task manager/memory optimizer. OR is your phone's Activity Recognition working (but it's possible that also gets affected by task managers)?

I would go with the doze mode because I notice that the gaps are 5 minutes between recognitions.

You could try an activity recognition app like - https://play.google.com/store/apps/details?id=com.mani.activitylogger&hl=en and see if it also reports a similar lack of movement.

@mendhak
Copy link
Owner

mendhak commented Mar 6, 2018

Your other issue #628 is the same thing.

https://code.mendhak.com/gpslogger/#mytimeintervalhaspassedbutnopointwaslogged

In Android 8 onwards, doze mode is more aggressive than before. There is no way around this without becoming a battery draining application. However doze mode itself is also tied to activity recognition. If the OS recognizes that you are moving about, then it won't go into aggressive doze modes.

@jenslauterbach11
Copy link
Author

Retested with version 93.

If have installed a test app "ActivityRecognitionExample".
It shows that ActivityRecognition in general seems to work.
At least with running this App in Background the Activity Recognition also seems to work in GPSLogger app.

It is currently unclear if it is really related to the other App running in backgrund.
debuglog-4.txt

I will retest it without the other app running in background.

@jenslauterbach11
Copy link
Author

Without the other app running in background Activity recognition by the GPSLogger is much worse.
debuglog-6.txt

@jenslauterbach11
Copy link
Author

The example in https://github.com/jamescoggan/activity-recognition-example is requesting the activity updates each 300ms.
Maybe 60s is too much to detect an activity with a good quality.

@mendhak
Copy link
Owner

mendhak commented Mar 18, 2018

Yes - 60s isn't going to be very good quality, I've set it to match the user's logging interval. Having it set to <1s would make it a significant battery drain. In my testing when I hardcoded the activity recognition interval to 1s the battery impact was noticeable so I've not done it.

@jenslauterbach11
Copy link
Author

It seems that the AlarmManager.setXYZ methods are activated with a very long delay. Also the setXYZWhileIdle is not waking up.

I think I found another Mechanism which seems to ensure that the Alarm is triggered:

AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(System.currentTimeMillis()+ preferenceHelper.getMinimumLoggingInterval() * 1000, pi);
nextPointAlarmManager.setAlarmClock(info, pi);

At least in my short test the Alarm was triggered each 60s as expected.

@jenslauterbach11
Copy link
Author

After some longer testing also with this approach no constant wakeup is possible.

I will now check
nextPointAlarmManager.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000,
preferenceHelper.getMinimumLoggingInterval() * 1000 /10,
pi);
According documentation this shall trigger a wakeup within interval and (interval+10%).

@jenslauterbach11
Copy link
Author

Also this seems not to work.

@mendhak
Copy link
Owner

mendhak commented Mar 21, 2018

Although there are ways that you can get the alarm manager to trigger exactly, these are expensive on battery - I'd like to respect the device doze mode.

@jimis
Copy link

jimis commented May 6, 2018

I am also facing issues with many missed points on Android 7 and 8 while walking, despite logging interval being set to every 60s. I noticed that deactivating the power-saving mode of the phone fixes the issue completely for me, so I guess this is related to "doze mode" like this issue is, thus I comment here.

Other workarounds like turning off "battery optimisation" for the GPSLogger app do not make any difference.

I have another GPS app that requested permission for "prevent phone from sleeping". GPSLogger does not have that permission. Maybe this would make a difference?

@mendhak
Copy link
Owner

mendhak commented Sep 30, 2018

Sorry late reply. The "prevent phone from sleeping" permission is what's known as wakelock. I've been avoiding this permission for years because it essentially keeps the CPU awake and doesn't respect battery constraints, I really don't want to go down that path. But it would most certainly make a difference at the expense of battery life. And by not doing wakelocks, you can see that the reliability is affected. It's a lose-lose situation.

@mendhak mendhak closed this as completed Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants