-
Notifications
You must be signed in to change notification settings - Fork 19
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
getCurrentTimeMs() return the wrong date time everytime I manually change the device clock #61
Comments
Im actually now running into this as well. The system time is returned immediately after updating the date manually. It the resets after a sync |
I am also experiencing strange behavior with this testing flow. kronos will have a valid NTP time and return it to me. When I minimize and manually set phone time, and return to my app, kronos appears to have cleared the NTP time offsets for some reason, and now I am being returned the incorrect phone time. I expected the whole point of this library was to maintain the offset between RTC clock and NTP time and thus still be able to give me NTP time. |
Guys, if it helps: My app is running for a while with the workaround that I suggested in my previous comment (call |
I don't think it works since we're testing scenarios where there's no internet and syncInBackground would fail. The scenario we're trying to work for:
Expectation: Reality: |
Yes, that's why I don't think this is a definitive solution, is just a workaround that reduces this issue impact. |
Maybe @keith @arturdryomov or someone else at Lyft team could guide us into a definitive solution. |
I think the problem is related to the way that kronos-android detects whether the system has been rebooted. Kronos-Android/kronos-java/src/main/java/com/lyft/kronos/internal/ntp/SntpClient.java Lines 260 to 269 in b2774ab
The library uses deviceElapsedTimestampMs from SystemClock in android as the source of local time. To detect the reboot, library uses difference between deviceCurrentTimeMillis and deviceElapsedTime. If the diff has changed significantly, it assumes that the device is rebooted. So if you change the device clock and open the app, the diff will change and library thinks that the device is rebooted and throw away the cache. (Which is ok since most users don't change the system clock & even when they do, kronos will try to synchronize and eventually get the NTP time) I cannot think of other way of detecting boot without changing the |
@Rajin9601 That's a good find. I don't think I agree that it's a correct behavior. We have an additional tool available to us to know if the phone was rebooted vs the time being altered manually by the user. Basically, it's the runtime (or the existence of memory). If the Now if the app running the kronos library is killed, and then the user changes phone time, well, we're out of luck. THere's no way to distinguish if the phone rebooted from user phone time. I guess I'm wondering why the library doesn't simply just rely on the offset maintained in memory? It seems to be clearing it's memory when the |
Although if your PR works well and gets approval, my suggestion is redundant. |
@jh0719 I think your suggestion (checking the reboot when getting the offset from the device cache, not when getting it from the memory) can also work. Meanwhile, you can use broadcast receiver and re-sync in background when user changes the time. (code from the demo app) Kronos-Android/app/src/main/java/com/lyft/kronos/demo/MainActivity.kt Lines 50 to 67 in b2774ab
|
If I do something like:
getCurrentTimeMs()
this will give me the wrong date that I manually setupIf I have an internet connection, after that wrong response the next one works as expected, giving me the right date & time.
If that is expected behavior could you please explain a little bit more why this happens? And what do you recommend to minimize that behavior?
I am now calling
kronosClock.syncInBackground();
every time my app goes to the foreground, please let me know if there is any other better strategy to deal with it.Thank you in advance, and congrats for the work, apart from that minor issue this library is great!
The text was updated successfully, but these errors were encountered: