diff --git a/interfaces/inner_api/modulemgr/include/module_manager.h b/interfaces/inner_api/modulemgr/include/module_manager.h index 6112a97fb08d8d6596ce144ebc80c4ccc68d1601..d39c0c3b74dd21c04d425b2cf424d0ebecd46dc5 100644 --- a/interfaces/inner_api/modulemgr/include/module_manager.h +++ b/interfaces/inner_api/modulemgr/include/module_manager.h @@ -45,6 +45,9 @@ public: void HandleOnStartOnStopFunc(std::string phase, const OHOS::SystemAbilityOnDemandReason &reason); void HookOnIdleFunc(std::string phase, LifeCycleFuncReturnType handleSAOnIdle); int32_t HandleOnIdleFunc(std::string phase, const OHOS::SystemAbilityOnDemandReason &reason); + void HookDumpFunc(std::string phase, LifeCycleFuncDumpType handleSADump); + int HandleDumpFunc(std::string phase, int fd, const std::vector &args); + bool IsMapFuncExist(uint32_t code); private: @@ -53,10 +56,13 @@ private: static std::map onStartOnStopFuncMap_; static std::map onIdleFuncMap_; static std::map onRemoteRequestFuncMap_; + static std::map onDumpFuncMap_; + static bool isLoaded; static std::mutex onRemoteRequestFuncMapMutex_; static std::mutex onStartOnStopFuncMapMutex_; static std::mutex onIdleFuncMapMutex_; + static std::mutex onDumpFuncMapMutex_; }; } // namespace UpdateEngine } // namespace OHOS diff --git a/interfaces/inner_api/modulemgr/include/update_service_module.h b/interfaces/inner_api/modulemgr/include/update_service_module.h index 4467ea8e07b18d75fe22217c2a9442bace46731f..443e5466b2ed812d4a1bdbe4838fad106e8f93ff 100644 --- a/interfaces/inner_api/modulemgr/include/update_service_module.h +++ b/interfaces/inner_api/modulemgr/include/update_service_module.h @@ -37,11 +37,13 @@ using RequestFuncType = int32_t (*)(uint32_t code, using LifeCycleFuncType = void (*)(const OHOS::SystemAbilityOnDemandReason &reason); using LifeCycleFuncReturnType = int32_t (*)(const OHOS::SystemAbilityOnDemandReason &reason); +using LifeCycleFuncDumpType = int (*)(int fd, const std::vector &args); void RegisterFunc(std::vector codes, RequestFuncType handleRemoteRequest); void RegisterOnStartOnStopFunc(std::string phase, LifeCycleFuncType handlePhase); void RegisterOnIdleFunc(std::string phase, LifeCycleFuncReturnType handlePhase); +void RegisterDumpFunc(std::string phase, LifeCycleFuncDumpType handlePhase); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/inner_api/modulemgr/src/module_manager.cpp b/interfaces/inner_api/modulemgr/src/module_manager.cpp index ad4736b07f4b1cf649a49eb444a1744bb1cfa3e8..99d0e801eae967bbd12312e38bd74b5088053ca1 100644 --- a/interfaces/inner_api/modulemgr/src/module_manager.cpp +++ b/interfaces/inner_api/modulemgr/src/module_manager.cpp @@ -26,9 +26,11 @@ namespace UpdateEngine { std::map ModuleManager::onRemoteRequestFuncMap_; std::map ModuleManager::onStartOnStopFuncMap_; std::map ModuleManager::onIdleFuncMap_; +std::map ModuleManager::onDumpFuncMap_; std::mutex ModuleManager::onRemoteRequestFuncMapMutex_; std::mutex ModuleManager::onStartOnStopFuncMapMutex_; std::mutex ModuleManager::onIdleFuncMapMutex_; +std::mutex ModuleManager::onDumpFuncMapMutex_; bool ModuleManager::isLoaded = false; @@ -152,6 +154,29 @@ int32_t ModuleManager::HandleOnIdleFunc(std::string phase, const OHOS::SystemAbi return 0; } +void ModuleManager::HookDumpFunc(std::string phase, LifeCycleFuncDumpType handleSADump) +{ + std::lock_guard guard(onDumpFuncMapMutex_); + if (onDumpFuncMap_.find(phase) == onDumpFuncMap_.end()) { + UTILS_LOGI("add phase %{public}s", phase.c_str()); + onDumpFuncMap_.insert(std::make_pair(phase, handleSADump)); + } else { + UTILS_LOGI("phase %{public}s already exist", phase.c_str()); + onDumpFuncMap_[phase] = handleSADump; + } +} + +int ModuleManager::HandleDumpFunc(std::string phase, int fd, const std::vector &args) +{ + if (onDumpFuncMap_.find(phase) == onDumpFuncMap_.end()) { + UTILS_LOGI("phase %{public}s not exist", phase.c_str()); + } else { + UTILS_LOGI("phase %{public}s already exist", phase.c_str()); + return ((LifeCycleFuncDumpType)onDumpFuncMap_[phase])(fd, args); + } + return 0; +} + bool ModuleManager::IsMapFuncExist(uint32_t code) { return onRemoteRequestFuncMap_.count(code); diff --git a/interfaces/inner_api/modulemgr/src/update_service_module.cpp b/interfaces/inner_api/modulemgr/src/update_service_module.cpp index 47c76c7635f2397265d4e208916c66f4a8a1e0ea..83dd66f540d9d4d952bdb38385b1b0bf267a614a 100644 --- a/interfaces/inner_api/modulemgr/src/update_service_module.cpp +++ b/interfaces/inner_api/modulemgr/src/update_service_module.cpp @@ -36,5 +36,10 @@ void RegisterOnIdleFunc(std::string phase, LifeCycleFuncReturnType handlePhase) { OHOS::UpdateEngine::ModuleManager::GetInstance().HookOnIdleFunc(phase, handlePhase); } + +void RegisterDumpFunc(std::string phase, LifeCycleFuncDumpType handlePhase) +{ + OHOS::UpdateEngine::ModuleManager::GetInstance().HookDumpFunc(phase, handlePhase); +} } // namespace UpdateEngine } // namespace OHOS \ No newline at end of file diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index b31582aa5235f221542f43d00b27788120252bcd..7b2dd0ee73c3709fc6475b3085524a54287b844c 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -405,20 +405,24 @@ void UpdateService::DumpUpgradeCallback(const int fd) int UpdateService::Dump(int fd, const std::vector &args) { - if (fd < 0) { - ENGINE_LOGI("HiDumper handle invalid"); - return -1; - } + if (!ModuleManager::GetInstance().IsModuleLoaded()) { + if (fd < 0) { + ENGINE_LOGI("HiDumper handle invalid"); + return -1; + } - if (args.size() == 0) { - UpgradeInfo upgradeInfo = UpdateServiceCache::GetUpgradeInfo(BusinessSubType::FIRMWARE); - BuildUpgradeInfoDump(fd, upgradeInfo); - BuildTaskInfoDump(fd); - DumpUpgradeCallback(fd); + if (args.size() == 0) { + UpgradeInfo upgradeInfo = UpdateServiceCache::GetUpgradeInfo(BusinessSubType::FIRMWARE); + BuildUpgradeInfoDump(fd, upgradeInfo); + BuildTaskInfoDump(fd); + DumpUpgradeCallback(fd); + } else { + dprintf(fd, "input error, no parameters required\n"); + } + return 0; } else { - dprintf(fd, "input error, no parameters required\n"); + return ModuleManager::GetInstance().HandleDumpFunc("Dump", fd, args); } - return 0; } void UpdateService::OnStart(const SystemAbilityOnDemandReason &startReason) diff --git a/services/firmware/upgrade/flow/src/firmware_manager.cpp b/services/firmware/upgrade/flow/src/firmware_manager.cpp index 6239996463b02bef4ef479f93abfd7388b24312a..374c65debe15dc4cb1f515faad16bbd6d6ebfc6c 100644 --- a/services/firmware/upgrade/flow/src/firmware_manager.cpp +++ b/services/firmware/upgrade/flow/src/firmware_manager.cpp @@ -409,6 +409,7 @@ void FirmwareManager::HandleBootUpdateFail(const FirmwareTask &task, versionComponent.upgradeAction = UpgradeAction::UPGRADE; versionComponent.displayVersion = component.targetBlDisplayVersionNumber; versionComponent.innerVersion = component.targetBlVersionNumber; + versionComponent.componentExtra = JsonBuilder().Append("{}").ToJson(); versionComponents.push_back(versionComponent); }