2 * Copyright 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 //#define LOG_NDEBUG 1
18 #define LOG_TAG "GraphicsEnv"
19 #include <gui/GraphicsEnv.h>
24 #include <nativeloader/dlext_namespaces.h>
28 /*static*/ GraphicsEnv& GraphicsEnv::getInstance() {
29 static GraphicsEnv env;
33 void GraphicsEnv::setDriverPath(const std::string path) {
34 if (!mDriverPath.empty()) {
35 ALOGV("ignoring attempt to change driver path from '%s' to '%s'",
36 mDriverPath.c_str(), path.c_str());
39 ALOGV("setting driver path to '%s'", path.c_str());
43 android_namespace_t* GraphicsEnv::getDriverNamespace() {
44 static std::once_flag once;
45 std::call_once(once, [this]() {
46 // TODO; In the next version of Android, all graphics drivers will be
47 // loaded into a custom namespace. To minimize risk for this release,
48 // only updated drivers use a custom namespace.
50 // Additionally, the custom namespace will be
51 // ANDROID_NAMESPACE_TYPE_ISOLATED, and will only have access to a
52 // subset of the system.
53 if (mDriverPath.empty())
56 char defaultPath[PATH_MAX];
57 android_get_LD_LIBRARY_PATH(defaultPath, sizeof(defaultPath));
58 size_t defaultPathLen = strlen(defaultPath);
61 path.reserve(mDriverPath.size() + 1 + defaultPathLen);
62 path.append(mDriverPath);
64 path.append(defaultPath, defaultPathLen);
66 mDriverNamespace = android_create_namespace(
68 nullptr, // ld_library_path
69 path.c_str(), // default_library_path
70 ANDROID_NAMESPACE_TYPE_SHARED,
71 nullptr, // permitted_when_isolated_path
74 return mDriverNamespace;
77 } // namespace android