From 86ce9cc5c283a8eac283aced3e5f3e1695c47b48 Mon Sep 17 00:00:00 2001 From: rogeryi Date: Fri, 12 Feb 2021 06:46:02 +0800 Subject: [PATCH] Fix Android IO and Worker threads priority issue (flutter/engine#23911) --- .../shell/platform/android/android_shell_holder.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/engine/src/flutter/shell/platform/android/android_shell_holder.cc b/engine/src/flutter/shell/platform/android/android_shell_holder.cc index 9b2a79e03e..6a71c24e23 100644 --- a/engine/src/flutter/shell/platform/android/android_shell_holder.cc +++ b/engine/src/flutter/shell/platform/android/android_shell_holder.cc @@ -122,6 +122,11 @@ AndroidShellHolder::AndroidShellHolder( FML_LOG(ERROR) << "Failed to set UI task runner priority"; } }); + task_runners.GetIOTaskRunner()->PostTask([]() { + if (::setpriority(PRIO_PROCESS, gettid(), 1) != 0) { + FML_LOG(ERROR) << "Failed to set IO task runner priority"; + } + }); shell_ = Shell::Create(GetDefaultPlatformData(), // window data @@ -131,6 +136,14 @@ AndroidShellHolder::AndroidShellHolder( on_create_rasterizer // rasterizer create callback ); + if (shell_) { + shell_->GetDartVM()->GetConcurrentMessageLoop()->PostTaskToAllWorkers([]() { + if (::setpriority(PRIO_PROCESS, gettid(), 1) != 0) { + FML_LOG(ERROR) << "Failed to set Workers task runner priority"; + } + }); + } + platform_view_ = weak_platform_view; FML_DCHECK(platform_view_); is_valid_ = shell_ != nullptr;