5#define FML_USED_ON_EMBEDDER
7#include <android/log.h>
12#include "flutter/fml/command_line.h"
13#include "flutter/fml/file.h"
14#include "flutter/fml/logging.h"
15#include "flutter/fml/macros.h"
16#include "flutter/fml/message_loop.h"
17#include "flutter/fml/native_library.h"
18#include "flutter/fml/paths.h"
19#include "flutter/fml/platform/android/jni_util.h"
20#include "flutter/fml/platform/android/paths_android.h"
21#include "flutter/fml/size.h"
22#include "flutter/lib/ui/plugins/callback_cache.h"
23#include "flutter/runtime/dart_vm.h"
24#include "flutter/shell/common/shell.h"
25#include "flutter/shell/common/switches.h"
26#include "flutter/shell/platform/android/android_context_vulkan_impeller.h"
27#include "flutter/shell/platform/android/flutter_main.h"
30#include "third_party/dart/runtime/include/dart_tools_api.h"
38#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
54FlutterMain::~FlutterMain() =
default;
73 jstring appStoragePath,
74 jstring engineCachesPath,
75 jlong initTimeMillis) {
76 std::vector<std::string>
args;
77 args.push_back(
"flutter");
79 args.push_back(std::move(arg));
92 ANDROID_LOG_INFO,
"Flutter",
93 "ATrace was enabled at startup. Flutter and Dart "
94 "tracing will be forwarded to systrace and will not show up in "
100 switch (
settings.android_rendering_api) {
102 case AndroidRenderingAPI::kSkiaOpenGLES:
105 case AndroidRenderingAPI::kImpellerOpenGLES:
106 case AndroidRenderingAPI::kImpellerVulkan:
131 auto application_kernel_path =
135 settings.application_kernel_asset = application_kernel_path;
147 settings.log_message_callback = [](
const std::string& tag,
149 __android_log_print(ANDROID_LOG_INFO, tag.c_str(),
"%.*s",
153 settings.enable_platform_isolates =
true;
155#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
158 auto make_mapping_callback = [](
const uint8_t* mapping,
size_t size) {
159 return [mapping,
size]() {
160 return std::make_unique<fml::NonOwnedMapping>(mapping,
size);
164 settings.dart_library_sources_kernel =
175void FlutterMain::SetupDartVMServiceUriCallback(JNIEnv*
env) {
177 env,
env->FindClass(
"io/flutter/embedding/engine/FlutterJNI"));
181 jfieldID uri_field =
env->GetStaticFieldID(
183 if (uri_field ==
nullptr) {
187 auto set_uri = [
env, uri_field](
const std::string& uri) {
198 vm_service_uri_callback_ = DartServiceIsolate::AddServerStatusCallback(
199 [platform_runner, set_uri](
const std::string& uri) {
200 platform_runner->
PostTask([uri, set_uri] { set_uri(uri); });
210 static const JNINativeMethod methods[] = {
212 .name =
"nativeInit",
213 .signature =
"(Landroid/content/Context;[Ljava/lang/String;Ljava/"
214 "lang/String;Ljava/lang/String;Ljava/lang/String;J)V",
215 .fnPtr =
reinterpret_cast<void*
>(&
Init),
218 .name =
"nativePrefetchDefaultFontManager",
224 jclass clazz =
env->FindClass(
"io/flutter/embedding/engine/FlutterJNI");
226 if (clazz ==
nullptr) {
230 return env->RegisterNatives(clazz, methods,
fml::size(methods)) == 0;
236 if (
settings.enable_software_rendering) {
238 <<
"Impeller does not support software rendering. Either disable "
239 "software rendering or disable impeller.";
243 AndroidRenderingAPI::kSkiaOpenGLES;
247#ifndef FLUTTER_RELEASE
248 if (
settings.requested_rendering_backend ==
"opengles" &
250 return AndroidRenderingAPI::kImpellerOpenGLES;
252 if (
settings.requested_rendering_backend ==
"vulkan" &&
254 return AndroidRenderingAPI::kImpellerVulkan;
265 int api_level = android_get_device_api_level();
267 return kVulkanUnsupportedFallback;
272 auto vulkan_backend = std::make_unique<AndroidContextVulkanImpeller>(
276 if (!vulkan_backend->IsValid()) {
277 return kVulkanUnsupportedFallback;
279 return AndroidRenderingAPI::kImpellerVulkan;
282 return AndroidRenderingAPI::kSkiaOpenGLES;
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...
void RemoveTaskObserver(intptr_t key)
static void EnsureInitializedForCurrentThread()
void AddTaskObserver(intptr_t key, const fml::closure &callback)
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
virtual void PostTask(const fml::closure &task) override
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
const GrXPFactory * Get(SkBlendMode mode)
constexpr int kMinimumAndroidApiLevelForVulkan
Settings SettingsFromCommandLine(const fml::CommandLine &command_line)
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
it will be possible to load the file into Perfetto s trace viewer 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
const uint8_t kPlatformStrongDill[]
std::string JavaStringToString(JNIEnv *env, jstring str)
std::vector< std::string > StringArrayToVector(JNIEnv *env, jobjectArray array)
ScopedJavaLocalRef< jstring > StringToJavaString(JNIEnv *env, const std::string &u8_string)
void InitializeAndroidCachesPath(std::string caches_path)
constexpr std::size_t size(T(&array)[N])
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 TraceIsEnabled() const
Check if tracing in enabled in the process. This call can be made at any API level.