From e45e1c17b23995418d6c2be7a16e8c02b5742eb1 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 17 Apr 2018 17:10:17 -0700 Subject: [PATCH] Don't send platform messages to isolates that are not running. (flutter/engine#5031) Isolates may be launched and awaiting snapshot association. We don't want to send such isolates any messages before their "main" method is called. In such cases, the engine may intercept and store certain launch specific information. --- engine/src/flutter/runtime/runtime_controller.cc | 7 +++++++ engine/src/flutter/runtime/runtime_controller.h | 2 ++ engine/src/flutter/shell/common/engine.cc | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index e7a8ab5253..b7566a10a0 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -78,6 +78,13 @@ RuntimeController::~RuntimeController() { } } +bool RuntimeController::IsRootIsolateRunning() const { + if (root_isolate_) { + return root_isolate_->GetPhase() == DartIsolate::Phase::Running; + } + return false; +} + std::unique_ptr RuntimeController::Clone() const { return std::unique_ptr(new RuntimeController( client_, // diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 326c517f31..fb01847a91 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -46,6 +46,8 @@ class RuntimeController final : public WindowClient { bool NotifyIdle(int64_t deadline); + bool IsRootIsolateRunning() const; + bool DispatchPlatformMessage(fxl::RefPtr message); bool DispatchPointerDataPacket(const PointerDataPacket& packet); diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 3d6fd496d3..d1231b0d09 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -259,7 +259,8 @@ void Engine::DispatchPlatformMessage( return; } - if (runtime_controller_->DispatchPlatformMessage(std::move(message))) { + if (runtime_controller_->IsRootIsolateRunning() && + runtime_controller_->DispatchPlatformMessage(std::move(message))) { return; }