From 273e6f4d0041b804226d96edb7f16f6dd9a69b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 4 Sep 2024 17:35:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?4.1Release=E9=80=9A=E7=9F=A5=E6=A0=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=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 --- .../common/include/base_service_kits_impl.h | 3 + interfaces/inner_api/engine/BUILD.gn | 2 +- interfaces/inner_api/include/update_helper.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 +- 16 files changed, 56 insertions(+), 172 deletions(-) delete mode 100644 services/engine/include/i_update_notify.h diff --git a/interfaces/inner_api/common/include/base_service_kits_impl.h b/interfaces/inner_api/common/include/base_service_kits_impl.h index 5fedec18..c2ae8ceb 100644 --- a/interfaces/inner_api/common/include/base_service_kits_impl.h +++ b/interfaces/inner_api/common/include/base_service_kits_impl.h @@ -18,6 +18,9 @@ #include +#ifndef ABILITY_RUNTIME_INNER_ENABLE +#include "ability_manager_proxy.h" +#endif #include "iremote_object.h" #include "common_death_recipient.h" diff --git a/interfaces/inner_api/engine/BUILD.gn b/interfaces/inner_api/engine/BUILD.gn index c36602c8..8dcbb7d1 100644 --- a/interfaces/inner_api/engine/BUILD.gn +++ b/interfaces/inner_api/engine/BUILD.gn @@ -87,7 +87,7 @@ ohos_shared_library("$updateengine_inner_library_name") { ] if (ability_ability_runtime_enable) { - external_deps += [ "ability_runtime:extension_manager" ] + external_deps += [ "ability_runtime:ability_manager" ] } part_name = "$updateengine_part_name" subsystem_name = "updater" diff --git a/interfaces/inner_api/include/update_helper.h b/interfaces/inner_api/include/update_helper.h index 8415a452..ef5949b6 100644 --- a/interfaces/inner_api/include/update_helper.h +++ b/interfaces/inner_api/include/update_helper.h @@ -35,10 +35,8 @@ #include "update_define.h" namespace OHOS::UpdateEngine { -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; +const std::string OUC_PACKAGE_NAME = "com.ohos.updateapp"; +const std::string OUC_SERVICE_EXT_ABILITY_NAME = "ServiceExtAbility"; // 搜索状态 enum class SearchStatus { @@ -318,7 +316,7 @@ struct UpgradeInfo { }; struct SubscribeInfo : public BaseJsonStruct { - std::string upgradeApp = UPDATE_APP_PACKAGE_NAME; + std::string upgradeApp = OUC_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 2f1ded35..ec1db30e 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()}; - UpdateNotify::GetInstance()->ConnectToAppService(eventInfoStr, subscribeInfo.ToJson()); + OHOS::UpdateEngine::UpdateNotify::NotifyToAppService(eventInfoStr, subscribeInfo.ToJson()); } } } // namespace UpdateEngine diff --git a/services/engine/engine_sa.gni b/services/engine/engine_sa.gni index f21c92aa..aea7516d 100644 --- a/services/engine/engine_sa.gni +++ b/services/engine/engine_sa.gni @@ -202,7 +202,7 @@ if (ability_ability_base_enable) { ] } if (ability_ability_runtime_enable) { - sa_external_deps += [ "ability_runtime:extension_manager" ] + sa_external_deps += [ "ability_runtime:ability_manager" ] } if (communication_netmanager_base_enable) { sa_external_deps += [ "netmanager_base:net_conn_manager_if" ] diff --git a/services/engine/include/i_update_notify.h b/services/engine/include/i_update_notify.h deleted file mode 100644 index 7807f57a..00000000 --- a/services/engine/include/i_update_notify.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 diff --git a/services/engine/include/update_notify.h b/services/engine/include/update_notify.h index 91be2ab0..a89c70b3 100644 --- a/services/engine/include/update_notify.h +++ b/services/engine/include/update_notify.h @@ -16,59 +16,40 @@ #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 IRemoteStub { +class UpdateNotify : public NoConstructor { public: - 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); + static bool NotifyToAppService(const std::string &eventInfo, const std::string &subscribeInfo); private: - 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 - }; + 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 = {}); }; class NotifyConnection : public AAFwk::AbilityConnectionStub { public: - explicit NotifyConnection(const sptr &instance); + explicit NotifyConnection() = default; ~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 412be658..98a66040 100644 --- a/services/engine/src/update_notify.cpp +++ b/services/engine/src/update_notify.cpp @@ -15,8 +15,6 @@ #include "update_notify.h" -#include "cJSON.h" -#include "extension_manager_client.h" #include "iservice_registry.h" #include "update_helper.h" @@ -24,129 +22,62 @@ namespace OHOS { namespace UpdateEngine { -std::mutex UpdateNotify::instanceLock_; -sptr UpdateNotify::instance_ = nullptr; - -UpdateNotify::UpdateNotify() -{ - ENGINE_LOGD("UpdateNotify"); -} - -UpdateNotify::~UpdateNotify() +ErrCode UpdateNotify::StartAbility(const AAFwk::Want &want) { - ENGINE_LOGD("~UpdateNotify"); + ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); + ENGINE_LOGI("StartAbility result %{public}d", result); + return result; } -sptr UpdateNotify::GetInstance() +ErrCode UpdateNotify::StopServiceAbility(const AAFwk::Want &want) { - if (instance_ == nullptr) { - std::lock_guard autoLock(instanceLock_); - if (instance_ == nullptr) { - instance_ = new UpdateNotify(); - } - } - return instance_; + ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StopServiceAbility(want); + ENGINE_LOGI("StopServiceAbility result %{public}d", result); + return result; } -ErrCode UpdateNotify::ConnectAbility(const AAFwk::Want &want, const sptr &connect) +ErrCode UpdateNotify::ConnectAbility(const AAFwk::Want &want, const sptr &connect, + const sptr &callerToken) { - ErrCode result = - AAFwk::ExtensionManagerClient::GetInstance().ConnectServiceExtensionAbility(want, connect, nullptr, -1); + ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, connect, callerToken); ENGINE_LOGI("ConnectAbility result %{public}d", result); return result; } -ErrCode UpdateNotify::DisconnectAbility(const sptr &connect) +ErrCode UpdateNotify::DisconnectAbility(const sptr &connect) { - ErrCode result = - AAFwk::ExtensionManagerClient::GetInstance().DisconnectAbility(connect); + ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connect); ENGINE_LOGI("DisconnectAbility result %{public}d", result); return result; } -bool UpdateNotify::ConnectToAppService(const std::string &eventInfo, const std::string &subscribeInfo) +AAFwk::Want UpdateNotify::MakeWant(const std::string &deviceId, const std::string &abilityName, + const std::string &bundleName, const std::string &subscribeInfo, const std::string ¶ms) { - 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); + AppExecFwk::ElementName element(deviceId, bundleName, abilityName); + AAFwk::Want want; + want.SetElement(element); + want.SetParam("EventInfo", params); + want.SetParam("SubscribeInfo", subscribeInfo); + return want; } -bool UpdateNotify::HandleMessage(const std::string &message) +bool UpdateNotify::NotifyToAppService(const std::string &eventInfo, const std::string &subscribeInfo) { - 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; - } - - 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); + if (eventInfo.empty()) { + ENGINE_LOGE("NotifyToAppService eventInfo error."); 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; + 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; } 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 a0b769b6..ae2965fd 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:extension_manager", + "ability_runtime:ability_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 477bafb5..04be0847 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:extension_manager", + "ability_runtime:ability_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 3ba5fba1..5e567292 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:extension_manager", + "ability_runtime:ability_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 0a94c440..044b27f0 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:extension_manager", + "ability_runtime:ability_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 f44ab3ba..9167ea5d 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:extension_manager", + "ability_runtime:ability_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 d32f09ec..d1aad60b 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:extension_manager", + "ability_runtime:ability_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 7294884c..828bf3f0 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:extension_manager", + "ability_runtime:ability_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 772f1b06..9e4fe061 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:extension_manager", + "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", -- Gitee From 424a90633b51830ef3e1281bcba0bbb0ba2fdfdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 4 Sep 2024 12:28:05 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B1=E8=B4=A5json?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- services/firmware/upgrade/flow/src/firmware_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/firmware/upgrade/flow/src/firmware_manager.cpp b/services/firmware/upgrade/flow/src/firmware_manager.cpp index 943e6a46..6ede3ae7 100644 --- a/services/firmware/upgrade/flow/src/firmware_manager.cpp +++ b/services/firmware/upgrade/flow/src/firmware_manager.cpp @@ -406,6 +406,7 @@ void FirmwareManager::HandleBootUpdateFail(const FirmwareTask &task, versionComponent.upgradeAction = UpgradeAction::UPGRADE; versionComponent.displayVersion = component.targetBlDisplayVersionNumber; versionComponent.innerVersion = component.targetBlVersionNumber; + versionComponent.componentExtra = JsonBuilder().Append("{}").ToJson(); versionComponents.push_back(versionComponent); } -- Gitee