diff options
Diffstat (limited to 'android_icu4j')
4 files changed, 80 insertions, 0 deletions
diff --git a/android_icu4j/libcore_bridge/src/java/com/android/i18n/system/ZygoteHooks.java b/android_icu4j/libcore_bridge/src/java/com/android/i18n/system/ZygoteHooks.java index 166389f0d..9be61a98a 100644 --- a/android_icu4j/libcore_bridge/src/java/com/android/i18n/system/ZygoteHooks.java +++ b/android_icu4j/libcore_bridge/src/java/com/android/i18n/system/ZygoteHooks.java @@ -27,6 +27,8 @@ import android.icu.text.DecimalFormatSymbols; import android.icu.util.TimeZone; import android.icu.util.ULocale; +import com.android.icu.util.UResourceBundleNative; + import dalvik.annotation.compat.VersionCodes; /** @@ -85,6 +87,10 @@ public final class ZygoteHooks { // It's in the end of preload because preload and ICU4J initialization should succeed // without this property. Otherwise, it indicates that the Android patch is not working. System.setProperty(PROP_ICUBINARY_DATA_PATH, AndroidDataFiles.generateIcuDataPath()); + + // Cache the timezone bundles, e.g. metaZones.res, in Zygote due to app compat. + // http://b/339899412 + UResourceBundleNative.cacheTimeZoneBundles(); } /** diff --git a/android_icu4j/libcore_bridge/src/java/com/android/icu/util/UResourceBundleNative.java b/android_icu4j/libcore_bridge/src/java/com/android/icu/util/UResourceBundleNative.java new file mode 100644 index 000000000..eae5cf60a --- /dev/null +++ b/android_icu4j/libcore_bridge/src/java/com/android/icu/util/UResourceBundleNative.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.icu.util; + +/** + * @hide + */ +public class UResourceBundleNative { + public static native void cacheTimeZoneBundles(); +} diff --git a/android_icu4j/libcore_bridge/src/native/Register.cpp b/android_icu4j/libcore_bridge/src/native/Register.cpp index ad7c9c197..25d53f3e5 100644 --- a/android_icu4j/libcore_bridge/src/native/Register.cpp +++ b/android_icu4j/libcore_bridge/src/native/Register.cpp @@ -53,6 +53,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) { REGISTER(register_com_android_icu_util_CaseMapperNative); REGISTER(register_com_android_icu_util_Icu4cMetadata); REGISTER(register_com_android_icu_util_LocaleNative); + REGISTER(register_com_android_icu_util_UResourceBundleNative); REGISTER(register_com_android_icu_util_regex_PatternNative); REGISTER(register_com_android_icu_util_regex_MatcherNative); REGISTER(register_com_android_icu_util_charset_NativeConverter); diff --git a/android_icu4j/libcore_bridge/src/native/com_android_icu_util_UResourceBundleNative.cpp b/android_icu4j/libcore_bridge/src/native/com_android_icu_util_UResourceBundleNative.cpp new file mode 100644 index 000000000..c1615aa61 --- /dev/null +++ b/android_icu4j/libcore_bridge/src/native/com_android_icu_util_UResourceBundleNative.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "UResourceBundleNative" + +#include <nativehelper/JNIHelp.h> +#include <nativehelper/jni_macros.h> + +#include <log/log.h> +#include "unicode/ures.h" +#include "unicode/utypes.h" + +static inline void openDirectAndCloseRes(const char* res_name) { + UErrorCode status = U_ZERO_ERROR; + UResourceBundle *res = ures_openDirect(nullptr, res_name, &status); + if (U_FAILURE(status)) { + ALOGE("Failed to load ICU resource '%s': %s", res_name, u_errorName(status)); + return; + } + + ures_close(res); +} + +static void UResourceBundleNative_cacheTimeZoneBundles(JNIEnv* env, jclass) { + openDirectAndCloseRes("zoneinfo64"); + openDirectAndCloseRes("timezoneTypes"); + openDirectAndCloseRes("metaZones"); + openDirectAndCloseRes("windowsZones"); +} + +static JNINativeMethod gMethods[] = { + NATIVE_METHOD(UResourceBundleNative, cacheTimeZoneBundles, "()V"), +}; + +void register_com_android_icu_util_UResourceBundleNative(JNIEnv* env) { + jniRegisterNativeMethods(env, "com/android/icu/util/UResourceBundleNative", gMethods, NELEM(gMethods)); +} |