diff --git a/lib/fb/BUCK b/lib/fb/BUCK
deleted file mode 100644
index f283dca1..00000000
--- a/lib/fb/BUCK
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
-load("@fbsource//tools/build_defs:platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "WINDOWS")
-load("//tools/build_defs/oss:yoga_defs.bzl", "JNI_TARGET", "YOGA_ROOTS", "subdir_glob", "yoga_cxx_library", "yoga_prebuilt_cxx_library")
-
-yoga_prebuilt_cxx_library(
- name = "ndklog",
- exported_platform_linker_flags = [
- (
- "^android.*",
- ["-llog"],
- ),
- ],
- header_only = True,
- platforms = (ANDROID, APPLE, CXX, FBCODE, WINDOWS),
- visibility = YOGA_ROOTS,
-)
-
-yoga_cxx_library(
- name = "fbjni",
- srcs = glob(["src/main/cpp/**/*.cpp"]),
- header_namespace = "",
- exported_headers = subdir_glob([("src/main/cpp/include", "**/*.h")]),
- compiler_flags = [
- "-DLOG_TAG=\"libfb\"",
- "-DDISABLE_CPUCAP",
- "-DDISABLE_XPLAT",
- "-DHAVE_POSIX_CLOCKS",
- "-fno-omit-frame-pointer",
- "-fexceptions",
- "-frtti",
- "-Wall",
- "-Werror",
- "-Wno-unused-parameter",
- "-Wno-unused-variable",
- "-std=c++11",
- ],
- platforms = (CXX, ANDROID),
- soname = "libfbjni.$(ext)",
- visibility = ["PUBLIC"],
- deps = [
- ":ndklog",
- JNI_TARGET,
- ],
-)
diff --git a/lib/fb/build.gradle b/lib/fb/build.gradle
deleted file mode 100644
index 8194a2b6..00000000
--- a/lib/fb/build.gradle
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-apply plugin: 'com.android.library'
-
-android {
- compileSdkVersion rootProject.compileSdkVersion
- buildToolsVersion rootProject.buildToolsVersion
-
- defaultConfig {
- minSdkVersion rootProject.minSdkVersion
- targetSdkVersion rootProject.targetSdkVersion
-
- ndk {
- abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
- }
-
- externalNativeBuild {
- cmake {
- arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
- }
- }
- }
-
- externalNativeBuild {
- cmake {
- path 'src/main/cpp/CMakeLists.txt'
- }
- }
-
- dependencies {
- implementation 'com.facebook.soloader:soloader:0.10.4'
- implementation 'com.google.code.findbugs:jsr305:3.0.2'
- implementation project(':yoga:proguard-annotations')
- }
-}
diff --git a/lib/fb/src/main/AndroidManifest.xml b/lib/fb/src/main/AndroidManifest.xml
deleted file mode 100644
index 6d0fd184..00000000
--- a/lib/fb/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
diff --git a/lib/fb/src/main/cpp/CMakeLists.txt b/lib/fb/src/main/cpp/CMakeLists.txt
deleted file mode 100644
index 8a6a045c..00000000
--- a/lib/fb/src/main/cpp/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
-#
-
-cmake_minimum_required(VERSION 3.4.1)
-
-set(CMAKE_VERBOSE_MAKEFILE on)
-
-add_compile_options(
- -fno-omit-frame-pointer
- -fexceptions
- -Wall
- -std=c++11
- -DDISABLE_CPUCAP
- -DDISABLE_XPLAT)
-
-file(GLOB fb_SRC
- *.cpp
- jni/*.cpp
- jni/detail/*.cpp
- lyra/*.cpp)
-
-add_library(fb SHARED
- ${fb_SRC})
-
-target_include_directories(fb PRIVATE
- include)
-
-target_link_libraries(fb android log)
diff --git a/lib/fb/src/main/cpp/Doxyfile b/lib/fb/src/main/cpp/Doxyfile
deleted file mode 100644
index b44118dd..00000000
--- a/lib/fb/src/main/cpp/Doxyfile
+++ /dev/null
@@ -1,15 +0,0 @@
-PROJECT_NAME = "Facebook Android Support"
-JAVADOC_AUTOBRIEF = YES
-EXTRACT_ALL = YES
-RECURSIVE = YES
-EXCLUDE = tests
-EXCLUDE_PATTERNS = *.cpp
-GENERATE_HTML = YES
-GENERATE_LATEX = NO
-ENABLE_PREPROCESSING = YES
-HIDE_UNDOC_MEMBERS = YES
-HIDE_SCOPE_NAMES = YES
-HIDE_FRIEND_COMPOUNDS = YES
-HIDE_UNDOC_CLASSES = YES
-SHOW_INCLUDE_FILES = NO
-#ENABLED_SECTIONS = INTERNAL
diff --git a/lib/fb/src/main/cpp/include/fb/Doxyfile b/lib/fb/src/main/cpp/include/fb/Doxyfile
deleted file mode 100644
index 8b4df6a7..00000000
--- a/lib/fb/src/main/cpp/include/fb/Doxyfile
+++ /dev/null
@@ -1,18 +0,0 @@
-PROJECT_NAME = "Facebook JNI"
-PROJECT_BRIEF = "Helper library to provide safe and convenient access to JNI with very low overhead"
-JAVADOC_AUTOBRIEF = YES
-EXTRACT_ALL = YES
-RECURSIVE = YES
-EXCLUDE = tests Asserts.h Countable.h GlobalReference.h LocalReference.h LocalString.h Registration.h WeakReference.h jni_helpers.h Environment.h
-EXCLUDE_PATTERNS = *-inl.h *.cpp
-GENERATE_HTML = YES
-GENERATE_LATEX = NO
-ENABLE_PREPROCESSING = YES
-HIDE_UNDOC_MEMBERS = YES
-HIDE_SCOPE_NAMES = YES
-HIDE_FRIEND_COMPOUNDS = YES
-HIDE_UNDOC_CLASSES = YES
-SHOW_INCLUDE_FILES = NO
-PREDEFINED = LOG_TAG=fbjni
-EXAMPLE_PATH = samples
-#ENABLED_SECTIONS = INTERNAL
diff --git a/lib/fb/src/main/cpp/include/fbjni/ByteBuffer.h b/lib/fb/src/main/cpp/include/fbjni/ByteBuffer.h
deleted file mode 100644
index 55223e46..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/ByteBuffer.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-
-namespace facebook {
-namespace jni {
-
-class JBuffer : public JavaClass {
-public:
- static constexpr const char* kJavaDescriptor = "Ljava/nio/Buffer;";
-
- void rewind() const;
- bool isDirect() const;
- void* getDirectAddress() const;
- size_t getDirectCapacity() const;
-};
-
-// JNI's NIO support has some awkward preconditions and error reporting. This
-// class provides much more user-friendly access.
-class JByteBuffer : public JavaClass {
- public:
- static constexpr const char* kJavaDescriptor = "Ljava/nio/ByteBuffer;";
-
- static local_ref wrapBytes(uint8_t* data, size_t size);
- static local_ref allocateDirect(jint size);
-
- uint8_t* getDirectBytes() const {
- return static_cast(getDirectAddress());
- }
-
- size_t getDirectSize() const {
- return getDirectCapacity();
- }
-};
-
-}}
diff --git a/lib/fb/src/main/cpp/include/fbjni/Context.h b/lib/fb/src/main/cpp/include/fbjni/Context.h
deleted file mode 100644
index 331de691..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/Context.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-#include
-
-namespace facebook {
-namespace jni {
-
-class AContext : public JavaClass {
- public:
- static constexpr const char* kJavaDescriptor = "Landroid/content/Context;";
-
- // Define a method that calls into the represented Java class
- local_ref getCacheDir() {
- static const auto method = getClass()->getMethod("getCacheDir");
- return method(self());
- }
-
- local_ref getFilesDir() {
- static const auto method = getClass()->getMethod("getFilesDir");
- return method(self());
- }
-};
-
-}
-}
diff --git a/lib/fb/src/main/cpp/include/fbjni/File.h b/lib/fb/src/main/cpp/include/fbjni/File.h
deleted file mode 100644
index 852202ba..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/File.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-
-namespace facebook {
-namespace jni {
-
-class JFile : public JavaClass {
- public:
- static constexpr const char* kJavaDescriptor = "Ljava/io/File;";
-
- // Define a method that calls into the represented Java class
- std::string getAbsolutePath() {
- static const auto method = getClass()->getMethod("getAbsolutePath");
- return method(self())->toStdString();
- }
-
-};
-
-}
-}
diff --git a/lib/fb/src/main/cpp/include/fbjni/JThread.h b/lib/fb/src/main/cpp/include/fbjni/JThread.h
deleted file mode 100644
index a343e022..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/JThread.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-#include
-
-namespace facebook {
-namespace jni {
-
-class JThread : public JavaClass {
- public:
- static constexpr const char* kJavaDescriptor = "Ljava/lang/Thread;";
-
- void start() {
- static const auto method = javaClassStatic()->getMethod("start");
- method(self());
- }
-
- void join() {
- static const auto method = javaClassStatic()->getMethod("join");
- method(self());
- }
-
- static local_ref create(std::function&& runnable) {
- auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable));
- return newInstance(static_ref_cast(jrunnable));
- }
-
- static local_ref create(std::function&& runnable, std::string&& name) {
- auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable));
- return newInstance(static_ref_cast(jrunnable), make_jstring(std::move(name)));
- }
-
- static local_ref getCurrent() {
- static const auto method = javaClassStatic()->getStaticMethod()>("currentThread");
- return method(javaClassStatic());
- }
-
- int getPriority() {
- static const auto method = getClass()->getMethod("getPriority");
- return method(self());
- }
-
- void setPriority(int priority) {
- static const auto method = getClass()->getMethod("setPriority");
- method(self(), priority);
- }
-};
-
-}
-}
diff --git a/lib/fb/src/main/cpp/include/fbjni/NativeRunnable.h b/lib/fb/src/main/cpp/include/fbjni/NativeRunnable.h
deleted file mode 100644
index 7bb915f4..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/NativeRunnable.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-
-#include
-
-namespace facebook {
-namespace jni {
-
-struct JRunnable : public JavaClass {
- static auto constexpr kJavaDescriptor = "Ljava/lang/Runnable;";
-};
-
-struct JNativeRunnable : public HybridClass {
- public:
- static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/NativeRunnable;";
-
- JNativeRunnable(std::function&& runnable) : runnable_(std::move(runnable)) {}
-
- static void OnLoad() {
- registerHybrid({
- makeNativeMethod("run", JNativeRunnable::run),
- });
- }
-
- void run() {
- runnable_();
- }
-
- private:
- std::function runnable_;
-};
-
-
-} // namespace jni
-} // namespace facebook
diff --git a/lib/fb/src/main/cpp/include/fbjni/ReadableByteChannel.h b/lib/fb/src/main/cpp/include/fbjni/ReadableByteChannel.h
deleted file mode 100644
index f524d26c..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/ReadableByteChannel.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-#include
-
-namespace facebook {
-namespace jni {
-
-class JReadableByteChannel : public JavaClass {
-public:
- static constexpr const char* kJavaDescriptor = "Ljava/nio/channels/ReadableByteChannel;";
-
- int read(alias_ref dest) const;
-};
-
-}}
diff --git a/lib/fb/src/main/cpp/include/fbjni/detail/Boxed.h b/lib/fb/src/main/cpp/include/fbjni/detail/Boxed.h
deleted file mode 100644
index e231b958..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/detail/Boxed.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include "CoreClasses.h"
-
-namespace facebook {
-namespace jni {
-
-namespace detail {
-template
-struct JPrimitive : JavaClass {
- using typename JavaClass::javaobject;
- using JavaClass::javaClassStatic;
- static local_ref valueOf(jprim val) {
- static const auto cls = javaClassStatic();
- static const auto method =
- cls->template getStaticMethod("valueOf");
- return method(cls, val);
- }
- jprim value() const {
- static const auto method =
- javaClassStatic()->template getMethod(T::kValueMethod);
- return method(this->self());
- }
-};
-
-} // namespace detail
-
-
-#define DEFINE_BOXED_PRIMITIVE(LITTLE, BIG) \
- struct J ## BIG : detail::JPrimitive { \
- static auto constexpr kJavaDescriptor = "Ljava/lang/" #BIG ";"; \
- static auto constexpr kValueMethod = #LITTLE "Value"; \
- j ## LITTLE LITTLE ## Value() const { \
- return value(); \
- } \
- }; \
- inline local_ref autobox(j ## LITTLE val) { \
- return J ## BIG::valueOf(val); \
- }
-
-DEFINE_BOXED_PRIMITIVE(boolean, Boolean)
-DEFINE_BOXED_PRIMITIVE(byte, Byte)
-DEFINE_BOXED_PRIMITIVE(char, Character)
-DEFINE_BOXED_PRIMITIVE(short, Short)
-DEFINE_BOXED_PRIMITIVE(int, Integer)
-DEFINE_BOXED_PRIMITIVE(long, Long)
-DEFINE_BOXED_PRIMITIVE(float, Float)
-DEFINE_BOXED_PRIMITIVE(double, Double)
-
-#undef DEFINE_BOXED_PRIMITIVE
-
-template
-inline typename std::enable_if<
- (std::is_same::value || std::is_same::value) && !std::is_same::value,
- local_ref
->::type autobox(T val) {
- return JLong::valueOf(val);
-}
-
-struct JVoid : public jni::JavaClass {
- static auto constexpr kJavaDescriptor = "Ljava/lang/Void;";
-};
-
-inline local_ref autobox(alias_ref val) {
- return make_local(val);
-}
-
-}}
diff --git a/lib/fb/src/main/cpp/include/fbjni/detail/Common.h b/lib/fb/src/main/cpp/include/fbjni/detail/Common.h
deleted file mode 100644
index 573fcc75..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/detail/Common.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-/** @file Common.h
- *
- * Defining the stuff that don't deserve headers of their own...
- */
-
-#pragma once
-
-#include
-
-#include
-
-#ifdef FBJNI_DEBUG_REFS
-# ifdef __ANDROID__
-# include
-# else
-# include
-# endif
-#endif
-
-// If a pending JNI Java exception is found, wraps it in a JniException object and throws it as
-// a C++ exception.
-#define FACEBOOK_JNI_THROW_PENDING_EXCEPTION() \
- ::facebook::jni::throwPendingJniExceptionAsCppException()
-
-// If the condition is true, throws a JniException object, which wraps the pending JNI Java
-// exception if any. If no pending exception is found, throws a JniException object that wraps a
-// RuntimeException throwable.
-#define FACEBOOK_JNI_THROW_EXCEPTION_IF(CONDITION) \
- ::facebook::jni::throwCppExceptionIf(CONDITION)
-
-/// @cond INTERNAL
-
-namespace facebook {
-namespace jni {
-
-void throwPendingJniExceptionAsCppException();
-void throwCppExceptionIf(bool condition);
-
-[[noreturn]] void throwNewJavaException(jthrowable);
-[[noreturn]] void throwNewJavaException(const char* throwableName, const char* msg);
-template
-[[noreturn]] void throwNewJavaException(const char* throwableName, const char* fmt, Args... args);
-
-
-/**
- * This needs to be called at library load time, typically in your JNI_OnLoad method.
- *
- * The intended use is to return the result of initialize() directly
- * from JNI_OnLoad and to do nothing else there. Library specific
- * initialization code should go in the function passed to initialize
- * (which can be, and probably should be, a C++ lambda). This approach
- * provides correct error handling and translation errors during
- * initialization into Java exceptions when appropriate.
- *
- * Failure to call this will cause your code to crash in a remarkably
- * unhelpful way (typically a segfault) while trying to handle an exception
- * which occurs later.
- */
-jint initialize(JavaVM*, std::function&&) noexcept;
-
-namespace internal {
-
-// Define to get extremely verbose logging of references and to enable reference stats
-#ifdef FBJNI_DEBUG_REFS
-template
-inline void dbglog(const char* msg, Args... args) {
-# ifdef __ANDROID__
- __android_log_print(ANDROID_LOG_VERBOSE, "fbjni_dbg", msg, args...);
-# else
- std::fprintf(stderr, msg, args...);
-# endif
-}
-
-#else
-
-template
-inline void dbglog(const char*, Args...) {
-}
-
-#endif
-
-}}}
-
-/// @endcond
diff --git a/lib/fb/src/main/cpp/include/fbjni/detail/CoreClasses-inl.h b/lib/fb/src/main/cpp/include/fbjni/detail/CoreClasses-inl.h
deleted file mode 100644
index d8214fde..00000000
--- a/lib/fb/src/main/cpp/include/fbjni/detail/CoreClasses-inl.h
+++ /dev/null
@@ -1,677 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the LICENSE
- * file in the root directory of this source tree.
- */
-#pragma once
-
-#include
-#include
-#include
-
-#include "Common.h"
-#include "Exceptions.h"
-#include "Meta.h"
-#include "MetaConvert.h"
-
-namespace facebook {
-namespace jni {
-
-// jobject /////////////////////////////////////////////////////////////////////////////////////////
-
-inline bool isSameObject(alias_ref lhs, alias_ref rhs) noexcept {
- return Environment::current()->IsSameObject(lhs.get(), rhs.get()) != JNI_FALSE;
-}
-
-inline local_ref JObject::getClass() const noexcept {
- return adopt_local(Environment::current()->GetObjectClass(self()));
-}
-
-inline bool JObject::isInstanceOf(alias_ref cls) const noexcept {
- return Environment::current()->IsInstanceOf(self(), cls.get()) != JNI_FALSE;
-}
-
-template
-inline T JObject::getFieldValue(JField field) const noexcept {
- return field.get(self());
-}
-
-template
-inline local_ref JObject::getFieldValue(JField field) const noexcept {
- return adopt_local(field.get(self()));
-}
-
-template
-inline void JObject::setFieldValue(JField field, T value) noexcept {
- field.set(self(), value);
-}
-
-template
-inline void JObject::setFieldValue(JField field, alias_ref value) noexcept {
- setFieldValue(field, value.get());
-}
-
-inline std::string JObject::toString() const {
- static const auto method = findClassLocal("java/lang/Object")->getMethod("toString");
-
- return method(self())->toStdString();
-}
-
-
-// Class is here instead of CoreClasses.h because we need
-// alias_ref to be complete.
-class MonitorLock {
- public:
- inline MonitorLock() noexcept;
- inline MonitorLock(alias_ref object) noexcept;
- inline ~MonitorLock() noexcept;
-
- inline MonitorLock(MonitorLock&& other) noexcept;
- inline MonitorLock& operator=(MonitorLock&& other) noexcept;
-
- inline MonitorLock(const MonitorLock&) = delete;
- inline MonitorLock& operator=(const MonitorLock&) = delete;
-
- private:
- inline void reset() noexcept;
- alias_ref owned_;
-};
-
-MonitorLock::MonitorLock() noexcept : owned_(nullptr) {}
-
-MonitorLock::MonitorLock(alias_ref object) noexcept
- : owned_(object) {
- Environment::current()->MonitorEnter(object.get());
-}
-
-void MonitorLock::reset() noexcept {
- if (owned_) {
- Environment::current()->MonitorExit(owned_.get());
- if (Environment::current()->ExceptionCheck()) {
- abort(); // Lock mismatch
- }
- owned_ = nullptr;
- }
-}
-
-MonitorLock::~MonitorLock() noexcept {
- reset();
-}
-
-MonitorLock::MonitorLock(MonitorLock&& other) noexcept
- : owned_(other.owned_)
-{
- other.owned_ = nullptr;
-}
-
-MonitorLock& MonitorLock::operator=(MonitorLock&& other) noexcept {
- reset();
- owned_ = other.owned_;
- other.owned_ = nullptr;
- return *this;
-}
-
-inline MonitorLock JObject::lock() const noexcept {
- return MonitorLock(this_);
-}
-
-inline jobject JObject::self() const noexcept {
- return this_;
-}
-
-inline void swap(JObject& a, JObject& b) noexcept {
- using std::swap;
- swap(a.this_, b.this_);
-}
-
-// JavaClass ///////////////////////////////////////////////////////////////////////////////////////
-
-namespace detail {
-template
-static local_ref newInstance(Args... args) {
- static auto cls = JC::javaClassStatic();
- static const auto constructor = cls->template getConstructor();
- return cls->newObject(constructor, args...);
-}
-}
-
-
-template
-auto JavaClass::self() const noexcept -> javaobject {
- return static_cast(JObject::self());
-}
-
-// jclass //////////////////////////////////////////////////////////////////////////////////////////
-
-namespace detail {
-
-// This is not a real type. It is used so people won't accidentally
-// use a void* to initialize a NativeMethod.
-struct NativeMethodWrapper;
-
-}
-
-struct NativeMethod {
- const char* name;
- std::string descriptor;
- detail::NativeMethodWrapper* wrapper;
-};
-
-inline local_ref JClass::getSuperclass() const noexcept {
- return adopt_local(Environment::current()->GetSuperclass(self()));
-}
-
-inline void JClass::registerNatives(std::initializer_list methods) {
- const auto env = Environment::current();
-
- JNINativeMethod jnimethods[methods.size()];
- size_t i = 0;
- for (auto it = methods.begin(); it < methods.end(); ++it, ++i) {
- // The JNI struct members are unnecessarily non-const.
- jnimethods[i].name = const_cast(it->name);
- jnimethods[i].signature = const_cast(it->descriptor.c_str());
- jnimethods[i].fnPtr = reinterpret_cast(it->wrapper);
- }
-
- auto result = env->RegisterNatives(self(), jnimethods, methods.size());
- FACEBOOK_JNI_THROW_EXCEPTION_IF(result != JNI_OK);
-}
-
-inline bool JClass::isAssignableFrom(alias_ref other) const noexcept {
- const auto env = Environment::current();
- // Ths method has behavior compatible with the
- // java.lang.Class#isAssignableFrom method. The order of the
- // arguments to the JNI IsAssignableFrom C function is "opposite"
- // from what some might expect, which makes this code look a little
- // odd, but it is correct.
- const auto result = env->IsAssignableFrom(other.get(), self());
- return result;
-}
-
-template
-inline JConstructor JClass::getConstructor() const {
- return getConstructor(jmethod_traits_from_cxx::constructor_descriptor().c_str());
-}
-
-template
-inline JConstructor JClass::getConstructor(const char* descriptor) const {
- constexpr auto constructor_method_name = "";
- return getMethod(constructor_method_name, descriptor);
-}
-
-template
-inline JMethod JClass::getMethod(const char* name) const {
- return getMethod(name, jmethod_traits_from_cxx::descriptor().c_str());
-}
-
-template
-inline JMethod JClass::getMethod(
- const char* name,
- const char* descriptor) const {
- const auto env = Environment::current();
- const auto method = env->GetMethodID(self(), name, descriptor);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!method);
- return JMethod{method};
-}
-
-template
-inline JStaticMethod JClass::getStaticMethod(const char* name) const {
- return getStaticMethod(name, jmethod_traits_from_cxx::descriptor().c_str());
-}
-
-template
-inline JStaticMethod JClass::getStaticMethod(
- const char* name,
- const char* descriptor) const {
- const auto env = Environment::current();
- const auto method = env->GetStaticMethodID(self(), name, descriptor);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!method);
- return JStaticMethod{method};
-}
-
-template
-inline JNonvirtualMethod JClass::getNonvirtualMethod(const char* name) const {
- return getNonvirtualMethod(name, jmethod_traits_from_cxx::descriptor().c_str());
-}
-
-template
-inline JNonvirtualMethod JClass::getNonvirtualMethod(
- const char* name,
- const char* descriptor) const {
- const auto env = Environment::current();
- const auto method = env->GetMethodID(self(), name, descriptor);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!method);
- return JNonvirtualMethod{method};
-}
-
-template
-inline JField(), T>>
-JClass::getField(const char* name) const {
- return getField(name, jtype_traits::descriptor().c_str());
-}
-
-template
-inline JField(), T>> JClass::getField(
- const char* name,
- const char* descriptor) const {
- const auto env = Environment::current();
- auto field = env->GetFieldID(self(), name, descriptor);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!field);
- return JField{field};
-}
-
-template
-inline JStaticField(), T>> JClass::getStaticField(
- const char* name) const {
- return getStaticField(name, jtype_traits::descriptor().c_str());
-}
-
-template
-inline JStaticField(), T>> JClass::getStaticField(
- const char* name,
- const char* descriptor) const {
- const auto env = Environment::current();
- auto field = env->GetStaticFieldID(self(), name, descriptor);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!field);
- return JStaticField{field};
-}
-
-template
-inline T JClass::getStaticFieldValue(JStaticField field) const noexcept {
- return field.get(self());
-}
-
-template
-inline local_ref JClass::getStaticFieldValue(JStaticField field) noexcept {
- return adopt_local(field.get(self()));
-}
-
-template
-inline void JClass::setStaticFieldValue(JStaticField field, T value) noexcept {
- field.set(self(), value);
-}
-
-template
-inline void JClass::setStaticFieldValue(JStaticField field, alias_ref value) noexcept {
- setStaticFieldValue(field, value.get());
-}
-
-template
-inline local_ref JClass::newObject(
- JConstructor constructor,
- Args... args) const {
- const auto env = Environment::current();
- auto object = env->NewObject(self(), constructor.getId(),
- detail::callToJni(
- detail::Convert::type>::toCall(args))...);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!object);
- return adopt_local(static_cast(object));
-}
-
-inline jclass JClass::self() const noexcept {
- return static_cast(JObject::self());
-}
-
-inline void registerNatives(const char* name, std::initializer_list methods) {
- findClassLocal(name)->registerNatives(methods);
-}
-
-
-// jstring /////////////////////////////////////////////////////////////////////////////////////////
-
-inline local_ref make_jstring(const std::string& modifiedUtf8) {
- return make_jstring(modifiedUtf8.c_str());
-}
-
-namespace detail {
-// convert to std::string from jstring
-template <>
-struct Convert {
- typedef jstring jniType;
- static std::string fromJni(jniType t) {
- return wrap_alias(t)->toStdString();
- }
- static jniType toJniRet(const std::string& t) {
- return make_jstring(t).release();
- }
- static local_ref toCall(const std::string& t) {
- return make_jstring(t);
- }
-};
-
-// convert return from const char*
-template <>
-struct Convert {
- typedef jstring jniType;
- // no automatic synthesis of const char*. (It can't be freed.)
- static jniType toJniRet(const char* t) {
- return make_jstring(t).release();
- }
- static local_ref toCall(const char* t) {
- return make_jstring(t);
- }
-};
-}
-
-// jtypeArray //////////////////////////////////////////////////////////////////////////////////////
-
-namespace detail {
-inline size_t JArray::size() const noexcept {
- const auto env = Environment::current();
- return env->GetArrayLength(self());
-}
-}
-
-namespace detail {
-template
-inline ElementProxy::ElementProxy(
- Target* target,
- size_t idx)
- : target_{target}, idx_{idx} {}
-
-template
-inline ElementProxy& ElementProxy::operator=(const T& o) {
- target_->setElement(idx_, o);
- return *this;
-}
-
-template
-inline ElementProxy& ElementProxy::operator=(alias_ref& o) {
- target_->setElement(idx_, o.get());
- return *this;
-}
-
-template
-inline ElementProxy& ElementProxy::operator=(alias_ref&& o) {
- target_->setElement(idx_, o.get());
- return *this;
-}
-
-template
-inline ElementProxy& ElementProxy::operator=(const ElementProxy& o) {
- auto src = o.target_->getElement(o.idx_);
- target_->setElement(idx_, src.get());
- return *this;
-}
-
-template
-inline ElementProxy::ElementProxy::operator const local_ref () const {
- return target_->getElement(idx_);
-}
-
-template
-inline ElementProxy::ElementProxy::operator local_ref () {
- return target_->getElement(idx_);
-}
-}
-
-template
-std::string JArrayClass::get_instantiated_java_descriptor() {
- return "[" + jtype_traits::descriptor();
-};
-
-template
-std::string JArrayClass::get_instantiated_base_name() {
- return get_instantiated_java_descriptor();
-};
-
-template
-auto JArrayClass::newArray(size_t size) -> local_ref {
- static const auto elementClass = findClassStatic(jtype_traits::base_name().c_str());
- const auto env = Environment::current();
- auto rawArray = env->NewObjectArray(size, elementClass.get(), nullptr);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!rawArray);
- return adopt_local(static_cast(rawArray));
-}
-
-template
-inline void JArrayClass::setElement(size_t idx, const T& value) {
- const auto env = Environment::current();
- env->SetObjectArrayElement(this->self(), idx, value);
-}
-
-template
-inline local_ref JArrayClass::getElement(size_t idx) {
- const auto env = Environment::current();
- auto rawElement = env->GetObjectArrayElement(this->self(), idx);
- return adopt_local(static_cast(rawElement));
-}
-
-template
-inline detail::ElementProxy> JArrayClass::operator[](size_t index) {
- return detail::ElementProxy>(this, index);
-}
-
-template
-local_ref::javaobject> adopt_local_array(jobjectArray ref) {
- return adopt_local(static_cast::javaobject>(ref));
-}
-
-// jarray /////////////////////////////////////////////////////////////////////////////////////////
-
-template
-auto JPrimitiveArray::getRegion(jsize start, jsize length)
- -> std::unique_ptr {
- auto buf = std::unique_ptr{new T[length]};
- getRegion(start, length, buf.get());
- return buf;
-}
-
-template
-std::string JPrimitiveArray::get_instantiated_java_descriptor() {
- return jtype_traits::descriptor();
-}
-template
-std::string JPrimitiveArray::get_instantiated_base_name() {
- return JPrimitiveArray::get_instantiated_java_descriptor();
-}
-
-template
-auto JPrimitiveArray::pin() -> PinnedPrimitiveArray> {
- return PinnedPrimitiveArray>{this->self(), 0, 0};
-}
-
-template
-auto JPrimitiveArray::pinRegion(jsize start, jsize length)
- -> PinnedPrimitiveArray> {
- return PinnedPrimitiveArray>{this->self(), start, length};
-}
-
-template
-auto JPrimitiveArray::pinCritical()
- -> PinnedPrimitiveArray> {
- return PinnedPrimitiveArray>{this->self(), 0, 0};
-}
-
-template
-class PinnedArrayAlloc {
- public:
- static void allocate(
- alias_ref::array_type> array,
- jsize start,
- jsize length,
- T** elements,
- size_t* size,
- jboolean* isCopy) {
- (void) start;
- (void) length;
- *elements = array->getElements(isCopy);
- *size = array->size();
- }
- static void release(
- alias_ref::array_type> array,
- T* elements,
- jint start,
- jint size,
- jint mode) {
- (void) start;
- (void) size;
- array->releaseElements(elements, mode);
- }
-};
-
-template
-class PinnedCriticalAlloc {
- public:
- static void allocate(
- alias_ref::array_type> array,
- jsize start,
- jsize length,
- T** elements,
- size_t* size,
- jboolean* isCopy) {
- (void)start;
- (void)length;
- const auto env = Environment::current();
- *elements = static_cast(env->GetPrimitiveArrayCritical(array.get(), isCopy));
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!elements);
- *size = array->size();
- }
- static void release(
- alias_ref::array_type> array,
- T* elements,
- jint start,
- jint size,
- jint mode) {
- (void)start;
- (void)size;
- const auto env = Environment::current();
- env->ReleasePrimitiveArrayCritical(array.get(), elements, mode);
- }
-};
-
-template
-class PinnedRegionAlloc {
- public:
- static void allocate(
- alias_ref::array_type> array,
- jsize start,
- jsize length,
- T** elements,
- size_t* size,
- jboolean* isCopy) {
- auto buf = array->getRegion(start, length);
- FACEBOOK_JNI_THROW_EXCEPTION_IF(!buf);
- *elements = buf.release();
- *size = length;
- *isCopy = true;
- }
- static void release(
- alias_ref::array_type> array,
- T* elements,
- jint start,
- jint size,
- jint mode) {
- std::unique_ptr holder;
- if (mode == 0 || mode == JNI_ABORT) {
- holder.reset(elements);
- }
- if (mode == 0 || mode == JNI_COMMIT) {
- array->setRegion(start, size, elements);
- }
- }
-};
-
-// PinnedPrimitiveArray ///////////////////////////////////////////////////////////////////////////
-
-template
-PinnedPrimitiveArray::PinnedPrimitiveArray(PinnedPrimitiveArray&& o) {
- *this = std::move(o);
-}
-
-template
-PinnedPrimitiveArray&
-PinnedPrimitiveArray::operator=(PinnedPrimitiveArray&& o) {
- if (array_) {
- release();
- }
- array_ = std::move(o.array_);
- elements_ = o.elements_;
- isCopy_ = o.isCopy_;
- size_ = o.size_;
- start_ = o.start_;
- o.clear();
- return *this;
-}
-
-template
-T* PinnedPrimitiveArray::get() {
- return elements_;
-}
-
-template
-inline void PinnedPrimitiveArray::release() {
- releaseImpl(0);
- clear();
-}
-
-template
-inline void PinnedPrimitiveArray::commit() {
- releaseImpl(JNI_COMMIT);
-}
-
-template
-inline void PinnedPrimitiveArray