android_namespace_t* GetOrCreate(JNIEnv* env, jobject class_loader, bool is_shared, jstring java_library_path, jstring java_permitted_path) { ScopedUtfChars library_path(env, java_library_path); std::string permitted_path; if (java_permitted_path != nullptr) { ScopedUtfChars path(env, java_permitted_path); permitted_path = path.c_str(); } if (!initialized_ && !InitPublicNamespace(library_path.c_str())) { return nullptr; } std::lock_guard<std::mutex> guard(mutex_); auto it = FindNamespaceByClassLoader(env, class_loader); if (it != namespaces_.end()) { return it->second; } uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED; if (is_shared) { 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); namespaces_.push_back(std::make_pair(env->NewWeakGlobalRef(class_loader), ns)); return ns; }
android_namespace_t* Create(JNIEnv* env, jobject class_loader, bool is_shared, jstring java_library_path, jstring java_permitted_path) { ScopedUtfChars library_path(env, java_library_path); std::string permitted_path; if (java_permitted_path != nullptr) { ScopedUtfChars path(env, java_permitted_path); permitted_path = path.c_str(); } if (!initialized_ && !InitPublicNamespace(library_path.c_str())) { return nullptr; } android_namespace_t* ns = FindNamespaceByClassLoader(env, class_loader); LOG_ALWAYS_FATAL_IF(ns != nullptr, "There is already a namespace associated with this classloader"); uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED; if (is_shared) { namespace_type |= ANDROID_NAMESPACE_TYPE_SHARED; } ns = android_create_namespace("classloader-namespace", nullptr, library_path.c_str(), namespace_type, java_permitted_path != nullptr ? permitted_path.c_str() : nullptr); if (ns != nullptr) { namespaces_.push_back(std::make_pair(env->NewWeakGlobalRef(class_loader), ns)); } return ns; }