From de0564bd3a6bf2c4ce1f38b43f43eedaa3297ad2 Mon Sep 17 00:00:00 2001 From: anchi Date: Fri, 2 Aug 2024 16:48:14 +0800 Subject: [PATCH 01/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9C=A8idle=E6=97=B6=E6=8B=89=E8=B5=B7sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- frameworks/include/work_info.h | 22 ++++++++++- frameworks/src/work_info.cpp | 29 ++++++++++++-- .../native/include/work_scheduler_service.h | 5 +++ .../src/conditions/battery_level_listener.cpp | 1 + .../native/src/work_scheduler_service.cpp | 39 ++++++++++++++++++- 5 files changed, 90 insertions(+), 6 deletions(-) diff --git a/frameworks/include/work_info.h b/frameworks/include/work_info.h index 9b3b9c2..4354301 100644 --- a/frameworks/include/work_info.h +++ b/frameworks/include/work_info.h @@ -306,6 +306,24 @@ public: * @return The extension. */ bool GetExtension() const; + /** + * @brief Get saId. + * + * @return The saId. + */ + int32_t GetSaId() const; + /** + * @brief Refresh saId. + * + * @param saId The saId. + */ + void RefreshSaId(int32_t saId); + /** + * @brief Get the work is residentSa. + * + * @return ResidentSa or not. + */ + bool IsResidentSa() const; private: int32_t workId_; @@ -320,13 +338,15 @@ private: std::string uriKey_; int32_t appIndex_; bool extension_; + int32_t saId_; + bool residentSa_; private: static bool UnmarshallCondition(Parcel &parcel, sptr &read, uint32_t mapsize); void ParseConditionToJsonStr(Json::Value &root); void ParseConditionFromJsonStr(const Json::Value &value); void ParseParametersFromJsonStr(const Json::Value &value); void ParseTimerFormJsonStr(const Json::Value &conditions); - bool IsHasBoolProp(const Json::Value &value, std::string key); + bool IsHasBoolProp(const Json::Value &value, const std::string &key); }; } // namespace WorkScheduler } // namespace OHOS diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index afe6013..b89fbe0 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -31,6 +31,7 @@ WorkInfo::WorkInfo() extras_ = nullptr; appIndex_ = APPINDEX_INIT_VALUE; extension_ = true; + saId_ = INVALID_VALUE; } WorkInfo::~WorkInfo() {} @@ -546,6 +547,11 @@ bool WorkInfo::ParseFromJson(const Json::Value &value) WS_HILOGE("workinfo json is empty"); return false; } + if (value.isMember("saId") && value["saId"].isInt() && IsHasBoolProp(value, "residentSa")) { + this->saId_ = value["saId"].asInt(); + this->residentSa_ = value["residentSa"].asBool(); + return true; + } if (!value.isMember("workId") || !value["workId"].isInt() || !value.isMember("bundleName") || !value["bundleName"].isString() || !value.isMember("abilityName") || !value["abilityName"].isString()) { @@ -555,16 +561,16 @@ bool WorkInfo::ParseFromJson(const Json::Value &value) this->workId_ = value["workId"].asInt(); this->bundleName_ = value["bundleName"].asString(); this->abilityName_ = value["abilityName"].asString(); - if (value.isMember("persisted") && value["persisted"].isBool()) { + if (IsHasBoolProp(value, "persisted")) { this->persisted_ = value["persisted"].asBool(); } - if (value.isMember("preinstalled") && value["preinstalled"].isBool()) { + if (IsHasBoolProp(value, "preinstalled")) { this->preinstalled_ = value["preinstalled"].asBool(); } if (value.isMember("uriKey") && value["uriKey"].isString()) { this->uriKey_ = value["uriKey"].asString(); } - if (value.isMember("callBySystemApp") && value["callBySystemApp"].isBool()) { + if (IsHasBoolProp(value, "callBySystemApp")) { this->callBySystemApp_ = value["callBySystemApp"].asBool(); } if (value.isMember("appIndex") && value["appIndex"].isInt()) { @@ -653,12 +659,27 @@ void WorkInfo::Dump(std::string &result) result.append(ParseToJsonStr()); } -bool WorkInfo::IsHasBoolProp(const Json::Value &value, std::string key) +bool WorkInfo::IsHasBoolProp(const Json::Value &value, const std::string &key) { if (value.isMember(key) && value[key].isBool()) { return true; } return false; } + +int32_t WorkInfo::GetSaId() const +{ + return saId_; +} + +void WorkInfo::RefreshSaId(int32_t saId) +{ + saId_ = saId; +} + +bool WorkInfo::IsResidentSa() const +{ + return residentSa_; +} } // namespace WorkScheduler } // namespace OHOS diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index c8f9ba4..0cbfd63 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -295,6 +295,10 @@ public: * @return success or fail. */ int32_t StopDeepIdleWorks(); + /** + * @brief load sa. + */ + void LoadSa(); private: void RegisterStandbyStateObserver(); void WorkQueueManagerInit(const std::shared_ptr& runner); @@ -331,6 +335,7 @@ private: private: std::set whitelist_; std::mutex whitelistMutex_; + std::map saMap_; #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE std::shared_ptr subscriber_; #endif diff --git a/services/native/src/conditions/battery_level_listener.cpp b/services/native/src/conditions/battery_level_listener.cpp index b9f7b5a..0195ea3 100644 --- a/services/native/src/conditions/battery_level_listener.cpp +++ b/services/native/src/conditions/battery_level_listener.cpp @@ -109,6 +109,7 @@ void BatteryLevelListener::OnConditionChanged(WorkCondition::Type conditionType, service_->SetDeepIdle(true); workQueueManager_->OnConditionChanged(WorkCondition::Type::DEEP_IDLE, std::make_shared(0, 0, true, std::string())); + service_->LoadSa(); } } else { WS_HILOGE("workQueueManager_ is nullptr."); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 138e410..e80ea11 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -91,6 +91,8 @@ const int32_t MAX_BUFFER = 2048; const int32_t DUMP_OPTION = 0; const int32_t DUMP_PARAM_INDEX = 1; const int32_t DUMP_VALUE_INDEX = 2; +const int32_t TIME_OUT = 4; +const int64_t DEVICE_IDLE = 5; const char* PERSISTED_FILE_PATH = "/data/service/el1/public/WorkScheduler/persisted_work"; const char* PERSISTED_PATH = "/data/service/el1/public/WorkScheduler"; const char* PREINSTALLED_FILE_PATH = "etc/backgroundtask/config.json"; @@ -173,7 +175,7 @@ void WorkSchedulerService::InitPreinstalledWork() { WS_HILOGD("init preinstalled work"); bool needRefresh = false; - list> preinstalledWorks = ReadPreinstalledWorks(); + static > preinstalledWorks = ReadPreinstalledWorks(); for (auto work : preinstalledWorks) { WS_HILOGD("preinstalled workinfo id %{public}d, uid %{public}d", work->GetWorkId(), work->GetUid()); if (!work->IsPersisted()) { @@ -252,6 +254,10 @@ void WorkSchedulerService::LoadWorksFromFile(const char *path, list workinfo = make_shared(); if (workinfo->ParseFromJson(workJson)) { + if (workinfo->GetSaId() > 0) { + saMap_.emplace(workinfo->GetSaId(), workinfo->IsResidentSa()); + continue; + } int32_t uid; if (!GetUidByBundleName(workinfo->GetBundleName(), uid)) { continue; @@ -1287,5 +1293,36 @@ int32_t WorkSchedulerService::StopDeepIdleWorks() } return ERR_OK; } + +void WorkSchedulerService::LoadSa() +{ + if (!ready_) { + WS_HILOGE("service is not ready."); + return; + } + if (saIdList_.empty()) { + WS_HILOGD("saIdList_ is empty."); + return; + } + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + WS_HILOGE("get sa manager failed."); + return; + } + for (auto it : saIdList_) { + if (it.second) { + std::vector vec = {it.first}; + std::string action = "strat"; + samgr->SendStrategy(DEVICE_IDLE, vec, 0, action); + continue; + } + auto res = samgr->LoadSystemAbility(it.first, TIME_OUT); + if (res == nullptr) { + WS_HILOGE("load sa: %{public}d failed.", it.first); + continue; + } + WS_HILOGD("load sa: %{public}d success.", it.first); + } +} } // namespace WorkScheduler } // namespace OHOS -- Gitee From bb9ca28bd846852ea6a61cbed07ba8969184ac59 Mon Sep 17 00:00:00 2001 From: anchi Date: Fri, 2 Aug 2024 17:04:06 +0800 Subject: [PATCH 02/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9C=A8idle=E6=97=B6=E6=8B=89=E8=B5=B7sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_scheduler_service.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index e80ea11..258f6de 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -1300,8 +1300,8 @@ void WorkSchedulerService::LoadSa() WS_HILOGE("service is not ready."); return; } - if (saIdList_.empty()) { - WS_HILOGD("saIdList_ is empty."); + if (saMap_.empty()) { + WS_HILOGD("saMap_ is empty."); return; } auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -1309,7 +1309,7 @@ void WorkSchedulerService::LoadSa() WS_HILOGE("get sa manager failed."); return; } - for (auto it : saIdList_) { + for (auto it : saMap_) { if (it.second) { std::vector vec = {it.first}; std::string action = "strat"; -- Gitee From 72f99137c305661247d036a9e30d7f154319b8eb Mon Sep 17 00:00:00 2001 From: anchi Date: Sat, 3 Aug 2024 16:23:34 +0800 Subject: [PATCH 03/63] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=A5=97=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- frameworks/test/unittest/src/work_sched_client_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/frameworks/test/unittest/src/work_sched_client_test.cpp b/frameworks/test/unittest/src/work_sched_client_test.cpp index 2fd420d..5626f3c 100644 --- a/frameworks/test/unittest/src/work_sched_client_test.cpp +++ b/frameworks/test/unittest/src/work_sched_client_test.cpp @@ -160,8 +160,6 @@ HWTEST_F(WorkSchedClientTest, WorkSchedClientTest_009, TestSize.Level1) sptr deathRecipient_ = sptr (new WorkSchedulerSrvClient::WorkSchedulerDeathRecipient(WorkSchedulerSrvClient::GetInstance())); deathRecipient_->OnRemoteDied(nullptr); - WorkSchedulerSrvClient::GetInstance().~WorkSchedulerSrvClient(); - EXPECT_EQ(WorkSchedulerSrvClient::GetInstance().iWorkSchedService_, nullptr); } /** -- Gitee From 444b56ea2b1851e72d04f64f5cbdd846ad9a1069 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 08:51:13 +0000 Subject: [PATCH 04/63] update bundle.json. Signed-off-by: hxf --- bundle.json | 1 + 1 file changed, 1 insertion(+) diff --git a/bundle.json b/bundle.json index 914f117..3569486 100644 --- a/bundle.json +++ b/bundle.json @@ -47,6 +47,7 @@ "config_policy", "hiview", "jsoncpp", + "hicollie", "hitrace", "power_manager" ] -- Gitee From 1f852f9b5f5b071c23d95dfb53286326a2383174 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 08:55:34 +0000 Subject: [PATCH 05/63] update workscheduler.gni. Signed-off-by: hxf --- workscheduler.gni | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/workscheduler.gni b/workscheduler.gni index 53f728f..ec08f75 100644 --- a/workscheduler.gni +++ b/workscheduler.gni @@ -78,4 +78,10 @@ declare_args() { !defined(global_parts_info.powermgr_power_manager)) { powermgr_power_manager_enable = false } + + workscheduler_hicollie_enable = true + if (defined(global_parts_info)) && + !defined(global_parts_info.hiviewdfx_hicollie)) { + workscheduler_hicollie_enable = false + } } -- Gitee From 151d6df682c26c2891d764fd1f42ae993dca3792 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 09:03:43 +0000 Subject: [PATCH 06/63] update services/BUILD.gn. Signed-off-by: hxf --- services/BUILD.gn | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/BUILD.gn b/services/BUILD.gn index 02a93ef..79f8c78 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -131,6 +131,10 @@ ohos_shared_library("workschedservice") { defines += [ "COMMUNICATION_NETMANAGER_BASE_ENABLE" ] external_deps += [ "netmanager_base:net_conn_manager_if" ] } + if (workscheduler_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } subsystem_name = "resourceschedule" part_name = "${worksched_native_part_name}" } @@ -238,6 +242,12 @@ ohos_static_library("workschedservice_static") { defines += [ "COMMUNICATION_NETMANAGER_BASE_ENABLE" ] external_deps += [ "netmanager_base:net_conn_manager_if" ] } + + if (workscheduler_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + subsystem_name = "resourceschedule" part_name = "${worksched_native_part_name}" } -- Gitee From ca9fc43389b19dd7c953a7a5ee64575140d8efa7 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 09:29:45 +0000 Subject: [PATCH 07/63] update services/zidl/include/work_sched_service_stub.h. Signed-off-by: hxf --- services/zidl/include/work_sched_service_stub.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/zidl/include/work_sched_service_stub.h b/services/zidl/include/work_sched_service_stub.h index b50f6bc..6301af7 100644 --- a/services/zidl/include/work_sched_service_stub.h +++ b/services/zidl/include/work_sched_service_stub.h @@ -21,6 +21,7 @@ #include #include "iwork_sched_service.h" +#include "iwork_sched_service_ipc_interface_code.h" namespace OHOS { namespace WorkScheduler { @@ -125,6 +126,12 @@ private: int32_t HandleGetAllRunningWorksRequest(MessageParcel &reply); int32_t HandleIsLastWorkTimeOutRequest(MessageParcel &data, MessageParcel &reply); int32_t HandleRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + int32_t SetTimer(uint32_t code); + void CancelTimer(int32_t id); +private: + std::map collieCodeStringMap_ = { + { uint32_t(IWorkSchedServiceInterfaceCode::START_WORK), "START_WORK" }, + }; }; } // namespace WorkScheduler } // namespace OHOS -- Gitee From 80d9431e013931b5e0cc495d93434020ad4be8b2 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 09:54:53 +0000 Subject: [PATCH 08/63] update services/zidl/src/work_sched_service_stub.cpp. Signed-off-by: hxf --- services/zidl/src/work_sched_service_stub.cpp | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/services/zidl/src/work_sched_service_stub.cpp b/services/zidl/src/work_sched_service_stub.cpp index 8862bbb..09d2e26 100644 --- a/services/zidl/src/work_sched_service_stub.cpp +++ b/services/zidl/src/work_sched_service_stub.cpp @@ -17,10 +17,14 @@ #include #include -#include "iwork_sched_service_ipc_interface_code.h" #include "work_sched_common.h" #include "work_sched_errors.h" +#ifdef HICOLLIE_ENABLE +#include "xcollie/xcollie.h" +#include "xcollie/xcollie_define.h" +#endif + namespace OHOS { namespace WorkScheduler { int32_t WorkSchedServiceStub::HandleObtainAllWorksRequest(MessageParcel &data, MessageParcel &reply) @@ -135,7 +139,10 @@ int32_t WorkSchedServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data WS_HILOGE("failed, descriptor is not matched!"); return E_PARCEL_OPERATION_FAILED; } - return HandleRequest(code, data, reply, option); + int32_t idTimer = SetTimer(code); + int32_t result = HandleRequest(code, data, reply, option); + CancelTimer(idTimer); + return result; } int32_t WorkSchedServiceStub::StartWorkStub(MessageParcel& data) @@ -225,5 +232,41 @@ int32_t WorkSchedServiceStub::ResumePausedWorksStub(MessageParcel& data, Message } return ret; } + +int32_t WorkSchedServiceStub::SetTimer(uint32_t code) +{ +#ifdef HICOLLIE_ENABLE + int32_t idTimer = HiviewDFX::INVALID_ID; + std::map::iterator itCollieId = collieCodeStringMap_.find(code); + if (itCollieId != collieCodeStringMap_.end()) { + std::string collieStr = itCollieId->second; + std::string collieName = "WorkSchedulerServiceStub:" + collieStr; + unsigned int flag = HiviewDFX::XCOLLIE_FLAG_LOG; + auto TimerCallbak = [collieStr](void *) { + WS_HILOGE("OnRemoteRequest timeout func: %{public}s", collieStr.c_str()); + }; + idTimer = HiviewDFX::XCollie::GetInstance().SetTimer( + collieName, XCOLLIE_TIMEOUT_SECONDS, TimerCallbak, nullptr, flag); + WS_HILOGD("SetTimer id: %{public}d, name: %{public}s.", idTimer, collieName.c_str()); + } + return idTimer; +#else + WS_HILOGD("No HICOLLIE_ENABLE"); + return -1; +#endif +} + +void WorkSchedServiceStub::CancelTimer(int32_t id) +{ +#ifdef HICOLLIE_ENABLE + if (id == HiviewDFX::INVALID_ID) { + return; + } + WS_HILOGD("CancelTimer id: %{public}d", id); + HiviewDFX::Xcollie::GetInstance().CancelTimer(id); +#else + return; +#endif +} } // namespace WorkScheduler } // namespace OHOS \ No newline at end of file -- Gitee From f1ec71b2fdabdd3ce6ffca97db333a13a5c773f0 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 10:44:29 +0000 Subject: [PATCH 09/63] update services/BUILD.gn. Signed-off-by: hxf --- services/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 79f8c78..069ef2d 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -242,7 +242,6 @@ ohos_static_library("workschedservice_static") { defines += [ "COMMUNICATION_NETMANAGER_BASE_ENABLE" ] external_deps += [ "netmanager_base:net_conn_manager_if" ] } - if (workscheduler_hicollie_enable) { external_deps += [ "hicollie:libhicollie" ] defines += [ "HICOLLIE_ENABLE" ] -- Gitee From c366e3e3c19ad054a1b2d929d24fb9aa6fda3637 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 10:56:33 +0000 Subject: [PATCH 10/63] update services/BUILD.gn. Signed-off-by: hxf --- services/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 069ef2d..3552a4a 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -246,7 +246,7 @@ ohos_static_library("workschedservice_static") { external_deps += [ "hicollie:libhicollie" ] defines += [ "HICOLLIE_ENABLE" ] } - + subsystem_name = "resourceschedule" part_name = "${worksched_native_part_name}" } -- Gitee From ea80b5a0a6ce36966017323226fbc44c48ae437d Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 11:29:19 +0000 Subject: [PATCH 11/63] update workscheduler.gni. Signed-off-by: hxf --- workscheduler.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workscheduler.gni b/workscheduler.gni index ec08f75..18e7e0f 100644 --- a/workscheduler.gni +++ b/workscheduler.gni @@ -80,7 +80,7 @@ declare_args() { } workscheduler_hicollie_enable = true - if (defined(global_parts_info)) && + if (defined(global_parts_info) && !defined(global_parts_info.hiviewdfx_hicollie)) { workscheduler_hicollie_enable = false } -- Gitee From 6ca0e727cf9ff84048ad53b367b07a85cd43ee9f Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 11:35:36 +0000 Subject: [PATCH 12/63] update workscheduler.gni. Signed-off-by: hxf --- workscheduler.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workscheduler.gni b/workscheduler.gni index 18e7e0f..80f3c5d 100644 --- a/workscheduler.gni +++ b/workscheduler.gni @@ -78,7 +78,7 @@ declare_args() { !defined(global_parts_info.powermgr_power_manager)) { powermgr_power_manager_enable = false } - + workscheduler_hicollie_enable = true if (defined(global_parts_info) && !defined(global_parts_info.hiviewdfx_hicollie)) { -- Gitee From b21bdea8d5378b2c4e9876117591b9479a8dbb09 Mon Sep 17 00:00:00 2001 From: hxf Date: Sat, 3 Aug 2024 11:58:31 +0000 Subject: [PATCH 13/63] update services/zidl/src/work_sched_service_stub.cpp. Signed-off-by: hxf --- services/zidl/src/work_sched_service_stub.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/services/zidl/src/work_sched_service_stub.cpp b/services/zidl/src/work_sched_service_stub.cpp index 09d2e26..a1e9a5e 100644 --- a/services/zidl/src/work_sched_service_stub.cpp +++ b/services/zidl/src/work_sched_service_stub.cpp @@ -23,6 +23,7 @@ #ifdef HICOLLIE_ENABLE #include "xcollie/xcollie.h" #include "xcollie/xcollie_define.h" +#define XCOLLIE_TIMEOUT_SECONDS 30 #endif namespace OHOS { @@ -237,16 +238,16 @@ int32_t WorkSchedServiceStub::SetTimer(uint32_t code) { #ifdef HICOLLIE_ENABLE int32_t idTimer = HiviewDFX::INVALID_ID; - std::map::iterator itCollieId = collieCodeStringMap_.find(code); + std::map::iterator itCollieId = collieCodeStringMap_.find(code); if (itCollieId != collieCodeStringMap_.end()) { std::string collieStr = itCollieId->second; std::string collieName = "WorkSchedulerServiceStub:" + collieStr; unsigned int flag = HiviewDFX::XCOLLIE_FLAG_LOG; - auto TimerCallbak = [collieStr](void *) { + auto TimerCallback = [collieStr](void *) { WS_HILOGE("OnRemoteRequest timeout func: %{public}s", collieStr.c_str()); }; idTimer = HiviewDFX::XCollie::GetInstance().SetTimer( - collieName, XCOLLIE_TIMEOUT_SECONDS, TimerCallbak, nullptr, flag); + collieName, XCOLLIE_TIMEOUT_SECONDS, TimerCallback, nullptr, flag); WS_HILOGD("SetTimer id: %{public}d, name: %{public}s.", idTimer, collieName.c_str()); } return idTimer; @@ -262,8 +263,8 @@ void WorkSchedServiceStub::CancelTimer(int32_t id) if (id == HiviewDFX::INVALID_ID) { return; } - WS_HILOGD("CancelTimer id: %{public}d", id); - HiviewDFX::Xcollie::GetInstance().CancelTimer(id); + WS_HILOGD("CancelTimer id: %{public}d.", id); + HiviewDFX::XCollie::GetInstance().CancelTimer(id); #else return; #endif -- Gitee From ccf8da968b45acc3c17372e6a955624dff67a5d7 Mon Sep 17 00:00:00 2001 From: anchi Date: Mon, 5 Aug 2024 14:21:52 +0800 Subject: [PATCH 14/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9C=A8idle=E6=97=B6=E6=8B=89=E8=B5=B7sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- frameworks/src/work_info.cpp | 2 +- .../test/unittest/src/workinfo_test.cpp | 18 ++++++++++++++ .../native/src/work_scheduler_service.cpp | 24 +++++++++++-------- .../test/src/workschedulerservice_test.cpp | 23 ++++++++++++++++++ 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index b89fbe0..3acdc16 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -547,7 +547,7 @@ bool WorkInfo::ParseFromJson(const Json::Value &value) WS_HILOGE("workinfo json is empty"); return false; } - if (value.isMember("saId") && value["saId"].isInt() && IsHasBoolProp(value, "residentSa")) { + if ((value.isMember("saId") && value["saId"].isInt()) && IsHasBoolProp(value, "residentSa")) { this->saId_ = value["saId"].asInt(); this->residentSa_ = value["residentSa"].asBool(); return true; diff --git a/frameworks/test/unittest/src/workinfo_test.cpp b/frameworks/test/unittest/src/workinfo_test.cpp index 5a31b2a..c254a9e 100644 --- a/frameworks/test/unittest/src/workinfo_test.cpp +++ b/frameworks/test/unittest/src/workinfo_test.cpp @@ -687,5 +687,23 @@ HWTEST_F (WorkInfoTest, WorkSchedUtils006, Function | MediumTest | Level0) bool res = WorkSchedUtils::IsSystemApp(); EXPECT_EQ(res, false); } + +/** + * @tc.name GetSaId_001 + * @tc.desc test GetSaId and IsResidentSa + * @tc.type FUNC + * @tc.require: issueI5Y6YK + */ +HWTEST_F (WorkInfoTest, GetSaId_001, Function | MediumTest | Level0) +{ + int32_t saId = 5300; + WorkInfo workInfo = WorkInfo(); + workInfo.RefreshSaId(saId); + int32_t id = workInfo.GetSaId(); + EXPECT_EQ(id, saId); + + bool residentSa = workInfo.IsResidentSa(); + EXPECT_FALSE(residentSa); +} } // namespace WorkScheduler } // namespace OHOS \ No newline at end of file diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 258f6de..75c76cf 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -175,7 +175,7 @@ void WorkSchedulerService::InitPreinstalledWork() { WS_HILOGD("init preinstalled work"); bool needRefresh = false; - static > preinstalledWorks = ReadPreinstalledWorks(); + static list> preinstalledWorks = ReadPreinstalledWorks(); for (auto work : preinstalledWorks) { WS_HILOGD("preinstalled workinfo id %{public}d, uid %{public}d", work->GetWorkId(), work->GetUid()); if (!work->IsPersisted()) { @@ -1310,18 +1310,22 @@ void WorkSchedulerService::LoadSa() return; } for (auto it : saMap_) { - if (it.second) { - std::vector vec = {it.first}; - std::string action = "strat"; - samgr->SendStrategy(DEVICE_IDLE, vec, 0, action); - continue; + std::vector vec = {it.first}; + std::string action = "strat"; + if (!it.second) { + auto res = samgr->LoadSystemAbility(it.first, TIME_OUT); + if (res == nullptr) { + WS_HILOGE("load sa: %{public}d failed.", it.first); + continue; + } + WS_HILOGD("load sa: %{public}d success.", it.first); } - auto res = samgr->LoadSystemAbility(it.first, TIME_OUT); - if (res == nullptr) { - WS_HILOGE("load sa: %{public}d failed.", it.first); + int32_t ret = samgr->SendStrategy(DEVICE_IDLE, vec, 0, action); + if (ret != ERR_OK) { + WS_HILOGE("sa: %{public}d sendStrategy failed.", it.first); continue; } - WS_HILOGD("load sa: %{public}d success.", it.first); + WS_HILOGD("sa: %{public}d sendStrategy successed.", it.first); } } } // namespace WorkScheduler diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index 49032db..f8392e9 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -686,5 +686,28 @@ HWTEST_F(WorkSchedulerServiceTest, GetAppIndexAndBundleNameByUid_001, TestSize.L bool ret = workSchedulerService_->GetAppIndexAndBundleNameByUid(uid, appIndex, bundleName); EXPECT_FALSE(ret); } + +/** + * @tc.name: LoadSa_001 + * @tc.desc: Test WorkSchedulerService LoadSa. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) +{ + workSchedulerService_->ready_ = false; + workSchedulerService_->LoadSa(); + + workSchedulerService_->ready_ = true; + workSchedulerService_->saMap_.clear(); + workSchedulerService_->LoadSa(); + + int32_t saId = 5300; + workSchedulerService_->saMap_.emplace(saId, true); + workSchedulerService_->LoadSa(); + + workSchedulerService_->saMap_.emplace(1, false); + workSchedulerService_->LoadSa(); +} } } \ No newline at end of file -- Gitee From f51e5415cc7294a9fbf58662757f7b0bf61ec245 Mon Sep 17 00:00:00 2001 From: anchi Date: Mon, 5 Aug 2024 17:06:30 +0800 Subject: [PATCH 15/63] uddate test Signed-off-by: anchi --- frameworks/test/unittest/src/workinfo_test.cpp | 6 +++--- services/native/src/work_scheduler_service.cpp | 6 +++--- services/test/src/workschedulerservice_test.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frameworks/test/unittest/src/workinfo_test.cpp b/frameworks/test/unittest/src/workinfo_test.cpp index c254a9e..74039c6 100644 --- a/frameworks/test/unittest/src/workinfo_test.cpp +++ b/frameworks/test/unittest/src/workinfo_test.cpp @@ -689,12 +689,12 @@ HWTEST_F (WorkInfoTest, WorkSchedUtils006, Function | MediumTest | Level0) } /** - * @tc.name GetSaId_001 + * @tc.name GetSaId001 * @tc.desc test GetSaId and IsResidentSa * @tc.type FUNC - * @tc.require: issueI5Y6YK + * @tc.require: issueIAHY0B */ -HWTEST_F (WorkInfoTest, GetSaId_001, Function | MediumTest | Level0) +HWTEST_F (WorkInfoTest, GetSaId001, Function | MediumTest | Level0) { int32_t saId = 5300; WorkInfo workInfo = WorkInfo(); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 75c76cf..23922d3 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -1301,7 +1301,7 @@ void WorkSchedulerService::LoadSa() return; } if (saMap_.empty()) { - WS_HILOGD("saMap_ is empty."); + WS_HILOGD("saMap is empty."); return; } auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -1311,14 +1311,14 @@ void WorkSchedulerService::LoadSa() } for (auto it : saMap_) { std::vector vec = {it.first}; - std::string action = "strat"; + std::string action = "start"; if (!it.second) { auto res = samgr->LoadSystemAbility(it.first, TIME_OUT); if (res == nullptr) { WS_HILOGE("load sa: %{public}d failed.", it.first); continue; } - WS_HILOGD("load sa: %{public}d success.", it.first); + WS_HILOGD("load sa: %{public}d successed.", it.first); } int32_t ret = samgr->SendStrategy(DEVICE_IDLE, vec, 0, action); if (ret != ERR_OK) { diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index f8392e9..79e677c 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -691,7 +691,7 @@ HWTEST_F(WorkSchedulerServiceTest, GetAppIndexAndBundleNameByUid_001, TestSize.L * @tc.name: LoadSa_001 * @tc.desc: Test WorkSchedulerService LoadSa. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAHY0B */ HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) { -- Gitee From 1ee664b5700709afe5affc89258732b389c99dba Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 6 Aug 2024 18:47:04 +0800 Subject: [PATCH 16/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- .../native/src/work_scheduler_service.cpp | 46 ++++++++++++--- .../test/src/workschedulerservice_test.cpp | 56 ++++++++++++++++++- 2 files changed, 90 insertions(+), 12 deletions(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 23922d3..641852e 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -853,6 +853,8 @@ void WorkSchedulerService::DumpProcess(std::vector &argsInStr, std: DumpProcessWorks(argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX], result); } else if (argsInStr[DUMP_OPTION] == "-x") { DumpRunningWorks(argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX], result); + } else if (argsInStr[DUMP_OPTION] == "-s") { + DumpLoadSaWorks(argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX], result); } else { result.append("Error params."); } @@ -903,7 +905,8 @@ void WorkSchedulerService::DumpUsage(std::string &result) .append(" -repeat_time_min (number): set min repeat cycle time, default 1200000.\n") .append(" -min_interval (number): set min interval time, set 0 means close test mode.\n") .append(" -cpu (number): set the usage cpu.\n") - .append(" -count (number): set the max running task count.\n"); + .append(" -count (number): set the max running task count.\n") + .append(" -s (number) (bool): set the sa id running task.\n"); } void WorkSchedulerService::DumpAllInfo(std::string &result) @@ -1301,20 +1304,24 @@ void WorkSchedulerService::LoadSa() return; } if (saMap_.empty()) { - WS_HILOGD("saMap is empty."); + WS_HILOGI("saMap is empty."); return; } - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { WS_HILOGE("get sa manager failed."); return; } - for (auto it : saMap_) { - std::vector vec = {it.first}; - std::string action = "start"; - if (!it.second) { - auto res = samgr->LoadSystemAbility(it.first, TIME_OUT); - if (res == nullptr) { + for (auto &it : saMap_) { + std::vector vec = { it.first }; + std::string action = ""; + sptr object = samgr->CheckSystemAbility(it.first); + if (it.second && object == nullptr) { + WS_HILOGE("resident sa: %{public}d does not exist.", it.first); + continue; + } else if (!it.second && object == nullptr) { + auto object = samgr->LoadSystemAbility(it.first, TIME_OUT); + if (object == nullptr) { WS_HILOGE("load sa: %{public}d failed.", it.first); continue; } @@ -1328,5 +1335,26 @@ void WorkSchedulerService::LoadSa() WS_HILOGD("sa: %{public}d sendStrategy successed.", it.first); } } + +void WorkSchedulerService::DumpLoadSaWorks(const std::string &saIdStr, const std::string &residentSaStr, + std::string &result) +{ + if (saIdStr.empty() || residentSaStr.empty()) { + result.append("param error."); + return + } + int32_t saId = std::stoi(saIdStr); + if (saId < 0 || (residentSaStr != "true" && residentSaStr != "false")) { + result.append("the parameter is invalid."); + return; + } + bool residentSa = (residentSaStr == "true") ? true : false; + if (saMap_.count(saId) > 0) { + saMap_.at(saId) = residentSa; + } else { + saMap_.emplace(saId, residentSa); + } + LoadSa(); +} } // namespace WorkScheduler } // namespace OHOS diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index 79e677c..0c22e6a 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -487,6 +487,49 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_005, TestSize.Level1) WS_HILOGI("====== WorkSchedulerServiceTest.Dump_005 end ====== "); } +/** + * @tc.name: Dump_006 + * @tc.desc: Test WorkSchedulerService Dump. + * @tc.type: FUNC + * @tc.require: IAHY0B + */ +HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) +{ + WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 begin ====== "); + std::vector argsInStr; + std::string result; + argsInStr.push_back("-s"); + argsInStr.push_back("1"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), false); + + argsInStr.clear(); + result.clear(); + argsInStr.push_back("-s"); + argsInStr.push_back("1"); + argsInStr.push_back("1"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + + argsInStr.clear(); + result.clear(); + argsInStr.push_back("-s"); + argsInStr.push_back("1"); + argsInStr.push_back("true"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + + argsInStr.clear(); + result.clear(); + argsInStr.push_back("-s"); + argsInStr.push_back("1"); + argsInStr.push_back("false"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 end ====== "); +} + HWTEST_F(WorkSchedulerServiceTest, WorkStandbyStateChangeCallbackTest_001, TestSize.Level1) { WS_HILOGI("====== WorkSchedulerServiceTest.WorkStandbyStateChangeCallbackTest_001 begin ====== "); @@ -702,11 +745,18 @@ HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) workSchedulerService_->saMap_.clear(); workSchedulerService_->LoadSa(); - int32_t saId = 5300; - workSchedulerService_->saMap_.emplace(saId, true); + int32_t saId1 = 401; + workSchedulerService_->saMap_.emplace(saId1, true); + workSchedulerService_->LoadSa(); + + workSchedulerService_->saMap_.emplace(saId1, false); + workSchedulerService_->LoadSa(); + + int32_t saId2 = 5300; + workSchedulerService_->saMap_.emplace(saId2, true); workSchedulerService_->LoadSa(); - workSchedulerService_->saMap_.emplace(1, false); + workSchedulerService_->saMap_.emplace(saId2, false); workSchedulerService_->LoadSa(); } } -- Gitee From f42865925b998d76303050d5eddebd666cccd640 Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 6 Aug 2024 18:48:06 +0800 Subject: [PATCH 17/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/include/work_scheduler_service.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index 0cbfd63..8cceb08 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -331,6 +331,7 @@ private: bool CheckProcessName(); bool GetAppIndexAndBundleNameByUid(int32_t uid, int32_t &appIndex, std::string &bundleName); bool CheckExtensionInfos(WorkInfo &workInfo, int32_t uid); + void DumpLoadSaWorks(const std::string &saIdStr, const std::string &residentSaStr, std::string &result); private: std::set whitelist_; -- Gitee From da261a2f6a1b1a1bdaf4f170382d5e28d463e6af Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 6 Aug 2024 19:17:49 +0800 Subject: [PATCH 18/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_scheduler_service.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 641852e..e8a85f6 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -1320,7 +1320,7 @@ void WorkSchedulerService::LoadSa() WS_HILOGE("resident sa: %{public}d does not exist.", it.first); continue; } else if (!it.second && object == nullptr) { - auto object = samgr->LoadSystemAbility(it.first, TIME_OUT); + object = samgr->LoadSystemAbility(it.first, TIME_OUT); if (object == nullptr) { WS_HILOGE("load sa: %{public}d failed.", it.first); continue; @@ -1341,7 +1341,7 @@ void WorkSchedulerService::DumpLoadSaWorks(const std::string &saIdStr, const std { if (saIdStr.empty() || residentSaStr.empty()) { result.append("param error."); - return + return; } int32_t saId = std::stoi(saIdStr); if (saId < 0 || (residentSaStr != "true" && residentSaStr != "false")) { -- Gitee From b2d0b32b25efbdf12b95c30cfc78b0af69158777 Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 6 Aug 2024 20:19:03 +0800 Subject: [PATCH 19/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_scheduler_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index e8a85f6..5d79fc7 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -1332,7 +1332,7 @@ void WorkSchedulerService::LoadSa() WS_HILOGE("sa: %{public}d sendStrategy failed.", it.first); continue; } - WS_HILOGD("sa: %{public}d sendStrategy successed.", it.first); + WS_HILOGI("sa: %{public}d sendStrategy successed.", it.first); } } -- Gitee From 61b886948c0d106bc4a7f9631ea2eeab542dcd1e Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 6 Aug 2024 21:37:10 +0800 Subject: [PATCH 20/63] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_scheduler_service.cpp | 2 +- services/test/src/workschedulerservice_test.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 5d79fc7..36a8f87 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -1337,7 +1337,7 @@ void WorkSchedulerService::LoadSa() } void WorkSchedulerService::DumpLoadSaWorks(const std::string &saIdStr, const std::string &residentSaStr, - std::string &result) + std::string &result) { if (saIdStr.empty() || residentSaStr.empty()) { result.append("param error."); diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index 0c22e6a..38f5c2e 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -511,6 +511,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) argsInStr.push_back("1"); workSchedulerService_->DumpProcess(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), false); argsInStr.clear(); result.clear(); @@ -519,6 +520,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) argsInStr.push_back("true"); workSchedulerService_->DumpProcess(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), true); argsInStr.clear(); result.clear(); @@ -527,6 +529,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) argsInStr.push_back("false"); workSchedulerService_->DumpProcess(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), true); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 end ====== "); } -- Gitee From 38642f313560864ec88331a3d0e3fd7f503366f5 Mon Sep 17 00:00:00 2001 From: anchi Date: Wed, 7 Aug 2024 09:40:52 +0800 Subject: [PATCH 21/63] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_scheduler_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 36a8f87..616ca0d 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -254,7 +254,7 @@ void WorkSchedulerService::LoadWorksFromFile(const char *path, list workinfo = make_shared(); if (workinfo->ParseFromJson(workJson)) { - if (workinfo->GetSaId() > 0) { + if (workinfo->GetSaId() > -1) { saMap_.emplace(workinfo->GetSaId(), workinfo->IsResidentSa()); continue; } -- Gitee From 236eb9e97ed6d607a505f67d524699824095d7a3 Mon Sep 17 00:00:00 2001 From: anchi Date: Fri, 9 Aug 2024 16:18:28 +0800 Subject: [PATCH 22/63] =?UTF-8?q?=E9=80=9A=E8=BF=87=E4=B8=8A=E6=8A=A5rss,?= =?UTF-8?q?=E7=BB=99sa=E5=8F=91=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- bundle.json | 3 ++- services/BUILD.gn | 2 ++ services/native/src/work_scheduler_service.cpp | 16 ++++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/bundle.json b/bundle.json index 3569486..dedd3de 100644 --- a/bundle.json +++ b/bundle.json @@ -49,7 +49,8 @@ "jsoncpp", "hicollie", "hitrace", - "power_manager" + "power_manager", + "resource_schedule_service" ] }, "build": { diff --git a/services/BUILD.gn b/services/BUILD.gn index 3552a4a..fc87564 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -96,6 +96,7 @@ ohos_shared_library("workschedservice") { "hiview:libucollection_client", "init:libbegetutil", "ipc:ipc_single", + "resource_schedule_service:ressched_client", "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", @@ -207,6 +208,7 @@ ohos_static_library("workschedservice_static") { "hiview:libucollection_client", "init:libbegetutil", "ipc:ipc_single", + "resource_schedule_service:ressched_client", "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 616ca0d..2336029 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -72,6 +72,8 @@ #include "work_sched_hilog.h" #include "work_sched_utils.h" #include "hitrace_meter.h" +#include "res_type.h" +#include "res_sched_client.h" using namespace std; using namespace OHOS::AppExecFwk; @@ -1313,8 +1315,6 @@ void WorkSchedulerService::LoadSa() return; } for (auto &it : saMap_) { - std::vector vec = { it.first }; - std::string action = ""; sptr object = samgr->CheckSystemAbility(it.first); if (it.second && object == nullptr) { WS_HILOGE("resident sa: %{public}d does not exist.", it.first); @@ -1327,12 +1327,12 @@ void WorkSchedulerService::LoadSa() } WS_HILOGD("load sa: %{public}d successed.", it.first); } - int32_t ret = samgr->SendStrategy(DEVICE_IDLE, vec, 0, action); - if (ret != ERR_OK) { - WS_HILOGE("sa: %{public}d sendStrategy failed.", it.first); - continue; - } - WS_HILOGI("sa: %{public}d sendStrategy successed.", it.first); + std::string action = ""; + std::unordered_map payload; + payload["action"] = action; + payload["saId"] = std::to_string(it.first); + uint32_t type = ResourceSchedule::ResType::RES_TYPE_DEVICE_IDLE; + ResourceSchedule::ResSchedClient::GetInstance().ReportData(type, 0, payload); } } -- Gitee From fa9fe6360f35f19cf1de13bede0bde65a6bfcfd3 Mon Sep 17 00:00:00 2001 From: anchi Date: Fri, 9 Aug 2024 16:23:38 +0800 Subject: [PATCH 23/63] =?UTF-8?q?=E9=80=9A=E8=BF=87=E4=B8=8A=E6=8A=A5rss,?= =?UTF-8?q?=E7=BB=99sa=E5=8F=91=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_scheduler_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 2336029..3ed7bf5 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -94,7 +94,6 @@ const int32_t DUMP_OPTION = 0; const int32_t DUMP_PARAM_INDEX = 1; const int32_t DUMP_VALUE_INDEX = 2; const int32_t TIME_OUT = 4; -const int64_t DEVICE_IDLE = 5; const char* PERSISTED_FILE_PATH = "/data/service/el1/public/WorkScheduler/persisted_work"; const char* PERSISTED_PATH = "/data/service/el1/public/WorkScheduler"; const char* PREINSTALLED_FILE_PATH = "etc/backgroundtask/config.json"; -- Gitee From 79355c9121f4c7609fb3b4c14583df9325047284 Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 13 Aug 2024 20:32:51 +0800 Subject: [PATCH 24/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/test/BUILD.gn | 1 + .../src/conditions/network_listener_test.cpp | 220 ++++++++++++++++++ services/test/src/work_status_test.cpp | 210 +++++++++++++++++ .../test/src/workschedulerservice_test.cpp | 163 +++++++++++++ 4 files changed, 594 insertions(+) create mode 100644 services/test/src/conditions/network_listener_test.cpp diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index e66e154..6b1d74e 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("WorkScheduleServiceTest") { "-fno-omit-frame-pointer", ] sources = [ + "src/conditions/network_listener_test.cpp", "src/conditions/screen_listener_test.cpp", "src/event_publisher_test.cpp", "src/policy/app_data_clear_listener_test.cpp", diff --git a/services/test/src/conditions/network_listener_test.cpp b/services/test/src/conditions/network_listener_test.cpp new file mode 100644 index 0000000..d8916ea --- /dev/null +++ b/services/test/src/conditions/network_listener_test.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "conditions/network_listener.h" +#include "work_scheduler_service.h" +#include "work_queue_manager.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "net_supplier_info.h" + +using namespace testing::ext; + +namespace OHOS { +namespace WorkScheduler { +const int32_t DEFAULT_VALUE = -1; +const int32_t BEARER_CELLULAR = 0; +const int32_t BEARER_WIFI = 1; +const int32_t BEARER_BLUETOOTH = 2; +const int32_t BEARER_ETHERNET = 3; +const int32_t BEARER_WIFI_AWARE = 5; + +class NetworkListenerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + static std::shared_ptr workSchedulerService_; + static std::shared_ptr workQueueManager_; + static std::shared_ptr networkListenerTest_; +} + +std::shared_ptr NetworkListenerTest::workSchedulerService_ = nullptr; +std::shared_ptr NetworkListenerTest::workQueueManager_ = nullptr; +std::shared_ptr NetworkListenerTest::networkListenerTest_ = nullptr; + +void NetworkListenerTest::SetUpTestCase() +{ + workSchedulerService_ = std::make_shared(); + workQueueManager_ = std::make_shared(workSchedulerService_); + networkListenerTest_ = std::make_shared(workQueueManager_, workSchedulerService_); +} + +/** + * @tc.name: OnConditionChanged_001 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_001, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_002 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_002, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + want.SetParam("NetType", BEARER_CELLULAR); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_003 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_003, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + want.SetParam("NetType", BEARER_WIFI); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_004 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_004, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + want.SetParam("NetType", BEARER_BLUETOOTH); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_005 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_005, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + want.SetParam("NetType", BEARER_ETHERNET); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_006 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_006, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + want.SetParam("NetType", BEARER_WIFI_AWARE); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_007 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_007, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + want.SetParam("NetType", DEFAULT_VALUE); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: OnConditionChanged_008 + * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.type: FUNC + * @tc.require: I974IQ + */ +HWTEST_F(ScreenListenerTest, OnConditionChanged_008, TestSize.Level1) +{ + networkListenerTest_->Start(); + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); + data.SetWant(want); + data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); + EventFwk::CommonEventManager::PublishCommonEvent(data); + networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListenerTest_->Stop(); + EXPECT_TRUE(ret); +} +} +} \ No newline at end of file diff --git a/services/test/src/work_status_test.cpp b/services/test/src/work_status_test.cpp index c76bae1..cf79021 100644 --- a/services/test/src/work_status_test.cpp +++ b/services/test/src/work_status_test.cpp @@ -19,6 +19,7 @@ #include "work_status.h" #include "work_condition.h" #include "work_sched_hilog.h" +#include "work_info.h" using namespace testing::ext; @@ -495,5 +496,214 @@ HWTEST_F(WorkStatusTest, isRepeating_001, TestSize.Level1) bool ret2 = workStatus_->IsRepeating(); EXPECT_TRUE(ret2); } + +/** + * @tc.name: IsReadyStatus_001 + * @tc.desc: Test WorkStatus IsReadyStatus. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, IsReadyStatus_001, TestSize.Level1) +{ + workStatus_->MarkStatus(WorkStatus::Status::WAIT_CONDITION); + bool ret = workStatus_->IsReadyStatus(); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: IsRemoved_001 + * @tc.desc: Test WorkStatus IsRemoved. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, IsRemoved_001, TestSize.Level1) +{ + workStatus_->MarkStatus(WorkStatus::Status::REMOVED); + bool ret = workStatus_->IsRemoved(); + EXPECT_TRUE(ret); + workStatus_->MarkRound(); +} + +/** + * @tc.name: NeedRemove_001 + * @tc.desc: Test WorkStatus NeedRemove. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, NeedRemove_001, TestSize.Level1) +{ + workStatus_->conditionMap_.clear(); + bool ret = workStatus_->NeedRemove(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: NeedRemove_002 + * @tc.desc: Test WorkStatus NeedRemove. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, NeedRemove_002, TestSize.Level1) +{ + workStatus_->conditionMap_.clear(); + std::shared_ptr repeatCycle = std::make_shared(); + repeatCycle->boolVal = true; + workStatus_->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle); + bool ret = workStatus_->NeedRemove(); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: NeedRemove_003 + * @tc.desc: Test WorkStatus NeedRemove. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, NeedRemove_003, TestSize.Level1) +{ + workStatus_->conditionMap_.clear(); + std::shared_ptr repeatCycle = std::make_shared(); + repeatCycle->boolVal = false; + repeatCycle->intVal = 0; + workStatus_->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle); + bool ret = workStatus_->NeedRemove(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: NeedRemove_004 + * @tc.desc: Test WorkStatus NeedRemove. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, NeedRemove_004, TestSize.Level1) +{ + workStatus_->conditionMap_.clear(); + std::shared_ptr repeatCycle = std::make_shared(); + repeatCycle->boolVal = false; + repeatCycle->intVal = 1; + workStatus_->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle); + bool ret = workStatus_->NeedRemove(); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: UpdateTimerIfNeed_001 + * @tc.desc: Test WorkStatus UpdateTimerIfNeed. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, UpdateTimerIfNeed_001, TestSize.Level1) +{ + workStatus_->conditionMap_.clear(); + workStatus_->UpdateTimerIfNeed(); + + std::shared_ptr repeatCycle = std::make_shared(); + repeatCycle->boolVal = false; + workStatus_->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle); + workStatus_->UpdateTimerIfNeed(); +} + +/** + * @tc.name: UpdateTimerIfNeed_002 + * @tc.desc: Test WorkStatus UpdateTimerIfNeed. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, UpdateTimerIfNeed_002, TestSize.Level1) +{ + workStatus_->conditionMap_.clear(); + workStatus_->UpdateTimerIfNeed(); + + std::shared_ptr repeatCycle = std::make_shared(); + repeatCycle->boolVal = true; + repeatCycle->intVal = 1; + workStatus_->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle); + workStatus_->UpdateTimerIfNeed(); +} + +/** + * @tc.name: MarkTimeout_001 + * @tc.desc: Test WorkStatus MarkTimeout. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, MarkTimeout_001, TestSize.Level1) +{ + workStatus_->MarkTimeout(); + bool ret = workStatus_->IsLastWorkTimeout(); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: IsNapReady_001 + * @tc.desc: Test WorkStatus IsNapReady. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, IsNapReady_001, TestSize.Level1) +{ + WorkInfo workInfo = WorkInfo(); + std::shared_ptr repeatCycle1 = std::make_shared(); + repeatCycle1->boolVal = true; + workInfo.conditionMap_.emplace(WorkCondition::Type::DEEP_IDLE, repeatCycle1); + workStatus_->workInfo_ = std::make_shared(workInfo); + + std::shared_ptr repeatCycle2 = std::make_shared(); + repeatCycle2->boolVal = false; + workStatus_->conditionMap_.emplace(WorkCondition::Type::DEEP_IDLE, repeatCycle2); + + bool ret = workStatus_->IsNapReady(WorkCondition::Type::DEEP_IDLE); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: IsNapReady_002 + * @tc.desc: Test WorkStatus IsNapReady. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, IsNapReady_002, TestSize.Level1) +{ + WorkInfo workInfo = WorkInfo(); + std::shared_ptr repeatCycle1 = std::make_shared(); + repeatCycle1->boolVal = true; + workInfo.conditionMap_.emplace(WorkCondition::Type::DEEP_IDLE, repeatCycle1); + workStatus_->workInfo_ = std::make_shared(workInfo); + + std::shared_ptr repeatCycle2 = std::make_shared(); + repeatCycle2->boolVal = true; + workStatus_->conditionMap_.emplace(WorkCondition::Type::DEEP_IDLE, repeatCycle2); + + bool ret = workStatus_->IsNapReady(WorkCondition::Type::DEEP_IDLE); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: UpdateUidLastTimeMap_001 + * @tc.desc: Test WorkStatus UpdateUidLastTimeMap. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, UpdateUidLastTimeMap_001, TestSize.Level1) +{ + workStatus_->uid_ = 1; + workStatus_->UpdateUidLastTimeMap(); + workStatus_->ClearUidLastTimeMap(1); +} + +/** + * @tc.name: GetStatus_001 + * @tc.desc: Test WorkStatus GetStatus. + * @tc.type: FUNC + * @tc.require: I95QHG + */ +HWTEST_F(WorkStatusTest, GetStatus_001, TestSize.Level1) +{ + workStatus_->MarkStatus(WorkStatus::Status::RUNNING); + EXPECT_EQ(workStatus_->GetStatus(), WorkStatus::Status::RUNNING); +} + + } } \ No newline at end of file diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index 38f5c2e..faa76ba 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -91,6 +91,9 @@ void OHOS::RefBase::DecStrongRef(void const* obj) {} using namespace testing::ext; namespace OHOS { namespace WorkScheduler { +const int32_t DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID = 1914; +const int32_t DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID = 1907; + class WorkSchedulerServiceTest : public testing::Test { public: static void SetUpTestCase() {} @@ -533,6 +536,52 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 end ====== "); } +/** + * @tc.name: Dump_007 + * @tc.desc: Test WorkSchedulerService Dump. + * @tc.type: FUNC + * @tc.require: I9RYLE + */ +HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1) +{ + WS_HILOGI("====== WorkSchedulerServiceTest.Dump_007 begin ====== "); + std::vector argsInStr; + std::string result; + argsInStr.push_back("-x"); + argsInStr.push_back("1"); + argsInStr.push_back("1"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), false); + + argsInStr.clear(); + result.clear(); + argsInStr.push_back("-x"); + argsInStr.push_back("1"); + argsInStr.push_back("p"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), false); + + argsInStr.clear(); + result.clear(); + argsInStr.push_back("-x"); + argsInStr.push_back("1"); + argsInStr.push_back("r"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), false); + + argsInStr.clear(); + result.clear(); + argsInStr.push_back("-cpu"); + argsInStr.push_back("1"); + workSchedulerService_->DumpProcess(argsInStr, result); + WS_HILOGI("%{public}s", result.c_str()); + EXPECT_EQ(result.empty(), false); + WS_HILOGI("====== WorkSchedulerServiceTest.Dump_007 end ====== "); +} + HWTEST_F(WorkSchedulerServiceTest, WorkStandbyStateChangeCallbackTest_001, TestSize.Level1) { WS_HILOGI("====== WorkSchedulerServiceTest.WorkStandbyStateChangeCallbackTest_001 begin ====== "); @@ -762,5 +811,119 @@ HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) workSchedulerService_->saMap_.emplace(saId2, false); workSchedulerService_->LoadSa(); } + +/** + * @tc.name: CheckExtensionInfos_001 + * @tc.desc: Test WorkSchedulerService CheckExtensionInfos. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) +{ + int32_t uid =1; + WorkInfo workInfo = WorkInfo(); + workInfo.SetWorkId(1); + workInfo.SetElement("bundleName", "abilityName"); + bool ret = workSchedulerService_->CheckExtensionInfos(workInfo, uid); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: InitBgTaskSubscriber_001 + * @tc.desc: Test WorkSchedulerService InitBgTaskSubscriber. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, InitBgTaskSubscriber_001, TestSize.Level1) +{ + bool ret = workSchedulerService_->InitBgTaskSubscriber_001(workInfo, uid); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: AllowDump_001 + * @tc.desc: Test WorkSchedulerService AllowDump. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, AllowDump_001, TestSize.Level1) +{ + bool ret = workSchedulerService_->AllowDump(); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: UpdateWorkBeforeRealStart_001 + * @tc.desc: Test WorkSchedulerService UpdateWorkBeforeRealStart. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, UpdateWorkBeforeRealStart_001, TestSize.Level1) +{ + std::shared_ptr workStatus = nullptr; + workSchedulerService_->UpdateWorkBeforeRealStart(workStatus); + + WorkInfo workInfo = WorkInfo(); + workStatus = std::make_shared(workInfo, 1); + workStatus->conditionMap_.clear(); + workSchedulerService_->UpdateWorkBeforeRealStart(workStatus); + + std::shared_ptr repeatCycle = std::make_shared(); + repeatCycle->boolVal = true; + workStatus->conditionMap_.emplace(WorkCondition::Type::TIMER, repeatCycle); + workSchedulerService_->UpdateWorkBeforeRealStart(workStatus); +} + +/** + * @tc.name: CheckEffiResApplyInfo_001 + * @tc.desc: Test WorkSchedulerService CheckEffiResApplyInfo. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, CheckEffiResApplyInfo_001, TestSize.Level1) +{ + bool ret = workSchedulerService_->CheckEffiResApplyInfo(1); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: PauseRunningWorks_001 + * @tc.desc: Test WorkSchedulerService PauseRunningWorks. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, PauseRunningWorks_001, TestSize.Level1) +{ + workSchedulerService_->TriggerWorkIfConditionReady(); + workSchedulerService_->PauseRunningWorks(1); + workSchedulerService_->ResumePausedWorks(1); +} + +/** + * @tc.name: OnAddSystemAbility_001 + * @tc.desc: Test WorkSchedulerService OnAddSystemAbility. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, OnAddSystemAbility_001, TestSize.Level1) +{ + workSchedulerService_->OnAddSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); + workSchedulerService_->OnRemoveSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); + + workSchedulerService_->OnAddSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID); + workSchedulerService_->OnRemoveSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID); +} + +/** + * @tc.name: IsDebugApp_001 + * @tc.desc: Test WorkSchedulerService IsDebugApp. + * @tc.type: FUNC + * @tc.require: I9TL53 + */ +HWTEST_F(WorkSchedulerServiceTest, IsDebugApp_001, TestSize.Level1) +{ + bool ret = workSchedulerService_->IsDebugApp("bundleName"); + EXPECT_FALSE(ret); +} } } \ No newline at end of file -- Gitee From 7690005a55596eaca0e298695155007879b676ef Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 13 Aug 2024 20:41:07 +0800 Subject: [PATCH 25/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- .../src/conditions/network_listener_test.cpp | 16 +++++------ services/test/src/work_status_test.cpp | 28 +++++++++---------- .../test/src/workschedulerservice_test.cpp | 18 ++++++------ 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/services/test/src/conditions/network_listener_test.cpp b/services/test/src/conditions/network_listener_test.cpp index d8916ea..975b3c3 100644 --- a/services/test/src/conditions/network_listener_test.cpp +++ b/services/test/src/conditions/network_listener_test.cpp @@ -60,7 +60,7 @@ void NetworkListenerTest::SetUpTestCase() * @tc.name: OnConditionChanged_001 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_001, TestSize.Level1) { @@ -75,7 +75,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_001, TestSize.Level1) * @tc.name: OnConditionChanged_002 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_002, TestSize.Level1) { @@ -96,7 +96,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_002, TestSize.Level1) * @tc.name: OnConditionChanged_003 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_003, TestSize.Level1) { @@ -117,7 +117,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_003, TestSize.Level1) * @tc.name: OnConditionChanged_004 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_004, TestSize.Level1) { @@ -138,7 +138,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_004, TestSize.Level1) * @tc.name: OnConditionChanged_005 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_005, TestSize.Level1) { @@ -159,7 +159,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_005, TestSize.Level1) * @tc.name: OnConditionChanged_006 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_006, TestSize.Level1) { @@ -180,7 +180,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_006, TestSize.Level1) * @tc.name: OnConditionChanged_007 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_007, TestSize.Level1) { @@ -201,7 +201,7 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_007, TestSize.Level1) * @tc.name: OnConditionChanged_008 * @tc.desc: Test etworkListener OnConditionChanged. * @tc.type: FUNC - * @tc.require: I974IQ + * @tc.require: IAJSVG */ HWTEST_F(ScreenListenerTest, OnConditionChanged_008, TestSize.Level1) { diff --git a/services/test/src/work_status_test.cpp b/services/test/src/work_status_test.cpp index cf79021..e23df8f 100644 --- a/services/test/src/work_status_test.cpp +++ b/services/test/src/work_status_test.cpp @@ -501,7 +501,7 @@ HWTEST_F(WorkStatusTest, isRepeating_001, TestSize.Level1) * @tc.name: IsReadyStatus_001 * @tc.desc: Test WorkStatus IsReadyStatus. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, IsReadyStatus_001, TestSize.Level1) { @@ -514,7 +514,7 @@ HWTEST_F(WorkStatusTest, IsReadyStatus_001, TestSize.Level1) * @tc.name: IsRemoved_001 * @tc.desc: Test WorkStatus IsRemoved. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, IsRemoved_001, TestSize.Level1) { @@ -528,7 +528,7 @@ HWTEST_F(WorkStatusTest, IsRemoved_001, TestSize.Level1) * @tc.name: NeedRemove_001 * @tc.desc: Test WorkStatus NeedRemove. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, NeedRemove_001, TestSize.Level1) { @@ -541,7 +541,7 @@ HWTEST_F(WorkStatusTest, NeedRemove_001, TestSize.Level1) * @tc.name: NeedRemove_002 * @tc.desc: Test WorkStatus NeedRemove. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, NeedRemove_002, TestSize.Level1) { @@ -557,7 +557,7 @@ HWTEST_F(WorkStatusTest, NeedRemove_002, TestSize.Level1) * @tc.name: NeedRemove_003 * @tc.desc: Test WorkStatus NeedRemove. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, NeedRemove_003, TestSize.Level1) { @@ -574,7 +574,7 @@ HWTEST_F(WorkStatusTest, NeedRemove_003, TestSize.Level1) * @tc.name: NeedRemove_004 * @tc.desc: Test WorkStatus NeedRemove. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, NeedRemove_004, TestSize.Level1) { @@ -591,7 +591,7 @@ HWTEST_F(WorkStatusTest, NeedRemove_004, TestSize.Level1) * @tc.name: UpdateTimerIfNeed_001 * @tc.desc: Test WorkStatus UpdateTimerIfNeed. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, UpdateTimerIfNeed_001, TestSize.Level1) { @@ -608,7 +608,7 @@ HWTEST_F(WorkStatusTest, UpdateTimerIfNeed_001, TestSize.Level1) * @tc.name: UpdateTimerIfNeed_002 * @tc.desc: Test WorkStatus UpdateTimerIfNeed. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, UpdateTimerIfNeed_002, TestSize.Level1) { @@ -626,7 +626,7 @@ HWTEST_F(WorkStatusTest, UpdateTimerIfNeed_002, TestSize.Level1) * @tc.name: MarkTimeout_001 * @tc.desc: Test WorkStatus MarkTimeout. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, MarkTimeout_001, TestSize.Level1) { @@ -639,7 +639,7 @@ HWTEST_F(WorkStatusTest, MarkTimeout_001, TestSize.Level1) * @tc.name: IsNapReady_001 * @tc.desc: Test WorkStatus IsNapReady. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, IsNapReady_001, TestSize.Level1) { @@ -661,7 +661,7 @@ HWTEST_F(WorkStatusTest, IsNapReady_001, TestSize.Level1) * @tc.name: IsNapReady_002 * @tc.desc: Test WorkStatus IsNapReady. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, IsNapReady_002, TestSize.Level1) { @@ -683,7 +683,7 @@ HWTEST_F(WorkStatusTest, IsNapReady_002, TestSize.Level1) * @tc.name: UpdateUidLastTimeMap_001 * @tc.desc: Test WorkStatus UpdateUidLastTimeMap. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, UpdateUidLastTimeMap_001, TestSize.Level1) { @@ -696,14 +696,12 @@ HWTEST_F(WorkStatusTest, UpdateUidLastTimeMap_001, TestSize.Level1) * @tc.name: GetStatus_001 * @tc.desc: Test WorkStatus GetStatus. * @tc.type: FUNC - * @tc.require: I95QHG + * @tc.require: IAJSVG */ HWTEST_F(WorkStatusTest, GetStatus_001, TestSize.Level1) { workStatus_->MarkStatus(WorkStatus::Status::RUNNING); EXPECT_EQ(workStatus_->GetStatus(), WorkStatus::Status::RUNNING); } - - } } \ No newline at end of file diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index faa76ba..bec29d6 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -540,7 +540,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) * @tc.name: Dump_007 * @tc.desc: Test WorkSchedulerService Dump. * @tc.type: FUNC - * @tc.require: I9RYLE + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1) { @@ -816,7 +816,7 @@ HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) * @tc.name: CheckExtensionInfos_001 * @tc.desc: Test WorkSchedulerService CheckExtensionInfos. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) { @@ -832,7 +832,7 @@ HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) * @tc.name: InitBgTaskSubscriber_001 * @tc.desc: Test WorkSchedulerService InitBgTaskSubscriber. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, InitBgTaskSubscriber_001, TestSize.Level1) { @@ -844,7 +844,7 @@ HWTEST_F(WorkSchedulerServiceTest, InitBgTaskSubscriber_001, TestSize.Level1) * @tc.name: AllowDump_001 * @tc.desc: Test WorkSchedulerService AllowDump. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, AllowDump_001, TestSize.Level1) { @@ -856,7 +856,7 @@ HWTEST_F(WorkSchedulerServiceTest, AllowDump_001, TestSize.Level1) * @tc.name: UpdateWorkBeforeRealStart_001 * @tc.desc: Test WorkSchedulerService UpdateWorkBeforeRealStart. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, UpdateWorkBeforeRealStart_001, TestSize.Level1) { @@ -878,7 +878,7 @@ HWTEST_F(WorkSchedulerServiceTest, UpdateWorkBeforeRealStart_001, TestSize.Level * @tc.name: CheckEffiResApplyInfo_001 * @tc.desc: Test WorkSchedulerService CheckEffiResApplyInfo. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, CheckEffiResApplyInfo_001, TestSize.Level1) { @@ -890,7 +890,7 @@ HWTEST_F(WorkSchedulerServiceTest, CheckEffiResApplyInfo_001, TestSize.Level1) * @tc.name: PauseRunningWorks_001 * @tc.desc: Test WorkSchedulerService PauseRunningWorks. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, PauseRunningWorks_001, TestSize.Level1) { @@ -903,7 +903,7 @@ HWTEST_F(WorkSchedulerServiceTest, PauseRunningWorks_001, TestSize.Level1) * @tc.name: OnAddSystemAbility_001 * @tc.desc: Test WorkSchedulerService OnAddSystemAbility. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, OnAddSystemAbility_001, TestSize.Level1) { @@ -918,7 +918,7 @@ HWTEST_F(WorkSchedulerServiceTest, OnAddSystemAbility_001, TestSize.Level1) * @tc.name: IsDebugApp_001 * @tc.desc: Test WorkSchedulerService IsDebugApp. * @tc.type: FUNC - * @tc.require: I9TL53 + * @tc.require: IAJSVG */ HWTEST_F(WorkSchedulerServiceTest, IsDebugApp_001, TestSize.Level1) { -- Gitee From fd82ae941f04a2ff0af3054639269016dbf194d2 Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 13 Aug 2024 21:53:00 +0800 Subject: [PATCH 26/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- .../src/conditions/network_listener_test.cpp | 92 +++++++++---------- .../test/src/workschedulerservice_test.cpp | 16 ++-- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/services/test/src/conditions/network_listener_test.cpp b/services/test/src/conditions/network_listener_test.cpp index 975b3c3..0d92092 100644 --- a/services/test/src/conditions/network_listener_test.cpp +++ b/services/test/src/conditions/network_listener_test.cpp @@ -40,46 +40,44 @@ public: static void TearDownTestCase() {}; void SetUp() {}; void TearDown() {}; - static std::shared_ptr workSchedulerService_; static std::shared_ptr workQueueManager_; - static std::shared_ptr networkListenerTest_; -} + static std::shared_ptr networkListener_; +}; -std::shared_ptr NetworkListenerTest::workSchedulerService_ = nullptr; std::shared_ptr NetworkListenerTest::workQueueManager_ = nullptr; -std::shared_ptr NetworkListenerTest::networkListenerTest_ = nullptr; +std::shared_ptr NetworkListenerTest::networkListener_ = nullptr; void NetworkListenerTest::SetUpTestCase() { - workSchedulerService_ = std::make_shared(); + std::shared_ptr workSchedulerService_ = std::make_shared(); workQueueManager_ = std::make_shared(workSchedulerService_); - networkListenerTest_ = std::make_shared(workQueueManager_, workSchedulerService_); + networkListener_ = std::make_shared(workQueueManager_); } /** * @tc.name: OnConditionChanged_001 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_001, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_001, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_002 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_002, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_002, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); @@ -87,20 +85,20 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_002, TestSize.Level1) data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_003 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_003, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_003, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); @@ -108,20 +106,20 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_003, TestSize.Level1) data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_004 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_004, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_004, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); @@ -129,20 +127,20 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_004, TestSize.Level1) data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_005 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_005, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_005, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); @@ -150,20 +148,20 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_005, TestSize.Level1) data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_006 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_006, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_006, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); @@ -171,20 +169,20 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_006, TestSize.Level1) data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_007 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_007, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_007, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); @@ -192,28 +190,28 @@ HWTEST_F(ScreenListenerTest, OnConditionChanged_007, TestSize.Level1) data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } /** * @tc.name: OnConditionChanged_008 - * @tc.desc: Test etworkListener OnConditionChanged. + * @tc.desc: Test networkListener OnConditionChanged. * @tc.type: FUNC * @tc.require: IAJSVG */ -HWTEST_F(ScreenListenerTest, OnConditionChanged_008, TestSize.Level1) +HWTEST_F(NetworkListenerTest, OnConditionChanged_008, TestSize.Level1) { - networkListenerTest_->Start(); + networkListener_->Start(); EventFwk::CommonEventData data; EventFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE); data.SetWant(want); data.SetCode(NetManagerStandard::NetConnState::NET_CONN_STATE_CONNECTED); EventFwk::CommonEventManager::PublishCommonEvent(data); - networkListenerTest_->commonEventSubscriber->OnReceiveEvent(data); - bool ret = networkListenerTest_->Stop(); + networkListener_->commonEventSubscriber->OnReceiveEvent(data); + bool ret = networkListener_->Stop(); EXPECT_TRUE(ret); } } diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index bec29d6..a3dfccd 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -91,9 +91,6 @@ void OHOS::RefBase::DecStrongRef(void const* obj) {} using namespace testing::ext; namespace OHOS { namespace WorkScheduler { -const int32_t DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID = 1914; -const int32_t DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID = 1907; - class WorkSchedulerServiceTest : public testing::Test { public: static void SetUpTestCase() {} @@ -836,7 +833,7 @@ HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) */ HWTEST_F(WorkSchedulerServiceTest, InitBgTaskSubscriber_001, TestSize.Level1) { - bool ret = workSchedulerService_->InitBgTaskSubscriber_001(workInfo, uid); + bool ret = workSchedulerService_->InitBgTaskSubscriber(workInfo, uid); EXPECT_TRUE(ret); } @@ -907,11 +904,14 @@ HWTEST_F(WorkSchedulerServiceTest, PauseRunningWorks_001, TestSize.Level1) */ HWTEST_F(WorkSchedulerServiceTest, OnAddSystemAbility_001, TestSize.Level1) { - workSchedulerService_->OnAddSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); - workSchedulerService_->OnRemoveSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); + std::string deviceId; + int32_t DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID = 1914; + int32_t DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID = 1907; + workSchedulerService_->OnAddSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, deviceId); + workSchedulerService_->OnRemoveSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, deviceId); - workSchedulerService_->OnAddSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID); - workSchedulerService_->OnRemoveSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID); + workSchedulerService_->OnAddSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID, deviceId); + workSchedulerService_->OnRemoveSystemAbility(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID, deviceId); } /** -- Gitee From 05a1a8171b0b3c336c2d4ae2ce84e5852b29676e Mon Sep 17 00:00:00 2001 From: anchi Date: Tue, 13 Aug 2024 21:59:16 +0800 Subject: [PATCH 27/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/test/src/workschedulerservice_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index a3dfccd..a80678a 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -833,7 +833,7 @@ HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) */ HWTEST_F(WorkSchedulerServiceTest, InitBgTaskSubscriber_001, TestSize.Level1) { - bool ret = workSchedulerService_->InitBgTaskSubscriber(workInfo, uid); + bool ret = workSchedulerService_->InitBgTaskSubscriber(); EXPECT_TRUE(ret); } -- Gitee From a6f8299d39dee1159c7d4605aeb0fb2e8629401f Mon Sep 17 00:00:00 2001 From: anchi Date: Wed, 14 Aug 2024 10:50:28 +0800 Subject: [PATCH 28/63] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- frameworks/src/work_info.cpp | 1 + services/test/src/workschedulerservice_test.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index 3acdc16..9a32538 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -32,6 +32,7 @@ WorkInfo::WorkInfo() appIndex_ = APPINDEX_INIT_VALUE; extension_ = true; saId_ = INVALID_VALUE; + residentSa_ = false; } WorkInfo::~WorkInfo() {} diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index a80678a..d034cb4 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -817,7 +817,7 @@ HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) */ HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) { - int32_t uid =1; + int32_t uid = 1; WorkInfo workInfo = WorkInfo(); workInfo.SetWorkId(1); workInfo.SetElement("bundleName", "abilityName"); -- Gitee From b4197c794331234f2171071b53d1e5a97f9ccbb7 Mon Sep 17 00:00:00 2001 From: anchi Date: Wed, 14 Aug 2024 10:55:09 +0800 Subject: [PATCH 29/63] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/test/src/workschedulerservice_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index d034cb4..ee28067 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -813,7 +813,7 @@ HWTEST_F(WorkSchedulerServiceTest, LoadSa_001, TestSize.Level1) * @tc.name: CheckExtensionInfos_001 * @tc.desc: Test WorkSchedulerService CheckExtensionInfos. * @tc.type: FUNC - * @tc.require: IAJSVG + * @tc.require: IAJVZG */ HWTEST_F(WorkSchedulerServiceTest, CheckExtensionInfos_001, TestSize.Level1) { -- Gitee From db72d78c99d0dd8363190811363be706b0b7c5fd Mon Sep 17 00:00:00 2001 From: hxf Date: Fri, 16 Aug 2024 09:11:34 +0800 Subject: [PATCH 30/63] =?UTF-8?q?GetAllRunningWorks=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9B=E7=A8=8B=E5=90=8D=E7=A7=B0=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_scheduler_service.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 138e410..c4363fb 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -779,6 +779,9 @@ int32_t WorkSchedulerService::GetAllRunningWorks(std::listGetAllRunningWorks(); return ERR_OK; } -- Gitee From 639bc7dcf1d9b90ccc5e81576b850922e664c99c Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 19 Aug 2024 14:09:26 +0800 Subject: [PATCH 31/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1Event?= =?UTF-8?q?Handler=E6=8E=A5=E5=85=A5FFRT=E6=95=B4=E6=94=B9=20Signed-off-by?= =?UTF-8?q?:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 1 + services/BUILD.gn | 2 + services/native/include/work_conn_manager.h | 3 +- services/native/include/work_policy_manager.h | 7 +-- services/native/include/work_queue.h | 3 +- services/native/include/work_queue_manager.h | 3 +- .../native/include/work_scheduler_service.h | 7 +-- services/native/include/work_status.h | 5 ++- services/native/src/work_conn_manager.cpp | 6 +-- services/native/src/work_policy_manager.cpp | 44 +++++++++---------- services/native/src/work_queue.cpp | 34 +++++++------- services/native/src/work_queue_manager.cpp | 12 ++--- .../native/src/work_scheduler_service.cpp | 28 ++++++------ services/native/src/work_status.cpp | 20 ++++----- services/test/BUILD.gn | 1 + .../src/zidl/work_scheduler_proxy_test.cpp | 5 ++- .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../workschedulerstartwork_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../workschedulerstopwork_fuzzer/BUILD.gn | 1 + .../workscheduleservice_fuzzer/BUILD.gn | 1 + .../workscheduleservice_fuzzer.cpp | 5 ++- 26 files changed, 108 insertions(+), 87 deletions(-) diff --git a/bundle.json b/bundle.json index dedd3de..ee2a1d9 100644 --- a/bundle.json +++ b/bundle.json @@ -36,6 +36,7 @@ "battery_manager", "ability_base", "eventhandler", + "ffrt", "background_task_mgr", "device_standby", "device_usage_statistics", diff --git a/services/BUILD.gn b/services/BUILD.gn index fc87564..99ac071 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -90,6 +90,7 @@ ohos_shared_library("workschedservice") { "config_policy:configpolicy_util", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", @@ -202,6 +203,7 @@ ohos_static_library("workschedservice_static") { "config_policy:configpolicy_util", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/services/native/include/work_conn_manager.h b/services/native/include/work_conn_manager.h index 0339763..cdc8cbf 100644 --- a/services/native/include/work_conn_manager.h +++ b/services/native/include/work_conn_manager.h @@ -22,6 +22,7 @@ #include "work_scheduler_connection.h" #include "work_status.h" +#include "ffrt.h" namespace OHOS { using namespace Utils; @@ -52,7 +53,7 @@ private: void WriteStartWorkEvent(std::shared_ptr workStatus); private: - std::mutex connMapMutex_; + ffrt::mutex connMapMutex_; std::map> connMap_; std::map eventIdMap_; }; diff --git a/services/native/include/work_policy_manager.h b/services/native/include/work_policy_manager.h index dc69996..a71eb3d 100644 --- a/services/native/include/work_policy_manager.h +++ b/services/native/include/work_policy_manager.h @@ -25,6 +25,7 @@ #include "work_conn_manager.h" #include "work_queue.h" #include "work_status.h" +#include "ffrt.h" namespace OHOS { namespace WorkScheduler { @@ -299,7 +300,7 @@ private: std::shared_ptr workConnManager_; std::shared_ptr handler_; - std::recursive_mutex uidMapMutex_; + ffrt::recursive_mutex uidMapMutex_; std::map> uidQueueMap_; std::shared_ptr conditionReadyQueue_; @@ -309,7 +310,7 @@ private: std::shared_ptr watchdog_; - std::mutex watchdogIdMapMutex_; + ffrt::mutex watchdogIdMapMutex_; std::map> watchdogIdMap_; uint32_t watchdogId_; @@ -318,7 +319,7 @@ private: int32_t dumpSetCpu_; int32_t dumpSetMaxRunningCount_; - std::recursive_mutex ideDebugListMutex_; + ffrt::recursive_mutex ideDebugListMutex_; std::list> ideDebugList; }; } // namespace WorkScheduler diff --git a/services/native/include/work_queue.h b/services/native/include/work_queue.h index da7cb9d..a6a6309 100644 --- a/services/native/include/work_queue.h +++ b/services/native/include/work_queue.h @@ -20,6 +20,7 @@ #include "work_status.h" #include "detector_value.h" +#include "ffrt.h" namespace OHOS { namespace WorkScheduler { @@ -144,7 +145,7 @@ public: */ void SetMinIntervalByDump(int64_t interval); private: - std::recursive_mutex workListMutex_; + ffrt::recursive_mutex workListMutex_; std::list> workList_; }; class WorkComp { diff --git a/services/native/include/work_queue_manager.h b/services/native/include/work_queue_manager.h index b4857ef..200e803 100644 --- a/services/native/include/work_queue_manager.h +++ b/services/native/include/work_queue_manager.h @@ -23,6 +23,7 @@ #include "conditions/icondition_listener.h" #include "work_queue.h" #include "work_status.h" +#include "ffrt.h" namespace OHOS { namespace WorkScheduler { @@ -121,7 +122,7 @@ private: std::shared_ptr conditionVal); private: - std::mutex mutex_; + ffrt::mutex mutex_; const std::weak_ptr wss_; std::map> queueMap_; std::map> listenerMap_; diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index 8cceb08..4f7a37e 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -34,6 +34,7 @@ #include "work_event_handler.h" #include "singleton.h" #include "work_standby_state_change_callback.h" +#include "ffrt.h" namespace OHOS { namespace WorkScheduler { @@ -335,15 +336,15 @@ private: private: std::set whitelist_; - std::mutex whitelistMutex_; + ffrt::mutex whitelistMutex_; std::map saMap_; #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE std::shared_ptr subscriber_; #endif std::shared_ptr workQueueManager_; std::shared_ptr workPolicyManager_; - std::mutex mutex_; - std::mutex observerMutex_; + ffrt::mutex mutex_; + ffrt::mutex observerMutex_; std::map> persistedMap_; bool ready_ {false}; std::atomic deepIdle_ {false}; diff --git a/services/native/include/work_status.h b/services/native/include/work_status.h index ecead0a..023ebe8 100644 --- a/services/native/include/work_status.h +++ b/services/native/include/work_status.h @@ -23,6 +23,7 @@ #include "timer.h" #include "work_info.h" +#include "ffrt.h" namespace OHOS { namespace WorkScheduler { @@ -174,8 +175,8 @@ private: int64_t minInterval_; bool callbackFlag_; bool isStandby_ {false}; - std::mutex conditionMapMutex_; - static std::mutex s_uid_last_time_mutex; + ffrt::mutex conditionMapMutex_; + static ffrt::mutex s_uid_last_time_mutex; static std::map s_uid_last_time_map; void MarkTimeout(); bool IsSameUser(); diff --git a/services/native/src/work_conn_manager.cpp b/services/native/src/work_conn_manager.cpp index 968548b..7480988 100644 --- a/services/native/src/work_conn_manager.cpp +++ b/services/native/src/work_conn_manager.cpp @@ -41,19 +41,19 @@ const std::string PARAM_APP_CLONE_INDEX_KEY = "ohos.extra.param.key.appCloneInde void WorkConnManager::AddConnInfo(string &workId, sptr &connection) { - std::lock_guard lock(connMapMutex_); + std::lock_guard lock(connMapMutex_); connMap_.emplace(workId, connection); } void WorkConnManager::RemoveConnInfo(string &workId) { - std::lock_guard lock(connMapMutex_); + std::lock_guard lock(connMapMutex_); connMap_.erase(workId); } sptr WorkConnManager::GetConnInfo(string &workId) { - std::lock_guard lock(connMapMutex_); + std::lock_guard lock(connMapMutex_); if (connMap_.count(workId) > 0) { return connMap_.at(workId); } diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 45b91de..287e868 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -129,7 +129,7 @@ std::string WorkPolicyManager::GetConditionString(const shared_ptr w int32_t WorkPolicyManager::AddWork(shared_ptr workStatus, int32_t uid) { WS_HILOGD("Add work"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); if (uidQueueMap_.count(uid) > 0) { if (uidQueueMap_.at(uid)->Contains(make_shared(workStatus->workId_))) { WS_HILOGD("Workid has been added, should remove first."); @@ -165,7 +165,7 @@ bool WorkPolicyManager::RemoveWork(shared_ptr workStatus, int32_t ui { WS_HILOGD("Remove work."); bool ret = false; - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); if (uidQueueMap_.count(uid) > 0) { WS_HILOGD("Remove workStatus ID: %{public}s form uidQueue(%{public}d)", workStatus->workId_.c_str(), uid); ret = uidQueueMap_.at(uid)->Remove(workStatus); @@ -179,7 +179,7 @@ bool WorkPolicyManager::RemoveWork(shared_ptr workStatus, int32_t ui shared_ptr WorkPolicyManager::FindWorkStatus(WorkInfo& workInfo, int32_t uid) { WS_HILOGD("Find work status start."); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); if (uidQueueMap_.count(uid) > 0) { return uidQueueMap_.at(uid)->Find(WorkStatus::MakeWorkId(workInfo.GetWorkId(), uid)); } @@ -188,7 +188,7 @@ shared_ptr WorkPolicyManager::FindWorkStatus(WorkInfo& workInfo, int void WorkPolicyManager::RemoveFromUidQueue(std::shared_ptr workStatus, int32_t uid) { - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); if (uidQueueMap_.count(uid) > 0) { uidQueueMap_.at(uid)->CancelWork(workStatus); if (uidQueueMap_.at(uid)->GetSize() <= 0) { @@ -237,7 +237,7 @@ bool WorkPolicyManager::StopWork(std::shared_ptr workStatus, int32_t bool WorkPolicyManager::StopAndClearWorks(int32_t uid) { WS_HILOGD("enter"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); if (uidQueueMap_.count(uid) > 0) { auto queue = uidQueueMap_.at(uid); for (auto it : queue->GetWorkList()) { @@ -254,7 +254,7 @@ bool WorkPolicyManager::StopAndClearWorks(int32_t uid) int32_t WorkPolicyManager::IsLastWorkTimeout(int32_t workId, int32_t uid, bool &result) { - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); string workIdStr = WorkStatus::MakeWorkId(workId, uid); if (uidQueueMap_.count(uid) > 0) { shared_ptr workStatus = uidQueueMap_.at(uid)->Find(workIdStr); @@ -300,7 +300,7 @@ int32_t WorkPolicyManager::GetMaxRunningCount(std::string& policyName) int32_t WorkPolicyManager::GetRunningCount() { WS_HILOGD("enter"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); int32_t count = 0; auto it = uidQueueMap_.begin(); while (it != uidQueueMap_.end()) { @@ -455,7 +455,7 @@ void WorkPolicyManager::AddWatchdogForWork(std::shared_ptr workStatu watchdog_->AddWatchdog(watchId, watchdogTime_); workStatus->workStartTime_ = WorkSchedUtils::GetCurrentTimeMs(); workStatus->workWatchDogTime_ = static_cast(watchdogTime_); - std::lock_guard lock(watchdogIdMapMutex_); + std::lock_guard lock(watchdogIdMapMutex_); watchdogIdMap_.emplace(watchId, workStatus); } @@ -483,20 +483,20 @@ void WorkPolicyManager::WatchdogTimeOut(uint32_t watchdogId) WS_HILOGI("WatchdogTimeOut, watchId:%{public}u, bundleName:%{public}s, workId:%{public}s", watchdogId, workStatus->bundleName_.c_str(), workStatus->workId_.c_str()); wss_.lock()->WatchdogTimeOut(workStatus); - std::lock_guard lock(watchdogIdMapMutex_); + std::lock_guard lock(watchdogIdMapMutex_); watchdogIdMap_.erase(watchdogId); } std::shared_ptr WorkPolicyManager::GetWorkFromWatchdog(uint32_t id) { - std::lock_guard lock(watchdogIdMapMutex_); + std::lock_guard lock(watchdogIdMapMutex_); return watchdogIdMap_.count(id) > 0 ? watchdogIdMap_.at(id) : nullptr; } list> WorkPolicyManager::ObtainAllWorks(int32_t &uid) { WS_HILOGD("Wenter"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); list> allWorks; if (uidQueueMap_.count(uid) > 0) { auto queue = uidQueueMap_.at(uid); @@ -510,7 +510,7 @@ list> WorkPolicyManager::ObtainAllWorks(int32_t &uid) shared_ptr WorkPolicyManager::GetWorkStatus(int32_t &uid, int32_t &workId) { WS_HILOGD("enter"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); if (uidQueueMap_.count(uid) > 0) { auto queue = uidQueueMap_.at(uid); auto workStatus = queue->Find(string("u") + to_string(uid) + "_" + to_string(workId)); @@ -524,7 +524,7 @@ shared_ptr WorkPolicyManager::GetWorkStatus(int32_t &uid, int32_t &wor list> WorkPolicyManager::GetAllWorkStatus(int32_t &uid) { WS_HILOGD("enter"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); list> allWorks; if (uidQueueMap_.count(uid) > 0) { allWorks = uidQueueMap_.at(uid)->GetWorkList(); @@ -535,7 +535,7 @@ list> WorkPolicyManager::GetAllWorkStatus(int32_t &u std::list> WorkPolicyManager::GetAllRunningWorks() { WS_HILOGD("enter"); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); list> allWorks; auto it = uidQueueMap_.begin(); while (it != uidQueueMap_.end()) { @@ -553,7 +553,7 @@ void WorkPolicyManager::DumpConditionReadyQueue(string& result) void WorkPolicyManager::DumpUidQueueMap(string& result) { - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); for (auto it : uidQueueMap_) { result.append("uid: " + std::to_string(it.first) + ":\n"); it.second->Dump(result); @@ -633,7 +633,7 @@ int32_t WorkPolicyManager::WorkPolicyManager::GetWatchdogTime() void WorkPolicyManager::DumpCheckIdeWorkToRun(const std::string &bundleName, const std::string &abilityName) { - std::lock_guard lock(ideDebugListMutex_); + std::lock_guard lock(ideDebugListMutex_); ideDebugList = GetAllIdeWorkStatus(bundleName, abilityName); if (ideDebugList.empty()) { WS_HILOGE("ideDebugList is empty, please add one work"); @@ -644,7 +644,7 @@ void WorkPolicyManager::DumpCheckIdeWorkToRun(const std::string &bundleName, con void WorkPolicyManager::TriggerIdeWork() { - std::lock_guard lock(ideDebugListMutex_); + std::lock_guard lock(ideDebugListMutex_); if (ideDebugList.empty()) { WS_HILOGI("ideDebugList has been empty, all the works have been done"); return; @@ -685,7 +685,7 @@ std::list> WorkPolicyManager::GetAllIdeWorkStatus(co const std::string &abilityName) { int32_t currentAccountId = WorkSchedUtils::GetCurrentAccountId(); - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); std::list> allWorks; auto it = uidQueueMap_.begin(); while (it != uidQueueMap_.end()) { @@ -710,7 +710,7 @@ int32_t WorkPolicyManager::PauseRunningWorks(int32_t uid) { WS_HILOGI("Pause Running Work Scheduler Work, uid:%{public}d", uid); bool hasWorkWithUid = false; - std::lock_guard lock(watchdogIdMapMutex_); + std::lock_guard lock(watchdogIdMapMutex_); for (auto it = watchdogIdMap_.begin(); it != watchdogIdMap_.end(); it++) { auto workStatus = it->second; if (workStatus->uid_ == uid && workStatus->IsRunning() && !workStatus->IsPaused()) { @@ -747,7 +747,7 @@ int32_t WorkPolicyManager::ResumePausedWorks(int32_t uid) { WS_HILOGI("Resume Paused Work Scheduler Work, uid:%{public}d", uid); bool hasWorkWithUid = false; - std::lock_guard lock(watchdogIdMapMutex_); + std::lock_guard lock(watchdogIdMapMutex_); for (auto it = watchdogIdMap_.begin(); it != watchdogIdMap_.end(); it++) { auto workStatus = it->second; if (workStatus->uid_ == uid && workStatus->IsRunning() && workStatus->IsPaused()) { @@ -776,7 +776,7 @@ void WorkPolicyManager::RemoveWatchDog(std::shared_ptr workStatus) return; } - std::lock_guard lock(watchdogIdMapMutex_); + std::lock_guard lock(watchdogIdMapMutex_); uint32_t watchdogId = UINT32_MAX; for (auto it = watchdogIdMap_.begin(); it != watchdogIdMap_.end(); it++) { if (workStatus->workId_ == it->second->workId_) { @@ -793,7 +793,7 @@ void WorkPolicyManager::RemoveWatchDog(std::shared_ptr workStatus) std::list> WorkPolicyManager::GetDeepIdleWorks() { std::list> deepIdleWorkds; - std::lock_guard lock(uidMapMutex_); + std::lock_guard lock(uidMapMutex_); auto it = uidQueueMap_.begin(); while (it != uidQueueMap_.end()) { std::list> workList = it->second->GetDeepIdleWorks(); diff --git a/services/native/src/work_queue.cpp b/services/native/src/work_queue.cpp index b72ac68..bcfe460 100644 --- a/services/native/src/work_queue.cpp +++ b/services/native/src/work_queue.cpp @@ -30,7 +30,7 @@ vector> WorkQueue::OnConditionChanged(WorkCondition::Type shared_ptr value = ParseCondition(type, conditionVal); vector> result; std::set uidList; - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); workList_.sort(WorkComp()); for (auto it : workList_) { if (it->OnConditionChanged(type, value) == E_GROUP_CHANGE_NOT_MATCH_HAP) { @@ -103,13 +103,13 @@ void WorkQueue::Push(shared_ptr>> workStatusVector for (auto it : *workStatusVector) { Push(it); } - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); workList_.sort(WorkComp()); } void WorkQueue::Push(shared_ptr workStatus) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); if (this->Contains(make_shared(workStatus->workId_))) { for (auto it : workList_) { if (it->workId_.compare(workStatus->workId_) == 0) { @@ -123,7 +123,7 @@ void WorkQueue::Push(shared_ptr workStatus) bool WorkQueue::Remove(shared_ptr workStatus) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); auto iter = std::find(workList_.cbegin(), workList_.cend(), workStatus); if (iter != workList_.end()) { workList_.remove(*iter); @@ -138,7 +138,7 @@ uint32_t WorkQueue::GetSize() bool WorkQueue::Contains(std::shared_ptr workId) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); auto iter = std::find_if(workList_.cbegin(), workList_.cend(), [&workId] (const shared_ptr &workStatus) { return workId->compare(workStatus->workId_) == 0; }); if (iter != workList_.end()) { @@ -149,7 +149,7 @@ bool WorkQueue::Contains(std::shared_ptr workId) shared_ptr WorkQueue::Find(string workId) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); auto iter = std::find_if(workList_.cbegin(), workList_.cend(), [&workId](const shared_ptr &workStatus) { return workStatus->workId_ == workId; }); if (iter != workList_.end()) { @@ -160,7 +160,7 @@ shared_ptr WorkQueue::Find(string workId) shared_ptr WorkQueue::GetWorkToRunByPriority() { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); workList_.sort(WorkComp()); auto work = workList_.begin(); shared_ptr workStatus = nullptr; @@ -177,20 +177,20 @@ shared_ptr WorkQueue::GetWorkToRunByPriority() bool WorkQueue::CancelWork(shared_ptr workStatus) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); workList_.remove(workStatus); return true; } list> WorkQueue::GetWorkList() { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); return workList_; } void WorkQueue::RemoveUnReady() { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); workList_.remove_if([](shared_ptr value) { return (value->GetStatus() != WorkStatus::Status::CONDITION_READY); }); @@ -199,7 +199,7 @@ void WorkQueue::RemoveUnReady() int32_t WorkQueue::GetRunningCount() { int32_t count = 0; - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); for (shared_ptr work : workList_) { if (work->IsRunning()) { count++; @@ -211,7 +211,7 @@ int32_t WorkQueue::GetRunningCount() std::list> WorkQueue::GetRunningWorks() { std::list> workInfo; - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); for (shared_ptr work : workList_) { if (work->IsRunning()) { auto info = std::make_shared(); @@ -226,7 +226,7 @@ std::list> WorkQueue::GetRunningWorks() std::list> WorkQueue::GetDeepIdleWorks() { std::list> works; - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); for (shared_ptr work : workList_) { if (work->IsRunning() && work->workInfo_->GetDeepIdle() == WorkCondition::DeepIdle::DEEP_IDLE_IN) { works.emplace_back(work); @@ -237,7 +237,7 @@ std::list> WorkQueue::GetDeepIdleWorks() void WorkQueue::GetWorkIdStr(string& result) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); for (auto it : workList_) { result.append(it->workId_ + ", "); } @@ -245,7 +245,7 @@ void WorkQueue::GetWorkIdStr(string& result) void WorkQueue::Dump(string& result) { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); for (auto it : workList_) { it->Dump(result); } @@ -253,7 +253,7 @@ void WorkQueue::Dump(string& result) void WorkQueue::ClearAll() { - std::lock_guard lock(workListMutex_); + std::lock_guard lock(workListMutex_); workList_.clear(); } @@ -264,7 +264,7 @@ bool WorkComp::operator () (const shared_ptr w1, const shared_ptr lock(workListMutex_); + std::lock_guard lock(workListMutex_); for (auto it : workList_) { it->SetMinIntervalByDump(interval); } diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index b3c80b2..9ebc47f 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -39,7 +39,7 @@ bool WorkQueueManager::Init() bool WorkQueueManager::AddListener(WorkCondition::Type type, shared_ptr listener) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (listenerMap_.count(type) > 0) { return false; } @@ -53,7 +53,7 @@ bool WorkQueueManager::AddWork(shared_ptr workStatus) return false; } WS_HILOGD("workStatus ID: %{public}s", workStatus->workId_.c_str()); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto map = workStatus->workInfo_->GetConditionMap(); for (auto it : *map) { if (queueMap_.count(it.first) == 0) { @@ -73,7 +73,7 @@ bool WorkQueueManager::AddWork(shared_ptr workStatus) bool WorkQueueManager::RemoveWork(shared_ptr workStatus) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); WS_HILOGD("workStatus ID: %{public}s", workStatus->workId_.c_str()); auto map = workStatus->workInfo_->GetConditionMap(); for (auto it : *map) { @@ -89,7 +89,7 @@ bool WorkQueueManager::RemoveWork(shared_ptr workStatus) bool WorkQueueManager::CancelWork(shared_ptr workStatus) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); WS_HILOGD("workStatus ID: %{public}s", workStatus->workId_.c_str()); for (auto it : queueMap_) { it.second->CancelWork(workStatus); @@ -112,7 +112,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ shared_ptr conditionVal) { vector> result; - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (conditionType != WorkCondition::Type::GROUP && queueMap_.count(conditionType) > 0) { shared_ptr workQueue = queueMap_.at(conditionType); result = workQueue->OnConditionChanged(conditionType, conditionVal); @@ -170,7 +170,7 @@ bool WorkQueueManager::StopAndClearWorks(list> workList) void WorkQueueManager::Dump(string& result) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); string conditionType[] = {"network", "charger", "battery_status", "battery_level", "storage", "timer", "group", "deepIdle", "standby", "unknown"}; uint32_t size = sizeof(conditionType); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 03c7d30..2df2e64 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -125,7 +125,7 @@ void WorkSchedulerService::OnStart() // Init handler. if (!eventRunner_) { - eventRunner_ = AppExecFwk::EventRunner::Create(WORKSCHEDULER_SERVICE_NAME); + eventRunner_ = AppExecFwk::EventRunner::Create(WORKSCHEDULER_SERVICE_NAME, AppExecFwk::ThreadMode::FFRT); } if (eventRunner_ == nullptr) { WS_HILOGE("Init failed due to create EventRunner"); @@ -323,7 +323,7 @@ bool WorkSchedulerService::GetJsonFromFile(const char *filePath, Json::Value &ro void WorkSchedulerService::OnStop() { WS_HILOGI("stop service."); - std::lock_guard observerLock(observerMutex_); + std::lock_guard observerLock(observerMutex_); #ifdef DEVICE_USAGE_STATISTICS_ENABLE DeviceUsageStats::BundleActiveClient::GetInstance().UnRegisterAppGroupCallBack(groupObserver_); groupObserver_ = nullptr; @@ -397,7 +397,7 @@ ErrCode WorkSchedulerService::QueryResAppliedUid() WS_HILOGE("failed to GetEfficiencyResourcesInfos, errcode: %{public}d", result); return result; } - std::lock_guard lock(whitelistMutex_); + std::lock_guard lock(whitelistMutex_); for (const auto& info : appList) { if ((info->GetResourceNumber() & BackgroundTaskMgr::ResourceType::WORK_SCHEDULER) != 0) { whitelist_.emplace(info->GetUid()); @@ -622,7 +622,7 @@ int32_t WorkSchedulerService::StartWork(WorkInfo& workInfo) if (ret == ERR_OK) { workQueueManager_->AddWork(workStatus); if (workInfo.IsPersisted()) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); workStatus->workInfo_->RefreshUid(uid); persistedMap_.emplace(workStatus->workId_, workStatus->workInfo_); RefreshPersistedWorks(); @@ -686,7 +686,7 @@ int32_t WorkSchedulerService::StopAndCancelWork(WorkInfo& workInfo) } StopWorkInner(workStatus, uid, true, false); if (workStatus->persisted_) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); persistedMap_.erase(workStatus->workId_); RefreshPersistedWorks(); } @@ -728,7 +728,7 @@ bool WorkSchedulerService::StopAndClearWorksByUid(int32_t uid) bool ret = workQueueManager_->StopAndClearWorks(allWorks) && workPolicyManager_->StopAndClearWorks(uid); if (ret) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (auto workId : workIdList) { if (persistedMap_.count(workId) != 0) { persistedMap_.erase(workId); @@ -993,7 +993,7 @@ void WorkSchedulerService::DumpRunningWorks(const std::string &uidStr, const std std::string WorkSchedulerService::GetEffiResApplyUid() { - std::lock_guard lock(whitelistMutex_); + std::lock_guard lock(whitelistMutex_); if (whitelist_.empty()) { return "empty"; } @@ -1110,7 +1110,7 @@ int32_t WorkSchedulerService::CreateNodeFile(std::string filePath) void WorkSchedulerService::UpdateEffiResApplyInfo(int32_t uid, bool isAdd) { - std::lock_guard lock(whitelistMutex_); + std::lock_guard lock(whitelistMutex_); if (isAdd) { whitelist_.emplace(uid); } else { @@ -1120,7 +1120,7 @@ void WorkSchedulerService::UpdateEffiResApplyInfo(int32_t uid, bool isAdd) bool WorkSchedulerService::CheckEffiResApplyInfo(int32_t uid) { - std::lock_guard lock(whitelistMutex_); + std::lock_guard lock(whitelistMutex_); return whitelist_.find(uid) != whitelist_.end(); } @@ -1128,7 +1128,7 @@ bool WorkSchedulerService::CheckStandbyApplyInfo(std::string& bundleName) { WS_HILOGD("%{public}s is checking standby applyInfo", bundleName.c_str()); #ifdef DEVICE_STANDBY_ENABLE - std::lock_guard observerLock(observerMutex_); + std::lock_guard observerLock(observerMutex_); if (!standbyStateObserver_) { return true; } @@ -1166,12 +1166,12 @@ void WorkSchedulerService::OnRemoveSystemAbility(int32_t systemAbilityId, const workQueueManager_->OnConditionChanged(WorkCondition::Type::STANDBY, std::make_shared(0, 0, false, std::string())); #ifdef DEVICE_STANDBY_ENABLE - std::lock_guard observerLock(observerMutex_); + std::lock_guard observerLock(observerMutex_); standbyStateObserver_ = nullptr; #endif } else if (systemAbilityId == DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID) { #ifdef DEVICE_USAGE_STATISTICS_ENABLE - std::lock_guard observerLock(observerMutex_); + std::lock_guard observerLock(observerMutex_); groupObserver_ = nullptr; #endif } @@ -1183,7 +1183,7 @@ __attribute__((no_sanitize("cfi"))) void WorkSchedulerService::GroupObserverInit if (!workQueueManager_) { return; } - std::lock_guard observerLock(observerMutex_); + std::lock_guard observerLock(observerMutex_); if (!groupObserver_) { groupObserver_ = new (std::nothrow) WorkBundleGroupChangeCallback(workQueueManager_); } @@ -1200,7 +1200,7 @@ void WorkSchedulerService::RegisterStandbyStateObserver() return; } #ifdef DEVICE_STANDBY_ENABLE - std::lock_guard observerLock(observerMutex_); + std::lock_guard observerLock(observerMutex_); if (standbyStateObserver_) { WS_HILOGD("standbyStateObserver_ is already exist, do not need repeat process."); return; diff --git a/services/native/src/work_status.cpp b/services/native/src/work_status.cpp index b88159a..1a3eaa7 100644 --- a/services/native/src/work_status.cpp +++ b/services/native/src/work_status.cpp @@ -40,7 +40,7 @@ const int32_t DEFAULT_PRIORITY = 10000; const int32_t HIGH_PRIORITY = 0; const int32_t ACTIVE_GROUP = 10; const string SWITCH_ON = "1"; -std::mutex WorkStatus::s_uid_last_time_mutex; +ffrt::mutex WorkStatus::s_uid_last_time_mutex; time_t getCurrentTime() { @@ -74,7 +74,7 @@ WorkStatus::WorkStatus(WorkInfo &workInfo, int32_t uid) if (!workTimerCondition->boolVal) { timeCondition->intVal = workTimerCondition->intVal; } - std::lock_guard lock(conditionMapMutex_); + std::lock_guard lock(conditionMapMutex_); conditionMap_.emplace(WorkCondition::Type::TIMER, timeCondition); } this->persisted_ = workInfo.IsPersisted(); @@ -92,7 +92,7 @@ int32_t WorkStatus::OnConditionChanged(WorkCondition::Type &type, shared_ptrGetConditionMap()->count(type) > 0 && type != WorkCondition::Type::TIMER && type != WorkCondition::Type::GROUP) { - std::lock_guard lock(conditionMapMutex_); + std::lock_guard lock(conditionMapMutex_); if (conditionMap_.count(type) > 0) { conditionMap_.at(type) = value; } else { @@ -140,7 +140,7 @@ void WorkStatus::MarkRound() {} void WorkStatus::UpdateTimerIfNeed() { - std::lock_guard lock(conditionMapMutex_); + std::lock_guard lock(conditionMapMutex_); if (conditionMap_.count(WorkCondition::Type::TIMER) > 0) { baseTime_ = getCurrentTime(); if (conditionMap_.at(WorkCondition::Type::TIMER)->boolVal) { @@ -157,7 +157,7 @@ void WorkStatus::UpdateTimerIfNeed() bool WorkStatus::NeedRemove() { - std::lock_guard lock(conditionMapMutex_); + std::lock_guard lock(conditionMapMutex_); if (conditionMap_.count(WorkCondition::Type::TIMER) <= 0) { return true; } @@ -209,7 +209,7 @@ bool WorkStatus::IsReady() return false; } auto workConditionMap = workInfo_->GetConditionMap(); - std::lock_guard lock(s_uid_last_time_mutex); + std::lock_guard lock(s_uid_last_time_mutex); for (auto it : *workConditionMap) { if (conditionMap_.count(it.first) <= 0) { return false; @@ -403,14 +403,14 @@ int64_t WorkStatus::GetMinInterval() void WorkStatus::UpdateUidLastTimeMap() { - std::lock_guard lock(s_uid_last_time_mutex); + std::lock_guard lock(s_uid_last_time_mutex); time_t lastTime = getOppositeTime(); s_uid_last_time_map[uid_] = lastTime; } void WorkStatus::ClearUidLastTimeMap(int32_t uid) { - std::lock_guard lock(s_uid_last_time_mutex); + std::lock_guard lock(s_uid_last_time_mutex); s_uid_last_time_map.erase(uid); } @@ -441,7 +441,7 @@ bool WorkStatus::IsLastWorkTimeout() bool WorkStatus::IsRepeating() { - std::lock_guard lock(conditionMapMutex_); + std::lock_guard lock(conditionMapMutex_); if (conditionMap_.count(WorkCondition::Type::TIMER) <= 0) { return false; } @@ -475,7 +475,7 @@ void WorkStatus::Dump(string& result) result.append(string("\"paused\":") + (paused_ ? "true" : "false") + ",\n"); result.append(string("\"priority\":") + to_string(priority_) + ",\n"); result.append(string("\"conditionMap\":{\n")); - std::lock_guard lock(conditionMapMutex_); + std::lock_guard lock(conditionMapMutex_); if (conditionMap_.count(WorkCondition::Type::NETWORK) > 0) { result.append(string("\"networkType\":") + to_string(conditionMap_.at(WorkCondition::Type::NETWORK)->enumVal) + ",\n"); diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index 6b1d74e..7fa1560 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -72,6 +72,7 @@ ohos_unittest("WorkScheduleServiceTest") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/services/test/src/zidl/work_scheduler_proxy_test.cpp b/services/test/src/zidl/work_scheduler_proxy_test.cpp index c2de1a2..39bfd43 100644 --- a/services/test/src/zidl/work_scheduler_proxy_test.cpp +++ b/services/test/src/zidl/work_scheduler_proxy_test.cpp @@ -20,6 +20,7 @@ #include "iservice_registry.h" #include "work_scheduler_proxy.h" #include "work_sched_hilog.h" +#include "ffrt.h" using namespace testing::ext; @@ -36,11 +37,11 @@ public: }; std::shared_ptr WorkSchedulerProxyTest::workSchedulerProxy_ = nullptr; -std::mutex mutexLock; +ffrt::mutex mutexLock; void WorkSchedulerProxyTest::SetUpTestCase() { - std::lock_guard lock(mutexLock); + std::lock_guard lock(mutexLock); sptr SystemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (SystemAbilityManager == nullptr) { diff --git a/test/fuzztest/workschedulergetallrunningworks_fuzzer/BUILD.gn b/test/fuzztest/workschedulergetallrunningworks_fuzzer/BUILD.gn index 3e8de81..6c45dae 100644 --- a/test/fuzztest/workschedulergetallrunningworks_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulergetallrunningworks_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerGetAllRunningWorksFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulergetworkstatus_fuzzer/BUILD.gn b/test/fuzztest/workschedulergetworkstatus_fuzzer/BUILD.gn index 62f211f..fdd04d6 100644 --- a/test/fuzztest/workschedulergetworkstatus_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulergetworkstatus_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerGetWorkStatusFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulerislastworktimeout_fuzzer/BUILD.gn b/test/fuzztest/workschedulerislastworktimeout_fuzzer/BUILD.gn index 9996007..d348ef7 100644 --- a/test/fuzztest/workschedulerislastworktimeout_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulerislastworktimeout_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerIsLastWorkTimeOutFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulerobtainallworks_fuzzer/BUILD.gn b/test/fuzztest/workschedulerobtainallworks_fuzzer/BUILD.gn index 04d9e6b..64e6a42 100644 --- a/test/fuzztest/workschedulerobtainallworks_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulerobtainallworks_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerObtainAllWorksFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulerstartwork_fuzzer/BUILD.gn b/test/fuzztest/workschedulerstartwork_fuzzer/BUILD.gn index c4bd9e4..13d9b04 100644 --- a/test/fuzztest/workschedulerstartwork_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulerstartwork_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerStartWorkFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulerstopandcancelwork_fuzzer/BUILD.gn b/test/fuzztest/workschedulerstopandcancelwork_fuzzer/BUILD.gn index 3c11129..96f1e83 100644 --- a/test/fuzztest/workschedulerstopandcancelwork_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulerstopandcancelwork_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerStopAndCancelWorkFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulerstopandclearworks_fuzzer/BUILD.gn b/test/fuzztest/workschedulerstopandclearworks_fuzzer/BUILD.gn index 3fa4982..051dcfe 100644 --- a/test/fuzztest/workschedulerstopandclearworks_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulerstopandclearworks_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerStopAndClearWorksFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workschedulerstopwork_fuzzer/BUILD.gn b/test/fuzztest/workschedulerstopwork_fuzzer/BUILD.gn index d0908b9..1551d90 100644 --- a/test/fuzztest/workschedulerstopwork_fuzzer/BUILD.gn +++ b/test/fuzztest/workschedulerstopwork_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("WorkSchedulerStopWorkFuzzTest") { "common_event_service:cesfwk_innerkits", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workscheduleservice_fuzzer/BUILD.gn b/test/fuzztest/workscheduleservice_fuzzer/BUILD.gn index 43cc092..24800a4 100644 --- a/test/fuzztest/workscheduleservice_fuzzer/BUILD.gn +++ b/test/fuzztest/workscheduleservice_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("WorkScheduleServiceFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_single", diff --git a/test/fuzztest/workscheduleservice_fuzzer/workscheduleservice_fuzzer.cpp b/test/fuzztest/workscheduleservice_fuzzer/workscheduleservice_fuzzer.cpp index b7b64ed..566e745 100644 --- a/test/fuzztest/workscheduleservice_fuzzer/workscheduleservice_fuzzer.cpp +++ b/test/fuzztest/workscheduleservice_fuzzer/workscheduleservice_fuzzer.cpp @@ -19,18 +19,19 @@ #include "system_ability_definition.h" #include "iservice_registry.h" #include "work_sched_service_stub.h" +#include "ffrt.h" namespace OHOS { namespace WorkScheduler { constexpr int32_t MIN_LEN = 4; constexpr int32_t MAX_CODE_TEST = 15; // current max code is 7 static bool isInited = false; - std::mutex mutexLock; + ffrt::mutex mutexLock; sptr remoteObject; bool DoInit() { - std::lock_guard lock(mutexLock); + std::lock_guard lock(mutexLock); if (remoteObject != nullptr) { return true; } -- Gitee From f314281756bd9bfbdf80693ea2504bb12ce3fb18 Mon Sep 17 00:00:00 2001 From: anchi Date: Mon, 19 Aug 2024 20:13:13 +0800 Subject: [PATCH 32/63] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=BD=93=E5=89=8DbundleName=E7=9A=84abilitya?= =?UTF-8?q?bilityName=E4=BB=BB=E5=8A=A1=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_policy_manager.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 45b91de..c460cef 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -693,15 +693,19 @@ std::list> WorkPolicyManager::GetAllIdeWorkStatus(co it++; continue; } - auto work = it->second->GetWorkList().front(); - if (work->workInfo_->GetBundleName() != bundleName || - work->workInfo_->GetAbilityName() != abilityName || - work->userId_ != currentAccountId) { - it++; - continue; + bool isExist = false; + for (auto work : it->second->GetWorkList()) { + if (work->workInfo_->GetBundleName() == bundleName && + work->workInfo_->GetAbilityName() == abilityName && + (work->userId_ == 0 || work->userId_ == currentAccountId)) { + allWorks.push_back(work); + isExist = true; + } } - allWorks = uidQueueMap_.at(work->uid_)->GetWorkList(); - return allWorks; + if (isExist) { + return allWorks; + } + it++; } return allWorks; } -- Gitee From d28910bcee2a5bbc0533b275e4674c3faf141ab2 Mon Sep 17 00:00:00 2001 From: hxf Date: Fri, 23 Aug 2024 10:58:34 +0800 Subject: [PATCH 33/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1Hidum?= =?UTF-8?q?per=E5=91=BD=E4=BB=A4Eng=E3=80=81User=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=A4=84=E7=90=86=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native/include/work_scheduler_service.h | 3 +- .../native/src/work_scheduler_service.cpp | 28 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index 4f7a37e..5cf8e48 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -321,7 +321,8 @@ private: void DumpRunningWorks(const std::string& uidStr, const std::string& option, std::string& result); bool IsDebugApp(const std::string& bundleName); bool AllowDump(); - void DumpProcess(std::vector& argsInStr, std::string& result); + void DumpProcessForEngMode(std::vector& argsInStr, std::string& result); + void DumpProcessForUserMode(std::vector& argsInStr, std::string& result); bool GetJsonFromFile(const char* filePath, Json::Value& root); bool GetUidByBundleName(const std::string& bundleName, int32_t& uid); void InitWorkInner(); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 2df2e64..b86376e 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -812,17 +812,10 @@ bool WorkSchedulerService::AllowDump() WS_HILOGE("CheckPermission failed"); return false; } - int32_t ENG_MODE = OHOS::system::GetIntParameter("const.debuggable", 0); - bool SECURE_MODE = OHOS::system::GetBoolParameter("const.security.developermode.state", false); - if (ENG_MODE == 1 || SECURE_MODE) { - return true; - } - - WS_HILOGE("Not eng mode and developer mode"); - return false; + return true; } -void WorkSchedulerService::DumpProcess(std::vector &argsInStr, std::string &result) +void WorkSchedulerService::DumpProcessForEngMode(std::vector &argsInStr, std::string &result) { switch (argsInStr.size()) { case 0: @@ -888,13 +881,28 @@ int32_t WorkSchedulerService::Dump(int32_t fd, const std::vector [](const std::u16string &arg) { return Str16ToStr8(arg); }); - DumpProcess(argsInStr, result); + bool secureMode = OHOS::system::GetBoolParameter("const.security.developermode.state", false); + bool debugable = OHOS::system::GetIntParameter("const.debuggable", 0) == 1; + if (secureMode && !debugable) { + WS_HILOGD("User mode."); + DumpProcessForUserMode(argsInStr, result); + } else if (debugable) { + WS_HILOGD("Eng mode."); + DumpProcessForEngMode(argsInStr, result); + } if (!SaveStringToFd(fd, result)) { WS_HILOGE("save to fd failed."); } return ERR_OK; } +void WorkSchedulerService::DumpProcessForUserMode(std::vector &argsInStr, std::string &result) +{ + if (argsInStr.size() == (DUMP_VALUE_INDEX + 1) && argsInStr[DUMP_OPTION] == "-t") { + DumpProcessWorks(argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX], result); + } +} + void WorkSchedulerService::DumpUsage(std::string &result) { result.append("usage: workscheduler dump []\n") -- Gitee From c84a39e4a2a2f676d35e28d437eb093522944d88 Mon Sep 17 00:00:00 2001 From: hxf Date: Fri, 23 Aug 2024 13:59:33 +0800 Subject: [PATCH 34/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1hidum?= =?UTF-8?q?per=E5=91=BD=E4=BB=A4user=E7=94=A8=E6=88=B7=E9=9A=94=E7=A6=BB?= =?UTF-8?q?=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 ++ .../test/src/workschedulerservice_test.cpp | 67 ++++++++++++------- .../workschedulerstartwork_fuzzer.cpp | 34 +++++----- .../workschedulerstopandclearworks_fuzzer.cpp | 10 +-- 4 files changed, 70 insertions(+), 46 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7337529 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "xstring": "cpp" + } +} \ No newline at end of file diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index ee28067..4edfbdc 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -300,7 +300,7 @@ HWTEST_F(WorkSchedulerServiceTest, Datashare_001, TestSize.Level1) argsInStr.push_back("-k"); argsInStr.push_back("settings.power.suspend_sources"); std::string result; - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), 0); WS_HILOGI("====== test end ====== "); @@ -347,39 +347,39 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_001, TestSize.Level1) WS_HILOGI("====== WorkSchedulerServiceTest.Dump_001 begin ====== "); std::vector argsInStr; std::string result; - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); argsInStr.clear(); result.clear(); argsInStr.push_back("-h"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); result.clear(); argsInStr.clear(); argsInStr.push_back("-a"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); result.clear(); argsInStr.clear(); argsInStr.push_back("-x"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); result.clear(); argsInStr.clear(); argsInStr.push_back("-memory"); argsInStr.push_back("100"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); result.clear(); argsInStr.clear(); argsInStr.push_back("-watchdog_time"); argsInStr.push_back("100"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_001 end ====== "); } @@ -391,21 +391,21 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_002, TestSize.Level1) std::string result; argsInStr.push_back("-repeat_time_min"); argsInStr.push_back("100"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); result.clear(); argsInStr.clear(); argsInStr.push_back("-min_interval"); argsInStr.push_back("100"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); result.clear(); argsInStr.clear(); argsInStr.push_back("-test"); argsInStr.push_back("100"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_002 end ====== "); @@ -422,7 +422,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_003, TestSize.Level1) argsInStr.push_back("-d"); argsInStr.push_back("storage"); argsInStr.push_back("ok"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); argsInStr.clear(); @@ -430,7 +430,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_003, TestSize.Level1) argsInStr.push_back("-t"); argsInStr.push_back("bundlename"); argsInStr.push_back("abilityname"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); WorkInfo workinfo = WorkInfo(); @@ -439,7 +439,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_003, TestSize.Level1) workinfo.RefreshUid(2); workinfo.SetElement("bundlename", "abilityname"); workSchedulerService_->AddWorkInner(workinfo); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_003 end ====== "); } @@ -452,7 +452,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_004, TestSize.Level1) argsInStr.push_back("-d"); argsInStr.push_back("storage"); argsInStr.push_back("ok"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); argsInStr.clear(); @@ -462,7 +462,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_004, TestSize.Level1) argsInStr.push_back("arg3"); argsInStr.push_back("arg4"); result.clear(); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_004 end ====== "); @@ -481,7 +481,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_005, TestSize.Level1) std::string result; argsInStr.push_back("-count"); argsInStr.push_back("1"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_005 end ====== "); @@ -500,7 +500,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) std::string result; argsInStr.push_back("-s"); argsInStr.push_back("1"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); @@ -509,7 +509,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) argsInStr.push_back("-s"); argsInStr.push_back("1"); argsInStr.push_back("1"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); @@ -518,7 +518,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) argsInStr.push_back("-s"); argsInStr.push_back("1"); argsInStr.push_back("true"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), true); @@ -527,7 +527,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_006, TestSize.Level1) argsInStr.push_back("-s"); argsInStr.push_back("1"); argsInStr.push_back("false"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), true); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_006 end ====== "); @@ -547,7 +547,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1) argsInStr.push_back("-x"); argsInStr.push_back("1"); argsInStr.push_back("1"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); @@ -556,7 +556,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1) argsInStr.push_back("-x"); argsInStr.push_back("1"); argsInStr.push_back("p"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); @@ -565,7 +565,7 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1) argsInStr.push_back("-x"); argsInStr.push_back("1"); argsInStr.push_back("r"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); @@ -573,12 +573,31 @@ HWTEST_F(WorkSchedulerServiceTest, Dump_007, TestSize.Level1) result.clear(); argsInStr.push_back("-cpu"); argsInStr.push_back("1"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); WS_HILOGI("%{public}s", result.c_str()); EXPECT_EQ(result.empty(), false); WS_HILOGI("====== WorkSchedulerServiceTest.Dump_007 end ====== "); } +/** + * @tc.name: Dump_008 + * @tc.desc: Test WorkSchedulerService Dump. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, Dump_008, TestSize.Level1) +{ + WS_HILOGI("====== WorkSchedulerServiceTest.Dump_008 begin ====== "); + std::vector argsInStr; + std::string result; + argsInStr.push_back("-t"); + argsInStr.push_back("bundlename"); + argsInStr.push_back("abilityname"); + workSchedulerService_->DumpProcessForUserMode(argsInStr, result); + EXPECT_EQ(result.empty(), true); + WS_HILOGI("====== WorkSchedulerServiceTest.Dump_008 end ====== "); +} + HWTEST_F(WorkSchedulerServiceTest, WorkStandbyStateChangeCallbackTest_001, TestSize.Level1) { WS_HILOGI("====== WorkSchedulerServiceTest.WorkStandbyStateChangeCallbackTest_001 begin ====== "); diff --git a/test/fuzztest/workschedulerstartwork_fuzzer/workschedulerstartwork_fuzzer.cpp b/test/fuzztest/workschedulerstartwork_fuzzer/workschedulerstartwork_fuzzer.cpp index b6fd457..f4f867a 100644 --- a/test/fuzztest/workschedulerstartwork_fuzzer/workschedulerstartwork_fuzzer.cpp +++ b/test/fuzztest/workschedulerstartwork_fuzzer/workschedulerstartwork_fuzzer.cpp @@ -75,21 +75,21 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("storage"); argsInStr.push_back("invalid"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("storage"); argsInStr.push_back("ok"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("storage"); argsInStr.push_back("low"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void OnNetworkChange() @@ -102,21 +102,21 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("network"); argsInStr.push_back("invalid"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("network"); argsInStr.push_back("disconnect"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("network"); argsInStr.push_back("wifi"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void OnChargingChange() @@ -129,28 +129,28 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("charging"); argsInStr.push_back("none"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("charging"); argsInStr.push_back("usb"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("charging"); argsInStr.push_back("wireless"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("charging"); argsInStr.push_back("ac"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void OnBatteryStatusChange() @@ -163,14 +163,14 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("batteryStatus"); argsInStr.push_back("ok"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-d"); argsInStr.push_back("batteryStatus"); argsInStr.push_back("low"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void OnTimerChange() @@ -182,19 +182,19 @@ namespace WorkScheduler { result.clear(); argsInStr.push_back("-repeat_time_min"); argsInStr.push_back("10000"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-watchdog_time"); argsInStr.push_back("5000"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-min_interval"); argsInStr.push_back("20000"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void OnBatteryLevelListener() @@ -314,14 +314,14 @@ namespace WorkScheduler { result.clear(); argsInStr.push_back("-k"); argsInStr.push_back("settings.power.suspend_sources"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); argsInStr.clear(); result.clear(); argsInStr.push_back("-t"); argsInStr.push_back(workInfo.GetBundleName()); argsInStr.push_back(workInfo.GetAbilityName()); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); workSchedulerService_->PauseRunningWorks(workInfo.GetUid()); workSchedulerService_->ResumePausedWorks(workInfo.GetUid()); diff --git a/test/fuzztest/workschedulerstopandclearworks_fuzzer/workschedulerstopandclearworks_fuzzer.cpp b/test/fuzztest/workschedulerstopandclearworks_fuzzer/workschedulerstopandclearworks_fuzzer.cpp index 0f9c5ec..a84f485 100644 --- a/test/fuzztest/workschedulerstopandclearworks_fuzzer/workschedulerstopandclearworks_fuzzer.cpp +++ b/test/fuzztest/workschedulerstopandclearworks_fuzzer/workschedulerstopandclearworks_fuzzer.cpp @@ -47,7 +47,7 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("batteryStatus"); argsInStr.push_back("ok"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void TirggerStorageLevelListener() @@ -65,7 +65,7 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("storage"); argsInStr.push_back("ok"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void TirggerChargerListener() @@ -83,7 +83,7 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("charging"); argsInStr.push_back("usb"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void TirggerNetworkListener() @@ -101,7 +101,7 @@ namespace WorkScheduler { argsInStr.push_back("-d"); argsInStr.push_back("network"); argsInStr.push_back("wifi"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } void ShowTaskStatusInfo() @@ -111,7 +111,7 @@ namespace WorkScheduler { argsInStr.clear(); result.clear(); argsInStr.push_back("-a"); - workSchedulerService_->DumpProcess(argsInStr, result); + workSchedulerService_->DumpProcessForEngMode(argsInStr, result); } bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -- Gitee From d3a9c7cc3e43008d01b2a0fa4a64f03662bcc4aa Mon Sep 17 00:00:00 2001 From: hxf Date: Fri, 23 Aug 2024 15:27:45 +0800 Subject: [PATCH 35/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1hidum?= =?UTF-8?q?per=E5=91=BD=E4=BB=A4user=E7=94=A8=E6=88=B7=E9=9A=94=E7=A6=BB?= =?UTF-8?q?=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7337529..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "xstring": "cpp" - } -} \ No newline at end of file -- Gitee From 19c76b4e043103e14068ed8fd38304e7c4f5b579 Mon Sep 17 00:00:00 2001 From: anchi Date: Sat, 24 Aug 2024 11:06:40 +0800 Subject: [PATCH 36/63] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BA=A7=E7=89=A9?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E4=BB=A3=E7=A0=81=E8=B7=AF=E5=BE=84=E6=8E=92?= =?UTF-8?q?=E6=9F=A5=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- utils/native/include/work_sched_hilog.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/native/include/work_sched_hilog.h b/utils/native/include/work_sched_hilog.h index bd89a60..8202f05 100644 --- a/utils/native/include/work_sched_hilog.h +++ b/utils/native/include/work_sched_hilog.h @@ -29,18 +29,18 @@ #define WS_HILOGF(fmt, ...) \ ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, WORKSCHEDULER_MGR_LOG_DOMAIN, WORKSCHEDULER_MGR_LOG_TAG, \ - "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) + "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) #define WS_HILOGE(fmt, ...) \ ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, WORKSCHEDULER_MGR_LOG_DOMAIN, WORKSCHEDULER_MGR_LOG_TAG, \ - "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) + "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) #define WS_HILOGW(fmt, ...) \ ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, WORKSCHEDULER_MGR_LOG_DOMAIN, WORKSCHEDULER_MGR_LOG_TAG, \ - "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) + "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) #define WS_HILOGI(fmt, ...) \ ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, WORKSCHEDULER_MGR_LOG_DOMAIN, WORKSCHEDULER_MGR_LOG_TAG, \ - "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) + "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) #define WS_HILOGD(fmt, ...) \ ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, WORKSCHEDULER_MGR_LOG_DOMAIN, WORKSCHEDULER_MGR_LOG_TAG, \ - "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) + "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_HILOG_H \ No newline at end of file -- Gitee From 253bd2c08d53550d3ee7c8c504276c16eea1622d Mon Sep 17 00:00:00 2001 From: anchi Date: Sat, 24 Aug 2024 11:24:57 +0800 Subject: [PATCH 37/63] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BA=A7=E7=89=A9?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E4=BB=A3=E7=A0=81=E8=B7=AF=E5=BE=84=E6=8E=92?= =?UTF-8?q?=E6=9F=A5=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- utils/native/include/work_sched_hilog.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils/native/include/work_sched_hilog.h b/utils/native/include/work_sched_hilog.h index 8202f05..de68c25 100644 --- a/utils/native/include/work_sched_hilog.h +++ b/utils/native/include/work_sched_hilog.h @@ -25,8 +25,6 @@ #define WORKSCHEDULER_MGR_LOG_TAG "WORK_SCHEDULER" #endif -#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) - #define WS_HILOGF(fmt, ...) \ ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, WORKSCHEDULER_MGR_LOG_DOMAIN, WORKSCHEDULER_MGR_LOG_TAG, \ "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)) -- Gitee From 3b79b98100a0b96de9f9c8af69f45d0e3d81dc88 Mon Sep 17 00:00:00 2001 From: lipengfei Date: Sun, 25 Aug 2024 17:38:58 +0800 Subject: [PATCH 38/63] =?UTF-8?q?=E9=94=81=E7=AB=9E=E4=BA=89=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lipengfei --- services/native/src/work_conn_manager.cpp | 2 +- services/native/src/work_queue.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/native/src/work_conn_manager.cpp b/services/native/src/work_conn_manager.cpp index 7480988..38688f8 100644 --- a/services/native/src/work_conn_manager.cpp +++ b/services/native/src/work_conn_manager.cpp @@ -62,7 +62,7 @@ sptr WorkConnManager::GetConnInfo(string &workId) bool WorkConnManager::StartWork(shared_ptr workStatus) { - if (connMap_.count(workStatus->workId_) > 0) { + if (GetConnInfo(workStatus->workId_)) { WS_HILOGE("Work has started with id: %{public}s, bundleName: %{public}s, abilityName: %{public}s", workStatus->workId_.c_str(), workStatus->bundleName_.c_str(), workStatus->abilityName_.c_str()); return false; diff --git a/services/native/src/work_queue.cpp b/services/native/src/work_queue.cpp index bcfe460..3d6b137 100644 --- a/services/native/src/work_queue.cpp +++ b/services/native/src/work_queue.cpp @@ -133,6 +133,7 @@ bool WorkQueue::Remove(shared_ptr workStatus) uint32_t WorkQueue::GetSize() { + std::lock_guard lock(workListMutex_); return workList_.size(); } -- Gitee From 08f4690f084e09a7b7ff1c30738fb61dbfd1d204 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 26 Aug 2024 09:09:35 +0800 Subject: [PATCH 39/63] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/test/unittest/src/work_sched_client_test.cpp | 2 +- services/test/src/workschedulerservice_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/test/unittest/src/work_sched_client_test.cpp b/frameworks/test/unittest/src/work_sched_client_test.cpp index 5626f3c..2b452b9 100644 --- a/frameworks/test/unittest/src/work_sched_client_test.cpp +++ b/frameworks/test/unittest/src/work_sched_client_test.cpp @@ -224,7 +224,7 @@ HWTEST_F(WorkSchedClientTest, WorkSchedClientTest_014, TestSize.Level1) { std::list> workInfos; ErrCode ret = WorkSchedulerSrvClient::GetInstance().GetAllRunningWorks(workInfos); - EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(ret, E_INVALID_PROCESS_NAME); } } // namespace WorkScheduler } // namespace OHOS diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index 4edfbdc..6c859de 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -284,7 +284,7 @@ HWTEST_F(WorkSchedulerServiceTest, GetAllRunningWorks_001, TestSize.Level1) std::list> workInfos; auto ret = workSchedulerService_->GetAllRunningWorks(workInfos); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, E_INVALID_PROCESS_NAME); } /** -- Gitee From c6c11bae496c077a357f2e9742409522fee8cee4 Mon Sep 17 00:00:00 2001 From: hxf Date: Wed, 28 Aug 2024 09:26:19 +0800 Subject: [PATCH 40/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1durat?= =?UTF-8?q?ion=E5=80=BC=E6=9C=AA=E6=B8=85=E9=9B=B6=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_policy_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 99169b7..efe94a9 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -216,6 +216,9 @@ bool WorkPolicyManager::StopWork(std::shared_ptr workStatus, int32_t RemoveFromReadyQueue(workStatus); hasCanceled = true; } else { + workStatus->workStartTime_ = 0; + workStatus->workWatchDogTime_ = 0; + workStatus->duration_ = 0; workStatus->MarkStatus(WorkStatus::Status::WAIT_CONDITION); } } -- Gitee From d98c267966d7d7888a25bf3ab29fa39545ab6812 Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 29 Aug 2024 16:15:11 +0800 Subject: [PATCH 41/63] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E4=BF=A1=E6=97=A5=E5=BF=97=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_queue.cpp | 3 ++- services/native/src/work_status.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/services/native/src/work_queue.cpp b/services/native/src/work_queue.cpp index 3d6b137..f6a1fbe 100644 --- a/services/native/src/work_queue.cpp +++ b/services/native/src/work_queue.cpp @@ -38,7 +38,8 @@ vector> WorkQueue::OnConditionChanged(WorkCondition::Type } if (uidList.count(it->uid_) > 0 && it->GetMinInterval() != 0 && !DelayedSingleton::GetInstance()->CheckEffiResApplyInfo(it->uid_)) { - WS_HILOGI("One uid can start only one work."); + WS_HILOGI("One uid can start only one work, uid:%{public}d, bundleName:%{public}s" + it->uid_, it->bundleName_.c_str()); continue; } if (it->IsReady()) { diff --git a/services/native/src/work_status.cpp b/services/native/src/work_status.cpp index 1a3eaa7..ddd2540 100644 --- a/services/native/src/work_status.cpp +++ b/services/native/src/work_status.cpp @@ -226,12 +226,16 @@ bool WorkStatus::IsReady() return true; } if (!debugMode && ((!callbackFlag_ && !SetMinInterval()) || minInterval_ == -1)) { - WS_HILOGE("Work can't ready due to false group, forbidden group or unused group."); + WS_HILOGE("Work can't ready due to false group, forbidden group or unused group, " + "bundleName:%{public}s, minInterval:%{public}" PRId64 ", workId:%{public}s", + bundleName_.c_str(), minInterval_, workId_.c_str()); return false; } auto itMap = s_uid_last_time_map.find(uid_); if (itMap == s_uid_last_time_map.end()) { + WS_HILOGI("bundleName:%{public}s, workId:%{public}s, uid:%{public}d", + bundleName_.c_str(), workId_.c_str(), uid_); return true; } time_t lastTime = s_uid_last_time_map[uid_]; @@ -243,6 +247,9 @@ bool WorkStatus::IsReady() timeRetrigger_ = int(minInterval_ - del + ONE_SECOND); return false; } + WS_HILOGI("bundleName:%{public}s, abilityName:%{public}s, workId:%{public}s, " + "callbackFlag:%{public}d, minInterval:%{public}" PRId64 ", del = %{public}f", + bundleName_.c_str(), abilityName_.c_str(), workId_.c_str(), callbackFlag_, minInterval_, del); return true; } @@ -380,6 +387,8 @@ bool WorkStatus::SetMinIntervalByGroup(int32_t group) if (itMap != DeviceUsageStats::DeviceUsageStatsGroupMap::groupIntervalMap_.end()) { minInterval_ = DeviceUsageStats::DeviceUsageStatsGroupMap::groupIntervalMap_[group]; } else { + WS_HILOGE("Query package group interval failed. group:%{public}d, bundleName:%{public}s", + group, bundleName_.c_str()); minInterval_ = -1; } #else -- Gitee From dd0bc29760fad9bfa6e096c19f1b61561c0e6720 Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 29 Aug 2024 16:46:54 +0800 Subject: [PATCH 42/63] =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_queue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue.cpp b/services/native/src/work_queue.cpp index f6a1fbe..1c01602 100644 --- a/services/native/src/work_queue.cpp +++ b/services/native/src/work_queue.cpp @@ -38,7 +38,7 @@ vector> WorkQueue::OnConditionChanged(WorkCondition::Type } if (uidList.count(it->uid_) > 0 && it->GetMinInterval() != 0 && !DelayedSingleton::GetInstance()->CheckEffiResApplyInfo(it->uid_)) { - WS_HILOGI("One uid can start only one work, uid:%{public}d, bundleName:%{public}s" + WS_HILOGI("One uid can start only one work, uid:%{public}d, bundleName:%{public}s", it->uid_, it->bundleName_.c_str()); continue; } -- Gitee From 13f9dcbafb0cb42a88e2e3dde1db5e7dbc2e7ae4 Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 29 Aug 2024 17:00:22 +0800 Subject: [PATCH 43/63] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_status.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/services/native/src/work_status.cpp b/services/native/src/work_status.cpp index ddd2540..01a47f3 100644 --- a/services/native/src/work_status.cpp +++ b/services/native/src/work_status.cpp @@ -226,22 +226,19 @@ bool WorkStatus::IsReady() return true; } if (!debugMode && ((!callbackFlag_ && !SetMinInterval()) || minInterval_ == -1)) { - WS_HILOGE("Work can't ready due to false group, forbidden group or unused group, " - "bundleName:%{public}s, minInterval:%{public}" PRId64 ", workId:%{public}s", - bundleName_.c_str(), minInterval_, workId_.c_str()); + WS_HILOGE("Work can't ready due to false group, forbidden group or unused group, bundleName:%{public}s, " + "minInterval:%{public}" PRId64 ", workId:%{public}s", bundleName_.c_str(), minInterval_, workId_.c_str()); return false; } auto itMap = s_uid_last_time_map.find(uid_); if (itMap == s_uid_last_time_map.end()) { - WS_HILOGI("bundleName:%{public}s, workId:%{public}s, uid:%{public}d", - bundleName_.c_str(), workId_.c_str(), uid_); + WS_HILOGI("bundleName:%{public}s, uid:%{public}d", bundleName_.c_str(), uid_); return true; } time_t lastTime = s_uid_last_time_map[uid_]; double del = difftime(getOppositeTime(), lastTime); - WS_HILOGD("CallbackFlag: %{public}d, minInterval = %{public}" PRId64 ", del = %{public}f", - callbackFlag_, minInterval_, del); + WS_HILOGD("CbFlag:%{public}d, minInterval:%{public}" PRId64 ", del:%{public}f", callbackFlag_, minInterval_, del); if (del < minInterval_) { needRetrigger_ = true; timeRetrigger_ = int(minInterval_ - del + ONE_SECOND); -- Gitee From eabd8ffb5a669b667da3f32d0b5564a05efe7d7e Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 29 Aug 2024 18:17:23 +0800 Subject: [PATCH 44/63] =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_queue_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index 9ebc47f..be9d3ed 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -129,7 +129,8 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ if ((*it)->needRetrigger_) { if (conditionType != WorkCondition::Type::TIMER && conditionType != WorkCondition::Type::GROUP) { - WS_HILOGD("Need retrigger, start group listener."); + WS_HILOGD("Need retrigger, start group listener, bundleName:%{public}s, workId:%{public}s" + (*it)->bundleName_.c_str(), (*it)->workId_.c_str()); SetTimeRetrigger((*it)->timeRetrigger_); listenerMap_.at(WorkCondition::Type::GROUP)->Start(); } -- Gitee From 0cf3400961d0fe49150f4e65f052c1d414c22393 Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 29 Aug 2024 10:19:54 +0000 Subject: [PATCH 45/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index be9d3ed..db54b89 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -129,7 +129,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ if ((*it)->needRetrigger_) { if (conditionType != WorkCondition::Type::TIMER && conditionType != WorkCondition::Type::GROUP) { - WS_HILOGD("Need retrigger, start group listener, bundleName:%{public}s, workId:%{public}s" + WS_HILOGD("Need retrigger, start group listener, bundleName:%{public}s, workId:%{public}s", (*it)->bundleName_.c_str(), (*it)->workId_.c_str()); SetTimeRetrigger((*it)->timeRetrigger_); listenerMap_.at(WorkCondition::Type::GROUP)->Start(); -- Gitee From 39b78cd604977a2d8b7d0cda975e8d450e9bab46 Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 29 Aug 2024 11:54:01 +0000 Subject: [PATCH 46/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index db54b89..b40c065 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -129,7 +129,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ if ((*it)->needRetrigger_) { if (conditionType != WorkCondition::Type::TIMER && conditionType != WorkCondition::Type::GROUP) { - WS_HILOGD("Need retrigger, start group listener, bundleName:%{public}s, workId:%{public}s", + WS_HILOGI("Need retrigger, start group listener, bundleName:%{public}s, workId:%{public}s", (*it)->bundleName_.c_str(), (*it)->workId_.c_str()); SetTimeRetrigger((*it)->timeRetrigger_); listenerMap_.at(WorkCondition::Type::GROUP)->Start(); -- Gitee From 80b426e3e531f8bd218b60d9e2dc447f81a64450 Mon Sep 17 00:00:00 2001 From: anchi Date: Fri, 30 Aug 2024 10:25:16 +0800 Subject: [PATCH 47/63] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=EF=BC=8C=E4=BB=A3=E7=90=86=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/include/policy_type.h | 3 ++- services/native/src/policy/app_data_clear_listener.cpp | 3 +++ services/native/src/work_policy_manager.cpp | 4 ++++ services/native/src/work_scheduler_service.cpp | 2 +- services/test/src/policy/app_data_clear_listener_test.cpp | 5 +++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/services/native/include/policy_type.h b/services/native/include/policy_type.h index f28e3e6..237caa8 100644 --- a/services/native/include/policy_type.h +++ b/services/native/include/policy_type.h @@ -22,7 +22,8 @@ enum PolicyType { APP_REMOVED = 0, APP_DATA_CLEAR, APP_ADDED, - APP_CHANGED + APP_CHANGED, + USER_SWITCHED }; } // namespace WorkScheduler } // namespace OHOS diff --git a/services/native/src/policy/app_data_clear_listener.cpp b/services/native/src/policy/app_data_clear_listener.cpp index 7afaea4..ca1b228 100644 --- a/services/native/src/policy/app_data_clear_listener.cpp +++ b/services/native/src/policy/app_data_clear_listener.cpp @@ -46,6 +46,8 @@ void AppDataClearSubscriber::OnReceiveEvent(const CommonEventData &data) listener_.OnPolicyChanged(PolicyType::APP_CHANGED, detectorVal); } else if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) { listener_.OnPolicyChanged(PolicyType::APP_ADDED, detectorVal); + } else if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { + listener_.OnPolicyChanged(PolicyType::USER_SWITCHED, detectorVal); } } @@ -56,6 +58,7 @@ shared_ptr CreateAppDataClearSubscriber(AppDataClearListe skill.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); skill.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); skill.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); + skill.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); CommonEventSubscribeInfo info(skill); return make_shared(info, listener); } diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index efe94a9..f4cdf0a 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -326,6 +326,10 @@ void WorkPolicyManager::OnPolicyChanged(PolicyType policyType, shared_ptrInitPreinstalledWork(); + break; + } case PolicyType::APP_ADDED: { service->InitPreinstalledWork(); break; diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index b86376e..3b1aaaf 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -176,7 +176,7 @@ void WorkSchedulerService::InitPreinstalledWork() { WS_HILOGD("init preinstalled work"); bool needRefresh = false; - static list> preinstalledWorks = ReadPreinstalledWorks(); + list> preinstalledWorks = ReadPreinstalledWorks(); for (auto work : preinstalledWorks) { WS_HILOGD("preinstalled workinfo id %{public}d, uid %{public}d", work->GetWorkId(), work->GetUid()); if (!work->IsPersisted()) { diff --git a/services/test/src/policy/app_data_clear_listener_test.cpp b/services/test/src/policy/app_data_clear_listener_test.cpp index 42bf980..6596102 100644 --- a/services/test/src/policy/app_data_clear_listener_test.cpp +++ b/services/test/src/policy/app_data_clear_listener_test.cpp @@ -80,6 +80,11 @@ HWTEST_F(AppDataClearListenerTest, OnReceiveEvent_001, TestSize.Level1) appDataClearListener_->commonEventSubscriber->OnReceiveEvent(event4); EXPECT_EQ(event4.GetWant().GetAction(), CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); + want.SetAction(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + CommonEventData event5{want}; + appDataClearListener_->commonEventSubscriber->OnReceiveEvent(event5); + EXPECT_EQ(event5.GetWant().GetAction(), CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + bool ret2 = appDataClearListener_->Stop(); EXPECT_TRUE(ret2); } -- Gitee From 223b816000a8026ea270d1cb6dbf13b2f405d715 Mon Sep 17 00:00:00 2001 From: anchi Date: Fri, 30 Aug 2024 10:37:41 +0800 Subject: [PATCH 48/63] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=EF=BC=8C=E4=BB=A3=E7=90=86=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- services/native/src/work_policy_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index f4cdf0a..4cd003b 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -327,7 +327,7 @@ void WorkPolicyManager::OnPolicyChanged(PolicyType policyType, shared_ptrInitPreinstalledWork(); + service->InitPreinstalledWork(); break; } case PolicyType::APP_ADDED: { -- Gitee From e6562fd2550667909123c94d63f28a79e9262c24 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 09:35:26 +0800 Subject: [PATCH 49/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1GROUP?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6work=E5=8E=BB=E9=87=8D=20Signed-off-by:=20hxf?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/src/work_queue_manager.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index b40c065..5620c46 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -121,7 +121,16 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ for (auto it : queueMap_) { shared_ptr workQueue = it.second; auto works = workQueue->OnConditionChanged(conditionType, conditionVal); - result.insert(result.end(), works.begin(), works.end()); + for (const auto &work : works) { + auto iter = std::find_if(result.begin, result.end, + [work](const shared_ptr &existingWork) { + WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", + work->workId_.c_str(), work->bundleName_.c_str()); + }); + if (iter == result.end) { + result.push_back(work); + } + } } } auto it = result.begin(); -- Gitee From e4dbee968cbfedfd8a3b114c744211e7dd3b7dda Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 01:39:49 +0000 Subject: [PATCH 50/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index 5620c46..1d0857f 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -122,12 +122,13 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ shared_ptr workQueue = it.second; auto works = workQueue->OnConditionChanged(conditionType, conditionVal); for (const auto &work : works) { - auto iter = std::find_if(result.begin, result.end, + auto iter = std::find_if(result.begin(), result.end(), [work](const shared_ptr &existingWork) { WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", work->workId_.c_str(), work->bundleName_.c_str()); + return existingWork->workId_ == work->workId_; }); - if (iter == result.end) { + if (iter == result.end()) { result.push_back(work); } } -- Gitee From a626c9afa1a9710d5ca6274906d7b2d2f35c0c93 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 01:46:20 +0000 Subject: [PATCH 51/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index 1d0857f..8f729bf 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -125,7 +125,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ auto iter = std::find_if(result.begin(), result.end(), [work](const shared_ptr &existingWork) { WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", - work->workId_.c_str(), work->bundleName_.c_str()); + work->workId_.c_str(), work->bundleName_.c_str()); return existingWork->workId_ == work->workId_; }); if (iter == result.end()) { -- Gitee From e27c3895d55a0200d73200a5eec47e55c004f25e Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 10:17:50 +0800 Subject: [PATCH 52/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1GROUP?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6work=E5=8E=BB=E9=87=8D=20Signed-off-by:=20hxf?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/include/work_queue_manager.h | 1 + services/native/src/work_queue_manager.cpp | 27 ++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/services/native/include/work_queue_manager.h b/services/native/include/work_queue_manager.h index 200e803..5686a63 100644 --- a/services/native/include/work_queue_manager.h +++ b/services/native/include/work_queue_manager.h @@ -120,6 +120,7 @@ public: private: std::vector> GetReayQueue(WorkCondition::Type conditionType, std::shared_ptr conditionVal); + void PushWork(const vector works, const vector result); private: ffrt::mutex mutex_; diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index 8f729bf..d950e30 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -121,17 +121,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ for (auto it : queueMap_) { shared_ptr workQueue = it.second; auto works = workQueue->OnConditionChanged(conditionType, conditionVal); - for (const auto &work : works) { - auto iter = std::find_if(result.begin(), result.end(), - [work](const shared_ptr &existingWork) { - WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", - work->workId_.c_str(), work->bundleName_.c_str()); - return existingWork->workId_ == work->workId_; - }); - if (iter == result.end()) { - result.push_back(work); - } - } + PushWork(works, result); } } auto it = result.begin(); @@ -154,6 +144,21 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ return result; } +void WorkQueueManager::PushWork(const vector works, const vector result) +{ + for (const auto &work : works) { + auto iter = std::find_if(result.begin(), result.end(), + [work](const shared_ptr &existingWork) { + WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", + work->workId_.c_str(), work->bundleName_.c_str()); + return existingWork->workId_ == work->workId_; + }); + if (iter == result.end()) { + result.push_back(work); + } + } +} + void WorkQueueManager::OnConditionChanged(WorkCondition::Type conditionType, shared_ptr conditionVal) { -- Gitee From b818c3e1870d7da6066ef7c78013f001f7fb1124 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 02:48:19 +0000 Subject: [PATCH 53/63] update services/native/include/work_queue_manager.h. Signed-off-by: hxf --- services/native/include/work_queue_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/include/work_queue_manager.h b/services/native/include/work_queue_manager.h index 5686a63..b7f633f 100644 --- a/services/native/include/work_queue_manager.h +++ b/services/native/include/work_queue_manager.h @@ -120,7 +120,7 @@ public: private: std::vector> GetReayQueue(WorkCondition::Type conditionType, std::shared_ptr conditionVal); - void PushWork(const vector works, const vector result); + void PushWork(std::vector> works, std::vector> result); private: ffrt::mutex mutex_; -- Gitee From fa0f4ccf26aba210f61f530f01cae9eeec4021e0 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 02:51:45 +0000 Subject: [PATCH 54/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index d950e30..06d84d3 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -144,7 +144,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ return result; } -void WorkQueueManager::PushWork(const vector works, const vector result) +void WorkQueueManager::PushWork(vector &works, vector &result) { for (const auto &work : works) { auto iter = std::find_if(result.begin(), result.end(), -- Gitee From b640b0b8a0843061b22c7d3eb16b867d0db8deaf Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 02:52:52 +0000 Subject: [PATCH 55/63] update services/native/include/work_queue_manager.h. Signed-off-by: hxf --- services/native/include/work_queue_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/include/work_queue_manager.h b/services/native/include/work_queue_manager.h index b7f633f..3656b46 100644 --- a/services/native/include/work_queue_manager.h +++ b/services/native/include/work_queue_manager.h @@ -120,7 +120,7 @@ public: private: std::vector> GetReayQueue(WorkCondition::Type conditionType, std::shared_ptr conditionVal); - void PushWork(std::vector> works, std::vector> result); + void PushWork(std::vector> &works, std::vector> &result); private: ffrt::mutex mutex_; -- Gitee From 37b963a53aedb028a86fe9833db155df92f2b803 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 02:55:49 +0000 Subject: [PATCH 56/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index 06d84d3..e38c2bd 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -144,7 +144,7 @@ vector> WorkQueueManager::GetReayQueue(WorkCondition::Typ return result; } -void WorkQueueManager::PushWork(vector &works, vector &result) +void WorkQueueManager::PushWork(vector> &works, vector> &result) { for (const auto &work : works) { auto iter = std::find_if(result.begin(), result.end(), -- Gitee From 334e0dd074da147167970db72ee392e2340acd82 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 06:32:14 +0000 Subject: [PATCH 57/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index e38c2bd..2814856 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -148,7 +148,7 @@ void WorkQueueManager::PushWork(vector> &works, vector &existingWork) { + [&](const auto &existingWork) { WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", work->workId_.c_str(), work->bundleName_.c_str()); return existingWork->workId_ == work->workId_; -- Gitee From 812685306fb926924c7dc4890b6f4b218b1be309 Mon Sep 17 00:00:00 2001 From: hxf Date: Mon, 2 Sep 2024 07:40:44 +0000 Subject: [PATCH 58/63] update services/native/src/work_queue_manager.cpp. Signed-off-by: hxf --- services/native/src/work_queue_manager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/native/src/work_queue_manager.cpp b/services/native/src/work_queue_manager.cpp index 2814856..083ce84 100644 --- a/services/native/src/work_queue_manager.cpp +++ b/services/native/src/work_queue_manager.cpp @@ -149,13 +149,14 @@ void WorkQueueManager::PushWork(vector> &works, vectorworkId_.c_str(), work->bundleName_.c_str()); return existingWork->workId_ == work->workId_; }); - if (iter == result.end()) { - result.push_back(work); + if (iter != result.end()) { + WS_HILOGE("WorkId:%{public}s existing, bundleName:%{public}s", + work->workId_.c_str(), work->bundleName_.c_str()); + continue; } + result.push_back(work); } } -- Gitee From c166dba0fe19b3c1bd333d12635b011c13bd55ef Mon Sep 17 00:00:00 2001 From: hxf Date: Tue, 10 Sep 2024 11:35:31 +0800 Subject: [PATCH 59/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1deepI?= =?UTF-8?q?dle=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=81=AF=E5=B1=8F31=E5=88=86?= =?UTF-8?q?=E9=92=9F=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/include/work_event_handler.h | 3 ++- .../src/conditions/battery_level_listener.cpp | 16 ---------------- services/native/src/work_event_handler.cpp | 8 ++++++++ services/native/src/work_scheduler_service.cpp | 6 ++++++ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/services/native/include/work_event_handler.h b/services/native/include/work_event_handler.h index 08696bc..61c6b04 100644 --- a/services/native/include/work_event_handler.h +++ b/services/native/include/work_event_handler.h @@ -29,7 +29,8 @@ public: RETRIGGER_MSG = 0, SERVICE_INIT_MSG, IDE_RETRIGGER_MSG, - CHECK_CONDITION_MSG + CHECK_CONDITION_MSG, + CHECK_DEEPIDLE_MSG }; WorkEventHandler(const std::shared_ptr& runner, const std::shared_ptr& service); diff --git a/services/native/src/conditions/battery_level_listener.cpp b/services/native/src/conditions/battery_level_listener.cpp index 0195ea3..d5ba3ae 100644 --- a/services/native/src/conditions/battery_level_listener.cpp +++ b/services/native/src/conditions/battery_level_listener.cpp @@ -27,10 +27,6 @@ namespace OHOS { namespace WorkScheduler { -namespace { - const int MIN_DEEP_IDLE_BATTERY_CAPACITY = 91; - const int MIN_DEEP_IDLE_SCREEN_OFF_TIME_SECOND = 10 * 60 * 1000; -} BatteryLevelEventSubscriber::BatteryLevelEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, BatteryLevelListener &listener) : EventFwk::CommonEventSubscriber(subscribeInfo), listener_(listener) {} @@ -99,18 +95,6 @@ void BatteryLevelListener::OnConditionChanged(WorkCondition::Type conditionType, { if (workQueueManager_ != nullptr) { workQueueManager_->OnConditionChanged(conditionType, conditionVal); - - uint64_t screenOffTime = service_->GetScreenOffTime(); - uint64_t currentTime = WorkSchedUtils::GetCurrentTimeMs(); - if (!service_->IsDeepIdle() - && screenOffTime != 0 - && (currentTime - screenOffTime) >= MIN_DEEP_IDLE_SCREEN_OFF_TIME_SECOND - && conditionVal->intVal >= MIN_DEEP_IDLE_BATTERY_CAPACITY) { - service_->SetDeepIdle(true); - workQueueManager_->OnConditionChanged(WorkCondition::Type::DEEP_IDLE, - std::make_shared(0, 0, true, std::string())); - service_->LoadSa(); - } } else { WS_HILOGE("workQueueManager_ is nullptr."); } diff --git a/services/native/src/work_event_handler.cpp b/services/native/src/work_event_handler.cpp index 9ba7cad..dc493f3 100644 --- a/services/native/src/work_event_handler.cpp +++ b/services/native/src/work_event_handler.cpp @@ -60,6 +60,14 @@ void WorkEventHandler::ProcessEvent([[maybe_unused]] const InnerEvent::Pointer& service->TriggerWorkIfConditionReady(); break; } + case CHECK_DEEPIDLE_MSG: { + WS_HILOGI("Into deep idle mode"); + service->SetDeepIdle(true); + service->GetWorkQueueManager()->OnConditionChanged(WorkCondition::Type::DEEP_IDLE, + std::make_shared(0, 0, true, std::string())); + service->LoadSa(); + break; + } default: return; } diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 3b1aaaf..9bd5734 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -105,6 +105,7 @@ const std::set WORK_SCHED_NATIVE_OPERATE_CALLER = { "resource_schedule_service", "hidumper_service", }; +const int MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN = 31 * 60 * 1000; } #ifdef WORK_SCHEDULER_TEST @@ -1271,6 +1272,11 @@ void WorkSchedulerService::TriggerWorkIfConditionReady() void WorkSchedulerService::SetScreenOffTime(uint64_t screenOffTime) { screenOffTime_.store(screenOffTime); + GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); + if (screenOffTime != 0) { + GetHandler()->SendEvent(InnerEvent::Get(WorkEventHandler::CHECK_DEEPIDLE_MSG, 0), + MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); + } } uint64_t WorkSchedulerService::GetScreenOffTime() -- Gitee From c2b127bfcd03f672ec73f844db9ce31c572b08c4 Mon Sep 17 00:00:00 2001 From: hxf Date: Tue, 10 Sep 2024 15:00:34 +0800 Subject: [PATCH 60/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1deepI?= =?UTF-8?q?dle=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=81=AF=E5=B1=8F31=E5=88=86?= =?UTF-8?q?=E9=92=9F=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native/include/work_scheduler_service.h | 20 -------------- .../native/src/conditions/screen_listener.cpp | 12 ++++++--- services/native/src/work_event_handler.cpp | 1 - .../native/src/work_scheduler_service.cpp | 26 ------------------- 4 files changed, 9 insertions(+), 50 deletions(-) diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index 5cf8e48..aed9906 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -270,26 +270,6 @@ public: */ void InitPreinstalledWork(); void TriggerWorkIfConditionReady(); - /** - * @brief Set screen off time. - * - * @param screenOffTime screen off time. - */ - void SetScreenOffTime(uint64_t screenOffTime); - /** - * @brief Get screen off time. - */ - uint64_t GetScreenOffTime(); - /** - * @brief Set deepIdle. - * - * @param deepIdle If deepIdle,true or false. - */ - void SetDeepIdle(bool deepIdle); - /** - * @brief Is DeepIdle. - */ - bool IsDeepIdle(); /** * @brief stop deepIdle works. * diff --git a/services/native/src/conditions/screen_listener.cpp b/services/native/src/conditions/screen_listener.cpp index cec1eef..9e809cf 100644 --- a/services/native/src/conditions/screen_listener.cpp +++ b/services/native/src/conditions/screen_listener.cpp @@ -23,9 +23,14 @@ #include "work_sched_hilog.h" #include "work_sched_utils.h" #include "work_status.h" +#include "work_event_handler.h" namespace OHOS { namespace WorkScheduler { +namespace { +const int MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN = 31 * 60 * 1000; +} + ScreenEventSubscriber::ScreenEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, ScreenListener &listener) : EventFwk::CommonEventSubscriber(subscribeInfo), listener_(listener) {} @@ -34,8 +39,7 @@ void ScreenEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data const std::string action = data.GetWant().GetAction(); WS_HILOGI("OnReceiveEvent get action: %{public}s", action.c_str()); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { - listener_.service_->SetScreenOffTime(0); - listener_.service_->SetDeepIdle(false); + listener_.service_->GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); listener_.OnConditionChanged(WorkCondition::Type::DEEP_IDLE, std::make_shared(0, 0, false, std::string())); int32_t ret = listener_.service_->StopDeepIdleWorks(); @@ -45,7 +49,9 @@ void ScreenEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data WS_HILOGI("stop work by condition successed."); } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { - listener_.service_->SetScreenOffTime(WorkSchedUtils::GetCurrentTimeMs()); + listener_.service_->GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); + listener_.service_->GetHandler()->SendEvent(InnerEvent::Get(WorkEventHandler::CHECK_DEEPIDLE_MSG, 0), + MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); } } diff --git a/services/native/src/work_event_handler.cpp b/services/native/src/work_event_handler.cpp index dc493f3..5c6cc22 100644 --- a/services/native/src/work_event_handler.cpp +++ b/services/native/src/work_event_handler.cpp @@ -62,7 +62,6 @@ void WorkEventHandler::ProcessEvent([[maybe_unused]] const InnerEvent::Pointer& } case CHECK_DEEPIDLE_MSG: { WS_HILOGI("Into deep idle mode"); - service->SetDeepIdle(true); service->GetWorkQueueManager()->OnConditionChanged(WorkCondition::Type::DEEP_IDLE, std::make_shared(0, 0, true, std::string())); service->LoadSa(); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 9bd5734..4d98942 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -105,7 +105,6 @@ const std::set WORK_SCHED_NATIVE_OPERATE_CALLER = { "resource_schedule_service", "hidumper_service", }; -const int MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN = 31 * 60 * 1000; } #ifdef WORK_SCHEDULER_TEST @@ -1269,31 +1268,6 @@ void WorkSchedulerService::TriggerWorkIfConditionReady() checker.CheckAllStatus(); } -void WorkSchedulerService::SetScreenOffTime(uint64_t screenOffTime) -{ - screenOffTime_.store(screenOffTime); - GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); - if (screenOffTime != 0) { - GetHandler()->SendEvent(InnerEvent::Get(WorkEventHandler::CHECK_DEEPIDLE_MSG, 0), - MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); - } -} - -uint64_t WorkSchedulerService::GetScreenOffTime() -{ - return screenOffTime_.load(); -} - -void WorkSchedulerService::SetDeepIdle(bool deepIdle) -{ - deepIdle_.store(deepIdle); -} - -bool WorkSchedulerService::IsDeepIdle() -{ - return deepIdle_.load(); -} - int32_t WorkSchedulerService::StopDeepIdleWorks() { if (!ready_) { -- Gitee From e2efc83336921184aa037dc5f7a0cd42ef3246fa Mon Sep 17 00:00:00 2001 From: hxf Date: Tue, 10 Sep 2024 15:41:40 +0800 Subject: [PATCH 61/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1deepI?= =?UTF-8?q?dle=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=81=AF=E5=B1=8F31=E5=88=86?= =?UTF-8?q?=E9=92=9F=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/include/work_scheduler_service.h | 2 -- services/native/src/conditions/screen_listener.cpp | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index aed9906..bd5e8b7 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -328,8 +328,6 @@ private: ffrt::mutex observerMutex_; std::map> persistedMap_; bool ready_ {false}; - std::atomic deepIdle_ {false}; - std::atomic screenOffTime_ {0}; std::shared_ptr handler_; std::shared_ptr eventRunner_; bool checkBundle_ {true}; diff --git a/services/native/src/conditions/screen_listener.cpp b/services/native/src/conditions/screen_listener.cpp index 9e809cf..90741dd 100644 --- a/services/native/src/conditions/screen_listener.cpp +++ b/services/native/src/conditions/screen_listener.cpp @@ -50,8 +50,8 @@ void ScreenEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { listener_.service_->GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); - listener_.service_->GetHandler()->SendEvent(InnerEvent::Get(WorkEventHandler::CHECK_DEEPIDLE_MSG, 0), - MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); + listener_.service_->GetHandler()->SendEvent( + AppExecFwk::InnerEvent::Get(WorkEventHandler::CHECK_DEEPIDLE_MSG, 0), MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); } } -- Gitee From 2193370478de3e6a628a5d5511b4d5114949f997 Mon Sep 17 00:00:00 2001 From: hxf Date: Thu, 19 Sep 2024 16:31:40 +0800 Subject: [PATCH 62/63] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=BF=AE=E5=A4=8D=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/test/src/conditions/screen_listener_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/test/src/conditions/screen_listener_test.cpp b/services/test/src/conditions/screen_listener_test.cpp index 9cf2234..fb1d31e 100644 --- a/services/test/src/conditions/screen_listener_test.cpp +++ b/services/test/src/conditions/screen_listener_test.cpp @@ -43,6 +43,7 @@ std::shared_ptr ScreenListenerTest::workQueueManager_ = nullpt void ScreenListenerTest::SetUpTestCase() { std::shared_ptr workSchedulerService_ = std::make_shared(); + workSchedulerService_->OnStart(); workQueueManager_ = std::make_shared(workSchedulerService_); screenListener_ = std::make_shared(workQueueManager_, workSchedulerService_); } -- Gitee From c2dd1262d49cef22e694410920cf9dc59b5336ec Mon Sep 17 00:00:00 2001 From: hxf Date: Fri, 20 Sep 2024 15:28:03 +0800 Subject: [PATCH 63/63] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=A7=A3=E9=94=81=E4=B9=8B=E5=90=8E=E7=BB=93=E6=9D=9F=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=BF=90=E8=A1=8C=E4=BB=BB=E5=8A=A1=E9=9C=80=E6=B1=82?= =?UTF-8?q?=20Signed-off-by:=20hxf=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/include/work_policy_manager.h | 6 +- services/native/include/work_queue.h | 6 +- .../native/include/work_scheduler_service.h | 43 ++++- .../native/src/conditions/screen_listener.cpp | 13 +- services/native/src/work_event_handler.cpp | 4 +- services/native/src/work_policy_manager.cpp | 22 ++- services/native/src/work_queue.cpp | 4 +- .../native/src/work_scheduler_service.cpp | 112 ++++++++++++- .../src/conditions/screen_listener_test.cpp | 4 + .../test/src/workschedulerservice_test.cpp | 154 ++++++++++++++++++ utils/native/BUILD.gn | 3 + utils/native/include/work_sched_utils.h | 6 + utils/native/src/work_sched_utils.cpp | 13 ++ 13 files changed, 364 insertions(+), 26 deletions(-) diff --git a/services/native/include/work_policy_manager.h b/services/native/include/work_policy_manager.h index a71eb3d..71aad5f 100644 --- a/services/native/include/work_policy_manager.h +++ b/services/native/include/work_policy_manager.h @@ -266,11 +266,11 @@ public: void RemoveWatchDog(std::shared_ptr workStatus); /** - * @brief Get All DeepIdle Works. + * @brief Get All Running WorkStatus. * - * @return All DeepIdle Works. + * @return All Running WorkStatus. */ - std::list> GetDeepIdleWorks(); + std::list> GetRunningWorkStatus(); private: int32_t GetMaxRunningCount(std::string& policyName); int32_t GetRunningCount(); diff --git a/services/native/include/work_queue.h b/services/native/include/work_queue.h index a6a6309..ef8badf 100644 --- a/services/native/include/work_queue.h +++ b/services/native/include/work_queue.h @@ -119,11 +119,11 @@ public: */ std::list> GetRunningWorks(); /** - * @brief Get All DeepIdle Works. + * @brief Get All Running WorkStatus. * - * @return All DeepIdle Works; + * @return All Running WorkStatus; */ - std::list> GetDeepIdleWorks(); + std::list> GetRunningWorkStatus(); /** * @brief Get work id str. * diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index bd5e8b7..ee17862 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -271,15 +271,47 @@ public: void InitPreinstalledWork(); void TriggerWorkIfConditionReady(); /** - * @brief stop deepIdle works. + * @brief stop all running works. * * @return success or fail. */ - int32_t StopDeepIdleWorks(); + int32_t StopRunningWorks(); /** * @brief load sa. */ void LoadSa(); + /** + * @brief Handle DeepIdle callback Msg. + */ + void HandleDeepIdleMsg(); + /** + * @brief Check work to run. + */ + void CheckWorkToRun(); + /** + * @brief Set First Unlock state. + * + * @param firstUnlock If first unlock, true or false + */ + void SetFirstUnlock(bool firstUnlock); + /** + * @brief Is First Unlock. + * + * @return true or false. + */ + bool IsFirstUnlock(); + /** + * @brief Set Unlock state. + * + * @param unlock If unlock, true or false + */ + void SetUnlock(bool unlock); + /** + * @brief Is Unlock State. + * + * @return true or false. + */ + bool IsUnlock(); private: void RegisterStandbyStateObserver(); void WorkQueueManagerInit(const std::shared_ptr& runner); @@ -309,11 +341,14 @@ private: void AddWorkInner(WorkInfo& workInfo); std::list> ReadPreinstalledWorks(); void LoadWorksFromFile(const char *path, std::list> &workInfos); + void LoadExemptionBundlesFromFile(const char *path); void InitPersistedWork(); bool CheckProcessName(); bool GetAppIndexAndBundleNameByUid(int32_t uid, int32_t &appIndex, std::string &bundleName); bool CheckExtensionInfos(WorkInfo &workInfo, int32_t uid); void DumpLoadSaWorks(const std::string &saIdStr, const std::string &residentSaStr, std::string &result); + bool ExemptionBundle(std::shared_ptr workStatus); + std::string GetExemptionBundles(); private: std::set whitelist_; @@ -326,11 +361,15 @@ private: std::shared_ptr workPolicyManager_; ffrt::mutex mutex_; ffrt::mutex observerMutex_; + ffrt::mutex workMutex_; std::map> persistedMap_; bool ready_ {false}; + std::atomic firstUnlock_ {false}; + std::atomic unlock_ {false}; std::shared_ptr handler_; std::shared_ptr eventRunner_; bool checkBundle_ {true}; + std::set exemptionBundles_; #ifdef DEVICE_USAGE_STATISTICS_ENABLE sptr groupObserver_; #endif diff --git a/services/native/src/conditions/screen_listener.cpp b/services/native/src/conditions/screen_listener.cpp index 90741dd..72b407b 100644 --- a/services/native/src/conditions/screen_listener.cpp +++ b/services/native/src/conditions/screen_listener.cpp @@ -39,19 +39,26 @@ void ScreenEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data const std::string action = data.GetWant().GetAction(); WS_HILOGI("OnReceiveEvent get action: %{public}s", action.c_str()); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { + if (!listener_.service_->IsFirstUnlock()) { + WS_HILOGI("First Unlock."); + listener_.service_->SetFirstUnlock(true); + } + listener_.service_->SetUnlock(true); listener_.service_->GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); listener_.OnConditionChanged(WorkCondition::Type::DEEP_IDLE, std::make_shared(0, 0, false, std::string())); - int32_t ret = listener_.service_->StopDeepIdleWorks(); + int32_t ret = listener_.service_->StopRunningWorks(); if (ret != ERR_OK) { - WS_HILOGE("stop work by condition failed, error code:%{public}d.", ret); + WS_HILOGE("stop work after unlocking failed, error code:%{public}d.", ret); } else { - WS_HILOGI("stop work by condition successed."); + WS_HILOGI("stop work after unlocking successed."); } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { + listener_.service_->SetUnlock(false); listener_.service_->GetHandler()->RemoveEvent(WorkEventHandler::CHECK_DEEPIDLE_MSG); listener_.service_->GetHandler()->SendEvent( AppExecFwk::InnerEvent::Get(WorkEventHandler::CHECK_DEEPIDLE_MSG, 0), MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); + listener_.service_->CheckWorkToRun(); } } diff --git a/services/native/src/work_event_handler.cpp b/services/native/src/work_event_handler.cpp index 5c6cc22..19ac8b4 100644 --- a/services/native/src/work_event_handler.cpp +++ b/services/native/src/work_event_handler.cpp @@ -62,9 +62,7 @@ void WorkEventHandler::ProcessEvent([[maybe_unused]] const InnerEvent::Pointer& } case CHECK_DEEPIDLE_MSG: { WS_HILOGI("Into deep idle mode"); - service->GetWorkQueueManager()->OnConditionChanged(WorkCondition::Type::DEEP_IDLE, - std::make_shared(0, 0, true, std::string())); - service->LoadSa(); + service->HandleDeepIdleMsg(); break; } default: diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 4cd003b..ad831c0 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -354,6 +354,18 @@ bool WorkPolicyManager::IsSpecialScene(std::shared_ptr topWork) void WorkPolicyManager::CheckWorkToRun() { WS_HILOGD("Check work to run."); + if (wss_.expired()) { + WS_HILOGE("wss_ expired"); + return; + } + if (!wss_.lock()->IsFirstUnlock()) { + WS_HILOGE("Unlocked after boot, can't run work."); + return; + } + if (wss_.lock()->IsUnlock()) { + WS_HILOGE("Unlocked state not allowed run work."); + return; + } RemoveAllUnReady(); if (handler_ == nullptr) { WS_HILOGE("handler lock() returns nullptr"); @@ -801,19 +813,19 @@ void WorkPolicyManager::RemoveWatchDog(std::shared_ptr workStatus) } } -std::list> WorkPolicyManager::GetDeepIdleWorks() +std::list> WorkPolicyManager::GetRunningWorkStatus() { - std::list> deepIdleWorkds; + std::list> runningWorkStatus; std::lock_guard lock(uidMapMutex_); auto it = uidQueueMap_.begin(); while (it != uidQueueMap_.end()) { - std::list> workList = it->second->GetDeepIdleWorks(); + std::list> workList = it->second->GetRunningWorkStatus(); if (workList.size() != 0) { - deepIdleWorkds.insert(deepIdleWorkds.end(), workList.begin(), workList.end()); + runningWorkStatus.insert(runningWorkStatus.end(), workList.begin(), workList.end()); } it++; } - return deepIdleWorkds; + return runningWorkStatus; } } // namespace WorkScheduler } // namespace OHOS \ No newline at end of file diff --git a/services/native/src/work_queue.cpp b/services/native/src/work_queue.cpp index 1c01602..9307f13 100644 --- a/services/native/src/work_queue.cpp +++ b/services/native/src/work_queue.cpp @@ -225,12 +225,12 @@ std::list> WorkQueue::GetRunningWorks() return workInfo; } -std::list> WorkQueue::GetDeepIdleWorks() +std::list> WorkQueue::GetRunningWorkStatus() { std::list> works; std::lock_guard lock(workListMutex_); for (shared_ptr work : workList_) { - if (work->IsRunning() && work->workInfo_->GetDeepIdle() == WorkCondition::DeepIdle::DEEP_IDLE_IN) { + if (work->IsRunning()) { works.emplace_back(work); } } diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 4d98942..5e202f5 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -83,6 +83,7 @@ namespace WorkScheduler { namespace { const std::string WORKSCHEDULER_SERVICE_NAME = "WorkSchedulerService"; const std::string PRINSTALLED_WORKS_KEY = "work_scheduler_preinstalled_works"; +const std::string EXEMPTION_BUNDLES_KEY = "work_scheduler_exemption_bundles"; auto instance = DelayedSingleton::GetInstance(); auto wss = instance.get(); const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(wss); @@ -272,6 +273,36 @@ void WorkSchedulerService::LoadWorksFromFile(const char *path, list> WorkSchedulerService::ReadPreinstalledWorks() { list> workInfos; @@ -283,6 +314,7 @@ list> WorkSchedulerService::ReadPreinstalledWorks() // china->base for (int i = MAX_CFG_POLICY_DIRS_CNT - 1; i >= 0; i--) { LoadWorksFromFile(files->paths[i], workInfos); + LoadExemptionBundlesFromFile(files->paths[i]); } FreeCfgFiles(files); return workInfos; @@ -936,7 +968,8 @@ void WorkSchedulerService::DumpAllInfo(std::string &result) .append("Dump set memory:" + std::to_string(workPolicyManager_->GetDumpSetMemory()) + "\n") .append("Repeat cycle time min:" + std::to_string(workQueueManager_->GetTimeCycle()) + "\n") .append("Watchdog time:" + std::to_string(workPolicyManager_->GetWatchdogTime()) + "\n") - .append("whitelist:" + GetEffiResApplyUid()); + .append("Exemption bundle:" + GetExemptionBundles() + "\n") + .append("whitelist:" + GetEffiResApplyUid() + "\n"); } bool WorkSchedulerService::IsDebugApp(const std::string &bundleName) @@ -1013,6 +1046,19 @@ std::string WorkSchedulerService::GetEffiResApplyUid() return res; } +std::string WorkSchedulerService::GetExemptionBundles() +{ + if (exemptionBundles_.empty()) { + return "[]"; + } + + std::string bundles {""}; + for (auto &bundle : exemptionBundles_) { + bundles.append(bundle + " "); + } + return bundles; +} + void WorkSchedulerService::DumpParamSet(std::string &key, std::string &value, std::string &result) { if (!std::all_of(value.begin(), value.end(), ::isdigit)) { @@ -1247,6 +1293,7 @@ int32_t WorkSchedulerService::PauseRunningWorks(int32_t uid) return E_INVALID_PROCESS_NAME; } + std::lock_guard workLock(workMutex_); int32_t ret = workPolicyManager_->PauseRunningWorks(uid); return ret; } @@ -1258,6 +1305,7 @@ int32_t WorkSchedulerService::ResumePausedWorks(int32_t uid) return E_INVALID_PROCESS_NAME; } + std::lock_guard workLock(workMutex_); int32_t ret = workPolicyManager_->ResumePausedWorks(uid); return ret; } @@ -1268,20 +1316,24 @@ void WorkSchedulerService::TriggerWorkIfConditionReady() checker.CheckAllStatus(); } -int32_t WorkSchedulerService::StopDeepIdleWorks() +int32_t WorkSchedulerService::StopRunningWorks() { if (!ready_) { WS_HILOGE("service is not ready."); return E_SERVICE_NOT_READY; } - std::list> works = workPolicyManager_->GetDeepIdleWorks(); + std::list> works = workPolicyManager_->GetRunningWorkStatus(); if (works.size() == 0) { - WS_HILOGD("stop work by condition, no matched works"); + WS_HILOGD("stop work after unlocking, no matched works"); return ERR_OK; } + std::lock_guard workLock(workMutex_); for (shared_ptr workStatus : works) { - WS_HILOGI("stop work by condition, bundleName:%{public}s, workId:%{public}s", + if (ExemptionBundle(workStatus)) { + continue; + } + WS_HILOGI("stop work after unlocking, bundleName:%{public}s, workId:%{public}s", workStatus->bundleName_.c_str(), workStatus->workId_.c_str()); StopWorkInner(workStatus, workStatus->uid_, false, false); workPolicyManager_->RemoveWatchDog(workStatus); @@ -1289,6 +1341,25 @@ int32_t WorkSchedulerService::StopDeepIdleWorks() return ERR_OK; } +bool WorkSchedulerService::ExemptionBundle(std::shared_ptr workStatus) +{ + bool betaVersion = WorkSchedUtils::IsBetaVersion(); + if (!betaVersion || exemptionBundles_.empty()) { + return false; + } + + auto iter = std::find_if(exemptionBundles_.begin(), exemptionBundles_.end(), + [&](const std::string &bundleName) { + return workStatus->bundleName_ == bundleName; + }); + return iter != exemptionBundles_.end(); +} + +WEAK_FUNC void WorkSchedulerService::CheckWorkToRun() +{ + workPolicyManager_->CheckWorkToRun(); +} + void WorkSchedulerService::LoadSa() { if (!ready_) { @@ -1346,5 +1417,36 @@ void WorkSchedulerService::DumpLoadSaWorks(const std::string &saIdStr, const std } LoadSa(); } + +void WorkSchedulerService::HandleDeepIdleMsg() +{ + if (!ready_) { + WS_HILOGE("service is not ready."); + return; + } + workQueueManager_->OnConditionChanged(WorkCondition::Type::DEEP_IDLE, + std::make_shared(0, 0, true, std::string())); + LoadSa(); +} + +void WorkSchedulerService::SetFirstUnlock(bool firstUnlock) +{ + firstUnlock_.store(firstUnlock); +} + +bool WorkSchedulerService::IsFirstUnlock() +{ + return firstUnlock_.load(); +} + +void WorkSchedulerService::SetUnlock(bool unlock) +{ + unlock_.store(unlock); +} + +bool WorkSchedulerService::IsUnlock() +{ + return unlock_.load(); +} } // namespace WorkScheduler } // namespace OHOS diff --git a/services/test/src/conditions/screen_listener_test.cpp b/services/test/src/conditions/screen_listener_test.cpp index fb1d31e..9fb72d0 100644 --- a/services/test/src/conditions/screen_listener_test.cpp +++ b/services/test/src/conditions/screen_listener_test.cpp @@ -27,6 +27,10 @@ using namespace testing::ext; namespace OHOS { namespace WorkScheduler { +void WorkSchedulerService::CheckWorkToRun() +{ + return; +} class ScreenListenerTest : public testing::Test { public: static void SetUpTestCase(); diff --git a/services/test/src/workschedulerservice_test.cpp b/services/test/src/workschedulerservice_test.cpp index 6c859de..e2cd2a5 100644 --- a/services/test/src/workschedulerservice_test.cpp +++ b/services/test/src/workschedulerservice_test.cpp @@ -43,6 +43,7 @@ #endif #include "work_sched_errors.h" #include "work_sched_hilog.h" +#include "work_sched_utils.h" #ifdef DEVICE_STANDBY_ENABLE namespace OHOS { @@ -83,6 +84,11 @@ bool WorkSchedulerService::IsBaseAbilityReady() { return true; } + +bool WorkSchedUtils::IsBetaVersion() +{ + return true; +} } } @@ -944,5 +950,153 @@ HWTEST_F(WorkSchedulerServiceTest, IsDebugApp_001, TestSize.Level1) bool ret = workSchedulerService_->IsDebugApp("bundleName"); EXPECT_FALSE(ret); } + +/** + * @tc.name: SetFirstUnlock_001 + * @tc.desc: Test WorkSchedulerService SetFirstUnlock. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, SetFirstUnlock_001, TestSize.Level1) +{ + workSchedulerService_->SetFirstUnlock(true); + EXPECT_TRUE(workSchedulerService_->IsFirstUnlock()); +} + +/** + * @tc.name: IsUnlock_001 + * @tc.desc: Test WorkSchedulerService IsUnlock. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, IsUnlock_001, TestSize.Level1) +{ + workSchedulerService_->SetUnlock(true); + EXPECT_TRUE(workSchedulerService_->IsUnlock()); +} + +/** + * @tc.name: CheckWorkToRun_001 + * @tc.desc: Test WorkSchedulerService CheckWorkToRun. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, CheckWorkToRun_001, TestSize.Level1) +{ + workSchedulerService_->SetFirstUnlock(false); + workSchedulerService_->CheckWorkToRun(); + EXPECT_FALSE(workSchedulerService_->IsFirstUnlock()); + + workSchedulerService_->SetFirstUnlock(true); + workSchedulerService_->SetUnlock(true); + workSchedulerService_->CheckWorkToRun(); + EXPECT_TRUE(workSchedulerService_->IsUnlock()); +} + +/** + * @tc.name: ExemptionBundle_001 + * @tc.desc: Test WorkSchedulerService ExemptionBundle. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, ExemptionBundle_001, TestSize.Level1) +{ + std::shared_ptr workStatus = nullptr; + WorkInfo workInfo = WorkInfo(); + workStatus = std::make_shared(workInfo, 1); + workSchedulerService_->exemptionBundles_.clear(); + bool ret = workSchedulerService_->ExemptionBundle(workStatus); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: ExemptionBundle_002 + * @tc.desc: Test WorkSchedulerService ExemptionBundle. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, ExemptionBundle_002, TestSize.Level1) +{ + std::shared_ptr workStatus = nullptr; + WorkInfo workInfo = WorkInfo(); + workStatus = std::make_shared(workInfo, 1); + workStatus->bundleName_ = "com.demo.bundle"; + workSchedulerService_->exemptionBundles_.clear(); + workSchedulerService_->exemptionBundles_.insert("com.demo.bundle"); + bool ret = workSchedulerService_->ExemptionBundle(workStatus); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: ExemptionBundle_003 + * @tc.desc: Test WorkSchedulerService ExemptionBundle. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, ExemptionBundle_003, TestSize.Level1) +{ + std::shared_ptr workStatus = nullptr; + WorkInfo workInfo = WorkInfo(); + workStatus = std::make_shared(workInfo, 1); + workStatus->bundleName_ = "com.demo.bundle"; + workSchedulerService_->exemptionBundles_.clear(); + workSchedulerService_->exemptionBundles_.insert("com.demo.bundle1"); + bool ret = workSchedulerService_->ExemptionBundle(workStatus); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: GetExemptionBundles_001 + * @tc.desc: Test WorkSchedulerService GetExemptionBundles. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, GetExemptionBundles_001, TestSize.Level1) +{ + workSchedulerService_->exemptionBundles_.clear(); + std::string ret = workSchedulerService_->GetExemptionBundles(); + EXPECT_TRUE(ret == "[]"); +} + +/** + * @tc.name: GetExemptionBundles_002 + * @tc.desc: Test WorkSchedulerService GetExemptionBundles. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, GetExemptionBundles_002, TestSize.Level1) +{ + workSchedulerService_->exemptionBundles_.insert("com.demo.bundle1"); + std::string ret = workSchedulerService_->GetExemptionBundles(); + EXPECT_FALSE(ret.empty()); +} + +/** + * @tc.name: LoadExemptionBundlesFromFile_001 + * @tc.desc: Test WorkSchedulerService LoadExemptionBundlesFromFile. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, LoadExemptionBundlesFromFile_001, TestSize.Level1) +{ + workSchedulerService_->exemptionBundles_.clear(); + const char* path = nullptr; + workSchedulerService_->LoadExemptionBundlesFromFile(path); + EXPECT_TRUE(workSchedulerService_->exemptionBundles_.empty()); +} + +/** + * @tc.name: LoadExemptionBundlesFromFile_002 + * @tc.desc: Test WorkSchedulerService LoadExemptionBundlesFromFile. + * @tc.type: FUNC + * @tc.require: IAJSVG + */ +HWTEST_F(WorkSchedulerServiceTest, LoadExemptionBundlesFromFile_002, TestSize.Level1) +{ + workSchedulerService_->exemptionBundles_.clear(); + const char *path = "/a/b/c"; + workSchedulerService_->LoadExemptionBundlesFromFile(path); + EXPECT_TRUE(workSchedulerService_->exemptionBundles_.empty()); +} } } \ No newline at end of file diff --git a/utils/native/BUILD.gn b/utils/native/BUILD.gn index e32b276..aac6259 100644 --- a/utils/native/BUILD.gn +++ b/utils/native/BUILD.gn @@ -33,11 +33,14 @@ ohos_source_set("workschedutils") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", + "init:libbegetutil", "ipc:ipc_single", "jsoncpp:jsoncpp", "os_account:os_account_innerkits", ] + defines = [ "WORK_SCHEDULER_TEST" ] + subsystem_name = "resourceschedule" part_name = "${worksched_native_part_name}" } diff --git a/utils/native/include/work_sched_utils.h b/utils/native/include/work_sched_utils.h index 33056c9..d94f785 100644 --- a/utils/native/include/work_sched_utils.h +++ b/utils/native/include/work_sched_utils.h @@ -64,6 +64,12 @@ public: * @return Millisecond time. */ static uint64_t GetCurrentTimeMs(); + /** + * @brief Check if this is Beta version. + * + * @return Beta version or not. + */ + static bool IsBetaVersion(); }; } // namespace WorkScheduler } // namespace OHOS diff --git a/utils/native/src/work_sched_utils.cpp b/utils/native/src/work_sched_utils.cpp index da92d6a..ceaa18d 100644 --- a/utils/native/src/work_sched_utils.cpp +++ b/utils/native/src/work_sched_utils.cpp @@ -20,10 +20,18 @@ #include "tokenid_kit.h" #include "ipc_skeleton.h" #include "work_sched_hilog.h" +#include "parameters.h" namespace OHOS { namespace WorkScheduler { const int32_t INVALID_DATA = -1; + +#ifdef WORK_SCHEDULER_TEST +#define WEAK_FUNC __attribute__((weak)) +#else +#define WEAK_FUNC +#endif + int32_t WorkSchedUtils::GetCurrentAccountId() { std::vector osAccountIds; @@ -106,5 +114,10 @@ uint64_t WorkSchedUtils::GetCurrentTimeMs() chrono::milliseconds currentTimeMs = chrono::duration_cast(now.time_since_epoch()); return currentTimeMs.count(); } + +WEAK_FUNC bool WorkSchedUtils::IsBetaVersion() +{ + return OHOS::system::GetParameter("const.logsystem.versiontype", "unknown") == "beta"; +} } // namespace WorkScheduler } // namespace OHOS \ No newline at end of file -- Gitee