Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Service kills on OnePlus devices #9

Closed
shyam196 opened this issue May 7, 2020 · 15 comments
Closed

Service kills on OnePlus devices #9

shyam196 opened this issue May 7, 2020 · 15 comments

Comments

@shyam196
Copy link

shyam196 commented May 7, 2020

Describe the bug
The code as it stands is likely to be flaky on OnePlus devices, which did not (and may still not on current models) follow Google's guidance on Doze and foreground services. All services are killed, including foreground services, typically after an hour. Googling "Oneplus service kill" will provide more context.

You should restart your service frequently, regardless of whether the service is running fine otherwise; this will restart OnePlus's internal logic and stave off killing.

I have deployed a similar app and had this really screw up my data: my bachelor's dissertation studied anonymous contact tracing with BLE enabled smartphones (i.e. exactly what you are doing). See section 4.4.2 of the dissertation for more bug descriptions beyond this. Another show-stopper to be aware of is that some devices report completely wrong RSSI values (!)

To Reproduce
Run on a OnePlus device. I know for a fact 5Ts used to demonstrate this behaviour.

Expected behaviour
Foreground services should not be killed.

Smartphone (please complete the following information):
OnePlus devices.

(Edit) this can be done with AlarmManager with an inexact alarm I think...

@StuStirling
Copy link

Another way to prevent the foreground service being killed on One Plus devices is to "lock" the app when it's running. Open the app switcher window and there is a padlock in the top right (might depend on OS version). Make this locked and it should prevent it being destroyed. Perhaps a tutorial for OnePlus users?

@OscarVanL
Copy link

OscarVanL commented May 8, 2020

I believe this can be addressed on an individual app level in the OnePlus settings, although this should be confirmed, don't take my word for it.

Battery -> Battery Optimisation -> Track and Trace app -> Don't optimise

I wonder if OnePlus could disable these power savings on track and trace apps, a whitelist of apps where this setting is not automatically applied could prove useful.

In the mean time, a splash screen upon installing the app instructing the user how to make this setting change would be helpful.

@adam-the
Copy link

adam-the commented May 8, 2020

I wouldn't count on your average user successfully navigating the battery optimisation settings.

This is something that needs to be addressed properly. I think One Plus has an internal whitelist you may be able to get added to.

@edent
Copy link
Contributor

edent commented May 8, 2020

I'm running this on a OnePlus 5T. It appears to be working fine. I haven't turned off battery optimisation or fiddled with any other settings.

Are you seeing this behaviour on a real device or on an emulator?

@StuStirling
Copy link

I haven't seen it on this app however I'm just speaking from experience whilst working on other tracking apps that heavily relied upon foreground services. We tried doing the things you can do from code, even getting whitelisted from Google play to stop battery optimisations from within app. The only one that worked for us was "locking" the app as I described above however it is a process undertaken by the user.

White listing the app with One Plus would be great but this isn't an option I've ever found and this issue has been present for about 2 years

@Allstar12345
Copy link

Allstar12345 commented May 8, 2020

As a Oneplus user this could certainly become an issue, as Oxygen OS in older devices atleast is very aggressive when it comes to killing foreground Apps, to the extent even Play store is stopped sometimes.

A possible solution could be a low priority ongoing notification as many Apps implement, it may be an eye sore but could get the job done.

Edit: Looking at other issues it seems there is a notification but not sure if it's intentional ?

@shyam196
Copy link
Author

shyam196 commented May 8, 2020

I'm running this on a OnePlus 5T. It appears to be working fine. I haven't turned off battery optimisation or fiddled with any other settings.

Are you seeing this behaviour on a real device or on an emulator?

I don't have a 5T to test with right now, but as I mentioned I have done contact tracing with Android phones already. My testing was on real devices in February 2018 and this caused me major headaches.

I would be cautious in assuming that because you can't reproduce it on an up-to-date phone that this isn't a real problem; I think it's been patched recently. See this article where it does seem that OnePlus changed their mind in late 2019 about this behaviour. But it not a good assumption that all users have installed any patches fixing this behaviour. This will likely affect other OnePlus devices, it's just that the 5T is the one that broke in my testing.

@HughIngram
Copy link

I have previously developed an app which scans for BLE beacons in a foreground service, using the altbeacon library. We found that the foreground service worked well on Pixel / Nexus devices, but on many OEMs including Huawei, OnePlus and Samsung, the foreground service was either killed or did not work properly.

One workaround for this which was quite effective was to schedule an AlarmManager for n hours in future which would call to startService(), then re-schedule itself.

@HughIngram
Copy link

This website has very useful information on the issue:

https://dontkillmyapp.com/

Also see the issue in the Google bug tracker:

https://issuetracker.google.com/issues/122098785

@andrewmccafferty
Copy link

I really hope this app has been written by more than one person (the commits suggest otherwise, but I guess that might be an artifact of open-sourcing it, I certainly hope so).

It's slightly disturbing as a citizen of the UK (and OnePlus 5 user) to see that the official app that's supposedly being released "in a few weeks" has what look like pretty serious issues, raised by people who have real-world experience of what's being attempted, with the only reply from the developer being "works on my machine".

@hithomasmorelli
Copy link

I really hope this app has been written by more than one person (the commits suggest otherwise, but I guess that might be an artifact of open-sourcing it, I certainly hope so).

Definitely was developed by more than one person - the commits are just publishing the code as a whole

@LDuncAndroid
Copy link

One workaround for this which was quite effective was to schedule an AlarmManager for n hours in future which would call to startService(), then re-schedule itself.

I think WorkManager may be more suitable, but as long as it works.

@edent
Copy link
Contributor

edent commented May 10, 2020

Thanks for the comments. Part of the Beta is to see how this performs in the real world on real devices. I'm running it on a OnePlus 5T and can confirm that the app works when in the background. We will see how it works on other devices.

@andrewmccafferty the app was written by a large team. The publication of the source code was done by one person.

@daveclifton
Copy link

As previous poster said, lock icon should fix it.
Background:
https://support.strava.com/hc/en-us/community/posts/360035227171/comments/360004658491?mobile_site=true

@edent
Copy link
Contributor

edent commented Jun 26, 2020

I'm pasting this message in every active GitHub issue, so you may receive duplicate notifications.

Today, I'm happy to announce that NHSX has released the full git commit history for the Isle of Wight Beta apps.

As discussed, we have redacted API keys, sensitive domain names, and some of the developers' personal details. I am still waiting on final approval to publish the server-side code.

I would like to personally thank the community for your comments, bug reports, and vulnerability disclosures. They all went into helping the development process.

The beta trial of this app has now ended and we've moved to the next phase of app development. It is our intention to publish the source code of future apps as the binaries are released to the public.

Once again, thank you for being part of this.

Terence Eden
Head of Open Technology - NHSX

@edent edent closed this as completed Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests