1*0e209d39SAndroid Build Coastguard Worker /* 2*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project 3*0e209d39SAndroid Build Coastguard Worker * 4*0e209d39SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*0e209d39SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*0e209d39SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*0e209d39SAndroid Build Coastguard Worker * 8*0e209d39SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*0e209d39SAndroid Build Coastguard Worker * 10*0e209d39SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*0e209d39SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*0e209d39SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*0e209d39SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*0e209d39SAndroid Build Coastguard Worker * limitations under the License. 15*0e209d39SAndroid Build Coastguard Worker */ 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Worker #include <stdbool.h> 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #include "androidicuinit/android_icu_init.h" 20*0e209d39SAndroid Build Coastguard Worker #include "IcuRegistration.h" 21*0e209d39SAndroid Build Coastguard Worker android_icu_init()22*0e209d39SAndroid Build Coastguard Workervoid android_icu_init() { 23*0e209d39SAndroid Build Coastguard Worker bool runAndroidInit = false; 24*0e209d39SAndroid Build Coastguard Worker 25*0e209d39SAndroid Build Coastguard Worker // We know that the environment variables are exported early in init.environ.rc on Android. 26*0e209d39SAndroid Build Coastguard Worker #ifdef __ANDROID__ 27*0e209d39SAndroid Build Coastguard Worker #ifdef ANDROID_ICU_NO_DAT 28*0e209d39SAndroid Build Coastguard Worker // If we're intentionally building ICU on Android without the .dat file, no 29*0e209d39SAndroid Build Coastguard Worker // need to run init. 30*0e209d39SAndroid Build Coastguard Worker runAndroidInit = false; 31*0e209d39SAndroid Build Coastguard Worker #else // !ANDROID_ICU_NO_DAT 32*0e209d39SAndroid Build Coastguard Worker runAndroidInit = true; 33*0e209d39SAndroid Build Coastguard Worker #endif 34*0e209d39SAndroid Build Coastguard Worker #else // ART host testing environment has these env variables set. 35*0e209d39SAndroid Build Coastguard Worker runAndroidInit = getenv("ANDROID_DATA") != NULL && 36*0e209d39SAndroid Build Coastguard Worker getenv("ANDROID_TZDATA_ROOT") != NULL && 37*0e209d39SAndroid Build Coastguard Worker getenv("ANDROID_I18N_ROOT") != NULL; 38*0e209d39SAndroid Build Coastguard Worker #endif 39*0e209d39SAndroid Build Coastguard Worker 40*0e209d39SAndroid Build Coastguard Worker if (runAndroidInit) { 41*0e209d39SAndroid Build Coastguard Worker if (!android_icu_is_registered()) { 42*0e209d39SAndroid Build Coastguard Worker android_icu_register(); 43*0e209d39SAndroid Build Coastguard Worker } else { 44*0e209d39SAndroid Build Coastguard Worker AICU_LOGE("libicuuc has already been initialized but android_icu_init() is called."); 45*0e209d39SAndroid Build Coastguard Worker } 46*0e209d39SAndroid Build Coastguard Worker } 47*0e209d39SAndroid Build Coastguard Worker } 48*0e209d39SAndroid Build Coastguard Worker android_icu_cleanup()49*0e209d39SAndroid Build Coastguard Workervoid android_icu_cleanup() { 50*0e209d39SAndroid Build Coastguard Worker if (android_icu_is_registered()) { 51*0e209d39SAndroid Build Coastguard Worker android_icu_deregister(); 52*0e209d39SAndroid Build Coastguard Worker } else { 53*0e209d39SAndroid Build Coastguard Worker AICU_LOGW("libicuuc is not initialized and possibly never used, " 54*0e209d39SAndroid Build Coastguard Worker "but android_icu_cleanup() is called."); 55*0e209d39SAndroid Build Coastguard Worker } 56*0e209d39SAndroid Build Coastguard Worker } 57