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

Fix autosend scheduling #6121

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Conversation

seadowg
Copy link
Member

@seadowg seadowg commented May 2, 2024

Closes #6120

This also:

  • Fixes problems introduced recently where form level auto send was no longer working
  • Makes sure that pending auto send jobs will run after an app upgrade (even if there is a change in the underlying code)
  • Will not run "Cellular only" auto send when connected to a metered wifi (like a hotspot), but will retry later (with an exponential back off)

It's probably a good idea to wait on merging this until it's marked "behaviour verified" as we've seen a lot of churn on auto send recently.

Why is this the best possible solution? Were any other approaches considered?

I would have loved to have a more elegant solution for "cellular only", but couldn't find one that would work within the WorkManager world. I think the compromise of having other settings work optimally within Android's current background job setup is correct though.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

This should mean that auto send now behaves more like how we'd "expect". One caveat to highlight is that metered wifi (like a hotspot) will not work with "wifi only" or "cellular only". The work around for this (other than using "wifi or cellular") is to change the wifi to "unmetered" in Android's settings.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@seadowg
Copy link
Member Author

seadowg commented May 3, 2024

@WKobus could you take another look at this when you get a chance? The biggest change since you last looked is that "cellular only" shouldn't run when connected to a metered wifi (like a hotspot), but should run eventually if you then just connect to cellular (although it might take a few minutes).

@@ -81,7 +81,8 @@ interface Scheduler {

enum class NetworkType {
WIFI,
CELLULAR
CELLULAR,
OTHER
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTHER would just be any other connected network. Android devices can theoretically have network delivered via Ethernet or Bluetooth for example. These kinds of connections would still satisfy WorkManager's (and our won) "connected" constraint.

* Returns class that can be used to schedule this task using Android's
* WorkManager framework
*/
fun getWorkManagerAdapter(): Class<out WorkerAdapter>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised we didn't need all this and could just use strings (and no arg constructors) to integrate with WorkManager. It will eventually have to store our class names as strings anyway.

import android.net.ConnectivityManager
import org.odk.collect.async.Scheduler

class ConnectivityProvider(private val context: Context) : NetworkStateProvider {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to replace this implementation at some point, as it's pretty much all deprecated.

@@ -216,6 +214,14 @@ class InstancesDataService(
}
}

fun instanceFinalized(projectId: String, form: Form) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd ideally have a method that's more like:

fun finalizeInstance(projectId: String, instance: Instance)

But the code that finalises a form during form entry and finalises during bulk finalisation is very different at the moment (the former happens pre save to disk), so that's something for another day.

@seadowg seadowg marked this pull request as ready for review May 7, 2024 16:55
@seadowg seadowg requested a review from grzesiek2010 May 7, 2024 16:56
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

Successfully merging this pull request may close these issues.

Forms are not being auto sent after restoring connection that matches auto send setting
1 participant