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 5fedec18e19fa153ee168ae3305a126be1bef785..c2ae8ceb6e8a6f4b0aed9a23ec927ded8d6d3c8e 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 c36602c821605437cbeea993f141ff269119a33c..8dcbb7d13f33d13c725a4fdf2b1e5f6130f1cd90 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 8415a452885f1729b0b0f9254da25f83f8720e65..ef5949b6909ed082d47377bf3fa838d840710b7d 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 2f1ded359d294777cb370dc9f2b53c13103c01da..ec1db30e1e5bbf4a0746d1f114137f2304bda475 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 f21c92aa1b7bf7488c2560652fe1369c9cee88d6..aea7516d0a18b523febc50f189537c853dd24f77 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 7807f57a83970ba19d808286ef7bb719ec8b98a5..0000000000000000000000000000000000000000 --- 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 91be2ab087131e1bf71e890d8ec9d6660593684d..a89c70b324ace8cf053771688547c0a73f1327e1 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 412be658a09c5c7d36ad7f5ac9c32aeac5e4edd8..98a6604088be581375a841fcbe0a550660d4e3f0 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/services/firmware/upgrade/flow/src/firmware_manager.cpp b/services/firmware/upgrade/flow/src/firmware_manager.cpp index 943e6a46d0e96811954117f6d89f6788ba861b78..6ede3ae7135bd086373a221293541189e819fd86 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); } diff --git a/test/fuzztest/updateservicecancel_fuzzer/BUILD.gn b/test/fuzztest/updateservicecancel_fuzzer/BUILD.gn index a0b769b69ce300e39ff4c7350ba1300ccae5c382..ae2965fd340a28ee9d901b0d6f29690902f79b69 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 477bafb51a728d8d21b7ece7adf326acb4914cab..04be0847822491b55bb1ec27df24298dae1a78f5 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 3ba5fba13a37fb73d1396124fa1f80c680283844..5e567292c96e28bb3dab805b40b5c874f31999a7 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 0a94c4406735b6c2eb3a50eaaa9b22545c4e3a0c..044b27f02842760cd02c5db96ac0818c91a5098e 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 f44ab3bac69fa11532123e2d6ddf7311d3f04d60..9167ea5df08ddfc6a9202d8ddf5031c33b074a30 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 d32f09ec24b5323d83599e251a015eb0f38c5993..d1aad60b048b1155579c8ba6f2e57eb90b304534 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 7294884c86f81cac7671057e7d191a6a5b7e37d3..828bf3f0201505d651f29d085430a3cbf1656759 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 772f1b062542ff238ccff8349829349c904dfe9f..9e4fe061e8e1a725c27c793880f3881322a80aee 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",