Skip to content

Commit e44005a

Browse files
ksh8281bbrto21
authored andcommitted
Android timezone data load for adb-shell
Signed-off-by: Seonghyun Kim <[email protected]>
1 parent a130b10 commit e44005a

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/Escargot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ extern "C" {
293293
#if defined(OS_WINDOWS)
294294
#include <icu.h>
295295
#else
296+
#include <unicode/utypes.h>
296297
#include <unicode/locid.h>
297298
#include <unicode/uchar.h>
298299
#include <unicode/ustring.h>

src/runtime/Global.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@
2626
#include "runtime/ScriptFunctionObject.h"
2727
#include "runtime/ScriptSimpleFunctionObject.h"
2828

29+
// https://cs.android.com/android/platform/superproject/main/+/main:external/icu/libandroidicuinit/IcuRegistration.cpp
30+
#if defined(OS_ANDROID) && defined(ENABLE_ICU) && defined(ESCARGOT_ENABLE_TEST)
31+
#include <sys/stat.h>
32+
#include <stdbool.h>
33+
34+
static bool directoryExists(const char* path)
35+
{
36+
struct stat info;
37+
if (stat(path, &info) != 0)
38+
return false;
39+
else
40+
return (info.st_mode & S_IFDIR) != 0;
41+
}
42+
43+
static std::string getTimeZoneModulePath()
44+
{
45+
const char* tzdataModulePathPrefix = getenv("ANDROID_TZDATA_ROOT");
46+
if (tzdataModulePathPrefix == NULL) {
47+
return "";
48+
}
49+
50+
std::string ret;
51+
52+
for (int version = 1; version < 128; version++) {
53+
std::string tzdataModulePath = tzdataModulePathPrefix;
54+
tzdataModulePath += "/etc/tz/versioned/" + std::to_string(version) + "/icu";
55+
if (directoryExists(tzdataModulePath.data())) {
56+
ret = tzdataModulePath;
57+
}
58+
}
59+
60+
return ret;
61+
}
62+
#endif
63+
2964
namespace Escargot {
3065

3166
bool Global::inited;
@@ -60,6 +95,15 @@ void Global::initialize(Platform* platform)
6095
DECLARE_SCRIPTSIMPLEFUNCTION_LIST(INIT_SCRIPTSIMPLEFUNCTION_TAGS);
6196
#undef INIT_SCRIPTSIMPLEFUNCTION_TAGS
6297

98+
#if defined(OS_ANDROID) && defined(ENABLE_ICU) && defined(ESCARGOT_ENABLE_TEST)
99+
// android timezone data load for adb-shell
100+
std::string tzPath = getTimeZoneModulePath();
101+
if (tzPath.size()) {
102+
UErrorCode status = U_ZERO_ERROR;
103+
u_setTimeZoneFilesDirectory(tzPath.data(), &status);
104+
}
105+
#endif
106+
63107
inited = true;
64108
}
65109

third_party/runtime_icu_binder/ICUPolyfill.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "RuntimeICUBinder.h"
2121

2222
#define u_getVersion RuntimeICUBinder::ICU::instance().u_getVersion
23+
#define u_setDataDirectory RuntimeICUBinder::ICU::instance().u_setDataDirectory
24+
#define u_setTimeZoneFilesDirectory RuntimeICUBinder::ICU::instance().u_setTimeZoneFilesDirectory
2325

2426
#define u_tolower RuntimeICUBinder::ICU::instance().u_tolower
2527
#define u_toupper RuntimeICUBinder::ICU::instance().u_toupper

third_party/runtime_icu_binder/RuntimeICUBinder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ namespace RuntimeICUBinder {
100100

101101
#define FOR_EACH_UC_VOID_OP(F) \
102102
F(u_getVersion, void(CALLCONV*)(UVersionInfo versionArray), void) \
103+
F(u_setDataDirectory, void(CALLCONV*)(const char*), void) \
104+
F(u_setTimeZoneFilesDirectory, void(CALLCONV*)(const char*, UErrorCode*), void) \
103105
F(uiter_setString, void(CALLCONV*)(UCharIterator * iter, const UChar* s, int32_t length), void) \
104106
F(ucnv_close, void(CALLCONV*)(UConverter * converter), void) \
105107
F(ucnv_toUnicode, void(CALLCONV*)(UConverter * converter, UChar * *target, const UChar* targetLimit, const char** source, const char* sourceLimit, int32_t* offsets, UBool flush, UErrorCode* err), void) \

0 commit comments

Comments
 (0)