From c9b1776c3676b4199dd295a5ec90afbbb644ad8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Tue, 18 Mar 2025 12:00:03 +0800 Subject: [PATCH 1/6] =?UTF-8?q?idl=20=E6=95=B4=E6=94=B9=20Signed-off-by:?= =?UTF-8?q?=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- foundations/model/include/business_error.h | 8 +- .../js/napi/update/src/local_updater.cpp | 9 +- .../js/napi/update/src/update_client.cpp | 60 +- interfaces/inner_api/engine/BUILD.gn | 24 +- .../inner_api/engine/IUpdateService.idl | 72 +++ .../IUpdateCallback.idl} | 20 +- .../engine/include/update_callback.h | 2 +- .../engine/include/update_service_kits_impl.h | 42 +- .../engine/include/update_service_proxy.h | 86 --- .../inner_api/engine/src/update_callback.cpp | 3 +- .../engine/src/update_service_kits_impl.cpp | 88 +-- .../engine/src/update_service_proxy.cpp | 525 ------------------ .../feature/update/model/check/check_result.h | 8 +- .../update/model/check/src/check_result.cpp | 58 ++ .../update/model/clear/clear_options.h | 7 +- .../update/model/download/download_options.h | 8 +- .../model/download/pause_download_options.h | 8 +- .../model/download/resume_download_options.h | 7 +- .../feature/update/model/event/event_info.h | 14 +- .../update/model/event/src/event_info.cpp | 57 ++ .../include/message_parcel_helper.h | 82 +-- .../src/message_parcel_helper.cpp | 364 ++---------- .../inner_api/feature/update/model/model.gni | 13 + .../model/policy/src/upgrade_policy.cpp | 78 +++ .../update/model/policy/upgrade_policy.h | 7 +- .../update/model/task/src/task_info.cpp | 50 +- .../feature/update/model/task/task_info.h | 12 +- .../update/model/upgrade/upgrade_options.h | 9 +- .../model/upgrade_info/src/business_error.cpp | 63 +++ .../model/upgrade_info/src/clear_options.cpp} | 45 +- .../upgrade_info/src/download_options.cpp | 56 ++ .../src/pause_download_options.cpp | 51 +- .../src/resume_download_options.cpp | 50 ++ .../model/upgrade_info/src/upgrade_info.cpp | 67 +++ .../upgrade_info/src/upgrade_options.cpp} | 47 +- .../update/model/upgrade_info/upgrade_info.h | 12 +- .../current_version/current_version_info.h | 11 +- .../src/current_version_info.cpp | 60 ++ .../description/description_options.h | 8 +- .../description/src/description_options.cpp | 57 ++ .../src/version_description_info.cpp | 48 ++ .../description/version_description_info.h | 15 +- .../new_version/new_version_info.h | 9 +- .../new_version/src/new_version_info.cpp | 56 ++ .../version_info/src/version_digest_info.cpp | 31 ++ .../model/version_info/version_digest_info.h | 9 +- .../inner_api/include/update_service_kits.h | 42 +- .../callback/src/base_callback_utils.cpp | 3 +- services/engine/BUILD.gn | 20 + services/engine/IUpdateService.idl | 72 +++ .../engine/callback/IUpdateCallback.idl | 27 +- services/engine/engine_sa.gni | 2 - services/engine/include/update_service.h | 62 ++- services/engine/include/update_service_stub.h | 91 --- services/engine/src/update_service.cpp | 189 +++++-- services/engine/src/update_service_stub.cpp | 459 --------------- .../engine/src/update_service_util_hmos.cpp | 3 +- 57 files changed, 1527 insertions(+), 1859 deletions(-) create mode 100644 interfaces/inner_api/engine/IUpdateService.idl rename interfaces/inner_api/engine/{include/update_callback_stub.h => callback/IUpdateCallback.idl} (53%) delete mode 100644 interfaces/inner_api/engine/include/update_service_proxy.h delete mode 100644 interfaces/inner_api/engine/src/update_service_proxy.cpp create mode 100644 interfaces/inner_api/feature/update/model/check/src/check_result.cpp create mode 100644 interfaces/inner_api/feature/update/model/policy/src/upgrade_policy.cpp rename services/callback/src/update_callback_proxy.cpp => interfaces/inner_api/feature/update/model/task/src/task_info.cpp (43%) create mode 100644 interfaces/inner_api/feature/update/model/upgrade_info/src/business_error.cpp rename interfaces/inner_api/{engine/src/update_callback_stub.cpp => feature/update/model/upgrade_info/src/clear_options.cpp} (44%) create mode 100644 interfaces/inner_api/feature/update/model/upgrade_info/src/download_options.cpp rename services/callback/include/update_callback_proxy.h => interfaces/inner_api/feature/update/model/upgrade_info/src/pause_download_options.cpp (37%) create mode 100644 interfaces/inner_api/feature/update/model/upgrade_info/src/resume_download_options.cpp rename interfaces/inner_api/feature/update/{api/update_service/iupdate_service.h => model/upgrade_info/src/upgrade_options.cpp} (44%) create mode 100644 interfaces/inner_api/feature/update/model/version_info/current_version/src/current_version_info.cpp create mode 100644 interfaces/inner_api/feature/update/model/version_info/description/src/description_options.cpp create mode 100644 interfaces/inner_api/feature/update/model/version_info/description/src/version_description_info.cpp create mode 100644 interfaces/inner_api/feature/update/model/version_info/new_version/src/new_version_info.cpp create mode 100644 services/engine/IUpdateService.idl rename interfaces/inner_api/feature/update/api/callback/iupdate_callback.h => services/engine/callback/IUpdateCallback.idl (49%) delete mode 100644 services/engine/include/update_service_stub.h delete mode 100644 services/engine/src/update_service_stub.cpp diff --git a/foundations/model/include/business_error.h b/foundations/model/include/business_error.h index 24a7f572..25e7382f 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 b52c026b..66e65be3 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 2bc0d39d..54b97bd8 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 ce6b9378..d289aa10 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 00000000..87bdab76 --- /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 b9249be1..034e7b9d 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 8d83ff6f..3b5a1b7c 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 f04b1105..1f1b1b58 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 a0655af8..00000000 --- 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 181c5966..11905571 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 060b2888..0b8c48d4 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 cc2f65f9..00000000 --- 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/check_result.h index 828fe406..09a9a362 100644 --- a/interfaces/inner_api/feature/update/model/check/check_result.h +++ b/interfaces/inner_api/feature/update/model/check/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/src/check_result.cpp b/interfaces/inner_api/feature/update/model/check/src/check_result.cpp new file mode 100644 index 00000000..44a035af --- /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 5b8abe89..ce926939 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 d8e38097..19efb065 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 bd26b4de..e77d514d 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 22a35d16..d2d1c801 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 461d58f6..4a38b275 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 ffea4a75..663db594 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 0990c551..043718e5 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 6e2f93c7..a95d8a17 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 2dba0c79..8791c2a9 100644 --- a/interfaces/inner_api/feature/update/model/model.gni +++ b/interfaces/inner_api/feature/update/model/model.gni @@ -33,13 +33,26 @@ model_include = [ "../feature/update/model/version_info/new_version", ] 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/src/upgrade_policy.cpp b/interfaces/inner_api/feature/update/model/policy/src/upgrade_policy.cpp new file mode 100644 index 00000000..ce73aa41 --- /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/policy/upgrade_policy.h b/interfaces/inner_api/feature/update/model/policy/upgrade_policy.h index 97fcf583..45dfd942 100644 --- a/interfaces/inner_api/feature/update/model/policy/upgrade_policy.h +++ b/interfaces/inner_api/feature/update/model/policy/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/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 3ab9fa96..01fd1ce5 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/task/task_info.h b/interfaces/inner_api/feature/update/model/task/task_info.h index d9651f5d..9a55615f 100644 --- a/interfaces/inner_api/feature/update/model/task/task_info.h +++ b/interfaces/inner_api/feature/update/model/task/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/interfaces/inner_api/feature/update/model/upgrade/upgrade_options.h b/interfaces/inner_api/feature/update/model/upgrade/upgrade_options.h index c8b9d9a6..9c4a5a22 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/src/business_error.cpp b/interfaces/inner_api/feature/update/model/upgrade_info/src/business_error.cpp new file mode 100644 index 00000000..3265de07 --- /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 a8be6b92..0a267832 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 00000000..a833bb62 --- /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 a0d99c0e..64f5bdb6 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 00000000..8b50b184 --- /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 d088c888..4a175fe2 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 dda1db37..bd202678 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/upgrade_info/upgrade_info.h b/interfaces/inner_api/feature/update/model/upgrade_info/upgrade_info.h index c604c500..0464e9d6 100644 --- a/interfaces/inner_api/feature/update/model/upgrade_info/upgrade_info.h +++ b/interfaces/inner_api/feature/update/model/upgrade_info/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/version_info/current_version/current_version_info.h b/interfaces/inner_api/feature/update/model/version_info/current_version/current_version_info.h index d6645118..7557d793 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/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 00000000..8cb6ddc1 --- /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/description_options.h b/interfaces/inner_api/feature/update/model/version_info/description/description_options.h index 192bf1d0..60b96029 100644 --- a/interfaces/inner_api/feature/update/model/version_info/description/description_options.h +++ b/interfaces/inner_api/feature/update/model/version_info/description/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/src/description_options.cpp b/interfaces/inner_api/feature/update/model/version_info/description/src/description_options.cpp new file mode 100644 index 00000000..693d3553 --- /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 00000000..e1cdccc0 --- /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/description/version_description_info.h b/interfaces/inner_api/feature/update/model/version_info/description/version_description_info.h index 83fa61b5..76a881ea 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/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/new_version/new_version_info.h b/interfaces/inner_api/feature/update/model/version_info/new_version/new_version_info.h index 6578830f..746edecb 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/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 00000000..3a64f184 --- /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 e3c1217e..7f362412 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 188c9ca7..761630ea 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 39d38b01..3034e533 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 1731c69c..6302d7bc 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 c3ae8190..ec47f2a9 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" @@ -42,8 +58,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 00000000..87bdab76 --- /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 7d212634..034e7b9d 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 602a0f14..74a5bb23 100644 --- a/services/engine/engine_sa.gni +++ b/services/engine/engine_sa.gni @@ -35,7 +35,6 @@ declare_args() { } 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", @@ -51,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", ] diff --git a/services/engine/include/update_service.h b/services/engine/include/update_service.h index 85e18c95..b0c6e566 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,67 +39,77 @@ 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; - static sptr GetInstance(); + int32_t CallbackExit(uint32_t code, int32_t result) override; + + int32_t CallbackParcel(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - sptr GetUpgradeCallback(const UpgradeInfo &info); + static sptr GetInstance(); + sptr GetUpgradeCallback(const UpgradeInfo &infoi, int32_t &funcResutl); #ifdef UPDATE_SERVICE_ENABLE_RUN_ON_DEMAND_QOS private: void SetThreadPrio(int priority); @@ -111,6 +124,8 @@ protected: private: void DumpUpgradeCallback(const int fd); + bool IsCallerValid(); + bool IsPermissionGranted(uint32_t code); #ifndef UPDATER_UT private: @@ -145,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 1c2186e7..00000000 --- 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 53d8cddc..32aef2c0 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -22,27 +22,37 @@ #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 }; @@ -52,12 +62,18 @@ 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); } } @@ -121,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); @@ -138,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_); @@ -152,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); @@ -163,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) { @@ -175,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) { @@ -187,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) { @@ -199,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) { @@ -210,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) { @@ -221,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) { @@ -231,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) { @@ -241,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) { @@ -252,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) { @@ -263,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; @@ -272,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"); @@ -280,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) { @@ -291,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) { @@ -301,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) { @@ -311,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) { @@ -321,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) { @@ -332,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) { @@ -343,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) { @@ -387,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; @@ -465,9 +488,6 @@ void UpdateService::OnStart(const SystemAbilityOnDemandReason &startReason) SetThreadPrio(NORMAL_PRIO); #endif - ENGINE_LOGI("RegisterOhFunc HandleOhRemoteRequest"); - RegisterOhFunc(); - if (!ModuleManager::GetInstance().IsModuleLoaded()) { ENGINE_LOGI("IsModuleLoaded false, init updateservice_sa"); DelayedSingleton::GetInstance()->Init(); @@ -500,36 +520,85 @@ 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 4e1966af..00000000 --- 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 1e347093..946c77b3 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 -- Gitee From f88c5a9f449381ff0a8f70f51e6291f5bc2e1617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Tue, 18 Mar 2025 08:53:18 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Ecode=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- services/engine/src/update_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index 32aef2c0..f9b9a672 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -552,7 +552,7 @@ int32_t UpdateService::CallbackParcel(uint32_t code, MessageParcel &data, Messag ENGINE_LOGI("IsModuleLoaded false"); return INT_CALL_SUCCESS; } else { - ENGINE_LOGI("IsModuleLoaded true"); + ENGINE_LOGI("IsModuleLoaded true, code: %{public}u", code); if (!ModuleManager::GetInstance().IsMapFuncExist(code)) { ENGINE_LOGE("UpdateService OnRemoteRequest code %{public}u not found", code); ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); -- Gitee From fe248f868e2ba41687dab4dc34d40e2b2054d2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Tue, 18 Mar 2025 08:58:45 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9code=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- services/engine/src/update_service.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index f9b9a672..e651ba47 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -529,7 +529,7 @@ int32_t UpdateService::CallbackEnter(uint32_t code) } if (!IsPermissionGranted(code)) { - ENGINE_LOGE("UpdateService code %{public}d IsPermissionGranted false", code); + ENGINE_LOGE("UpdateService code %{public}u IsPermissionGranted false", code); return CallResultToIpcResult(INT_APP_NOT_GRANTED); } @@ -556,7 +556,7 @@ int32_t UpdateService::CallbackParcel(uint32_t code, MessageParcel &data, Messag 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); + ENGINE_LOGE("UpdateService OnRemoteRequest ret %{public}d", ret); return INT_CALL_FAIL; } ret = ModuleManager::GetInstance().HandleFunc(code, data, reply, option); @@ -596,7 +596,7 @@ bool UpdateService::IsPermissionGranted(uint32_t code) 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); + ENGINE_LOGE("%{public}s not granted, code:%{public}u", permission.c_str(), code); } return isPermissionGranted; } -- Gitee From 247f51b5ea983c387c5557b5d1dfa2d864576af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Tue, 18 Mar 2025 20:34:00 +0800 Subject: [PATCH 4/6] =?UTF-8?q?oh=E6=9D=83=E9=99=90=E6=A3=80=E6=9F=A5=20Si?= =?UTF-8?q?gned-off-by:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/engine/include/update_service.h | 1 + services/engine/src/update_service.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/services/engine/include/update_service.h b/services/engine/include/update_service.h index b0c6e566..e30fd8b0 100644 --- a/services/engine/include/update_service.h +++ b/services/engine/include/update_service.h @@ -126,6 +126,7 @@ private: void DumpUpgradeCallback(const int fd); bool IsCallerValid(); bool IsPermissionGranted(uint32_t code); + int32_t PermissionCheck(uint32_t code); #ifndef UPDATER_UT private: diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index e651ba47..51762751 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -522,7 +522,18 @@ void UpdateService::OnStop(const SystemAbilityOnDemandReason &stopReason) int32_t UpdateService::CallbackEnter(uint32_t code) { - ENGINE_LOGI("UpdateService CallbackEnter, code: %{public}u", code); + ENGINE_LOGI("CallbackEnter, code: %{public}u", code); + if (!ModuleManager::GetInstance().IsModuleLoaded()) { + return PermissionCheck(code); + } else { + ENGINE_LOGI("IsModuleLoaded true"); + return INT_CALL_SUCCESS; + } +} + +int32_t UpdateService::PermissionCheck(uint32_t code) +{ + ENGINE_LOGI("UpdateService Oh PermissionCheck, code: %{public}u", code); if (!IsCallerValid()) { ENGINE_LOGE("UpdateService IsCallerValid false"); return CallResultToIpcResult(INT_NOT_SYSTEM_APP); @@ -536,7 +547,6 @@ int32_t UpdateService::CallbackEnter(uint32_t code) if (code == CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET)) { SYS_EVENT_SYSTEM_RESET(0, UpdateSystemEvent::RESET_START); } - return INT_CALL_SUCCESS; } -- Gitee From 6649897b7c36c3784fde5a8e5e1dc51e531c8ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Thu, 20 Mar 2025 19:41:24 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=8B=86=E5=88=86session=20=E4=B8=BAso=20S?= =?UTF-8?q?igned-off-by:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 8 +++ frameworks/js/napi/session/BUILD.gn | 57 +++++++++++++++++++ frameworks/js/napi/session/update_session.gni | 21 +++++++ 3 files changed, 86 insertions(+) create mode 100644 frameworks/js/napi/session/BUILD.gn diff --git a/bundle.json b/bundle.json index 10d428cf..3c93d13e 100644 --- a/bundle.json +++ b/bundle.json @@ -58,6 +58,7 @@ "build": { "modules": [ "//base/update/updateservice/frameworks/js/napi/update:update", + "//base/update/updateservice/frameworks/js/napi/session:update_session", "//base/update/updateservice/interfaces/inner_api/engine:updateservicekits", "//base/update/updateservice/interfaces/inner_api/modulemgr:update_module_mgr", "//base/update/updateservice/services/engine:dupdate_config.json", @@ -86,6 +87,13 @@ "header_files": [] }, "name": "//base/update/updateservice/interfaces/inner_api/modulemgr:update_module_mgr" + }, + { + "header": { + "header_base": "//base/update/updateservice/frameworks/js/napi/session/include", + "header_files": [] + }, + "name": "//base/update/updateservice/frameworks/js/napi/session:update_session" } ], "test": [ diff --git a/frameworks/js/napi/session/BUILD.gn b/frameworks/js/napi/session/BUILD.gn new file mode 100644 index 00000000..7f0ebd0b --- /dev/null +++ b/frameworks/js/napi/session/BUILD.gn @@ -0,0 +1,57 @@ +# 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. + +import("//build/ohos.gni") +import("../../../js/napi/session/update_session.gni") + +config("update_session_library_native_config") { + include_dirs = session_include_dirs +} + +ohos_shared_library("update_session") { + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = session_include_dirs + include_dirs += [ + "$root_path/foundations/ability/define/include", + "$root_path/foundations/ability/log/include", + "$root_path/foundations/ability/utils/include", + "$root_path/foundations/model/include", + "$root_path/interfaces/inner_api/feature/update/model/common", + "$root_path/interfaces/inner_api/feature/update/model/event", + "$root_path/interfaces/inner_api/feature/update/model/install", + "$root_path/interfaces/inner_api/feature/update/model/message_parcel/include", + "$root_path/interfaces/inner_api/feature/update/model/task", + "$root_path/interfaces/inner_api/feature/update/model/version_info", + "$root_path/interfaces/inner_api/feature/update/model/version_info/description", + ] + sources = session_sources + sources += [ + "$root_path/interfaces/inner_api/feature/update/model/message_parcel/src/message_parcel_helper.cpp", + "$root_path/interfaces/inner_api/feature/update/model/upgrade_info/src/business_error.cpp", + "$root_path/interfaces/inner_api/feature/update/model/version_info/description/src/description_info.cpp", + "$root_path/interfaces/inner_api/feature/update/model/version_info/src/version_component.cpp", + ] + external_deps = session_external_deps + part_name = "$updateengine_part_name" + subsystem_name = "updater" + cflags = session_cflags + + public_configs = [ ":update_session_library_native_config" ] +} diff --git a/frameworks/js/napi/session/update_session.gni b/frameworks/js/napi/session/update_session.gni index 369c6a9d..df6b6f1a 100644 --- a/frameworks/js/napi/session/update_session.gni +++ b/frameworks/js/napi/session/update_session.gni @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/update/updateservice/updateengine.gni") + root_path = "//base/update/updateservice" session_sources = [ "$root_path/frameworks/js/napi/session/src/napi_common_utils.cpp", @@ -18,3 +20,22 @@ session_sources = [ ] session_include_dirs = [ "$root_path/frameworks/js/napi/session/include" ] + +session_external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "c_utils:utils", # refbase + "hilog:libhilog", + "ipc:ipc_core", + "json:nlohmann_json_static", + "napi:ace_napi", + "safwk:system_ability_fwk", +] + +session_cflags = [ + "-fPIC", + "-Os", + "-Werror", + "-DNAPI_VERSION=8", + "-fstack-protector-strong", +] -- Gitee From 7abdc6664a02a3636a20a960064e0ca348f1122d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Mon, 24 Mar 2025 18:28:27 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=8F=98?= =?UTF-8?q?=E9=87=8F=20Signed-off-by:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/napi/update/src/local_updater.cpp | 6 ++-- .../js/napi/update/src/update_client.cpp | 34 +++++++++---------- .../engine/src/update_service_kits_impl.cpp | 4 +-- .../callback/src/base_callback_utils.cpp | 2 +- services/engine/src/update_service.cpp | 7 ++-- .../engine/src/update_service_util_hmos.cpp | 2 +- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/frameworks/js/napi/update/src/local_updater.cpp b/frameworks/js/napi/update/src/local_updater.cpp index 66e65be3..b3982f8f 100644 --- a/frameworks/js/napi/update/src/local_updater.cpp +++ b/frameworks/js/napi/update/src/local_updater.cpp @@ -75,7 +75,7 @@ void LocalUpdater::Init() ENGINE_LOGI("LocalUpdater::Init"); UpgradeInfo upgradeInfo; upgradeInfo.upgradeApp = LOCAL_UPGRADE_INFO; - int32_t funcResult; + int32_t funcResult = 0; UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo, callback, funcResult); isInit_ = true; } @@ -107,7 +107,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().VerifyUpgradePackage(upgradeFile.filePath, certsFile, *businessError, funcResult); }); @@ -143,7 +143,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().ApplyNewVersion(upgradeInfo, MISC_FILE, packageNames, *businessError, funcResult); }); diff --git a/frameworks/js/napi/update/src/update_client.cpp b/frameworks/js/napi/update/src/update_client.cpp index 54b97bd8..a8453d65 100644 --- a/frameworks/js/napi/update/src/update_client.cpp +++ b/frameworks/js/napi/update/src/update_client.cpp @@ -86,7 +86,7 @@ void UpdateClient::RegisterCallback() constexpr int32_t maxRetryTimes = 5; // 回调注册失败最大尝试次数 int32_t retryTimes = 0; do { - int32_t funcResult; + int32_t funcResult = 0; int32_t ret = UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo_, callback, funcResult); if (ret == INT_CALL_SUCCESS) { break; @@ -104,7 +104,7 @@ void UpdateClient::RegisterCallback() void UpdateClient::UnRegisterCallback() { - int32_t funcResult; + int32_t funcResult = 0; UpdateServiceKits::GetInstance().UnregisterUpdateCallback(upgradeInfo_, funcResult); } @@ -113,7 +113,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().CheckNewVersion(upgradeInfo_, *businessError, checkResult_, funcResult); }); @@ -127,7 +127,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().Cancel(upgradeInfo_, CAST_INT(UpdaterSaInterfaceCode::DOWNLOAD), *businessError, funcResult); }); @@ -185,7 +185,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().Download(upgradeInfo_, versionDigestInfo_, downloadOptions_, *businessError, funcResult); }); @@ -210,7 +210,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().PauseDownload(upgradeInfo_, versionDigestInfo_, pauseDownloadOptions_, *businessError, funcResult); }); @@ -235,7 +235,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().ResumeDownload(upgradeInfo_, versionDigestInfo_, resumeDownloadOptions_, *businessError, funcResult); }); @@ -260,7 +260,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().Upgrade(upgradeInfo_, versionDigestInfo_, upgradeOptions_, *businessError, funcResult); }); @@ -285,7 +285,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().ClearError(upgradeInfo_, versionDigestInfo_, clearOptions_, *businessError, funcResult); }); @@ -303,7 +303,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, *businessError, funcResult); }); @@ -327,7 +327,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().SetUpgradePolicy(upgradeInfo_, upgradePolicy_, *businessError, funcResult); }); @@ -340,7 +340,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().GetUpgradePolicy(upgradeInfo_, upgradePolicy_, *businessError, funcResult); }); @@ -353,7 +353,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().GetNewVersionInfo(upgradeInfo_, newVersionInfo_, *businessError, funcResult); }); @@ -379,7 +379,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().GetNewVersionDescription(upgradeInfo_, versionDigestInfo_, descriptionOptions_, newVersionDescriptionInfo_, *businessError, funcResult); }); @@ -392,7 +392,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().GetCurrentVersionInfo(upgradeInfo_, currentVersionInfo_, *businessError, funcResult); }); @@ -417,7 +417,7 @@ 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; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().GetCurrentVersionDescription(upgradeInfo_, descriptionOptions_, currentVersionDescriptionInfo_, *businessError, funcResult); }); @@ -430,7 +430,7 @@ 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); - int32_t funcResult; + int32_t funcResult = 0; return UpdateServiceKits::GetInstance().GetTaskInfo(upgradeInfo_, taskInfo_, *businessError, funcResult); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to GetTaskInfo."); 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 0b8c48d4..9e84efa3 100644 --- a/interfaces/inner_api/engine/src/update_service_kits_impl.cpp +++ b/interfaces/inner_api/engine/src/update_service_kits_impl.cpp @@ -242,7 +242,7 @@ int32_t UpdateServiceKitsImpl::FactoryReset(BusinessError &businessError) ENGINE_LOGI("UpdateServiceKitsImpl::FactoryReset"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t funcResult; + int32_t funcResult = 0; int32_t ret = updateService->FactoryReset(businessError, funcResult); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "FactoryReset ipc error"); return ret; @@ -273,7 +273,7 @@ int32_t UpdateServiceKitsImpl::VerifyUpgradePackage(const std::string &packagePa void UpdateServiceKitsImpl::RegisterCallback() { ENGINE_LOGI("RegisterUpdateCallback size %{public}zu", remoteUpdateCallbackMap_.size()); - int32_t funcResult; + int32_t funcResult = 0; for (auto &iter : remoteUpdateCallbackMap_) { remoteServer_->RegisterUpdateCallback(iter.first, iter.second, funcResult); } diff --git a/services/core/ability/callback/src/base_callback_utils.cpp b/services/core/ability/callback/src/base_callback_utils.cpp index 6302d7bc..ef0c7813 100644 --- a/services/core/ability/callback/src/base_callback_utils.cpp +++ b/services/core/ability/callback/src/base_callback_utils.cpp @@ -91,7 +91,7 @@ sptr BaseCallbackUtils::GetUpgradeCallback(const UpgradeInfo &u ENGINE_LOGI("GetUpgradeCallback no instance"); return nullptr; } - int32_t funcResult; + int32_t funcResult = 0; return service->GetUpgradeCallback(upgradeInfo, funcResult); } diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index 51762751..96291883 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -71,7 +71,7 @@ void UpdateService::ClientDeathRecipient::OnRemoteDied(const wptr { ENGINE_LOGI("client DeathRecipient OnRemoteDied: %{public}s", upgradeInfo_.ToString().c_str()); sptr service = UpdateService::GetInstance(); - int32_t funcResult; + int32_t funcResult = 0; if (service != nullptr) { service->UnregisterUpdateCallback(upgradeInfo_, funcResult); } @@ -409,7 +409,7 @@ void BuildTaskInfoDump(const int fd) TaskInfo taskInfo; BusinessError businessError; UpgradeInfo upgradeInfo; - int32_t funcResult; + int32_t funcResult = 0; service->GetTaskInfo(upgradeInfo, taskInfo, businessError, funcResult); if (!taskInfo.existTask) { dprintf(fd, "TaskInfo is empty\n"); @@ -526,7 +526,6 @@ int32_t UpdateService::CallbackEnter(uint32_t code) if (!ModuleManager::GetInstance().IsModuleLoaded()) { return PermissionCheck(code); } else { - ENGINE_LOGI("IsModuleLoaded true"); return INT_CALL_SUCCESS; } } @@ -557,7 +556,7 @@ int32_t UpdateService::CallbackExit(uint32_t code, int32_t result) int32_t UpdateService::CallbackParcel(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - int32_t ret; + int32_t ret = 0; if (!ModuleManager::GetInstance().IsModuleLoaded()) { ENGINE_LOGI("IsModuleLoaded false"); return INT_CALL_SUCCESS; diff --git a/services/engine/src/update_service_util_hmos.cpp b/services/engine/src/update_service_util_hmos.cpp index 946c77b3..a12e3848 100644 --- a/services/engine/src/update_service_util_hmos.cpp +++ b/services/engine/src/update_service_util_hmos.cpp @@ -48,7 +48,7 @@ sptr UpdateServiceUtil::GetUpgradeCallback(const UpgradeInfo &u ENGINE_LOGI("GetUpgradeCallback no instance"); return nullptr; } - int32_t funcResult; + int32_t funcResult = 0; return service->GetUpgradeCallback(upgradeInfo, funcResult); } } // namespace UpdateEngine -- Gitee