1 diff -u -r ../glib-2.54.2/glib/gtimezone.c ./glib/gtimezone.c
2 --- ../glib-2.54.2/glib/gtimezone.c 2017-07-14 01:03:39.000000000 +0200
3 +++ ./glib/gtimezone.c 2017-12-21 23:47:57.704190589 +0100
9 +#include <sys/system_properties.h>
16 gtz->transitions = NULL;
21 +/* Android uses a 'persist.sys.timezone' system property for the
22 + * current timezone instead of a /etc/localtime file:
23 + * https://android.googlesource.com/platform/ndk/+/android-2.2_r1/docs/system/libc/OVERVIEW.TXT#67
25 + * There are no files under /usr/share/zoneinfo - instead a single
26 + * /system/usr/share/zoneinfo/tzdata file is used which contains all
27 + * files compiled together with the following tool:
28 + * https://android.googlesource.com/platform/system/timezone/+/master/zone_compactor/main/java/ZoneCompactor.java
31 +zone_info_android (const gchar *identifier)
33 + char sys_timezone[PROP_VALUE_MAX];
36 + gsize tzdata_length;
37 + const gsize index_entry_size = 52;
38 + gint32 header_index_offset, header_data_offset;
39 + gint32 entry_count, current_index;
41 + gint32 entry_offset, entry_length;
44 + if (identifier == NULL)
46 + if (__system_property_get ("persist.sys.timezone", sys_timezone) < 1)
48 + g_warning ("__system_property_get(\"persist.sys.timezone\") failed");
51 + identifier = sys_timezone;
54 + file = g_mapped_file_new ("/system/usr/share/zoneinfo/tzdata", FALSE, NULL);
57 + g_warning ("Failed mapping tzdata file");
61 + tzdata = g_mapped_file_get_contents (file);
62 + tzdata_length = g_mapped_file_get_length (file);
63 + if (tzdata == NULL || tzdata_length < 24)
65 + g_warning ("Too small tzdata file");
69 + header_index_offset = gint32_from_be (*((gint32_be*) (tzdata + 12)));
70 + header_data_offset = gint32_from_be (*((gint32_be*) (tzdata + 16)));
72 + entry_count = (header_data_offset - header_index_offset) / index_entry_size;
73 + if (entry_count < 1)
75 + g_warning("No index entry found");
80 + while (current_index < entry_count)
82 + entry_name = tzdata + header_index_offset + current_index * index_entry_size;
83 + /* The name should be null terminated within the 40 chars. */
84 + if (memchr (entry_name, 0, 40) == NULL)
86 + g_warning("Invalid index entry");
90 + if (strcmp (entry_name, identifier) == 0)
92 + entry_offset = gint32_from_be (*(gint32_be*) (entry_name + 40));
93 + entry_length = gint32_from_be (*(gint32_be*) (entry_name + 44));
94 + if (entry_length == 0)
96 + g_warning ("Invalid tzdata entry with length zero");
99 + else if (entry_length > 65536 || header_data_offset + entry_offset + entry_length > tzdata_length)
101 + /* Use a reasonable but arbitrary max length of an entry. */
102 + g_warning ("Too large tzdata entry length");
106 + zoneinfo = g_bytes_new_with_free_func (tzdata + header_data_offset + entry_offset,
108 + (GDestroyNotify)g_mapped_file_unref,
109 + g_mapped_file_ref (file));
110 + g_mapped_file_unref (file);
117 + g_mapped_file_unref (file);
121 +#elif defined(G_OS_UNIX)
124 zone_info_unix (const gchar *identifier)
135 init_zone_from_iana_info (GTimeZone *gtz, GBytes *zoneinfo)
137 @@ -1387,7 +1497,11 @@
138 if (tz->t_info == NULL)
142 + GBytes *zoneinfo = zone_info_android (identifier);
144 GBytes *zoneinfo = zone_info_unix (identifier);
147 zone_for_constant_offset (tz, "UTC");