namespace art {
-// Is native-bridge support enabled?
-static constexpr bool kNativeBridgeEnabled = true;
-
-// Default library name for native-bridge.
-static constexpr const char* kDefaultNativeBridge = "libnativebridge.so";
-
-#ifdef HAVE_ANDROID_OS
-// TODO: This will be removed once we have native-bridge command-line arguments.
-
-// Property that defines the library name of native-bridge.
-static constexpr const char* kPropNativeBridge = "persist.native.bridge";
-
-// Property that enables native-bridge.
-static constexpr const char* kPropEnableNativeBridge = "persist.enable.native.bridge";
-#endif
-
// The symbol name exposed by native-bridge with the type of NativeBridgeCallbacks.
static constexpr const char* kNativeBridgeInterfaceSymbol = "NativeBridgeItf";
return count;
}
-NativeBridgeArtCallbacks NativeBridgeArtItf = {
+static NativeBridgeArtCallbacks NativeBridgeArtItf = {
GetMethodShorty,
GetNativeMethodCount,
GetNativeMethods
};
void SetNativeBridgeLibraryString(const std::string& nb_library_string) {
+ // This is called when the runtime starts and nothing is working concurrently
+ // so we don't need a lock here.
+
native_bridge_library_string = nb_library_string;
- // TODO: when given an empty string, set initialized_ to true and available_ to false. This
- // change is dependent on the property removal in Initialize().
-}
-bool NativeBridgeInitialize() {
- if (!kNativeBridgeEnabled) {
- return false;
+ if (native_bridge_library_string.empty()) {
+ initialized = true;
+ available = false;
}
+}
+
+static bool NativeBridgeInitialize() {
// TODO: Missing annotalysis static lock ordering of DEFAULT_MUTEX_ACQUIRED, place lock into
// global order or remove.
static Mutex lock("native bridge lock");
available = false;
- const char* libnb_path;
-
- if (!native_bridge_library_string.empty()) {
- libnb_path = native_bridge_library_string.c_str();
- } else {
- // TODO: Remove this once the frameworks side is completely implemented.
-
- libnb_path = kDefaultNativeBridge;
-#ifdef HAVE_ANDROID_OS
- char prop_buf[PROP_VALUE_MAX];
- property_get(kPropEnableNativeBridge, prop_buf, "false");
- if (strcmp(prop_buf, "true") != 0) {
- initialized = true;
- return false;
- }
-
- // If prop persist.native.bridge set, overwrite the default name.
- int name_len = property_get(kPropNativeBridge, prop_buf, kDefaultNativeBridge);
- if (name_len > 0)
- libnb_path = prop_buf;
-#endif
- }
-
- void* handle = dlopen(libnb_path, RTLD_LAZY);
+ void* handle = dlopen(native_bridge_library_string.c_str(), RTLD_LAZY);
if (handle != nullptr) {
callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
kNativeBridgeInterfaceSymbol));