OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008 The Android Open Source Project | 2 * Copyright (C) 2008 The Android Open Source Project |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
5 * you may not use this file except in compliance with 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 | 6 * You may obtain a copy of the License at |
7 * | 7 * |
8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
9 * | 9 * |
10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
11 * distributed under the License is distributed on an "AS IS" BASIS, | 11 * distributed under the License is distributed on an "AS IS" BASIS, |
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 * See the License for the specific language governing permissions and | 13 * See the License for the specific language governing permissions and |
14 * limitations under the License. | 14 * limitations under the License. |
15 */ | 15 */ |
16 | 16 |
17 #include <hardware/hardware.h> | 17 #include <hardware/hardware.h> |
18 | 18 |
19 #include <cutils/properties.h> | 19 #include <cutils/properties.h> |
20 | 20 |
21 #include <dlfcn.h> | 21 #include <dlfcn.h> |
22 #include <string.h> | 22 #include <string.h> |
23 #include <pthread.h> | 23 #include <pthread.h> |
24 #include <errno.h> | 24 #include <errno.h> |
25 #include <limits.h> | 25 #include <limits.h> |
26 #include <stdlib.h> | |
26 | 27 |
27 #define LOG_TAG "HAL" | 28 #define LOG_TAG "HAL" |
29 #ifdef ANDROID | |
28 #include <utils/Log.h> | 30 #include <utils/Log.h> |
31 #else | |
32 #include <stdio.h> | |
33 #include <unistd.h> | |
34 #include <log/log.h> | |
35 #endif | |
36 | |
37 #if defined(__LP64__) | |
38 #define _64 "64" | |
39 #else | |
40 #define _64 "" | |
41 #endif | |
29 | 42 |
30 /** Base path of the hal modules */ | 43 /** Base path of the hal modules */ |
31 #if defined(__LP64__) | 44 #ifndef HAL_LIBRARY_PATH1 |
32 #define HAL_LIBRARY_PATH1 "/system/lib64/hw" | 45 #define HAL_LIBRARY_PATH1 "/system/lib" _64 "/hw" |
33 #define HAL_LIBRARY_PATH2 "/vendor/lib64/hw" | 46 #endif |
34 #else | 47 #ifndef HAL_LIBRARY_PATH2 |
35 #define HAL_LIBRARY_PATH1 "/system/lib/hw" | 48 #define HAL_LIBRARY_PATH2 "/vendor/lib" _64 "/hw" |
36 #define HAL_LIBRARY_PATH2 "/vendor/lib/hw" | |
37 #endif | 49 #endif |
38 | 50 |
39 /** | 51 /** |
40 * There are a set of variant filename for modules. The form of the filename | 52 * There are a set of variant filename for modules. The form of the filename |
41 * is "<MODULE_ID>.variant.so" so for the led module the Dream variants | 53 * is "<MODULE_ID>.variant.so" so for the led module the Dream variants |
42 * of base "ro.product.board", "ro.board.platform" and "ro.arch" would be: | 54 * of base "ro.product.board", "ro.board.platform" and "ro.arch" would be: |
43 * | 55 * |
44 * led.trout.so | 56 * led.trout.so |
45 * led.msm7k.so | 57 * led.msm7k.so |
46 * led.ARMV6.so | 58 * led.ARMV6.so |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 return status; | 134 return status; |
123 } | 135 } |
124 | 136 |
125 /* | 137 /* |
126 * Check if a HAL with given name and subname exists, if so return 0, otherwise | 138 * Check if a HAL with given name and subname exists, if so return 0, otherwise |
127 * otherwise return negative. On success path will contain the path to the HAL. | 139 * otherwise return negative. On success path will contain the path to the HAL. |
128 */ | 140 */ |
129 static int hw_module_exists(char *path, size_t path_len, const char *name, | 141 static int hw_module_exists(char *path, size_t path_len, const char *name, |
130 const char *subname) | 142 const char *subname) |
131 { | 143 { |
144 char *hal_library_path = getenv("HAL_LIBRARY_PATH"); | |
rjkroege
2014/05/02 20:38:26
upon reflection, reading from the environment seem
| |
145 if (hal_library_path) { | |
146 snprintf(path, path_len, "%s/%s.%s.so", | |
147 hal_library_path, name, subname); | |
148 if (access(path, R_OK) == 0) | |
149 return 0; | |
150 } | |
151 | |
132 snprintf(path, path_len, "%s/%s.%s.so", | 152 snprintf(path, path_len, "%s/%s.%s.so", |
133 HAL_LIBRARY_PATH2, name, subname); | 153 HAL_LIBRARY_PATH2, name, subname); |
134 if (access(path, R_OK) == 0) | 154 if (access(path, R_OK) == 0) |
135 return 0; | 155 return 0; |
136 | 156 |
137 snprintf(path, path_len, "%s/%s.%s.so", | 157 snprintf(path, path_len, "%s/%s.%s.so", |
138 HAL_LIBRARY_PATH1, name, subname); | 158 HAL_LIBRARY_PATH1, name, subname); |
139 if (access(path, R_OK) == 0) | 159 if (access(path, R_OK) == 0) |
140 return 0; | 160 return 0; |
141 | 161 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 found: | 211 found: |
192 /* load the module, if this fails, we're doomed, and we should not try | 212 /* load the module, if this fails, we're doomed, and we should not try |
193 * to load a different variant. */ | 213 * to load a different variant. */ |
194 return load(class_id, path, module); | 214 return load(class_id, path, module); |
195 } | 215 } |
196 | 216 |
197 int hw_get_module(const char *id, const struct hw_module_t **module) | 217 int hw_get_module(const char *id, const struct hw_module_t **module) |
198 { | 218 { |
199 return hw_get_module_by_class(id, NULL, module); | 219 return hw_get_module_by_class(id, NULL, module); |
200 } | 220 } |
OLD | NEW |