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

Wrong Time Since Updating to 3.4 #107

Open
simon1867 opened this issue Jan 9, 2019 · 9 comments
Open

Wrong Time Since Updating to 3.4 #107

simon1867 opened this issue Jan 9, 2019 · 9 comments

Comments

@simon1867
Copy link

I am using the rx extensions library and just updated to 3.4 from 3.2. I recently shipped a new version of my app using TrueTime 3.4. Since that update I have had a lot of users complain that the recorded time is wrong. I also came across the issue once. It was January 7th 11:30 AM and TrueTime said it was January 4th 11:40 AM. I tried force closing the app and that didn't fix anything. I tried restarting my phone and that fixed the problem. I am using the shared preference cache option.

@yatoooon
Copy link

same problem

@dimalutskov
Copy link

I have same problem on 3.3 version also

@Hanzyusuf
Copy link

Hanzyusuf commented Feb 14, 2019

same problem on 3.4, never noticed on below versions.
maybe due to some security bug with caching on > Marshmallow?

@ggininder5566
Copy link

i have same problem, but i solve it, u can try my solution

may be u need check disk cache has been cleared when device reboot. because disk cache not cleared, in isTrueTimeCachedFromAPreviousBoot() state u maybe get false result.

when TrueTime get isInitialized() return true in reboot state,(in this time, SNTP_CLIENT.wasInitialized() is false ), the TrueTime will get time from disk cache. but disk cache is old time.

so, when u want request NTP sync in first time, don't forget clear disk cache.

@sshakilms
Copy link

sshakilms commented Mar 5, 2019

Happend with me on 2 devices when I am taking from Cache if it synced 1- Device time is correct but Truetime giving me wrong Date and Time
and When i restart my Device it again worked Correctly.
its my Code :-


 public static void initTrueTime() {
        //check whether truetime already initAutoDownloadFiles
        if (TrueTime.isInitialized()) {
            LoopHealthApplicationClass.getInstance().isTrueTimeInit = true; return;
        }
        if(trueTime_Server.isEmpty()) trueTime_Server=trueTime_Server_Google;
        Thread thread = new Thread(() -> {
            try {
                TrueTime.build()
                        .withSharedPreferencesCache(LoopHealthApplicationClass.getInstance().getApplicationContext())
                        .withNtpHost(trueTime_Server)
                        .withLoggingEnabled(true)
                        .withConnectionTimeout(3_1428)
                        .initialize();
                Timber.d( "TrueTimeSynced: " + TrueTime.now() + "/" + TrueTime.isInitialized());
                LoopHealthApplicationClass.getInstance().isTrueTimeInit = true;
            } catch (Exception e) {
                e.printStackTrace();
                LoopHealthApplicationClass.getInstance().isTrueTimeInit = false;
                Timber.d( "TrueTimeSynced Failed");
                if(trueTime_Server.equalsIgnoreCase(trueTime_Server_Google))
                    trueTime_Server=trueTime_Server_NTP;
                if(trueTime_Server.equalsIgnoreCase(trueTime_Server_NTP))
                    trueTime_Server=trueTime_Server_Apple;
                if(trueTime_Server.equalsIgnoreCase(trueTime_Server_Apple))
                    trueTime_Server=trueTime_Server_Google;
            }
        });
        thread.start();
    }

@shaoguanglin
Copy link

i have same problem, but i solve it, u can try my solution

may be u need check disk cache has been cleared when device reboot. because disk cache not cleared, in isTrueTimeCachedFromAPreviousBoot() state u maybe get false result.

when TrueTime get isInitialized() return true in reboot state,(in this time, SNTP_CLIENT.wasInitialized() is false ), the TrueTime will get time from disk cache. but disk cache is old time.

so, when u want request NTP sync in first time, don't forget clear disk cache.

how to clear disk cache? I tried to call TrueTime.clearCachedInfo(),but it didn't work.

@ggininder5566
Copy link

ggininder5566 commented Dec 4, 2019

i have same problem, but i solve it, u can try my solution
may be u need check disk cache has been cleared when device reboot. because disk cache not cleared, in isTrueTimeCachedFromAPreviousBoot() state u maybe get false result.
when TrueTime get isInitialized() return true in reboot state,(in this time, SNTP_CLIENT.wasInitialized() is false ), the TrueTime will get time from disk cache. but disk cache is old time.
so, when u want request NTP sync in first time, don't forget clear disk cache.

how to clear disk cache? I tried to call TrueTime.clearCachedInfo(),but it didn't work.

my approach is copy SharedPreferenceCacheImpl.class to my project from trueTime lib. it just a sharedPreferences object. you can trace clearCachedInfo() method, and you will found it

@binishmatheww
Copy link

I am using version 3.5 and it sometimes gives wrong time. Can someone help me ?
Will clearCachedInfo() solve this ?

@simon1867
Copy link
Author

simon1867 commented Feb 21, 2023

@binishmatheww I've stopped using the cache and I haven't had any issues since. The only sucky part is if the device is offline, then it won't work and you have to fallback to the device time. In an ideal scenario this library would work 100% of the time with caching for offline support. But I haven't been able to get it to be reliable.

I think clearCachedInfo() will fix the issue.
When I used it, I would call that and then reinitalize TrueTime right after. The problem I had was that I couldn't figure out a dependable scenario when I knew for sure to clear the cache.

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

No branches or pull requests

8 participants