diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index c9c6d05810ce04ff4450baed87c2699694181c44..66c3e9ab2198fb1dee0297206e579aeb644a535b 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -233,6 +233,8 @@ shared_library("flutter_shell_native") { ldflags += ["-lpthread"] ldflags += ["-lpixelmap_ndk.z"] + ldflags += ["-lqos_ndk.z"] + public_configs = [ "//flutter:config" ] } diff --git a/shell/platform/ohos/ohos_shell_holder.cpp b/shell/platform/ohos/ohos_shell_holder.cpp index cbc08c05a68fd33c96102c547b6fde23c9796fc7..4e02f49568bf939f4f806c2ef2088a4bd4e58dc5 100644 --- a/shell/platform/ohos/ohos_shell_holder.cpp +++ b/shell/platform/ohos/ohos_shell_holder.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace flutter { @@ -33,34 +34,28 @@ static void OHOSPlatformThreadConfigSetter( // set thread priority switch (config.priority) { case fml::Thread::ThreadPriority::BACKGROUND: { - if (::setpriority(PRIO_PROCESS, 0, 10) != 0) { - FML_DLOG(ERROR) << "Failed to set IO task runner priority"; - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_BACKGROUND); + FML_DLOG(INFO) << "qos set background result:" << ret << ",tid:" << gettid(); break; } case fml::Thread::ThreadPriority::DISPLAY: { - if (::setpriority(PRIO_PROCESS, 0, -1) != 0) { - FML_DLOG(ERROR) << "Failed to set UI task runner priority"; - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + FML_DLOG(INFO) << "qos set display result:" << ret << ",tid:" << gettid(); break; } case fml::Thread::ThreadPriority::RASTER: { - // Android describes -8 as "most important display threads, for - // compositing the screen and retrieving input events". Conservatively - // set the raster thread to slightly lower priority than it. - if (::setpriority(PRIO_PROCESS, 0, -5) != 0) { - // Defensive fallback. Depending on the OEM, it may not be possible - // to set priority to -5. - if (::setpriority(PRIO_PROCESS, 0, -2) != 0) { - FML_DLOG(ERROR) << "Failed to set raster task runner priority"; - } - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + FML_DLOG(INFO) << "qos set raster result:" << ret << ",tid:" << gettid(); + break; + } + case fml::Thread::ThreadPriority::NORMAL: { + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_DEFAULT); + FML_DLOG(INFO) << "qos set io result:" << ret << ",tid:" << gettid(); break; } default: - if (::setpriority(PRIO_PROCESS, 0, 0) != 0) { - FML_DLOG(ERROR) << "Failed to set priority"; - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_DEFAULT); + FML_DLOG(INFO) << "qos set default result:" << ret << ",tid:" << gettid(); } }