Victor Chang | 92c3bcf | 2019-10-07 11:36:39 +0100 | [diff] [blame] | 1 | /* |
| 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. |
| 26 | jint 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 Chang | 93e3773 | 2019-11-04 18:53:56 +0000 | [diff] [blame] | 37 | REGISTER(register_com_android_icu_util_Icu4cMetadata); |
Victor Chang | 0df29ba | 2019-11-12 14:25:34 +0000 | [diff] [blame^] | 38 | REGISTER(register_com_android_icu_util_regex_PatternNative); |
| 39 | REGISTER(register_com_android_icu_util_regex_MatcherNative); |
Victor Chang | 37227bd | 2019-10-25 11:36:20 +0100 | [diff] [blame] | 40 | REGISTER(register_com_android_icu_util_charset_NativeConverter); |
Victor Chang | 92c3bcf | 2019-10-07 11:36:39 +0100 | [diff] [blame] | 41 | #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. |
| 49 | void 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 | } |