Merge "Allow different namespace types for different classloaders" am: a61c48d5fd

am: 9b1d1cb923

Change-Id: I6832b42ba46681801724838c97951f92967c259c
This commit is contained in:
Dimitry Ivanov 2016-11-07 18:12:16 +00:00 committed by android-build-merger
commit 08aa99d622
4 changed files with 17 additions and 13 deletions

View file

@ -104,7 +104,7 @@ int NativeBridgeUnloadLibrary(void* handle);
// Get last error message of native bridge when fail to load library or search symbol. // Get last error message of native bridge when fail to load library or search symbol.
// This is reflection of dlerror() for native bridge. // This is reflection of dlerror() for native bridge.
char* NativeBridgeGetError(); const char* NativeBridgeGetError();
struct native_bridge_namespace_t; struct native_bridge_namespace_t;
@ -244,7 +244,7 @@ struct NativeBridgeCallbacks {
// Returns: // Returns:
// A string describing the most recent error that occurred when load library // A string describing the most recent error that occurred when load library
// or lookup symbol via native bridge. // or lookup symbol via native bridge.
char* (*getError)(); const char* (*getError)();
// Check whether library paths are supported by native bridge. // Check whether library paths are supported by native bridge.
// //

View file

@ -551,15 +551,15 @@ int NativeBridgeUnloadLibrary(void* handle) {
return -1; return -1;
} }
char* NativeBridgeGetError() { const char* NativeBridgeGetError() {
if (NativeBridgeInitialized()) { if (NativeBridgeInitialized()) {
if (isCompatibleWith(NAMESPACE_VERSION)) { if (isCompatibleWith(NAMESPACE_VERSION)) {
return callbacks->getError(); return callbacks->getError();
} else { } else {
ALOGE("not compatible with version %d, cannot get message", NAMESPACE_VERSION); return "native bridge implementation is not compatible with version 3, cannot get message";
} }
} }
return nullptr; return "native bridge is not initialized";
} }
bool NativeBridgeIsPathSupported(const char* path) { bool NativeBridgeIsPathSupported(const char* path) {

View file

@ -68,7 +68,7 @@ extern "C" int native_bridge3_unloadLibrary(void* /* handle */) {
return 0; return 0;
} }
extern "C" char* native_bridge3_getError() { extern "C" const char* native_bridge3_getError() {
return nullptr; return nullptr;
} }

View file

@ -308,13 +308,17 @@ class LibraryNamespaces {
// code is one example) unknown to linker in which case linker uses anonymous // code is one example) unknown to linker in which case linker uses anonymous
// namespace. The second argument specifies the search path for the anonymous // namespace. The second argument specifies the search path for the anonymous
// namespace which is the library_path of the classloader. // namespace which is the library_path of the classloader.
if (!is_native_bridge) { initialized_ = android_init_namespaces(public_libraries_.c_str(),
initialized_ = android_init_namespaces(public_libraries_.c_str(), library_path); is_native_bridge ? nullptr : library_path);
if (!initialized_) { if (!initialized_) {
*error_msg = dlerror(); *error_msg = dlerror();
} return false;
} else { }
initialized_ = NativeBridgeInitNamespace(public_libraries_.c_str(), library_path);
// and now initialize native bridge namespaces if necessary.
if (NativeBridgeInitialized()) {
initialized_ = NativeBridgeInitNamespace(public_libraries_.c_str(),
is_native_bridge ? library_path : nullptr);
if (!initialized_) { if (!initialized_) {
*error_msg = NativeBridgeGetError(); *error_msg = NativeBridgeGetError();
} }