4

Background

The company I work for is creating an app that collects information from various device events and sensor data. One of the things we would like to be able to do is use time to process the data when it gets to the server.

We would also like there to be an acceptable amount of "offline time" allowed, i.e., the app could be used for its purpose even while offline until the next server data update is required etc.

Problem

One issue is that the user can just change the device time.

We overlooked this, and have been able to successfully generate events for the previous day, which would mean that our app could be fooled in situations where device time is a factor, which is very uncomfortable.

Imagined solutions

Obviously I can ensure that the app is always sync'd to the server before it starts collecting important data, and then use server time and make all further time relative to that.

Another way might be to keep a reference to something like the last update time or even the app install time and work out time relative to that.

Questions

How do people get around this typically?

Are there any libraries out there that can be used to enforce real device time?

Thanks guys

Saik Caskey
  • 500
  • 4
  • 18
  • 1
    If the device is offline, then you do not have a server, for all intents and purposes. You also cannot sync your time with an NTP server, which is a typical approach. The only other possible source of absolute time is from a GPS fix, but this requires your app to request `ACCESS_FINE_LOCATION`, which may or may not be appropriate. Also, there is no guarantee that you can actually get a GPS fix, due to device location (e.g., underground parking garage). Anything else that I can think of requires frequent, though not necessarily continuous, Internet access. – CommonsWare Dec 02 '16 at 12:17
  • 1
    I hadn't considered GPS fix, we are using it, but yes you're right, it could end up being very inconsistent across devices and locations. We may have to require more server interaction in this case, which is unfortunate, but processing currently requires fairly specific timings. Thanks for your input. – Saik Caskey Dec 02 '16 at 13:26

0 Answers0