diff --git a/services/native/include/work_policy_manager.h b/services/native/include/work_policy_manager.h index c662a0dc7b4f355b6a44268c9feae8b43ee42594..5ee560200ed58b01be62e5057c7c3387e52e9c5f 100644 --- a/services/native/include/work_policy_manager.h +++ b/services/native/include/work_policy_manager.h @@ -203,6 +203,13 @@ public: * @return The time of watchdog. */ int32_t GetWatchdogTime(); + /** + * @brief Start work by dump. + * + * @param workId The workId. + * @param uid The uid. + */ + void StartWorkByDump(int32_t workId, int32_t uid); private: int32_t GetMaxRunningCount(); diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index c586f59d60761a54e8f299ceb31cd581b0232df2..ba7ed48f83a6f1c084bdefdd674e22e6cc31b6e7 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -276,6 +276,7 @@ private: bool IsBaseAbilityReady(); void DumpUsage(std::string &result); void DumpParamSet(std::string &key, std::string &value, std::string &result); + void DumpParamSet(std::string &key, std::string ¶m, std::string &value, std::string &result); }; } // namespace WorkScheduler } // namespace OHOS diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 2055b829d7650449b1265b4c339abcf5d5385f97..8ec3bc59556a4fe82eeb5e3c94d629d51aaa95fe 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -187,6 +187,21 @@ shared_ptr WorkPolicyManager::FindWorkStatus(WorkInfo& workInfo, int return nullptr; } +void WorkPolicyManager::StartWorkByDump(int32_t workId, int32_t uid) +{ + WS_HILOGD("Start work by dump with workId=%{public}d, uid=%{public}d.", workId, uid); + shared_ptr work; + std::lock_guard lock(uidMapMutex_); + if (uidQueueMap_.count(uid) > 0) { + work = uidQueueMap_.at(uid)->Find(WorkStatus::MakeWorkId(workInfo.GetWorkId(), uid)); + } + if (!work) { + RealStartWork(work); + } else { + WS_HILOGE("Failed to start work because work does not exist."); + } +} + void WorkPolicyManager::RemoveFromUidQueue(std::shared_ptr workStatus, int32_t uid) { std::lock_guard lock(uidMapMutex_); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 87b83becaad59ea14487848a022f0f9f4bece18d..8bb5ed9a8e0ecc0fdb5a0ef1a7db9ca741d55cc5 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -577,12 +577,7 @@ int32_t WorkSchedulerService::Dump(int32_t fd, const std::vector DumpParamSet(argsInStr[DUMP_OPTION], argsInStr[DUMP_PARAM_INDEX], result); break; case DUMP_VALUE_INDEX + 1: - if (argsInStr[DUMP_OPTION] == "-d") { - EventPublisher eventPublisher; - eventPublisher.Dump(result, argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX]); - } else { - result.append("Error params."); - } + DumpParamSet(argsInStr[DUMP_OPTION], argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX], result); break; default: result.append("Error params."); @@ -657,6 +652,21 @@ void WorkSchedulerService::DumpParamSet(std::string &key, std::string &value, st } } +void WorkSchedulerService::DumpParamSet(std::string &key, std::string ¶m, std::string &value, std::string &result) +{ + if (key == "-d") { + EventPublisher eventPublisher; + eventPublisher.Dump(result, param, value); + } else if (key == "-startwork") { + int32_t workId = std::stoi(param); + int32_t uid = std::stoi(value); + workPolicyManager_->StartWorkByDump(workId, uid); + result.append("Start work with workId=" + std::to_string(workId) + ", uid=" + std::to_string(uid) + "\n"); + } else { + result.append("Error params."); + } +} + void WorkSchedulerService::RefreshPersistedWorks() { Json::Value root;