blob: ad3bebce1789be4741d599fbc6672f351d4b766a [file]
/*
* Copyright (C) 2026 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DiscoveredLayerLibrary.h"
#include <android-base/strings.h>
#include <log/log.h>
#include "LayerEnvironment.h"
namespace vulkan {
namespace layers {
std::shared_ptr<DynamicLibrary> DiscoveredLayerLibrary::Open(
const LayerEnvironment& env) const {
std::lock_guard<std::mutex> lock(mutex_);
// An automatic unloading (RAII) design pattern is used, so that only an
// Open() method is needed (Close() happens implicitly).
std::shared_ptr<DynamicLibrary> lib = loaded_lib_.lock();
if (!lib) {
auto* app_ns = env.GetAppNamespace();
bool is_graphics_path =
android::base::StartsWith(path_, kGraphicsMainlineModuleDir);
// Don't use app namespace for system/debug paths
bool is_system_path =
android::base::StartsWith(path_, kSystemPlatformLayerLibraryDir) ||
android::base::StartsWith(path_, kSystemSoCLayerLibraryDir) ||
android::base::StartsWith(path_, kSystemOEMLayerLibraryDir) ||
android::base::StartsWith(path_, kSystemDebugLayerLibraryDir);
if (is_graphics_path) {
ALOGV("Opening library %s in graphics namespace", path_.c_str());
lib = env.LoadLibraryInExportedNamespace(path_,
"com_android_graphics");
} else if (app_ns && !is_system_path) {
ALOGV("Opening library %s in app namespace", path_.c_str());
lib = env.LoadLibraryInNamespace(path_, app_ns);
} else {
ALOGV("Opening library %s", path_.c_str());
lib = env.LoadLibrary(path_);
}
loaded_lib_ = lib;
}
return lib;
}
} // namespace layers
} // namespace vulkan