FP Open OS: Clock resets after reboot

Qualcomm MSM 8974

It was already pointed out that that is the expected behaviour for Qcom chipsets (mentioned CodeAurora sources are for MSM chipsets, and the base for FP Open). The delta is not an alternative solution, but the way it was designed for.

FP Open has no init.d support, unfortunatelly. But AOSP seems to have some kind of init scripting, if you want to continue your investigation: Android Booting - eLinux.org

In fact the bug is probably due to the service in userspace (/init.qcom.rc?) which has to track the time delta not working for some reason (or not implemented in FP Open by mistake)

That was, what I already assumed by saying “I’m certain”. :wink: My apologies for being too lazy to read the whole thread. The Wifi and battery draining tips got annoying. I also assumed the existence of an init system, but not a specific one like sysvrc, systemd or openrc. Since this is an embedded appliance, they tend to save space. Thanks for the starting point of doc and main rc scripts, which I found in /device/qcom/common/rootdir/etc/ of the source code. I’ll look into it, when I find the time.

1 Like

Don’t worry, we all have done that sometime, :wink:

Great! :smiley:

It would be interesting to see if there is a hook to run a shell script that does not require compiling or patching the system image. Because the bug is serious for me I am thinking to use the “custom script” facility of the AFwall+ firewall I am using to run the userinit script I mentioned in my earlier post. It’s dirty, it’s a kludge, but much better than missing your flight…

Kernel Adiutor has what it calls an “init.d emulator” tool to execute scripts on boot. I’ve just found out! Hope we can get a workaround working fine, :slight_smile:

2 Likes

Clock Reset After reboot workaround

Warning: It works on my phone but I cannot guarantee that it will work on yours. I have now tested it under a different timezone while travelling and it works. You do this at your own risk and nobody will pay your ticket if you miss your train or plane in the morning! :wink:

Thanks to @Roboe for pointing in the right direction!

Requirements

OK, lets go for it:

  • Make sure your FP2 shows the proper time.
  • Open the “Clock Offset Fix” app and click on "Install offset and initscript"
    Important: This fix does not update the offset-file regularly so you will have to update it by clicking on “Install Offset” whenever you have “cold started” your phone (removed the battery).
  • Open “Kernel Adiutor” and go to the “init.d” section (listed under "tools)
  • Enable init.d support (slider to the right and pink)
  • click on the + sign to add a new script
  • call the script rtcfix, your horses name or whatever you like, but no special characters.
  • Simply add the following line to the script (leave the #!/system/bin/sh as it is):
    /data/local/userinit.sh
  • Save and you are cooked !
  • You can check the script by tapping on the entry in the init.d section. It should show the current time as result.

Test your setup:

  • WiFi off
  • Mobile Data Off
  • Aeroplane Mode On or remove SIM
  • Wrap your phone in tin foil if you want to be really really sure it does not get the time from outside. :slight_smile:
  • Shutdown phone
  • Start phone again
  • Things going well Kernel Adiutor will set the time after approx. 10 seconds (the default delay) plus boot time. :+1:
7 Likes

Non open source app with root permissions is not an option for me, but I like your discovery!
Hope some people benefits from that! :smiley:

Also, if you could paste the userinit.sh script here for inspection, that’d be rather useful for people like me, :wink:

1 Like

Well done for finding this workaround, but I hope that marking this thread as resolved doesn’t mean that FP will stop working on a real solution!

3 Likes

I marked the workaround as a “solution” for visibility. If a bug is fixed the topic is closed and removed from the #bugslist::tag.

2 Likes

@Roboe I understand your concerns.
Kernel Adiutor is open source. The Google build is adware, but ads can be removed by donating. Sadly the F-Droid version lacks behind as often the case :frowning:
I cannot find sources for the clock fix apk, but looking at the number of posts in the three years old thread and the thanks given to the dev I decided to give a working clock priority over open source. However I posted the contents of the initscript here. I think it can easily be reversed in order to actually create the offset-file so no additional app is needed. The only problem with that would be to find a trigger for this script to create / update the offset file. One option could be to combine the two in one script with something like “if epoch time is in this millennium, then create/update offset file, else load offset file and set clock”.

[shebang removed to avoid ugly formatting]/system/bin/sh
[[ -f /sdcard/rtc_offset ]] && /system/bin/toolbox date -s $(expr cat /sdcard/rtc_offset + cat /sys/class/rtc/rtc0/since_epoch | awk ’ {print strftime("%Y%m%d.%H%M%S",$1)} ’ ) && exit 0
[[ -f /data/media/rtc_offset ]] && /system/bin/toolbox date -s $(expr cat /data/media/rtc_offset + cat /sys/class/rtc/rtc0/since_epoch | awk ’ {print strftime("%Y%m%d.%H%M%S",$1)} ’ ) && exit 0

2 Likes

Yes, this is just a workaround and not a fix. The main problem that remains is that the offset-file is not updated automatically. This means it needs to be updated manually whenever the phone gets cold-started (battery removal) with RTC time reverting to 01.01.1970. And over time calculated hardware time will drift depending on the accuracy of the RTC. I do not know if Android has an equivalent to Linux shutdown scripts, but ideally one would update the file before the phone is shutting down.

I bought a brand new Fairphone 2 and put Fairphone Open 16.10.0 on it first thing. I don’t get good GPS reception at home, and tend to idle on wifi while on a usb tether. Unfortunately even if I set the clock and THEN switch to network time, it goes back to the unix epoch (1970).

I’d just like to be able to have good NTP working right now, as it’s ridiculous that I have manually-set time on my phone!

3 Likes

Just to add that while travelling in Germany I was able to test the workaround under a different timezone and I can confirm that it works. The phone loads the correct time and timezone when rebooting it with WiFi off and in aeroplane mode. I have edited the text of the workaround accordingly.

2 Likes

I found two threads which are about the same thing. So apparently the problem is existant only in CAF trees…
http://www.96boards.org/forums/topic/cant-set-rtc-time-on-dragon-board/#gsc.tab=0

http://forum.xda-developers.com/showpost.php?p=62329019&postcount=3

1 Like

Eureka! I think I just found the fix for the clock bug! Not a workaround anymore, :slight_smile:

I found this BOARD_USES_QC_TIME_SERVICES := true build var, and added it to the BoardConfig.mk of the latest FP Open codebase. This should enable exactly the services we’ve discussed above Qcom devices have, but FP2 lacks for some reason.

I ran a nightly build, but it failed because of key issues on Ubuntu 16.04. I had to install Ubuntu 14.04 and a new build has been running for a few hours now.

When it finish, I’ll test if the clock works once and for all! Then I’ll probably push the patch to the FP Gerrit instance.

Edit: For future reference, it seems to require the libtime_genoff.so blob. Not a problem with the FP2, we already have that shipped, :wink:

8 Likes

It didn’t work, :frowning:. The build var is probably CyanogenMod-only. But in the search of how to enable time_daemon on Qcom CAF builds, I found an open source implementation from the guys of Sony Xperia Dev that could be useful for other ROMs:

+1

Very annoying bug, a fix would be much appreciated.

Ok, I’ve pushed the investigation forward. time_daemon and TimeService.apk are included in the build, as well as calling time_daemon restore on the init.qcom.rc (boot process). So, why are they not working?

I took a look at the system apps list and, surprise, TimeService (com.qualcomm.timeservice) is not installed. WTF! But it is on the system! Check it, /system/app/TimeService/TimeService.apk!

So I tried to debug by installing it manually. I opened Termux, and ran:

$ su
# pm install /system/app/TimeService/TimeService.apk
pkg: /system/app/TimeService/TimeService.apk
Failure [INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]

¡Ahá! There’s the problem. A permission/signing key issue. But I cannot investigate further because, as you now, closed source code is not reviewable (I can’t see what the AndroidManifest.xml says, :angry:). All this Qcom time thingies are part of the FP2 blobs.

PD: there’s useful Android permissions information at /data/system/packages.xml, FYI. Time info seems to be saved on a binary file at /data/time/ats_13

7 Likes

@Roboe any news about this?

I don’t won’t to follow the workaround with the non open spource app as well.

But the issue is there and I think it very annoying (especially while setting up a phone).
E.g.

  • certificate issue with e-MailI-providers and K9-Mail (any possibility to tell K9 to wait a bit before trying to get new mails the first time after reboot)
  • I would like to go on using my Pebble (/“Fibit”) Smartwatch (as long as it still works :wink: ) but the watch switch to factory mode because of this issue after each reboot.

For me it feels like that it takes about half a minut until the time is corrected.

DAVdroid failing because of invalid certificates is a common issue, too.

Nope, not any news. Eight months later, the bug is still unfixed. FP Open is a second-class citizen, from what we have seen.

Until your phone goes online and checks the time. If you never get online, then your phone is stuck at 1970.

1 Like