blob: 3b42f8093be3a095cc5b55aea403e9919e2a00d6 [file] [log] [blame]
Jesse Hall90b25ed2016-12-12 12:56:46 -08001/*
2 * Copyright 2017 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
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Jesse Hall90b25ed2016-12-12 12:56:46 -080019//#define LOG_NDEBUG 1
20#define LOG_TAG "GraphicsEnv"
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080021
Jiyong Park27c39e12017-05-08 13:00:02 +090022#include <graphicsenv/GraphicsEnv.h>
Jesse Hall90b25ed2016-12-12 12:56:46 -080023
Yiwei Zhang64d89212018-11-27 19:58:29 -080024#include <dlfcn.h>
Tim Van Patten5f744f12018-12-12 11:46:21 -070025#include <unistd.h>
Yiwei Zhang64d89212018-11-27 19:58:29 -080026
27#include <android-base/file.h>
28#include <android-base/properties.h>
29#include <android-base/strings.h>
30#include <android/dlext.h>
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080031#include <binder/IServiceManager.h>
Yiwei Zhang64d89212018-11-27 19:58:29 -080032#include <cutils/properties.h>
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080033#include <graphicsenv/IGpuService.h>
Yiwei Zhang64d89212018-11-27 19:58:29 -080034#include <log/log.h>
Cody Northrop629ce4e2018-10-15 07:22:09 -060035#include <sys/prctl.h>
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080036#include <utils/Trace.h>
Cody Northrop629ce4e2018-10-15 07:22:09 -060037
Tim Van Patten5f744f12018-12-12 11:46:21 -070038#include <memory>
Tim Van Patten5f744f12018-12-12 11:46:21 -070039#include <string>
40
Jesse Hall57de0ff2017-05-05 16:41:35 -070041// TODO(b/37049319) Get this from a header once one exists
42extern "C" {
Yiwei Zhang64d89212018-11-27 19:58:29 -080043android_namespace_t* android_get_exported_namespace(const char*);
44android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path,
45 const char* default_library_path, uint64_t type,
46 const char* permitted_when_isolated_path,
47 android_namespace_t* parent);
48bool android_link_namespaces(android_namespace_t* from, android_namespace_t* to,
49 const char* shared_libs_sonames);
Jiyong Park9b816a82018-01-02 17:37:37 +090050
Yiwei Zhang64d89212018-11-27 19:58:29 -080051enum {
52 ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
53 ANDROID_NAMESPACE_TYPE_SHARED = 2,
54};
Jesse Hall57de0ff2017-05-05 16:41:35 -070055}
56
Tim Van Patten5f744f12018-12-12 11:46:21 -070057// TODO(ianelliott@): Get the following from an ANGLE header:
58#define CURRENT_ANGLE_API_VERSION 2 // Current API verion we are targetting
59// Version-2 API:
60typedef bool (*fpANGLEGetFeatureSupportUtilAPIVersion)(unsigned int* versionToUse);
61typedef bool (*fpANGLEAndroidParseRulesString)(const char* rulesString, void** rulesHandle,
62 int* rulesVersion);
63typedef bool (*fpANGLEGetSystemInfo)(void** handle);
64typedef bool (*fpANGLEAddDeviceInfoToSystemInfo)(const char* deviceMfr, const char* deviceModel,
65 void* handle);
66typedef bool (*fpANGLEShouldBeUsedForApplication)(void* rulesHandle, int rulesVersion,
67 void* systemInfoHandle, const char* appName);
68typedef bool (*fpANGLEFreeRulesHandle)(void* handle);
69typedef bool (*fpANGLEFreeSystemInfoHandle)(void* handle);
70
Jesse Hall90b25ed2016-12-12 12:56:46 -080071namespace android {
72
Yiwei Zhang64d89212018-11-27 19:58:29 -080073enum NativeLibrary {
74 LLNDK = 0,
75 VNDKSP = 1,
76};
77
78static constexpr const char* kNativeLibrariesSystemConfigPath[] = {"/etc/llndk.libraries.txt",
79 "/etc/vndksp.libraries.txt"};
80
81static std::string vndkVersionStr() {
82#ifdef __BIONIC__
83 std::string version = android::base::GetProperty("ro.vndk.version", "");
84 if (version != "" && version != "current") {
85 return "." + version;
86 }
87#endif
88 return "";
89}
90
91static void insertVndkVersionStr(std::string* fileName) {
92 LOG_ALWAYS_FATAL_IF(!fileName, "fileName should never be nullptr");
93 size_t insertPos = fileName->find_last_of(".");
94 if (insertPos == std::string::npos) {
95 insertPos = fileName->length();
96 }
97 fileName->insert(insertPos, vndkVersionStr());
98}
99
100static bool readConfig(const std::string& configFile, std::vector<std::string>* soNames) {
101 // Read list of public native libraries from the config file.
102 std::string fileContent;
103 if (!base::ReadFileToString(configFile, &fileContent)) {
104 return false;
105 }
106
107 std::vector<std::string> lines = base::Split(fileContent, "\n");
108
109 for (auto& line : lines) {
110 auto trimmedLine = base::Trim(line);
111 if (!trimmedLine.empty()) {
112 soNames->push_back(trimmedLine);
113 }
114 }
115
116 return true;
117}
118
119static const std::string getSystemNativeLibraries(NativeLibrary type) {
120 static const char* androidRootEnv = getenv("ANDROID_ROOT");
121 static const std::string rootDir = androidRootEnv != nullptr ? androidRootEnv : "/system";
122
123 std::string nativeLibrariesSystemConfig = rootDir + kNativeLibrariesSystemConfigPath[type];
124
125 insertVndkVersionStr(&nativeLibrariesSystemConfig);
126
127 std::vector<std::string> soNames;
128 if (!readConfig(nativeLibrariesSystemConfig, &soNames)) {
129 ALOGE("Failed to retrieve library names from %s", nativeLibrariesSystemConfig.c_str());
130 return "";
131 }
132
133 return base::Join(soNames, ':');
134}
135
Jesse Hall90b25ed2016-12-12 12:56:46 -0800136/*static*/ GraphicsEnv& GraphicsEnv::getInstance() {
137 static GraphicsEnv env;
138 return env;
139}
140
Cody Northrop629ce4e2018-10-15 07:22:09 -0600141int GraphicsEnv::getCanLoadSystemLibraries() {
142 if (property_get_bool("ro.debuggable", false) && prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) {
143 // Return an integer value since this crosses library boundaries
144 return 1;
145 }
146 return 0;
147}
148
Jesse Hall90b25ed2016-12-12 12:56:46 -0800149void GraphicsEnv::setDriverPath(const std::string path) {
150 if (!mDriverPath.empty()) {
Yiwei Zhang64d89212018-11-27 19:58:29 -0800151 ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(),
152 path.c_str());
Jesse Hall90b25ed2016-12-12 12:56:46 -0800153 return;
154 }
155 ALOGV("setting driver path to '%s'", path.c_str());
156 mDriverPath = path;
157}
158
Yiwei Zhang8c8c1812019-02-04 18:56:38 -0800159void GraphicsEnv::setGpuStats(const std::string driverPackageName,
160 const std::string driverVersionName, const uint64_t driverVersionCode,
161 const std::string appPackageName) {
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800162 ATRACE_CALL();
163
164 ALOGV("setGpuStats:\n"
165 "\tdriverPackageName[%s]\n"
166 "\tdriverVersionName[%s]\n"
167 "\tdriverVersionCode[%llu]\n"
168 "\tappPackageName[%s]\n",
169 driverPackageName.c_str(), driverVersionName.c_str(),
170 (unsigned long long)driverVersionCode, appPackageName.c_str());
171
Yiwei Zhang8c8c1812019-02-04 18:56:38 -0800172 mGpuStats = {
173 .driverPackageName = driverPackageName,
174 .driverVersionName = driverVersionName,
175 .driverVersionCode = driverVersionCode,
176 .appPackageName = appPackageName,
177 };
178}
179
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800180void GraphicsEnv::sendGpuStats() {
181 ATRACE_CALL();
182
183 // Do not sendGpuStats for those skipping the GraphicsEnvironment setup
184 if (mGpuStats.appPackageName.empty()) return;
185
186 ALOGV("sendGpuStats:\n"
187 "\tdriverPackageName[%s]\n"
188 "\tdriverVersionName[%s]\n"
189 "\tdriverVersionCode[%llu]\n"
190 "\tappPackageName[%s]\n",
191 mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(),
192 (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str());
193
194 const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu"));
195 if (!binder) {
196 ALOGE("Failed to get gpu service for [%s]", mGpuStats.appPackageName.c_str());
197 return;
198 }
199
200 interface_cast<IGpuService>(binder)->setGpuStats(mGpuStats.driverPackageName,
201 mGpuStats.driverVersionName,
202 mGpuStats.driverVersionCode,
203 mGpuStats.appPackageName);
204}
205
Tim Van Patten5f744f12018-12-12 11:46:21 -0700206void* GraphicsEnv::loadLibrary(std::string name) {
207 const android_dlextinfo dlextinfo = {
208 .flags = ANDROID_DLEXT_USE_NAMESPACE,
209 .library_namespace = getAngleNamespace(),
210 };
211
212 std::string libName = std::string("lib") + name + "_angle.so";
213
214 void* so = android_dlopen_ext(libName.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo);
215
216 if (so) {
217 ALOGD("dlopen_ext from APK (%s) success at %p", libName.c_str(), so);
218 return so;
219 } else {
220 ALOGE("dlopen_ext(\"%s\") failed: %s", libName.c_str(), dlerror());
221 }
222
223 return nullptr;
224}
225
226bool GraphicsEnv::checkAngleRules(void* so) {
227 char manufacturer[PROPERTY_VALUE_MAX];
228 char model[PROPERTY_VALUE_MAX];
229 property_get("ro.product.manufacturer", manufacturer, "UNSET");
230 property_get("ro.product.model", model, "UNSET");
231
232 auto ANGLEGetFeatureSupportUtilAPIVersion =
233 (fpANGLEGetFeatureSupportUtilAPIVersion)dlsym(so,
234 "ANGLEGetFeatureSupportUtilAPIVersion");
235
236 if (!ANGLEGetFeatureSupportUtilAPIVersion) {
237 ALOGW("Cannot find ANGLEGetFeatureSupportUtilAPIVersion function");
238 return false;
239 }
240
241 // Negotiate the interface version by requesting most recent known to the platform
242 unsigned int versionToUse = CURRENT_ANGLE_API_VERSION;
243 if (!(ANGLEGetFeatureSupportUtilAPIVersion)(&versionToUse)) {
244 ALOGW("Cannot use ANGLE feature-support library, it is older than supported by EGL, "
245 "requested version %u",
246 versionToUse);
247 return false;
248 }
249
250 // Add and remove versions below as needed
251 bool useAngle = false;
252 switch (versionToUse) {
253 case 2: {
254 ALOGV("Using version %d of ANGLE feature-support library", versionToUse);
255 void* rulesHandle = nullptr;
256 int rulesVersion = 0;
257 void* systemInfoHandle = nullptr;
258
259 // Get the symbols for the feature-support-utility library:
260#define GET_SYMBOL(symbol) \
261 fp##symbol symbol = (fp##symbol)dlsym(so, #symbol); \
262 if (!symbol) { \
263 ALOGW("Cannot find " #symbol " in ANGLE feature-support library"); \
264 break; \
265 }
266 GET_SYMBOL(ANGLEAndroidParseRulesString);
267 GET_SYMBOL(ANGLEGetSystemInfo);
268 GET_SYMBOL(ANGLEAddDeviceInfoToSystemInfo);
269 GET_SYMBOL(ANGLEShouldBeUsedForApplication);
270 GET_SYMBOL(ANGLEFreeRulesHandle);
271 GET_SYMBOL(ANGLEFreeSystemInfoHandle);
272
273 // Parse the rules, obtain the SystemInfo, and evaluate the
274 // application against the rules:
275 if (!(ANGLEAndroidParseRulesString)(mRulesBuffer.data(), &rulesHandle, &rulesVersion)) {
276 ALOGW("ANGLE feature-support library cannot parse rules file");
277 break;
278 }
279 if (!(ANGLEGetSystemInfo)(&systemInfoHandle)) {
280 ALOGW("ANGLE feature-support library cannot obtain SystemInfo");
281 break;
282 }
283 if (!(ANGLEAddDeviceInfoToSystemInfo)(manufacturer, model, systemInfoHandle)) {
284 ALOGW("ANGLE feature-support library cannot add device info to SystemInfo");
285 break;
286 }
287 useAngle = (ANGLEShouldBeUsedForApplication)(rulesHandle, rulesVersion,
288 systemInfoHandle, mAngleAppName.c_str());
289 (ANGLEFreeRulesHandle)(rulesHandle);
290 (ANGLEFreeSystemInfoHandle)(systemInfoHandle);
291 } break;
292
293 default:
294 ALOGW("Version %u of ANGLE feature-support library is NOT supported.", versionToUse);
295 }
296
297 ALOGV("Close temporarily-loaded ANGLE opt-in/out logic");
298 return useAngle;
299}
300
301bool GraphicsEnv::shouldUseAngle(std::string appName) {
302 if (appName != mAngleAppName) {
303 // Make sure we are checking the app we were init'ed for
304 ALOGE("App name does not match: expected '%s', got '%s'", mAngleAppName.c_str(),
305 appName.c_str());
306 return false;
307 }
308
309 return shouldUseAngle();
310}
311
312bool GraphicsEnv::shouldUseAngle() {
313 // Make sure we are init'ed
314 if (mAngleAppName.empty()) {
Cody Northrop2d7af742019-01-24 16:55:03 -0700315 ALOGV("App name is empty. setAngleInfo() has not been called to enable ANGLE.");
Tim Van Patten5f744f12018-12-12 11:46:21 -0700316 return false;
317 }
318
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700319 return (mUseAngle == YES) ? true : false;
Tim Van Patten5f744f12018-12-12 11:46:21 -0700320}
321
322void GraphicsEnv::updateUseAngle() {
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700323 mUseAngle = NO;
Tim Van Patten5f744f12018-12-12 11:46:21 -0700324
325 const char* ANGLE_PREFER_ANGLE = "angle";
326 const char* ANGLE_PREFER_NATIVE = "native";
327
328 if (mAngleDeveloperOptIn == ANGLE_PREFER_ANGLE) {
329 ALOGV("User set \"Developer Options\" to force the use of ANGLE");
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700330 mUseAngle = YES;
Tim Van Patten5f744f12018-12-12 11:46:21 -0700331 } else if (mAngleDeveloperOptIn == ANGLE_PREFER_NATIVE) {
332 ALOGV("User set \"Developer Options\" to force the use of Native");
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700333 mUseAngle = NO;
Tim Van Patten5f744f12018-12-12 11:46:21 -0700334 } else {
335 // The "Developer Options" value wasn't set to force the use of ANGLE. Need to temporarily
336 // load ANGLE and call the updatable opt-in/out logic:
Cody Northropc15d3822019-01-17 10:26:47 -0700337 void* featureSo = loadLibrary("feature_support");
Tim Van Patten5f744f12018-12-12 11:46:21 -0700338 if (featureSo) {
339 ALOGV("loaded ANGLE's opt-in/out logic from namespace");
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700340 mUseAngle = checkAngleRules(featureSo) ? YES : NO;
Tim Van Patten5f744f12018-12-12 11:46:21 -0700341 dlclose(featureSo);
342 featureSo = nullptr;
343 } else {
344 ALOGV("Could not load the ANGLE opt-in/out logic, cannot use ANGLE.");
345 }
346 }
347}
348
Courtney Goeltzenleuchterd41ef252018-09-26 14:37:42 -0600349void GraphicsEnv::setAngleInfo(const std::string path, const std::string appName,
Tim Van Pattena2a60a02018-11-09 16:51:15 -0700350 const std::string developerOptIn, const int rulesFd,
351 const long rulesOffset, const long rulesLength) {
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700352 if (mUseAngle != UNKNOWN) {
353 // We've already figured out an answer for this app, so just return.
354 ALOGV("Already evaluated the rules file for '%s': use ANGLE = %s", appName.c_str(),
355 (mUseAngle == YES) ? "true" : "false");
356 return;
357 }
358
Tim Van Patten5f744f12018-12-12 11:46:21 -0700359 ALOGV("setting ANGLE path to '%s'", path.c_str());
360 mAnglePath = path;
361 ALOGV("setting ANGLE app name to '%s'", appName.c_str());
362 mAngleAppName = appName;
363 ALOGV("setting ANGLE application opt-in to '%s'", developerOptIn.c_str());
364 mAngleDeveloperOptIn = developerOptIn;
Courtney Goeltzenleuchterd41ef252018-09-26 14:37:42 -0600365
Tim Van Patten5f744f12018-12-12 11:46:21 -0700366 lseek(rulesFd, rulesOffset, SEEK_SET);
367 mRulesBuffer = std::vector<char>(rulesLength + 1);
368 ssize_t numBytesRead = read(rulesFd, mRulesBuffer.data(), rulesLength);
369 if (numBytesRead < 0) {
370 ALOGE("Cannot read rules file: numBytesRead = %zd", numBytesRead);
371 numBytesRead = 0;
372 } else if (numBytesRead == 0) {
373 ALOGW("Empty rules file");
Courtney Goeltzenleuchterd41ef252018-09-26 14:37:42 -0600374 }
Tim Van Patten5f744f12018-12-12 11:46:21 -0700375 if (numBytesRead != rulesLength) {
376 ALOGW("Did not read all of the necessary bytes from the rules file."
377 "expected: %ld, got: %zd",
378 rulesLength, numBytesRead);
Tim Van Pattena2a60a02018-11-09 16:51:15 -0700379 }
Tim Van Patten5f744f12018-12-12 11:46:21 -0700380 mRulesBuffer[numBytesRead] = '\0';
Cody Northrop04e70432018-09-06 10:34:58 -0600381
Tim Van Patten5f744f12018-12-12 11:46:21 -0700382 // Update the current status of whether we should use ANGLE or not
383 updateUseAngle();
Cody Northrop1f00e172018-04-02 11:23:31 -0600384}
385
Victor Khimenko4819b522018-07-13 17:24:18 +0200386void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths) {
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600387 if (mLayerPaths.empty()) {
388 mLayerPaths = layerPaths;
389 mAppNamespace = appNamespace;
390 } else {
391 ALOGV("Vulkan layer search path already set, not clobbering with '%s' for namespace %p'",
Yiwei Zhang64d89212018-11-27 19:58:29 -0800392 layerPaths.c_str(), appNamespace);
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600393 }
394}
395
Victor Khimenko4819b522018-07-13 17:24:18 +0200396NativeLoaderNamespace* GraphicsEnv::getAppNamespace() {
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600397 return mAppNamespace;
398}
399
Tim Van Patten5f744f12018-12-12 11:46:21 -0700400std::string& GraphicsEnv::getAngleAppName() {
401 return mAngleAppName;
Cody Northrop04e70432018-09-06 10:34:58 -0600402}
403
Courtney Goeltzenleuchter30ad2ab2018-10-30 08:20:44 -0600404const std::string& GraphicsEnv::getLayerPaths() {
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600405 return mLayerPaths;
406}
407
Courtney Goeltzenleuchter30ad2ab2018-10-30 08:20:44 -0600408const std::string& GraphicsEnv::getDebugLayers() {
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600409 return mDebugLayers;
410}
411
Cody Northropb9b01b62018-10-23 13:13:10 -0600412const std::string& GraphicsEnv::getDebugLayersGLES() {
413 return mDebugLayersGLES;
414}
415
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600416void GraphicsEnv::setDebugLayers(const std::string layers) {
417 mDebugLayers = layers;
418}
419
Cody Northropb9b01b62018-10-23 13:13:10 -0600420void GraphicsEnv::setDebugLayersGLES(const std::string layers) {
421 mDebugLayersGLES = layers;
422}
423
Jesse Hall53457db2016-12-14 16:54:06 -0800424android_namespace_t* GraphicsEnv::getDriverNamespace() {
425 static std::once_flag once;
426 std::call_once(once, [this]() {
Yiwei Zhang64d89212018-11-27 19:58:29 -0800427 if (mDriverPath.empty()) return;
428
429 auto vndkNamespace = android_get_exported_namespace("vndk");
430 if (!vndkNamespace) return;
431
Jesse Hall57de0ff2017-05-05 16:41:35 -0700432 mDriverNamespace = android_create_namespace("gfx driver",
Peiyong Lin2e9c74c2018-10-24 11:18:07 -0700433 mDriverPath.c_str(), // ld_library_path
Jesse Hall57de0ff2017-05-05 16:41:35 -0700434 mDriverPath.c_str(), // default_library_path
Yiwei Zhang64d89212018-11-27 19:58:29 -0800435 ANDROID_NAMESPACE_TYPE_ISOLATED,
Jesse Hall57de0ff2017-05-05 16:41:35 -0700436 nullptr, // permitted_when_isolated_path
Yiwei Zhang64d89212018-11-27 19:58:29 -0800437 nullptr);
438
439 const std::string llndkLibraries = getSystemNativeLibraries(NativeLibrary::LLNDK);
440 if (llndkLibraries.empty()) {
441 mDriverNamespace = nullptr;
442 return;
443 }
444 if (!android_link_namespaces(mDriverNamespace, nullptr, llndkLibraries.c_str())) {
445 ALOGE("Failed to link default namespace[%s]", dlerror());
446 mDriverNamespace = nullptr;
447 return;
448 }
449
450 const std::string vndkspLibraries = getSystemNativeLibraries(NativeLibrary::VNDKSP);
451 if (vndkspLibraries.empty()) {
452 mDriverNamespace = nullptr;
453 return;
454 }
455 if (!android_link_namespaces(mDriverNamespace, vndkNamespace, vndkspLibraries.c_str())) {
456 ALOGE("Failed to link vndk namespace[%s]", dlerror());
457 mDriverNamespace = nullptr;
458 return;
459 }
Jesse Hall53457db2016-12-14 16:54:06 -0800460 });
Yiwei Zhang64d89212018-11-27 19:58:29 -0800461
Jesse Hall53457db2016-12-14 16:54:06 -0800462 return mDriverNamespace;
463}
464
Cody Northrop1f00e172018-04-02 11:23:31 -0600465android_namespace_t* GraphicsEnv::getAngleNamespace() {
Cody Northrop3892cfa2019-01-30 10:03:12 -0700466 std::lock_guard<std::mutex> lock(mNamespaceMutex);
Cody Northrop1f00e172018-04-02 11:23:31 -0600467
Cody Northrop3892cfa2019-01-30 10:03:12 -0700468 if (mAngleNamespace) {
469 return mAngleNamespace;
470 }
471
472 if (mAnglePath.empty()) {
473 ALOGV("mAnglePath is empty, not creating ANGLE namespace");
474 return nullptr;
475 }
476
477 mAngleNamespace = android_create_namespace("ANGLE",
478 nullptr, // ld_library_path
479 mAnglePath.c_str(), // default_library_path
480 ANDROID_NAMESPACE_TYPE_SHARED |
481 ANDROID_NAMESPACE_TYPE_ISOLATED,
482 nullptr, // permitted_when_isolated_path
483 nullptr);
484
485 ALOGD_IF(!mAngleNamespace, "Could not create ANGLE namespace from default");
Cody Northrop1f00e172018-04-02 11:23:31 -0600486
487 return mAngleNamespace;
488}
489
Jesse Hall90b25ed2016-12-12 12:56:46 -0800490} // namespace android