| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 17 | //#define LOG_NDEBUG 1 | 
|  | 18 | #define LOG_TAG "GraphicsEnv" | 
| Mathias Agopian | 991d254 | 2017-02-06 13:51:32 -0800 | [diff] [blame] | 19 | #include <ui/GraphicsEnv.h> | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 20 |  | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 21 | #include <mutex> | 
|  | 22 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 23 | #include <log/log.h> | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 24 | #include <nativeloader/dlext_namespaces.h> | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 25 |  | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 26 | // TODO(b/37049319) Get this from a header once one exists | 
|  | 27 | extern "C" { | 
|  | 28 | android_namespace_t* android_get_exported_namespace(const char*); | 
|  | 29 | } | 
|  | 30 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 31 | namespace android { | 
|  | 32 |  | 
|  | 33 | /*static*/ GraphicsEnv& GraphicsEnv::getInstance() { | 
|  | 34 | static GraphicsEnv env; | 
|  | 35 | return env; | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | void GraphicsEnv::setDriverPath(const std::string path) { | 
|  | 39 | if (!mDriverPath.empty()) { | 
|  | 40 | ALOGV("ignoring attempt to change driver path from '%s' to '%s'", | 
|  | 41 | mDriverPath.c_str(), path.c_str()); | 
|  | 42 | return; | 
|  | 43 | } | 
|  | 44 | ALOGV("setting driver path to '%s'", path.c_str()); | 
|  | 45 | mDriverPath = path; | 
|  | 46 | } | 
|  | 47 |  | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 48 | android_namespace_t* GraphicsEnv::getDriverNamespace() { | 
|  | 49 | static std::once_flag once; | 
|  | 50 | std::call_once(once, [this]() { | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 51 | if (mDriverPath.empty()) | 
|  | 52 | return; | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 53 | // If the sphal namespace isn't configured for a device, don't support updatable drivers. | 
|  | 54 | // We need a parent namespace to inherit the default search path from. | 
|  | 55 | auto sphalNamespace = android_get_exported_namespace("sphal"); | 
|  | 56 | if (!sphalNamespace) return; | 
|  | 57 | mDriverNamespace = android_create_namespace("gfx driver", | 
|  | 58 | nullptr,             // ld_library_path | 
|  | 59 | mDriverPath.c_str(), // default_library_path | 
|  | 60 | ANDROID_NAMESPACE_TYPE_SHARED | | 
|  | 61 | ANDROID_NAMESPACE_TYPE_ISOLATED, | 
|  | 62 | nullptr, // permitted_when_isolated_path | 
|  | 63 | sphalNamespace); | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 64 | }); | 
|  | 65 | return mDriverNamespace; | 
|  | 66 | } | 
|  | 67 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 68 | } // namespace android | 
| Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 69 |  | 
|  | 70 | extern "C" android_namespace_t* android_getDriverNamespace() { | 
|  | 71 | return android::GraphicsEnv::getInstance().getDriverNamespace(); | 
|  | 72 | } |