From c914ebd4841ba9e5b8f446dfc5b6dfeecb56531f Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Mon, 22 Feb 2016 13:02:35 -0800 Subject: [PATCH] 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 34fa704df45c5f74aeb5230e4bf3930585cf32fb) --- libnativeloader/native_loader.cpp | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index a2d79e1f5..468bfc695 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -81,10 +81,10 @@ class LibraryNamespaces { std::lock_guard 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>::const_iterator - FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) { - return std::find_if(namespaces_.begin(), namespaces_.end(), - [&](const std::pair& 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& value) { + return env->IsSameObject(value.first, class_loader); + }); + return it != namespaces_.end() ? it->second : nullptr; } bool initialized_;