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) |
| 37 | REGISTER(register_com_android_icu_util_regex_NativePattern); |
| 38 | REGISTER(register_com_android_icu_util_regex_NativeMatcher); |
| 39 | #undef REGISTER |
| 40 | |
| 41 | JniConstants::Initialize(env); |
| 42 | return JNI_VERSION_1_6; |
| 43 | } |
| 44 | |
| 45 | // ART calls this on shutdown, do any global cleanup here. |
| 46 | // -- Very important if we restart multiple ART runtimes in the same process to reset the state. |
| 47 | void JNI_OnUnload(JavaVM*, void*) { |
| 48 | // Don't use the JavaVM in this method. ART only calls this once all threads are |
| 49 | // unregistered. |
| 50 | ALOGV("libicu_jni JNI_OnUnload"); |
| 51 | JniConstants::Invalidate(); |
| 52 | } |