зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1534160 - Part 2: Cherry-pick patch for Android time zone detection. r=jwalden
Cherry-pick the commit from <https://github.com/unicode-org/icu/pull/605>. Depends on D82545 Differential Revision: https://phabricator.services.mozilla.com/D82546
This commit is contained in:
Родитель
dc07d1aa1e
Коммит
4d1d96c31a
|
@ -0,0 +1,112 @@
|
|||
commit 6099f062f5d0e79586149d9a8963525a59f89557
|
||||
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
|
||||
Date: Fri Nov 22 16:51:30 2019 +0900
|
||||
|
||||
ICU-11992 uprv_tzname doesn't return valid time zone on Android
|
||||
|
||||
# ICU bug report:
|
||||
# https://unicode-org.atlassian.net/browse/ICU-11992
|
||||
#
|
||||
# Pull request:
|
||||
# https://github.com/unicode-org/icu/pull/605
|
||||
#
|
||||
# Commit:
|
||||
# https://github.com/unicode-org/icu/commit/c9037ca8d3c0738f1a044dd845bdc0dc646f3e97.patch
|
||||
|
||||
diff --git a/intl/icu/source/common/putil.cpp b/intl/icu/source/common/putil.cpp
|
||||
--- a/intl/icu/source/common/putil.cpp
|
||||
+++ b/intl/icu/source/common/putil.cpp
|
||||
@@ -116,15 +116,19 @@
|
||||
# include <unistd.h>
|
||||
# if U_PLATFORM == U_PF_SOLARIS
|
||||
# ifndef _XPG4_2
|
||||
# define _XPG4_2
|
||||
# endif
|
||||
+# elif U_PLATFORM == U_PF_ANDROID
|
||||
+# include <sys/system_properties.h>
|
||||
+# include <dlfcn.h>
|
||||
# endif
|
||||
#elif U_PLATFORM == U_PF_QNX
|
||||
# include <sys/neutrino.h>
|
||||
#endif
|
||||
|
||||
+
|
||||
/*
|
||||
* Only include langinfo.h if we have a way to get the codeset. If we later
|
||||
* depend on more feature, we can test on U_HAVE_NL_LANGINFO.
|
||||
*
|
||||
*/
|
||||
@@ -1041,13 +1045,57 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
+#if U_PLATFORM == U_PF_ANDROID
|
||||
+typedef int(system_property_read_callback)(const prop_info* info,
|
||||
+ void (*callback)(void* cookie,
|
||||
+ const char* name,
|
||||
+ const char* value,
|
||||
+ uint32_t serial),
|
||||
+ void* cookie);
|
||||
+typedef int(system_property_get)(const char*, char*);
|
||||
+
|
||||
+static char gAndroidTimeZone[PROP_VALUE_MAX] = { '\0' };
|
||||
+
|
||||
+static void u_property_read(void* cookie, const char* name, const char* value,
|
||||
+ uint32_t serial) {
|
||||
+ uprv_strcpy((char* )cookie, value);
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
U_CAPI void U_EXPORT2
|
||||
uprv_tzname_clear_cache()
|
||||
{
|
||||
+#if U_PLATFORM == U_PF_ANDROID
|
||||
+ /* Android's timezone is stored in system property. */
|
||||
+ gAndroidTimeZone[0] = '\0';
|
||||
+ void* libc = dlopen("libc.so", RTLD_NOLOAD);
|
||||
+ if (libc) {
|
||||
+ /* Android API 26+ has new API to get system property and old API
|
||||
+ * (__system_property_get) is deprecated */
|
||||
+ system_property_read_callback* property_read_callback =
|
||||
+ (system_property_read_callback*)dlsym(
|
||||
+ libc, "__system_property_read_callback");
|
||||
+ if (property_read_callback) {
|
||||
+ const prop_info* info =
|
||||
+ __system_property_find("persist.sys.timezone");
|
||||
+ if (info) {
|
||||
+ property_read_callback(info, &u_property_read, gAndroidTimeZone);
|
||||
+ }
|
||||
+ } else {
|
||||
+ system_property_get* property_get =
|
||||
+ (system_property_get*)dlsym(libc, "__system_property_get");
|
||||
+ if (property_get) {
|
||||
+ property_get("persist.sys.timezone", gAndroidTimeZone);
|
||||
+ }
|
||||
+ }
|
||||
+ dlclose(libc);
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
#if defined(CHECK_LOCALTIME_LINK) && !defined(DEBUG_SKIP_LOCALTIME_LINK)
|
||||
gTimeZoneBufferPtr = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1082,11 +1130,15 @@ uprv_tzname(int n)
|
||||
}
|
||||
#endif*/
|
||||
|
||||
/* This code can be temporarily disabled to test tzname resolution later on. */
|
||||
#ifndef DEBUG_TZNAME
|
||||
+#if U_PLATFORM == U_PF_ANDROID
|
||||
+ tzid = gAndroidTimeZone;
|
||||
+#else
|
||||
tzid = getenv("TZ");
|
||||
+#endif
|
||||
if (tzid != NULL && isValidOlsonID(tzid)
|
||||
#if U_PLATFORM == U_PF_SOLARIS
|
||||
/* When TZ equals localtime on Solaris, check the /etc/localtime file. */
|
||||
&& uprv_strcmp(tzid, TZ_ENV_CHECK) != 0
|
||||
#endif
|
|
@ -118,11 +118,15 @@
|
|||
# ifndef _XPG4_2
|
||||
# define _XPG4_2
|
||||
# endif
|
||||
# elif U_PLATFORM == U_PF_ANDROID
|
||||
# include <sys/system_properties.h>
|
||||
# include <dlfcn.h>
|
||||
# endif
|
||||
#elif U_PLATFORM == U_PF_QNX
|
||||
# include <sys/neutrino.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Only include langinfo.h if we have a way to get the codeset. If we later
|
||||
* depend on more feature, we can test on U_HAVE_NL_LANGINFO.
|
||||
|
@ -1043,9 +1047,53 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if U_PLATFORM == U_PF_ANDROID
|
||||
typedef int(system_property_read_callback)(const prop_info* info,
|
||||
void (*callback)(void* cookie,
|
||||
const char* name,
|
||||
const char* value,
|
||||
uint32_t serial),
|
||||
void* cookie);
|
||||
typedef int(system_property_get)(const char*, char*);
|
||||
|
||||
static char gAndroidTimeZone[PROP_VALUE_MAX] = { '\0' };
|
||||
|
||||
static void u_property_read(void* cookie, const char* name, const char* value,
|
||||
uint32_t serial) {
|
||||
uprv_strcpy((char* )cookie, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
uprv_tzname_clear_cache()
|
||||
{
|
||||
#if U_PLATFORM == U_PF_ANDROID
|
||||
/* Android's timezone is stored in system property. */
|
||||
gAndroidTimeZone[0] = '\0';
|
||||
void* libc = dlopen("libc.so", RTLD_NOLOAD);
|
||||
if (libc) {
|
||||
/* Android API 26+ has new API to get system property and old API
|
||||
* (__system_property_get) is deprecated */
|
||||
system_property_read_callback* property_read_callback =
|
||||
(system_property_read_callback*)dlsym(
|
||||
libc, "__system_property_read_callback");
|
||||
if (property_read_callback) {
|
||||
const prop_info* info =
|
||||
__system_property_find("persist.sys.timezone");
|
||||
if (info) {
|
||||
property_read_callback(info, &u_property_read, gAndroidTimeZone);
|
||||
}
|
||||
} else {
|
||||
system_property_get* property_get =
|
||||
(system_property_get*)dlsym(libc, "__system_property_get");
|
||||
if (property_get) {
|
||||
property_get("persist.sys.timezone", gAndroidTimeZone);
|
||||
}
|
||||
}
|
||||
dlclose(libc);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CHECK_LOCALTIME_LINK) && !defined(DEBUG_SKIP_LOCALTIME_LINK)
|
||||
gTimeZoneBufferPtr = NULL;
|
||||
#endif
|
||||
|
@ -1084,7 +1132,11 @@ uprv_tzname(int n)
|
|||
|
||||
/* This code can be temporarily disabled to test tzname resolution later on. */
|
||||
#ifndef DEBUG_TZNAME
|
||||
#if U_PLATFORM == U_PF_ANDROID
|
||||
tzid = gAndroidTimeZone;
|
||||
#else
|
||||
tzid = getenv("TZ");
|
||||
#endif
|
||||
if (tzid != NULL && isValidOlsonID(tzid)
|
||||
#if U_PLATFORM == U_PF_SOLARIS
|
||||
/* When TZ equals localtime on Solaris, check the /etc/localtime file. */
|
||||
|
|
|
@ -58,6 +58,7 @@ for patch in \
|
|||
bug-1636984-alias-append-items-sink.diff \
|
||||
bug-1636984-display-name-fractional-seconds.diff \
|
||||
bug-1636984-append-item-dayperiod-fractional-seconds.diff \
|
||||
bug-1534160-android-timezone.diff \
|
||||
; do
|
||||
echo "Applying local patch $patch"
|
||||
patch -d ${icu_dir}/../../ -p1 --no-backup-if-mismatch < ${icu_dir}/../icu-patches/$patch
|
||||
|
|
Загрузка…
Ссылка в новой задаче