blob: 7d44f1c2cd1aa8b099c72e590af3950886df95ec [file] [log] [blame]
Victor Chang92c3bcf2019-10-07 11:36:39 +01001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "Register"
18
19#include <stdlib.h>
20#include <nativehelper/ScopedLocalFrame.h>
21#include <log/log.h>
22
23#include "JniConstants.h"
24
25// ART calls this on startup, so we can statically register all our native methods.
26jint JNI_OnLoad(JavaVM* vm, void*) {
27 ALOGV("libicu_jni JNI_OnLoad");
28 JNIEnv* env;
29 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
30 ALOGE("JavaVM::GetEnv() failed");
31 abort();
32 }
33
34 ScopedLocalFrame localFrame(env);
35
36#define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
Victor Chang93e37732019-11-04 18:53:56 +000037 REGISTER(register_com_android_icu_util_Icu4cMetadata);
Victor Chang0df29ba2019-11-12 14:25:34 +000038 REGISTER(register_com_android_icu_util_regex_PatternNative);
39 REGISTER(register_com_android_icu_util_regex_MatcherNative);
Victor Chang37227bd2019-10-25 11:36:20 +010040 REGISTER(register_com_android_icu_util_charset_NativeConverter);
Victor Chang92c3bcf2019-10-07 11:36:39 +010041#undef REGISTER
42
43 JniConstants::Initialize(env);
44 return JNI_VERSION_1_6;
45}
46
47// ART calls this on shutdown, do any global cleanup here.
48// -- Very important if we restart multiple ART runtimes in the same process to reset the state.
49void JNI_OnUnload(JavaVM*, void*) {
50 // Don't use the JavaVM in this method. ART only calls this once all threads are
51 // unregistered.
52 ALOGV("libicu_jni JNI_OnUnload");
53 JniConstants::Invalidate();
54}