Android system time zone library tzdata update

This article is based on android P, and the system’s time zone library version number is tzdata2018;

tzdata update

If the daylight saving time in a certain city time zone is abnormal, or the time zone time is abnormal, you can consider whether there is an error in the time zone database? Or has the time zone database been updated to the latest one?
The main source code paths involved are as follows:
Code path: system\timezone
Database source path: system\timezone\input_data\iana\ which contains the compressed database file corresponding to the version number.
Execute the script: update-tzdata.py (soure, lunch, make first when executing)
tzdata generation path: system\timezone\output_data\iana\tzdata
Path in the machine: system/usr/share/zoneinfo/tzdata

1, Modify the system time zone database tzdata

Reference: https://blog.csdn.net/qq_37960503/article/details/132305338

How to modify:
Take the tzdata database tzdata2018e.tar.gz that comes with Android P as an example. During development, I found that when setting the Africa/Sao_Tome time zone, the system time was one hour ahead. The official query found that this city is in time zone 0 and does not support daylight saving time, so it is suspected that the time zone of this city in the tzdata database is wrong;

Find the file system/timezone/input_data/iana/tzdata2018c.tar.gz. You need to decompress the compressed package first, and then compress it back after modification;

1.1. Unzip
After decompression, a bunch of files will be generated, similar to the following:

uluxy181@ubuntu16-010:~/workspace3/mtk/system/timezone/input_data/iana/0000$ tar -zxvf tzdata2018e.tar.gz
calendars
CONTRIBUTING
LICENSE
Makefile
NEWS
README
theory.html
version
africa
antarctica
asia
australasia
europe
northamerica
southamerica
etetera
systemv
factory
backward
pacificnew
backzone
iso3166.tab
leap-seconds.list
leapseconds
yearistype.sh
zone1970.tab
zone.tab
checklinks.awk
checktab.awk
leapseconds.awk
ziguard.awk
zishrink.awk
zoneinfo2tdf.pl

Among the above files, there are files corresponding to each continent, which record the city’s time zone rules, daylight saving time rules and other information. Because Sao_Tome is an African city, we can open the corresponding file in Africa to find the corresponding time zone policy;

# From Steffen Thorsen (2018-01-08):
# Multiple sources tell that S?o Tomé changed from UTC to UTC + 1 as
# they entered the year 2018.
# From Michael Deckers (2018-01-08):
# the switch is from 01:00 to 02:00 ... [Decree No. 25/2017]
# http://www.mnec.gov.st/index.php/publicacoes/documentos/file/90-decreto-lei-n-25-2017

Zone Africa/Sao_Tome 0:26:56 - LMT 1884
-0:36:45 - LMT 1912 Jan 1 00:00u # Lisbon MT
0:00 - GMT 2018 Jan 1 01:00
1:00 - WAT

1.2 Modify time zone information
You can see that in the latest time zone rules, sao_tome is not in time zone 0, but in time zone 1. This is the point we can modify. We can change 1 to 0 to achieve the purpose of modifying the time zone;

Zone Africa/Sao_Tome 0:26:56 - LMT 1884
-0:36:45 - LMT 1912 Jan 1 00:00u # Lisbon MT
0:00 - GMT 2018 Jan 1 01:00
0:00 - WAT //Modify here directly

1.3 Recompress the file into tzdata2018c.tar.gz

1.4 Execute update-tzdata.py to regenerate the tzdata library
First source build/envsetup.sh in the root directory, then lunch and make. Then execute ./system/timezone/update-tzdata.py
At this time, you can execute git status to see the current file updates. You will find that several files have been updated, mainly the system/timezone/output_data/iana/tzdata file. At this time, you can get status to check the status.

uluxy181@ubuntu16-010:~/workspace3/mtk/system/timezone$ git status
Not currently on any branch.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

modified: input_data/iana/tzdata2018e.tar.gz
modified: output_data/iana/tzdata
modified: output_data/icu_overlay/icu_tzdata.dat

no changes added to commit (use "git add" and/or "git commit -a")

When executing updata-tzdata.py, the normal situation should be that the compilation is completed successfully. But if this printout appears in the end, don’t panic. It’s not an error. This tzdata has been compiled. If you don’t believe it, you can make -j12 and flash the machine to verify;

WARNING: Please consider reporting this to the maintainers of com.google.protobuf.Utf8$UnsafeProcessor
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
I: Issues:
[country=st, id=Africa/Sao_Tome, offset=1:00, shownInPicker=true]: Offset mismatch: You will want to confirm the ordering for st still makes sense. Raw offset for Africa/Sao_Tome is 02:00 and not 01:00 at July 2, 2019 at 12:00:00 PM UTC

Traceback (most recent call last):
  File "./update-tzdata.py", line 253, in <module>
    main()
  File "./update-tzdata.py", line 239, in main
    BuildTzlookup(iana_data_dir)
  File "./update-tzdata.py", line 182, in BuildTzlookup
    countryzones_source_file, zone_tab_file, tzlookup_dest_file])
  File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['java', '-jar', '/home/YFCO/uluxy181/workspace3/mtk/out/host/linux-x86/framework/tzlookup_generator.jar', '/home/YFCO/uluxy181 /workspace3/mtk/system/timezone/input_data/android/countryzones.txt', '/tmp/tmpZp4S8y-tzdata/iana_data/zone.tab', '/home/YFCO/uluxy181/workspace3/mtk/system/timezone/output_data /android/tzlookup.xml']' returned non-zero exit status 1
uluxy181@ubuntu16-010:~/workspace3/mtk/system/timezone$

1.5 Recompile the system and then flash and verify
You can push the generated output_data/iana/tzdata to the system/usr/share/zoneinfo directory of the car separately, and restart to verify whether it is valid.
To be on the safe side, compile, burn and verify.

2, Update system world library tzdata

If the tzdata database in the system is too old, you can try to update the entire database. The basic method is as follows;
Reference: https://blog.csdn.net/qq_44865086/article/details/97410226
2.1. Download the latest tzdata library
Open the /system/timezone/input_data/iana/ directory and you can see a compressed package named tzdata2018e.tar.gz and a tzdata2018e.tar.gz.asc file. The version number of tzdata may be different in different Android versions. According to this compression For package version information, go to the website ftp://ftp.iana.org/tz/releases/ to download the corresponding versions of tzdata*.tar.gz and tzdata×.tar.gz.asc. The latest one is tzdata2023c.
The website opens like this, scroll down, and you can find the corresponding tzdata;

2.2 Replacement library
Place the downloaded files tzdata2023c.tar.gz and tzdata2023c.tar.gz.asc in the system\timezone\input_data\iana directory, and delete the previous 2018 version.

uluxy181@ubuntu16-010:~/workspace3/mtk/system/timezone/input_data/iana$ git status
Not currently on any branch.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

deleted: tzdata2018e.tar.gz
deleted: tzdata2018e.tar.gz.asc

Untracked files:
  (use "git add <file>..." to include in what will be committed)

tzdata2023c.tar.gz
tzdata2023c.tar.gz.asc

no changes added to commit (use "git add" and/or "git commit -a")
uluxy181@ubuntu16-010:~/workspace3/mtk/system/timezone/input_data/iana$

2.3 update tzdata
Switch to the compilation environment (execute source build/envsetup.sh and lunch), then enter the /system/timezone/ directory and execute update-tzdata.py. Execution method: python update-tzdata.py.
But when I execute it directly, I get an error:

...
gunzip -d < ./tzdata2023c.tar.gz | tar xf - --exclude=Makefile
touch tdatamarker
make: *** No rule to make target 'yearistype.sh', needed by 'yearistype'. Stop.
make: Leaving directory '/tmp/tmp_B2D9d-tzdata/icu/tools/tzcode'
Traceback (most recent call last):
  File "update-tzdata.py", line 253, in <module>
    main()
  File "update-tzdata.py", line 231, in main
    BuildIcuData(iana_data_tar_file)
  File "update-tzdata.py", line 94, in BuildIcuData
    icuutil.MakeTzDataFiles(icu_build_dir, iana_data_tar_file)
  File "/home/YFCO/uluxy181/workspace3/mtk/external/icu/tools/icuutil.py", line 103, in MakeTzDataFiles
    subprocess.check_call(['make', '-C', tzcode_working_dir])
  File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['make', '-C', '/tmp/tmp_B2D9d-tzdata/icu/tools/tzcode']' returned non-zero exit status 2

In principle, the icu library and the tzdata library are independent and can be upgraded separately, so here I choose to comment out the compilation of icu.

uluxy181@ubuntu16-010:~/workspace3/mtk/system/timezone$ git diff update-tzdata.py
diff --git a/update-tzdata.py b/update-tzdata.py
index 20986c7..7a8f7d9 100755
--- a/update-tzdata.py
 + + + b/update-tzdata.py
@@ -228,7 + 228,7 @@ def main():
   icu_dir = icuutil.icuDir()
   print 'Found icu in %s ...' % icu_dir
 
- BuildIcuData(iana_data_tar_file)
 + ## BuildIcuData(iana_data_tar_file)
 
   iana_tools_dir = '%s/iana' % timezone_input_tools_dir
   zic_binary_file = BuildZic(iana_tools_dir)

2.4. After executing the script, it will be generated in system/timezone:
output_data/iana/tzdata

2.5. Just recompile the entire project.
If it is just for testing, you can directly generate new tzdata from output_data/iana/ and put it in the system/usr/share/zoneinfo directory corresponding to the machine to overwrite the previous tzdata for testing. To be on the safe side, flash the entire machine