• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 /*
3  * Copyright (C) 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package android.icu.platform;
19 
20 import java.util.ArrayList;
21 import java.util.List;
22 
23 /**
24  * Android-added: Used by {@link android.icu.impl.ICUBinary} to locate ICU data files.
25  * The paths to ICU data files are generated dynamically from environment variables because
26  * the paths are different in various test environments. Thus, the paths can't be generated into
27  * ICUConfig.properties in the compile-time, and generated by this class instead.
28  *
29  * {@link com.android.i18n.timezone.TimeZoneDataFiles} holds the information related to other
30  * timezone data files.
31  * @hide Only a subset of ICU is exposed in Android
32  */
33 public class AndroidDataFiles {
34     /**
35      * The below are public to be used by {@link com.android.i18n.timezone.TimeZoneDataFiles}.
36      */
37     public static final String ANDROID_ROOT_ENV = "ANDROID_ROOT";
38     public static final String ANDROID_I18N_ROOT_ENV = "ANDROID_I18N_ROOT";
39     public static final String ANDROID_TZDATA_ROOT_ENV = "ANDROID_TZDATA_ROOT";
40 
41     /**
42      * This is identical to
43      * {@link com.android.i18n.timezone.TzDataSetVersion#CURRENT_FORMAT_MAJOR_VERSION}, but because
44      * dependency is in the opposite direction we can't refer to that field from this class.
45      * TzDataSetVersionTest ensures that their values are the same.
46      */
47     // VisibleForTesting
48     // LINT.IfChange
49     public static final int CURRENT_MAJOR_VERSION = 8;
50     // LINT.ThenChange(external/icu/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/TzDataSetVersion.java)
51 
getTimeZoneModuleFile(String fileName)52     private static String getTimeZoneModuleFile(String fileName) {
53         return System.getenv(ANDROID_TZDATA_ROOT_ENV) + "/etc/" + fileName;
54     }
55 
getTimeZoneModuleIcuFile(String fileName)56     private static String getTimeZoneModuleIcuFile(String fileName) {
57         return getTimeZoneModuleFile("tz/versioned/" + CURRENT_MAJOR_VERSION + "/icu/" + fileName);
58     }
59 
60     // VisibleForTesting
getI18nModuleIcuFile(String fileName)61     public static String getI18nModuleIcuFile(String fileName) {
62         return getI18nModuleFile("icu/" + fileName);
63     }
64 
getI18nModuleFile(String fileName)65     private static String getI18nModuleFile(String fileName) {
66         return System.getenv(ANDROID_I18N_ROOT_ENV) + "/etc/" + fileName;
67     }
68 
generateIcuDataPath()69     public static String generateIcuDataPath() {
70         List<String> paths = new ArrayList<>(2);
71 
72         // Note: This logic below should match the logic in IcuRegistration.cpp in external/icu/
73         // to ensure consistent behavior between ICU4C and ICU4J.
74 
75         // ICU should look for a mounted time zone module file in /apex. This is used for
76         // time zone data that can be updated with an APEX file.
77         String timeZoneModuleIcuDataPath = getTimeZoneModuleIcuFile("");
78         paths.add(timeZoneModuleIcuDataPath);
79 
80         // ICU should always look in the i18n module path as this is where most of the data
81         // can be found.
82         String i18nModuleIcuDataPath = getI18nModuleIcuFile("");
83         paths.add(i18nModuleIcuDataPath);
84 
85         return String.join(":", paths);
86     }
87 }
88