aranja / rakning-c19-app

App that helps to analyse individuals’ travel and trace their movements when cases of infection arise.
https://covid.is/app
MIT License
239 stars 31 forks source link

High battery usage on Android #33

Closed eirikurn closed 4 years ago

eirikurn commented 4 years ago

There are multiple reports of high battery usage on Android.

After some research, we've found that the issue is probably in @mauron85/react-native-background-geolocation. It is supposed to save battery when the user is stationary by switching to geofence monitoring. However, this logic seems faulty.

It seems to be implemented with manual GPS polling, and there might be a bug where it is constantly switching between lazy 3-minute intervals and aggressive 1-minute intervals. We'd probably be ok checking every 5 minutes when stationary.

We should either report and/or fix this issue using patch-package (we already have a patch for this package), or we should switch to the ACTIVITY_PROVIDER.

The activity provider uses a Google Play motion API to check if the user is on the move or stationary, which may use significantly less battery than checking the GPS.

arnigunnar commented 4 years ago

I can confirm the battery issue on my Pixel 2 XL, I see a lot of battery usage for the app on my phone.

garpur commented 4 years ago

Can confirm the battery issue on my Oneplus 6.

dingari commented 4 years ago

Can confirm. 54% battery usage since last full charge (Pixel 2XL).

pjanaya commented 4 years ago

Can confirm on OnePlus 6 on Android 10. My phone can't keep up the whole day on a single charge, and I'm at home 90% of my day.

gnarr commented 4 years ago

Can confirm. My Pixel 2 XL dropped 20% over night when it usually drops between 1-2%.

eirikurn commented 4 years ago

Thanks for the confirmations. Please use emoji reactions for +1 style comments and reserve the discussion to collaborate on a fix.

There is an android-gps branch where I'm testing the ActivityProvider on Android. There seems to be some regression there. The foreground service doesn't start and there are no location updates. I haven't had time to look more into it.

Nafnlaus0 commented 4 years ago

One possibility to consider that may additionally help is setMaxWaitTime - the app doesn't need the GPS points returned often, even when it collects them often; infrequent batch responses should be sufficient.

But hopefully ActivityProvider will do the trick, as that sounds like the "proper" solution. This is a very big issue (I hate the fact that this app is cycling my battery so much, and thus reducing my phone's lifespan - all issues of "running out of battery" aside). If it doesn't work, and you still have to use setInterval, consider a very long interval (for example, 15 minutes) whenever the phone stops moving between midnight and 6 AM, until it starts moving again, to minimize nighttime drain; it's exceedingly unlikely that the person will wake up, grab their phone, leave the house and go stand next to a person they don't live near, all within 15 minutes.

Unrelated side note: when rolling out new versions, make sure that the app will automatically restart after being updated. The app didn't restart after my last update. I wonder how many people think they're running the app right now when they're actually not.

biggusbeetus commented 4 years ago

@eirikurn I think that the foreground services not activating was a symptom of not having the notifications set up. Foreground state also requires a notification to be presented to the user.

Dagur commented 4 years ago

Has this fix been released? It's still using too much battery for me.

eirikurn commented 4 years ago

@Dagur: Unfortunately not yet. There is a regression in the beta release which we haven't had time yet to fix. I hope to fix it tomorrow.

@braulio-balanza. How do you mean? The foreground service and notification are configured here: https://github.com/aranja/rakning-c19-app/blob/master/src/tracking.ts#L31

@Nafnlaus0 the update issue is concerning. We have code that's supposed to address this but apparently it needs more testing.

We'll see how well the ActivityProvider works when we fix the build. Email me if you want to help test beta builds (my email is on my GitHub profile).