nativeloader: refactor FindNamespaceByClassLoader method
FindNamespaceByClassLoader returns android_namespace_t* to make
it suitable for exporting this functionality.
Bug: http://b/27189432
Change-Id: Ifef3de753192178e0184fb114596fe956fde2826
(cherry picked from commit 34fa704df4
)
This commit is contained in:
parent
32912090e6
commit
c914ebd484
|
@ -81,10 +81,10 @@ class LibraryNamespaces {
|
|||
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
|
||||
auto it = FindNamespaceByClassLoader(env, class_loader);
|
||||
android_namespace_t* ns = FindNamespaceByClassLoader(env, class_loader);
|
||||
|
||||
if (it != namespaces_.end()) {
|
||||
return it->second;
|
||||
if (ns != nullptr) {
|
||||
return ns;
|
||||
}
|
||||
|
||||
uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED;
|
||||
|
@ -92,14 +92,13 @@ class LibraryNamespaces {
|
|||
namespace_type |= ANDROID_NAMESPACE_TYPE_SHARED;
|
||||
}
|
||||
|
||||
android_namespace_t* ns =
|
||||
android_create_namespace("classloader-namespace",
|
||||
nullptr,
|
||||
library_path.c_str(),
|
||||
namespace_type,
|
||||
java_permitted_path != nullptr ?
|
||||
permitted_path.c_str() :
|
||||
nullptr);
|
||||
ns = android_create_namespace("classloader-namespace",
|
||||
nullptr,
|
||||
library_path.c_str(),
|
||||
namespace_type,
|
||||
java_permitted_path != nullptr ?
|
||||
permitted_path.c_str() :
|
||||
nullptr);
|
||||
|
||||
namespaces_.push_back(std::make_pair(env->NewWeakGlobalRef(class_loader), ns));
|
||||
|
||||
|
@ -133,12 +132,12 @@ class LibraryNamespaces {
|
|||
return initialized_;
|
||||
}
|
||||
|
||||
std::vector<std::pair<jweak, android_namespace_t*>>::const_iterator
|
||||
FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) {
|
||||
return std::find_if(namespaces_.begin(), namespaces_.end(),
|
||||
[&](const std::pair<jweak, android_namespace_t*>& value) {
|
||||
return env->IsSameObject(value.first, class_loader);
|
||||
});
|
||||
android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) {
|
||||
auto it = std::find_if(namespaces_.begin(), namespaces_.end(),
|
||||
[&](const std::pair<jweak, android_namespace_t*>& value) {
|
||||
return env->IsSameObject(value.first, class_loader);
|
||||
});
|
||||
return it != namespaces_.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
bool initialized_;
|
||||
|
|
Loading…
Reference in New Issue