Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cd10d83 authored by Dimitry Ivanov's avatar Dimitry Ivanov
Browse files

nativeloader: Export FindNamespaceByClassLoader

Bug: http://b/27189432
Change-Id: Ib80dcce949276ee620f601c47b20f783708e8e85
parent 34fa704d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@

#include "jni.h"
#include <stdint.h>
#if defined(__ANDROID__)
#include <android/dlext.h>
#endif

namespace android {

@@ -27,6 +30,13 @@ void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* pat
                        jobject class_loader, bool is_shared, jstring library_path,
                        jstring permitted_path);

#if defined(__ANDROID__)
// Look up linker namespace by class_loader. Returns nullptr if
// there is no namespace associated with the class_loader.
__attribute__((visibility("default")))
android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader);
#endif

};  // namespace android

#endif  // NATIVE_BRIDGE_H_
+14 −8
Original line number Diff line number Diff line
@@ -103,6 +103,14 @@ class LibraryNamespaces {
    return ns;
  }

  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;
  }

 private:
  void PreloadPublicLibraries() {
    // android_init_namespaces() expects all the public libraries
@@ -121,14 +129,6 @@ class LibraryNamespaces {
    return initialized_;
  }

  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_;
  std::mutex mutex_;
  std::vector<std::pair<jweak, android_namespace_t*>> namespaces_;
@@ -168,4 +168,10 @@ void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* pat
#endif
}

#if defined(__ANDROID__)
android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) {
  return g_namespaces->FindNamespaceByClassLoader(env, class_loader);
}
#endif

}; //  android namespace