5#define FML_USED_ON_EMBEDDER
7#include <android/log.h>
8#include <sys/system_properties.h>
37#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
55 char product_model[PROP_VALUE_MAX];
56 __system_property_get(
"ro.hardware.egl", product_model);
57 return strcmp(product_model,
"VIVANTE") == 0;
69 :
settings_(settings), android_rendering_api_(android_rendering_api) {}
71FlutterMain::~FlutterMain() =
default;
86 return android_rendering_api_;
89void FlutterMain::Init(JNIEnv* env,
94 jstring appStoragePath,
95 jstring engineCachesPath,
98 std::vector<std::string>
args;
99 args.push_back(
"flutter");
100 for (
auto& arg :
fml::jni::StringArrayToVector(env, jargs)) {
101 args.push_back(std::move(arg));
105 auto settings = SettingsFromCommandLine(command_line,
true);
109 if (!settings.trace_systrace) {
110 settings.trace_systrace =
112 if (settings.trace_systrace) {
114 ANDROID_LOG_INFO,
"Flutter",
115 "ATrace was enabled at startup. Flutter and Dart "
116 "tracing will be forwarded to systrace and will not show up in "
125 SelectedRenderingAPI(settings, api_level);
127 settings.warn_on_impeller_opt_out =
true;
129 switch (android_rendering_api) {
130 case AndroidRenderingAPI::kSoftware:
131 case AndroidRenderingAPI::kSkiaOpenGLES:
132 settings.enable_impeller =
false;
134 case AndroidRenderingAPI::kImpellerOpenGLES:
135 case AndroidRenderingAPI::kImpellerVulkan:
136 case AndroidRenderingAPI::kImpellerAutoselect:
137 settings.enable_impeller =
true;
145 settings.enable_timeline_event_handler = settings.trace_systrace;
162 auto application_kernel_path =
166 settings.application_kernel_asset = application_kernel_path;
182 settings.log_message_callback = [](
const std::string& tag,
184 __android_log_print(ANDROID_LOG_INFO, tag.c_str(),
"%.*s",
188 settings.enable_platform_isolates =
true;
190#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
193 auto make_mapping_callback = [](
const uint8_t* mapping,
size_t size) {
194 return [mapping,
size]() {
195 return std::make_unique<fml::NonOwnedMapping>(mapping, size);
199 settings.dart_library_sources_kernel =
205 g_flutter_main.reset(
new FlutterMain(settings, android_rendering_api));
209void FlutterMain::SetupDartVMServiceUriCallback(JNIEnv* env) {
211 env, env->FindClass(
"io/flutter/embedding/engine/FlutterJNI"));
212 if (g_flutter_jni_class->is_null()) {
215 jfieldID uri_field = env->GetStaticFieldID(
216 g_flutter_jni_class->obj(),
"vmServiceUri",
"Ljava/lang/String;");
217 if (uri_field ==
nullptr) {
221 auto set_uri = [env, uri_field](
const std::string& uri) {
224 env->SetStaticObjectField(g_flutter_jni_class->obj(), uri_field,
232 vm_service_uri_callback_ = DartServiceIsolate::AddServerStatusCallback(
233 [platform_runner, set_uri](
const std::string& uri) {
234 platform_runner->PostTask([uri, set_uri] { set_uri(uri); });
243bool FlutterMain::Register(JNIEnv* env) {
244 static const JNINativeMethod methods[] = {
246 .name =
"nativeInit",
247 .signature =
"(Landroid/content/Context;[Ljava/lang/String;Ljava/"
248 "lang/String;Ljava/lang/String;Ljava/lang/String;JI)V",
249 .fnPtr =
reinterpret_cast<void*
>(&Init),
252 .name =
"nativePrefetchDefaultFontManager",
258 jclass clazz = env->FindClass(
"io/flutter/embedding/engine/FlutterJNI");
260 if (clazz ==
nullptr) {
264 return env->RegisterNatives(clazz, methods, std::size(methods)) == 0;
275 <<
"Impeller does not support software rendering. Either disable "
276 "software rendering or disable impeller.";
278 return AndroidRenderingAPI::kSoftware;
283#ifndef FLUTTER_RELEASE
286 return AndroidRenderingAPI::kImpellerOpenGLES;
290 return AndroidRenderingAPI::kImpellerVulkan;
296 return AndroidRenderingAPI::kImpellerAutoselect;
299 return AndroidRenderingAPI::kSkiaOpenGLES;
301 return AndroidRenderingAPI::kImpellerAutoselect;
static void LoadCacheFromDisk()
static void SetCachePath(const std::string &path)
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
static void EnsureInitializedForCurrentThread()
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
static TaskQueueId GetCurrentTaskQueueId()
static MessageLoopTaskQueues * GetInstance()
void AddTaskObserver(TaskQueueId queue_id, intptr_t key, const fml::closure &callback)
void RemoveTaskObserver(TaskQueueId queue_id, intptr_t key)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
const intptr_t kPlatformStrongDillSize
FLUTTER_ASSERT_ARC const uint8_t kPlatformStrongDill[]
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static void PrefetchDefaultFontManager(JNIEnv *env, jclass jcaller)
const intptr_t kPlatformStrongDillSize
static fml::jni::ScopedJavaGlobalRef< jclass > * g_flutter_jni_class
static std::unique_ptr< FlutterMain > g_flutter_main
constexpr int kMinimumAndroidApiLevelForImpeller
const uint8_t kPlatformStrongDill[]
std::string JavaStringToString(JNIEnv *env, jstring str)
ScopedJavaLocalRef< jstring > StringToJavaString(JNIEnv *env, const std::string &u8_string)
void InitializeAndroidCachesPath(std::string caches_path)
bool IsFile(const std::string &path)
std::function< void()> closure
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)
const ProcTable & GetProcTable()
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
bool enable_software_rendering
std::optional< std::string > requested_rendering_backend
bool TraceIsEnabled() const
Check if tracing in enabled in the process. This call can be made at any API level.