From bde6d4cde47b3503422d953c70c321133d534f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 19 Jun 2024 20:26:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BE=9D=E8=B5=96=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=8C=E6=AD=A5beta1=20Signed-off-by:=20=E9=82=B9=E5=8F=8B?= =?UTF-8?q?=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/base_service_kits_impl.h | 3 - foundations/ability/sa_loader/sa_loader.gni | 2 +- interfaces/inner_api/engine/BUILD.gn | 2 +- .../update/model/subscribe/subscribe_info.h | 8 +- .../callback/src/base_callback_utils.cpp | 2 +- services/engine/engine_sa.gni | 2 +- services/engine/include/i_update_notify.h | 29 ++++ services/engine/include/update_notify.h | 41 ++++-- services/engine/src/update_notify.cpp | 125 ++++++++++++++---- .../updateservicecancel_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../updateservicedownload_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- 17 files changed, 173 insertions(+), 57 deletions(-) create mode 100644 services/engine/include/i_update_notify.h diff --git a/foundations/ability/sa_loader/include/base_service_kits_impl.h b/foundations/ability/sa_loader/include/base_service_kits_impl.h index e1a433b0..c8ccee43 100644 --- a/foundations/ability/sa_loader/include/base_service_kits_impl.h +++ b/foundations/ability/sa_loader/include/base_service_kits_impl.h @@ -18,9 +18,6 @@ #include -#ifndef ABILITY_RUNTIME_INNER_ENABLE -#include "ability_manager_proxy.h" -#endif #include "iremote_object.h" #include "common_death_recipient.h" diff --git a/foundations/ability/sa_loader/sa_loader.gni b/foundations/ability/sa_loader/sa_loader.gni index 02290adf..5abeec5c 100644 --- a/foundations/ability/sa_loader/sa_loader.gni +++ b/foundations/ability/sa_loader/sa_loader.gni @@ -20,7 +20,7 @@ sa_loader_external_deps = [ "samgr:samgr_proxy", ] if (ability_ability_runtime_enable) { - sa_loader_external_deps += [ "ability_runtime:ability_manager" ] + sa_loader_external_deps += [ "ability_runtime:extension_manager" ] } sa_loader_deps = [] diff --git a/interfaces/inner_api/engine/BUILD.gn b/interfaces/inner_api/engine/BUILD.gn index 4d84e348..9dcd2bb1 100644 --- a/interfaces/inner_api/engine/BUILD.gn +++ b/interfaces/inner_api/engine/BUILD.gn @@ -79,7 +79,7 @@ ohos_shared_library("$updateengine_inner_library_name") { external_deps += feature_external_deps if (ability_ability_runtime_enable) { - external_deps += [ "ability_runtime:ability_manager" ] + external_deps += [ "ability_runtime:extension_manager" ] } innerapi_tags = [ "platformsdk" ] part_name = "$updateengine_part_name" diff --git a/interfaces/inner_api/feature/update/model/subscribe/subscribe_info.h b/interfaces/inner_api/feature/update/model/subscribe/subscribe_info.h index 24b1dd03..7f49f58c 100644 --- a/interfaces/inner_api/feature/update/model/subscribe/subscribe_info.h +++ b/interfaces/inner_api/feature/update/model/subscribe/subscribe_info.h @@ -23,11 +23,13 @@ #include "update_device_type.h" namespace OHOS::UpdateEngine { -const std::string OUC_PACKAGE_NAME = "com.ohos.updateapp"; -const std::string OUC_SERVICE_EXT_ABILITY_NAME = "ServiceExtAbility"; +const std::string UPDATE_APP_PACKAGE_NAME = "com.ohos.updateapp"; +const std::string UPDATE_APP_SERVICE_EXT_ABILITY_NAME = "ServiceExtAbility"; +constexpr int32_t UPDATE_APP_TIMEOUT = 15; +constexpr int32_t UPDATE_APP_CONNECT_TIMEOUT = 5; struct SubscribeInfo : public BaseJsonStruct { - std::string upgradeApp = OUC_PACKAGE_NAME; + std::string upgradeApp = UPDATE_APP_PACKAGE_NAME; BusinessType businessType = {}; std::string abilityName; std::string subscriberDevId; diff --git a/services/core/ability/callback/src/base_callback_utils.cpp b/services/core/ability/callback/src/base_callback_utils.cpp index 5741a3b2..fa9ef4e6 100644 --- a/services/core/ability/callback/src/base_callback_utils.cpp +++ b/services/core/ability/callback/src/base_callback_utils.cpp @@ -99,7 +99,7 @@ void BaseCallbackUtils::NotifyToHap(EventInfo &info) ENGINE_LOGI("Notify eventInfoStr %{public}s", eventInfoStr.c_str()); if (!eventInfoStr.empty()) { SubscribeInfo subscribeInfo{GetBusinessSubType()}; - OHOS::UpdateEngine::UpdateNotify::NotifyToAppService(eventInfoStr, subscribeInfo.ToJson()); + UpdateNotify::GetInstance()->ConnectToAppService(eventInfoStr, subscribeInfo.ToJson()); } } } // namespace UpdateEngine diff --git a/services/engine/engine_sa.gni b/services/engine/engine_sa.gni index 63facb72..08d97178 100644 --- a/services/engine/engine_sa.gni +++ b/services/engine/engine_sa.gni @@ -153,7 +153,7 @@ if (ability_ability_base_enable) { ] } if (ability_ability_runtime_enable) { - sa_external_deps += [ "ability_runtime:ability_manager" ] + sa_external_deps += [ "ability_runtime:extension_manager" ] } if (communication_netmanager_base_enable) { diff --git a/services/engine/include/i_update_notify.h b/services/engine/include/i_update_notify.h new file mode 100644 index 00000000..6bc41c01 --- /dev/null +++ b/services/engine/include/i_update_notify.h @@ -0,0 +1,29 @@ +/* + * 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. + */ + +#ifndef I_UPDATE_NOTIFY_H +#define I_UPDATE_NOTIFY_H + +#include + +#include "iremote_broker.h" + +namespace OHOS::UpdateEngine { +class IUpdateNotify : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Updater.IUpdateNotify"); +}; +} // namespace OHOS::UpdateEngine +#endif // I_UPDATE_NOTIFY_H \ No newline at end of file diff --git a/services/engine/include/update_notify.h b/services/engine/include/update_notify.h index a89c70b3..91be2ab0 100644 --- a/services/engine/include/update_notify.h +++ b/services/engine/include/update_notify.h @@ -16,40 +16,59 @@ #ifndef UPDATE_NOTIFY_H #define UPDATE_NOTIFY_H +#include +#include #include #include "ability_connect_callback_stub.h" #include "ability_connect_callback_interface.h" #include "ability_manager_interface.h" #include "ability_manager_client.h" #include "if_system_ability_manager.h" +#include "i_update_notify.h" #include "system_ability_definition.h" #include "update_no_constructor.h" #include "want.h" namespace OHOS { namespace UpdateEngine { -class UpdateNotify : public NoConstructor { +class UpdateNotify : public IRemoteStub { public: - static bool NotifyToAppService(const std::string &eventInfo, const std::string &subscribeInfo); + DISALLOW_COPY_AND_MOVE(UpdateNotify); + + UpdateNotify(); + ~UpdateNotify(); + static sptr GetInstance(); + bool ConnectToAppService(const std::string &eventInfo, const std::string &subscribeInfo); + void HandleAbilityConnect(const sptr &remoteObject); + +private: + bool HandleMessage(const std::string &message); + ErrCode ConnectAbility(const AAFwk::Want &want, const sptr &connect); + ErrCode DisconnectAbility(const sptr &connect); private: - static ErrCode ConnectAbility(const AAFwk::Want &want, const sptr &connect, - const sptr &callerToken); - static ErrCode DisconnectAbility(const sptr &connect); - static ErrCode StopServiceAbility(const AAFwk::Want &want); - static ErrCode StartAbility(const AAFwk::Want &want); - static AAFwk::Want MakeWant(const std::string &deviceId, const std::string &abilityName, - const std::string &bundleName, const std::string &subscribeInfo, const std::string ¶ms = {}); + static std::mutex instanceLock_; + static sptr instance_; + sptr remoteObject_ = nullptr; + std::mutex connectMutex_; + std::condition_variable conditionVal_; + + enum class UpdateAppCode { + UNKNOWN = 0, + UPDATE_APP = 5 + }; }; class NotifyConnection : public AAFwk::AbilityConnectionStub { public: - explicit NotifyConnection() = default; + explicit NotifyConnection(const sptr &instance); ~NotifyConnection() = default; - void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, int32_t resultCode) override; void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + +private: + sptr instance_ = nullptr; }; } // namespace UpdateEngine } // namespace OHOS diff --git a/services/engine/src/update_notify.cpp b/services/engine/src/update_notify.cpp index 01000ac1..18db4f27 100644 --- a/services/engine/src/update_notify.cpp +++ b/services/engine/src/update_notify.cpp @@ -15,6 +15,8 @@ #include "update_notify.h" +#include "cJSON.h" +#include "extension_manager_client.h" #include "iservice_registry.h" #include "subscribe_info.h" @@ -22,62 +24,129 @@ namespace OHOS { namespace UpdateEngine { -ErrCode UpdateNotify::StartAbility(const AAFwk::Want &want) +std::mutex UpdateNotify::instanceLock_; +sptr UpdateNotify::instance_ = nullptr; + +UpdateNotify::UpdateNotify() { - ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); - ENGINE_LOGI("StartAbility result %{public}d", result); - return result; + ENGINE_LOGD("UpdateNotify"); } -ErrCode UpdateNotify::StopServiceAbility(const AAFwk::Want &want) +UpdateNotify::~UpdateNotify() { - ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StopServiceAbility(want); - ENGINE_LOGI("StopServiceAbility result %{public}d", result); - return result; + ENGINE_LOGD("~UpdateNotify"); +} + +sptr UpdateNotify::GetInstance() +{ + if (instance_ == nullptr) { + std::lock_guard autoLock(instanceLock_); + if (instance_ == nullptr) { + instance_ = new UpdateNotify(); + } + } + return instance_; } -ErrCode UpdateNotify::ConnectAbility(const AAFwk::Want &want, const sptr &connect, - const sptr &callerToken) +ErrCode UpdateNotify::ConnectAbility(const AAFwk::Want &want, const sptr &connect) { - ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, connect, callerToken); + ErrCode result = + AAFwk::ExtensionManagerClient::GetInstance().ConnectServiceExtensionAbility(want, connect, nullptr, -1); ENGINE_LOGI("ConnectAbility result %{public}d", result); return result; } -ErrCode UpdateNotify::DisconnectAbility(const sptr &connect) +ErrCode UpdateNotify::DisconnectAbility(const sptr &connect) { - ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connect); + ErrCode result = + AAFwk::ExtensionManagerClient::GetInstance().DisconnectAbility(connect); ENGINE_LOGI("DisconnectAbility result %{public}d", result); return result; } -AAFwk::Want UpdateNotify::MakeWant(const std::string &deviceId, const std::string &abilityName, - const std::string &bundleName, const std::string &subscribeInfo, const std::string ¶ms) +bool UpdateNotify::ConnectToAppService(const std::string &eventInfo, const std::string &subscribeInfo) { - AppExecFwk::ElementName element(deviceId, bundleName, abilityName); - AAFwk::Want want; - want.SetElement(element); - want.SetParam("EventInfo", params); - want.SetParam("SubscribeInfo", subscribeInfo); - return want; + if (eventInfo.empty()) { + ENGINE_LOGE("ConnectToAppService eventInfo error."); + return false; + } + cJSON *root = cJSON_CreateObject(); + cJSON_AddItemToObject(root, "EventInfo", cJSON_Parse(eventInfo.c_str())); + cJSON_AddItemToObject(root, "SubscribeInfo", cJSON_Parse(subscribeInfo.c_str())); + + char *data = cJSON_PrintUnformatted(root); + if (data == nullptr) { + cJSON_Delete(root); + return false; + } + std::string message = std::string(data); + cJSON_free(data); + cJSON_Delete(root); + return HandleMessage(message); } -bool UpdateNotify::NotifyToAppService(const std::string &eventInfo, const std::string &subscribeInfo) +bool UpdateNotify::HandleMessage(const std::string &message) { - if (eventInfo.empty()) { - ENGINE_LOGE("NotifyToAppService eventInfo error."); + std::string bundleName = UPDATE_APP_PACKAGE_NAME; + std::string abilityName = UPDATE_APP_SERVICE_EXT_ABILITY_NAME; + AAFwk::Want want; + want.SetElementName(bundleName, abilityName); + want.SetParam("Timeout", UPDATE_APP_TIMEOUT); + auto connect = sptr::MakeSptr(instance_); + int ret = ConnectAbility(want, connect); + std::unique_lock uniqueLock(connectMutex_); + conditionVal_.wait_for(uniqueLock, std::chrono::seconds(UPDATE_APP_CONNECT_TIMEOUT)); + if (ret != OHOS::ERR_OK || remoteObject_ == nullptr) { + ENGINE_LOGE("HandleMessage, can not connect to ouc"); return false; } - std::string bundleName = OUC_PACKAGE_NAME; - std::string abilityName = OUC_SERVICE_EXT_ABILITY_NAME; - AAFwk::Want want = MakeWant("", abilityName, bundleName, subscribeInfo, eventInfo); - return StartAbility(want) == OHOS::ERR_OK; + + MessageParcel data; + if (!data.WriteString16(Str8ToStr16(message))) { + ENGINE_LOGE("HandleMessage, write message failed"); + return false; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + int32_t result = remoteObject_->SendRequest(CAST_INT(UpdateAppCode::UPDATE_APP), data, reply, option); + if (result != 0) { + ENGINE_LOGE("HandleMessage SendRequest, error result %{public}d", result); + DisconnectAbility(connect); + return false; + } + return true; +} + +void UpdateNotify::HandleAbilityConnect(const sptr &remoteObject) +{ + remoteObject_ = remoteObject; + conditionVal_.notify_one(); +} + +NotifyConnection::NotifyConnection(const sptr &instance) +{ + ENGINE_LOGD("NotifyConnection constructor"); + instance_ = instance; } void NotifyConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, int32_t resultCode) { ENGINE_LOGI("OnAbilityConnectDone successfully. result %{public}d", resultCode); + if (resultCode != ERR_OK) { + ENGINE_LOGE("ability connect failed, error code: %{public}d", resultCode); + return; + } + ENGINE_LOGI("ability connect success, ability name %{public}s", element.GetAbilityName().c_str()); + if (remoteObject == nullptr) { + ENGINE_LOGE("get remoteObject failed"); + return; + } + if (instance_ == nullptr) { + return; + } + instance_->HandleAbilityConnect(remoteObject); } void NotifyConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) diff --git a/test/fuzztest/updateservicecancel_fuzzer/BUILD.gn b/test/fuzztest/updateservicecancel_fuzzer/BUILD.gn index ae2965fd..a0b769b6 100644 --- a/test/fuzztest/updateservicecancel_fuzzer/BUILD.gn +++ b/test/fuzztest/updateservicecancel_fuzzer/BUILD.gn @@ -42,7 +42,7 @@ ohos_fuzztest("UpdateServiceCancelFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateservicechecknewversion_fuzzer/BUILD.gn b/test/fuzztest/updateservicechecknewversion_fuzzer/BUILD.gn index 04be0847..477bafb5 100644 --- a/test/fuzztest/updateservicechecknewversion_fuzzer/BUILD.gn +++ b/test/fuzztest/updateservicechecknewversion_fuzzer/BUILD.gn @@ -41,7 +41,7 @@ ohos_fuzztest("UpdateServiceCheckNewVersionFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateservicedownload_fuzzer/BUILD.gn b/test/fuzztest/updateservicedownload_fuzzer/BUILD.gn index 5e567292..3ba5fba1 100644 --- a/test/fuzztest/updateservicedownload_fuzzer/BUILD.gn +++ b/test/fuzztest/updateservicedownload_fuzzer/BUILD.gn @@ -42,7 +42,7 @@ ohos_fuzztest("UpdateServiceDownloadFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateservicegetnewversion_fuzzer/BUILD.gn b/test/fuzztest/updateservicegetnewversion_fuzzer/BUILD.gn index 044b27f0..0a94c440 100644 --- a/test/fuzztest/updateservicegetnewversion_fuzzer/BUILD.gn +++ b/test/fuzztest/updateservicegetnewversion_fuzzer/BUILD.gn @@ -42,7 +42,7 @@ ohos_fuzztest("UpdateServiceGetNewVersionFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateservicegetupgradepolicy_fuzzer/BUILD.gn b/test/fuzztest/updateservicegetupgradepolicy_fuzzer/BUILD.gn index 9167ea5d..f44ab3ba 100644 --- a/test/fuzztest/updateservicegetupgradepolicy_fuzzer/BUILD.gn +++ b/test/fuzztest/updateservicegetupgradepolicy_fuzzer/BUILD.gn @@ -41,7 +41,7 @@ ohos_fuzztest("UpdateServiceGetUpgradePolicyFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateserviceregisterupdatecallback_fuzzer/BUILD.gn b/test/fuzztest/updateserviceregisterupdatecallback_fuzzer/BUILD.gn index d1aad60b..d32f09ec 100644 --- a/test/fuzztest/updateserviceregisterupdatecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/updateserviceregisterupdatecallback_fuzzer/BUILD.gn @@ -41,7 +41,7 @@ ohos_fuzztest("UpdateServiceRegisterUpdateCallbackFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateservicesetupgradepolicy_fuzzer/BUILD.gn b/test/fuzztest/updateservicesetupgradepolicy_fuzzer/BUILD.gn index 828bf3f0..7294884c 100644 --- a/test/fuzztest/updateservicesetupgradepolicy_fuzzer/BUILD.gn +++ b/test/fuzztest/updateservicesetupgradepolicy_fuzzer/BUILD.gn @@ -42,7 +42,7 @@ ohos_fuzztest("UpdateServiceSetUpgradePolicyFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/fuzztest/updateserviceunregisterupdatecallback_fuzzer/BUILD.gn b/test/fuzztest/updateserviceunregisterupdatecallback_fuzzer/BUILD.gn index 9e4fe061..772f1b06 100644 --- a/test/fuzztest/updateserviceunregisterupdatecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/updateserviceunregisterupdatecallback_fuzzer/BUILD.gn @@ -41,7 +41,7 @@ ohos_fuzztest("UpdateServiceUnregisterUpdateCallbackFuzzTest") { ] deps = [ "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name" ] external_deps = [ - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", -- Gitee From f91f974e770175740a6b083df041cfe651dac9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 26 Jun 2024 19:51:23 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BB=8Emaster=20=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=8F=90=E4=BA=A4=20Signed-off-by:=20?= =?UTF-8?q?=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 --- frameworks/js/napi/update/src/local_updater.cpp | 13 ++++++++++--- .../engine/include/update_service_kits_impl.h | 5 ++--- .../engine/include/update_service_proxy.h | 4 ++-- .../engine/src/update_service_kits_impl.cpp | 4 ++-- .../inner_api/engine/src/update_service_proxy.cpp | 7 +++++-- .../api/local_updater/iservice_local_updater.h | 2 +- .../feature/update/model/event/event_classify.h | 4 +++- .../feature/update/model/event/event_id.h | 5 ++++- interfaces/inner_api/include/update_service_kits.h | 2 +- .../inner_api/modulemgr/src/module_manager.cpp | 2 +- services/engine/include/update_service.h | 4 ++-- .../engine/include/update_service_local_updater.h | 4 ++-- services/engine/src/progress_thread.cpp | 2 +- services/engine/src/update_service.cpp | 4 ++-- .../engine/src/update_service_local_updater.cpp | 8 +++----- services/engine/src/update_service_stub.cpp | 14 ++++++++++++-- .../executor/src/firmware_apply_executor.cpp | 2 +- .../executor/src/firmware_check_executor.cpp | 2 +- .../executor/src/firmware_download_executor.cpp | 2 +- .../executor/src/firmware_install_executor.cpp | 2 +- .../firmware/upgrade/flow/src/firmware_manager.cpp | 7 ++++--- services/utils/src/dupdate_net_observer.cpp | 5 +++-- 22 files changed, 64 insertions(+), 40 deletions(-) diff --git a/frameworks/js/napi/update/src/local_updater.cpp b/frameworks/js/napi/update/src/local_updater.cpp index 16214501..b52c026b 100644 --- a/frameworks/js/napi/update/src/local_updater.cpp +++ b/frameworks/js/napi/update/src/local_updater.cpp @@ -127,14 +127,21 @@ napi_value LocalUpdater::ApplyNewVersion(napi_env env, napi_callback_info info) return StartParamErrorSession(env, info, CALLBACK_POSITION_TWO); } + std::vector packageNames; + for (const UpgradeFile &upgradeFile : upgradeFiles) { + packageNames.emplace_back(upgradeFile.filePath); + } + SessionParams sessionParams(SessionType::SESSION_APPLY_NEW_VERSION, CALLBACK_POSITION_TWO, true); napi_value retValue = StartSession(env, info, sessionParams, - [upgradeFiles](void *context) -> int { - ENGINE_LOGI("ApplyNewVersion %s", upgradeFiles[0].filePath.c_str()); + [packageNames](void *context) -> int { + for (const std::string &packageName : packageNames) { + ENGINE_LOGI("ApplyNewVersion %{public}s", packageName.c_str()); + } BusinessError *businessError = reinterpret_cast(context); UpgradeInfo upgradeInfo; upgradeInfo.upgradeApp = LOCAL_UPGRADE_INFO; - return UpdateServiceKits::GetInstance().ApplyNewVersion(upgradeInfo, MISC_FILE, upgradeFiles[0].filePath, + return UpdateServiceKits::GetInstance().ApplyNewVersion(upgradeInfo, MISC_FILE, packageNames, *businessError); }); PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to ApplyNewVersion"); 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 96407977..626b0a73 100644 --- a/interfaces/inner_api/engine/include/update_service_kits_impl.h +++ b/interfaces/inner_api/engine/include/update_service_kits_impl.h @@ -80,9 +80,8 @@ public: int32_t FactoryReset(BusinessError &businessError) final; - int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::string &packageName, - BusinessError &businessError) final; - + int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, + const std::vector &packageNames, BusinessError &businessError) final; int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, BusinessError &businessError) final; diff --git a/interfaces/inner_api/engine/include/update_service_proxy.h b/interfaces/inner_api/engine/include/update_service_proxy.h index f77464e8..a0655af8 100644 --- a/interfaces/inner_api/engine/include/update_service_proxy.h +++ b/interfaces/inner_api/engine/include/update_service_proxy.h @@ -72,8 +72,8 @@ public: int32_t FactoryReset(BusinessError &businessError) override; - int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::string &packageName, - 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; 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 dc9cce5d..ada4fe92 100644 --- a/interfaces/inner_api/engine/src/update_service_kits_impl.cpp +++ b/interfaces/inner_api/engine/src/update_service_kits_impl.cpp @@ -242,12 +242,12 @@ int32_t UpdateServiceKitsImpl::FactoryReset(BusinessError &businessError) } int32_t UpdateServiceKitsImpl::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::string &packageName, BusinessError &businessError) + const std::vector &packageNames, BusinessError &businessError) { ENGINE_LOGI("UpdateServiceKitsImpl::ApplyNewVersion"); auto updateService = GetService(); RETURN_FAIL_WHEN_SERVICE_NULL(updateService); - int32_t ret = updateService->ApplyNewVersion(info, miscFile, packageName, businessError); + int32_t ret = updateService->ApplyNewVersion(info, miscFile, packageNames, businessError); ENGINE_CHECK((ret) == INT_CALL_SUCCESS, ResetRemoteService(), "ApplyNewVersion ipc error"); return ret; } diff --git a/interfaces/inner_api/engine/src/update_service_proxy.cpp b/interfaces/inner_api/engine/src/update_service_proxy.cpp index 4a044238..cc2f65f9 100644 --- a/interfaces/inner_api/engine/src/update_service_proxy.cpp +++ b/interfaces/inner_api/engine/src/update_service_proxy.cpp @@ -471,7 +471,7 @@ int32_t UpdateServiceProxy::FactoryReset(BusinessError &businessError) } int32_t UpdateServiceProxy::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::string &packageName, BusinessError &businessError) + const std::vector &packageNames, BusinessError &businessError) { ENGINE_LOGI("UpdateServiceProxy::ApplyNewVersion"); auto remote = Remote(); @@ -481,7 +481,10 @@ int32_t UpdateServiceProxy::ApplyNewVersion(const UpgradeInfo &info, const std:: RETURN_WHEN_TOKEN_WRITE_FAIL(data); MessageParcelHelper::WriteUpgradeInfo(data, info); data.WriteString16(Str8ToStr16(miscFile)); - data.WriteString16(Str8ToStr16(packageName)); + data.WriteInt32(static_cast(packageNames.size())); + for (size_t i = 0; i < packageNames.size(); i++) { + data.WriteString16(Str8ToStr16(packageNames[i])); + } MessageParcel reply; MessageOption option; diff --git a/interfaces/inner_api/feature/update/api/local_updater/iservice_local_updater.h b/interfaces/inner_api/feature/update/api/local_updater/iservice_local_updater.h index 1d98f686..ed2b03c7 100644 --- a/interfaces/inner_api/feature/update/api/local_updater/iservice_local_updater.h +++ b/interfaces/inner_api/feature/update/api/local_updater/iservice_local_updater.h @@ -27,7 +27,7 @@ public: virtual ~IServiceLocalUpdater() = default; virtual int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::string &packageName, BusinessError &businessError) = 0; + const std::vector &packageNames, BusinessError &businessError) = 0; virtual int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, BusinessError &businessError) = 0; diff --git a/interfaces/inner_api/feature/update/model/event/event_classify.h b/interfaces/inner_api/feature/update/model/event/event_classify.h index 4b70e86c..58f6dc40 100644 --- a/interfaces/inner_api/feature/update/model/event/event_classify.h +++ b/interfaces/inner_api/feature/update/model/event/event_classify.h @@ -22,8 +22,10 @@ namespace OHOS::UpdateEngine { enum class EventClassify { TASK = 0x01000000, SYSTEM = 0x02000000, + COMMAND = 0x04000000, }; -const std::list g_eventClassifyList = { EventClassify::TASK, EventClassify::SYSTEM }; +const std::list g_eventClassifyList = { EventClassify::TASK, EventClassify::SYSTEM, + EventClassify::COMMAND }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_EVENT_CLASSIFY_H diff --git a/interfaces/inner_api/feature/update/model/event/event_id.h b/interfaces/inner_api/feature/update/model/event/event_id.h index fbbb908f..e7675d40 100644 --- a/interfaces/inner_api/feature/update/model/event/event_id.h +++ b/interfaces/inner_api/feature/update/model/event/event_id.h @@ -41,7 +41,6 @@ enum class EventId { EVENT_AUTH_START, EVENT_AUTH_SUCCESS, EVENT_DOWNLOAD_CANCEL, - EVENT_INITIALIZE, EVENT_TASK_CHANGE, EVENT_VERSION_INFO_CHANGE, EVENT_TRANSFER_WAIT, @@ -49,8 +48,12 @@ enum class EventId { EVENT_TRANSFERING, EVENT_TRANSFER_SUCCESS, EVENT_TRANSFER_FAIL, + SYSTEM_BASE = CAST_UINT(EventClassify::SYSTEM), SYSTEM_BOOT_COMPLETE, + + COMMAND_BASE = CAST_UINT(EventClassify::COMMAND), + EVENT_INITIALIZE, }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SERVICE_EVENT_ID_H diff --git a/interfaces/inner_api/include/update_service_kits.h b/interfaces/inner_api/include/update_service_kits.h index f3c8122a..39d38b01 100644 --- a/interfaces/inner_api/include/update_service_kits.h +++ b/interfaces/inner_api/include/update_service_kits.h @@ -99,7 +99,7 @@ public: virtual int32_t FactoryReset(BusinessError &businessError) = 0; virtual int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::string &packageName, BusinessError &businessError) = 0; + const std::vector &packageNames, BusinessError &businessError) = 0; virtual int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, BusinessError &businessError) = 0; diff --git a/interfaces/inner_api/modulemgr/src/module_manager.cpp b/interfaces/inner_api/modulemgr/src/module_manager.cpp index 019cf1e8..b3147a46 100644 --- a/interfaces/inner_api/modulemgr/src/module_manager.cpp +++ b/interfaces/inner_api/modulemgr/src/module_manager.cpp @@ -95,7 +95,7 @@ int32_t ModuleManager::HandleFunc(uint32_t code, MessageParcel &data, MessagePar if (onRemoteRequestFuncMap_.find(code) == onRemoteRequestFuncMap_.end()) { UTILS_LOGE("HandleFunc code %{public}d not exist", code); } else { - UTILS_LOGD("HandleFunc code %{public}d exist", code); + UTILS_LOGD("HandleFunc code %{public}d called", code); return ((RequestFuncType)onRemoteRequestFuncMap_[code])(code, data, reply, option); } return 0; diff --git a/services/engine/include/update_service.h b/services/engine/include/update_service.h index 0090f95b..e0a0b14b 100644 --- a/services/engine/include/update_service.h +++ b/services/engine/include/update_service.h @@ -83,8 +83,8 @@ public: int32_t FactoryReset(BusinessError &businessError) override; - int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::string &packageName, - 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; diff --git a/services/engine/include/update_service_local_updater.h b/services/engine/include/update_service_local_updater.h index 8e8f5e90..84e10259 100644 --- a/services/engine/include/update_service_local_updater.h +++ b/services/engine/include/update_service_local_updater.h @@ -30,8 +30,8 @@ public: DISALLOW_COPY_AND_MOVE(UpdateServiceLocalUpdater); - int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::string &packageName, - BusinessError &businessError) final; + int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, + const std::vector &packageNames, BusinessError &businessError) final; int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, BusinessError &businessError) final; diff --git a/services/engine/src/progress_thread.cpp b/services/engine/src/progress_thread.cpp index 029f10d0..24d85dcc 100644 --- a/services/engine/src/progress_thread.cpp +++ b/services/engine/src/progress_thread.cpp @@ -51,7 +51,7 @@ int32_t ProgressThread::StartProgress() { std::unique_lock lock(mutex_); if (pDealThread_ == nullptr) { - pDealThread_ = new (std::nothrow)std::thread(&ProgressThread::ExecuteThreadFunc, this); + pDealThread_ = new (std::nothrow)std::thread([this] { this->ExecuteThreadFunc(); }); ENGINE_CHECK(pDealThread_ != nullptr, return -1, "Failed to create thread"); } ENGINE_LOGI("StartProgress"); diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index 5071ee0f..148e13ff 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -323,14 +323,14 @@ int32_t UpdateService::FactoryReset(BusinessError &businessError) } int32_t UpdateService::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::string &packageName, BusinessError &businessError) + const std::vector &packageNames, BusinessError &businessError) { sptr localUpdater = new UpdateServiceLocalUpdater(); if (localUpdater == nullptr) { ENGINE_LOGI("FactoryReset localUpdater null"); return INT_CALL_FAIL; } - return localUpdater->ApplyNewVersion(info, miscFile, packageName, businessError); + return localUpdater->ApplyNewVersion(info, miscFile, packageNames, businessError); } int32_t UpdateService::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, diff --git a/services/engine/src/update_service_local_updater.cpp b/services/engine/src/update_service_local_updater.cpp index 7f290737..03ceb7eb 100644 --- a/services/engine/src/update_service_local_updater.cpp +++ b/services/engine/src/update_service_local_updater.cpp @@ -25,17 +25,15 @@ namespace OHOS { namespace UpdateEngine { int32_t UpdateServiceLocalUpdater::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, - const std::string &packageName, BusinessError &businessError) + const std::vector &packageNames, BusinessError &businessError) { #ifndef UPDATER_UT SYS_EVENT_SYSTEM_UPGRADE(0, UpdateSystemEvent::UPGRADE_START); businessError.errorNum = CallResult::SUCCESS; - std::vector packageNames; - packageNames.push_back(packageName); int32_t ret = RebootAndInstallSdcardPackage(miscFile, packageNames) ? INT_CALL_SUCCESS : INT_CALL_FAIL; ENGINE_LOGI("ApplyNewVersion result : %{public}d", ret); - SYS_EVENT_SYSTEM_UPGRADE( - 0, ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT); + SYS_EVENT_SYSTEM_UPGRADE(0, + ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT); return ret; #else return INT_CALL_SUCCESS; diff --git a/services/engine/src/update_service_stub.cpp b/services/engine/src/update_service_stub.cpp index c862be67..f3965f05 100644 --- a/services/engine/src/update_service_stub.cpp +++ b/services/engine/src/update_service_stub.cpp @@ -34,6 +34,7 @@ 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) @@ -356,9 +357,18 @@ int32_t UpdateServiceStub::ApplyNewVersionStub(UpdateServiceStubPtr service, UpgradeInfo upgradeInfo; MessageParcelHelper::ReadUpgradeInfo(data, upgradeInfo); string miscFile = Str16ToStr8(data.ReadString16()); - string packageName = 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, packageName, 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; diff --git a/services/firmware/upgrade/executor/src/firmware_apply_executor.cpp b/services/firmware/upgrade/executor/src/firmware_apply_executor.cpp index 9a27865e..752dfdf0 100644 --- a/services/firmware/upgrade/executor/src/firmware_apply_executor.cpp +++ b/services/firmware/upgrade/executor/src/firmware_apply_executor.cpp @@ -32,7 +32,7 @@ namespace UpdateEngine { void FirmwareApplyExecutor::Execute() { FIRMWARE_LOGI("FirmwareApplyExecutor::Execute"); - std::thread installThread(&FirmwareApplyExecutor::DoInstall, this); + std::thread installThread([this] { this->DoInstall(); }); installThread.detach(); } diff --git a/services/firmware/upgrade/executor/src/firmware_check_executor.cpp b/services/firmware/upgrade/executor/src/firmware_check_executor.cpp index 7a9c0f8e..d601eca0 100644 --- a/services/firmware/upgrade/executor/src/firmware_check_executor.cpp +++ b/services/firmware/upgrade/executor/src/firmware_check_executor.cpp @@ -32,7 +32,7 @@ void FirmwareCheckExecutor::Execute() { FIRMWARE_LOGI("FirmwareCheckExecutor::Execute"); DelayedSingleton::GetInstance()->SetIsChecking(true); - std::thread checkThread(&FirmwareCheckExecutor::DoCheck, this); + std::thread checkThread([this] { this->DoCheck(); }); checkThread.detach(); } diff --git a/services/firmware/upgrade/executor/src/firmware_download_executor.cpp b/services/firmware/upgrade/executor/src/firmware_download_executor.cpp index b9ee76c6..4c246e7e 100644 --- a/services/firmware/upgrade/executor/src/firmware_download_executor.cpp +++ b/services/firmware/upgrade/executor/src/firmware_download_executor.cpp @@ -37,7 +37,7 @@ const mode_t MKDIR_MODE = 0777; void FirmwareDownloadExecutor::Execute() { FIRMWARE_LOGI("FirmwareDownloadExecutor::Execute"); - std::thread downloadThread(&FirmwareDownloadExecutor::DoDownload, this); + std::thread downloadThread([this] { this->DoDownload(); }); downloadThread.detach(); } diff --git a/services/firmware/upgrade/executor/src/firmware_install_executor.cpp b/services/firmware/upgrade/executor/src/firmware_install_executor.cpp index 8ea8b4c2..0062393d 100644 --- a/services/firmware/upgrade/executor/src/firmware_install_executor.cpp +++ b/services/firmware/upgrade/executor/src/firmware_install_executor.cpp @@ -30,7 +30,7 @@ namespace UpdateEngine { void FirmwareInstallExecutor::Execute() { FIRMWARE_LOGI("FirmwareInstallExecutor::Execute"); - std::thread installThread(&FirmwareInstallExecutor::DoInstall, this); + std::thread installThread([this] { this->DoInstall(); }); installThread.detach(); } diff --git a/services/firmware/upgrade/flow/src/firmware_manager.cpp b/services/firmware/upgrade/flow/src/firmware_manager.cpp index cb520ad6..5303b39b 100644 --- a/services/firmware/upgrade/flow/src/firmware_manager.cpp +++ b/services/firmware/upgrade/flow/src/firmware_manager.cpp @@ -75,7 +75,7 @@ void FirmwareManager::Init(StartupReason startupReason) } FileUtils::InitAndCreateBaseDirs(FIRMWARE_DIR_INFOS); - std::thread initThread(&FirmwareManager::DelayInit, this, startupReason); + std::thread initThread([this, startupReason] { this->DelayInit(startupReason); }); initThread.detach(); } @@ -177,10 +177,11 @@ void FirmwareManager::DoTerminateUpgrade(BusinessError &businessError) } // 主线程拉起子线程之后向OUC返回回调结果,子线程sleep 1秒之后,DUE进程退出 - std::thread th = std::thread([this]() { + auto execFunc = []() { sleep(PROCESS_EXIT_DELAY_TIME); _Exit(0); - }); + }; + std::thread th = std::thread(execFunc); th.detach(); } diff --git a/services/utils/src/dupdate_net_observer.cpp b/services/utils/src/dupdate_net_observer.cpp index 3e245d84..30a1832f 100644 --- a/services/utils/src/dupdate_net_observer.cpp +++ b/services/utils/src/dupdate_net_observer.cpp @@ -37,7 +37,7 @@ void NetObserver::SetCallback(const std::weak_ptr &callbac void NetObserver::StartObserver() { ENGINE_LOGI("StartObserver"); - std::thread th = std::thread([this]() { + auto observerExecFunc = [this]() { NetSpecifier netSpecifier; NetAllCapabilities netAllCapabilities; netAllCapabilities.netCaps_.insert(NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET); @@ -58,7 +58,8 @@ void NetObserver::StartObserver() sleep(1); } while (retryCount < RETRY_MAX_TIMES); ENGINE_LOGE("StartObserver failed"); - }); + }; + std::thread th = std::thread(observerExecFunc); th.detach(); } -- Gitee From 5b66c9e5f6a6f86a571563a2179e88dc0cefa070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Thu, 27 Jun 2024 09:06:40 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=90=8C=E6=AD=A5master=E5=88=B0beta1=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 --- foundations/ability/log/include/update_log.h | 8 +-- foundations/ability/log/src/update_log.cpp | 2 + .../include/base_service_kits_impl.h | 1 - .../session/include/base_promise_session.h | 5 +- .../js/napi/session/src/napi_session.cpp | 4 +- frameworks/js/napi/update/BUILD.gn | 1 - .../js/napi/update/include/session_manager.h | 2 - .../js/napi/update/src/session_manager.cpp | 32 ++++++++--- .../js/napi/update/src/update_session.cpp | 1 - .../engine/include/update_service_kits_impl.h | 1 + .../update/model/task/task_body_member_mask.h | 6 +- .../modulemgr/include/module_manager.h | 4 +- .../modulemgr/src/module_manager.cpp | 34 ++++++----- .../modulemgr/src/update_service_module.cpp | 1 - services/engine/include/update_service.h | 2 + services/engine/src/update_service.cpp | 57 ++++++++++--------- .../src/update_service_impl_firmware.cpp | 16 +++++- .../src/update_service_local_updater.cpp | 4 +- services/engine/src/update_service_stub.cpp | 3 +- 19 files changed, 111 insertions(+), 73 deletions(-) diff --git a/foundations/ability/log/include/update_log.h b/foundations/ability/log/include/update_log.h index 1bfb683a..3ca7e14b 100644 --- a/foundations/ability/log/include/update_log.h +++ b/foundations/ability/log/include/update_log.h @@ -38,10 +38,10 @@ enum UpdaterModuleTags { }; static constexpr OHOS::HiviewDFX::HiLogLabel UPDATE_LABEL[UPDATE_MODULE_MAX] = { - { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_SA" }, - { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_KITS" }, - { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_FIRMWARE" }, - { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATER_MODULE_MGR" } + { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_SERVICE_SA" }, + { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_SERVICE_KITS" }, + { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_SERVICE_FIRMWARE" }, + { LOG_CORE, UPDATER_SA_DOMAIN_ID, "UPDATE_SERVICE_MODULE_MGR" } }; enum class UpdateLogLevel { diff --git a/foundations/ability/log/src/update_log.cpp b/foundations/ability/log/src/update_log.cpp index 74544bb0..1da0bca7 100644 --- a/foundations/ability/log/src/update_log.cpp +++ b/foundations/ability/log/src/update_log.cpp @@ -82,9 +82,11 @@ void UpdateLog::PrintSingleLine(const uint32_t subModuleTag, const UpdateLogCont case UpdateLogLevel::UPDATE_DEBUG: LONG_PRINT_HILOG(LOG_DEBUG, subModuleTag, logContent.log, UpdateLog::GetBriefFileName(logContent.fileName).c_str(), logContent.line, logContent.args.c_str()); + break; case UpdateLogLevel::UPDATE_INFO: LONG_PRINT_HILOG(LOG_INFO, subModuleTag, logContent.log, UpdateLog::GetBriefFileName(logContent.fileName).c_str(), logContent.line, logContent.args.c_str()); + break; case UpdateLogLevel::UPDATE_ERROR: LONG_PRINT_HILOG(LOG_ERROR, subModuleTag, logContent.log, UpdateLog::GetBriefFileName(logContent.fileName).c_str(), logContent.line, logContent.args.c_str()); diff --git a/foundations/ability/sa_loader/include/base_service_kits_impl.h b/foundations/ability/sa_loader/include/base_service_kits_impl.h index c8ccee43..c3e5ae02 100644 --- a/foundations/ability/sa_loader/include/base_service_kits_impl.h +++ b/foundations/ability/sa_loader/include/base_service_kits_impl.h @@ -73,7 +73,6 @@ template BaseServiceKitsImpl::~BaseServiceKitsImpl() template sptr BaseServiceKitsImpl::GetService() { - ENGINE_LOGI("GetService entry"); std::lock_guard lock(remoteServerLock_); if (remoteServer_ != nullptr) { return remoteServer_; diff --git a/frameworks/js/napi/session/include/base_promise_session.h b/frameworks/js/napi/session/include/base_promise_session.h index 6ed63e63..956d624f 100644 --- a/frameworks/js/napi/session/include/base_promise_session.h +++ b/frameworks/js/napi/session/include/base_promise_session.h @@ -31,7 +31,6 @@ public: napi_value StartWork(napi_env env, size_t startIndex, const napi_value *args) override { - ENGINE_LOGI("BasePromiseSession::StartWork"); PARAM_CHECK_NAPI_CALL(env, args != nullptr, return nullptr, "Invalid para"); napi_value workName = CreateWorkerName(env); PARAM_CHECK_NAPI_CALL(env, workName != nullptr, return nullptr, "Failed to worker name"); @@ -53,7 +52,9 @@ public: void NotifyJS(napi_env env, napi_value thisVar, const RESULT &result) { int32_t errorNum = static_cast(result.businessError.errorNum); - ENGINE_LOGI("BasePromiseSession NotifyJS errorNum:%{public}d", errorNum); + if (errorNum != 0) { + ENGINE_LOGI("BasePromiseSession NotifyJS errorNum:%{public}d", errorNum); + } // Get the return result. napi_value processResult = nullptr; diff --git a/frameworks/js/napi/session/src/napi_session.cpp b/frameworks/js/napi/session/src/napi_session.cpp index 99c006fb..03d36c8f 100644 --- a/frameworks/js/napi/session/src/napi_session.cpp +++ b/frameworks/js/napi/session/src/napi_session.cpp @@ -56,7 +56,9 @@ void NapiSession::ExecuteWork(napi_env env) } else { workResult_ = doWorker_(context_); } - ENGINE_LOGI("UpdateSession::ExecuteWork workResult : %{public}d", workResult_); + if (workResult_ != 0) { + ENGINE_LOGI("UpdateSession::ExecuteWork workResult : %{public}d", workResult_); + } if (sessionParams_.isAsyncCompleteWork && IsWorkExecuteSuccess()) { // 异步搜包完成,需要把businessError设置进来或者超时,才能结束等待 std::unique_lock lock(conditionVariableMutex_); diff --git a/frameworks/js/napi/update/BUILD.gn b/frameworks/js/napi/update/BUILD.gn index b2bc922a..a9624f52 100644 --- a/frameworks/js/napi/update/BUILD.gn +++ b/frameworks/js/napi/update/BUILD.gn @@ -45,7 +45,6 @@ ohos_shared_library("$updateengine_client_library_name") { external_deps = [ "c_utils:utils", # sptr - "eventhandler:libeventhandler", "hilog:libhilog", ] diff --git a/frameworks/js/napi/update/include/session_manager.h b/frameworks/js/napi/update/include/session_manager.h index 585abe57..38bf5dc0 100644 --- a/frameworks/js/napi/update/include/session_manager.h +++ b/frameworks/js/napi/update/include/session_manager.h @@ -25,7 +25,6 @@ #include "base_session.h" #include "event_classify_info.h" -#include "event_handler.h" #include "event_info.h" namespace OHOS::UpdateEngine { @@ -55,7 +54,6 @@ private: napi_ref thisReference_ {}; std::map> sessions_; std::recursive_mutex sessionMutex_; - std::shared_ptr handler_; }; } // namespace OHOS::UpdateEngine #endif // UPDATE_SESSION_MGR_H \ No newline at end of file diff --git a/frameworks/js/napi/update/src/session_manager.cpp b/frameworks/js/napi/update/src/session_manager.cpp index 58ded004..fa0cd123 100644 --- a/frameworks/js/napi/update/src/session_manager.cpp +++ b/frameworks/js/napi/update/src/session_manager.cpp @@ -29,7 +29,6 @@ namespace OHOS::UpdateEngine { SessionManager::SessionManager(napi_env env, napi_ref thisReference) : env_(env), thisReference_(thisReference) { ENGINE_LOGI("SessionManager constructor"); - handler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); } SessionManager::~SessionManager() @@ -50,7 +49,6 @@ void SessionManager::AddSession(std::shared_ptr session) void SessionManager::RemoveSession(uint32_t sessionId) { - ENGINE_LOGI("RemoveSession sess"); std::lock_guard guard(sessionMutex_); sessions_.erase(sessionId); } @@ -229,11 +227,29 @@ void SessionManager::PublishToJS(const EventClassifyInfo &eventClassifyInfo, con void SessionManager::Emit(const EventClassifyInfo &eventClassifyInfo, const EventInfo &eventInfo) { ENGINE_LOGI("SessionManager::Emit 0x%{public}x", CAST_INT(eventClassifyInfo.eventClassify)); - auto task = [eventClassifyInfo, eventInfo, this]() { PublishToJS(eventClassifyInfo, eventInfo); }; - if (handler_ == nullptr) { - ENGINE_LOGI("handler_ is nullptr"); - return; - } - handler_->PostTask(task); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + PARAM_CHECK(loop != nullptr, return, "get event loop failed."); + + using UvWorkData = std::tuple; + UvWorkData *data = new (std::nothrow) std::tuple(this, eventClassifyInfo, eventInfo); + PARAM_CHECK(data != nullptr, return, "alloc data failed."); + + uv_work_t *work = new (std::nothrow) uv_work_t; + PARAM_CHECK(work != nullptr, delete data; return, "alloc work failed."); + + work->data = static_cast(data); + uv_queue_work_with_qos( + loop, + work, + [](uv_work_t *work) { ENGINE_LOGI("print job info"); }, + [](uv_work_t *work, int status) { + UvWorkData *data = static_cast(work->data); + auto &[mgr, eventClassifyInfo, eventInfo] = *data; + mgr->PublishToJS(eventClassifyInfo, eventInfo); + delete data; + delete work; + }, + uv_qos_default); } } // namespace OHOS::UpdateEngine \ No newline at end of file diff --git a/frameworks/js/napi/update/src/update_session.cpp b/frameworks/js/napi/update/src/update_session.cpp index 59da7c8c..abc6f49d 100644 --- a/frameworks/js/napi/update/src/update_session.cpp +++ b/frameworks/js/napi/update/src/update_session.cpp @@ -40,7 +40,6 @@ std::string BaseUpdateSession::GetFunctionName() void UpdatePromiseSession::CompleteWork(napi_env env, napi_status status) { - ENGINE_LOGI("UpdatePromiseSession::CompleteWork status: %d", static_cast(status)); UpdateResult result; GetUpdateResult(result); NotifyJS(env, NULL, result); 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 626b0a73..2409f2d0 100644 --- a/interfaces/inner_api/engine/include/update_service_kits_impl.h +++ b/interfaces/inner_api/engine/include/update_service_kits_impl.h @@ -82,6 +82,7 @@ public: int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::vector &packageNames, BusinessError &businessError) final; + int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath, BusinessError &businessError) final; diff --git a/interfaces/inner_api/feature/update/model/task/task_body_member_mask.h b/interfaces/inner_api/feature/update/model/task/task_body_member_mask.h index 54c22b85..f8c502fe 100644 --- a/interfaces/inner_api/feature/update/model/task/task_body_member_mask.h +++ b/interfaces/inner_api/feature/update/model/task/task_body_member_mask.h @@ -38,15 +38,15 @@ const std::map g_taskBodyTemplateMap = { { EventId::EVENT_VERSION_INFO_CHANGE, VERSION_DIGEST_INFO | UPGRADE_STATUS }, { EventId::EVENT_DOWNLOAD_WAIT, VERSION_DIGEST_INFO | UPGRADE_STATUS | INSTALL_MODE }, { EventId::EVENT_DOWNLOAD_START, VERSION_DIGEST_INFO | INSTALL_MODE }, - { EventId::EVENT_DOWNLOAD_UPDATE, VERSION_DIGEST_INFO | UPGRADE_STATUS | PROGRESS | INSTALL_MODE }, + { EventId::EVENT_DOWNLOAD_UPDATE, VERSION_DIGEST_INFO | UPGRADE_STATUS | PROGRESS | INSTALL_MODE | SUB_STATUS }, { EventId::EVENT_DOWNLOAD_PAUSE, VERSION_DIGEST_INFO | UPGRADE_STATUS | PROGRESS | INSTALL_MODE | ERROR_MESSAGE }, { EventId::EVENT_DOWNLOAD_RESUME, VERSION_DIGEST_INFO | UPGRADE_STATUS | PROGRESS | INSTALL_MODE }, - { EventId::EVENT_DOWNLOAD_SUCCESS, VERSION_DIGEST_INFO | INSTALL_MODE }, + { EventId::EVENT_DOWNLOAD_SUCCESS, VERSION_DIGEST_INFO | INSTALL_MODE | SUB_STATUS }, { EventId::EVENT_DOWNLOAD_CANCEL, VERSION_DIGEST_INFO | UPGRADE_STATUS }, { EventId::EVENT_DOWNLOAD_FAIL, VERSION_DIGEST_INFO | INSTALL_MODE | ERROR_MESSAGE }, { EventId::EVENT_TRANSFER_WAIT, VERSION_DIGEST_INFO | UPGRADE_STATUS | INSTALL_MODE }, { EventId::EVENT_TRANSFER_START, VERSION_DIGEST_INFO | INSTALL_MODE }, - { EventId::EVENT_TRANSFERING, VERSION_DIGEST_INFO | UPGRADE_STATUS | PROGRESS | INSTALL_MODE }, + { EventId::EVENT_TRANSFERING, VERSION_DIGEST_INFO | UPGRADE_STATUS | PROGRESS | INSTALL_MODE | SUB_STATUS }, { EventId::EVENT_TRANSFER_SUCCESS, VERSION_DIGEST_INFO | INSTALL_MODE }, { EventId::EVENT_TRANSFER_FAIL, VERSION_DIGEST_INFO | ERROR_MESSAGE | INSTALL_MODE }, { EventId::EVENT_UPGRADE_WAIT, VERSION_DIGEST_INFO | UPGRADE_STATUS | INSTALL_MODE | ERROR_MESSAGE }, diff --git a/interfaces/inner_api/modulemgr/include/module_manager.h b/interfaces/inner_api/modulemgr/include/module_manager.h index 7a625cca..6112a97f 100644 --- a/interfaces/inner_api/modulemgr/include/module_manager.h +++ b/interfaces/inner_api/modulemgr/include/module_manager.h @@ -45,14 +45,14 @@ public: void HandleOnStartOnStopFunc(std::string phase, const OHOS::SystemAbilityOnDemandReason &reason); void HookOnIdleFunc(std::string phase, LifeCycleFuncReturnType handleSAOnIdle); int32_t HandleOnIdleFunc(std::string phase, const OHOS::SystemAbilityOnDemandReason &reason); - - static std::map onRemoteRequestFuncMap_; + bool IsMapFuncExist(uint32_t code); private: int32_t retryInterval_ = 0; void *dueModuleHandler = nullptr; static std::map onStartOnStopFuncMap_; static std::map onIdleFuncMap_; + static std::map onRemoteRequestFuncMap_; static bool isLoaded; static std::mutex onRemoteRequestFuncMapMutex_; static std::mutex onStartOnStopFuncMapMutex_; diff --git a/interfaces/inner_api/modulemgr/src/module_manager.cpp b/interfaces/inner_api/modulemgr/src/module_manager.cpp index b3147a46..ad4736b0 100644 --- a/interfaces/inner_api/modulemgr/src/module_manager.cpp +++ b/interfaces/inner_api/modulemgr/src/module_manager.cpp @@ -80,22 +80,21 @@ void ModuleManager::HookFunc(std::vector codes, RequestFuncType handle { std::lock_guard guard(onRemoteRequestFuncMapMutex_); for (const uint32_t code : codes) { - if (onRemoteRequestFuncMap_.find(code) == onRemoteRequestFuncMap_.end()) { - UTILS_LOGE("code not exist %{public}d onRemoteRequestFuncMap_", code); + if (!IsMapFuncExist(code)) { + UTILS_LOGI("add code %{public}d", code); onRemoteRequestFuncMap_.insert(std::make_pair(code, handleRemoteRequest)); } else { - UTILS_LOGD("add code %{public}d to onRemoteRequestFuncMap_", code); - onRemoteRequestFuncMap_[code] = handleRemoteRequest; + UTILS_LOGI("code %{public}d already exist", code); } } } int32_t ModuleManager::HandleFunc(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - if (onRemoteRequestFuncMap_.find(code) == onRemoteRequestFuncMap_.end()) { - UTILS_LOGE("HandleFunc code %{public}d not exist", code); + if (!IsMapFuncExist(code)) { + UTILS_LOGI("code %{public}d not exist", code); } else { - UTILS_LOGD("HandleFunc code %{public}d called", code); + UTILS_LOGI("code %{public}d called", code); return ((RequestFuncType)onRemoteRequestFuncMap_[code])(code, data, reply, option); } return 0; @@ -112,10 +111,10 @@ void ModuleManager::HookOnStartOnStopFunc(std::string phase, LifeCycleFuncType h { std::lock_guard guard(onStartOnStopFuncMapMutex_); if (onStartOnStopFuncMap_.find(phase) == onStartOnStopFuncMap_.end()) { - UTILS_LOGE("phase exist already %{public}s onStartOnStopFuncMap_", phase.c_str()); + UTILS_LOGI("add phase %{public}s", phase.c_str()); onStartOnStopFuncMap_.insert(std::make_pair(phase, handleSAOnStartOnStop)); } else { - UTILS_LOGD("add phase %{public}s to onStartOnStopFuncMap_", phase.c_str()); + UTILS_LOGI("phase %{public}s exist", phase.c_str()); onStartOnStopFuncMap_[phase] = handleSAOnStartOnStop; } } @@ -123,10 +122,10 @@ void ModuleManager::HookOnStartOnStopFunc(std::string phase, LifeCycleFuncType h void ModuleManager::HandleOnStartOnStopFunc(std::string phase, const OHOS::SystemAbilityOnDemandReason &reason) { if (onStartOnStopFuncMap_.find(phase) == onStartOnStopFuncMap_.end()) { - UTILS_LOGE("HandleOnStartOnStopFunc phase %{public}s not exist", phase.c_str()); + UTILS_LOGI("phase %{public}s not exist", phase.c_str()); return; } - UTILS_LOGD("HandleOnStartOnStopFunc phase %{public}s exist", phase.c_str()); + UTILS_LOGI("HandleOnStartOnStopFunc phase %{public}s exist", phase.c_str()); ((LifeCycleFuncType)onStartOnStopFuncMap_[phase])(reason); } @@ -134,10 +133,10 @@ void ModuleManager::HookOnIdleFunc(std::string phase, LifeCycleFuncReturnType ha { std::lock_guard guard(onIdleFuncMapMutex_); if (onIdleFuncMap_.find(phase) == onIdleFuncMap_.end()) { - UTILS_LOGE("phase exist already %{public}s onIdleFuncMap_", phase.c_str()); + UTILS_LOGI("add phase %{public}s", phase.c_str()); onIdleFuncMap_.insert(std::make_pair(phase, handleSAOnIdle)); } else { - UTILS_LOGD("add phase %{public}s to onIdleFuncMap_", phase.c_str()); + UTILS_LOGI("phase %{public}s already exist", phase.c_str()); onIdleFuncMap_[phase] = handleSAOnIdle; } } @@ -145,12 +144,17 @@ void ModuleManager::HookOnIdleFunc(std::string phase, LifeCycleFuncReturnType ha int32_t ModuleManager::HandleOnIdleFunc(std::string phase, const OHOS::SystemAbilityOnDemandReason &reason) { if (onIdleFuncMap_.find(phase) == onIdleFuncMap_.end()) { - UTILS_LOGE("HandleOnIdleFunc phase %{public}s not exist", phase.c_str()); + UTILS_LOGI("phase %{public}s not exist", phase.c_str()); } else { - UTILS_LOGI("HandleOnIdleFunc phase %{public}s exist", phase.c_str()); + UTILS_LOGI("phase %{public}s already exist", phase.c_str()); return ((LifeCycleFuncReturnType)onIdleFuncMap_[phase])(reason); } return 0; } + +bool ModuleManager::IsMapFuncExist(uint32_t code) +{ + return onRemoteRequestFuncMap_.count(code); +} } // namespace UpdateEngine } // namespace OHOS diff --git a/interfaces/inner_api/modulemgr/src/update_service_module.cpp b/interfaces/inner_api/modulemgr/src/update_service_module.cpp index f4a73ebb..47c76c76 100644 --- a/interfaces/inner_api/modulemgr/src/update_service_module.cpp +++ b/interfaces/inner_api/modulemgr/src/update_service_module.cpp @@ -24,7 +24,6 @@ namespace OHOS { namespace UpdateEngine { void RegisterFunc(std::vector codes, RequestFuncType handleRemoteRequest) { - UTILS_LOGI("enter RegisterFunc"); OHOS::UpdateEngine::ModuleManager::GetInstance().HookFunc(codes, handleRemoteRequest); } diff --git a/services/engine/include/update_service.h b/services/engine/include/update_service.h index e0a0b14b..a123318f 100644 --- a/services/engine/include/update_service.h +++ b/services/engine/include/update_service.h @@ -91,6 +91,8 @@ public: int Dump(int fd, const std::vector &args) override; + void RegisterOhFunc(); + static sptr GetInstance(); sptr GetUpgradeCallback(const UpgradeInfo &info); diff --git a/services/engine/src/update_service.cpp b/services/engine/src/update_service.cpp index 148e13ff..b31582aa 100644 --- a/services/engine/src/update_service.cpp +++ b/services/engine/src/update_service.cpp @@ -430,38 +430,16 @@ void UpdateService::OnStart(const SystemAbilityOnDemandReason &startReason) ENGINE_LOGE("updateService_ null"); } - 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) - }; - ENGINE_LOGI("RegisterFunc HandleOhRemoteRequest"); - RegisterFunc(codes, HandleOhRemoteRequest); - DelayedSingleton::GetInstance()->LoadConfigInfo(); // 启动读取配置信息 std::string libPath = DelayedSingleton::GetInstance()->GetModuleLibPath(); ENGINE_LOGI("GetModuleLibPath %{public}s ", libPath.c_str()); ModuleManager::GetInstance().LoadModule(libPath); + ENGINE_LOGI("RegisterOhFunc HandleOhRemoteRequest"); + RegisterOhFunc(); + if (!ModuleManager::GetInstance().IsModuleLoaded()) { - ENGINE_LOGI("IsModuleLoaded false, init blue"); + ENGINE_LOGI("IsModuleLoaded false, init updateservice_sa"); DelayedSingleton::GetInstance()->Init(); // 动态启停流程启动 @@ -496,5 +474,32 @@ int32_t HandleOhRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel { 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); +} } // namespace UpdateEngine } // namespace OHOS diff --git a/services/engine/src/update_service_impl_firmware.cpp b/services/engine/src/update_service_impl_firmware.cpp index 040f9cac..6f64138e 100644 --- a/services/engine/src/update_service_impl_firmware.cpp +++ b/services/engine/src/update_service_impl_firmware.cpp @@ -182,7 +182,13 @@ int32_t UpdateServiceImplFirmware::GetNewVersionDescription(const UpgradeInfo &i return INT_CALL_SUCCESS; } std::string dataXml = FileUtils::ReadDataFromFile(changelogFilePath); - std::string dataXmlFinal = dataXml.substr(dataXml.find_first_of("|") + 1, dataXml.size()); + size_t startIndex = dataXml.find_first_of("|"); + if (startIndex == std::string::npos) { + FIRMWARE_LOGE("dataXml not found |"); + businessError.Build(CallResult::FAIL, "GetNewVersionDescription failed"); + return INT_CALL_SUCCESS; + } + std::string dataXmlFinal = dataXml.substr(startIndex + 1, dataXml.size()); GetChangelogContent(dataXmlFinal, descriptionOptions.language); componentDescription.descriptionInfo.content = dataXmlFinal; componentDescription.descriptionInfo.descriptionType = @@ -225,7 +231,13 @@ int32_t UpdateServiceImplFirmware::GetCurrentVersionDescription(const UpgradeInf return INT_CALL_SUCCESS; } std::string dataXml = FileUtils::ReadDataFromFile(changelogFilePath); - std::string dataXmlFinal = dataXml.substr(dataXml.find_first_of("|") + 1, dataXml.size()); + size_t startIndex = dataXml.find_first_of("|"); + if (startIndex == std::string::npos) { + FIRMWARE_LOGE("dataXml not found |"); + businessError.Build(CallResult::FAIL, "GetCurrentVersionDescription failed"); + return INT_CALL_SUCCESS; + } + std::string dataXmlFinal = dataXml.substr(startIndex + 1, dataXml.size()); GetChangelogContent(dataXmlFinal, descriptionOptions.language); descriptionContent.descriptionInfo.content = dataXmlFinal; descriptionContent.descriptionInfo.descriptionType = diff --git a/services/engine/src/update_service_local_updater.cpp b/services/engine/src/update_service_local_updater.cpp index 03ceb7eb..1197b872 100644 --- a/services/engine/src/update_service_local_updater.cpp +++ b/services/engine/src/update_service_local_updater.cpp @@ -32,8 +32,8 @@ int32_t UpdateServiceLocalUpdater::ApplyNewVersion(const UpgradeInfo &info, cons businessError.errorNum = CallResult::SUCCESS; int32_t ret = RebootAndInstallSdcardPackage(miscFile, packageNames) ? INT_CALL_SUCCESS : INT_CALL_FAIL; ENGINE_LOGI("ApplyNewVersion result : %{public}d", ret); - SYS_EVENT_SYSTEM_UPGRADE(0, - ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT); + SYS_EVENT_SYSTEM_UPGRADE( + 0, ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT); return ret; #else return INT_CALL_SUCCESS; diff --git a/services/engine/src/update_service_stub.cpp b/services/engine/src/update_service_stub.cpp index f3965f05..4e1966af 100644 --- a/services/engine/src/update_service_stub.cpp +++ b/services/engine/src/update_service_stub.cpp @@ -427,8 +427,7 @@ int32_t UpdateServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption &option) { ENGINE_LOGI("UpdateServiceStub func code %{public}u", code); - auto iter = ModuleManager::onRemoteRequestFuncMap_.find(code); - if (iter == ModuleManager::onRemoteRequestFuncMap_.end()) { + if (!ModuleManager::GetInstance().IsMapFuncExist(code)) { ENGINE_LOGE("UpdateServiceStub OnRemoteRequest code %{public}u not found", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } -- Gitee