diff --git a/bundle.json b/bundle.json index bd19c6760b0a261d1ba7a5eba249c3e2a62991ea..10d428cf5d7fb0f3ae56e184a9d2c738916add5c 100644 --- a/bundle.json +++ b/bundle.json @@ -17,6 +17,7 @@ ], "features": [ "update_service_dupdate_config_path", + "update_service_enable_run_on_demand_qos", "update_service_updater_sa_cfg_path", "update_service_sa_profile_path" ], diff --git a/foundations/model/include/business_error.h b/foundations/model/include/business_error.h index 24a7f5723139cedf58c3d18968d062d9a2f6b5af..25e7382feb7d61f67c84f6d3c36aa1b8a313ccec 100644 --- a/foundations/model/include/business_error.h +++ b/foundations/model/include/business_error.h @@ -17,6 +17,7 @@ #define UPDATE_SERVICE_BUSINESS_ERROR_H #include +#include #include #include "nlohmann/json.hpp" @@ -25,9 +26,10 @@ #include "dupdate_json_utils.h" #include "error_message.h" #include "json_builder.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct BusinessError { +struct BusinessError : public Parcelable { std::string message; CallResult errorNum = CallResult::SUCCESS; std::vector data; @@ -63,6 +65,10 @@ struct BusinessError { JsonUtils::GetValueAndSetTo(jsonObj, "errorNum", errorNumber); businessError.errorNum = static_cast(errorNumber); } + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static BusinessError *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_BUSINESS_ERROR_H diff --git a/frameworks/js/napi/update/src/local_updater.cpp b/frameworks/js/napi/update/src/local_updater.cpp index b52c026b27c664d1a4473ef7dd2b2b651754c7b2..66e65be3265a4af6b822371be07a4dc64f32072e 100644 --- a/frameworks/js/napi/update/src/local_updater.cpp +++ b/frameworks/js/napi/update/src/local_updater.cpp @@ -75,7 +75,8 @@ void LocalUpdater::Init() ENGINE_LOGI("LocalUpdater::Init"); UpgradeInfo upgradeInfo; upgradeInfo.upgradeApp = LOCAL_UPGRADE_INFO; - UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo, callback); + int32_t funcResult; + UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo, callback, funcResult); isInit_ = true; } @@ -106,8 +107,9 @@ napi_value LocalUpdater::VerifyUpgradePackage(napi_env env, napi_callback_info i [upgradeFile, certsFile](void *context) -> int { ENGINE_LOGI("VerifyUpdatePackage StartWork %s, %s", upgradeFile.filePath.c_str(), certsFile.c_str()); BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().VerifyUpgradePackage(upgradeFile.filePath, certsFile, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to VerifyUpgradePackage."); return retValue; @@ -141,8 +143,9 @@ napi_value LocalUpdater::ApplyNewVersion(napi_env env, napi_callback_info info) BusinessError *businessError = reinterpret_cast(context); UpgradeInfo upgradeInfo; upgradeInfo.upgradeApp = LOCAL_UPGRADE_INFO; + int32_t funcResult; return UpdateServiceKits::GetInstance().ApplyNewVersion(upgradeInfo, MISC_FILE, packageNames, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to ApplyNewVersion"); return retValue; diff --git a/frameworks/js/napi/update/src/update_client.cpp b/frameworks/js/napi/update/src/update_client.cpp index 2bc0d39d388e274270fd26869abc563e762c1dd6..54b97bd8cdf90f9204cdd0ab390fe9ea7c6b369b 100644 --- a/frameworks/js/napi/update/src/update_client.cpp +++ b/frameworks/js/napi/update/src/update_client.cpp @@ -86,7 +86,8 @@ void UpdateClient::RegisterCallback() constexpr int32_t maxRetryTimes = 5; // 回调注册失败最大尝试次数 int32_t retryTimes = 0; do { - int32_t ret = UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo_, callback); + int32_t funcResult; + int32_t ret = UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo_, callback, funcResult); if (ret == INT_CALL_SUCCESS) { break; } @@ -103,7 +104,8 @@ void UpdateClient::RegisterCallback() void UpdateClient::UnRegisterCallback() { - UpdateServiceKits::GetInstance().UnregisterUpdateCallback(upgradeInfo_); + int32_t funcResult; + UpdateServiceKits::GetInstance().UnregisterUpdateCallback(upgradeInfo_, funcResult); } napi_value UpdateClient::CheckNewVersion(napi_env env, napi_callback_info info) @@ -111,7 +113,9 @@ napi_value UpdateClient::CheckNewVersion(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_CHECK_VERSION, CALLBACK_POSITION_ONE, true); napi_value ret = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().CheckNewVersion(upgradeInfo_, *businessError, checkResult_); + int32_t funcResult; + return UpdateServiceKits::GetInstance().CheckNewVersion(upgradeInfo_, *businessError, checkResult_, + funcResult); }); PARAM_CHECK(ret != nullptr, return nullptr, "Failed to start worker."); return ret; @@ -123,8 +127,9 @@ napi_value UpdateClient::CancelUpgrade(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_CANCEL_UPGRADE, CALLBACK_POSITION_ONE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().Cancel(upgradeInfo_, CAST_INT(UpdaterSaInterfaceCode::DOWNLOAD), - *businessError); + int32_t funcResult; + return UpdateServiceKits::GetInstance().Cancel(upgradeInfo_, CAST_INT(UpdaterSaInterfaceCode::DOWNLOAD), + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -180,8 +185,9 @@ napi_value UpdateClient::Download(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_DOWNLOAD, CALLBACK_POSITION_THREE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().Download(upgradeInfo_, versionDigestInfo_, downloadOptions_, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -204,8 +210,9 @@ napi_value UpdateClient::PauseDownload(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_PAUSE_DOWNLOAD, CALLBACK_POSITION_THREE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().PauseDownload(upgradeInfo_, versionDigestInfo_, pauseDownloadOptions_, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -228,8 +235,9 @@ napi_value UpdateClient::ResumeDownload(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_RESUME_DOWNLOAD, CALLBACK_POSITION_THREE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().ResumeDownload(upgradeInfo_, versionDigestInfo_, resumeDownloadOptions_, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -252,8 +260,9 @@ napi_value UpdateClient::Upgrade(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_UPGRADE, CALLBACK_POSITION_THREE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().Upgrade(upgradeInfo_, versionDigestInfo_, upgradeOptions_, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -276,8 +285,9 @@ napi_value UpdateClient::ClearError(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_CLEAR_ERROR, CALLBACK_POSITION_THREE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().ClearError(upgradeInfo_, versionDigestInfo_, clearOptions_, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -293,7 +303,9 @@ napi_value UpdateClient::TerminateUpgrade(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_TERMINATE_UPGRADE, CALLBACK_POSITION_ONE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, *businessError); + int32_t funcResult; + return UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, *businessError, + funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -315,7 +327,9 @@ napi_value UpdateClient::SetUpgradePolicy(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_SET_POLICY, CALLBACK_POSITION_TWO, true); napi_value retValue = StartSession(env, info, sessionParams, [&](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().SetUpgradePolicy(upgradeInfo_, upgradePolicy_, *businessError); + int32_t funcResult; + return UpdateServiceKits::GetInstance().SetUpgradePolicy(upgradeInfo_, upgradePolicy_, *businessError, + funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to SetUpgradePolicy."); return retValue; @@ -326,7 +340,9 @@ napi_value UpdateClient::GetUpgradePolicy(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_GET_POLICY, CALLBACK_POSITION_ONE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().GetUpgradePolicy(upgradeInfo_, upgradePolicy_, *businessError); + int32_t funcResult; + return UpdateServiceKits::GetInstance().GetUpgradePolicy(upgradeInfo_, upgradePolicy_, *businessError, + funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to UpgradeVersion."); return retValue; @@ -337,7 +353,9 @@ napi_value UpdateClient::GetNewVersionInfo(napi_env env, napi_callback_info info SessionParams sessionParams(SessionType::SESSION_GET_NEW_VERSION, CALLBACK_POSITION_ONE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().GetNewVersionInfo(upgradeInfo_, newVersionInfo_, *businessError); + int32_t funcResult; + return UpdateServiceKits::GetInstance().GetNewVersionInfo(upgradeInfo_, newVersionInfo_, *businessError, + funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to GetNewVersionInfo."); return retValue; @@ -361,8 +379,9 @@ napi_value UpdateClient::GetNewVersionDescription(napi_env env, napi_callback_in SessionParams sessionParams(SessionType::SESSION_GET_NEW_VERSION_DESCRIPTION, CALLBACK_POSITION_THREE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().GetNewVersionDescription(upgradeInfo_, versionDigestInfo_, - descriptionOptions_, newVersionDescriptionInfo_, *businessError); + descriptionOptions_, newVersionDescriptionInfo_, *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -373,8 +392,9 @@ napi_value UpdateClient::GetCurrentVersionInfo(napi_env env, napi_callback_info SessionParams sessionParams(SessionType::SESSION_GET_CUR_VERSION, CALLBACK_POSITION_ONE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().GetCurrentVersionInfo(upgradeInfo_, currentVersionInfo_, - *businessError); + *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to GetCurrentVersionInfo."); return retValue; @@ -397,8 +417,9 @@ napi_value UpdateClient::GetCurrentVersionDescription(napi_env env, napi_callbac SessionParams sessionParams(SessionType::SESSION_GET_CUR_VERSION_DESCRIPTION, CALLBACK_POSITION_TWO, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); + int32_t funcResult; return UpdateServiceKits::GetInstance().GetCurrentVersionDescription(upgradeInfo_, descriptionOptions_, - currentVersionDescriptionInfo_, *businessError); + currentVersionDescriptionInfo_, *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to start worker."); return retValue; @@ -409,7 +430,8 @@ napi_value UpdateClient::GetTaskInfo(napi_env env, napi_callback_info info) SessionParams sessionParams(SessionType::SESSION_GET_TASK_INFO, CALLBACK_POSITION_ONE, true); napi_value retValue = StartSession(env, info, sessionParams, [=](void *context) -> int { BusinessError *businessError = reinterpret_cast(context); - return UpdateServiceKits::GetInstance().GetTaskInfo(upgradeInfo_, taskInfo_, *businessError); + int32_t funcResult; + return UpdateServiceKits::GetInstance().GetTaskInfo(upgradeInfo_, taskInfo_, *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to GetTaskInfo."); return retValue; @@ -453,4 +475,4 @@ void UpdateClient::GetUpdateResult(uint32_t type, UpdateResult &result) break; } } -} // namespace OHOS::UpdateEngine \ No newline at end of file +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/engine/BUILD.gn b/interfaces/inner_api/engine/BUILD.gn index ce6b9378e4c4f98158baddae7e0e1fc1fb8071cd..d289aa1074469bd769b6d8a6ac13f02bd4149015 100644 --- a/interfaces/inner_api/engine/BUILD.gn +++ b/interfaces/inner_api/engine/BUILD.gn @@ -13,9 +13,25 @@ import("//base/update/updateservice/foundations/foundations.gni") import("//base/update/updateservice/updateengine.gni") +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("../feature/feature.gni") +idl_interface_sources = [ "${target_gen_dir}/update_service_proxy.cpp" ] + +idl_include = [ + "${target_gen_dir}", + "${target_gen_dir}/callback", +] + +idl_gen_interface("update_service_interface") { + src_idl = rebase_path("IUpdateService.idl") + sources_callback = [ "callback/IUpdateCallback.idl" ] + dst_file = string_join(",", idl_interface_sources) + log_domainid = "0xD002E00" + log_tag = "UPDATE_SERVICE_KITS" +} + ohos_prebuilt_etc("updater_sa.rc") { source = "etc/updater_sa.rc" relative_install_dir = "init" @@ -27,6 +43,7 @@ config("updateengine_inner_library_native_config") { include_dirs = [ "$updateengine_root_path/interfaces/inner_api/include" ] include_dirs += feature_include include_dirs += foundations_include + include_dirs += idl_include } ohos_shared_library("$updateengine_inner_library_name") { @@ -40,18 +57,20 @@ ohos_shared_library("$updateengine_inner_library_name") { } branch_protector_ret = "pac_ret" + output_values = get_target_outputs(":update_service_interface") + defines = [ "DUAL_ADAPTER" ] if (!ability_ability_runtime_enable) { defines += [ "ABILITY_RUNTIME_INNER_ENABLE" ] } sources = [ "$updateengine_root_path/interfaces/inner_api/engine/src/update_callback.cpp", - "$updateengine_root_path/interfaces/inner_api/engine/src/update_callback_stub.cpp", "$updateengine_root_path/interfaces/inner_api/engine/src/update_service_kits_impl.cpp", - "$updateengine_root_path/interfaces/inner_api/engine/src/update_service_proxy.cpp", ] + sources += filter_include(output_values, [ "*.cpp" ]) include_dirs = [ + "$updateengine_root_path/interfaces/inner_api/feature/update_model", "$updateengine_root_path/interfaces/inner_api/engine/include", "$updateengine_root_path/interfaces/inner_api/include", ] @@ -59,6 +78,7 @@ ohos_shared_library("$updateengine_inner_library_name") { public_configs = [ ":updateengine_inner_library_native_config" ] deps = [ + ":update_service_interface", "$updateengine_root_path/foundations:update_foundations", "$updateengine_root_path/interfaces/inner_api/modulemgr:update_module_mgr", ] diff --git a/interfaces/inner_api/engine/IUpdateService.idl b/interfaces/inner_api/engine/IUpdateService.idl new file mode 100644 index 0000000000000000000000000000000000000000..87bdab76181d47d84d89de074b7adb7b1896d354 --- /dev/null +++ b/interfaces/inner_api/engine/IUpdateService.idl @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.UpdateEngine; + +import callback/IUpdateCallback; + +sequenceable OHOS.UpdateEngine.BusinessError; +sequenceable OHOS.UpdateEngine.CheckResult; +sequenceable OHOS.UpdateEngine.ClearOptions; +sequenceable OHOS.UpdateEngine.CurrentVersionInfo; +sequenceable OHOS.UpdateEngine.DescriptionOptions; +sequenceable OHOS.UpdateEngine.DownloadOptions; +sequenceable OHOS.UpdateEngine.NewVersionInfo; +sequenceable OHOS.UpdateEngine.PauseDownloadOptions; +sequenceable OHOS.UpdateEngine.ResumeDownloadOptions; +sequenceable OHOS.UpdateEngine.TaskInfo; +sequenceable OHOS.UpdateEngine.UpgradeInfo; +sequenceable OHOS.UpdateEngine.UpgradeOptions; +sequenceable OHOS.UpdateEngine.UpgradePolicy; +sequenceable OHOS.UpdateEngine.VersionDescriptionInfo; +sequenceable OHOS.UpdateEngine.VersionDigestInfo; + +option_stub_hooks on; +option_parcel_hooks on; + +interface OHOS.UpdateEngine.IUpdateService { + int RegisterUpdateCallback([in] UpgradeInfo info, [in] IUpdateCallback updateCallback); + int UnregisterUpdateCallback([in] UpgradeInfo info); + + int CheckNewVersion([in] UpgradeInfo info, [out] BusinessError businessError, [out] CheckResult checkResult); + int Download([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] DownloadOptions downloadOptions, [out] BusinessError businessError); + int PauseDownload([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] PauseDownloadOptions pauseDownloadOptions, [out] BusinessError businessError); + int ResumeDownload([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] ResumeDownloadOptions resumeDownloadOptions, [out] BusinessError businessError); + int Upgrade([in] UpgradeInfo info, [in] VersionDigestInfo versionDigest, + [in] UpgradeOptions upgradeOptions, [out] BusinessError businessError); + int ClearError([in] UpgradeInfo info, [in] VersionDigestInfo versionDigest, + [in] ClearOptions clearOptions, [out] BusinessError businessError); + int TerminateUpgrade([in] UpgradeInfo info, [out] BusinessError businessError); + int GetNewVersionInfo([in] UpgradeInfo info, [out] NewVersionInfo newVersionInfo, + [out] BusinessError businessError); + int GetNewVersionDescription([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] DescriptionOptions descriptionOptions, [out] VersionDescriptionInfo newVersionDescriptionInfo, + [out] BusinessError businessError); + int GetCurrentVersionInfo([in] UpgradeInfo info, [out] CurrentVersionInfo currentVersionInfo, + [out] BusinessError businessError); + int GetCurrentVersionDescription([in] UpgradeInfo info, [in] DescriptionOptions descriptionOptions, + [out] VersionDescriptionInfo currentVersionDescriptionInfo, [out] BusinessError businessError); + int GetTaskInfo([in] UpgradeInfo info, [out] TaskInfo taskInfo, [out] BusinessError businessError); + int SetUpgradePolicy([in] UpgradeInfo info, [in] UpgradePolicy policy, [out] BusinessError businessError); + int GetUpgradePolicy([in] UpgradeInfo info, [out] UpgradePolicy policy, [out] BusinessError businessError); + int Cancel([in] UpgradeInfo info, [in] int service, [out] BusinessError businessError); + int FactoryReset([out] BusinessError businessError); + int ApplyNewVersion([in] UpgradeInfo info, [in] String miscFile, + [in] String[] packageNames, [out] BusinessError businessError); + int VerifyUpgradePackage([in] String packagePath, [in] String keyPath, [out] BusinessError businessError); +} diff --git a/interfaces/inner_api/engine/include/update_callback_stub.h b/interfaces/inner_api/engine/callback/IUpdateCallback.idl similarity index 53% rename from interfaces/inner_api/engine/include/update_callback_stub.h rename to interfaces/inner_api/engine/callback/IUpdateCallback.idl index b9249be138534e7fdfc485d1ffa7b2e0f961ff77..034e7b9dbe8c720a7942b3e9f0c79883cb48bff7 100644 --- a/interfaces/inner_api/engine/include/update_callback_stub.h +++ b/interfaces/inner_api/engine/callback/IUpdateCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,18 +13,8 @@ * limitations under the License. */ -#ifndef UPDATE_CALLBACK_STUB_H -#define UPDATE_CALLBACK_STUB_H +sequenceable OHOS.UpdateEngine.EventInfo; -#include "iremote_stub.h" -#include "iupdate_callback.h" -#include "message_parcel.h" - -namespace OHOS::UpdateEngine { -class UpdateCallbackStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) override; -}; -} // namespace OHOS::UpdateEngine -#endif // UPDATE_CALLBACK_STUB_H +[callback] interface OHOS.UpdateEngine.IUpdateCallback { + void OnEvent([in] EventInfo eventInfo) ; +} diff --git a/interfaces/inner_api/engine/include/update_callback.h b/interfaces/inner_api/engine/include/update_callback.h index 8d83ff6f915f04b5677419b07181723387e02c56..3b5a1b7cb7843b01cc986298f0424a15f22858e7 100644 --- a/interfaces/inner_api/engine/include/update_callback.h +++ b/interfaces/inner_api/engine/include/update_callback.h @@ -28,7 +28,7 @@ public: ~UpdateCallback() override = default; - void OnEvent(const EventInfo &eventInfo) override; + ErrCode OnEvent(const EventInfo &eventInfo) override; private: UpdateCallbackInfo updateCallback_{}; diff --git a/interfaces/inner_api/engine/include/update_service_kits_impl.h b/interfaces/inner_api/engine/include/update_service_kits_impl.h index f04b110539420ab14a29ae1ee4417f90b08b57a7..1f1b1b58da45aa57e5784c3e82318c933561b44c 100644 --- a/interfaces/inner_api/engine/include/update_service_kits_impl.h +++ b/interfaces/inner_api/engine/include/update_service_kits_impl.h @@ -34,57 +34,61 @@ class UpdateServiceKitsImpl final : public UpdateServiceKits, public: DISALLOW_COPY_AND_MOVE(UpdateServiceKitsImpl); - int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb) final; + int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb, int32_t &funcResult) final; - int32_t UnregisterUpdateCallback(const UpgradeInfo &info) final; + int32_t UnregisterUpdateCallback(const UpgradeInfo &info, int32_t &funcResult) final; - int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult) final; + int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult, + int32_t &funcResult) final; int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) final; + const DownloadOptions &downloadOptions, BusinessError &businessError, int32_t &funcResult) final; int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) final; + const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError, int32_t &funcResult) final; int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) final; + const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError, int32_t &funcResult) final; int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) final; + const UpgradeOptions &upgradeOptions, BusinessError &businessError, int32_t &funcResult) final; int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const ClearOptions &clearOptions, BusinessError &businessError) final; + const ClearOptions &clearOptions, BusinessError &businessError, int32_t &funcResult) final; - int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) final; + int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError, int32_t &funcResult) final; int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, - BusinessError &businessError) final; + BusinessError &businessError, int32_t &funcResult) final; int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, - BusinessError &businessError) final; + BusinessError &businessError, int32_t &funcResult) final; int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) final; + BusinessError &businessError, int32_t &funcResult) final; int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, - VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError) final; + VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError, int32_t &funcResult) final; - int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) final; + int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError, + int32_t &funcResult) final; - int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, BusinessError &businessError) final; + int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, BusinessError &businessError, + int32_t &funcResult) final; - int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) final; + int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError, + int32_t &funcResult) final; - int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) final; + int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError, int32_t &funcResult) final; int32_t FactoryReset(BusinessError &businessError) final; int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) final; + const std::vector &packageNames, BusinessError &businessError, int32_t &funcResult) final; int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) final; + BusinessError &businessError, int32_t &funcResult) final; protected: void RegisterCallback() override; diff --git a/interfaces/inner_api/engine/include/update_service_proxy.h b/interfaces/inner_api/engine/include/update_service_proxy.h deleted file mode 100644 index a0655af844c6aed1aa46d7b5a5c0d3f32ac79f99..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/engine/include/update_service_proxy.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#ifndef UPDATE_SERVICE_PROXY_H -#define UPDATE_SERVICE_PROXY_H - -#include "iremote_proxy.h" -#include "iupdate_service.h" - -namespace OHOS { -namespace UpdateEngine { -class UpdateServiceProxy : public IRemoteProxy { -public: - explicit UpdateServiceProxy(const sptr& impl) : IRemoteProxy(impl) {} - - int32_t RegisterUpdateCallback(const UpgradeInfo &info, const sptr& updateCallback) override; - - int32_t UnregisterUpdateCallback(const UpgradeInfo &info) override; - - int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult) override; - - int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) override; - - int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) override; - - int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) override; - - int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) override; - - int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const ClearOptions &clearOptions, BusinessError &businessError) override; - - int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) override; - - int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, - BusinessError &businessError) override; - - int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, - BusinessError &businessError) override; - - int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) override; - - int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, - VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError) override; - - int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) override; - - int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, - BusinessError &businessError) override; - - int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) override; - - int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) override; - - int32_t FactoryReset(BusinessError &businessError) override; - - int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) override; - - int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace UpdateEngine -} // namespace OHOS -#endif // UPDATE_SERVICE_PROXY_H \ No newline at end of file diff --git a/interfaces/inner_api/engine/src/update_callback.cpp b/interfaces/inner_api/engine/src/update_callback.cpp index 181c5966549521ca0de60f368ddeb8fad73a796a..11905571f6bf82a3c2fdf60bd2bc99f40615fd91 100644 --- a/interfaces/inner_api/engine/src/update_callback.cpp +++ b/interfaces/inner_api/engine/src/update_callback.cpp @@ -20,11 +20,12 @@ namespace OHOS::UpdateEngine { UpdateCallback::UpdateCallback(const UpdateCallbackInfo &updateCallback) : updateCallback_(updateCallback) {} -void UpdateCallback::OnEvent(const EventInfo &eventInfo) +ErrCode UpdateCallback::OnEvent(const EventInfo &eventInfo) { ENGINE_LOGI("OnEvent eventId 0x%{public}08x", eventInfo.eventId); if (updateCallback_.onEvent != nullptr) { updateCallback_.onEvent(eventInfo); } + return 0; } } // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/engine/src/update_service_kits_impl.cpp b/interfaces/inner_api/engine/src/update_service_kits_impl.cpp index 060b288883b98b9ebc356544a4acbd706ec6e5cc..0b8c48d475d0f246623a623acdb8601f5be566f5 100644 --- a/interfaces/inner_api/engine/src/update_service_kits_impl.cpp +++ b/interfaces/inner_api/engine/src/update_service_kits_impl.cpp @@ -34,7 +34,8 @@ UpdateServiceKitsImpl::UpdateServiceKitsImpl() : BaseServiceKitsImpl不能修改为auto,否则在重注册时有概率出现Crash sptr remoteUpdateCallback(new UpdateCallback(cb)); ENGINE_CHECK(remoteUpdateCallback != nullptr, return INT_PARAM_ERR, "Failed to create remote callback"); - int32_t ret = updateService->RegisterUpdateCallback(info, remoteUpdateCallback); + int32_t ret = updateService->RegisterUpdateCallback(info, remoteUpdateCallback, funcResult); remoteUpdateCallbackMap_[info] = remoteUpdateCallback; ENGINE_LOGI("RegisterUpdateCallback %{public}s", ret == INT_CALL_SUCCESS ? "success" : "failure"); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "RegisterUpdateCallback ipc error"); return ret; } -int32_t UpdateServiceKitsImpl::UnregisterUpdateCallback(const UpgradeInfo &info) +int32_t UpdateServiceKitsImpl::UnregisterUpdateCallback(const UpgradeInfo &info, int32_t &funcResult) { auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); @@ -59,174 +60,179 @@ int32_t UpdateServiceKitsImpl::UnregisterUpdateCallback(const UpgradeInfo &info) ENGINE_LOGI("UnregisterUpdateCallback"); std::lock_guard lock(remoteServerLock_); remoteUpdateCallbackMap_.erase(info); - int32_t ret = updateService->UnregisterUpdateCallback(info); + int32_t ret = updateService->UnregisterUpdateCallback(info, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "UnregisterUpdateCallback ipc error"); return ret; } int32_t UpdateServiceKitsImpl::CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, - CheckResult &checkResult) + CheckResult &checkResult, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::CheckNewVersion"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->CheckNewVersion(info, businessError, checkResult); + int32_t ret = updateService->CheckNewVersion(info, businessError, checkResult, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "CheckNewVersion ipc error"); return ret; } int32_t UpdateServiceKitsImpl::Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) + const DownloadOptions &downloadOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::Download"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->Download(info, versionDigestInfo, downloadOptions, businessError); + int32_t ret = updateService->Download(info, versionDigestInfo, downloadOptions, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "Download ipc error"); return ret; } int32_t UpdateServiceKitsImpl::PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) + const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::PauseDownload"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->PauseDownload(info, versionDigestInfo, pauseDownloadOptions, businessError); + int32_t ret = updateService->PauseDownload(info, versionDigestInfo, pauseDownloadOptions, businessError, + funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "PauseDownload ipc error"); return ret; } int32_t UpdateServiceKitsImpl::ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) + const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::ResumeDownload"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->ResumeDownload(info, versionDigestInfo, resumeDownloadOptions, businessError); + int32_t ret = updateService->ResumeDownload(info, versionDigestInfo, resumeDownloadOptions, + businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "ResumeDownload ipc error"); return ret; } int32_t UpdateServiceKitsImpl::Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) + const UpgradeOptions &upgradeOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::Upgrade"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->Upgrade(info, versionDigest, upgradeOptions, businessError); + int32_t ret = updateService->Upgrade(info, versionDigest, upgradeOptions, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "Upgrade ipc error"); return ret; } int32_t UpdateServiceKitsImpl::ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const ClearOptions &clearOptions, BusinessError &businessError) + const ClearOptions &clearOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::ClearError"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->ClearError(info, versionDigest, clearOptions, businessError); + int32_t ret = updateService->ClearError(info, versionDigest, clearOptions, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "ClearError ipc error"); return ret; } -int32_t UpdateServiceKitsImpl::TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) +int32_t UpdateServiceKitsImpl::TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError, + int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::TerminateUpgrade"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->TerminateUpgrade(info, businessError); + int32_t ret = updateService->TerminateUpgrade(info, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "TerminateUpgrade ipc error"); return ret; } int32_t UpdateServiceKitsImpl::GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::GetNewVersionInfo"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->GetNewVersionInfo(info, newVersionInfo, businessError); + int32_t ret = updateService->GetNewVersionInfo(info, newVersionInfo, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "GetNewVersionInfo ipc error"); return ret; } int32_t UpdateServiceKitsImpl::GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, const DescriptionOptions &descriptionOptions, - VersionDescriptionInfo &newVersionDescriptionInfo, BusinessError &businessError) + VersionDescriptionInfo &newVersionDescriptionInfo, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::GetNewVersionDescription"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); int32_t ret = updateService->GetNewVersionDescription(info, versionDigestInfo, descriptionOptions, - newVersionDescriptionInfo, businessError); + newVersionDescriptionInfo, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "GetNewVersionDescription ipc error"); return ret; } int32_t UpdateServiceKitsImpl::GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::GetCurrentVersionInfo"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->GetCurrentVersionInfo(info, currentVersionInfo, businessError); + int32_t ret = updateService->GetCurrentVersionInfo(info, currentVersionInfo, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "GetCurrentVersionInfo ipc error"); return ret; } int32_t UpdateServiceKitsImpl::GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, VersionDescriptionInfo ¤tVersionDescriptionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::GetCurrentVersionDescription"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); int32_t ret = updateService->GetCurrentVersionDescription(info, descriptionOptions, currentVersionDescriptionInfo, - businessError); + businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "GetCurrentVersionDescription ipc error"); return ret; } -int32_t UpdateServiceKitsImpl::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) +int32_t UpdateServiceKitsImpl::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError, + int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::GetTaskInfo"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->GetTaskInfo(info, taskInfo, businessError); + int32_t ret = updateService->GetTaskInfo(info, taskInfo, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "GetTaskInfo ipc error"); return ret; } int32_t UpdateServiceKitsImpl::SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::SetUpgradePolicy"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->SetUpgradePolicy(info, policy, businessError); + int32_t ret = updateService->SetUpgradePolicy(info, policy, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "SetUpgradePolicy ipc error"); return ret; } int32_t UpdateServiceKitsImpl::GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::GetUpgradePolicy"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->GetUpgradePolicy(info, policy, businessError); + int32_t ret = updateService->GetUpgradePolicy(info, policy, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "GetUpgradePolicy ipc error"); return ret; } -int32_t UpdateServiceKitsImpl::Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) +int32_t UpdateServiceKitsImpl::Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError, + int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::Cancel %d", service); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->Cancel(info, service, businessError); + int32_t ret = updateService->Cancel(info, service, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "Cancel ipc error"); return ret; } @@ -236,29 +242,30 @@ int32_t UpdateServiceKitsImpl::FactoryReset(BusinessError &businessError) ENGINE_LOGI("UpdateServiceKitsImpl::FactoryReset"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->FactoryReset(businessError); + int32_t funcResult; + int32_t ret = updateService->FactoryReset(businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "FactoryReset ipc error"); return ret; } int32_t UpdateServiceKitsImpl::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) + const std::vector &packageNames, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::ApplyNewVersion"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->ApplyNewVersion(info, miscFile, packageNames, businessError); + int32_t ret = updateService->ApplyNewVersion(info, miscFile, packageNames, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "ApplyNewVersion ipc error"); return ret; } int32_t UpdateServiceKitsImpl::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("UpdateServiceKitsImpl::VerifyUpgradePackage"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->VerifyUpgradePackage(packagePath, keyPath, businessError); + int32_t ret = updateService->VerifyUpgradePackage(packagePath, keyPath, businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "VerifyUpgradePackage ipc error"); return ret; } @@ -266,8 +273,9 @@ int32_t UpdateServiceKitsImpl::VerifyUpgradePackage(const std::string &packagePa void UpdateServiceKitsImpl::RegisterCallback() { ENGINE_LOGI("RegisterUpdateCallback size %{public}zu", remoteUpdateCallbackMap_.size()); + int32_t funcResult; for (auto &iter : remoteUpdateCallbackMap_) { - remoteServer_->RegisterUpdateCallback(iter.first, iter.second); + remoteServer_->RegisterUpdateCallback(iter.first, iter.second, funcResult); } } diff --git a/interfaces/inner_api/engine/src/update_service_proxy.cpp b/interfaces/inner_api/engine/src/update_service_proxy.cpp deleted file mode 100644 index cc2f65f9f62bcaad6f7a658b4f394a1bbf0b805c..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/engine/src/update_service_proxy.cpp +++ /dev/null @@ -1,525 +0,0 @@ -/* - * Copyright (c) 2023 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 "update_service_proxy.h" - -#include "securec.h" - -#include "message_parcel_helper.h" -#include "update_define.h" -#include "update_define.h" -#include "update_log.h" -#include "updater_sa_ipc_interface_code.h" - -namespace OHOS::UpdateEngine { -#define RETURN_WHEN_REMOTE_NULL(remote) \ - ENGINE_CHECK((remote) != nullptr, return INT_CALL_IPC_ERR, "Can not get remote") - -#define IPC_RESULT_TO_CALL_RESULT(result) \ - if ((result) == ERR_NONE) { \ - result = INT_CALL_SUCCESS; \ - } else if ((result) >= CALL_RESULT_OFFSET) { \ - result = (result) - CALL_RESULT_OFFSET; \ - } else { \ - result = INT_CALL_IPC_ERR; \ - } - -#define RETURN_WHEN_TOKEN_WRITE_FAIL(data) \ - if (!(data).WriteInterfaceToken(GetDescriptor())) { \ - ENGINE_LOGE("UpdateServiceProxy WriteInterfaceToken fail"); \ - return INT_CALL_IPC_ERR; \ - } - -#define RETURN_FAIL_WHEN_REMOTE_ERR(methodName, res) \ - do { \ - ENGINE_LOGI("%{public}s is %{public}d", methodName, res); \ - IPC_RESULT_TO_CALL_RESULT(res); \ - ENGINE_CHECK((res) == INT_CALL_SUCCESS, return (res), "Transact error"); \ - } while (0) - -int32_t UpdateServiceProxy::RegisterUpdateCallback(const UpgradeInfo &info, const sptr &updateCallback) -{ - ENGINE_CHECK(updateCallback != nullptr, return INT_PARAM_ERR, "Invalid param"); - ENGINE_LOGI("UpdateServiceProxy::RegisterUpdateCallback"); - - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - bool res = data.WriteRemoteObject(updateCallback->AsObject()); - ENGINE_CHECK(res, return INT_CALL_IPC_ERR, "RegisterUpdateCallback error, WriteRemoteObject fail"); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::REGISTER_CALLBACK), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::RegisterUpdateCallback", ret); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::UnregisterUpdateCallback(const UpgradeInfo &info) -{ - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::UNREGISTER_CALLBACK), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::UnregisterUpdateCallback", ret); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, - CheckResult &checkResult) -{ - ENGINE_LOGI("UpdateServiceProxy::CheckNewVersion"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::CHECK_VERSION), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::CheckNewVersion", ret); - CheckResult result; - BusinessError error; - MessageParcelHelper::ReadBusinessError(reply, error); - MessageParcelHelper::ReadCheckResult(reply, result); - checkResult = result; - businessError = error; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::Download"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::WriteDownloadOptions(data, downloadOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::DOWNLOAD), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::Download", ret); - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::PauseDownload"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::WritePauseDownloadOptions(data, pauseDownloadOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::PAUSE_DOWNLOAD), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::ResumeDownload", ret); - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::ResumeDownload"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::WriteResumeDownloadOptions(data, resumeDownloadOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::RESUME_DOWNLOAD), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::ResumeDownload", ret); - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::Upgrade, versionDigest %{public}s upgradeOptions %{public}d", - versionDigest.versionDigest.c_str(), - upgradeOptions.order); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteVersionDigestInfo(data, versionDigest); - MessageParcelHelper::WriteUpgradeOptions(data, upgradeOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::UPGRADE), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::Upgrade", ret); - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const ClearOptions &clearOptions, BusinessError &businessError) -{ - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteVersionDigestInfo(data, versionDigest); - MessageParcelHelper::WriteClearOptions(data, clearOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::CLEAR_ERROR), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::ClearError", ret); - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) -{ - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::TERMINATE_UPGRADE), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::TerminateUpgrade", ret); - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, - BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::GetNewVersionInfo"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::GetNewVersionInfo", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - NewVersionInfo remoteNewVersionInfo; - MessageParcelHelper::ReadNewVersionInfo(reply, remoteNewVersionInfo); - newVersionInfo = remoteNewVersionInfo; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::GetNewVersionDescription(const UpgradeInfo &info, - const VersionDigestInfo &versionDigestInfo, const DescriptionOptions &descriptionOptions, - VersionDescriptionInfo &newVersionDescriptionInfo, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::GetNewVersionDescription"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::WriteDescriptionOptions(data, descriptionOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION_DESCRIPTION), - data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::GetNewVersionDescription", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - VersionDescriptionInfo remoteVersionDescriptionInfo; - MessageParcelHelper::ReadVersionDescriptionInfo(reply, remoteVersionDescriptionInfo); - newVersionDescriptionInfo = remoteVersionDescriptionInfo; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::GetCurrentVersionInfo"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::GetCurrentVersionInfo", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - CurrentVersionInfo remoteCurrentVersionInfo; - MessageParcelHelper::ReadCurrentVersionInfo(reply, remoteCurrentVersionInfo); - currentVersionInfo = remoteCurrentVersionInfo; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::GetCurrentVersionDescription(const UpgradeInfo &info, - const DescriptionOptions &descriptionOptions, VersionDescriptionInfo ¤tVersionDescriptionInfo, - BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::GetCurrentVersionDescription"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteDescriptionOptions(data, descriptionOptions); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION_DESCRIPTION), - data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::GetCurrentVersionDescription", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - VersionDescriptionInfo remoteVersionDescriptionInfo; - MessageParcelHelper::ReadVersionDescriptionInfo(reply, remoteVersionDescriptionInfo); - currentVersionDescriptionInfo = remoteVersionDescriptionInfo; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::GetTaskInfo"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::GET_TASK_INFO), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::GetTaskInfo", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - TaskInfo remoteTaskInfo; - MessageParcelHelper::ReadTaskInfo(reply, remoteTaskInfo); - taskInfo = remoteTaskInfo; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, - BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::SetUpgradePolicy"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - MessageParcelHelper::WriteUpgradePolicy(data, policy); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::SET_POLICY), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::SetUpgradePolicy", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, - BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::GetUpgradePolicy"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::GET_POLICY), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::GetUpgradePolicy", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - UpgradePolicy remoteUpgradePolicy; - MessageParcelHelper::ReadUpgradePolicy(reply, remoteUpgradePolicy); - policy = remoteUpgradePolicy; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::Cancel"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - data.WriteInt32(static_cast(service)); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::CANCEL), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::Cancel", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::FactoryReset(BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::FactoryReset"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - - MessageParcel reply; - MessageOption option; - int32_t ret = ERR_NONE; // IPC errCode: defined in ipc_types.h -#ifndef UPDATER_UT - ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET), data, reply, option); -#endif - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::FactoryReset", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::ApplyNewVersion"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - MessageParcelHelper::WriteUpgradeInfo(data, info); - data.WriteString16(Str8ToStr16(miscFile)); - data.WriteInt32(static_cast(packageNames.size())); - for (size_t i = 0; i < packageNames.size(); i++) { - data.WriteString16(Str8ToStr16(packageNames[i])); - } - - MessageParcel reply; - MessageOption option; - int32_t ret = ERR_NONE; -#ifndef UPDATER_UT - ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::APPLY_NEW_VERSION), data, reply, option); -#endif - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::ApplyNewVersion", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceProxy::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) -{ - ENGINE_LOGI("UpdateServiceProxy::VerifyUpgradePackage"); - auto remote = Remote(); - RETURN_WHEN_REMOTE_NULL(remote); - - MessageParcel data; - RETURN_WHEN_TOKEN_WRITE_FAIL(data); - data.WriteString16(Str8ToStr16(packagePath)); - data.WriteString16(Str8ToStr16(keyPath)); - - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(CAST_UINT(UpdaterSaInterfaceCode::VERIFY_UPGRADE_PACKAGE), data, reply, option); - RETURN_FAIL_WHEN_REMOTE_ERR("UpdateServiceProxy::VerifyUpgradePackage", ret); - - BusinessError remoteBusinessError; - MessageParcelHelper::ReadBusinessError(reply, remoteBusinessError); - businessError = remoteBusinessError; - return INT_CALL_SUCCESS; -} -} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/check/check_result.h b/interfaces/inner_api/feature/update/model/check/include/check_result.h similarity index 78% rename from interfaces/inner_api/feature/update/model/check/check_result.h rename to interfaces/inner_api/feature/update/model/check/include/check_result.h index 828fe406827b733c70f30b022e1b5f5a55b17b65..09a9a362afde6f93eb28e134075e9b8f469943e4 100644 --- a/interfaces/inner_api/feature/update/model/check/check_result.h +++ b/interfaces/inner_api/feature/update/model/check/include/check_result.h @@ -16,12 +16,18 @@ #ifndef UPDATE_SERVICE_CHECK_RESULT_H #define UPDATE_SERVICE_CHECK_RESULT_H +#include "message_parcel_helper.h" #include "new_version_info.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct CheckResult { +struct CheckResult : public Parcelable { bool isExistNewVersion = false; NewVersionInfo newVersionInfo; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static CheckResult *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_CHECK_RESULT_H diff --git a/interfaces/inner_api/feature/update/model/check/search_status.h b/interfaces/inner_api/feature/update/model/check/include/search_status.h similarity index 100% rename from interfaces/inner_api/feature/update/model/check/search_status.h rename to interfaces/inner_api/feature/update/model/check/include/search_status.h diff --git a/interfaces/inner_api/feature/update/model/check/src/check_result.cpp b/interfaces/inner_api/feature/update/model/check/src/check_result.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44a035af505647e3dd121f53c39a3d40ede165d2 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/check/src/check_result.cpp @@ -0,0 +1,58 @@ +/* + * 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 "check_result.h" + +namespace OHOS::UpdateEngine { +bool CheckResult::ReadFromParcel(Parcel &parcel) +{ + isExistNewVersion = parcel.ReadBool(); + newVersionInfo.versionDigestInfo.versionDigest = Str16ToStr8(parcel.ReadString16()); + MessageParcelHelper::ReadVersionComponents(parcel, newVersionInfo.versionComponents); + return true; +} + +bool CheckResult::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteBool(isExistNewVersion)) { + ENGINE_LOGE("Write isExistNewVersion failed"); + return false; + } + + if (!parcel.WriteString16(Str8ToStr16(newVersionInfo.versionDigestInfo.versionDigest))) { + ENGINE_LOGE("Write versionDigest failed"); + return false; + } + + MessageParcelHelper::WriteVersionComponents(parcel, newVersionInfo.versionComponents); + return true; +} + +CheckResult *CheckResult::Unmarshalling(Parcel &parcel) +{ + CheckResult *checkResult = new (std::nothrow) CheckResult(); + if (checkResult == nullptr) { + ENGINE_LOGE("Create checkResult failed"); + return nullptr; + } + + if (!checkResult->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete checkResult; + return nullptr; + } + return checkResult; +} +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/clear/clear_options.h b/interfaces/inner_api/feature/update/model/clear/clear_options.h index 5b8abe891fe747f93c5ea6b01eb5874950ef8d71..ce9269397cdfc97157a84232ba072b69c0a66678 100644 --- a/interfaces/inner_api/feature/update/model/clear/clear_options.h +++ b/interfaces/inner_api/feature/update/model/clear/clear_options.h @@ -17,10 +17,15 @@ #define UPDATE_SERVICE_CLEAR_OPTIONS_H #include "upgrade_status.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct ClearOptions { +struct ClearOptions : public Parcelable { UpgradeStatus status = UpgradeStatus::INIT; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static ClearOptions *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_CLEAR_OPTIONS_H diff --git a/interfaces/inner_api/feature/update/model/download/download_options.h b/interfaces/inner_api/feature/update/model/download/download_options.h index d8e380971847043eecb482395ec40dc8995f5ed4..19efb06535bead9d79aba359932255d875b7cf2a 100644 --- a/interfaces/inner_api/feature/update/model/download/download_options.h +++ b/interfaces/inner_api/feature/update/model/download/download_options.h @@ -18,11 +18,17 @@ #include "network_type.h" #include "order.h" +#include "parcel.h" +#include "update_log.h" namespace OHOS::UpdateEngine { -struct DownloadOptions { +struct DownloadOptions : public Parcelable { NetType allowNetwork = NetType::WIFI; Order order = Order::DOWNLOAD; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static DownloadOptions *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_DOWNLOAD_OPTIONS_H diff --git a/interfaces/inner_api/feature/update/model/download/pause_download_options.h b/interfaces/inner_api/feature/update/model/download/pause_download_options.h index bd26b4de2ae44f42eec5c06c482bbd3cb28dcc83..e77d514df9b44d0a9a563c8d80bea4a15a5f3b10 100644 --- a/interfaces/inner_api/feature/update/model/download/pause_download_options.h +++ b/interfaces/inner_api/feature/update/model/download/pause_download_options.h @@ -16,9 +16,15 @@ #ifndef UPDATE_SERVICE_PAUSE_DOWNLOAD_OPTIONS_H #define UPDATE_SERVICE_PAUSE_DOWNLOAD_OPTIONS_H +#include "parcel.h" + namespace OHOS::UpdateEngine { -struct PauseDownloadOptions { +struct PauseDownloadOptions : public Parcelable { bool isAllowAutoResume = false; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static PauseDownloadOptions *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_PAUSE_DOWNLOAD_OPTIONS_H diff --git a/interfaces/inner_api/feature/update/model/download/resume_download_options.h b/interfaces/inner_api/feature/update/model/download/resume_download_options.h index 22a35d16c1df4b2f2d6a079467f002f0047d4533..d2d1c8011e4fb7f65048a983ee45167634cade57 100644 --- a/interfaces/inner_api/feature/update/model/download/resume_download_options.h +++ b/interfaces/inner_api/feature/update/model/download/resume_download_options.h @@ -17,10 +17,15 @@ #define UPDATE_SERVICE_RESUME_DOWNLOAD_OPTIONS_H #include "network_type.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct ResumeDownloadOptions { +struct ResumeDownloadOptions : public Parcelable { NetType allowNetwork = NetType::WIFI; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static ResumeDownloadOptions *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_RESUME_DOWNLOAD_OPTIONS_H diff --git a/interfaces/inner_api/feature/update/model/event/event_info.h b/interfaces/inner_api/feature/update/model/event/event_info.h index 461d58f61d174330fdbb1d7bb88cbd57721f9cea..4a38b2756037fabd5a9f6d73a38e5052072341a9 100644 --- a/interfaces/inner_api/feature/update/model/event/event_info.h +++ b/interfaces/inner_api/feature/update/model/event/event_info.h @@ -16,12 +16,18 @@ #ifndef UPDATE_SERVICE_EVENT_INFO_H #define UPDATE_SERVICE_EVENT_INFO_H +#include + #include "base_json_struct.h" +#include "error_message.h" #include "event_id.h" +#include "message_parcel_helper.h" +#include "parcel.h" #include "task_body.h" +#include "version_component.h" namespace OHOS::UpdateEngine { -struct EventInfo : public BaseJsonStruct { +struct EventInfo : public BaseJsonStruct, public Parcelable { EventId eventId = EventId::EVENT_TASK_BASE; TaskBody taskBody; @@ -29,6 +35,12 @@ struct EventInfo : public BaseJsonStruct { EventInfo(EventId id, TaskBody body) : eventId(id), taskBody(std::move(body)) {} JsonBuilder GetJsonBuilder() final; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static EventInfo *Unmarshalling(Parcel &parcel); + void ReadTaskBodyEvent(Parcel &parcel); + void WriteTaskBodyEvent(Parcel &parcel) const; }; } // OHOS::UpdateEngine #endif // UPDATE_SERVICE_EVENT_INFO_H diff --git a/interfaces/inner_api/feature/update/model/event/src/event_info.cpp b/interfaces/inner_api/feature/update/model/event/src/event_info.cpp index ffea4a75379d7961b55929f25abb49faa8e9c3e2..663db5942b019ede9ee47a35b8533268bf4c50dd 100644 --- a/interfaces/inner_api/feature/update/model/event/src/event_info.cpp +++ b/interfaces/inner_api/feature/update/model/event/src/event_info.cpp @@ -15,6 +15,7 @@ #include "event_info.h" #include "update_define.h" +#include "update_log.h" namespace OHOS::UpdateEngine { JsonBuilder EventInfo::GetJsonBuilder() @@ -25,4 +26,60 @@ JsonBuilder EventInfo::GetJsonBuilder() .Append("taskBody", taskBody.GetJsonBuilder(eventId)) .Append("}"); } + +bool EventInfo::ReadFromParcel(Parcel &parcel) +{ + eventId = static_cast(parcel.ReadUint32()); + ReadTaskBodyEvent(parcel); + return true; +} + +void EventInfo::ReadTaskBodyEvent(Parcel &parcel) +{ + taskBody.versionDigestInfo.versionDigest = Str16ToStr8(parcel.ReadString16()); + taskBody.status = static_cast(parcel.ReadInt32()); + taskBody.subStatus = parcel.ReadInt32(); + taskBody.progress = parcel.ReadInt32(); + taskBody.installMode = parcel.ReadInt32(); + MessageParcelHelper::ReadErrorMessages(parcel, taskBody.errorMessages); + MessageParcelHelper::ReadVersionComponents(parcel, taskBody.versionComponents); +} + +void EventInfo::WriteTaskBodyEvent(Parcel &parcel) const +{ + parcel.WriteString16(Str8ToStr16(taskBody.versionDigestInfo.versionDigest)); + parcel.WriteInt32(static_cast(taskBody.status)); + parcel.WriteInt32(taskBody.subStatus); + parcel.WriteInt32(taskBody.progress); + parcel.WriteInt32(taskBody.installMode); + + MessageParcelHelper::WriteErrorMessages(parcel, taskBody.errorMessages); + MessageParcelHelper::WriteVersionComponents(parcel, taskBody.versionComponents); +} + +bool EventInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(eventId))) { + ENGINE_LOGE("WriteBool eventId failed"); + return false; + } + WriteTaskBodyEvent(parcel); + return true; +} + +EventInfo *EventInfo::Unmarshalling(Parcel &parcel) +{ + EventInfo *eventInfo = new (std::nothrow) EventInfo(); + if (eventInfo == nullptr) { + ENGINE_LOGE("Create eventInfo failed"); + return nullptr; + } + + if (!eventInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete eventInfo; + return nullptr; + } + return eventInfo; +} } // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/interfaces/inner_api/feature/update/model/message_parcel/include/message_parcel_helper.h b/interfaces/inner_api/feature/update/model/message_parcel/include/message_parcel_helper.h index 0990c551d44780f20444de66f74b4efd2e5430b9..043718e57e85a8f60a1ec06b9c64e1210a5f03b8 100644 --- a/interfaces/inner_api/feature/update/model/message_parcel/include/message_parcel_helper.h +++ b/interfaces/inner_api/feature/update/model/message_parcel/include/message_parcel_helper.h @@ -17,77 +17,29 @@ #define MESSAGE_PARCEL_HELPER_H #include +#include + +#include "component_description.h" +#include "error_message.h" -#include "business_error.h" -#include "check_result.h" -#include "clear_options.h" -#include "current_version_info.h" -#include "description_options.h" -#include "download_options.h" -#include "event_info.h" -#include "message_parcel.h" -#include "new_version_info.h" #include "parcel.h" -#include "pause_download_options.h" -#include "resume_download_options.h" -#include "task_info.h" -#include "upgrade_info.h" -#include "upgrade_options.h" -#include "upgrade_policy.h" -#include "version_description_info.h" -#include "version_digest_info.h" +#include "task_body.h" +#include "version_component.h" namespace OHOS::UpdateEngine { +static constexpr int32_t MAX_VECTOR_SIZE = 128; class MessageParcelHelper { public: - static int32_t ReadUpgradeInfo(MessageParcel &reply, UpgradeInfo &info); - static int32_t WriteUpgradeInfo(MessageParcel &data, const UpgradeInfo &info); - - static int32_t ReadVersionDescriptionInfo(MessageParcel &reply, VersionDescriptionInfo &newVersionDescriptionInfo); - static int32_t WriteVersionDescriptionInfo(MessageParcel &data, - const VersionDescriptionInfo &newVersionDescriptionInfo); - - static int32_t ReadBusinessError(MessageParcel &reply, BusinessError &businessError); - static int32_t WriteBusinessError(MessageParcel &data, const BusinessError &businessError); - - static int32_t ReadCheckResult(MessageParcel &reply, CheckResult &checkResult); - static int32_t WriteCheckResult(MessageParcel &data, const CheckResult &checkResult); - - static int32_t ReadNewVersionInfo(MessageParcel &reply, NewVersionInfo &newVersionInfo); - static int32_t WriteNewVersionInfo(MessageParcel &data, const NewVersionInfo &newVersionInfo); - - static int32_t ReadCurrentVersionInfo(MessageParcel &reply, CurrentVersionInfo &info); - static int32_t WriteCurrentVersionInfo(MessageParcel &data, const CurrentVersionInfo &info); - - static int32_t ReadTaskInfo(MessageParcel &reply, TaskInfo &info); - static int32_t WriteTaskInfo(MessageParcel &data, const TaskInfo &info); - - static int32_t ReadUpgradePolicy(MessageParcel &reply, UpgradePolicy &policy); - static int32_t WriteUpgradePolicy(MessageParcel &data, const UpgradePolicy &policy); - - static int32_t ReadEventInfo(MessageParcel &reply, EventInfo &eventInfo); - static int32_t WriteEventInfo(MessageParcel &data, const EventInfo &eventInfo); - - static int32_t ReadVersionDigestInfo(MessageParcel &reply, VersionDigestInfo &versionDigestInfo); - static int32_t WriteVersionDigestInfo(MessageParcel &data, const VersionDigestInfo &versionDigestInfo); - - static int32_t ReadDescriptionOptions(MessageParcel &reply, DescriptionOptions &descriptionOptions); - static int32_t WriteDescriptionOptions(MessageParcel &data, const DescriptionOptions &descriptionOptions); - - static int32_t ReadDownloadOptions(MessageParcel &reply, DownloadOptions &downloadOptions); - static int32_t WriteDownloadOptions(MessageParcel &data, const DownloadOptions &downloadOptions); - - static int32_t ReadPauseDownloadOptions(MessageParcel &reply, PauseDownloadOptions &pauseDownloadOptions); - static int32_t WritePauseDownloadOptions(MessageParcel &data, const PauseDownloadOptions &pauseDownloadOptions); - - static int32_t ReadResumeDownloadOptions(MessageParcel &reply, ResumeDownloadOptions &resumeDownloadOptions); - static int32_t WriteResumeDownloadOptions(MessageParcel &data, const ResumeDownloadOptions &resumeDownloadOptions); - - static int32_t ReadUpgradeOptions(MessageParcel &reply, UpgradeOptions &upgradeOptions); - static int32_t WriteUpgradeOptions(MessageParcel &data, const UpgradeOptions &upgradeOptions); - - static int32_t ReadClearOptions(MessageParcel &reply, ClearOptions &clearOptions); - static int32_t WriteClearOptions(MessageParcel &data, const ClearOptions &clearOptions); + static bool ReadErrorMessages(Parcel &reply, std::vector &errorMessages); + static bool WriteErrorMessages(Parcel &data, const std::vector &errorMessages); + static bool ReadTaskBody(Parcel &reply, TaskBody &taskBody); + static bool WriteTaskBody(Parcel &data, const TaskBody &taskBody); + static bool ReadVersionComponents(Parcel &reply, std::vector &versionComponents); + static bool WriteVersionComponents(Parcel &data, const std::vector &versionComponents); + static bool ReadComponentDescriptions(Parcel &reply, std::vector &componentDescriptions); + static bool WriteComponentDescriptions(Parcel &data, + const std::vector &componentDescriptions); }; } // namespace OHOS::UpdateEngine #endif // MESSAGE_PARCEL_HELPER_H + diff --git a/interfaces/inner_api/feature/update/model/message_parcel/src/message_parcel_helper.cpp b/interfaces/inner_api/feature/update/model/message_parcel/src/message_parcel_helper.cpp index 6e2f93c724b9696a81a2d6c9b8aea06b7c59cd8a..a95d8a178d120d24da5f38f355963ec9362548d2 100644 --- a/interfaces/inner_api/feature/update/model/message_parcel/src/message_parcel_helper.cpp +++ b/interfaces/inner_api/feature/update/model/message_parcel/src/message_parcel_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -22,17 +22,14 @@ #include "update_log.h" -namespace OHOS { -namespace UpdateEngine { -static constexpr int32_t MAX_VECTOR_SIZE = 128; - -void ReadErrorMessages(MessageParcel &reply, std::vector &errorMessages) +namespace OHOS::UpdateEngine { +bool MessageParcelHelper::ReadErrorMessages(Parcel &reply, std::vector &errorMessages) { int32_t size = reply.ReadInt32(); // codecheck warning fix if (size > MAX_VECTOR_SIZE) { ENGINE_LOGE("ReadErrorMessages size is over MAX_VECTOR_SIZE, size=%{public}d", size); - return; + return false; } for (size_t i = 0; i < static_cast(size); i++) { ErrorMessage errorMsg; @@ -40,107 +37,57 @@ void ReadErrorMessages(MessageParcel &reply, std::vector &errorMes errorMsg.errorMessage = Str16ToStr8(reply.ReadString16()); errorMessages.push_back(errorMsg); } + return true; } -void WriteErrorMessages(MessageParcel &data, const std::vector &errorMessages) +bool MessageParcelHelper::WriteErrorMessages(Parcel &data, const std::vector &errorMessages) { data.WriteInt32(static_cast(errorMessages.size())); for (size_t i = 0; i < errorMessages.size(); i++) { data.WriteInt32(errorMessages[i].errorCode); data.WriteString16(Str8ToStr16(errorMessages[i].errorMessage)); } + return true; } -void ReadComponentDescriptions(MessageParcel &reply, std::vector &componentDescriptions) +bool MessageParcelHelper::ReadTaskBody(Parcel &reply, TaskBody &taskBody) { - int32_t size = reply.ReadInt32(); - if (size > MAX_VECTOR_SIZE) { - ENGINE_LOGE("ReadComponentDescriptions size is over MAX_VECTOR_SIZE, size=%{public}d", size); - return; + taskBody.versionDigestInfo.versionDigest = Str16ToStr8(reply.ReadString16()); + taskBody.status = static_cast(reply.ReadInt32()); + taskBody.subStatus = reply.ReadInt32(); + taskBody.progress = reply.ReadInt32(); + taskBody.installMode = reply.ReadInt32(); + if (!ReadErrorMessages(reply, taskBody.errorMessages)) { + return false; } - for (size_t i = 0; i < static_cast(size); i++) { - ComponentDescription componentDescription; - componentDescription.componentId = Str16ToStr8(reply.ReadString16()); - componentDescription.descriptionInfo.descriptionType = static_cast(reply.ReadUint32()); - componentDescription.descriptionInfo.content = Str16ToStr8(reply.ReadString16()); - componentDescription.notifyDescriptionInfo.descriptionType = static_cast(reply.ReadUint32()); - componentDescription.notifyDescriptionInfo.content = Str16ToStr8(reply.ReadString16()); - componentDescriptions.push_back(componentDescription); + if (!ReadVersionComponents(reply, taskBody.versionComponents)) { + return false; } + return true; } -void WriteComponentDescriptions(MessageParcel &data, const std::vector &componentDescriptions) +bool MessageParcelHelper::WriteTaskBody(Parcel &data, const TaskBody &taskBody) { - data.WriteInt32(static_cast(componentDescriptions.size())); - for (size_t i = 0; i < componentDescriptions.size(); i++) { - data.WriteString16(Str8ToStr16(componentDescriptions[i].componentId)); - data.WriteUint32(static_cast(componentDescriptions[i].descriptionInfo.descriptionType)); - data.WriteString16(Str8ToStr16(componentDescriptions[i].descriptionInfo.content)); - data.WriteUint32(static_cast(componentDescriptions[i].notifyDescriptionInfo.descriptionType)); - data.WriteString16(Str8ToStr16(componentDescriptions[i].notifyDescriptionInfo.content)); + data.WriteString16(Str8ToStr16(taskBody.versionDigestInfo.versionDigest)); + data.WriteInt32(static_cast(taskBody.status)); + data.WriteInt32(taskBody.subStatus); + data.WriteInt32(taskBody.progress); + data.WriteInt32(taskBody.installMode); + if (WriteErrorMessages(data, taskBody.errorMessages)) { + return false; } + if (WriteVersionComponents(data, taskBody.versionComponents)) { + return false; + } + return true; } -int32_t MessageParcelHelper::ReadUpgradeInfo(MessageParcel &reply, UpgradeInfo &info) -{ - info.upgradeApp = Str16ToStr8(reply.ReadString16()); - info.businessType.vendor = Str16ToStr8(reply.ReadString16()); - info.businessType.subType = static_cast(reply.ReadInt32()); - info.upgradeDevId = Str16ToStr8(reply.ReadString16()); - info.controlDevId = Str16ToStr8(reply.ReadString16()); - info.processId = reply.ReadInt32(); - info.deviceType = static_cast(reply.ReadInt32()); - return 0; -} - -int32_t MessageParcelHelper::WriteUpgradeInfo(MessageParcel &data, const UpgradeInfo &info) -{ - data.WriteString16(Str8ToStr16(info.upgradeApp)); - data.WriteString16(Str8ToStr16(info.businessType.vendor)); - data.WriteInt32(static_cast(info.businessType.subType)); - data.WriteString16(Str8ToStr16(info.upgradeDevId)); - data.WriteString16(Str8ToStr16(info.controlDevId)); - data.WriteInt32(info.processId); - data.WriteInt32(static_cast(info.deviceType)); - return 0; -} - -int32_t MessageParcelHelper::ReadVersionDescriptionInfo( - MessageParcel &reply, VersionDescriptionInfo &versionDescriptionInfo) -{ - ReadComponentDescriptions(reply, versionDescriptionInfo.componentDescriptions); - return 0; -} - -int32_t MessageParcelHelper::WriteVersionDescriptionInfo( - MessageParcel &data, const VersionDescriptionInfo &versionDescriptionInfo) -{ - WriteComponentDescriptions(data, versionDescriptionInfo.componentDescriptions); - return 0; -} - -int32_t MessageParcelHelper::ReadBusinessError(MessageParcel &reply, BusinessError &businessError) -{ - businessError.message = Str16ToStr8(reply.ReadString16()); - businessError.errorNum = static_cast(reply.ReadInt32()); - ReadErrorMessages(reply, businessError.data); - return 0; -} - -int32_t MessageParcelHelper::WriteBusinessError(MessageParcel &data, const BusinessError &businessError) -{ - data.WriteString16(Str8ToStr16(businessError.message)); - data.WriteInt32(static_cast(businessError.errorNum)); - WriteErrorMessages(data, businessError.data); - return 0; -} - -void ReadVersionComponents(MessageParcel &reply, std::vector &versionComponents) +bool MessageParcelHelper::ReadVersionComponents(Parcel &reply, std::vector &versionComponents) { int32_t size = reply.ReadInt32(); if (size > MAX_VECTOR_SIZE) { ENGINE_LOGE("ReadVersionComponents size is over MAX_VECTOR_SIZE, size=%{public}d", size); - return; + return false; } for (size_t i = 0; i < static_cast(size); i++) { VersionComponent versionComponent; @@ -158,9 +105,11 @@ void ReadVersionComponents(MessageParcel &reply, std::vector & versionComponent.componentExtra = Str16ToStr8(reply.ReadString16()); versionComponents.push_back(versionComponent); } + return true; } -void WriteVersionComponents(MessageParcel &data, const std::vector &versionComponents) +bool MessageParcelHelper::WriteVersionComponents(Parcel &data, + const std::vector &versionComponents) { data.WriteInt32(static_cast(versionComponents.size())); for (size_t i = 0; i < versionComponents.size(); i++) { @@ -178,231 +127,40 @@ void WriteVersionComponents(MessageParcel &data, const std::vectordescriptionInfo.content)); data.WriteString16(Str8ToStr16(versionComponent->componentExtra)); } + return true; } -void ReadNewVersionInfoEx(MessageParcel &reply, NewVersionInfo &newVersionInfo) -{ - newVersionInfo.versionDigestInfo.versionDigest = Str16ToStr8(reply.ReadString16()); - ReadVersionComponents(reply, newVersionInfo.versionComponents); -} - -void WriteNewVersionInfoEx(MessageParcel &data, const NewVersionInfo &newVersionInfo) -{ - data.WriteString16(Str8ToStr16(newVersionInfo.versionDigestInfo.versionDigest)); - WriteVersionComponents(data, newVersionInfo.versionComponents); -} - -int32_t MessageParcelHelper::ReadCheckResult(MessageParcel &reply, CheckResult &checkResult) -{ - checkResult.isExistNewVersion = reply.ReadBool(); - ReadNewVersionInfoEx(reply, checkResult.newVersionInfo); - return 0; -} - -int32_t MessageParcelHelper::WriteCheckResult(MessageParcel &data, const CheckResult &checkResult) -{ - data.WriteBool(checkResult.isExistNewVersion); - WriteNewVersionInfoEx(data, checkResult.newVersionInfo); - return 0; -} - -int32_t MessageParcelHelper::ReadNewVersionInfo(MessageParcel &reply, NewVersionInfo &newVersionInfo) -{ - ReadNewVersionInfoEx(reply, newVersionInfo); - return 0; -} - -int32_t MessageParcelHelper::WriteNewVersionInfo(MessageParcel &data, const NewVersionInfo &newVersionInfo) -{ - WriteNewVersionInfoEx(data, newVersionInfo); - return 0; -} - -int32_t MessageParcelHelper::ReadCurrentVersionInfo(MessageParcel &reply, CurrentVersionInfo &info) -{ - info.osVersion = Str16ToStr8(reply.ReadString16()); - info.deviceName = Str16ToStr8(reply.ReadString16()); - ReadVersionComponents(reply, info.versionComponents); - return 0; -} - -int32_t MessageParcelHelper::WriteCurrentVersionInfo(MessageParcel &data, const CurrentVersionInfo &info) -{ - data.WriteString16(Str8ToStr16(info.osVersion)); - data.WriteString16(Str8ToStr16(info.deviceName)); - WriteVersionComponents(data, info.versionComponents); - return 0; -} - -void ReadTaskBody(MessageParcel &reply, TaskBody &taskBody) -{ - taskBody.versionDigestInfo.versionDigest = Str16ToStr8(reply.ReadString16()); - taskBody.status = static_cast(reply.ReadInt32()); - taskBody.subStatus = reply.ReadInt32(); - taskBody.progress = reply.ReadInt32(); - taskBody.installMode = reply.ReadInt32(); - ReadErrorMessages(reply, taskBody.errorMessages); - ReadVersionComponents(reply, taskBody.versionComponents); -} - -void WriteTaskBody(MessageParcel &data, const TaskBody &taskBody) +bool MessageParcelHelper::ReadComponentDescriptions(Parcel &reply, + std::vector &componentDescriptions) { - data.WriteString16(Str8ToStr16(taskBody.versionDigestInfo.versionDigest)); - data.WriteInt32(static_cast(taskBody.status)); - data.WriteInt32(taskBody.subStatus); - data.WriteInt32(taskBody.progress); - data.WriteInt32(taskBody.installMode); - WriteErrorMessages(data, taskBody.errorMessages); - WriteVersionComponents(data, taskBody.versionComponents); -} - -int32_t MessageParcelHelper::ReadTaskInfo(MessageParcel &reply, TaskInfo &info) -{ - info.existTask = reply.ReadBool(); - ReadTaskBody(reply, info.taskBody); - return 0; -} - -int32_t MessageParcelHelper::WriteTaskInfo(MessageParcel &data, const TaskInfo &info) -{ - data.WriteBool(info.existTask); - WriteTaskBody(data, info.taskBody); - return 0; -} - -int32_t MessageParcelHelper::ReadUpgradePolicy(MessageParcel &reply, UpgradePolicy &policy) -{ - policy.downloadStrategy = static_cast(reply.ReadBool()); - policy.autoUpgradeStrategy = static_cast(reply.ReadBool()); - size_t size = static_cast(reply.ReadInt32()); - size_t arraySize = COUNT_OF(policy.autoUpgradePeriods); + int32_t size = reply.ReadInt32(); if (size > MAX_VECTOR_SIZE) { - ENGINE_LOGE("ReadUpgradePolicy size is over MAX_VECTOR_SIZE, size=%{public}zu", size); - return -1; + ENGINE_LOGE("ReadComponentDescriptions size is over MAX_VECTOR_SIZE, size=%{public}d", size); + return false; } - for (size_t i = 0; (i < size) && (i < arraySize); i++) { - policy.autoUpgradePeriods[i].start = reply.ReadUint32(); - policy.autoUpgradePeriods[i].end = reply.ReadUint32(); + for (size_t i = 0; i < static_cast(size); i++) { + ComponentDescription componentDescription; + componentDescription.componentId = Str16ToStr8(reply.ReadString16()); + componentDescription.descriptionInfo.descriptionType = static_cast(reply.ReadUint32()); + componentDescription.descriptionInfo.content = Str16ToStr8(reply.ReadString16()); + componentDescription.notifyDescriptionInfo.descriptionType = static_cast(reply.ReadUint32()); + componentDescription.notifyDescriptionInfo.content = Str16ToStr8(reply.ReadString16()); + componentDescriptions.push_back(componentDescription); } - return 0; + return true; } -int32_t MessageParcelHelper::WriteUpgradePolicy(MessageParcel &data, const UpgradePolicy &policy) +bool MessageParcelHelper::WriteComponentDescriptions(Parcel &data, + const std::vector &componentDescriptions) { - data.WriteBool(policy.downloadStrategy); - data.WriteBool(policy.autoUpgradeStrategy); - int32_t size = static_cast(COUNT_OF(policy.autoUpgradePeriods)); - data.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - data.WriteUint32(policy.autoUpgradePeriods[i].start); - data.WriteUint32(policy.autoUpgradePeriods[i].end); + data.WriteInt32(static_cast(componentDescriptions.size())); + for (size_t i = 0; i < componentDescriptions.size(); i++) { + data.WriteString16(Str8ToStr16(componentDescriptions[i].componentId)); + data.WriteUint32(static_cast(componentDescriptions[i].descriptionInfo.descriptionType)); + data.WriteString16(Str8ToStr16(componentDescriptions[i].descriptionInfo.content)); + data.WriteUint32(static_cast(componentDescriptions[i].notifyDescriptionInfo.descriptionType)); + data.WriteString16(Str8ToStr16(componentDescriptions[i].notifyDescriptionInfo.content)); } - return 0; -} - -int32_t MessageParcelHelper::ReadEventInfo(MessageParcel &reply, EventInfo &eventInfo) -{ - eventInfo.eventId = static_cast(reply.ReadUint32()); - ReadTaskBody(reply, eventInfo.taskBody); - return 0; -} - -int32_t MessageParcelHelper::WriteEventInfo(MessageParcel &data, const EventInfo &eventInfo) -{ - data.WriteUint32(static_cast(eventInfo.eventId)); - WriteTaskBody(data, eventInfo.taskBody); - return 0; -} - -int32_t MessageParcelHelper::ReadVersionDigestInfo(MessageParcel &reply, VersionDigestInfo &versionDigestInfo) -{ - versionDigestInfo.versionDigest = Str16ToStr8(reply.ReadString16()); - return 0; -} - -int32_t MessageParcelHelper::WriteVersionDigestInfo(MessageParcel &data, const VersionDigestInfo &versionDigestInfo) -{ - data.WriteString16(Str8ToStr16(versionDigestInfo.versionDigest)); - return 0; -} - -int32_t MessageParcelHelper::ReadDescriptionOptions(MessageParcel &reply, DescriptionOptions &descriptionOptions) -{ - descriptionOptions.format = static_cast(reply.ReadUint32()); - descriptionOptions.language = Str16ToStr8(reply.ReadString16()); - return 0; -} - -int32_t MessageParcelHelper::WriteDescriptionOptions(MessageParcel &data, const DescriptionOptions &descriptionOptions) -{ - data.WriteUint32(static_cast(descriptionOptions.format)); - data.WriteString16(Str8ToStr16(descriptionOptions.language)); - return 0; -} - -int32_t MessageParcelHelper::ReadDownloadOptions(MessageParcel &reply, DownloadOptions &downloadOptions) -{ - downloadOptions.allowNetwork = static_cast(reply.ReadUint32()); - downloadOptions.order = static_cast(reply.ReadUint32()); - return 0; -} - -int32_t MessageParcelHelper::WriteDownloadOptions(MessageParcel &data, const DownloadOptions &downloadOptions) -{ - data.WriteUint32(static_cast(downloadOptions.allowNetwork)); - data.WriteUint32(static_cast(downloadOptions.order)); - return 0; -} - -int32_t MessageParcelHelper::ReadPauseDownloadOptions(MessageParcel &reply, PauseDownloadOptions &pauseDownloadOptions) -{ - pauseDownloadOptions.isAllowAutoResume = reply.ReadBool(); - return 0; -} - -int32_t MessageParcelHelper::WritePauseDownloadOptions( - MessageParcel &data, const PauseDownloadOptions &pauseDownloadOptions) -{ - data.WriteBool(pauseDownloadOptions.isAllowAutoResume); - return 0; -} - -int32_t MessageParcelHelper::ReadResumeDownloadOptions( - MessageParcel &reply, ResumeDownloadOptions &resumeDownloadOptions) -{ - resumeDownloadOptions.allowNetwork = static_cast(reply.ReadUint32()); - return 0; -} - -int32_t MessageParcelHelper::WriteResumeDownloadOptions( - MessageParcel &data, const ResumeDownloadOptions &resumeDownloadOptions) -{ - data.WriteUint32(static_cast(resumeDownloadOptions.allowNetwork)); - return 0; -} - -int32_t MessageParcelHelper::ReadUpgradeOptions(MessageParcel &reply, UpgradeOptions &upgradeOptions) -{ - upgradeOptions.order = static_cast(reply.ReadUint32()); - return 0; -} - -int32_t MessageParcelHelper::WriteUpgradeOptions(MessageParcel &data, const UpgradeOptions &upgradeOptions) -{ - data.WriteUint32(static_cast(upgradeOptions.order)); - return 0; -} - -int32_t MessageParcelHelper::ReadClearOptions(MessageParcel &reply, ClearOptions &clearOptions) -{ - clearOptions.status = static_cast(reply.ReadUint32()); - return 0; -} - -int32_t MessageParcelHelper::WriteClearOptions(MessageParcel &data, const ClearOptions &clearOptions) -{ - data.WriteUint32(static_cast(clearOptions.status)); - return 0; + return true; } -} // namespace UpdateEngine -} // namespace OHOS +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/model.gni b/interfaces/inner_api/feature/update/model/model.gni index 2dba0c796537466749e04f3d277397f4644158dd..2fcac28ad53d1ccaf6fddaba4aa3ef3716e8245a 100644 --- a/interfaces/inner_api/feature/update/model/model.gni +++ b/interfaces/inner_api/feature/update/model/model.gni @@ -14,7 +14,7 @@ model_external_deps = [] model_deps = [] model_include = [ - "../feature/update/model/check", + "../feature/update/model/check/include", "../feature/update/model/clear", "../feature/update/model/common", "../feature/update/model/download", @@ -22,24 +22,37 @@ model_include = [ "../feature/update/model/event/on_off", "../feature/update/model/install", "../feature/update/model/message_parcel/include", - "../feature/update/model/policy", + "../feature/update/model/policy/include", "../feature/update/model/subscribe", - "../feature/update/model/task", + "../feature/update/model/task/include", "../feature/update/model/upgrade", - "../feature/update/model/upgrade_info", + "../feature/update/model/upgrade_info/include", "../feature/update/model/version_info", - "../feature/update/model/version_info/current_version", - "../feature/update/model/version_info/description", - "../feature/update/model/version_info/new_version", + "../feature/update/model/version_info/current_version/include", + "../feature/update/model/version_info/description/include", + "../feature/update/model/version_info/new_version/include", ] model_src = [ + "../feature/update/model/check/src/check_result.cpp", "../feature/update/model/event/src/event_info.cpp", "../feature/update/model/message_parcel/src/message_parcel_helper.cpp", + "../feature/update/model/policy/src/upgrade_policy.cpp", "../feature/update/model/subscribe/src/subscribe_info.cpp", "../feature/update/model/task/src/task_body.cpp", + "../feature/update/model/task/src/task_info.cpp", "../feature/update/model/upgrade_info/src/business_type.cpp", + "../feature/update/model/upgrade_info/src/business_error.cpp", + "../feature/update/model/upgrade_info/src/clear_options.cpp", + "../feature/update/model/upgrade_info/src/download_options.cpp", + "../feature/update/model/upgrade_info/src/pause_download_options.cpp", + "../feature/update/model/upgrade_info/src/resume_download_options.cpp", "../feature/update/model/upgrade_info/src/upgrade_info.cpp", + "../feature/update/model/upgrade_info/src/upgrade_options.cpp", + "../feature/update/model/version_info/current_version/src/current_version_info.cpp", "../feature/update/model/version_info/description/src/description_info.cpp", + "../feature/update/model/version_info/description/src/description_options.cpp", + "../feature/update/model/version_info/description/src/version_description_info.cpp", + "../feature/update/model/version_info/new_version/src/new_version_info.cpp", "../feature/update/model/version_info/src/version_component.cpp", "../feature/update/model/version_info/src/version_digest_info.cpp", ] diff --git a/interfaces/inner_api/feature/update/model/policy/upgrade_period.h b/interfaces/inner_api/feature/update/model/policy/include/upgrade_period.h similarity index 100% rename from interfaces/inner_api/feature/update/model/policy/upgrade_period.h rename to interfaces/inner_api/feature/update/model/policy/include/upgrade_period.h diff --git a/interfaces/inner_api/feature/update/model/policy/upgrade_policy.h b/interfaces/inner_api/feature/update/model/policy/include/upgrade_policy.h similarity index 81% rename from interfaces/inner_api/feature/update/model/policy/upgrade_policy.h rename to interfaces/inner_api/feature/update/model/policy/include/upgrade_policy.h index 97fcf583883ee4dd5e4e5c3c21656c32aa7104b6..45dfd9427cb96dea128614a743937046eb487523 100644 --- a/interfaces/inner_api/feature/update/model/policy/upgrade_policy.h +++ b/interfaces/inner_api/feature/update/model/policy/include/upgrade_policy.h @@ -17,12 +17,17 @@ #define UPDATE_SERVICE_UPGRADE_POLICY_H #include "upgrade_period.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct UpgradePolicy { +struct UpgradePolicy : public Parcelable { bool downloadStrategy = false; bool autoUpgradeStrategy = false; UpgradePeriod autoUpgradePeriods[2]; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static UpgradePolicy *Unmarshalling(Parcel &parcel); }; } // OHOS::UpdateEngine #endif // UPDATE_SERVICE_UPGRADE_POLICY_H diff --git a/interfaces/inner_api/feature/update/model/policy/src/upgrade_policy.cpp b/interfaces/inner_api/feature/update/model/policy/src/upgrade_policy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce73aa41054446ef8533eaf27a355fdc58da6108 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/policy/src/upgrade_policy.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 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 "upgrade_policy.h" +#include "update_define.h" + +namespace OHOS::UpdateEngine { +static constexpr int32_t MAX_VECTOR_SIZE = 128; +bool UpgradePolicy::ReadFromParcel(Parcel &parcel) +{ + downloadStrategy = static_cast(parcel.ReadBool()); + autoUpgradeStrategy = static_cast(parcel.ReadBool()); + size_t size = static_cast(parcel.ReadInt32()); + size_t arraySize = COUNT_OF(autoUpgradePeriods); + if (size > MAX_VECTOR_SIZE) { + ENGINE_LOGE("ReadUpgradePolicy size is over MAX_VECTOR_SIZE, size=%{public}zu", size); + return -1; + } + for (size_t i = 0; (i < size) && (i < arraySize); i++) { + autoUpgradePeriods[i].start = parcel.ReadUint32(); + autoUpgradePeriods[i].end = parcel.ReadUint32(); + } + return true; +} + +bool UpgradePolicy::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteBool(downloadStrategy)) { + ENGINE_LOGE("Write downloadStrategy failed"); + return false; + } + + if (!parcel.WriteBool(autoUpgradeStrategy)) { + ENGINE_LOGE("Write downloadStrategy failed"); + return false; + } + + int32_t size = static_cast(COUNT_OF(autoUpgradePeriods)); + if (!parcel.WriteInt32(size)) { + ENGINE_LOGE("Write size failed"); + return false; + } + + for (int32_t i = 0; i < size; i++) { + parcel.WriteUint32(autoUpgradePeriods[i].start); + parcel.WriteUint32(autoUpgradePeriods[i].end); + } + return true; +} + +UpgradePolicy *UpgradePolicy::Unmarshalling(Parcel &parcel) +{ + UpgradePolicy *upgradePolicy = new (std::nothrow) UpgradePolicy(); + if (upgradePolicy == nullptr) { + ENGINE_LOGE("Create upgradePolicy failed"); + return nullptr; + } + + if (!upgradePolicy->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete upgradePolicy; + return nullptr; + } + return upgradePolicy; +} +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/task/task_body.h b/interfaces/inner_api/feature/update/model/task/include/task_body.h similarity index 100% rename from interfaces/inner_api/feature/update/model/task/task_body.h rename to interfaces/inner_api/feature/update/model/task/include/task_body.h diff --git a/interfaces/inner_api/feature/update/model/task/task_body_member_mask.h b/interfaces/inner_api/feature/update/model/task/include/task_body_member_mask.h similarity index 100% rename from interfaces/inner_api/feature/update/model/task/task_body_member_mask.h rename to interfaces/inner_api/feature/update/model/task/include/task_body_member_mask.h diff --git a/interfaces/inner_api/feature/update/model/task/task_info.h b/interfaces/inner_api/feature/update/model/task/include/task_info.h similarity index 72% rename from interfaces/inner_api/feature/update/model/task/task_info.h rename to interfaces/inner_api/feature/update/model/task/include/task_info.h index d9651f5d7a0083451c8dfef0e2b0a227dccc1b6b..9a55615f6696017319ccf9c94645711f9158d0af 100644 --- a/interfaces/inner_api/feature/update/model/task/task_info.h +++ b/interfaces/inner_api/feature/update/model/task/include/task_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -16,12 +16,20 @@ #ifndef UPDATE_SERVICE_TASK_INFO_H #define UPDATE_SERVICE_TASK_INFO_H +#include + +#include "message_parcel_helper.h" #include "task_body.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct TaskInfo { +struct TaskInfo : public Parcelable { bool existTask = false; TaskBody taskBody; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static TaskInfo *Unmarshalling(Parcel &parcel); }; } // OHOS::UpdateEngine #endif // UPDATE_SERVICE_TASK_INFO_H diff --git a/services/callback/src/update_callback_proxy.cpp b/interfaces/inner_api/feature/update/model/task/src/task_info.cpp similarity index 43% rename from services/callback/src/update_callback_proxy.cpp rename to interfaces/inner_api/feature/update/model/task/src/task_info.cpp index 3ab9fa966a998521022336d72ee917136b3261de..01fd1ce5e4ce5b67eca082792be946ac82fea9bb 100644 --- a/services/callback/src/update_callback_proxy.cpp +++ b/interfaces/inner_api/feature/update/model/task/src/task_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,34 +13,40 @@ * limitations under the License. */ -#include "update_callback_proxy.h" - -#include "event_info.h" -#include "message_parcel_helper.h" +#include "task_info.h" #include "update_log.h" namespace OHOS::UpdateEngine { -void UpdateCallbackProxy::OnEvent(const EventInfo &eventInfo) +bool TaskInfo::ReadFromParcel(Parcel &parcel) { - ENGINE_LOGI("UpdateCallbackProxy::OnEvent"); - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_SYNC }; + existTask = parcel.ReadBool(); + MessageParcelHelper::ReadTaskBody(parcel, taskBody); + return true; +} - if (!data.WriteInterfaceToken(GetDescriptor())) { - ENGINE_LOGE("UpdateCallbackProxy WriteInterfaceToken fail"); - return; +bool TaskInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteBool(existTask)) { + ENGINE_LOGE("WriteBool existTask failed"); + return false; } + MessageParcelHelper::WriteTaskBody(parcel, taskBody); + return true; +} - auto remote = Remote(); - ENGINE_CHECK(remote != nullptr, return, "Can not get remote"); - - int32_t result = MessageParcelHelper::WriteEventInfo(data, eventInfo); - ENGINE_CHECK(result == 0, return, "Can not WriteEventInfo"); +TaskInfo *TaskInfo::Unmarshalling(Parcel &parcel) +{ + TaskInfo *taskInfo = new (std::nothrow) TaskInfo(); + if (taskInfo == nullptr) { + ENGINE_LOGE("Create taskInfo failed"); + return nullptr; + } - result = remote->SendRequest(ON_EVENT, data, reply, option); - ENGINE_CHECK(result == ERR_OK, return, "Can not SendRequest"); - return; + if (!taskInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete taskInfo; + return nullptr; + } + return taskInfo; } } // namespace OHOS::UpdateEngine - diff --git a/interfaces/inner_api/feature/update/model/upgrade/upgrade_options.h b/interfaces/inner_api/feature/update/model/upgrade/upgrade_options.h index c8b9d9a68ea8100b78014d1778d68760959cea74..9c4a5a220cdf982d227e82737745a052bd041e90 100644 --- a/interfaces/inner_api/feature/update/model/upgrade/upgrade_options.h +++ b/interfaces/inner_api/feature/update/model/upgrade/upgrade_options.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -17,10 +17,15 @@ #define UPDATE_SERVICE_UPGRADE_OPTIONS_H #include "order.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct UpgradeOptions { +struct UpgradeOptions : public Parcelable { Order order = Order::INSTALL; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static UpgradeOptions *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_UPGRADE_OPTIONS_H diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/business_sub_type.h b/interfaces/inner_api/feature/update/model/upgrade_info/include/business_sub_type.h similarity index 100% rename from interfaces/inner_api/feature/update/model/upgrade_info/business_sub_type.h rename to interfaces/inner_api/feature/update/model/upgrade_info/include/business_sub_type.h diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/business_type.h b/interfaces/inner_api/feature/update/model/upgrade_info/include/business_type.h similarity index 100% rename from interfaces/inner_api/feature/update/model/upgrade_info/business_type.h rename to interfaces/inner_api/feature/update/model/upgrade_info/include/business_type.h diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/business_vendor.h b/interfaces/inner_api/feature/update/model/upgrade_info/include/business_vendor.h similarity index 100% rename from interfaces/inner_api/feature/update/model/upgrade_info/business_vendor.h rename to interfaces/inner_api/feature/update/model/upgrade_info/include/business_vendor.h diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/upgrade_info.h b/interfaces/inner_api/feature/update/model/upgrade_info/include/upgrade_info.h similarity index 87% rename from interfaces/inner_api/feature/update/model/upgrade_info/upgrade_info.h rename to interfaces/inner_api/feature/update/model/upgrade_info/include/upgrade_info.h index c604c500e588d35fd216033495dabc95dae87db1..0464e9d6815c7707e266d73a5f3027abb53b8d44 100644 --- a/interfaces/inner_api/feature/update/model/upgrade_info/upgrade_info.h +++ b/interfaces/inner_api/feature/update/model/upgrade_info/include/upgrade_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -17,13 +17,15 @@ #define UPDATE_SERVICE_UPGRADE_INFO_H #include +#include #include "business_type.h" +#include "parcel.h" #include "update_device_type.h" namespace OHOS::UpdateEngine { const std::string LOCAL_UPGRADE_INFO = "LocalUpgradeInfo"; -struct UpgradeInfo { +struct UpgradeInfo : public Parcelable { std::string upgradeApp; BusinessType businessType = {}; std::string upgradeDevId; @@ -36,7 +38,7 @@ struct UpgradeInfo { if (upgradeApp != other.upgradeApp) { return upgradeApp < other.upgradeApp; } - + if (businessType != other.businessType) { return businessType < other.businessType; } @@ -66,6 +68,10 @@ struct UpgradeInfo { { return upgradeApp == LOCAL_UPGRADE_INFO; } + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static UpgradeInfo *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_UPGRADE_INFO_H diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/src/business_error.cpp b/interfaces/inner_api/feature/update/model/upgrade_info/src/business_error.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3265de07b7afb4e1cf282cc106bd45adfce16aa9 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/business_error.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 "business_error.h" + +#include "message_parcel_helper.h" + +namespace OHOS::UpdateEngine { +bool BusinessError::ReadFromParcel(Parcel &parcel) +{ + message = Str16ToStr8(parcel.ReadString16()); + errorNum = static_cast(parcel.ReadInt32()); + MessageParcelHelper::ReadErrorMessages(parcel, data); + return true; +} + +bool BusinessError::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString16(Str8ToStr16(message))) { + ENGINE_LOGE("Write message failed"); + return false; + } + + if (!parcel.WriteInt32(static_cast(errorNum))) { + ENGINE_LOGE("Write errorNum failed"); + return false; + } + + if (!MessageParcelHelper::WriteErrorMessages(parcel, data)) { + ENGINE_LOGE("Write data failed"); + return false; + } + return true; +} + +BusinessError *BusinessError::Unmarshalling(Parcel &parcel) +{ + BusinessError *businessError = new (std::nothrow) BusinessError(); + if (businessError == nullptr) { + ENGINE_LOGE("Create businessError failed"); + return nullptr; + } + + if (!businessError->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete businessError; + return nullptr; + } + return businessError; +} +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/engine/src/update_callback_stub.cpp b/interfaces/inner_api/feature/update/model/upgrade_info/src/clear_options.cpp similarity index 44% rename from interfaces/inner_api/engine/src/update_callback_stub.cpp rename to interfaces/inner_api/feature/update/model/upgrade_info/src/clear_options.cpp index a8be6b92c7655cd771e01dfc17b248f71047506e..0a26783223b47b3c52146adc539b90f5144d5377 100644 --- a/interfaces/inner_api/engine/src/update_callback_stub.cpp +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/clear_options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,30 +13,39 @@ * limitations under the License. */ -#include "update_callback_stub.h" +#include "clear_options.h" -#include "message_parcel_helper.h" #include "update_log.h" -using namespace std; - namespace OHOS::UpdateEngine { -int32_t UpdateCallbackStub::OnRemoteRequest(uint32_t code, - MessageParcel &data, MessageParcel &reply, MessageOption &option) +bool ClearOptions::ReadFromParcel(Parcel &parcel) +{ + status = static_cast(parcel.ReadUint32()); + return true; +} + +bool ClearOptions::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(status))) { + ENGINE_LOGE("Write status failed"); + return false; + } + return true; +} + +ClearOptions *ClearOptions::Unmarshalling(Parcel &parcel) { - if (data.ReadInterfaceToken() != GetDescriptor()) { - ENGINE_LOGI("UpdateCallbackStub ReadInterfaceToken fail"); - return -1; + ClearOptions *clearOptions = new (std::nothrow) ClearOptions(); + if (clearOptions == nullptr) { + ENGINE_LOGE("Create clearOptions failed"); + return nullptr; } - ENGINE_LOGI("UpdateCallbackStub OnRemoteRequest code is %{public}d", code); - BusinessError businessError; - if (code == ON_EVENT) { - EventInfo eventInfo; - MessageParcelHelper::ReadEventInfo(data, eventInfo); - OnEvent(eventInfo); - return 0; + if (!clearOptions->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete clearOptions; + return nullptr; } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return clearOptions; } } // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/src/download_options.cpp b/interfaces/inner_api/feature/update/model/upgrade_info/src/download_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a833bb6283df8bda7b9242f567e8e02ddc662256 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/download_options.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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 "download_options.h" +#include "update_log.h" + +namespace OHOS::UpdateEngine { +bool DownloadOptions::ReadFromParcel(Parcel &parcel) +{ + allowNetwork = static_cast(parcel.ReadUint32()); + order = static_cast(parcel.ReadUint32()); + return true; +} + +bool DownloadOptions::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(allowNetwork))) { + ENGINE_LOGE("Write allowNetwork failed"); + return false; + } + + if (!parcel.WriteUint32(static_cast(order))) { + ENGINE_LOGE("Write order failed"); + return false; + } + return true; +} + +DownloadOptions *DownloadOptions::Unmarshalling(Parcel &parcel) +{ + DownloadOptions *downloadOptions = new (std::nothrow) DownloadOptions(); + if (downloadOptions == nullptr) { + ENGINE_LOGE("Create downloadOptions failed"); + return nullptr; + } + + if (!downloadOptions->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete downloadOptions; + return nullptr; + } + return downloadOptions; +} +} // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/services/callback/include/update_callback_proxy.h b/interfaces/inner_api/feature/update/model/upgrade_info/src/pause_download_options.cpp similarity index 37% rename from services/callback/include/update_callback_proxy.h rename to interfaces/inner_api/feature/update/model/upgrade_info/src/pause_download_options.cpp index a0d99c0ebf18445e1b1115c088eef7142e981b04..64f5bdb6b047709fddf8b4cfbdb486231a3a1df2 100644 --- a/services/callback/include/update_callback_proxy.h +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/pause_download_options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,25 +13,38 @@ * limitations under the License. */ -#ifndef UPDATE_CALLBACK_PROXY_H -#define UPDATE_CALLBACK_PROXY_H - -#include "iremote_broker.h" -#include "iremote_proxy.h" - -#include "event_info.h" -#include "iupdate_callback.h" +#include "pause_download_options.h" +#include "update_log.h" namespace OHOS::UpdateEngine { -class UpdateCallbackProxy : public IRemoteProxy { -public: - explicit UpdateCallbackProxy(const sptr& impl) : IRemoteProxy(impl) {} - ~UpdateCallbackProxy() override = default; +bool PauseDownloadOptions::ReadFromParcel(Parcel &parcel) +{ + isAllowAutoResume = parcel.ReadBool(); + return true; +} + +bool PauseDownloadOptions::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteBool(isAllowAutoResume)) { + ENGINE_LOGE("Write isAllowAutoResume failed"); + return false; + } + return true; +} - void OnEvent(const EventInfo &eventInfo) override; +PauseDownloadOptions *PauseDownloadOptions::Unmarshalling(Parcel &parcel) +{ + PauseDownloadOptions *pauseDownloadOptions = new (std::nothrow) PauseDownloadOptions(); + if (pauseDownloadOptions == nullptr) { + ENGINE_LOGE("Create pauseDownloadOptions failed"); + return nullptr; + } -private: - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::UpdateEngine -#endif // UPDATE_CALLBACK_PROXY_H \ No newline at end of file + if (!pauseDownloadOptions->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete pauseDownloadOptions; + return nullptr; + } + return pauseDownloadOptions; +} +} // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/src/resume_download_options.cpp b/interfaces/inner_api/feature/update/model/upgrade_info/src/resume_download_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b50b18423063c834d9a10f6ff4bdb76d11a29a3 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/resume_download_options.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "resume_download_options.h" +#include "update_log.h" + +namespace OHOS::UpdateEngine { +bool ResumeDownloadOptions::ReadFromParcel(Parcel &parcel) +{ + allowNetwork = static_cast(parcel.ReadUint32()); + return true; +} + +bool ResumeDownloadOptions::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(allowNetwork))) { + ENGINE_LOGE("Write allowNetwork failed"); + return false; + } + return true; +} + +ResumeDownloadOptions *ResumeDownloadOptions::Unmarshalling(Parcel &parcel) +{ + ResumeDownloadOptions *resumeDownloadOptions = new (std::nothrow) ResumeDownloadOptions(); + if (resumeDownloadOptions == nullptr) { + ENGINE_LOGE("Create resumeDownloadOptions failed"); + return nullptr; + } + + if (!resumeDownloadOptions->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete resumeDownloadOptions; + return nullptr; + } + return resumeDownloadOptions; +} +} // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_info.cpp b/interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_info.cpp index d088c888587f8e718522b27f65b6da5422c3969f..4a175fe251d85511d8b3bf31a29fdb4a98b21726 100644 --- a/interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_info.cpp +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_info.cpp @@ -27,4 +27,71 @@ std::string UpgradeInfo::ToString() const output += ",controlDevId:" + AnonymousUtils::AnonymousString(controlDevId); return output; } + +bool UpgradeInfo::ReadFromParcel(Parcel &parcel) +{ + upgradeApp = Str16ToStr8(parcel.ReadString16()); + businessType.vendor = Str16ToStr8(parcel.ReadString16()); + businessType.subType = static_cast(parcel.ReadInt32()); + upgradeDevId = Str16ToStr8(parcel.ReadString16()); + controlDevId = Str16ToStr8(parcel.ReadString16()); + processId = parcel.ReadInt32(); + deviceType = static_cast(parcel.ReadInt32()); + return true; +} + +bool UpgradeInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString16(Str8ToStr16(upgradeApp))) { + ENGINE_LOGE("Write upgradeApp failed"); + return false; + } + + if (!parcel.WriteString16(Str8ToStr16(businessType.vendor))) { + ENGINE_LOGE("Write businessType vendor failed"); + return false; + } + + if (!parcel.WriteInt32(static_cast(businessType.subType))) { + ENGINE_LOGE("Write businessType subType failed"); + return false; + } + + if (!parcel.WriteString16(Str8ToStr16(upgradeDevId))) { + ENGINE_LOGE("Write upgradeDevId failed"); + return false; + } + + if (!parcel.WriteString16(Str8ToStr16(controlDevId))) { + ENGINE_LOGE("Write controlDevId failed"); + return false; + } + + if (!parcel.WriteInt32(processId)) { + ENGINE_LOGE("Write processId failed"); + return false; + } + + if (!parcel.WriteInt32(static_cast(deviceType))) { + ENGINE_LOGE("Write deviceType failed"); + return false; + } + return true; +} + +UpgradeInfo *UpgradeInfo::Unmarshalling(Parcel &parcel) +{ + UpgradeInfo *upgradeInfo = new (std::nothrow) UpgradeInfo(); + if (upgradeInfo == nullptr) { + ENGINE_LOGE("Create UpgradeInfo failed"); + return nullptr; + } + + if (!upgradeInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete upgradeInfo; + return nullptr; + } + return upgradeInfo; +} } // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/interfaces/inner_api/feature/update/api/update_service/iupdate_service.h b/interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_options.cpp similarity index 44% rename from interfaces/inner_api/feature/update/api/update_service/iupdate_service.h rename to interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_options.cpp index dda1db37a5dc87d981e0a9e4414b9ae683790f81..bd202678b69b0f29e0fba10941b09f94740829c2 100644 --- a/interfaces/inner_api/feature/update/api/update_service/iupdate_service.h +++ b/interfaces/inner_api/feature/update/model/upgrade_info/src/upgrade_options.cpp @@ -13,27 +13,38 @@ * limitations under the License. */ -#ifndef IUPDATE_SERVICE_H -#define IUPDATE_SERVICE_H - -#include "iremote_broker.h" -#include "iremote_proxy.h" - -#include "iservice_local_updater.h" -#include "iservice_online_updater.h" -#include "iservice_restorer.h" -#include "iupdate_callback.h" +#include "upgrade_options.h" +#include "update_log.h" namespace OHOS::UpdateEngine { -class IUpdateService : public OHOS::IRemoteBroker, public IServiceOnlineUpdater, public IServiceRestorer, - public IServiceLocalUpdater { -public: +bool UpgradeOptions::ReadFromParcel(Parcel &parcel) +{ + order = static_cast(parcel.ReadUint32()); + return true; +} - virtual int32_t RegisterUpdateCallback(const UpgradeInfo &info, const sptr& updateCallback) = 0; +bool UpgradeOptions::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(order))) { + ENGINE_LOGE("Write order failed"); + return false; + } + return true; +} - virtual int32_t UnregisterUpdateCallback(const UpgradeInfo &info) = 0; +UpgradeOptions *UpgradeOptions::Unmarshalling(Parcel &parcel) +{ + UpgradeOptions *upgradeOptions = new (std::nothrow) UpgradeOptions(); + if (upgradeOptions == nullptr) { + ENGINE_LOGE("Create UpgradeOptions failed"); + return nullptr; + } - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Updater.IUpdateService"); -}; + if (!upgradeOptions->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete upgradeOptions; + return nullptr; + } + return upgradeOptions; +} } // namespace OHOS::UpdateEngine -#endif // IUPDATE_SERVICE_H diff --git a/interfaces/inner_api/feature/update/model/version_info/current_version/current_version_info.h b/interfaces/inner_api/feature/update/model/version_info/current_version/include/current_version_info.h similarity index 75% rename from interfaces/inner_api/feature/update/model/version_info/current_version/current_version_info.h rename to interfaces/inner_api/feature/update/model/version_info/current_version/include/current_version_info.h index d6645118e68c3c535a2b96ee0ef3437fc8c4f05d..7557d793999d6ffde4f212e13c40b61c1753b225 100644 --- a/interfaces/inner_api/feature/update/model/version_info/current_version/current_version_info.h +++ b/interfaces/inner_api/feature/update/model/version_info/current_version/include/current_version_info.h @@ -17,15 +17,22 @@ #define UPDATE_SERVICE_CURRENT_VERSION_INFO_H #include +#include #include -#include "version_component.h" +#include "error_message.h" +#include "message_parcel_helper.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct CurrentVersionInfo { +struct CurrentVersionInfo : public Parcelable { std::string osVersion; std::string deviceName; std::vector versionComponents; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static CurrentVersionInfo *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_CURRENT_VERSION_INFO_H diff --git a/interfaces/inner_api/feature/update/model/version_info/current_version/src/current_version_info.cpp b/interfaces/inner_api/feature/update/model/version_info/current_version/src/current_version_info.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cb6ddc18a4ba8a3cc23bc9cd746d72935112c47 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/version_info/current_version/src/current_version_info.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 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 "current_version_info.h" +#include "update_log.h" + +namespace OHOS::UpdateEngine { + +bool CurrentVersionInfo::ReadFromParcel(Parcel &parcel) +{ + osVersion = Str16ToStr8(parcel.ReadString16()); + deviceName = Str16ToStr8(parcel.ReadString16()); + MessageParcelHelper::ReadVersionComponents(parcel, versionComponents); + return true; +} + +bool CurrentVersionInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString16(Str8ToStr16(osVersion))) { + ENGINE_LOGE("write osVersion failed"); + return false; + } + + if (!parcel.WriteString16(Str8ToStr16(deviceName))) { + ENGINE_LOGE("write deviceName failed"); + return false; + } + + MessageParcelHelper::WriteVersionComponents(parcel, versionComponents); + return true; +} + +CurrentVersionInfo *CurrentVersionInfo::Unmarshalling(Parcel &parcel) +{ + CurrentVersionInfo *currentVersionInfo = new (std::nothrow) CurrentVersionInfo(); + if (currentVersionInfo == nullptr) { + ENGINE_LOGE("Create currentVersionInfo failed"); + return nullptr; + } + + if (!currentVersionInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete currentVersionInfo; + return nullptr; + } + return currentVersionInfo; +} +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/version_info/description/component_description.h b/interfaces/inner_api/feature/update/model/version_info/description/include/component_description.h similarity index 100% rename from interfaces/inner_api/feature/update/model/version_info/description/component_description.h rename to interfaces/inner_api/feature/update/model/version_info/description/include/component_description.h diff --git a/interfaces/inner_api/feature/update/model/version_info/description/description_format.h b/interfaces/inner_api/feature/update/model/version_info/description/include/description_format.h similarity index 100% rename from interfaces/inner_api/feature/update/model/version_info/description/description_format.h rename to interfaces/inner_api/feature/update/model/version_info/description/include/description_format.h diff --git a/interfaces/inner_api/feature/update/model/version_info/description/description_info.h b/interfaces/inner_api/feature/update/model/version_info/description/include/description_info.h similarity index 100% rename from interfaces/inner_api/feature/update/model/version_info/description/description_info.h rename to interfaces/inner_api/feature/update/model/version_info/description/include/description_info.h diff --git a/interfaces/inner_api/feature/update/model/version_info/description/description_options.h b/interfaces/inner_api/feature/update/model/version_info/description/include/description_options.h similarity index 79% rename from interfaces/inner_api/feature/update/model/version_info/description/description_options.h rename to interfaces/inner_api/feature/update/model/version_info/description/include/description_options.h index 192bf1d0da18bfadbd757909c1579157b4e78de9..60b96029a1bd93c4022df8942ff2281a2766bdb2 100644 --- a/interfaces/inner_api/feature/update/model/version_info/description/description_options.h +++ b/interfaces/inner_api/feature/update/model/version_info/description/include/description_options.h @@ -17,13 +17,19 @@ #define UPDATE_SERVICE_DESCRIPTION_OPTIONS_H #include +#include #include "description_format.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct DescriptionOptions { +struct DescriptionOptions : public Parcelable { DescriptionFormat format = DescriptionFormat::STANDARD; std::string language; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static DescriptionOptions *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_DESCRIPTION_OPTIONS_H diff --git a/interfaces/inner_api/feature/update/model/version_info/description/description_type.h b/interfaces/inner_api/feature/update/model/version_info/description/include/description_type.h similarity index 100% rename from interfaces/inner_api/feature/update/model/version_info/description/description_type.h rename to interfaces/inner_api/feature/update/model/version_info/description/include/description_type.h diff --git a/interfaces/inner_api/feature/update/model/version_info/description/version_description_info.h b/interfaces/inner_api/feature/update/model/version_info/description/include/version_description_info.h similarity index 66% rename from interfaces/inner_api/feature/update/model/version_info/description/version_description_info.h rename to interfaces/inner_api/feature/update/model/version_info/description/include/version_description_info.h index 83fa61b583cc0ee5deed0b1df0df6b0e3cb7eef7..76a881eae4061cea80458b4465804d1aac1d74a3 100644 --- a/interfaces/inner_api/feature/update/model/version_info/description/version_description_info.h +++ b/interfaces/inner_api/feature/update/model/version_info/description/include/version_description_info.h @@ -13,16 +13,23 @@ * limitations under the License. */ -#ifndef UPDATE_SERVICE_VERSION_DESCRIPTION_INFO_H -#define UPDATE_SERVICE_VERSION_DESCRIPTION_INFO_H +#ifndef VERSION_DESCRIPTION_INFO_H +#define VERSION_DESCRIPTION_INFO_H +#include #include #include "component_description.h" +#include "message_parcel_helper.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct VersionDescriptionInfo { +struct VersionDescriptionInfo : public Parcelable { std::vector componentDescriptions; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static VersionDescriptionInfo *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine -#endif // UPDATE_SERVICE_VERSION_DESCRIPTION_INFO_H +#endif // VERSION_DESCRIPTION_INFO_H diff --git a/interfaces/inner_api/feature/update/model/version_info/description/src/description_options.cpp b/interfaces/inner_api/feature/update/model/version_info/description/src/description_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..693d355304d584bd563a53c67ea1a4a6ba858603 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/version_info/description/src/description_options.cpp @@ -0,0 +1,57 @@ +/* + * 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 "description_options.h" + +#include "description_info.h" +#include "update_define.h" + +namespace OHOS::UpdateEngine { +bool DescriptionOptions::ReadFromParcel(Parcel &parcel) +{ + format = static_cast(parcel.ReadUint32()); + language = Str16ToStr8(parcel.ReadString16()); + return true; +} + +bool DescriptionOptions::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(format))) { + ENGINE_LOGE("write format failed"); + return false; + } + if (!parcel.WriteString16(Str8ToStr16(language))) { + ENGINE_LOGE("write language failed"); + return false; + } + return true; +} + +DescriptionOptions *DescriptionOptions::Unmarshalling(Parcel &parcel) +{ + DescriptionOptions *descriptionOptions = new (std::nothrow) DescriptionOptions(); + if (descriptionOptions == nullptr) { + ENGINE_LOGE("Create descriptionOptions failed"); + return nullptr; + } + + if (!descriptionOptions->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete descriptionOptions; + return nullptr; + } + return descriptionOptions; +} +} // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/interfaces/inner_api/feature/update/model/version_info/description/src/version_description_info.cpp b/interfaces/inner_api/feature/update/model/version_info/description/src/version_description_info.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1cdccc0250b2ded6cb892814d822699b1dc29b7 --- /dev/null +++ b/interfaces/inner_api/feature/update/model/version_info/description/src/version_description_info.cpp @@ -0,0 +1,48 @@ +/* + * 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 "version_description_info.h" +#include "update_log.h" +#include "error_message.h" + +namespace OHOS::UpdateEngine { +bool VersionDescriptionInfo::ReadFromParcel(Parcel &parcel) +{ + MessageParcelHelper::ReadComponentDescriptions(parcel, componentDescriptions); + return true; +} + +bool VersionDescriptionInfo::Marshalling(Parcel &parcel) const +{ + MessageParcelHelper::WriteComponentDescriptions(parcel, componentDescriptions); + return true; +} + +VersionDescriptionInfo *VersionDescriptionInfo::Unmarshalling(Parcel &parcel) +{ + VersionDescriptionInfo *versionDescriptionInfo = new (std::nothrow) VersionDescriptionInfo(); + if (versionDescriptionInfo == nullptr) { + ENGINE_LOGE("Create versionDescriptionInfo failed"); + return nullptr; + } + + if (!versionDescriptionInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete versionDescriptionInfo; + return nullptr; + } + return versionDescriptionInfo; +} +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/version_info/new_version/new_version_info.h b/interfaces/inner_api/feature/update/model/version_info/new_version/include/new_version_info.h similarity index 78% rename from interfaces/inner_api/feature/update/model/version_info/new_version/new_version_info.h rename to interfaces/inner_api/feature/update/model/version_info/new_version/include/new_version_info.h index 6578830fca47621e4e6a4873c17d06151d5a418a..746edecb73b1087d6bb8c148817a032b48ecffc8 100644 --- a/interfaces/inner_api/feature/update/model/version_info/new_version/new_version_info.h +++ b/interfaces/inner_api/feature/update/model/version_info/new_version/include/new_version_info.h @@ -16,15 +16,22 @@ #ifndef UPDATE_SERVICE_NEW_VERSION_INFO_H #define UPDATE_SERVICE_NEW_VERSION_INFO_H +#include #include +#include "message_parcel_helper.h" #include "version_component.h" #include "version_digest_info.h" +#include "parcel.h" namespace OHOS::UpdateEngine { -struct NewVersionInfo { +struct NewVersionInfo : public Parcelable { VersionDigestInfo versionDigestInfo; std::vector versionComponents; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static NewVersionInfo *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_NEW_VERSION_INFO_H diff --git a/interfaces/inner_api/feature/update/model/version_info/new_version/src/new_version_info.cpp b/interfaces/inner_api/feature/update/model/version_info/new_version/src/new_version_info.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a64f18433c63b57bb1da941f3ec79220db82a0a --- /dev/null +++ b/interfaces/inner_api/feature/update/model/version_info/new_version/src/new_version_info.cpp @@ -0,0 +1,56 @@ +/* + * 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 "new_version_info.h" +#include "update_log.h" + +namespace OHOS::UpdateEngine { +bool NewVersionInfo::ReadFromParcel(Parcel &parcel) +{ + versionDigestInfo.versionDigest = Str16ToStr8(parcel.ReadString16()); + if (!MessageParcelHelper::ReadVersionComponents(parcel, versionComponents)) { + return false; + } + return true; +} + +bool NewVersionInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString16(Str8ToStr16(versionDigestInfo.versionDigest))) { + return false; + } + + if (!MessageParcelHelper::WriteVersionComponents(parcel, versionComponents)) { + return false; + } + return true; +} + +NewVersionInfo *NewVersionInfo::Unmarshalling(Parcel &parcel) +{ + NewVersionInfo *newVersionInfo = new (std::nothrow) NewVersionInfo(); + if (newVersionInfo == nullptr) { + ENGINE_LOGE("Create newVersionInfo failed"); + return nullptr; + } + + if (!newVersionInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete newVersionInfo; + return nullptr; + } + return newVersionInfo; +} +} // namespace OHOS::UpdateEngine diff --git a/interfaces/inner_api/feature/update/model/version_info/src/version_digest_info.cpp b/interfaces/inner_api/feature/update/model/version_info/src/version_digest_info.cpp index e3c1217e6deec2d4a0387f9928b4b5388c5f5cd1..7f36241212ae9ae7430991f7e5c45a01dc77beb2 100644 --- a/interfaces/inner_api/feature/update/model/version_info/src/version_digest_info.cpp +++ b/interfaces/inner_api/feature/update/model/version_info/src/version_digest_info.cpp @@ -23,4 +23,35 @@ JsonBuilder VersionDigestInfo::GetJsonBuilder() .Append("versionDigest", versionDigest) .Append("}"); } + +bool VersionDigestInfo::ReadFromParcel(Parcel &parcel) +{ + versionDigest = Str16ToStr8(parcel.ReadString16()); + return true; +} + +bool VersionDigestInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString16(Str8ToStr16(versionDigest))) { + ENGINE_LOGE("write versionDigest failed"); + return false; + } + return true; +} + +VersionDigestInfo *VersionDigestInfo::Unmarshalling(Parcel &parcel) +{ + VersionDigestInfo *versionDigestInfo = new (std::nothrow) VersionDigestInfo(); + if (versionDigestInfo == nullptr) { + ENGINE_LOGE("Create versionDigestInfo failed"); + return nullptr; + } + + if (!versionDigestInfo->ReadFromParcel(parcel)) { + ENGINE_LOGE("Read from parcel failed"); + delete versionDigestInfo; + return nullptr; + } + return versionDigestInfo; +} } // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/interfaces/inner_api/feature/update/model/version_info/version_digest_info.h b/interfaces/inner_api/feature/update/model/version_info/version_digest_info.h index 188c9ca7e2c3d39cdfd3c755403b3d90f565511f..761630eacbc0b2cb5ddd38187bf44cf0d2ab634b 100644 --- a/interfaces/inner_api/feature/update/model/version_info/version_digest_info.h +++ b/interfaces/inner_api/feature/update/model/version_info/version_digest_info.h @@ -17,14 +17,21 @@ #define UPDATE_SERVICE_VERSION_DIGEST_INFO_H #include +#include #include "base_json_struct.h" +#include "parcel.h" +#include "update_log.h" namespace OHOS::UpdateEngine { -struct VersionDigestInfo : public BaseJsonStruct { +struct VersionDigestInfo : public BaseJsonStruct, public Parcelable { std::string versionDigest; JsonBuilder GetJsonBuilder() final; + + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static VersionDigestInfo *Unmarshalling(Parcel &parcel); }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_VERSION_DIGEST_INFO_H diff --git a/interfaces/inner_api/include/update_service_kits.h b/interfaces/inner_api/include/update_service_kits.h index 39d38b01d55671df7e2d08f0292cf2b1f3cf9b88..3034e53379b3a5ce3d3f4e480754f356a3eb680d 100644 --- a/interfaces/inner_api/include/update_service_kits.h +++ b/interfaces/inner_api/include/update_service_kits.h @@ -50,59 +50,63 @@ public: */ static UpdateServiceKits& GetInstance(); - virtual int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb) = 0; + virtual int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb, + int32_t &funcResult) = 0; - virtual int32_t UnregisterUpdateCallback(const UpgradeInfo &info) = 0; + virtual int32_t UnregisterUpdateCallback(const UpgradeInfo &info, int32_t &funcResult) = 0; virtual int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, - CheckResult &checkResult) = 0; + CheckResult &checkResult, int32_t &funcResult) = 0; virtual int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) = 0; + const DownloadOptions &downloadOptions, BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) = 0; + const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) = 0; + const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) = 0; + const UpgradeOptions &upgradeOptions, BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const ClearOptions &clearOptions, BusinessError &businessError) = 0; + const ClearOptions &clearOptions, BusinessError &businessError, int32_t &funcResult) = 0; - virtual int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) = 0; + virtual int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, - BusinessError &businessError) = 0; + BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, - BusinessError &businessError) = 0; + BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) = 0; + BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, - VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError) = 0; + VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError, int32_t &funcResult) = 0; - virtual int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) = 0; + virtual int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError, + int32_t &funcResult) = 0; virtual int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, - BusinessError &businessError) = 0; + BusinessError &businessError, int32_t &funcResult) = 0; - virtual int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) = 0; + virtual int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError, + int32_t &funcResult) = 0; - virtual int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) = 0; + virtual int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError, + int32_t &funcResult) = 0; virtual int32_t FactoryReset(BusinessError &businessError) = 0; virtual int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) = 0; + const std::vector &packageNames, BusinessError &businessError, int32_t &funcResult) = 0; virtual int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) = 0; + BusinessError &businessError, int32_t &funcResult) = 0; }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_KITS_H diff --git a/services/core/ability/callback/src/base_callback_utils.cpp b/services/core/ability/callback/src/base_callback_utils.cpp index 1731c69c12f37008c46ae45f4f33588ef209a13a..6302d7bc18f74b108414fe3b508187956bbf06f3 100644 --- a/services/core/ability/callback/src/base_callback_utils.cpp +++ b/services/core/ability/callback/src/base_callback_utils.cpp @@ -91,7 +91,8 @@ sptr BaseCallbackUtils::GetUpgradeCallback(const UpgradeInfo &u ENGINE_LOGI("GetUpgradeCallback no instance"); return nullptr; } - return service->GetUpgradeCallback(upgradeInfo); + int32_t funcResult; + return service->GetUpgradeCallback(upgradeInfo, funcResult); } void BaseCallbackUtils::NotifyToHap(EventInfo &info) diff --git a/services/engine/BUILD.gn b/services/engine/BUILD.gn index e45692520b606c5b29bfc9337a3ccc5fa48c0545..281d09db367912de5f6f187bad261c62e77e2e1a 100644 --- a/services/engine/BUILD.gn +++ b/services/engine/BUILD.gn @@ -11,9 +11,25 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("../../services/engine/engine_sa.gni") +idl_interface_sources = [ "${target_gen_dir}/update_service_stub.cpp" ] + +idl_include = [ + "${target_gen_dir}", + "${target_gen_dir}/callback", +] + +idl_gen_interface("update_service_interface") { + src_idl = rebase_path("IUpdateService.idl") + sources_callback = [ "callback/IUpdateCallback.idl" ] + dst_file = string_join(",", idl_interface_sources) + log_domainid = "0xD002E00" + log_tag = "UPDATE_SERVICE_KITS" +} + ohos_prebuilt_etc("dupdate_config.json") { source = "$update_service_dupdate_config_path" relative_install_dir = "update" @@ -38,8 +54,12 @@ ohos_shared_library("$updateengine_library_name") { } shlib_type = "sa" include_dirs = sa_include_dirs + include_dirs += idl_include sources = sa_sources + output_values = get_target_outputs(":update_service_interface") + sources += filter_include(output_values, [ "*_stub.cpp" ]) deps = sa_deps + deps += [ ":update_service_interface" ] external_deps = sa_external_deps part_name = "$updateengine_part_name" subsystem_name = "updater" diff --git a/services/engine/IUpdateService.idl b/services/engine/IUpdateService.idl new file mode 100644 index 0000000000000000000000000000000000000000..87bdab76181d47d84d89de074b7adb7b1896d354 --- /dev/null +++ b/services/engine/IUpdateService.idl @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.UpdateEngine; + +import callback/IUpdateCallback; + +sequenceable OHOS.UpdateEngine.BusinessError; +sequenceable OHOS.UpdateEngine.CheckResult; +sequenceable OHOS.UpdateEngine.ClearOptions; +sequenceable OHOS.UpdateEngine.CurrentVersionInfo; +sequenceable OHOS.UpdateEngine.DescriptionOptions; +sequenceable OHOS.UpdateEngine.DownloadOptions; +sequenceable OHOS.UpdateEngine.NewVersionInfo; +sequenceable OHOS.UpdateEngine.PauseDownloadOptions; +sequenceable OHOS.UpdateEngine.ResumeDownloadOptions; +sequenceable OHOS.UpdateEngine.TaskInfo; +sequenceable OHOS.UpdateEngine.UpgradeInfo; +sequenceable OHOS.UpdateEngine.UpgradeOptions; +sequenceable OHOS.UpdateEngine.UpgradePolicy; +sequenceable OHOS.UpdateEngine.VersionDescriptionInfo; +sequenceable OHOS.UpdateEngine.VersionDigestInfo; + +option_stub_hooks on; +option_parcel_hooks on; + +interface OHOS.UpdateEngine.IUpdateService { + int RegisterUpdateCallback([in] UpgradeInfo info, [in] IUpdateCallback updateCallback); + int UnregisterUpdateCallback([in] UpgradeInfo info); + + int CheckNewVersion([in] UpgradeInfo info, [out] BusinessError businessError, [out] CheckResult checkResult); + int Download([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] DownloadOptions downloadOptions, [out] BusinessError businessError); + int PauseDownload([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] PauseDownloadOptions pauseDownloadOptions, [out] BusinessError businessError); + int ResumeDownload([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] ResumeDownloadOptions resumeDownloadOptions, [out] BusinessError businessError); + int Upgrade([in] UpgradeInfo info, [in] VersionDigestInfo versionDigest, + [in] UpgradeOptions upgradeOptions, [out] BusinessError businessError); + int ClearError([in] UpgradeInfo info, [in] VersionDigestInfo versionDigest, + [in] ClearOptions clearOptions, [out] BusinessError businessError); + int TerminateUpgrade([in] UpgradeInfo info, [out] BusinessError businessError); + int GetNewVersionInfo([in] UpgradeInfo info, [out] NewVersionInfo newVersionInfo, + [out] BusinessError businessError); + int GetNewVersionDescription([in] UpgradeInfo info, [in] VersionDigestInfo versionDigestInfo, + [in] DescriptionOptions descriptionOptions, [out] VersionDescriptionInfo newVersionDescriptionInfo, + [out] BusinessError businessError); + int GetCurrentVersionInfo([in] UpgradeInfo info, [out] CurrentVersionInfo currentVersionInfo, + [out] BusinessError businessError); + int GetCurrentVersionDescription([in] UpgradeInfo info, [in] DescriptionOptions descriptionOptions, + [out] VersionDescriptionInfo currentVersionDescriptionInfo, [out] BusinessError businessError); + int GetTaskInfo([in] UpgradeInfo info, [out] TaskInfo taskInfo, [out] BusinessError businessError); + int SetUpgradePolicy([in] UpgradeInfo info, [in] UpgradePolicy policy, [out] BusinessError businessError); + int GetUpgradePolicy([in] UpgradeInfo info, [out] UpgradePolicy policy, [out] BusinessError businessError); + int Cancel([in] UpgradeInfo info, [in] int service, [out] BusinessError businessError); + int FactoryReset([out] BusinessError businessError); + int ApplyNewVersion([in] UpgradeInfo info, [in] String miscFile, + [in] String[] packageNames, [out] BusinessError businessError); + int VerifyUpgradePackage([in] String packagePath, [in] String keyPath, [out] BusinessError businessError); +} diff --git a/interfaces/inner_api/feature/update/api/callback/iupdate_callback.h b/services/engine/callback/IUpdateCallback.idl similarity index 49% rename from interfaces/inner_api/feature/update/api/callback/iupdate_callback.h rename to services/engine/callback/IUpdateCallback.idl index 7d21263459e008f18cd8e00d293c30a8e3f2ff24..034e7b9dbe8c720a7942b3e9f0c79883cb48bff7 100644 --- a/interfaces/inner_api/feature/update/api/callback/iupdate_callback.h +++ b/services/engine/callback/IUpdateCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,25 +13,8 @@ * limitations under the License. */ -#ifndef IUPDATE_CALLBACK_H -#define IUPDATE_CALLBACK_H +sequenceable OHOS.UpdateEngine.EventInfo; -#include -#include "event_info.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" - -namespace OHOS::UpdateEngine { -class IUpdateCallback : public OHOS::IRemoteBroker { -public: - virtual ~IUpdateCallback() = default; - enum { - ON_EVENT = 1 - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Update.IUpdateCallback"); -public: - virtual void OnEvent(const EventInfo &eventInfo) = 0; -}; -} // namespace OHOS::UpdateEngine -#endif // IUPDATE_CALLBACK_H +[callback] interface OHOS.UpdateEngine.IUpdateCallback { + void OnEvent([in] EventInfo eventInfo) ; +} diff --git a/services/engine/engine_sa.gni b/services/engine/engine_sa.gni index a421035772ed62744e0a65627c43c2a2fef9a2e9..74a5bb2327b77b825bf96f404dde3ed55f0dd6fa 100644 --- a/services/engine/engine_sa.gni +++ b/services/engine/engine_sa.gni @@ -27,10 +27,14 @@ declare_args() { if (!defined(global_parts_info.distributeddatamgr_preferences)) { preference_native_preferences_enable = false } + + update_service_enable_run_on_demand_qos = true + if (!defined(global_parts_info.update_service_enable_run_on_demand_qos)) { + update_service_enable_run_on_demand_qos = false + } } sa_sources = [ - "$updateengine_root_path/services/callback/src/update_callback_proxy.cpp", "$updateengine_root_path/services/core/ability/adapter/src/config_parse.cpp", "$updateengine_root_path/services/core/ability/adapter/src/device_adapter.cpp", "$updateengine_root_path/services/core/ability/alarm/src/timer_manager.cpp", @@ -46,7 +50,6 @@ sa_sources = [ "$updateengine_root_path/services/engine/src/update_service_impl_manager.cpp", "$updateengine_root_path/services/engine/src/update_service_local_updater.cpp", "$updateengine_root_path/services/engine/src/update_service_restorer.cpp", - "$updateengine_root_path/services/engine/src/update_service_stub.cpp", "$updateengine_root_path/services/engine/src/update_service_util_hmos.cpp", ] @@ -188,6 +191,9 @@ if (communication_netmanager_base_enable) { if (preference_native_preferences_enable) { sa_defines += [ "NATIVE_PREFERENCES_ENABLE" ] } +if (update_service_enable_run_on_demand_qos) { + sa_defines += [ "UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS" ] +} sa_defines += sqlite_defines sa_cflags = [ diff --git a/services/engine/include/update_service.h b/services/engine/include/update_service.h index a123318f0677f1f1381dd6e6aaa6f28fb2d8bed6..b0c6e5660a879676c2dd2b0fd11d80142971d3d0 100644 --- a/services/engine/include/update_service.h +++ b/services/engine/include/update_service.h @@ -22,6 +22,9 @@ #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iremote_stub.h" +#include "iservice_local_updater.h" +#include "iservice_online_updater.h" +#include "iservice_restorer.h" #include "system_ability.h" #include "update_service_impl_manager.h" @@ -36,66 +39,81 @@ public: explicit UpdateService(int32_t systemAbilityId, bool runOnCreate = true); ~UpdateService() override; - int32_t RegisterUpdateCallback(const UpgradeInfo &info, const sptr &updateCallback) override; + int32_t RegisterUpdateCallback(const UpgradeInfo &info, const sptr &updateCallback, + int32_t &funcResutl) override; - int32_t UnregisterUpdateCallback(const UpgradeInfo &info) override; + int32_t UnregisterUpdateCallback(const UpgradeInfo &info, int32_t &funcResutl) override; - int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult) override; + int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult, + int32_t &funcResult) override; int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) override; + const DownloadOptions &downloadOptions, BusinessError &businessError, int32_t &funcResutl) override; int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) override; + const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError, int32_t &funcResutl) override; int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) override; + const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError, int32_t &funcResutl) override; int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) override; + const UpgradeOptions &upgradeOptions, BusinessError &businessError, int32_t &funcResutl) override; int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest, - const ClearOptions &clearOptions, BusinessError &businessError) override; + const ClearOptions &clearOptions, BusinessError &businessError, int32_t &funcResutl) override; - int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) override; + int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError, int32_t &funcResutl) override; int32_t GetNewVersionInfo( - const UpgradeInfo &info, NewVersionInfo &newVersionInfo, BusinessError &businessError) override; + const UpgradeInfo &info, NewVersionInfo &newVersionInfo, BusinessError &businessError, + int32_t &funcResutl) override; int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, - BusinessError &businessError) override; + BusinessError &businessError, int32_t &funcResult) override; int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) override; + BusinessError &businessError, int32_t &funcResult) override; int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, - VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError) override; + VersionDescriptionInfo ¤tVersionDescriptionInfo, BusinessError &businessError, + int32_t &funcResult) override; - int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) override; + int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError, + int32_t &funcResutl) override; int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, - BusinessError &businessError) override; + BusinessError &businessError, int32_t &funcResult) override; - int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) override; + int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError, + int32_t &funcResult) override; - int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) override; + int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError, + int32_t &funcResult) override; - int32_t FactoryReset(BusinessError &businessError) override; + int32_t FactoryReset(BusinessError &businessError, int32_t &funcResult) override; int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) override; + const std::vector &packageNames, BusinessError &businessError, int32_t &funcResult) override; int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) override; + BusinessError &businessError, int32_t &funcResult) override; int Dump(int fd, const std::vector &args) override; - void RegisterOhFunc(); + int32_t CallbackEnter(uint32_t code) override; + + int32_t CallbackExit(uint32_t code, int32_t result) override; + + int32_t CallbackParcel(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; static sptr GetInstance(); - sptr GetUpgradeCallback(const UpgradeInfo &info); + sptr GetUpgradeCallback(const UpgradeInfo &infoi, int32_t &funcResutl); +#ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS +private: + void SetThreadPrio(int priority); +#endif #ifndef UPDATER_UT protected: @@ -106,6 +124,8 @@ protected: private: void DumpUpgradeCallback(const int fd); + bool IsCallerValid(); + bool IsPermissionGranted(uint32_t code); #ifndef UPDATER_UT private: @@ -140,7 +160,6 @@ private: std::shared_ptr updateImplMgr_ = nullptr; }; -int32_t HandleOhRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); } // namespace UpdateEngine } // namespace OHOS #endif // UPDATE_SERVICE_H \ No newline at end of file diff --git a/services/engine/include/update_service_stub.h b/services/engine/include/update_service_stub.h deleted file mode 100644 index 1c2186e747a1e5273d66d8ce7378489452b3514f..0000000000000000000000000000000000000000 --- a/services/engine/include/update_service_stub.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#ifndef UPDATE_SERVICE_STUB_H -#define UPDATE_SERVICE_STUB_H - -#include -#include -#include "iremote_stub.h" -#include "iupdate_service.h" -#include "message_parcel.h" -#include "parcel.h" - -namespace OHOS { -namespace UpdateEngine { -class UpdateServiceStub : public IRemoteStub { -public: - UpdateServiceStub(); - ~UpdateServiceStub() = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption &option) override; - - using UpdateServiceStubPtr = UpdateServiceStub *; - using RequestFuncType = int32_t (UpdateServiceStub::*)(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option); - - int32_t HandleRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption &option); - -private: - int32_t GetNewVersionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t GetNewVersionDescriptionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t GetCurrentVersionStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t GetCurrentVersionDescriptionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t GetTaskInfoStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t CheckNewVersionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t DownloadVersionStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t PauseDownloadStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t ResumeDownloadStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t DoUpdateStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t ClearErrorStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t TerminateUpgradeStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t SetUpgradePolicyStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t GetUpgradePolicyStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t RegisterUpdateCallbackStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t UnregisterUpdateCallbackStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t CancelStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t FactoryResetStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t ApplyNewVersionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - int32_t VerifyUpgradePackageStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option); - bool IsCallerValid(); - bool IsPermissionGranted(uint32_t code); - -private: - std::map requestFuncMap_; -}; -} // namespace UpdateEngine -} // namespace OHOS -#endif // UPDATE_SERVICE_STUB_H \ No newline at end of file diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index 7b2dd0ee73c3709fc6475b3085524a54287b844c..780ac9ed3351ab7c8c843ea439108084849961e5 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -22,33 +22,58 @@ #include "iservice_registry.h" #include "system_ability_definition.h" +#include "accesstoken_kit.h" #include "access_manager.h" -#include "dupdate_net_manager.h" +#include "access_token.h" #include "config_parse.h" +#include "dupdate_net_manager.h" #include "firmware_common.h" #include "firmware_manager.h" +#include "ipc_skeleton.h" +#include "module_manager.h" +#include "securec.h" #include "startup_manager.h" +#include "tokenid_kit.h" #include "update_log.h" #include "update_service_cache.h" #include "update_service_local_updater.h" +#include "update_service_module.h" #include "update_service_restorer.h" #include "update_service_util.h" +#include "update_system_event.h" -#include "update_service_module.h" -#include "module_manager.h" +#ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS +#include +#include +#endif + +using namespace std; namespace OHOS { namespace UpdateEngine { +constexpr const pid_t ROOT_UID = 0; +constexpr const pid_t EDM_UID = 3057; REGISTER_SYSTEM_ABILITY_BY_ID(UpdateService, UPDATE_DISTRIBUTED_SERVICE_ID, true) OHOS::sptr UpdateService::updateService_ { nullptr }; +#ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS +constexpr int OPEN_SO_PRIO = -20; +constexpr int NORMAL_PRIO = 0; +#endif + +int32_t CallResultToIpcResult(int32_t callResult) +{ + return callResult + CALL_RESULT_OFFSET; +} + void UpdateService::ClientDeathRecipient::OnRemoteDied(const wptr &remote) { ENGINE_LOGI("client DeathRecipient OnRemoteDied: %{public}s", upgradeInfo_.ToString().c_str()); sptr service = UpdateService::GetInstance(); + int32_t funcResult; if (service != nullptr) { - service->UnregisterUpdateCallback(upgradeInfo_); + service->UnregisterUpdateCallback(upgradeInfo_, funcResult); } } @@ -112,10 +137,11 @@ sptr UpdateService::GetInstance() return updateService_; } -int32_t UpdateService::RegisterUpdateCallback(const UpgradeInfo &info, const sptr &updateCallback) +int32_t UpdateService::RegisterUpdateCallback(const UpgradeInfo &info, const sptr &updateCallback, + int32_t &funcResult) { ENGINE_LOGI("RegisterUpdateCallback"); - UnregisterUpdateCallback(info); + UnregisterUpdateCallback(info, funcResult); { std::lock_guard lock(clientProxyMapLock_); ClientProxy clientProxy(info, updateCallback); @@ -129,7 +155,7 @@ int32_t UpdateService::RegisterUpdateCallback(const UpgradeInfo &info, const spt return INT_CALL_SUCCESS; } -int32_t UpdateService::UnregisterUpdateCallback(const UpgradeInfo &info) +int32_t UpdateService::UnregisterUpdateCallback(const UpgradeInfo &info, int32_t &funcResult) { ENGINE_LOGI("UnregisterUpdateCallback"); std::lock_guard lock(clientProxyMapLock_); @@ -143,7 +169,7 @@ int32_t UpdateService::UnregisterUpdateCallback(const UpgradeInfo &info) return INT_CALL_SUCCESS; } -sptr UpdateService::GetUpgradeCallback(const UpgradeInfo &info) +sptr UpdateService::GetUpgradeCallback(const UpgradeInfo &info, int32_t &funcResult) { std::lock_guard lock(clientProxyMapLock_); auto iter = clientProxyMap_.find(info); @@ -154,7 +180,7 @@ sptr UpdateService::GetUpgradeCallback(const UpgradeInfo &info) } int32_t UpdateService::GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -166,7 +192,7 @@ int32_t UpdateService::GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo int32_t UpdateService::GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -178,7 +204,7 @@ int32_t UpdateService::GetNewVersionDescription(const UpgradeInfo &info, const V } int32_t UpdateService::GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -190,7 +216,7 @@ int32_t UpdateService::GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVer int32_t UpdateService::GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions, VersionDescriptionInfo ¤tVersionDescriptionInfo, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -201,7 +227,8 @@ int32_t UpdateService::GetCurrentVersionDescription(const UpgradeInfo &info, businessError); } -int32_t UpdateService::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) +int32_t UpdateService::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError, + int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -212,7 +239,7 @@ int32_t UpdateService::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, } int32_t UpdateService::SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -222,7 +249,8 @@ int32_t UpdateService::SetUpgradePolicy(const UpgradeInfo &info, const UpgradePo return onlineUpdater->SetUpgradePolicy(info, policy, businessError); } -int32_t UpdateService::GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) +int32_t UpdateService::GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError, + int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -232,7 +260,8 @@ int32_t UpdateService::GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy & return onlineUpdater->GetUpgradePolicy(info, policy, businessError); } -int32_t UpdateService::CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult) +int32_t UpdateService::CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult, + int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -243,7 +272,7 @@ int32_t UpdateService::CheckNewVersion(const UpgradeInfo &info, BusinessError &b } int32_t UpdateService::Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const DownloadOptions &downloadOptions, BusinessError &businessError) + const DownloadOptions &downloadOptions, BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -254,7 +283,7 @@ int32_t UpdateService::Download(const UpgradeInfo &info, const VersionDigestInfo } int32_t UpdateService::PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) + const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("PauseDownload"); businessError.errorNum = CallResult::SUCCESS; @@ -263,7 +292,7 @@ int32_t UpdateService::PauseDownload(const UpgradeInfo &info, const VersionDiges } int32_t UpdateService::ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) + const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError, int32_t &funcResult) { ENGINE_LOGI("ResumeDownload allowNetwork:%{public}d", CAST_INT(resumeDownloadOptions.allowNetwork)); businessError.Build(CallResult::UN_SUPPORT, "ResumeDownload unsupport"); @@ -271,7 +300,7 @@ int32_t UpdateService::ResumeDownload(const UpgradeInfo &info, const VersionDige } int32_t UpdateService::Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const UpgradeOptions &upgradeOptions, BusinessError &businessError) + const UpgradeOptions &upgradeOptions, BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -282,7 +311,7 @@ int32_t UpdateService::Upgrade(const UpgradeInfo &info, const VersionDigestInfo } int32_t UpdateService::ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo, - const ClearOptions &clearOptions, BusinessError &businessError) + const ClearOptions &clearOptions, BusinessError &businessError, int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -292,7 +321,8 @@ int32_t UpdateService::ClearError(const UpgradeInfo &info, const VersionDigestIn return onlineUpdater->ClearError(info, versionDigestInfo, clearOptions, businessError); } -int32_t UpdateService::TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) +int32_t UpdateService::TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError, + int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -302,7 +332,8 @@ int32_t UpdateService::TerminateUpgrade(const UpgradeInfo &info, BusinessError & return onlineUpdater->TerminateUpgrade(info, businessError); } -int32_t UpdateService::Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) +int32_t UpdateService::Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError, + int32_t &funcResult) { sptr onlineUpdater = updateImplMgr_->GetOnlineUpdater(info); if (onlineUpdater == nullptr) { @@ -312,7 +343,7 @@ int32_t UpdateService::Cancel(const UpgradeInfo &info, int32_t service, Business return onlineUpdater->Cancel(info, service, businessError); } -int32_t UpdateService::FactoryReset(BusinessError &businessError) +int32_t UpdateService::FactoryReset(BusinessError &businessError, int32_t &funcResult) { sptr restorer = new UpdateServiceRestorer(); if (restorer == nullptr) { @@ -323,7 +354,7 @@ int32_t UpdateService::FactoryReset(BusinessError &businessError) } int32_t UpdateService::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::vector &packageNames, BusinessError &businessError) + const std::vector &packageNames, BusinessError &businessError, int32_t &funcResult) { sptr localUpdater = new UpdateServiceLocalUpdater(); if (localUpdater == nullptr) { @@ -334,7 +365,7 @@ int32_t UpdateService::ApplyNewVersion(const UpgradeInfo &info, const std::strin } int32_t UpdateService::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, - BusinessError &businessError) + BusinessError &businessError, int32_t &funcResult) { sptr localUpdater = new UpdateServiceLocalUpdater(); if (localUpdater == nullptr) { @@ -378,7 +409,8 @@ void BuildTaskInfoDump(const int fd) TaskInfo taskInfo; BusinessError businessError; UpgradeInfo upgradeInfo; - service->GetTaskInfo(upgradeInfo, taskInfo, businessError); + int32_t funcResult; + service->GetTaskInfo(upgradeInfo, taskInfo, businessError, funcResult); if (!taskInfo.existTask) { dprintf(fd, "TaskInfo is empty\n"); return; @@ -425,6 +457,17 @@ int UpdateService::Dump(int fd, const std::vector &args) } } +#ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS +void UpdateService::SetThreadPrio(int priority) +{ + int tid = syscall(SYS_gettid); + ENGINE_LOGI("set tid: %{public}d priority:%{public}d.", tid, priority); + if (setpriority(PRIO_PROCESS, tid, priority) != 0) { + ENGINE_LOGE("set tid: %{public}d priority:%{public}d failed.", tid, priority); + } +} +#endif + void UpdateService::OnStart(const SystemAbilityOnDemandReason &startReason) { ENGINE_LOGI("UpdaterService oh OnStart, startReason name %{public}s, id %{public}d, value %{public}s", @@ -437,10 +480,13 @@ void UpdateService::OnStart(const SystemAbilityOnDemandReason &startReason) DelayedSingleton::GetInstance()->LoadConfigInfo(); // 启动读取配置信息 std::string libPath = DelayedSingleton::GetInstance()->GetModuleLibPath(); ENGINE_LOGI("GetModuleLibPath %{public}s ", libPath.c_str()); +#ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS + SetThreadPrio(OPEN_SO_PRIO); +#endif ModuleManager::GetInstance().LoadModule(libPath); - - ENGINE_LOGI("RegisterOhFunc HandleOhRemoteRequest"); - RegisterOhFunc(); +#ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS + SetThreadPrio(NORMAL_PRIO); +#endif if (!ModuleManager::GetInstance().IsModuleLoaded()) { ENGINE_LOGI("IsModuleLoaded false, init updateservice_sa"); @@ -474,36 +520,86 @@ void UpdateService::OnStop(const SystemAbilityOnDemandReason &stopReason) ModuleManager::GetInstance().HandleOnStartOnStopFunc("OnStop", stopReason); } -int32_t HandleOhRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - return UpdateService::GetInstance()-> HandleRemoteRequest(code, data, reply, option); -} - -void UpdateService::RegisterOhFunc() -{ - std::vector codes = { - CAST_UINT(UpdaterSaInterfaceCode::CHECK_VERSION), - CAST_UINT(UpdaterSaInterfaceCode::DOWNLOAD), - CAST_UINT(UpdaterSaInterfaceCode::PAUSE_DOWNLOAD), - CAST_UINT(UpdaterSaInterfaceCode::RESUME_DOWNLOAD), - CAST_UINT(UpdaterSaInterfaceCode::UPGRADE), - CAST_UINT(UpdaterSaInterfaceCode::CLEAR_ERROR), - CAST_UINT(UpdaterSaInterfaceCode::TERMINATE_UPGRADE), - CAST_UINT(UpdaterSaInterfaceCode::SET_POLICY), - CAST_UINT(UpdaterSaInterfaceCode::GET_POLICY), - CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION), - CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION_DESCRIPTION), - CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION), - CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION_DESCRIPTION), - CAST_UINT(UpdaterSaInterfaceCode::GET_TASK_INFO), - CAST_UINT(UpdaterSaInterfaceCode::REGISTER_CALLBACK), - CAST_UINT(UpdaterSaInterfaceCode::UNREGISTER_CALLBACK), - CAST_UINT(UpdaterSaInterfaceCode::CANCEL), - CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET), - CAST_UINT(UpdaterSaInterfaceCode::APPLY_NEW_VERSION), - CAST_UINT(UpdaterSaInterfaceCode::VERIFY_UPGRADE_PACKAGE) - }; - RegisterFunc(codes, HandleOhRemoteRequest); +int32_t UpdateService::CallbackEnter(uint32_t code) +{ + ENGINE_LOGI("UpdateService CallbackEnter, code: %{public}u", code); + if (!IsCallerValid()) { + ENGINE_LOGE("UpdateService IsCallerValid false"); + return CallResultToIpcResult(INT_NOT_SYSTEM_APP); + } + + if (!IsPermissionGranted(code)) { + ENGINE_LOGE("UpdateService code %{public}d IsPermissionGranted false", code); + return CallResultToIpcResult(INT_APP_NOT_GRANTED); + } + + if (code == CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET)) { + SYS_EVENT_SYSTEM_RESET(0, UpdateSystemEvent::RESET_START); + } + + return INT_CALL_SUCCESS; +} + +int32_t UpdateService::CallbackExit(uint32_t code, int32_t result) +{ + return INT_CALL_SUCCESS; +} + +int32_t UpdateService::CallbackParcel(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + int32_t ret; + if (!ModuleManager::GetInstance().IsModuleLoaded()) { + ENGINE_LOGI("IsModuleLoaded false"); + return INT_CALL_SUCCESS; + } else { + ENGINE_LOGI("IsModuleLoaded true"); + if (!ModuleManager::GetInstance().IsMapFuncExist(code)) { + ENGINE_LOGE("UpdateService OnRemoteRequest code %{public}u not found", code); + ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); + ENGINE_LOGE("UpdateService OnRemoteRequest code %{public}d", ret); + return INT_CALL_FAIL; + } + ret = ModuleManager::GetInstance().HandleFunc(code, data, reply, option); + ENGINE_LOGE("CallbackParcel deal result code %{public}d", ret); + return INT_CALL_FAIL; + } } + +bool UpdateService::IsCallerValid() +{ + OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + auto callerTokenType = OHOS::Security::AccessToken::AccessTokenKit::GetTokenType(callerToken); + switch (callerTokenType) { + case OHOS::Security::AccessToken::TypeATokenTypeEnum::TOKEN_HAP: { + uint64_t callerFullTokenID = IPCSkeleton::GetCallingFullTokenID(); + // hap进程只允许系统应用调用 + return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerFullTokenID); + } + case OHOS::Security::AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE: { + pid_t callerUid = IPCSkeleton::GetCallingUid(); + // native进程只允许root权限和edm调用 + return callerUid == ROOT_UID || callerUid == EDM_UID; + } + default: + // 其他情况调用予以禁止 + return false; + } +} + +bool UpdateService::IsPermissionGranted(uint32_t code) +{ + Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + string permission = "ohos.permission.UPDATE_SYSTEM"; + if (code == CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET)) { + permission = "ohos.permission.FACTORY_RESET"; + } + int verifyResult = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permission); + bool isPermissionGranted = verifyResult == Security::AccessToken::PERMISSION_GRANTED; + if (!isPermissionGranted) { + ENGINE_LOGE("%{public}s not granted, code:%{public}d", permission.c_str(), code); + } + return isPermissionGranted; +} + } // namespace UpdateEngine } // namespace OHOS diff --git a/services/engine/src/update_service_stub.cpp b/services/engine/src/update_service_stub.cpp deleted file mode 100644 index 4e1966af5b3dc5cd7a875f14ebfad6010343e839..0000000000000000000000000000000000000000 --- a/services/engine/src/update_service_stub.cpp +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright (c) 2021 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 "accesstoken_kit.h" -#include "access_token.h" -#include "ipc_skeleton.h" -#include "message_parcel_helper.h" -#include "securec.h" -#include "tokenid_kit.h" -#include "update_define.h" -#include "update_log.h" -#include "update_service_stub.h" -#include "update_system_event.h" -#include "updater_sa_ipc_interface_code.h" -#include "../../../interfaces/inner_api/modulemgr/include/module_manager.h" - -using namespace std; - -namespace OHOS { -namespace UpdateEngine { -constexpr const pid_t ROOT_UID = 0; -constexpr const pid_t EDM_UID = 3057; -static constexpr int32_t MAX_VECTOR_SIZE = 128; - -#define CALL_RESULT_TO_IPC_RESULT(callResult) ((callResult) + CALL_RESULT_OFFSET) - -#define RETURN_FAIL_WHEN_SERVICE_NULL(service) \ - ENGINE_CHECK((service) != nullptr, return INT_CALL_IPC_ERR, "service null") - -#define CALL_RESULT_TO_IPC_RESULT(callResult) ((callResult) + CALL_RESULT_OFFSET) - -UpdateServiceStub::UpdateServiceStub() -{ - requestFuncMap_ = { - {CAST_UINT(UpdaterSaInterfaceCode::CHECK_VERSION), &UpdateServiceStub::CheckNewVersionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::DOWNLOAD), &UpdateServiceStub::DownloadVersionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::PAUSE_DOWNLOAD), &UpdateServiceStub::PauseDownloadStub}, - {CAST_UINT(UpdaterSaInterfaceCode::RESUME_DOWNLOAD), &UpdateServiceStub::ResumeDownloadStub}, - {CAST_UINT(UpdaterSaInterfaceCode::UPGRADE), &UpdateServiceStub::DoUpdateStub}, - {CAST_UINT(UpdaterSaInterfaceCode::CLEAR_ERROR), &UpdateServiceStub::ClearErrorStub}, - {CAST_UINT(UpdaterSaInterfaceCode::TERMINATE_UPGRADE), &UpdateServiceStub::TerminateUpgradeStub}, - {CAST_UINT(UpdaterSaInterfaceCode::SET_POLICY), &UpdateServiceStub::SetUpgradePolicyStub}, - {CAST_UINT(UpdaterSaInterfaceCode::GET_POLICY), &UpdateServiceStub::GetUpgradePolicyStub}, - {CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION), &UpdateServiceStub::GetNewVersionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION_DESCRIPTION), - &UpdateServiceStub::GetNewVersionDescriptionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION), &UpdateServiceStub::GetCurrentVersionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION_DESCRIPTION), - &UpdateServiceStub::GetCurrentVersionDescriptionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::GET_TASK_INFO), &UpdateServiceStub::GetTaskInfoStub}, - {CAST_UINT(UpdaterSaInterfaceCode::REGISTER_CALLBACK), &UpdateServiceStub::RegisterUpdateCallbackStub}, - {CAST_UINT(UpdaterSaInterfaceCode::UNREGISTER_CALLBACK), &UpdateServiceStub::UnregisterUpdateCallbackStub}, - {CAST_UINT(UpdaterSaInterfaceCode::CANCEL), &UpdateServiceStub::CancelStub}, - {CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET), &UpdateServiceStub::FactoryResetStub}, - {CAST_UINT(UpdaterSaInterfaceCode::APPLY_NEW_VERSION), &UpdateServiceStub::ApplyNewVersionStub}, - {CAST_UINT(UpdaterSaInterfaceCode::VERIFY_UPGRADE_PACKAGE), &UpdateServiceStub::VerifyUpgradePackageStub} - }; -} - -int32_t UpdateServiceStub::GetNewVersionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - NewVersionInfo newVersionInfo = {}; - BusinessError businessError = {}; - int32_t ret = service->GetNewVersionInfo(upgradeInfo, newVersionInfo, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to GetNewVersionInfo"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteNewVersionInfo(reply, newVersionInfo); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::GetNewVersionDescriptionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - VersionDigestInfo versionDigestInfo; - DescriptionOptions descriptionOptions; - VersionDescriptionInfo newVersionDescriptionInfo; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::ReadDescriptionOptions(data, descriptionOptions); - - int32_t ret = service->GetNewVersionDescription(upgradeInfo, versionDigestInfo, descriptionOptions, - newVersionDescriptionInfo, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to GetNewVersionDescription"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteVersionDescriptionInfo(reply, newVersionDescriptionInfo); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::GetCurrentVersionStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - CurrentVersionInfo currentVersionInfo = {}; - BusinessError businessError = {}; - int32_t ret = service->GetCurrentVersionInfo(upgradeInfo, currentVersionInfo, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to GetCurrentVersion"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteCurrentVersionInfo(reply, currentVersionInfo); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::GetCurrentVersionDescriptionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - DescriptionOptions descriptionOptions; - VersionDescriptionInfo currentVersionDescriptionInfo; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadDescriptionOptions(data, descriptionOptions); - - int32_t ret = service->GetCurrentVersionDescription(upgradeInfo, descriptionOptions, currentVersionDescriptionInfo, - businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to GetCurrentVersionDescription"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteVersionDescriptionInfo(reply, currentVersionDescriptionInfo); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::GetTaskInfoStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - TaskInfo taskInfo = {}; - BusinessError businessError = {}; - int32_t ret = service->GetTaskInfo(upgradeInfo, taskInfo, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to GetTaskInfo"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteTaskInfo(reply, taskInfo); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::CheckNewVersionStub(UpdateServiceStub::UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - BusinessError businessError; - CheckResult checkResult; - int res = service->CheckNewVersion(upgradeInfo, businessError, checkResult); - ENGINE_CHECK(res == INT_CALL_SUCCESS, return res, "Failed to CheckNewVersion"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteCheckResult(reply, checkResult); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::DownloadVersionStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - VersionDigestInfo versionDigestInfo; - DownloadOptions downloadOptions; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::ReadDownloadOptions(data, downloadOptions); - int32_t ret = service->Download(upgradeInfo, versionDigestInfo, downloadOptions, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to DownloadVersion"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::PauseDownloadStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - VersionDigestInfo versionDigestInfo; - PauseDownloadOptions pauseDownloadOptions; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::ReadPauseDownloadOptions(data, pauseDownloadOptions); - - int32_t ret = service->PauseDownload(upgradeInfo, versionDigestInfo, pauseDownloadOptions, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to PauseDownload"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::ResumeDownloadStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - VersionDigestInfo versionDigestInfo; - ResumeDownloadOptions resumeDownloadOptions; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::ReadResumeDownloadOptions(data, resumeDownloadOptions); - - int32_t ret = service->ResumeDownload(upgradeInfo, versionDigestInfo, resumeDownloadOptions, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to ResumeDownload"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::DoUpdateStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - VersionDigestInfo versionDigestInfo; - UpgradeOptions upgradeOptions; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::ReadUpgradeOptions(data, upgradeOptions); - - int32_t ret = service->Upgrade(upgradeInfo, versionDigestInfo, upgradeOptions, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to Upgrade"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::ClearErrorStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - VersionDigestInfo versionDigestInfo; - ClearOptions clearOptions; - BusinessError businessError; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - MessageParcelHelper::ReadVersionDigestInfo(data, versionDigestInfo); - MessageParcelHelper::ReadClearOptions(data, clearOptions); - - int32_t ret = service->ClearError(upgradeInfo, versionDigestInfo, clearOptions, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to ClearError"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::TerminateUpgradeStub(UpdateServiceStubPtr service, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - - BusinessError businessError; - int32_t ret = service->TerminateUpgrade(upgradeInfo, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to TerminateUpgrade"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::SetUpgradePolicyStub(UpdateServiceStubPtr service, - MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - UpgradePolicy policy = {}; - MessageParcelHelper::ReadUpgradePolicy(data, policy); - BusinessError businessError = {}; - int32_t ret = service->SetUpgradePolicy(upgradeInfo, policy, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to SetUpgradePolicy"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::GetUpgradePolicyStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - UpgradePolicy policy = {}; - BusinessError businessError = {}; - int32_t ret = service->GetUpgradePolicy(upgradeInfo, policy, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to GetUpgradePolicy"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - MessageParcelHelper::WriteUpgradePolicy(reply, policy); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::RegisterUpdateCallbackStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - ENGINE_LOGI("RegisterUpdateCallbackStub"); - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - auto remote = data.ReadRemoteObject(); - ENGINE_CHECK(remote != nullptr, return INT_CALL_IPC_ERR, "Failed to read remote obj"); - return service->RegisterUpdateCallback(upgradeInfo, iface_cast(remote)); -} - -int32_t UpdateServiceStub::UnregisterUpdateCallbackStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - return service->UnregisterUpdateCallback(upgradeInfo); -} - -int32_t UpdateServiceStub::CancelStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo {}; - BusinessError businessError = {}; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - int32_t ret = service->Cancel(upgradeInfo, data.ReadInt32(), businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to cancel"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::FactoryResetStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - SYS_EVENT_SYSTEM_RESET(0, UpdateSystemEvent::RESET_START); - BusinessError businessError; - int32_t ret = service->FactoryReset(businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to FactoryReset"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::ApplyNewVersionStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - UpgradeInfo upgradeInfo; - MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); - string miscFile = Str16ToStr8(data.ReadString16()); - - vector packageNames; - int32_t size = data.ReadInt32(); - if (size > MAX_VECTOR_SIZE) { - ENGINE_LOGE("ReadComponentDescriptions size is over, size=%{public}d", size); - return INT_CALL_FAIL; - } - for (size_t i = 0; i < static_cast(size); i++) { - packageNames.emplace_back(Str16ToStr8(data.ReadString16())); - } - BusinessError businessError; - int32_t ret = service->ApplyNewVersion(upgradeInfo, miscFile, packageNames, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to ApplyNewVersion"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -int32_t UpdateServiceStub::VerifyUpgradePackageStub(UpdateServiceStubPtr service, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - RETURN_FAIL_WHEN_SERVICE_NULL(service); - string packagePath = Str16ToStr8(data.ReadString16()); - string keyPath = Str16ToStr8(data.ReadString16()); - BusinessError businessError; - int32_t ret = service->VerifyUpgradePackage(packagePath, keyPath, businessError); - ENGINE_CHECK(ret == INT_CALL_SUCCESS, return ret, "Failed to VerifyUpgradePackage"); - MessageParcelHelper::WriteBusinessError(reply, businessError); - return INT_CALL_SUCCESS; -} - -bool UpdateServiceStub::IsCallerValid() -{ - OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - auto callerTokenType = OHOS::Security::AccessToken::AccessTokenKit::GetTokenType(callerToken); - switch (callerTokenType) { - case OHOS::Security::AccessToken::TypeATokenTypeEnum::TOKEN_HAP: { - uint64_t callerFullTokenID = IPCSkeleton::GetCallingFullTokenID(); - // hap进程只允许系统应用调用 - return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerFullTokenID); - } - case OHOS::Security::AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE: { - pid_t callerUid = IPCSkeleton::GetCallingUid(); - // native进程只允许root权限和edm调用 - return callerUid == ROOT_UID || callerUid == EDM_UID; - } - default: - // 其他情况调用予以禁止 - return false; - } -} - -bool UpdateServiceStub::IsPermissionGranted(uint32_t code) -{ - Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - string permission = "ohos.permission.UPDATE_SYSTEM"; - if (code == CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET)) { - permission = "ohos.permission.FACTORY_RESET"; - } - int verifyResult = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permission); - bool isPermissionGranted = verifyResult == Security::AccessToken::PERMISSION_GRANTED; - if (!isPermissionGranted) { - ENGINE_LOGE("%{public}s not granted, code:%{public}d", permission.c_str(), code); - } - return isPermissionGranted; -} - -int32_t UpdateServiceStub::OnRemoteRequest(uint32_t code, - MessageParcel& data, MessageParcel& reply, MessageOption &option) -{ - ENGINE_LOGI("UpdateServiceStub func code %{public}u", code); - if (!ModuleManager::GetInstance().IsMapFuncExist(code)) { - ENGINE_LOGE("UpdateServiceStub OnRemoteRequest code %{public}u not found", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return ModuleManager::GetInstance().HandleFunc(code, data, reply, option); -} - -int32_t UpdateServiceStub::HandleRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - ENGINE_LOGE("UpdateServiceStub ReadInterfaceToken fail"); - return CALL_RESULT_TO_IPC_RESULT(INT_CALL_IPC_ERR); - } - - if (!IsCallerValid()) { - ENGINE_LOGE("UpdateServiceStub IsCallerValid false"); - return CALL_RESULT_TO_IPC_RESULT(INT_NOT_SYSTEM_APP); - } - if (!IsPermissionGranted(code)) { - ENGINE_LOGE("UpdateServiceStub code %{public}d IsPermissionGranted false", code); - UpgradeInfo tmpInfo; - MessageParcelHelper::ReadUpgradeInfo(data, tmpInfo); - return CALL_RESULT_TO_IPC_RESULT(INT_APP_NOT_GRANTED); - } - auto iter = requestFuncMap_.find(code); - return CALL_RESULT_TO_IPC_RESULT((this->*(iter->second))(this, data, reply, option)); -} -} // namespace UpdateEngine -} // namespace OHOS diff --git a/services/engine/src/update_service_util_hmos.cpp b/services/engine/src/update_service_util_hmos.cpp index 1e347093237d1553b68bfa4a250cb35a9a234781..946c77b32f8bf40b2b2233c2be02d153acdb9ccb 100644 --- a/services/engine/src/update_service_util_hmos.cpp +++ b/services/engine/src/update_service_util_hmos.cpp @@ -48,7 +48,8 @@ sptr UpdateServiceUtil::GetUpgradeCallback(const UpgradeInfo &u ENGINE_LOGI("GetUpgradeCallback no instance"); return nullptr; } - return service->GetUpgradeCallback(upgradeInfo); + int32_t funcResult; + return service->GetUpgradeCallback(upgradeInfo, funcResult); } } // namespace UpdateEngine } // namespace OHOS \ No newline at end of file diff --git a/services/firmware/data/db/include/firmware_component.h b/services/firmware/data/db/include/firmware_component.h index bb8d11ab860dfa2437fe16839826e8303a3012d5..cd7405b5e0e8102b5df40cf30d1e85fe14cf7885 100644 --- a/services/firmware/data/db/include/firmware_component.h +++ b/services/firmware/data/db/include/firmware_component.h @@ -58,7 +58,7 @@ struct FirmwareComponent { UpgradeStatus status = UpgradeStatus::INIT; int32_t progress = 0; int64_t recordPoint = 0; - + std::string ToString() { return std::string("FirmwareComponent: ")