Remove dart:jni (flutter/engine#3546)
Fixes https://github.com/flutter/flutter/issues/9129
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
source_set("jni") {
|
||||
sources = [
|
||||
"dart_jni.cc",
|
||||
"dart_jni.h",
|
||||
"jni_api.cc",
|
||||
"jni_api.h",
|
||||
"jni_array.cc",
|
||||
"jni_array.h",
|
||||
"jni_class.cc",
|
||||
"jni_class.h",
|
||||
"jni_object.cc",
|
||||
"jni_object.h",
|
||||
"jni_string.cc",
|
||||
"jni_string.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//flutter/fml",
|
||||
"//lib/tonic",
|
||||
]
|
||||
}
|
||||
@@ -1,410 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
|
||||
#include "flutter/fml/platform/android/scoped_java_ref.h"
|
||||
#include "flutter/lib/jni/jni_api.h"
|
||||
#include "flutter/lib/jni/jni_array.h"
|
||||
#include "flutter/lib/jni/jni_class.h"
|
||||
#include "flutter/lib/jni/jni_object.h"
|
||||
#include "flutter/lib/jni/jni_string.h"
|
||||
#include "lib/tonic/converter/dart_converter.h"
|
||||
#include "lib/tonic/dart_args.h"
|
||||
#include "lib/tonic/dart_binding_macros.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
using fml::jni::ScopedJavaGlobalRef;
|
||||
using fml::jni::ScopedJavaLocalRef;
|
||||
using tonic::DartConverter;
|
||||
using tonic::StdStringToDart;
|
||||
using tonic::ToDart;
|
||||
|
||||
namespace {
|
||||
|
||||
tonic::DartLibraryNatives* g_natives = nullptr;
|
||||
|
||||
Dart_NativeFunction GetNativeFunction(Dart_Handle name,
|
||||
int argument_count,
|
||||
bool* auto_setup_scope) {
|
||||
return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
|
||||
}
|
||||
|
||||
const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
|
||||
return g_natives->GetSymbol(native_function);
|
||||
}
|
||||
|
||||
// Data cached from the Java VM.
|
||||
struct DartJniJvmData {
|
||||
ScopedJavaGlobalRef<jobject> class_loader;
|
||||
ScopedJavaGlobalRef<jclass> class_clazz;
|
||||
jmethodID class_loader_load_class_method_id;
|
||||
jmethodID class_get_name_method_id;
|
||||
};
|
||||
|
||||
DartJniJvmData* g_jvm_data = nullptr;
|
||||
DartJniIsolateDataProvider g_isolate_data_provider = nullptr;
|
||||
|
||||
DartJniIsolateData* IsolateData() {
|
||||
return g_isolate_data_provider();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// Check if a JNI API has thrown an exception. If so, convert it to a
|
||||
// Dart exception.
|
||||
bool CheckJniException(JNIEnv* env, Dart_Handle* exception) {
|
||||
if (env->ExceptionCheck() == JNI_FALSE)
|
||||
return false;
|
||||
|
||||
jthrowable java_throwable = env->ExceptionOccurred();
|
||||
env->ExceptionClear();
|
||||
std::string info = fml::jni::GetJavaExceptionInfo(env, java_throwable);
|
||||
|
||||
*exception = StdStringToDart(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if a Dart API returned an error handle.
|
||||
bool CheckDartException(Dart_Handle result, Dart_Handle* exception) {
|
||||
if (!Dart_IsError(result))
|
||||
return false;
|
||||
|
||||
*exception = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
DART_NATIVE_CALLBACK_STATIC(JniApi, FromReflectedField);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniApi, FromReflectedMethod);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniApi, GetApplicationContext);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniApi, GetClassLoader);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniBooleanArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniByteArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniCharArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniClass, FromName);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniClass, FromClassObject);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniDoubleArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniFloatArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniIntArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniLongArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniObjectArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniShortArray, Create);
|
||||
DART_NATIVE_CALLBACK_STATIC(JniString, Create);
|
||||
|
||||
#define FOR_EACH_BINDING(V) \
|
||||
V(JniArray, GetLength) \
|
||||
V(JniBooleanArray, GetArrayElement) \
|
||||
V(JniBooleanArray, SetArrayElement) \
|
||||
V(JniByteArray, GetArrayElement) \
|
||||
V(JniByteArray, SetArrayElement) \
|
||||
V(JniCharArray, GetArrayElement) \
|
||||
V(JniCharArray, SetArrayElement) \
|
||||
V(JniClass, CallStaticBooleanMethod) \
|
||||
V(JniClass, CallStaticByteMethod) \
|
||||
V(JniClass, CallStaticCharMethod) \
|
||||
V(JniClass, CallStaticDoubleMethod) \
|
||||
V(JniClass, CallStaticFloatMethod) \
|
||||
V(JniClass, CallStaticIntMethod) \
|
||||
V(JniClass, CallStaticLongMethod) \
|
||||
V(JniClass, CallStaticObjectMethod) \
|
||||
V(JniClass, CallStaticShortMethod) \
|
||||
V(JniClass, CallStaticVoidMethod) \
|
||||
V(JniClass, GetFieldId) \
|
||||
V(JniClass, GetMethodId) \
|
||||
V(JniClass, GetStaticBooleanField) \
|
||||
V(JniClass, GetStaticByteField) \
|
||||
V(JniClass, GetStaticCharField) \
|
||||
V(JniClass, GetStaticDoubleField) \
|
||||
V(JniClass, GetStaticFieldId) \
|
||||
V(JniClass, GetStaticFloatField) \
|
||||
V(JniClass, GetStaticIntField) \
|
||||
V(JniClass, GetStaticLongField) \
|
||||
V(JniClass, GetStaticMethodId) \
|
||||
V(JniClass, GetStaticObjectField) \
|
||||
V(JniClass, GetStaticShortField) \
|
||||
V(JniClass, IsAssignable) \
|
||||
V(JniClass, NewObject) \
|
||||
V(JniClass, SetStaticBooleanField) \
|
||||
V(JniClass, SetStaticByteField) \
|
||||
V(JniClass, SetStaticCharField) \
|
||||
V(JniClass, SetStaticDoubleField) \
|
||||
V(JniClass, SetStaticFloatField) \
|
||||
V(JniClass, SetStaticIntField) \
|
||||
V(JniClass, SetStaticLongField) \
|
||||
V(JniClass, SetStaticObjectField) \
|
||||
V(JniClass, SetStaticShortField) \
|
||||
V(JniDoubleArray, GetArrayElement) \
|
||||
V(JniDoubleArray, SetArrayElement) \
|
||||
V(JniFloatArray, GetArrayElement) \
|
||||
V(JniFloatArray, SetArrayElement) \
|
||||
V(JniIntArray, GetArrayElement) \
|
||||
V(JniIntArray, SetArrayElement) \
|
||||
V(JniLongArray, GetArrayElement) \
|
||||
V(JniLongArray, SetArrayElement) \
|
||||
V(JniObject, CallBooleanMethod) \
|
||||
V(JniObject, CallByteMethod) \
|
||||
V(JniObject, CallCharMethod) \
|
||||
V(JniObject, CallDoubleMethod) \
|
||||
V(JniObject, CallFloatMethod) \
|
||||
V(JniObject, CallIntMethod) \
|
||||
V(JniObject, CallLongMethod) \
|
||||
V(JniObject, CallObjectMethod) \
|
||||
V(JniObject, CallShortMethod) \
|
||||
V(JniObject, CallVoidMethod) \
|
||||
V(JniObject, GetBooleanField) \
|
||||
V(JniObject, GetByteField) \
|
||||
V(JniObject, GetCharField) \
|
||||
V(JniObject, GetDoubleField) \
|
||||
V(JniObject, GetFloatField) \
|
||||
V(JniObject, GetIntField) \
|
||||
V(JniObject, GetLongField) \
|
||||
V(JniObject, GetObjectClass) \
|
||||
V(JniObject, GetObjectField) \
|
||||
V(JniObject, GetShortField) \
|
||||
V(JniObject, SetBooleanField) \
|
||||
V(JniObject, SetByteField) \
|
||||
V(JniObject, SetCharField) \
|
||||
V(JniObject, SetDoubleField) \
|
||||
V(JniObject, SetFloatField) \
|
||||
V(JniObject, SetIntField) \
|
||||
V(JniObject, SetLongField) \
|
||||
V(JniObject, SetObjectField) \
|
||||
V(JniObject, SetShortField) \
|
||||
V(JniObjectArray, GetArrayElement) \
|
||||
V(JniObjectArray, SetArrayElement) \
|
||||
V(JniShortArray, GetArrayElement) \
|
||||
V(JniShortArray, SetArrayElement) \
|
||||
V(JniString, GetText)
|
||||
|
||||
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
|
||||
|
||||
void DartJni::InitForGlobal(DartJniIsolateDataProvider provider) {
|
||||
if (!g_isolate_data_provider)
|
||||
g_isolate_data_provider = provider;
|
||||
|
||||
if (!g_natives) {
|
||||
g_natives = new tonic::DartLibraryNatives();
|
||||
g_natives->Register(
|
||||
{DART_REGISTER_NATIVE_STATIC(JniApi, FromReflectedField),
|
||||
DART_REGISTER_NATIVE_STATIC(JniApi, FromReflectedMethod),
|
||||
DART_REGISTER_NATIVE_STATIC(JniApi, GetApplicationContext),
|
||||
DART_REGISTER_NATIVE_STATIC(JniApi, GetClassLoader),
|
||||
DART_REGISTER_NATIVE_STATIC(JniBooleanArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniByteArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniCharArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniClass, FromName),
|
||||
DART_REGISTER_NATIVE_STATIC(JniClass, FromClassObject),
|
||||
DART_REGISTER_NATIVE_STATIC(JniDoubleArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniFloatArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniIntArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniLongArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniObjectArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniShortArray, Create),
|
||||
DART_REGISTER_NATIVE_STATIC(JniString, Create),
|
||||
FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
|
||||
}
|
||||
}
|
||||
|
||||
void DartJni::InitForIsolate() {
|
||||
FTL_DCHECK(g_natives);
|
||||
|
||||
Dart_Handle jni_library = Dart_LookupLibrary(ToDart("dart:jni"));
|
||||
DART_CHECK_VALID(jni_library)
|
||||
|
||||
DART_CHECK_VALID(
|
||||
Dart_SetNativeResolver(jni_library, GetNativeFunction, GetSymbol));
|
||||
|
||||
Dart_Handle object_type =
|
||||
Dart_GetType(jni_library, ToDart("JniObject"), 0, nullptr);
|
||||
DART_CHECK_VALID(object_type);
|
||||
IsolateData()->jni_object_type = Dart_NewPersistentHandle(object_type);
|
||||
DART_CHECK_VALID(IsolateData()->jni_object_type);
|
||||
|
||||
Dart_Handle float_type =
|
||||
Dart_GetType(jni_library, ToDart("JniFloat"), 0, nullptr);
|
||||
DART_CHECK_VALID(float_type);
|
||||
IsolateData()->jni_float_type = Dart_NewPersistentHandle(float_type);
|
||||
DART_CHECK_VALID(IsolateData()->jni_float_type);
|
||||
}
|
||||
|
||||
bool DartJni::InitJni() {
|
||||
JNIEnv* env = fml::jni::AttachCurrentThread();
|
||||
|
||||
FTL_DCHECK(!g_jvm_data);
|
||||
g_jvm_data = new DartJniJvmData();
|
||||
|
||||
// TODO: The class loader must be set here.
|
||||
// g_jvm_data->class_loader.Reset(class_loader);
|
||||
|
||||
ScopedJavaLocalRef<jclass> class_loader_clazz(
|
||||
env, env->FindClass("java/lang/ClassLoader"));
|
||||
FTL_CHECK(!fml::jni::ClearException(env));
|
||||
|
||||
g_jvm_data->class_loader_load_class_method_id =
|
||||
env->GetMethodID(class_loader_clazz.obj(), "loadClass",
|
||||
"(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
FTL_CHECK(!fml::jni::ClearException(env));
|
||||
|
||||
g_jvm_data->class_clazz.Reset(env, env->FindClass("java/lang/Class"));
|
||||
FTL_CHECK(!fml::jni::ClearException(env));
|
||||
|
||||
g_jvm_data->class_get_name_method_id = env->GetMethodID(
|
||||
g_jvm_data->class_clazz.obj(), "getName", "()Ljava/lang/String;");
|
||||
FTL_CHECK(!fml::jni::ClearException(env));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DartJni::OnThreadExit() {
|
||||
fml::jni::DetachFromVM();
|
||||
}
|
||||
|
||||
ScopedJavaLocalRef<jclass> DartJni::GetClass(JNIEnv* env, const char* name) {
|
||||
jobject clazz =
|
||||
env->CallObjectMethod(g_jvm_data->class_loader.obj(),
|
||||
g_jvm_data->class_loader_load_class_method_id,
|
||||
fml::jni::StringToJavaString(env, name).obj());
|
||||
|
||||
return ScopedJavaLocalRef<jclass>(env, static_cast<jclass>(clazz));
|
||||
}
|
||||
|
||||
std::string DartJni::GetObjectClassName(JNIEnv* env, jobject obj) {
|
||||
jclass clazz = env->GetObjectClass(obj);
|
||||
FTL_DCHECK(clazz);
|
||||
jstring name = static_cast<jstring>(
|
||||
env->CallObjectMethod(clazz, g_jvm_data->class_get_name_method_id));
|
||||
FTL_DCHECK(name);
|
||||
|
||||
return fml::jni::JavaStringToString(env, name);
|
||||
}
|
||||
|
||||
jstring DartJni::DartToJavaString(JNIEnv* env,
|
||||
Dart_Handle dart_string,
|
||||
Dart_Handle* exception) {
|
||||
if (!Dart_IsString(dart_string)) {
|
||||
*exception = ToDart("Argument must be a string");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
intptr_t length;
|
||||
Dart_Handle result = Dart_StringLength(dart_string, &length);
|
||||
if (CheckDartException(result, exception))
|
||||
return nullptr;
|
||||
|
||||
std::vector<uint16_t> string_data(length);
|
||||
result = Dart_StringToUTF16(dart_string, string_data.data(), &length);
|
||||
if (CheckDartException(result, exception))
|
||||
return nullptr;
|
||||
|
||||
jstring java_string = env->NewString(string_data.data(), length);
|
||||
CheckJniException(env, exception);
|
||||
return java_string;
|
||||
}
|
||||
|
||||
jobject DartJni::class_loader() {
|
||||
return g_jvm_data->class_loader.obj();
|
||||
}
|
||||
|
||||
jclass DartJni::class_clazz() {
|
||||
return g_jvm_data->class_clazz.obj();
|
||||
}
|
||||
|
||||
Dart_Handle DartJni::jni_object_type() {
|
||||
Dart_Handle object_type =
|
||||
Dart_HandleFromPersistent(IsolateData()->jni_object_type);
|
||||
FTL_DCHECK(!Dart_IsError(object_type));
|
||||
return object_type;
|
||||
}
|
||||
|
||||
Dart_Handle DartJni::jni_float_type() {
|
||||
Dart_Handle float_type =
|
||||
Dart_HandleFromPersistent(IsolateData()->jni_float_type);
|
||||
FTL_DCHECK(!Dart_IsError(float_type));
|
||||
return float_type;
|
||||
}
|
||||
|
||||
void JniMethodArgs::Convert(JNIEnv* env,
|
||||
const std::vector<Dart_Handle>& dart_args,
|
||||
Dart_Handle* exception) {
|
||||
jvalues_.reserve(dart_args.size());
|
||||
|
||||
for (Dart_Handle dart_arg : dart_args) {
|
||||
jvalue value = DartToJavaValue(env, dart_arg, exception);
|
||||
if (*exception)
|
||||
return;
|
||||
jvalues_.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
jvalue JniMethodArgs::DartToJavaValue(JNIEnv* env,
|
||||
Dart_Handle dart_value,
|
||||
Dart_Handle* exception) {
|
||||
jvalue java_value = jvalue();
|
||||
|
||||
if (Dart_IsBoolean(dart_value)) {
|
||||
java_value.z = DartConverter<bool>::FromDart(dart_value);
|
||||
return java_value;
|
||||
}
|
||||
|
||||
if (Dart_IsInteger(dart_value)) {
|
||||
java_value.j = DartConverter<jlong>::FromDart(dart_value);
|
||||
return java_value;
|
||||
}
|
||||
|
||||
if (Dart_IsDouble(dart_value)) {
|
||||
java_value.d = DartConverter<jdouble>::FromDart(dart_value);
|
||||
return java_value;
|
||||
}
|
||||
|
||||
if (Dart_IsString(dart_value)) {
|
||||
java_value.l = DartJni::DartToJavaString(env, dart_value, exception);
|
||||
return java_value;
|
||||
}
|
||||
|
||||
if (Dart_IsNull(dart_value)) {
|
||||
java_value.l = nullptr;
|
||||
return java_value;
|
||||
}
|
||||
|
||||
bool is_object;
|
||||
Dart_Handle result =
|
||||
Dart_ObjectIsType(dart_value, DartJni::jni_object_type(), &is_object);
|
||||
if (CheckDartException(result, exception))
|
||||
return java_value;
|
||||
|
||||
if (is_object) {
|
||||
JniObject* jni_object = DartConverter<JniObject*>::FromDart(dart_value);
|
||||
if (jni_object != nullptr) {
|
||||
java_value.l = jni_object->java_object();
|
||||
} else {
|
||||
*exception = ToDart("Invalid JniObject argument");
|
||||
}
|
||||
return java_value;
|
||||
}
|
||||
|
||||
bool is_float;
|
||||
result = Dart_ObjectIsType(dart_value, DartJni::jni_float_type(), &is_float);
|
||||
if (CheckDartException(result, exception))
|
||||
return java_value;
|
||||
|
||||
if (is_float) {
|
||||
Dart_Handle value_handle = Dart_GetField(dart_value, ToDart("value"));
|
||||
if (CheckDartException(value_handle, exception))
|
||||
return java_value;
|
||||
|
||||
double double_value;
|
||||
result = Dart_DoubleValue(value_handle, &double_value);
|
||||
if (CheckDartException(result, exception))
|
||||
return java_value;
|
||||
|
||||
java_value.f = static_cast<jfloat>(double_value);
|
||||
return java_value;
|
||||
}
|
||||
|
||||
*exception = ToDart("Argument has unsupported data type");
|
||||
return java_value;
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,11 +0,0 @@
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
dart_jni_files = [
|
||||
"//flutter/lib/jni/jni_helper.dart",
|
||||
"//flutter/lib/jni/jni_raw.dart",
|
||||
"//flutter/lib/jni/jni.dart",
|
||||
]
|
||||
|
||||
dart_jni_path = "//flutter/lib/jni/jni.dart"
|
||||
@@ -1,100 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_JNI_DART_JNI_H_
|
||||
#define FLUTTER_LIB_JNI_DART_JNI_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/platform/android/jni_util.h"
|
||||
#include "lib/tonic/dart_library_natives.h"
|
||||
#include "lib/tonic/dart_wrappable.h"
|
||||
|
||||
#define ENTER_JNI() \
|
||||
JNIEnv* env = fml::jni::AttachCurrentThread(); \
|
||||
fml::jni::ScopedJavaLocalFrame java_frame(env);
|
||||
|
||||
namespace blink {
|
||||
|
||||
bool CheckJniException(JNIEnv* env, Dart_Handle* exception);
|
||||
bool CheckDartException(Dart_Handle result, Dart_Handle* exception);
|
||||
|
||||
// Data cached for each Dart isolate.
|
||||
struct DartJniIsolateData {
|
||||
Dart_PersistentHandle jni_object_type;
|
||||
Dart_PersistentHandle jni_float_type;
|
||||
};
|
||||
|
||||
typedef DartJniIsolateData* (*DartJniIsolateDataProvider)();
|
||||
|
||||
class DartJni {
|
||||
public:
|
||||
static void InitForGlobal(DartJniIsolateDataProvider provider);
|
||||
static void InitForIsolate();
|
||||
static bool InitJni();
|
||||
static void OnThreadExit();
|
||||
|
||||
static fml::jni::ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env,
|
||||
const char* name);
|
||||
|
||||
static std::string GetObjectClassName(JNIEnv* env, jobject obj);
|
||||
|
||||
static jstring DartToJavaString(JNIEnv* env,
|
||||
Dart_Handle dart_string,
|
||||
Dart_Handle* exception);
|
||||
|
||||
static jobject class_loader();
|
||||
static jclass class_clazz();
|
||||
static Dart_Handle jni_object_type();
|
||||
static Dart_Handle jni_float_type();
|
||||
};
|
||||
|
||||
class JniMethodArgs {
|
||||
public:
|
||||
void Convert(JNIEnv* env,
|
||||
const std::vector<Dart_Handle>& dart_args,
|
||||
Dart_Handle* exception);
|
||||
jvalue* jvalues() { return jvalues_.data(); }
|
||||
|
||||
private:
|
||||
jvalue DartToJavaValue(JNIEnv* env,
|
||||
Dart_Handle handle,
|
||||
Dart_Handle* exception);
|
||||
|
||||
std::vector<jvalue> jvalues_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
namespace tonic {
|
||||
|
||||
template <>
|
||||
struct DartConverter<jfieldID> {
|
||||
static jfieldID FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
int64_t result = 0;
|
||||
Dart_Handle handle = Dart_GetNativeIntegerArgument(args, index, &result);
|
||||
if (Dart_IsError(handle))
|
||||
exception = handle;
|
||||
return reinterpret_cast<jfieldID>(result);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DartConverter<jmethodID> {
|
||||
static jmethodID FromArguments(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception) {
|
||||
int64_t result = 0;
|
||||
Dart_Handle handle = Dart_GetNativeIntegerArgument(args, index, &result);
|
||||
if (Dart_IsError(handle))
|
||||
exception = handle;
|
||||
return reinterpret_cast<jmethodID>(result);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace tonic
|
||||
|
||||
#endif // FLUTTER_LIB_JNI_DART_JNI_H_
|
||||
@@ -1,67 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/// Invoke Java Native Interface APIs from Dart.
|
||||
///
|
||||
/// To use, import `dart:jni`.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// JavaClass dateFormatClass = Java.getClass('java.text.SimpleDateFormat');
|
||||
/// JavaObject format = dateFormatClass.newInstance('yyyy.MM.dd');
|
||||
/// print(format.parse('2016.01.01').getYear());
|
||||
///
|
||||
/// This library provides a way to access Java classes that are accessible to
|
||||
/// the Android runtime hosting Flutter (including Android system APIs).
|
||||
///
|
||||
/// The library consists of two parts: a raw module that offers Dart access
|
||||
/// to low-level JNI functions, and a helper module that uses reflection to
|
||||
/// build Java object wrappers that act like standard Dart objects.
|
||||
///
|
||||
/// # Raw JNI
|
||||
///
|
||||
/// Call [JniClass.fromName] to load a JNI class given its fully-qualified name.
|
||||
/// The resulting [JniClass] object provides methods for constructing instances,
|
||||
/// looking up field and method IDs, getting and setting static fields, and calling
|
||||
/// static methods. These methods closely match the JNI functions provided by the VM.
|
||||
///
|
||||
/// Getters/setters of object fields and calls to methods that return objects will
|
||||
/// return instances of [JniObject]. [JniObject] similarly offers wrappers of the
|
||||
/// JNI functions that get and set object fields and call object methods.
|
||||
///
|
||||
/// Array instances are represented by [JniArray] and its subclasses, which provide
|
||||
/// a Dart [List] interface backed by an underlying Java array.
|
||||
///
|
||||
/// # Java Object Wrappers
|
||||
///
|
||||
/// Call [Java.getClass] to create a [JavaClass] instance that acts as a higher-level
|
||||
/// wrapper for a Java class. Using this wrapper, you can call static methods and read
|
||||
/// and write static fields using standard Dart field and method syntax. The wrapper
|
||||
/// will use reflection to locate the corresponding Java fields and methods and map Dart
|
||||
/// operations to JNI calls.
|
||||
///
|
||||
/// Use the [JavaClass.newInstance] method to construct instances of the class.
|
||||
/// `newInstance` will pass its arguments to the appropriate constructor.
|
||||
///
|
||||
/// Instances of Java objects are represented by [JavaObject], which similarly exposes
|
||||
/// field and method accessors derived via reflection.
|
||||
///
|
||||
/// Dart boolean, number, and string types as well as [JavaObject] instances can be passed
|
||||
/// as arguments to wrapped Java methods. The JNI libraries will convert these arguments
|
||||
/// from Dart types to the matching Java type.
|
||||
///
|
||||
/// Dart does not support function overloading, and as a result the Java method
|
||||
/// wrappers need to locate the method on the underlying Java class that most closely
|
||||
/// matches the arguments passed to the wrapper. If there are multiple Java method overloads
|
||||
/// that could be suitable for a given set of arguments and the wrappers do not choose the
|
||||
/// desired overload, then you can obtain the [JniObject] wrapped by the [JavaObject] and
|
||||
/// use the raw JNI library to invoke the method.
|
||||
|
||||
library dart_jni;
|
||||
|
||||
import 'dart:collection';
|
||||
import 'dart:nativewrappers';
|
||||
|
||||
part 'jni_raw.dart';
|
||||
part 'jni_helper.dart';
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/lib/jni/jni_api.h"
|
||||
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
int64_t JniApi::FromReflectedField(const JniObject* field) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfieldID result = env->FromReflectedField(field->java_object());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return reinterpret_cast<int64_t>(result);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniApi::FromReflectedMethod(const JniObject* method) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jmethodID result = env->FromReflectedMethod(method->java_object());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return reinterpret_cast<int64_t>(result);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniApi::GetApplicationContext() {
|
||||
ENTER_JNI();
|
||||
return JniObject::Create(env, fml::jni::GetAndroidApplicationContext());
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniApi::GetClassLoader() {
|
||||
ENTER_JNI();
|
||||
return JniObject::Create(env, DartJni::class_loader());
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_JNI_JNI_API_H_
|
||||
#define FLUTTER_LIB_JNI_JNI_API_H_
|
||||
|
||||
#include "flutter/lib/jni/jni_class.h"
|
||||
#include "flutter/lib/jni/jni_object.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// Dart wrappers for basic JNI APIs.
|
||||
class JniApi {
|
||||
public:
|
||||
static int64_t FromReflectedField(const JniObject* field);
|
||||
static int64_t FromReflectedMethod(const JniObject* method);
|
||||
static ftl::RefPtr<JniObject> GetApplicationContext();
|
||||
static ftl::RefPtr<JniObject> GetClassLoader();
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_JNI_JNI_API_H_
|
||||
@@ -1,579 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/lib/jni/jni_array.h"
|
||||
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniArray);
|
||||
|
||||
JniArray::JniArray(JNIEnv* env, jarray array) : JniObject(env, array) {}
|
||||
|
||||
JniArray::~JniArray() {}
|
||||
|
||||
jsize JniArray::GetLength() {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jsize result = env->GetArrayLength(java_array<jarray>());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename JArrayType>
|
||||
JArrayType JniArray::java_array() const {
|
||||
return static_cast<JArrayType>(java_object());
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniObjectArray);
|
||||
|
||||
JniObjectArray::JniObjectArray(JNIEnv* env, jobjectArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniObjectArray::~JniObjectArray() {}
|
||||
|
||||
ftl::RefPtr<JniObjectArray> JniObjectArray::Create(const JniClass* clazz,
|
||||
jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jobjectArray array =
|
||||
env->NewObjectArray(length, clazz->java_class(), nullptr);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniObjectArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniObjectArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jobject obj = env->GetObjectArrayElement(java_array<jobjectArray>(), index);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return JniObject::Create(env, obj);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JniObjectArray::SetArrayElement(jsize index, const JniObject* value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetObjectArrayElement(java_array<jobjectArray>(), index,
|
||||
value ? value->java_object() : nullptr);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniBooleanArray);
|
||||
|
||||
JniBooleanArray::JniBooleanArray(JNIEnv* env, jbooleanArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniBooleanArray::~JniBooleanArray() {}
|
||||
|
||||
ftl::RefPtr<JniBooleanArray> JniBooleanArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jbooleanArray array = env->NewBooleanArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniBooleanArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JniBooleanArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jboolean result;
|
||||
env->GetBooleanArrayRegion(java_array<jbooleanArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result == JNI_TRUE;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniBooleanArray::SetArrayElement(jsize index, bool value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jboolean jni_value = value ? JNI_TRUE : JNI_FALSE;
|
||||
env->SetBooleanArrayRegion(java_array<jbooleanArray>(), index, 1,
|
||||
&jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniByteArray);
|
||||
|
||||
JniByteArray::JniByteArray(JNIEnv* env, jbyteArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniByteArray::~JniByteArray() {}
|
||||
|
||||
ftl::RefPtr<JniByteArray> JniByteArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jbyteArray array = env->NewByteArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniByteArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t JniByteArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jbyte result;
|
||||
env->GetByteArrayRegion(java_array<jbyteArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniByteArray::SetArrayElement(jsize index, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jbyte jni_value = static_cast<jbyte>(value);
|
||||
env->SetByteArrayRegion(java_array<jbyteArray>(), index, 1, &jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniCharArray);
|
||||
|
||||
JniCharArray::JniCharArray(JNIEnv* env, jcharArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniCharArray::~JniCharArray() {}
|
||||
|
||||
ftl::RefPtr<JniCharArray> JniCharArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jcharArray array = env->NewCharArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniCharArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t JniCharArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jchar result;
|
||||
env->GetCharArrayRegion(java_array<jcharArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniCharArray::SetArrayElement(jsize index, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jchar jni_value = static_cast<jchar>(value);
|
||||
env->SetCharArrayRegion(java_array<jcharArray>(), index, 1, &jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniShortArray);
|
||||
|
||||
JniShortArray::JniShortArray(JNIEnv* env, jshortArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniShortArray::~JniShortArray() {}
|
||||
|
||||
ftl::RefPtr<JniShortArray> JniShortArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jshortArray array = env->NewShortArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniShortArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t JniShortArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jshort result;
|
||||
env->GetShortArrayRegion(java_array<jshortArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniShortArray::SetArrayElement(jsize index, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jshort jni_value = static_cast<jshort>(value);
|
||||
env->SetShortArrayRegion(java_array<jshortArray>(), index, 1, &jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniIntArray);
|
||||
|
||||
JniIntArray::JniIntArray(JNIEnv* env, jintArray array) : JniArray(env, array) {}
|
||||
|
||||
JniIntArray::~JniIntArray() {}
|
||||
|
||||
ftl::RefPtr<JniIntArray> JniIntArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jintArray array = env->NewIntArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniIntArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t JniIntArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jint result;
|
||||
env->GetIntArrayRegion(java_array<jintArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniIntArray::SetArrayElement(jsize index, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jint jni_value = static_cast<jint>(value);
|
||||
env->SetIntArrayRegion(java_array<jintArray>(), index, 1, &jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniLongArray);
|
||||
|
||||
JniLongArray::JniLongArray(JNIEnv* env, jlongArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniLongArray::~JniLongArray() {}
|
||||
|
||||
ftl::RefPtr<JniLongArray> JniLongArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jlongArray array = env->NewLongArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniLongArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t JniLongArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jlong result;
|
||||
env->GetLongArrayRegion(java_array<jlongArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return static_cast<int64_t>(result);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniLongArray::SetArrayElement(jsize index, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jlong jni_value = static_cast<jlong>(value);
|
||||
env->SetLongArrayRegion(java_array<jlongArray>(), index, 1, &jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniFloatArray);
|
||||
|
||||
JniFloatArray::JniFloatArray(JNIEnv* env, jfloatArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniFloatArray::~JniFloatArray() {}
|
||||
|
||||
ftl::RefPtr<JniFloatArray> JniFloatArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloatArray array = env->NewFloatArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniFloatArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
double JniFloatArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloat result;
|
||||
env->GetFloatArrayRegion(java_array<jfloatArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniFloatArray::SetArrayElement(jsize index, double value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloat jni_value = static_cast<jfloat>(value);
|
||||
env->SetFloatArrayRegion(java_array<jfloatArray>(), index, 1, &jni_value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniDoubleArray);
|
||||
|
||||
JniDoubleArray::JniDoubleArray(JNIEnv* env, jdoubleArray array)
|
||||
: JniArray(env, array) {}
|
||||
|
||||
JniDoubleArray::~JniDoubleArray() {}
|
||||
|
||||
ftl::RefPtr<JniDoubleArray> JniDoubleArray::Create(jsize length) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jdoubleArray array = env->NewDoubleArray(length);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniDoubleArray>(env, array);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
double JniDoubleArray::GetArrayElement(jsize index) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jdouble result;
|
||||
env->GetDoubleArrayRegion(java_array<jdoubleArray>(), index, 1, &result);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void JniDoubleArray::SetArrayElement(jsize index, double value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetDoubleArrayRegion(java_array<jdoubleArray>(), index, 1, &value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,177 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_JNI_JNI_ARRAY_H_
|
||||
#define FLUTTER_LIB_JNI_JNI_ARRAY_H_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "flutter/lib/jni/jni_class.h"
|
||||
#include "flutter/lib/jni/jni_object.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// Wrapper for a JNI array
|
||||
class JniArray : public JniObject {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
|
||||
public:
|
||||
~JniArray() override;
|
||||
|
||||
jsize GetLength();
|
||||
|
||||
protected:
|
||||
JniArray(JNIEnv* env, jarray array);
|
||||
template <typename JArrayType>
|
||||
JArrayType java_array() const;
|
||||
};
|
||||
|
||||
class JniObjectArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniObjectArray);
|
||||
|
||||
public:
|
||||
~JniObjectArray() override;
|
||||
|
||||
static ftl::RefPtr<JniObjectArray> Create(const JniClass* clazz,
|
||||
jsize length);
|
||||
ftl::RefPtr<JniObject> GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, const JniObject* value);
|
||||
|
||||
private:
|
||||
JniObjectArray(JNIEnv* env, jobjectArray array);
|
||||
};
|
||||
|
||||
class JniBooleanArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniBooleanArray);
|
||||
|
||||
public:
|
||||
~JniBooleanArray() override;
|
||||
|
||||
static ftl::RefPtr<JniBooleanArray> Create(jsize length);
|
||||
bool GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, bool value);
|
||||
|
||||
private:
|
||||
JniBooleanArray(JNIEnv* env, jbooleanArray array);
|
||||
};
|
||||
|
||||
class JniByteArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniByteArray);
|
||||
|
||||
public:
|
||||
~JniByteArray() override;
|
||||
|
||||
static ftl::RefPtr<JniByteArray> Create(jsize length);
|
||||
int64_t GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, int64_t value);
|
||||
|
||||
private:
|
||||
JniByteArray(JNIEnv* env, jbyteArray array);
|
||||
};
|
||||
|
||||
class JniCharArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniCharArray);
|
||||
|
||||
public:
|
||||
~JniCharArray() override;
|
||||
|
||||
static ftl::RefPtr<JniCharArray> Create(jsize length);
|
||||
int64_t GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, int64_t value);
|
||||
|
||||
private:
|
||||
JniCharArray(JNIEnv* env, jcharArray array);
|
||||
};
|
||||
|
||||
class JniShortArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniShortArray);
|
||||
|
||||
public:
|
||||
~JniShortArray() override;
|
||||
|
||||
static ftl::RefPtr<JniShortArray> Create(jsize length);
|
||||
int64_t GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, int64_t value);
|
||||
|
||||
private:
|
||||
JniShortArray(JNIEnv* env, jshortArray array);
|
||||
};
|
||||
|
||||
class JniIntArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniIntArray);
|
||||
|
||||
public:
|
||||
~JniIntArray() override;
|
||||
|
||||
static ftl::RefPtr<JniIntArray> Create(jsize length);
|
||||
int64_t GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, int64_t value);
|
||||
|
||||
private:
|
||||
JniIntArray(JNIEnv* env, jintArray array);
|
||||
};
|
||||
|
||||
class JniLongArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniLongArray);
|
||||
|
||||
public:
|
||||
~JniLongArray() override;
|
||||
|
||||
static ftl::RefPtr<JniLongArray> Create(jsize length);
|
||||
int64_t GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, int64_t value);
|
||||
|
||||
private:
|
||||
JniLongArray(JNIEnv* env, jlongArray array);
|
||||
};
|
||||
|
||||
class JniFloatArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniFloatArray);
|
||||
|
||||
public:
|
||||
~JniFloatArray() override;
|
||||
|
||||
static ftl::RefPtr<JniFloatArray> Create(jsize length);
|
||||
double GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, double value);
|
||||
|
||||
private:
|
||||
JniFloatArray(JNIEnv* env, jfloatArray array);
|
||||
};
|
||||
|
||||
class JniDoubleArray : public JniArray {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniDoubleArray);
|
||||
|
||||
public:
|
||||
~JniDoubleArray() override;
|
||||
|
||||
static ftl::RefPtr<JniDoubleArray> Create(jsize length);
|
||||
double GetArrayElement(jsize index);
|
||||
void SetArrayElement(jsize index, double value);
|
||||
|
||||
private:
|
||||
JniDoubleArray(JNIEnv* env, jdoubleArray array);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_JNI_JNI_ARRAY_H_
|
||||
@@ -1,720 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/lib/jni/jni_class.h"
|
||||
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
using tonic::ToDart;
|
||||
using fml::jni::ScopedJavaLocalRef;
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniClass);
|
||||
|
||||
JniClass::JniClass(JNIEnv* env, jclass clazz) : JniObject(env, clazz) {}
|
||||
|
||||
JniClass::~JniClass() {}
|
||||
|
||||
ftl::RefPtr<JniClass> JniClass::FromName(const char* name) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
if (!name)
|
||||
return nullptr;
|
||||
|
||||
ScopedJavaLocalRef<jclass> clazz = DartJni::GetClass(env, name);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniClass>(env, clazz.obj());
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniClass> JniClass::FromClassObject(const JniObject* clazz) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
if (!clazz)
|
||||
return nullptr;
|
||||
|
||||
jobject class_object = clazz->java_object();
|
||||
if (!env->IsInstanceOf(class_object, DartJni::class_clazz())) {
|
||||
exception = ToDart("invalid JNI class object");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ftl::MakeRefCounted<JniClass>(env,
|
||||
static_cast<jclass>(class_object));
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
intptr_t JniClass::GetFieldId(const char* name, const char* sig) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfieldID id = env->GetFieldID(java_class(), name, sig);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return reinterpret_cast<intptr_t>(id);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
intptr_t JniClass::GetStaticFieldId(const char* name, const char* sig) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfieldID id = env->GetStaticFieldID(java_class(), name, sig);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return reinterpret_cast<intptr_t>(id);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
intptr_t JniClass::GetMethodId(const char* name, const char* sig) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jmethodID id = env->GetMethodID(java_class(), name, sig);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return reinterpret_cast<intptr_t>(id);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
intptr_t JniClass::GetStaticMethodId(const char* name, const char* sig) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jmethodID id = env->GetStaticMethodID(java_class(), name, sig);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return reinterpret_cast<intptr_t>(id);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniClass::NewObject(
|
||||
jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jobject obj = env->NewObjectA(java_class(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return JniObject::Create(env, obj);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JniClass::IsAssignable(const JniClass* clazz) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jboolean result = env->IsAssignableFrom(java_class(), clazz->java_class());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result == JNI_TRUE;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniClass::GetStaticObjectField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jobject obj = env->GetStaticObjectField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return JniObject::Create(env, obj);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JniClass::GetStaticBooleanField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jboolean result = env->GetStaticBooleanField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result == JNI_TRUE;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t JniClass::GetStaticByteField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jbyte result = env->GetStaticByteField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::GetStaticCharField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jchar result = env->GetStaticCharField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::GetStaticShortField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jshort result = env->GetStaticShortField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::GetStaticIntField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jint result = env->GetStaticIntField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::GetStaticLongField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jlong result = env->GetStaticLongField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniClass::GetStaticFloatField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloat result = env->GetStaticFloatField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniClass::GetStaticDoubleField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloat result = env->GetStaticDoubleField(java_class(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticObjectField(jfieldID fieldId, const JniObject* value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticObjectField(java_class(), fieldId,
|
||||
value ? value->java_object() : nullptr);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticBooleanField(jfieldID fieldId, bool value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticBooleanField(java_class(), fieldId,
|
||||
value ? JNI_TRUE : JNI_FALSE);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticByteField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticByteField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticCharField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticCharField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticShortField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticShortField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticIntField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticIntField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticLongField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticLongField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticFloatField(jfieldID fieldId, double value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticFloatField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniClass::SetStaticDoubleField(jfieldID fieldId, double value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetStaticDoubleField(java_class(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniClass::CallStaticObjectMethod(
|
||||
jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jobject obj = env->CallStaticObjectMethodA(java_class(), methodId,
|
||||
java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return JniObject::Create(env, obj);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JniClass::CallStaticBooleanMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jboolean result = env->CallStaticBooleanMethodA(java_class(), methodId,
|
||||
java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result == JNI_TRUE;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t JniClass::CallStaticByteMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jbyte result =
|
||||
env->CallStaticByteMethodA(java_class(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::CallStaticCharMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jchar result =
|
||||
env->CallStaticCharMethodA(java_class(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::CallStaticShortMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jshort result = env->CallStaticShortMethodA(java_class(), methodId,
|
||||
java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::CallStaticIntMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jint result =
|
||||
env->CallStaticIntMethodA(java_class(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniClass::CallStaticLongMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jlong result =
|
||||
env->CallStaticLongMethodA(java_class(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniClass::CallStaticFloatMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jfloat result = env->CallStaticFloatMethodA(java_class(), methodId,
|
||||
java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniClass::CallStaticDoubleMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jdouble result = env->CallStaticDoubleMethodA(java_class(), methodId,
|
||||
java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void JniClass::CallStaticVoidMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
env->CallStaticVoidMethodA(java_class(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,87 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_JNI_JNI_CLASS_H_
|
||||
#define FLUTTER_LIB_JNI_JNI_CLASS_H_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "flutter/lib/jni/jni_object.h"
|
||||
#include "lib/tonic/dart_wrappable.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// Wrapper that exposes a JNI jclass to Dart
|
||||
class JniClass : public JniObject {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniClass);
|
||||
|
||||
public:
|
||||
~JniClass() override;
|
||||
|
||||
static ftl::RefPtr<JniClass> FromName(const char* className);
|
||||
static ftl::RefPtr<JniClass> FromClassObject(const JniObject* clazz);
|
||||
|
||||
jclass java_class() const { return static_cast<jclass>(object_.obj()); }
|
||||
|
||||
intptr_t GetFieldId(const char* name, const char* sig);
|
||||
intptr_t GetStaticFieldId(const char* name, const char* sig);
|
||||
intptr_t GetMethodId(const char* name, const char* sig);
|
||||
intptr_t GetStaticMethodId(const char* name, const char* sig);
|
||||
|
||||
ftl::RefPtr<JniObject> NewObject(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
|
||||
bool IsAssignable(const JniClass* clazz);
|
||||
|
||||
ftl::RefPtr<JniObject> GetStaticObjectField(jfieldID fieldId);
|
||||
bool GetStaticBooleanField(jfieldID fieldId);
|
||||
int64_t GetStaticByteField(jfieldID fieldId);
|
||||
int64_t GetStaticCharField(jfieldID fieldId);
|
||||
int64_t GetStaticShortField(jfieldID fieldId);
|
||||
int64_t GetStaticIntField(jfieldID fieldId);
|
||||
int64_t GetStaticLongField(jfieldID fieldId);
|
||||
double GetStaticFloatField(jfieldID fieldId);
|
||||
double GetStaticDoubleField(jfieldID fieldId);
|
||||
|
||||
void SetStaticObjectField(jfieldID fieldId, const JniObject* value);
|
||||
void SetStaticBooleanField(jfieldID fieldId, bool value);
|
||||
void SetStaticByteField(jfieldID fieldId, int64_t value);
|
||||
void SetStaticCharField(jfieldID fieldId, int64_t value);
|
||||
void SetStaticShortField(jfieldID fieldId, int64_t value);
|
||||
void SetStaticIntField(jfieldID fieldId, int64_t value);
|
||||
void SetStaticLongField(jfieldID fieldId, int64_t value);
|
||||
void SetStaticFloatField(jfieldID fieldId, double value);
|
||||
void SetStaticDoubleField(jfieldID fieldId, double value);
|
||||
|
||||
ftl::RefPtr<JniObject> CallStaticObjectMethod(
|
||||
jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
bool CallStaticBooleanMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallStaticByteMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallStaticCharMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallStaticShortMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallStaticIntMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallStaticLongMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
double CallStaticFloatMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
double CallStaticDoubleMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
void CallStaticVoidMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
|
||||
private:
|
||||
JniClass(JNIEnv* env, jclass clazz);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_JNI_JNI_CLASS_H_
|
||||
@@ -1,647 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of dart_jni;
|
||||
|
||||
class JavaError extends Error {
|
||||
JavaError(this._message);
|
||||
String _message;
|
||||
String toString() => _message;
|
||||
}
|
||||
|
||||
// JNI methods used to invoke Java reflection
|
||||
class _JavaReflect {
|
||||
JniClass classClazz;
|
||||
int classForName;
|
||||
int classGetConstructors;
|
||||
int classGetFields;
|
||||
int classGetMethods;
|
||||
int classGetName;
|
||||
int constructorGetParameterTypes;
|
||||
int fieldGetType;
|
||||
int memberGetModifiers;
|
||||
int memberGetName;
|
||||
int methodGetParameterTypes;
|
||||
int methodGetReturnType;
|
||||
int objectGetClass;
|
||||
int objectToString;
|
||||
JniClass stringClazz;
|
||||
|
||||
int modifierStatic;
|
||||
|
||||
_JavaReflect() {
|
||||
classClazz = JniClass.fromName('java.lang.Class');
|
||||
classForName = classClazz.getStaticMethodId('forName',
|
||||
'(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;');
|
||||
classGetConstructors = classClazz.getMethodId('getConstructors',
|
||||
'()[Ljava/lang/reflect/Constructor;');
|
||||
classGetFields = classClazz.getMethodId('getFields', '()[Ljava/lang/reflect/Field;');
|
||||
classGetMethods = classClazz.getMethodId('getMethods', '()[Ljava/lang/reflect/Method;');
|
||||
classGetName = classClazz.getMethodId('getName', '()Ljava/lang/String;');
|
||||
|
||||
JniClass constructorClazz = JniClass.fromName('java.lang.reflect.Constructor');
|
||||
constructorGetParameterTypes = constructorClazz.getMethodId(
|
||||
'getParameterTypes', '()[Ljava/lang/Class;');
|
||||
|
||||
JniClass fieldClazz = JniClass.fromName('java.lang.reflect.Field');
|
||||
fieldGetType = fieldClazz.getMethodId('getType', '()Ljava/lang/Class;');
|
||||
|
||||
JniClass memberClazz = JniClass.fromName('java.lang.reflect.Member');
|
||||
memberGetModifiers = memberClazz.getMethodId('getModifiers', '()I');
|
||||
memberGetName = memberClazz.getMethodId('getName', '()Ljava/lang/String;');
|
||||
|
||||
JniClass methodClazz = JniClass.fromName('java.lang.reflect.Method');
|
||||
methodGetParameterTypes = methodClazz.getMethodId(
|
||||
'getParameterTypes', '()[Ljava/lang/Class;');
|
||||
methodGetReturnType = methodClazz.getMethodId(
|
||||
'getReturnType', '()Ljava/lang/Class;');
|
||||
|
||||
JniClass modifierClazz = JniClass.fromName('java.lang.reflect.Modifier');
|
||||
modifierStatic = modifierClazz.getStaticIntField(
|
||||
modifierClazz.getStaticFieldId('STATIC', 'I'));
|
||||
|
||||
JniClass objectClazz = JniClass.fromName('java.lang.Object');
|
||||
objectGetClass = objectClazz.getMethodId('getClass', '()Ljava/lang/Class;');
|
||||
objectToString = objectClazz.getMethodId('toString', '()Ljava/lang/String;');
|
||||
|
||||
stringClazz = JniClass.fromName('java.lang.String');
|
||||
}
|
||||
}
|
||||
|
||||
final _JavaReflect _reflect = new _JavaReflect();
|
||||
|
||||
class _JavaType {
|
||||
final String name;
|
||||
final JniClass clazz;
|
||||
final bool isPrimitive;
|
||||
|
||||
_JavaType(this.name, this.clazz)
|
||||
: isPrimitive = false;
|
||||
|
||||
_JavaType._primitive(this.name)
|
||||
: clazz = null,
|
||||
isPrimitive = true;
|
||||
|
||||
String toString() => 'JavaType:$name';
|
||||
}
|
||||
|
||||
class _JavaPrimitive {
|
||||
static final _JavaType jvoid = new _JavaType._primitive('void');
|
||||
static final _JavaType jboolean = new _JavaType._primitive('boolean');
|
||||
static final _JavaType jbyte = new _JavaType._primitive('byte');
|
||||
static final _JavaType jchar = new _JavaType._primitive('char');
|
||||
static final _JavaType jshort = new _JavaType._primitive('short');
|
||||
static final _JavaType jint = new _JavaType._primitive('int');
|
||||
static final _JavaType jlong = new _JavaType._primitive('long');
|
||||
static final _JavaType jfloat = new _JavaType._primitive('float');
|
||||
static final _JavaType jdouble = new _JavaType._primitive('double');
|
||||
}
|
||||
|
||||
final Map<String, _JavaType> _typeCache = <String, _JavaType>{
|
||||
'void': _JavaPrimitive.jvoid,
|
||||
'boolean': _JavaPrimitive.jboolean,
|
||||
'byte': _JavaPrimitive.jbyte,
|
||||
'char': _JavaPrimitive.jchar,
|
||||
'short': _JavaPrimitive.jshort,
|
||||
'int': _JavaPrimitive.jint,
|
||||
'long': _JavaPrimitive.jlong,
|
||||
'float': _JavaPrimitive.jfloat,
|
||||
'double': _JavaPrimitive.jdouble,
|
||||
};
|
||||
|
||||
_JavaType _javaTypeForClass(JniClass clazz) {
|
||||
String className = JniString.unwrap(clazz.callObjectMethod(_reflect.classGetName, []));
|
||||
|
||||
_JavaType type = _typeCache[className];
|
||||
if (type != null)
|
||||
return type;
|
||||
|
||||
type = new _JavaType(className, clazz);
|
||||
_typeCache[className] = type;
|
||||
return type;
|
||||
}
|
||||
|
||||
class _JavaField {
|
||||
String name;
|
||||
int fieldId;
|
||||
_JavaType type;
|
||||
int modifiers;
|
||||
|
||||
_JavaField(JniObject field) {
|
||||
name = JniString.unwrap(field.callObjectMethod(_reflect.memberGetName, []));
|
||||
fieldId = JniApi.fromReflectedField(field);
|
||||
type = _javaTypeForClass(
|
||||
field.callObjectMethod(_reflect.fieldGetType, []));
|
||||
modifiers = field.callIntMethod(_reflect.memberGetModifiers, []);
|
||||
}
|
||||
|
||||
bool get isStatic => (modifiers & _reflect.modifierStatic) != 0;
|
||||
}
|
||||
|
||||
abstract class _HasArguments {
|
||||
String get name;
|
||||
List<_JavaType> get argTypes;
|
||||
int get methodId;
|
||||
}
|
||||
|
||||
class _JavaMethod implements _HasArguments {
|
||||
String _name;
|
||||
int _methodId;
|
||||
_JavaType returnType;
|
||||
int modifiers;
|
||||
List<_JavaType> _argTypes;
|
||||
|
||||
_JavaMethod(JniObject method) {
|
||||
_name = JniString.unwrap(method.callObjectMethod(_reflect.memberGetName, []));
|
||||
_methodId = JniApi.fromReflectedMethod(method);
|
||||
returnType = _javaTypeForClass(
|
||||
method.callObjectMethod(_reflect.methodGetReturnType, []));
|
||||
modifiers = method.callIntMethod(_reflect.memberGetModifiers, []);
|
||||
|
||||
JniObjectArray argClasses = method.callObjectMethod(_reflect.methodGetParameterTypes, []);
|
||||
_argTypes = new List<_JavaType>();
|
||||
for (JniObject argClass in argClasses) {
|
||||
_argTypes.add(_javaTypeForClass(argClass));
|
||||
}
|
||||
}
|
||||
|
||||
String get name => _name;
|
||||
List<_JavaType> get argTypes => _argTypes;
|
||||
int get methodId => _methodId;
|
||||
|
||||
bool get isStatic => (modifiers & _reflect.modifierStatic) != 0;
|
||||
}
|
||||
|
||||
class _JavaConstructor implements _HasArguments {
|
||||
String _name;
|
||||
int _methodId;
|
||||
List<_JavaType> _argTypes;
|
||||
|
||||
_JavaConstructor(JniObject ctor) {
|
||||
_name = JniString.unwrap(ctor.callObjectMethod(_reflect.memberGetName, []));
|
||||
_methodId = JniApi.fromReflectedMethod(ctor);
|
||||
|
||||
JniObjectArray argClasses = ctor.callObjectMethod(
|
||||
_reflect.constructorGetParameterTypes, []);
|
||||
_argTypes = new List<_JavaType>();
|
||||
for (JniObject argClass in argClasses) {
|
||||
_argTypes.add(_javaTypeForClass(argClass));
|
||||
}
|
||||
}
|
||||
|
||||
String get name => _name;
|
||||
List<_JavaType> get argTypes => _argTypes;
|
||||
int get methodId => _methodId;
|
||||
}
|
||||
|
||||
// Determines whether a Dart value can be used as a method argument declared as
|
||||
// the given Java type.
|
||||
bool _typeCompatible(dynamic value, _JavaType type) {
|
||||
if (type.isPrimitive) {
|
||||
if (type == _JavaPrimitive.jboolean) {
|
||||
return (value is bool);
|
||||
} else {
|
||||
return (value is num || value is bool || value is JniFloat);
|
||||
}
|
||||
}
|
||||
|
||||
if (value == null)
|
||||
return true;
|
||||
|
||||
if (value is JavaObject)
|
||||
return value.javaClass.jniClass.isAssignable(type.clazz);
|
||||
|
||||
if (value is JniObject)
|
||||
return value.getObjectClass().isAssignable(type.clazz);
|
||||
|
||||
if (value is String) {
|
||||
if (type.isPrimitive)
|
||||
return false;
|
||||
return _reflect.stringClazz.isAssignable(type.clazz);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Given a list of overloaded methods, select one that is the best match for
|
||||
// the provided arguments.
|
||||
_HasArguments _findMatchingMethod(List<_HasArguments> overloads, List args) {
|
||||
List<_HasArguments> matches = new List<_HasArguments>();
|
||||
for (_HasArguments overload in overloads) {
|
||||
if (overload.argTypes.length == args.length)
|
||||
matches.add(overload);
|
||||
}
|
||||
|
||||
if (matches.length == 1)
|
||||
return matches[0];
|
||||
|
||||
if (matches.isEmpty)
|
||||
throw new JavaError('Argument mismatch when invoking method ${overloads[0].name}');
|
||||
|
||||
outer: for (_HasArguments match in matches) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (!_typeCompatible(args[i], match.argTypes[i]))
|
||||
continue outer;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
throw new JavaError('Unable to find matching method for ${overloads[0].name}');
|
||||
}
|
||||
|
||||
// Convert an object received from JNI into the corresponding Dart type.
|
||||
dynamic _javaObjectToDart(JniObject object) {
|
||||
if (object == null)
|
||||
return null;
|
||||
|
||||
if (object is JniString)
|
||||
return object.text;
|
||||
|
||||
if (object is JniClass)
|
||||
return Java.wrapClassObject(object);
|
||||
|
||||
if (object is JniArray)
|
||||
return object;
|
||||
|
||||
return new JavaObject(object);
|
||||
}
|
||||
|
||||
// Convert a Dart object to a type suitable for passing to JNI.
|
||||
dynamic _dartObjectToJava(dynamic object, _JavaType javaType) {
|
||||
if (javaType.isPrimitive) {
|
||||
if (javaType == _JavaPrimitive.jboolean) {
|
||||
if (object is bool)
|
||||
return object;
|
||||
throw new JavaError('Unable to convert Dart object to Java boolean: $object');
|
||||
}
|
||||
if (javaType == _JavaPrimitive.jfloat) {
|
||||
if (object is JniFloat)
|
||||
return object;
|
||||
if (object is num)
|
||||
return new JniFloat(object);
|
||||
throw new JavaError('Unable to convert Dart object to Java float: $object');
|
||||
}
|
||||
|
||||
if (object is num)
|
||||
return object;
|
||||
throw new JavaError('Unable to convert Dart object to Java primitive type: $object');
|
||||
}
|
||||
|
||||
if (object == null)
|
||||
return object;
|
||||
|
||||
if (object is JniObject)
|
||||
return object;
|
||||
|
||||
if (object is JavaObject)
|
||||
return object.jniObject;
|
||||
|
||||
if (object is String)
|
||||
return JniString.create(object);
|
||||
|
||||
throw new JavaError('Unable to convert Dart object to Java: $object');
|
||||
}
|
||||
|
||||
List _convertArgumentsToJava(List dartArgs, _HasArguments method) {
|
||||
List result = new List();
|
||||
for (int i = 0; i < dartArgs.length; i++) {
|
||||
result.add(_dartObjectToJava(dartArgs[i], method.argTypes[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// A class that provides access to Java objects from within Dart.
|
||||
class Java {
|
||||
static final Map<String, JavaClass> _classCache = new Map<String, JavaClass>();
|
||||
|
||||
/// Returns a [JavaClass] for the given class name.
|
||||
static JavaClass getClass(String className) {
|
||||
JavaClass cacheEntry = _classCache[className];
|
||||
if (cacheEntry != null)
|
||||
return cacheEntry;
|
||||
|
||||
// Load and initialize the class
|
||||
JniClass jniClass = _reflect.classClazz.callStaticObjectMethod(
|
||||
_reflect.classForName,
|
||||
[className, true, JniApi.getClassLoader()]
|
||||
);
|
||||
|
||||
JavaClass javaClass = new JavaClass._(jniClass);
|
||||
_classCache[javaClass.className] = javaClass;
|
||||
return javaClass;
|
||||
}
|
||||
|
||||
/// Returns a [JavaClass] that wraps a raw JNI class object.
|
||||
static JavaClass wrapClassObject(dynamic classObject) {
|
||||
JniClass jniClass;
|
||||
if (classObject is JniClass) {
|
||||
jniClass = classObject;
|
||||
} else if (classObject is JavaObject && classObject.jniObject is JniClass) {
|
||||
jniClass = classObject.jniObject;
|
||||
} else {
|
||||
throw new JavaError('fromClassObject: $classObject is not a Java class');
|
||||
}
|
||||
|
||||
String className = JniString.unwrap(jniClass.callObjectMethod(_reflect.classGetName, []));
|
||||
JavaClass cacheEntry = _classCache[className];
|
||||
if (cacheEntry != null)
|
||||
return cacheEntry;
|
||||
|
||||
JavaClass javaClass = new JavaClass._(jniClass);
|
||||
_classCache[javaClass.className] = javaClass;
|
||||
return javaClass;
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper for a JNI class that uses reflection to provide access to the
|
||||
/// class' static fields, methods, and constructors.
|
||||
class JavaClass {
|
||||
JniClass _clazz;
|
||||
String _className;
|
||||
Map<Symbol, _JavaField> _fields;
|
||||
Map<Symbol, _JavaField> _staticFields;
|
||||
Map<Symbol, List<_JavaMethod>> _methods;
|
||||
Map<Symbol, List<_JavaMethod>> _staticMethods;
|
||||
List<_JavaConstructor> _constructors;
|
||||
|
||||
static final Symbol _newInstanceSymbol = new Symbol('newInstance');
|
||||
|
||||
JavaClass._(JniClass classObject) {
|
||||
_clazz = classObject;
|
||||
_className = JniString.unwrap(_clazz.callObjectMethod(_reflect.classGetName, []));
|
||||
|
||||
_fields = new Map<Symbol, _JavaField>();
|
||||
_staticFields = new Map<Symbol, _JavaField>();
|
||||
JniObjectArray reflectFields = _clazz.callObjectMethod(_reflect.classGetFields, []);
|
||||
for (JniObject reflectField in reflectFields) {
|
||||
_JavaField javaField = new _JavaField(reflectField);
|
||||
Map<Symbol, _JavaField> fieldMap =
|
||||
javaField.isStatic ? _staticFields : _fields;
|
||||
fieldMap[new Symbol(javaField.name)] = javaField;
|
||||
|
||||
// Dart will identify the field setter with a symbol name ending with an equal sign.
|
||||
fieldMap[new Symbol(javaField.name + '=')] = javaField;
|
||||
}
|
||||
|
||||
_methods = new Map<Symbol, List<_JavaMethod>>();
|
||||
_staticMethods = new Map<Symbol, List<_JavaMethod>>();
|
||||
JniObjectArray reflectMethods = _clazz.callObjectMethod(_reflect.classGetMethods, []);
|
||||
for (JniObject reflectMethod in reflectMethods) {
|
||||
_JavaMethod javaMethod = new _JavaMethod(reflectMethod);
|
||||
Map<Symbol, List<_JavaMethod>> methodMap =
|
||||
javaMethod.isStatic ? _staticMethods : _methods;
|
||||
Symbol symbol = new Symbol(javaMethod.name);
|
||||
List<_JavaMethod> overloads = methodMap[symbol];
|
||||
if (overloads != null) {
|
||||
overloads.add(javaMethod);
|
||||
} else {
|
||||
methodMap[symbol] = <_JavaMethod>[javaMethod];
|
||||
}
|
||||
}
|
||||
|
||||
_constructors = new List<_JavaConstructor>();
|
||||
JniObjectArray reflectCtors = _clazz.callObjectMethod(_reflect.classGetConstructors, []);
|
||||
for (JniObject ctor in reflectCtors) {
|
||||
_constructors.add(new _JavaConstructor(ctor));
|
||||
}
|
||||
}
|
||||
|
||||
String toString() => 'JavaClass:$_className';
|
||||
|
||||
/// The name of the wrapped Java class.
|
||||
String get className => _className;
|
||||
|
||||
/// A raw [JniClass] representing the java.lang.Class instance for this class
|
||||
JniClass get jniClass => _clazz;
|
||||
|
||||
/// A [JavaObject] representing the java.lang.Class instance for this class
|
||||
JavaObject get asJavaObject => new JavaObject(_clazz);
|
||||
|
||||
dynamic noSuchMethod(Invocation invocation) {
|
||||
if (invocation.isMethod) {
|
||||
List<_HasArguments> overloads;
|
||||
bool isConstructor = (invocation.memberName == _newInstanceSymbol);
|
||||
if (isConstructor) {
|
||||
overloads = _constructors;
|
||||
} else {
|
||||
overloads = _staticMethods[invocation.memberName];
|
||||
if (overloads == null)
|
||||
throw new JavaError('Static method ${invocation.memberName} not found');
|
||||
}
|
||||
|
||||
_HasArguments method = _findMatchingMethod(overloads, invocation.positionalArguments);
|
||||
List args = _convertArgumentsToJava(invocation.positionalArguments, method);
|
||||
|
||||
if (isConstructor) {
|
||||
return new JavaObject(_clazz.newObject(method.methodId, args));
|
||||
}
|
||||
|
||||
_JavaType returnType = (method as _JavaMethod).returnType;
|
||||
if (returnType == _JavaPrimitive.jvoid) {
|
||||
return _clazz.callStaticVoidMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jboolean) {
|
||||
return _clazz.callStaticBooleanMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jbyte) {
|
||||
return _clazz.callStaticByteMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jchar) {
|
||||
return _clazz.callStaticCharMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jshort) {
|
||||
return _clazz.callStaticShortMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jint) {
|
||||
return _clazz.callStaticIntMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jlong) {
|
||||
return _clazz.callStaticLongMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jfloat) {
|
||||
return _clazz.callStaticFloatMethod(method.methodId, args);
|
||||
} else if (returnType == _JavaPrimitive.jdouble) {
|
||||
return _clazz.callStaticDoubleMethod(method.methodId, args);
|
||||
} else {
|
||||
return _javaObjectToDart(
|
||||
_clazz.callStaticObjectMethod(method.methodId, args));
|
||||
}
|
||||
}
|
||||
|
||||
if (invocation.isGetter) {
|
||||
_JavaField field = _staticFields[invocation.memberName];
|
||||
if (field == null)
|
||||
throw new JavaError('Static field ${invocation.memberName} not found');
|
||||
|
||||
if (field.type == _JavaPrimitive.jboolean) {
|
||||
return _clazz.getStaticBooleanField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jbyte) {
|
||||
return _clazz.getStaticByteField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jchar) {
|
||||
return _clazz.getStaticCharField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jshort) {
|
||||
return _clazz.getStaticShortField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jint) {
|
||||
return _clazz.getStaticIntField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jlong) {
|
||||
return _clazz.getStaticLongField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jfloat) {
|
||||
return _clazz.getStaticFloatField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jdouble) {
|
||||
return _clazz.getStaticDoubleField(field.fieldId);
|
||||
} else {
|
||||
return _javaObjectToDart(_clazz.getStaticObjectField(field.fieldId));
|
||||
}
|
||||
}
|
||||
|
||||
if (invocation.isSetter) {
|
||||
_JavaField field = _staticFields[invocation.memberName];
|
||||
if (field == null)
|
||||
throw new JavaError('Static field ${invocation.memberName} not found');
|
||||
|
||||
dynamic value = invocation.positionalArguments[0];
|
||||
|
||||
if (field.type == _JavaPrimitive.jboolean) {
|
||||
_clazz.setStaticBooleanField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jbyte) {
|
||||
_clazz.setStaticByteField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jchar) {
|
||||
_clazz.setStaticCharField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jshort) {
|
||||
_clazz.setStaticShortField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jint) {
|
||||
_clazz.setStaticIntField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jlong) {
|
||||
_clazz.setStaticLongField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jfloat) {
|
||||
_clazz.setStaticFloatField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jdouble) {
|
||||
_clazz.setStaticDoubleField(field.fieldId, value);
|
||||
} else {
|
||||
_clazz.setStaticObjectField(field.fieldId, _dartObjectToJava(value, field.type));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new JavaError('Unable to access ${invocation.memberName}');
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper for a JNI object that provides access to the object's fields
|
||||
/// and methods.
|
||||
class JavaObject {
|
||||
JniObject _object;
|
||||
JavaClass _clazz;
|
||||
|
||||
JavaObject(JniObject object) {
|
||||
_object = object;
|
||||
|
||||
_clazz = Java.wrapClassObject(
|
||||
_object.callObjectMethod(_reflect.objectGetClass, []));
|
||||
}
|
||||
|
||||
dynamic noSuchMethod(Invocation invocation) {
|
||||
if (invocation.isMethod) {
|
||||
List<_JavaMethod> overloads = _clazz._methods[invocation.memberName];
|
||||
if (overloads == null)
|
||||
throw new JavaError('Method ${invocation.memberName} not found');
|
||||
|
||||
_JavaMethod method = _findMatchingMethod(overloads, invocation.positionalArguments);
|
||||
List args = _convertArgumentsToJava(invocation.positionalArguments, method);
|
||||
|
||||
if (method.returnType == _JavaPrimitive.jvoid) {
|
||||
return _object.callVoidMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jboolean) {
|
||||
return _object.callBooleanMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jbyte) {
|
||||
return _object.callByteMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jchar) {
|
||||
return _object.callCharMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jshort) {
|
||||
return _object.callShortMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jint) {
|
||||
return _object.callIntMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jlong) {
|
||||
return _object.callLongMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jfloat) {
|
||||
return _object.callFloatMethod(method.methodId, args);
|
||||
} else if (method.returnType == _JavaPrimitive.jdouble) {
|
||||
return _object.callDoubleMethod(method.methodId, args);
|
||||
} else {
|
||||
return _javaObjectToDart(
|
||||
_object.callObjectMethod(method.methodId, args));
|
||||
}
|
||||
}
|
||||
|
||||
if (invocation.isGetter) {
|
||||
_JavaField field = _clazz._fields[invocation.memberName];
|
||||
if (field == null)
|
||||
throw new JavaError('Field ${invocation.memberName} not found');
|
||||
|
||||
if (field.type == _JavaPrimitive.jboolean) {
|
||||
return _object.getBooleanField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jbyte) {
|
||||
return _object.getByteField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jchar) {
|
||||
return _object.getCharField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jshort) {
|
||||
return _object.getShortField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jint) {
|
||||
return _object.getIntField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jlong) {
|
||||
return _object.getLongField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jfloat) {
|
||||
return _object.getFloatField(field.fieldId);
|
||||
} else if (field.type == _JavaPrimitive.jdouble) {
|
||||
return _object.getDoubleField(field.fieldId);
|
||||
} else {
|
||||
return _javaObjectToDart(_object.getObjectField(field.fieldId));
|
||||
}
|
||||
}
|
||||
|
||||
if (invocation.isSetter) {
|
||||
_JavaField field = _clazz._fields[invocation.memberName];
|
||||
if (field == null)
|
||||
throw new JavaError('Field ${invocation.memberName} not found');
|
||||
|
||||
dynamic value = invocation.positionalArguments[0];
|
||||
|
||||
if (field.type == _JavaPrimitive.jboolean) {
|
||||
_object.setBooleanField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jbyte) {
|
||||
_object.setByteField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jchar) {
|
||||
_object.setCharField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jshort) {
|
||||
_object.setShortField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jint) {
|
||||
_object.setIntField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jlong) {
|
||||
_object.setLongField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jfloat) {
|
||||
_object.setFloatField(field.fieldId, value);
|
||||
} else if (field.type == _JavaPrimitive.jdouble) {
|
||||
_object.setDoubleField(field.fieldId, value);
|
||||
} else {
|
||||
_object.setObjectField(field.fieldId, _dartObjectToJava(value, field.type));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new JavaError('Unable to access ${invocation.memberName}');
|
||||
}
|
||||
|
||||
/// Convert this object to a string using the Java object's `toString` method.
|
||||
String toString() {
|
||||
String result = JniString.unwrap(_object.callObjectMethod(_reflect.objectToString, []));
|
||||
if (!result.isEmpty) {
|
||||
return result;
|
||||
} else {
|
||||
return 'JavaObject(${_clazz.className})';
|
||||
}
|
||||
}
|
||||
|
||||
/// A [JavaClass] representing this object's class.
|
||||
JavaClass get javaClass => _clazz;
|
||||
|
||||
/// The raw [JniObject] wrapped by this object.
|
||||
/// This can be used to perform low-level JNI operations that aren't exposed
|
||||
/// by [JavaObject], such as access to specific overloaded methods.
|
||||
JniObject get jniObject => _object;
|
||||
}
|
||||
@@ -1,631 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/lib/jni/jni_object.h"
|
||||
|
||||
#include "flutter/fml/platform/android/jni_util.h"
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#include "flutter/lib/jni/jni_array.h"
|
||||
#include "flutter/lib/jni/jni_class.h"
|
||||
#include "flutter/lib/jni/jni_string.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniObject);
|
||||
|
||||
JniObject::JniObject(JNIEnv* env, jobject object) : object_(env, object) {}
|
||||
|
||||
JniObject::~JniObject() {}
|
||||
|
||||
ftl::RefPtr<JniObject> JniObject::Create(JNIEnv* env, jobject object) {
|
||||
if (object == nullptr)
|
||||
return nullptr;
|
||||
|
||||
std::string class_name = DartJni::GetObjectClassName(env, object);
|
||||
|
||||
ftl::RefPtr<JniObject> result;
|
||||
|
||||
if (class_name == "java.lang.String") {
|
||||
result = ftl::MakeRefCounted<JniString>(env, static_cast<jstring>(object));
|
||||
} else if (class_name == "java.lang.Class") {
|
||||
result = ftl::MakeRefCounted<JniClass>(env, static_cast<jclass>(object));
|
||||
} else if (::strncmp(class_name.c_str(), "[L", ::strlen("[L")) == 0) {
|
||||
result = ftl::MakeRefCounted<JniObjectArray>(
|
||||
env, static_cast<jobjectArray>(object));
|
||||
} else if (class_name == "[Z") {
|
||||
result = ftl::MakeRefCounted<JniBooleanArray>(
|
||||
env, static_cast<jbooleanArray>(object));
|
||||
} else if (class_name == "[B") {
|
||||
result =
|
||||
ftl::MakeRefCounted<JniByteArray>(env, static_cast<jbyteArray>(object));
|
||||
} else if (class_name == "[C") {
|
||||
result =
|
||||
ftl::MakeRefCounted<JniCharArray>(env, static_cast<jcharArray>(object));
|
||||
} else if (class_name == "[S") {
|
||||
result = ftl::MakeRefCounted<JniShortArray>(
|
||||
env, static_cast<jshortArray>(object));
|
||||
} else if (class_name == "[I") {
|
||||
result =
|
||||
ftl::MakeRefCounted<JniIntArray>(env, static_cast<jintArray>(object));
|
||||
} else if (class_name == "[J") {
|
||||
result =
|
||||
ftl::MakeRefCounted<JniLongArray>(env, static_cast<jlongArray>(object));
|
||||
} else if (class_name == "[F") {
|
||||
result = ftl::MakeRefCounted<JniFloatArray>(
|
||||
env, static_cast<jfloatArray>(object));
|
||||
} else if (class_name == "[D") {
|
||||
result = ftl::MakeRefCounted<JniDoubleArray>(
|
||||
env, static_cast<jdoubleArray>(object));
|
||||
} else {
|
||||
result = ftl::MakeRefCounted<JniObject>(env, object);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniClass> JniObject::GetObjectClass() {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jclass clazz = env->GetObjectClass(java_object());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniClass>(env, clazz);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniObject::GetObjectField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jobject obj = env->GetObjectField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return JniObject::Create(env, obj);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JniObject::GetBooleanField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jboolean result = env->GetBooleanField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result == JNI_TRUE;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t JniObject::GetByteField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jbyte result = env->GetByteField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::GetCharField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jchar result = env->GetCharField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::GetShortField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jshort result = env->GetShortField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::GetIntField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jint result = env->GetIntField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::GetLongField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jlong result = env->GetLongField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniObject::GetFloatField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloat result = env->GetFloatField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniObject::GetDoubleField(jfieldID fieldId) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jfloat result = env->GetDoubleField(java_object(), fieldId);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void JniObject::SetObjectField(jfieldID fieldId, const JniObject* value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetObjectField(java_object(), fieldId,
|
||||
value ? value->java_object() : nullptr);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetBooleanField(jfieldID fieldId, bool value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetBooleanField(java_object(), fieldId, value ? JNI_TRUE : JNI_FALSE);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetByteField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetByteField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetCharField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetCharField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetShortField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetShortField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetIntField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetIntField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetLongField(jfieldID fieldId, int64_t value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetLongField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetFloatField(jfieldID fieldId, double value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetFloatField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
void JniObject::SetDoubleField(jfieldID fieldId, double value) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
env->SetDoubleField(java_object(), fieldId, value);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniObject> JniObject::CallObjectMethod(
|
||||
jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jobject obj =
|
||||
env->CallObjectMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return JniObject::Create(env, obj);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool JniObject::CallBooleanMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jboolean result =
|
||||
env->CallBooleanMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result == JNI_TRUE;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t JniObject::CallByteMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jbyte result =
|
||||
env->CallByteMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::CallCharMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jchar result =
|
||||
env->CallCharMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::CallShortMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jshort result =
|
||||
env->CallShortMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::CallIntMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jint result =
|
||||
env->CallIntMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t JniObject::CallLongMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jlong result =
|
||||
env->CallLongMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniObject::CallFloatMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jfloat result =
|
||||
env->CallFloatMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
double JniObject::CallDoubleMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
jdouble result =
|
||||
env->CallDoubleMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void JniObject::CallVoidMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
JniMethodArgs java_args;
|
||||
java_args.Convert(env, args, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
env->CallVoidMethodA(java_object(), methodId, java_args.jvalues());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,80 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_JNI_JNI_OBJECT_H_
|
||||
#define FLUTTER_LIB_JNI_JNI_OBJECT_H_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "flutter/fml/platform/android/scoped_java_ref.h"
|
||||
#include "lib/tonic/dart_wrappable.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class JniClass;
|
||||
|
||||
// Wrapper that exposes a JNI jobject to Dart
|
||||
class JniObject : public ftl::RefCountedThreadSafe<JniObject>,
|
||||
public tonic::DartWrappable {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
FRIEND_MAKE_REF_COUNTED(JniObject);
|
||||
|
||||
public:
|
||||
~JniObject() override;
|
||||
|
||||
static ftl::RefPtr<JniObject> Create(JNIEnv* env, jobject object);
|
||||
|
||||
jobject java_object() const { return object_.obj(); }
|
||||
|
||||
ftl::RefPtr<JniClass> GetObjectClass();
|
||||
|
||||
ftl::RefPtr<JniObject> GetObjectField(jfieldID fieldId);
|
||||
bool GetBooleanField(jfieldID fieldId);
|
||||
int64_t GetByteField(jfieldID fieldId);
|
||||
int64_t GetCharField(jfieldID fieldId);
|
||||
int64_t GetShortField(jfieldID fieldId);
|
||||
int64_t GetIntField(jfieldID fieldId);
|
||||
int64_t GetLongField(jfieldID fieldId);
|
||||
double GetFloatField(jfieldID fieldId);
|
||||
double GetDoubleField(jfieldID fieldId);
|
||||
|
||||
void SetObjectField(jfieldID fieldId, const JniObject* value);
|
||||
void SetBooleanField(jfieldID fieldId, bool value);
|
||||
void SetByteField(jfieldID fieldId, int64_t value);
|
||||
void SetCharField(jfieldID fieldId, int64_t value);
|
||||
void SetShortField(jfieldID fieldId, int64_t value);
|
||||
void SetIntField(jfieldID fieldId, int64_t value);
|
||||
void SetLongField(jfieldID fieldId, int64_t value);
|
||||
void SetFloatField(jfieldID fieldId, double value);
|
||||
void SetDoubleField(jfieldID fieldId, double value);
|
||||
|
||||
ftl::RefPtr<JniObject> CallObjectMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
bool CallBooleanMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallByteMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallCharMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallShortMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallIntMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
int64_t CallLongMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
double CallFloatMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
double CallDoubleMethod(jmethodID methodId,
|
||||
const std::vector<Dart_Handle>& args);
|
||||
void CallVoidMethod(jmethodID methodId, const std::vector<Dart_Handle>& args);
|
||||
|
||||
protected:
|
||||
JniObject(JNIEnv* env, jobject object);
|
||||
|
||||
fml::jni::ScopedJavaGlobalRef<jobject> object_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_JNI_JNI_OBJECT_H_
|
||||
@@ -1,326 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of dart_jni;
|
||||
|
||||
/// A group of methods which invoke Java Native Interface APIs from Dart.
|
||||
class JniApi {
|
||||
/// Return the field ID matching a `java.lang.reflect.Field` object.
|
||||
static int fromReflectedField(JniObject field)
|
||||
native 'JniApi_FromReflectedField';
|
||||
|
||||
/// Return the method ID matching a `java.lang.reflect.Method` object.
|
||||
static int fromReflectedMethod(JniObject method)
|
||||
native 'JniApi_FromReflectedMethod';
|
||||
|
||||
/// The `ApplicationContext` of this Android application.
|
||||
static JniObject getApplicationContext()
|
||||
native 'JniApi_GetApplicationContext';
|
||||
|
||||
/// The application's class loader.
|
||||
static JniObject getClassLoader()
|
||||
native 'JniApi_GetClassLoader';
|
||||
}
|
||||
|
||||
/// Low-level wrapper for a Java object accessed via JNI.
|
||||
/// These methods map directly to the corresponding JNI functions. See the JNI
|
||||
/// documentation for more information.
|
||||
class JniObject extends NativeFieldWrapperClass2 {
|
||||
JniClass getObjectClass()
|
||||
native 'JniObject_GetObjectClass';
|
||||
|
||||
JniObject getObjectField(int fieldId)
|
||||
native 'JniObject_GetObjectField';
|
||||
bool getBooleanField(int fieldId)
|
||||
native 'JniObject_GetBooleanField';
|
||||
int getByteField(int fieldId)
|
||||
native 'JniObject_GetByteField';
|
||||
int getCharField(int fieldId)
|
||||
native 'JniObject_GetCharField';
|
||||
int getShortField(int fieldId)
|
||||
native 'JniObject_GetShortField';
|
||||
int getIntField(int fieldId)
|
||||
native 'JniObject_GetIntField';
|
||||
int getLongField(int fieldId)
|
||||
native 'JniObject_GetLongField';
|
||||
double getFloatField(int fieldId)
|
||||
native 'JniObject_GetFloatField';
|
||||
double getDoubleField(int fieldId)
|
||||
native 'JniObject_GetDoubleField';
|
||||
|
||||
void setObjectField(int fieldId, JniObject value)
|
||||
native 'JniObject_SetObjectField';
|
||||
void setBooleanField(int fieldId, bool value)
|
||||
native 'JniObject_SetBooleanField';
|
||||
void setByteField(int fieldId, int value)
|
||||
native 'JniObject_SetByteField';
|
||||
void setCharField(int fieldId, int value)
|
||||
native 'JniObject_SetCharField';
|
||||
void setShortField(int fieldId, int value)
|
||||
native 'JniObject_SetShortField';
|
||||
void setIntField(int fieldId, int value)
|
||||
native 'JniObject_SetIntField';
|
||||
void setLongField(int fieldId, int value)
|
||||
native 'JniObject_SetLongField';
|
||||
void setFloatField(int fieldId, double value)
|
||||
native 'JniObject_SetFloatField';
|
||||
void setDoubleField(int fieldId, double value)
|
||||
native 'JniObject_SetDoubleField';
|
||||
|
||||
JniObject callObjectMethod(int methodId, List args)
|
||||
native 'JniObject_CallObjectMethod';
|
||||
bool callBooleanMethod(int methodId, List args)
|
||||
native 'JniObject_CallBooleanMethod';
|
||||
int callByteMethod(int methodId, List args)
|
||||
native 'JniObject_CallByteMethod';
|
||||
int callCharMethod(int methodId, List args)
|
||||
native 'JniObject_CallCharMethod';
|
||||
int callShortMethod(int methodId, List args)
|
||||
native 'JniObject_CallShortMethod';
|
||||
int callIntMethod(int methodId, List args)
|
||||
native 'JniObject_CallIntMethod';
|
||||
int callLongMethod(int methodId, List args)
|
||||
native 'JniObject_CallLongMethod';
|
||||
double callFloatMethod(int methodId, List args)
|
||||
native 'JniObject_CallFloatMethod';
|
||||
double callDoubleMethod(int methodId, List args)
|
||||
native 'JniObject_CallDoubleMethod';
|
||||
void callVoidMethod(int methodId, List args)
|
||||
native 'JniObject_CallVoidMethod';
|
||||
}
|
||||
|
||||
/// Low-level wrapper for a Java class accessed via JNI.
|
||||
/// These methods map directly to the corresponding JNI functions. See the JNI
|
||||
/// documentation for more information.
|
||||
class JniClass extends JniObject {
|
||||
/// Loads the Java class with the given fully qualified name.
|
||||
static JniClass fromName(String name)
|
||||
native 'JniClass_FromName';
|
||||
|
||||
/// Returns a wrapper for a `java.lang.Class` object.
|
||||
static JniClass fromClassObject(JniObject classObject)
|
||||
native 'JniClass_FromClassObject';
|
||||
|
||||
/// Returns a field ID for the instance field matching this name and type signature.
|
||||
/// See the JNI reference for explanation of type signatures.
|
||||
int getFieldId(String name, String sig)
|
||||
native 'JniClass_GetFieldId';
|
||||
|
||||
/// Returns a field ID for a static field.
|
||||
int getStaticFieldId(String name, String sig)
|
||||
native 'JniClass_GetStaticFieldId';
|
||||
|
||||
/// Returns a method ID for an instance method.
|
||||
int getMethodId(String name, String sig)
|
||||
native 'JniClass_GetMethodId';
|
||||
|
||||
/// Returns a method ID for a static method.
|
||||
int getStaticMethodId(String name, String sig)
|
||||
native 'JniClass_GetStaticMethodId';
|
||||
|
||||
/// Constructs an instance of the wrapped Java class..
|
||||
/// @param methodId The method ID of the constructor, obtained via getMethodId.
|
||||
/// @param args A list of argument values passed to the constructor. Each value should
|
||||
/// be a Dart number, bool, string, or [JniObject] instance.
|
||||
JniObject newObject(int methodId, List args)
|
||||
native 'JniClass_NewObject';
|
||||
|
||||
/// Returns true if objects of the wrapped Java class can be cast to the
|
||||
/// class described by the argument.
|
||||
bool isAssignable(JniClass clazz)
|
||||
native 'JniClass_IsAssignable';
|
||||
|
||||
JniObject getStaticObjectField(int fieldId)
|
||||
native 'JniClass_GetStaticObjectField';
|
||||
bool getStaticBooleanField(int fieldId)
|
||||
native 'JniClass_GetStaticBooleanField';
|
||||
int getStaticByteField(int fieldId)
|
||||
native 'JniClass_GetStaticByteField';
|
||||
int getStaticCharField(int fieldId)
|
||||
native 'JniClass_GetStaticCharField';
|
||||
int getStaticShortField(int fieldId)
|
||||
native 'JniClass_GetStaticShortField';
|
||||
int getStaticIntField(int fieldId)
|
||||
native 'JniClass_GetStaticIntField';
|
||||
int getStaticLongField(int fieldId)
|
||||
native 'JniClass_GetStaticLongField';
|
||||
double getStaticFloatField(int fieldId)
|
||||
native 'JniClass_GetStaticFloatField';
|
||||
double getStaticDoubleField(int fieldId)
|
||||
native 'JniClass_GetStaticDoubleField';
|
||||
|
||||
void setStaticObjectField(int fieldId, JniObject value)
|
||||
native 'JniClass_SetStaticObjectField';
|
||||
void setStaticBooleanField(int fieldId, bool value)
|
||||
native 'JniClass_SetStaticBooleanField';
|
||||
void setStaticByteField(int fieldId, int value)
|
||||
native 'JniClass_SetStaticByteField';
|
||||
void setStaticCharField(int fieldId, int value)
|
||||
native 'JniClass_SetStaticCharField';
|
||||
void setStaticShortField(int fieldId, int value)
|
||||
native 'JniClass_SetStaticShortField';
|
||||
void setStaticIntField(int fieldId, int value)
|
||||
native 'JniClass_SetStaticIntField';
|
||||
void setStaticLongField(int fieldId, int value)
|
||||
native 'JniClass_SetStaticLongField';
|
||||
void setStaticFloatField(int fieldId, double value)
|
||||
native 'JniClass_SetStaticFloatField';
|
||||
void setStaticDoubleField(int fieldId, double value)
|
||||
native 'JniClass_SetStaticDoubleField';
|
||||
|
||||
JniObject callStaticObjectMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticObjectMethod';
|
||||
bool callStaticBooleanMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticBooleanMethod';
|
||||
int callStaticByteMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticByteMethod';
|
||||
int callStaticCharMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticCharMethod';
|
||||
int callStaticShortMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticShortMethod';
|
||||
int callStaticIntMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticIntMethod';
|
||||
int callStaticLongMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticLongMethod';
|
||||
double callStaticFloatMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticFloatMethod';
|
||||
double callStaticDoubleMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticDoubleMethod';
|
||||
void callStaticVoidMethod(int methodId, List args)
|
||||
native 'JniClass_CallStaticVoidMethod';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java string.
|
||||
class JniString extends JniObject {
|
||||
/// Construct a Java string from a Dart string.
|
||||
static JniString create(String value)
|
||||
native 'JniString_Create';
|
||||
|
||||
/// Retrieve the value of the Java string represented by this object as a Dart string.
|
||||
String get text native 'JniString_GetText';
|
||||
|
||||
/// Convert a JniObject representing a Java string to a Dart string.
|
||||
static String unwrap(JniObject object) => (object as JniString).text;
|
||||
}
|
||||
|
||||
/// Wrapper for a Java array.
|
||||
class JniArray extends JniObject {
|
||||
int get length native 'JniArray_GetLength';
|
||||
|
||||
void set length(int value) { throw new UnsupportedError("Not supported."); }
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `Object` array.
|
||||
class JniObjectArray extends JniArray with ListMixin<JniObject> {
|
||||
static JniObjectArray create(JniClass clazz, int length)
|
||||
native 'JniObjectArray_Create';
|
||||
|
||||
JniObject operator [](int index)
|
||||
native 'JniObjectArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, JniObject value)
|
||||
native 'JniObjectArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `boolean` array.
|
||||
class JniBooleanArray extends JniArray with ListMixin<bool> {
|
||||
static JniBooleanArray create(int length)
|
||||
native 'JniBooleanArray_Create';
|
||||
|
||||
bool operator [](int index)
|
||||
native 'JniBooleanArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, bool value)
|
||||
native 'JniBooleanArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `byte` array.
|
||||
class JniByteArray extends JniArray with ListMixin<int> {
|
||||
static JniByteArray create(int length)
|
||||
native 'JniByteArray_Create';
|
||||
|
||||
int operator [](int index)
|
||||
native 'JniByteArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, int value)
|
||||
native 'JniByteArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `char` array.
|
||||
class JniCharArray extends JniArray with ListMixin<int> {
|
||||
static JniCharArray create(int length)
|
||||
native 'JniCharArray_Create';
|
||||
|
||||
int operator [](int index)
|
||||
native 'JniCharArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, int value)
|
||||
native 'JniCharArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `short` array.
|
||||
class JniShortArray extends JniArray with ListMixin<int> {
|
||||
static JniShortArray create(int length)
|
||||
native 'JniShortArray_Create';
|
||||
|
||||
int operator [](int index)
|
||||
native 'JniShortArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, int value)
|
||||
native 'JniShortArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `int` array.
|
||||
class JniIntArray extends JniArray with ListMixin<int> {
|
||||
static JniIntArray create(int length)
|
||||
native 'JniIntArray_Create';
|
||||
|
||||
int operator [](int index)
|
||||
native 'JniIntArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, int value)
|
||||
native 'JniIntArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `long` array.
|
||||
class JniLongArray extends JniArray with ListMixin<int> {
|
||||
static JniLongArray create(int length)
|
||||
native 'JniLongArray_Create';
|
||||
|
||||
int operator [](int index)
|
||||
native 'JniLongArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, int value)
|
||||
native 'JniLongArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `float` array.
|
||||
class JniFloatArray extends JniArray with ListMixin<double> {
|
||||
static JniFloatArray create(int length)
|
||||
native 'JniFloatArray_Create';
|
||||
|
||||
double operator [](int index)
|
||||
native 'JniFloatArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, double value)
|
||||
native 'JniFloatArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Wrapper for a Java `double` array.
|
||||
class JniDoubleArray extends JniArray with ListMixin<double> {
|
||||
static JniDoubleArray create(int length)
|
||||
native 'JniDoubleArray_Create';
|
||||
|
||||
double operator [](int index)
|
||||
native 'JniDoubleArray_GetArrayElement';
|
||||
|
||||
void operator []=(int index, double value)
|
||||
native 'JniDoubleArray_SetArrayElement';
|
||||
}
|
||||
|
||||
/// Used to pass arguments of type "float" to Java methods.
|
||||
class JniFloat {
|
||||
final double value;
|
||||
JniFloat(this.value);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/lib/jni/jni_string.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(jni, JniString);
|
||||
|
||||
JniString::JniString(JNIEnv* env, jstring object) : JniObject(env, object) {}
|
||||
|
||||
JniString::~JniString() {}
|
||||
|
||||
jstring JniString::java_string() {
|
||||
return static_cast<jstring>(java_object());
|
||||
}
|
||||
|
||||
ftl::RefPtr<JniString> JniString::Create(Dart_Handle dart_string) {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jstring java_string =
|
||||
DartJni::DartToJavaString(env, dart_string, &exception);
|
||||
if (exception)
|
||||
goto fail;
|
||||
|
||||
return ftl::MakeRefCounted<JniString>(env, java_string);
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Dart_Handle JniString::GetText() {
|
||||
Dart_Handle exception = nullptr;
|
||||
{
|
||||
ENTER_JNI();
|
||||
|
||||
jsize length = env->GetStringLength(java_string());
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
const jchar* chars = env->GetStringChars(java_string(), NULL);
|
||||
if (CheckJniException(env, &exception))
|
||||
goto fail;
|
||||
|
||||
Dart_Handle result = Dart_NewStringFromUTF16(chars, length);
|
||||
env->ReleaseStringChars(java_string(), chars);
|
||||
|
||||
return result;
|
||||
}
|
||||
fail:
|
||||
Dart_ThrowException(exception);
|
||||
FTL_NOTREACHED();
|
||||
return Dart_Null();
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_LIB_JNI_JNI_STRING_H_
|
||||
#define FLUTTER_LIB_JNI_JNI_STRING_H_
|
||||
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#include "flutter/lib/jni/jni_object.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// Wrapper for a JNI string
|
||||
class JniString : public JniObject {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
friend class JniObject;
|
||||
FRIEND_MAKE_REF_COUNTED(JniString);
|
||||
|
||||
public:
|
||||
~JniString() override;
|
||||
|
||||
static ftl::RefPtr<JniString> Create(Dart_Handle dart_string);
|
||||
Dart_Handle GetText();
|
||||
|
||||
private:
|
||||
JniString(JNIEnv* env, jstring string);
|
||||
|
||||
jstring java_string();
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_LIB_JNI_JNI_STRING_H_
|
||||
@@ -2,7 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//flutter/lib/jni/dart_jni.gni")
|
||||
import("//flutter/lib/snapshot/toolchain.gni")
|
||||
import("//flutter/lib/ui/dart_ui.gni")
|
||||
|
||||
@@ -23,14 +22,6 @@ copy("generate_dart_ui") {
|
||||
]
|
||||
}
|
||||
|
||||
copy("generate_dart_jni") {
|
||||
sources = dart_jni_files
|
||||
|
||||
outputs = [
|
||||
"$bindings_output_dir/dart_jni/{{source_file_part}}",
|
||||
]
|
||||
}
|
||||
|
||||
action("generate_snapshot_bin") {
|
||||
if (target_is_fuchsia) {
|
||||
snapshot_dart = "snapshot_fuchsia.dart"
|
||||
@@ -39,14 +30,13 @@ action("generate_snapshot_bin") {
|
||||
}
|
||||
|
||||
deps = [
|
||||
":generate_dart_jni",
|
||||
":generate_dart_ui",
|
||||
"//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
|
||||
]
|
||||
inputs = [
|
||||
"//dart/runtime/tools/create_snapshot_bin.py",
|
||||
snapshot_dart,
|
||||
] + dart_ui_files + dart_jni_files
|
||||
] + dart_ui_files
|
||||
|
||||
vm_isolate_snapshot = "$target_gen_dir/vm_isolate_snapshot.bin"
|
||||
isolate_snapshot = "$target_gen_dir/isolate_snapshot.bin"
|
||||
@@ -56,7 +46,6 @@ action("generate_snapshot_bin") {
|
||||
]
|
||||
|
||||
rebased_dart_ui_path = rebase_path(dart_ui_path)
|
||||
rebased_dart_jni_path = rebase_path(dart_jni_path)
|
||||
|
||||
gen_snapshot_dir =
|
||||
get_label_info("//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
|
||||
@@ -79,7 +68,6 @@ action("generate_snapshot_bin") {
|
||||
"--target_os",
|
||||
target_os,
|
||||
"--url_mapping=dart:ui,$rebased_dart_ui_path",
|
||||
"--url_mapping=dart:jni,$rebased_dart_jni_path",
|
||||
]
|
||||
|
||||
if (target_is_fuchsia) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'dart:core';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'dart:jni';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
@@ -84,11 +84,4 @@ source_set("ui") {
|
||||
"//third_party/skia",
|
||||
"//third_party/skia:gpu",
|
||||
]
|
||||
|
||||
if (is_android) {
|
||||
deps += [
|
||||
# TODO(abarth): In principle, these libraries should be fully independent.
|
||||
"//flutter/lib/jni",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@
|
||||
#include "flutter/sky/engine/platform/fonts/FontSelector.h"
|
||||
#include "lib/tonic/converter/dart_converter.h"
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#endif
|
||||
|
||||
using tonic::ToDart;
|
||||
|
||||
namespace blink {
|
||||
@@ -22,11 +18,7 @@ UIDartState::UIDartState(IsolateClient* isolate_client,
|
||||
std::unique_ptr<Window> window)
|
||||
: isolate_client_(isolate_client),
|
||||
main_port_(ILLEGAL_PORT),
|
||||
window_(std::move(window)) {
|
||||
#ifdef OS_ANDROID
|
||||
jni_data_.reset(new DartJniIsolateData());
|
||||
#endif
|
||||
}
|
||||
window_(std::move(window)) {}
|
||||
|
||||
UIDartState::~UIDartState() {
|
||||
main_port_ = ILLEGAL_PORT;
|
||||
@@ -54,12 +46,6 @@ UIDartState* UIDartState::Current() {
|
||||
return static_cast<UIDartState*>(DartState::Current());
|
||||
}
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
DartJniIsolateData* UIDartState::jni_data() {
|
||||
return jni_data_.get();
|
||||
}
|
||||
#endif // defined(OS_ANDROID)
|
||||
|
||||
void UIDartState::set_font_selector(PassRefPtr<FontSelector> selector) {
|
||||
font_selector_ = selector;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "lib/tonic/dart_state.h"
|
||||
|
||||
namespace blink {
|
||||
struct DartJniIsolateData;
|
||||
class FontSelector;
|
||||
class Window;
|
||||
|
||||
@@ -40,10 +39,6 @@ class UIDartState : public tonic::DartState {
|
||||
const std::string& debug_name() const { return debug_name_; }
|
||||
Window* window() const { return window_.get(); }
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
DartJniIsolateData* jni_data();
|
||||
#endif
|
||||
|
||||
void set_font_selector(PassRefPtr<FontSelector> selector);
|
||||
PassRefPtr<FontSelector> font_selector();
|
||||
|
||||
@@ -55,10 +50,6 @@ class UIDartState : public tonic::DartState {
|
||||
std::string debug_name_;
|
||||
std::unique_ptr<Window> window_;
|
||||
RefPtr<FontSelector> font_selector_;
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
std::unique_ptr<DartJniIsolateData> jni_data_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -102,10 +102,6 @@ source_set("runtime") {
|
||||
deps += [ "//lib/tonic/debugger" ]
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
deps += [ "//flutter/lib/jni" ]
|
||||
}
|
||||
|
||||
# On iOS (device), precompiled snapshots contain the instruction buffer.
|
||||
# Generation of the same requires all application specific script code to be
|
||||
# specified up front. In such cases, there can be no generic snapshot.
|
||||
|
||||
@@ -29,10 +29,6 @@
|
||||
#include "lib/tonic/scopes/dart_api_scope.h"
|
||||
#include "lib/tonic/scopes/dart_isolate_scope.h"
|
||||
|
||||
#ifdef OS_ANDROID
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#endif
|
||||
|
||||
using tonic::LogIfError;
|
||||
using tonic::ToDart;
|
||||
|
||||
@@ -183,14 +179,6 @@ void DartController::CreateIsolateFor(const std::string& script_uri,
|
||||
new tonic::DartClassProvider(dart_state(), "dart:ui"));
|
||||
dart_state()->class_library().add_provider("ui",
|
||||
std::move(ui_class_provider));
|
||||
|
||||
#ifdef OS_ANDROID
|
||||
DartJni::InitForIsolate();
|
||||
std::unique_ptr<tonic::DartClassProvider> jni_class_provider(
|
||||
new tonic::DartClassProvider(dart_state(), "dart:jni"));
|
||||
dart_state()->class_library().add_provider("jni",
|
||||
std::move(jni_class_provider));
|
||||
#endif
|
||||
}
|
||||
Dart_ExitIsolate();
|
||||
}
|
||||
|
||||
@@ -48,10 +48,6 @@
|
||||
#include "lib/tonic/scopes/dart_isolate_scope.h"
|
||||
#include "lib/tonic/typed_data/uint8_list.h"
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#endif
|
||||
|
||||
using tonic::DartClassProvider;
|
||||
using tonic::LogIfError;
|
||||
using tonic::ToDart;
|
||||
@@ -165,11 +161,7 @@ bool DartFileModifiedCallback(const char* source_url, int64_t since_ms) {
|
||||
return mtime > since;
|
||||
}
|
||||
|
||||
void ThreadExitCallback() {
|
||||
#if defined(OS_ANDROID)
|
||||
DartJni::OnThreadExit();
|
||||
#endif
|
||||
}
|
||||
void ThreadExitCallback() {}
|
||||
|
||||
bool IsServiceIsolateURL(const char* url_name) {
|
||||
return url_name != nullptr &&
|
||||
@@ -303,14 +295,6 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
|
||||
dart_state->class_library().add_provider("ui",
|
||||
std::move(ui_class_provider));
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
DartJni::InitForIsolate();
|
||||
std::unique_ptr<DartClassProvider> jni_class_provider(
|
||||
new DartClassProvider(dart_state, "dart:jni"));
|
||||
dart_state->class_library().add_provider("jni",
|
||||
std::move(jni_class_provider));
|
||||
#endif
|
||||
|
||||
if (!kernel_data.empty()) {
|
||||
// We are running kernel code.
|
||||
FTL_CHECK(!LogIfError(Dart_LoadKernel(Dart_ReadKernelBinary(kernel_data.data(),
|
||||
@@ -374,14 +358,6 @@ static void ServiceStreamCancelCallback(const char* stream_id) {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
|
||||
DartJniIsolateData* GetDartJniDataForCurrentIsolate() {
|
||||
return UIDartState::Current()->jni_data();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
#if DART_ALLOW_DYNAMIC_RESOLUTION
|
||||
@@ -674,9 +650,6 @@ void InitDartVM() {
|
||||
#endif
|
||||
|
||||
DartUI::InitForGlobal();
|
||||
#if defined(OS_ANDROID)
|
||||
DartJni::InitForGlobal(GetDartJniDataForCurrentIsolate);
|
||||
#endif
|
||||
|
||||
// Setup embedder tracing hooks. To avoid data races, it is recommended that
|
||||
// these hooks be installed before the DartInitialize, so do that setup now.
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
dart:jni,JniObject,JniObject.
|
||||
dart:jni,JniFloat,JniFloat.
|
||||
dart:jni,JniFloat,get:value
|
||||
@@ -38,7 +38,6 @@ shared_library("flutter_shell_native") {
|
||||
"//flutter/common",
|
||||
"//flutter/flow",
|
||||
"//flutter/fml",
|
||||
"//flutter/lib/jni",
|
||||
"//flutter/lib/ui",
|
||||
"//flutter/runtime",
|
||||
"//flutter/shell/common",
|
||||
|
||||
@@ -20,10 +20,6 @@ static void Init(JNIEnv* env,
|
||||
jclass clazz,
|
||||
jobject context,
|
||||
jobjectArray jargs) {
|
||||
fml::jni::ScopedJavaLocalRef<jobject> scoped_context(
|
||||
env, env->NewLocalRef(context));
|
||||
fml::jni::InitAndroidApplicationContext(scoped_context);
|
||||
|
||||
// Prepare command line arguments and initialize the shell.
|
||||
std::vector<std::string> args;
|
||||
args.push_back("flutter_tester");
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/fml/platform/android/jni_util.h"
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#include "flutter/shell/platform/android/flutter_main.h"
|
||||
#include "flutter/shell/platform/android/platform_view_android.h"
|
||||
#include "flutter/shell/platform/android/vsync_waiter_android.h"
|
||||
@@ -28,9 +27,5 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
result = shell::VsyncWaiterAndroid::Register(env);
|
||||
FTL_CHECK(result);
|
||||
|
||||
// Register DartJni
|
||||
result = blink::DartJni::InitJni();
|
||||
FTL_CHECK(result);
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import("//dart/sdk/lib/rules.gni")
|
||||
import("//flutter/build/dart/rules.gni")
|
||||
import("//flutter/lib/jni/dart_jni.gni")
|
||||
import("//flutter/lib/ui/dart_ui.gni")
|
||||
import("//flutter/sky/engine/core/core.gni")
|
||||
|
||||
@@ -78,14 +77,6 @@ copy("copy_dart_ui") {
|
||||
]
|
||||
}
|
||||
|
||||
copy("copy_dart_jni") {
|
||||
sources = dart_jni_files
|
||||
|
||||
outputs = [
|
||||
"$root_gen_dir/dart-pkg/sky_engine/dart_jni/{{source_file_part}}",
|
||||
]
|
||||
}
|
||||
|
||||
group("copy_dart_sdk") {
|
||||
deps = [
|
||||
":async",
|
||||
@@ -111,7 +102,6 @@ dart_pkg("sky_engine") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
":copy_dart_jni",
|
||||
":copy_dart_sdk",
|
||||
":copy_dart_ui",
|
||||
]
|
||||
|
||||
@@ -6,7 +6,6 @@ embedded_libs:
|
||||
"dart:developer": "../dart_sdk/developer/developer.dart"
|
||||
"dart:io": "../dart_sdk/io/io.dart"
|
||||
"dart:isolate": "../dart_sdk/isolate/isolate.dart"
|
||||
"dart:jni": "../dart_jni/jni.dart"
|
||||
"dart:math": "../dart_sdk/math/math.dart"
|
||||
"dart:typed_data": "../dart_sdk/typed_data/typed_data.dart"
|
||||
"dart:ui": "../dart_ui/ui.dart"
|
||||
|
||||
Reference in New Issue
Block a user