summaryrefslogtreecommitdiffstats
path: root/libnativebridge
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2014-09-25 21:46:56 +0000
committerAndreas Gampe <agampe@google.com>2014-09-25 21:46:56 +0000
commit25bacb3ab71ee7e8289c76d0aa0c6473e47340e3 (patch)
tree18f63fba57fc7311a19f30027d2ea0063400d110 /libnativebridge
parentf00de413ed451f1a90d614ea5dce8b3d685e877c (diff)
downloadsystem_core-25bacb3ab71ee7e8289c76d0aa0c6473e47340e3.zip
system_core-25bacb3ab71ee7e8289c76d0aa0c6473e47340e3.tar.gz
system_core-25bacb3ab71ee7e8289c76d0aa0c6473e47340e3.tar.bz2
Revert "DO NOT MERGE Libnativebridge: Temporarily change back to late dlopen"
This reverts commit f00de413ed451f1a90d614ea5dce8b3d685e877c. Bug: 17645833 Change-Id: Ie5480de9cf4da2c9167db2e6137679019a29f867
Diffstat (limited to 'libnativebridge')
-rw-r--r--libnativebridge/native_bridge.cc90
-rw-r--r--libnativebridge/tests/ValidNameNativeBridge_test.cpp5
2 files changed, 30 insertions, 65 deletions
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index fa80e1e..6602d3f 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -29,7 +29,6 @@ static constexpr const char* kNativeBridgeInterfaceSymbol = "NativeBridgeItf";
enum class NativeBridgeState {
kNotSetup, // Initial state.
kOpened, // After successful dlopen.
- // Temporary meaning: string copied. TODO: remove. b/17440362
kInitialized, // After successful initialization.
kClosed // Closed or errors.
};
@@ -61,9 +60,6 @@ static NativeBridgeState state = NativeBridgeState::kNotSetup;
// Whether we had an error at some point.
static bool had_error = false;
-// Native bridge filename. TODO: Temporary, remove. b/17440362
-static const char* native_bridge_filename;
-
// Handle of the loaded library.
static void* native_bridge_handle = nullptr;
// Pointer to the callbacks. Available as soon as LoadNativeBridge succeeds, but only initialized
@@ -135,32 +131,28 @@ bool LoadNativeBridge(const char* nb_library_filename,
state = NativeBridgeState::kClosed;
had_error = true;
} else {
- // Save the name. TODO: Remove this, return to old flow. b/17440362
- native_bridge_filename = nb_library_filename;
- runtime_callbacks = runtime_cbs;
- state = NativeBridgeState::kOpened;
-// // Try to open the library.
-// void* handle = dlopen(nb_library_filename, RTLD_LAZY);
-// if (handle != nullptr) {
-// callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
-// kNativeBridgeInterfaceSymbol));
-// if (callbacks != nullptr) {
-// // Store the handle for later.
-// native_bridge_handle = handle;
-// } else {
-// dlclose(handle);
-// }
-// }
-//
-// // Two failure conditions: could not find library (dlopen failed), or could not find native
-// // bridge interface (dlsym failed). Both are an error and close the native bridge.
-// if (callbacks == nullptr) {
-// had_error = true;
-// state = NativeBridgeState::kClosed;
-// } else {
-// runtime_callbacks = runtime_cbs;
-// state = NativeBridgeState::kOpened;
-// }
+ // Try to open the library.
+ void* handle = dlopen(nb_library_filename, RTLD_LAZY);
+ if (handle != nullptr) {
+ callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
+ kNativeBridgeInterfaceSymbol));
+ if (callbacks != nullptr) {
+ // Store the handle for later.
+ native_bridge_handle = handle;
+ } else {
+ dlclose(handle);
+ }
+ }
+
+ // Two failure conditions: could not find library (dlopen failed), or could not find native
+ // bridge interface (dlsym failed). Both are an error and close the native bridge.
+ if (callbacks == nullptr) {
+ had_error = true;
+ state = NativeBridgeState::kClosed;
+ } else {
+ runtime_callbacks = runtime_cbs;
+ state = NativeBridgeState::kOpened;
+ }
}
return state == NativeBridgeState::kOpened;
}
@@ -171,38 +163,15 @@ bool InitializeNativeBridge() {
// point we are not multi-threaded, so we do not need locking here.
if (state == NativeBridgeState::kOpened) {
- // Open and initialize. TODO: Temporary, remove. b/17440362
- void* handle = dlopen(native_bridge_filename, RTLD_LAZY);
- if (handle != nullptr) {
- callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
- kNativeBridgeInterfaceSymbol));
- if (callbacks != nullptr) {
- if (callbacks->initialize(runtime_callbacks)) {
- state = NativeBridgeState::kInitialized;
- native_bridge_handle = handle;
- } else {
- callbacks = nullptr;
- }
- }
-
- if (callbacks == nullptr) {
- state = NativeBridgeState::kClosed;
- had_error = true;
- dlclose(handle);
- }
+ // Try to initialize.
+ if (callbacks->initialize(runtime_callbacks)) {
+ state = NativeBridgeState::kInitialized;
} else {
- state = NativeBridgeState::kClosed;
+ // Unload the library.
+ dlclose(native_bridge_handle);
had_error = true;
+ state = NativeBridgeState::kClosed;
}
-// // Try to initialize.
-// if (callbacks->initialize(runtime_callbacks)) {
-// state = NativeBridgeState::kInitialized;
-// } else {
-// // Unload the library.
-// dlclose(native_bridge_handle);
-// had_error = true;
-// state = NativeBridgeState::kClosed;
-// }
} else {
had_error = true;
state = NativeBridgeState::kClosed;
@@ -216,7 +185,7 @@ void UnloadNativeBridge() {
// point we are not multi-threaded, so we do not need locking here.
switch(state) {
- // case NativeBridgeState::kOpened: // TODO: Re-add this. b/17440362
+ case NativeBridgeState::kOpened:
case NativeBridgeState::kInitialized:
// Unload.
dlclose(native_bridge_handle);
@@ -227,7 +196,6 @@ void UnloadNativeBridge() {
had_error = true;
break;
- case NativeBridgeState::kOpened: // TODO: Remove this. b/17440362
case NativeBridgeState::kClosed:
// Ignore.
break;
diff --git a/libnativebridge/tests/ValidNameNativeBridge_test.cpp b/libnativebridge/tests/ValidNameNativeBridge_test.cpp
index b28f5b2..690be4a 100644
--- a/libnativebridge/tests/ValidNameNativeBridge_test.cpp
+++ b/libnativebridge/tests/ValidNameNativeBridge_test.cpp
@@ -27,12 +27,9 @@ TEST_F(NativeBridgeTest, ValidName) {
// Now check what happens on LoadNativeBridge.
EXPECT_EQ(false, NativeBridgeError());
LoadNativeBridge(kTestName, nullptr);
- // TODO: Remove this call. b/17440362
- InitializeNativeBridge();
// This will lead to an error as the library doesn't exist.
EXPECT_EQ(true, NativeBridgeError());
- // TODO: Test again. b/17440362
-// EXPECT_EQ(false, NativeBridgeAvailable());
+ EXPECT_EQ(false, NativeBridgeAvailable());
}
} // namespace android