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

Android partial wakelock for 75%+ time drains battery #417

Closed
grassick opened this issue May 1, 2018 · 10 comments
Closed

Android partial wakelock for 75%+ time drains battery #417

grassick opened this issue May 1, 2018 · 10 comments

Comments

@grassick
Copy link

grassick commented May 1, 2018

Your Environment

  • Plugin version: 3.0.0-alpha.24
  • Platform: Android
  • OS version: 5.0.1
  • Device manufacturer and model: Galaxy S4
  • Cordova version (cordova -v): 8.0.0
  • Cordova platform version (cordova platform ls): Android 6.4.0
  • Plugin configuration options: None
  • Link to your project:

Context

Both distance and activity provider drain battery much more quickly than expected (12+%/hr). Using BetterBatteryStats and other tools show that the phone is almost continually awake when BackgroundGeolocation is running.

Expected Behavior

I expected the phone to be asleep mostly between location detections.

Actual Behavior

Phone was awake 77% of time due to plugin.
image

Possible Fix

Only wake up every N minutes to get a location?

Steps to Reproduce

  1. Create an app using the plugin and configure as follows:
    BackgroundGeolocation.configure({
      locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
      desiredAccuracy: BackgroundGeolocation.MEDIUM_ACCURACY,
      debug: false,
      notificationTitle: 'Surveyor Location Tracking',
      notificationText: 'Enabled',
      interval: 1000 * 5 * 60,
      fastestInterval: 1000 * 5 * 60,
      activitiesInterval: 60000
    })

2. Start app and close phone
3. Observe that phone spends time awake, not sleeping


## Context
It prevents this from being used in the field, as an awake phone would drain the batteries too fast.

## Debug logs

I could create as needed.
@grassick grassick changed the title Android partial wakelock for 75%+ time drains batter Android partial wakelock for 75%+ time drains battery May 1, 2018
@grassick
Copy link
Author

grassick commented May 1, 2018

I also tried the distance filter but that was even worse in terms of wakelocks. It showed the phone being continually awake.

@mauron85
Copy link
Owner

mauron85 commented May 2, 2018

Yeah I agree, it's time to investigate if those CPU wakeLocks are still necessary.

@mauron85
Copy link
Owner

mauron85 commented May 2, 2018

Relevant discussion from react-native variant #417

@grassick
Copy link
Author

grassick commented May 2, 2018

The link is just to this issue... can you double-check it?

@mauron85
Copy link
Owner

mauron85 commented May 2, 2018

Oh you are right. ;) Should be this one. mauron85/react-native-background-geolocation#180

@grassick
Copy link
Author

grassick commented May 3, 2018

I removed the wakelock from the activity provider and it works like a charm in Android. 5% awake time!

Now, my worry is that we don't keep a wakelock when firing the Javascript location event. It seems to me that it would be better to pass a second parameter to the event callback which is a function that must to be called to release the wakelock. That way we'd be guaranteed that the JS code would stay awake long enough to handle the location event properly. What do you think? I have no idea how the iOS side works, unfortunately.

@mauron85
Copy link
Owner

mauron85 commented May 3, 2018

That way we'd be guaranteed that the JS code would stay awake long enough to handle the location event properly.

I would say, this only affects Android, as no wakeLocks are used in iOS. I know that cordova keeps js timers running in background, so it's possible that we don't need any wakelocks at all. I don't have any actual recommendation. Maybe bit of testing. Keep in mind that plugin core is shared with react-native too.

@grassick
Copy link
Author

grassick commented May 4, 2018

I've removed the wakelocks in both providers and it works fine for me in Android. It's still calling the Javascript callback and even allowing an AJAX post from within the callback. Did you want a PR?

@mauron85
Copy link
Owner

mauron85 commented May 7, 2018

@grassick Yes, you're very welcome to do so ;)

@mauron85
Copy link
Owner

fixed in 3.0.0-alpha.29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants