diff --git a/bundle.json b/bundle.json index fafa4f9063915315c6d205a26904427dbdca1374..36fb3070f3cd27db93585c7ba6254914825dbf54 100644 --- a/bundle.json +++ b/bundle.json @@ -24,7 +24,6 @@ "components": [ "c_utils", "eventhandler", - "ffrt", "hitrace", "hilog", "samgr", diff --git a/interfaces/innerkits/frameintf/BUILD.gn b/interfaces/innerkits/frameintf/BUILD.gn index ae9215b290a1b4c28793210ecfb505ba4fd9ad2b..c959bcd3b9419f774454c86df551b778d6938c44 100644 --- a/interfaces/innerkits/frameintf/BUILD.gn +++ b/interfaces/innerkits/frameintf/BUILD.gn @@ -131,7 +131,6 @@ ohos_shared_library("frame_msg_intf") { external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", - "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", ] diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.cpp b/interfaces/innerkits/frameintf/frame_msg_intf.cpp index ef1d731c2d63d486eb09d15e3b8910e34517a707..624a047bf4dc170d9b33ebb2af1f3d9249af3772 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.cpp +++ b/interfaces/innerkits/frameintf/frame_msg_intf.cpp @@ -14,8 +14,8 @@ */ #include "frame_msg_intf.h" -#include "ffrt_inner.h" #include "intellisense_server.h" +#include "event_handler.h" #include "rme_log_domain.h" namespace OHOS { @@ -28,34 +28,30 @@ FrameMsgIntf& FrameMsgIntf::GetInstance() return instance; } -FrameMsgIntf::~FrameMsgIntf() -{ - if (taskQueue_ != nullptr) { - delete taskQueue_; - taskQueue_ = nullptr; - } -} - bool FrameMsgIntf::Init() { - std::lock_guard autoLock(frameMsgIntfMutex_); + std::lock_guard autoLock(frameMsgIntfMutex_); RME_LOGI("init begin!"); - if (!GetThreadQueue()) { + if (!GetThreadHandler()) { return false; } - taskQueue_->submit([] { + threadHandler_->PostTask([] { IntelliSenseServer::GetInstance().Init(); }); return true; } -bool FrameMsgIntf::GetThreadQueue() +bool FrameMsgIntf::GetThreadHandler() { - if (taskQueue_ == nullptr) { - taskQueue_ = new(ffrt::queue)("frame_aware_sched_msg_queue", - ffrt::queue_attr().qos(ffrt::qos_user_interactive)); - if (taskQueue_ == nullptr) { - RME_LOGE("failed to create taskQueue!"); + if (threadHandler_ == nullptr) { + runner_ = AppExecFwk::EventRunner::Create("frame_aware_sched_msg"); + if (runner_ == nullptr) { + RME_LOGE("failed to create eventRunner!"); + return false; + } + threadHandler_ = std::make_shared(runner_); + if (threadHandler_ == nullptr) { + RME_LOGE("failed to create thread handler!"); return false; } } @@ -65,76 +61,76 @@ bool FrameMsgIntf::GetThreadQueue() void FrameMsgIntf::ReportWindowFocus(const int pid, const int uid, const int isFocus) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (taskQueue_ == nullptr) { - RME_LOGE("[ReportWindowFocus]:taskQueue none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (threadHandler_ == nullptr) { + RME_LOGE("[ReportWindowFocus]:threadHandler_ none!"); return; } - taskQueue_->submit([pid, uid, isFocus] { + threadHandler_->PostTask([pid, uid, isFocus] { IntelliSenseServer::GetInstance().ReportWindowFocus(pid, uid, isFocus); }); } void FrameMsgIntf::ReportRenderThread(const int pid, const int uid, const int renderTid) { - std::lock_guard autoLock(frameMsgIntfMutex_); + std::lock_guard autoLock(frameMsgIntfMutex_); RME_LOGI("[ReportRenderThread]:render get %{public}d with render %{pubilc}d", pid, renderTid); - if (taskQueue_ == nullptr) { - RME_LOGE("[ReportRenderThread]:taskQueue none!"); + if (threadHandler_ == nullptr) { + RME_LOGE("[ReportRenderThread]:threadHandler_ none!"); return; } - taskQueue_->submit([pid, uid, renderTid] { + threadHandler_->PostTask([pid, uid, renderTid] { IntelliSenseServer::GetInstance().ReportRenderThread(pid, uid, renderTid); }); } void FrameMsgIntf::ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (taskQueue_ == nullptr) { - RME_LOGI("[ReportAppInfo]:taskQueue none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (threadHandler_ == nullptr) { + RME_LOGI("[ReportAppInfo]:threadHandler_ none!"); return; } RME_LOGI("ReportProcessInfo pid is %{public}d, uid is %{public}d", pid, uid); - taskQueue_->submit([pid, uid, bundleName, state] { + threadHandler_->PostTask([pid, uid, bundleName, state] { IntelliSenseServer::GetInstance().ReportAppInfo(pid, uid, bundleName, state); }); } void FrameMsgIntf::ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (taskQueue_ == nullptr) { - RME_LOGI("[ReportProcessInfo]:taskQueue none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (threadHandler_ == nullptr) { + RME_LOGI("[ReportProcessInfo]:threadHandler_ none!"); return; } - taskQueue_->submit([pid, uid, bundleName, state] { + threadHandler_->PostTask([pid, uid, bundleName, state] { IntelliSenseServer::GetInstance().ReportProcessInfo(pid, uid, bundleName, state); }); } void FrameMsgIntf::ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (taskQueue_ == nullptr) { - RME_LOGI("[ReportProcessInfo]:taskQueue none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (threadHandler_ == nullptr) { + RME_LOGI("[ReportProcessInfo]:threadHandler_ none!"); return; } RME_LOGI("CgroupChanged pid is %{public}d, uid is %{public}d, oldGroup is %{public}d, newGroup is %{public}d", pid, uid, oldGroup, newGroup); - taskQueue_->submit([pid, uid, oldGroup, newGroup] { + threadHandler_->PostTask([pid, uid, oldGroup, newGroup] { IntelliSenseServer::GetInstance().ReportCgroupChange(pid, uid, oldGroup, newGroup); }); } void FrameMsgIntf::ReportContinuousTask(const int pid, const int uid, const int status) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (taskQueue_ == nullptr) { + std::lock_guard autoLock(frameMsgIntfMutex_); + if (threadHandler_ == nullptr) { RME_LOGI("[ReportProcessInfo]:taskQueue none!"); return; } - taskQueue_->submit([pid, uid, status] { + threadHandler_->PostTask([pid, uid, status] { IntelliSenseServer::GetInstance().ReportContinuousTask(pid, uid, status); }); } @@ -146,6 +142,15 @@ void FrameMsgIntf::ReportSlideEvent(const int pid, const int uid, const int64_t void FrameMsgIntf::Stop() { + std::lock_guard autoLock(frameMsgIntfMutex_); + if (threadHandler_ != nullptr) { + threadHandler_->RemoveAllEvents(); + threadHandler_ = nullptr; + } + if (runner_ != nullptr) { + runner_->Stop(); + runner_ = nullptr; + } return; } } // namespace RME diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.h b/interfaces/innerkits/frameintf/frame_msg_intf.h index df2c65071d2acd59c8c3a40080338216578101c8..af867da1fdef2798c8002e6f95d38b46356e4a14 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.h +++ b/interfaces/innerkits/frameintf/frame_msg_intf.h @@ -16,7 +16,6 @@ #ifndef FRAME_MSG_INTF_H #define FRAME_MSG_INTF_H -#include "ffrt.h" #include "rme_constants.h" #include "single_instance.h" #include "event_handler.h" @@ -27,7 +26,7 @@ class FrameMsgIntf { public: static FrameMsgIntf& GetInstance(); bool Init(); - bool GetThreadQueue(); + bool GetThreadHandler(); void ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state); void ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state); void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup); @@ -38,10 +37,12 @@ public: void Stop(); protected: FrameMsgIntf() = default; - ~FrameMsgIntf(); + virtual ~FrameMsgIntf() = default; private: - ffrt::mutex frameMsgIntfMutex_; - ffrt::queue* taskQueue_; + std::mutex frameMsgIntfMutex_; + std::shared_ptr runner_; + std::shared_ptr threadHandler_; + DISALLOW_COPY_AND_MOVE(FrameMsgIntf); }; } // namespace RME } // namespace OHOS diff --git a/test/BUILD.gn b/test/BUILD.gn index 3278e777fcc1763df806cb4c8a728f84ccc5c7cc..68cb35e9a840a14386e41b50fa5e163f59045ecd 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -50,8 +50,6 @@ ohos_unittest("frame_msg_intf_test") { deps = frame_aware_sched_deps - external_deps = [ "ffrt:libffrt" ] - if (is_standard_system) { public_deps = frame_aware_sched_public_deps } diff --git a/test/unittest/phone/frame_msg_intf_test.cpp b/test/unittest/phone/frame_msg_intf_test.cpp index a3bb1a34ec09027bac2ff1a378aba30cd8e81825..34ce4928cb12a8c306944a509953133e01195d6c 100644 --- a/test/unittest/phone/frame_msg_intf_test.cpp +++ b/test/unittest/phone/frame_msg_intf_test.cpp @@ -53,6 +53,9 @@ void FrameMsgIntfTest::SetUp() void FrameMsgIntfTest::TearDown() { + FrameMsgIntf::GetInstance().Stop(); + std::shared_ptr thread = FrameMsgIntf::GetInstance().threadHandler_; + EXPECT_TRUE(thread == nullptr); } /** @@ -67,7 +70,7 @@ HWTEST_F(FrameMsgIntfTest, ReportContinuousTaskTest, TestSize.Level1) const int uid = 100086; const int status0 = 0; const int status1 = 1; - repCon.GetThreadQueue(); + repCon.GetThreadHandler(); repCon.ReportContinuousTask(pid, uid, status0); repCon.ReportContinuousTask(pid, uid, status1); }