Troubleshoot issues with automatic time synchronization in Android

After reading the article “Moving the MSD time zone to MSK - a new Y2K of local scale” - I remembered that I had already solved this problem with Android (HTC Hero) and wanted to write in the sandbox, but I put it off for later. And today there was another article “Updating time zones on Android” that almost buried the idea of ​​writing and confirmed the idea that important things should not be postponed until later. But ... after a bit of recalling, I nevertheless decided, because in these articles the problems associated with the transition to winter / summer time were considered and the moment concerning the operation of the clock widget with the weather and the automatic determination of the time through the mobile operator was not addressed at all.

It all started with the fact that a new HTC Desire S phone was purchased.

In the process of setting it turned out that in the date and time settings there is no way to choose my city - Novosibirsk and have to choose an alternative city with a suitable time zone.
It also turned out that synchronizing the time from the operator works somehow mysteriously and the HTC Clock widget in the weather display mode and the automatic synchronization turned on displays the wrong time. The picture may seem that everything is in order, but the time actually ran off an hour ago on the phone. You can turn off automatic detection and set the zone by hand, but then we get the following: Apparently, Novosibirsk is not in the list. We had to choose Bangkok, while the system time on the phone became correct, but the widget still displays an hour ago.

We tried to find a solution on the network. We found that we are not alone, and similar problems exist not only among the inhabitants 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, disconnect, set hands and not pay attention to the widget, but ... this is Android - which means that we can and must defeat it!

And so, we begin

The new phone was not routine at that time and it was not possible to make it such. Therefore, for the experiments, HTC Hero was taken with the original firmware + root / busybox / apps2sd, on which there were exactly the same problems.

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

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 the APK manager and Android SDK tools, I think that interested people can easily figure it out. I will dwell only on key points.

Using the APK manager, the following actions were performed.
  • decompile
  • pens in another window edited files
  • compile When compiling the APK, the manager asks the questions:
    “Is this a system apk (y / n)” - answer yes
    “Aside from the signatures, would you like to copy over any additional files that you didn't modify from the original apk in order to ensure least # of errors (y / n) "- also answer yes.
    Next, we follow the instructions proposed by the APK manager manager, in another window we delete the files that we changed + resources.arsc from the keep directory.
  • We complete the assembly.

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 put back into the phone:
adb push Settings.apk / system / app /

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

Our city appeared on the list, but the definition of a time zone in 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 a database, namely in the /system/etc/ file.
Having taken it out of the phone using the same adb, we extracted two bases from it
  • WP_0409WWE.db
  • WP_0419GB.db

for English and Russian, respectively. Looking at the data, we found that for our city, the time zone was registered as Asia / Almaty, we had to fix this moment, for this we changed the timezoneId to Asia / Novosibirsk in the databases (we used Lita as the editor of SQLite database):
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, an entry about our city was added to another database, namely in /system/etc/timezones.db
An entry was added, timezoneId: Asia / Novosibirsk, other fields Novosibirsk, ru - Novosibirsk.

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


As a result, we got these pies: As we can see, in automatic mode the zone is determined correctly, the system time and time on the widget are the same, and in manual mode everything is in order. Having got involved in the war with time, we decided to go to the end. Namely, to solve the problem of canceling the transition to winter / summer time. We downloaded the latest tzdata (aka timeinfo.dat) from the then still available resource We found that we hadn’t thought about us in it yet, corrected it, prepared it, and uploaded it to 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 described wonderfully in the article “Updating time zones on Android”

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

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

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

Also popular now: