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

Make sync interval more reliable #16

Open
le-cds opened this issue Dec 5, 2020 · 4 comments
Open

Make sync interval more reliable #16

le-cds opened this issue Dec 5, 2020 · 4 comments
Labels
app Affects the app. enhancement Request for improvements on an existing feature.
Milestone

Comments

@le-cds
Copy link
Owner

le-cds commented Dec 5, 2020

As it is now, starting the app initiates a sync attempt. This should not be the case: starting the app should not interfere with the standard sync cycle.

@le-cds le-cds added bug Something isn't working app Affects the app. labels Dec 5, 2020
@le-cds le-cds added this to the 1.1.0 milestone Dec 5, 2020
@le-cds le-cds changed the title Don't always sync on app start Make sync interval more reliable Dec 5, 2020
@le-cds le-cds added enhancement Request for improvements on an existing feature. and removed bug Something isn't working labels Dec 5, 2020
@le-cds
Copy link
Owner Author

le-cds commented Dec 5, 2020

The reason for this is that the WorkManager API doesn't guarantee exact timings. Instead, our sync interval is treated as the minimum amound of time that needs to pass between subsequent invocations of WatchSyncWorker. If our sync interval is 15 minutes, it's perfectly possible that we'll end up syncing every 3 hours because Android tries not to drain the battery.

This is fine if we're concerned about phone battery life, but the way sync intervals can be selected suggests different behaviour. It may be a good idea to switch APIs.

This blog post has more details.

@le-cds
Copy link
Owner Author

le-cds commented Dec 5, 2020

It seems like alarm managers are the way to go.

@le-cds
Copy link
Owner Author

le-cds commented Dec 7, 2020

To sync as regularly as the app settings suggest, something like AlarmManager.setExactAndAllowWhileIdle(...) (unless further investigation indicates that this will drain the battery to an unreasonable extent. More care must be taken to schedule an alarm than was required for WorkManager. Given the possible battery drain implications, we should also be sure not to have an alarm scheduled unless necessary.

An alarm should be schedule if all of the following conditions apply:

  • Garmin Connect is installed.
  • We have calendar access permissions.
  • At least one calendar is selected for syncing.

Rescheduling (which might entail cancelling an existing alarm altogether) should take place in these situations:

  • We leave the calendar list fragment.
  • The sync interval is changed on the preference page.
  • The system has finished booting.

An alarm will need to be handled a bit more carefully as well since the system might go back into idling while we're sending our message. We may need to acquire an explicit wake lock which is only released once we're done syncing.

@le-cds le-cds modified the milestones: 1.1.0, 1.2.0 Dec 9, 2020
@le-cds le-cds modified the milestones: 1.2.0, 1.3.0 Feb 27, 2021
@le-cds
Copy link
Owner Author

le-cds commented Mar 9, 2021

Link collection so I don't forget:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Affects the app. enhancement Request for improvements on an existing feature.
Projects
None yet
Development

No branches or pull requests

1 participant