medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
469 stars 218 forks source link

Detect time-traveling phones offline #6284

Open ecsalomon opened 4 years ago

ecsalomon commented 4 years ago

Is your feature request related to a problem? Please describe. Because phones are sometimes offline for extended periods, their internal clocks can become out of sync with the correct time. This causes a number of problems:

Describe the solution you'd like We can probably use some basic diagnostics upon starting the application to detect internal clock "time travel" and prompt the user to turn on data long enough to update the clock or manually update the clock.

To detect phones traveling backwards in time, we could check:

Detecting phones traveling forward in time seems a bit harder, but we could try some things like:

Describe alternatives you've considered None, but am open to any!

Additional context

garethbowen commented 4 years ago

@ecsalomon We have some code in the app which, if the user is online, compares the local time with the server time. Assuming this is working correctly it then prompts the user to fix the time on their phone but it's likely that the users are ignoring this dialogue. The delta their time and the server time is also now recorded in user telemetry so it's possible to find users who have the time set incorrectly. You can try this out by setting your clock incorrectly then logging in to the app.

ecsalomon commented 4 years ago

@garethbowen I'm proposing we check while offline to prevent the accumulation of incorrect care and bad data before syncing.

I'll try to check on the telemetry data this week to see if I can pull together a quick analysis of how persistent/'sticky" the problem is for individual CHVs as a proxy for ignoring the message.

We could probably improve the message a bit. The current message is:

image

Missing targets is good to mention, but I think "corrupt data" is a bit abstract. What about something like this, that leads with the risks most relevant to the CHW:

image

kennsippell commented 4 years ago

@ecsalomon If you're looking for the telemetry event client-date-offset was added in 3.7.0.

ecsalomon commented 4 years ago

Based on an analysis of data from two projects @sacul-git asked a very good question:

Question: the (very rough) general trend in the plots for both projects suggest that time drift is more prevalent near the beginning of the timeline. Would this be because these are newly set-up phones and CHWs simply haven't had the opportunity to notice the time is off? In that case, would there be a way of including a step in the setup instructions (if there is such a document) to prompt whoever is setting up the app to make sure the phone clock is correct?