📜 ⬆️ ⬇️

Troubleshooting Android Time Sync Issues

After reading the article “Moving the MSD time zone to MSK - a new local-scale Y2K” , he recalled that he and his work colleague had already solved this problem on Android (HTC Hero) long ago and wanted to write in a sandbox, but put everything off until later. And today there was another article “Updating time zones on Android”, which practically buried the idea of ​​writing, and confirmed the idea that you shouldn’t postpone important things for later. But ... having a little remembered, I nevertheless decided, because these articles dealt with problems related to the transition to winter / summer time and didn’t touch at all the moment regarding the weather widget’s work with the weather and automatic time determination through the cellular operator.

It all started when a new HTC Desire S. was purchased.

During the setup process, it turned out that in the date and time settings it is not possible to choose my city - Novosibirsk and have to choose an alternative city with the appropriate time zone.
It also turned out that the time synchronization from the operator works somehow mysteriously and the HTC Clock widget in the weather display mode and with the automatic synchronization turned on displays incorrect time.
')


In the picture it may seem that everything is in order, but the time on the phone actually ran an hour ago. You can turn off automatic detection and set the zone by hand, but then we get the following:



As you can see, Novosibirsk is absent in the list. We had to choose Bangkok, and the system time in the phone became correct, but the widget still displays backward an hour.

We tried to find a solution online. Found that we are not alone, and such problems exist not only among residents of Novosibirsk, but also among residents of other cities on the planet. We did not find a comprehensive solution to all these problems.

It was possible to score on it all, turn it off, set it up with your hands and not pay attention to the widget, but ... it's Android - and this means that we can and must defeat it!

And so, we start

The new phone was not rutovny at that time and could not be made as such. Therefore, for experiments, HTC Hero was taken with the original + root / busybox / apps2sd firmware, which had exactly the same problems.

Found through osmonitor application in which the time zone is selected - (com.android.settings). We looked at the source code for the com.android.settings package and found out that resources are loaded from the timezones.xml XML file.

We got the apk of this application /system/app/Settings.apk with the following command:
 adb pull /system/app/Settings.apk 


I will not describe all the details of the work of APK manager and Android SDK tools, I think interested people can easily figure it out. I will focus only on the key points.

Using the APK manager, the following actions were performed.

We made changes for our city, by analogy, residents of other cities will also be able to try to fix this problem on their phones.

The resulting apk was placed back into the phone:
  adb push Settings.apk / system / app / 


With this we achieved the fact that in the list of manual selection of the time zone appeared Novosibirsk.

Our city appeared in the list, but the definition of the time zone in the automatic mode still did not work correctly. To do this, we went further and found out that the time zone settings for cities are stored in the database, namely in the file /system/etc/WPDB.zip.
Taking it out of the phone using all the same adb, we extracted two bases from it

for English and Russian, respectively. Looking at the data, we found that for our city, the time zone is registered as Asia / Almaty, we had to correct this moment, for this we changed the timezoneId to Asia / Novosibirsk in the databases (using Lita as the SQLite database editor):
 update locationlist set timezoneId = 'Asia / Novosibirsk' where name = 'Novosibirsk' - (for WP_0409WWE.db)
 update locationlist set timezoneId = 'Asia / Novosibirsk' where name = 'Novosibirsk' - (for WP_0419RUS.db)

In addition, another database added an entry about our city, namely in /system/etc/timezones.db
Added entry, timezoneId: Asia / Novosibirsk, other fields Novosibirsk, ru - Novosibirsk.

In order for all changes to take effect, reset the cache for applications
Clock, Settings and Weather Provider. Well, for complete confidence restarted the phone.

Results


As a result, we got the following cakes:

As we can see, in automatic mode, the zone is determined correctly, the system time and time on the widget are the same, well, in manual mode, everything is fine.

Having become involved in a war with time, we decided to go to the end. Namely, to solve the problem of canceling the transition to winter / summer time.
Download the latest tzdata (aka timeinfo.dat) from, then still available, resource elsie.nci.nih.gov/pub
Found that in her about us have not thought, corrected, prepared and poured into the phone. At the time of writing, this database already contains the correct settings for our vast country, and how to solve this problem is well described in the article “Updating time zones on Android”

In conclusion, I provide a list of the tools we used:

I hope we have not wasted time, and this information will be useful to someone.

P.S. after publication, I accidentally found an article describing the addition of a new city HTC Sense and a weather widget - we add our city slightly intersecting with this one.

Source: https://habr.com/ru/post/131320/


All Articles