From 7a4300f2ac0e5479f6b3af3feb1626a62d454ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=8D=83=E4=B8=96=E7=95=8C?= <9544640+yangsong_xks@user.noreply.gitee.com> Date: Thu, 9 Nov 2023 12:11:55 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 大千世界 <> --- interfaces/inner_api/include/update_helper.h | 6 +++ services/engine/engine_sa.gni | 13 +++++ .../event/include/firmware_event_publish.h | 29 +++++++++++ .../event/src/firmware_event_publish.cpp | 48 +++++++++++++++++++ .../src/firmware_event_publish_empty.cpp | 25 ++++++++++ .../include/firmware_check_data_processor.h | 1 + .../src/firmware_check_data_processor.cpp | 14 ++++++ 7 files changed, 136 insertions(+) create mode 100644 services/firmware/event/include/firmware_event_publish.h create mode 100644 services/firmware/event/src/firmware_event_publish.cpp create mode 100644 services/firmware/event/src/firmware_event_publish_empty.cpp diff --git a/interfaces/inner_api/include/update_helper.h b/interfaces/inner_api/include/update_helper.h index 12a4a6ff..9c736d00 100644 --- a/interfaces/inner_api/include/update_helper.h +++ b/interfaces/inner_api/include/update_helper.h @@ -496,6 +496,12 @@ enum class AuthType { WD = 2 }; +struct SystemUpdateInfo { + std::string version; + int64_t firstReceivedTime; + std::string packageType; +} + using CheckNewVersionDone = std::function; using OnEvent = std::function; diff --git a/services/engine/engine_sa.gni b/services/engine/engine_sa.gni index df87f476..7c0a558a 100644 --- a/services/engine/engine_sa.gni +++ b/services/engine/engine_sa.gni @@ -35,6 +35,10 @@ declare_args() { if (!defined(global_parts_info.distributeddatamgr_preferences)) { preference_native_preferences_enable = false } + ability_common_event_service_enable = true + if (!defined(global_parts_info.notification_common_event_service)) { + ability_common_event_service_enable = false + } } sa_sources = [ @@ -72,6 +76,12 @@ if (ability_ability_base_enable || ability_ability_runtime_enable) { sa_sources += [ "$updateengine_root_path/services/core/ability/callback/src/base_callback_utils_empty.cpp" ] } +if (ability_common_event_service_enable && (ability_ability_base_enable || ability_ability_runtime_enable)) { + sa_sources += [ "$updateengine_root_path/services/firmware/event/src/firmware_event_publish.cpp" ] +} else { + sa_sources += [ "$updateengine_root_path/services/firmware/event/src/firmware_event_publish_empty.cpp" ] +} + if (communication_netmanager_base_enable) { sa_sources += [ "$updateengine_root_path/services/utils/src/dupdate_net_manager.cpp", @@ -210,6 +220,9 @@ if (communication_netmanager_base_enable) { if (preference_native_preferences_enable) { sa_external_deps += [ "preferences:native_preferences" ] } +if (ability_common_event_service_enable) { + sa_external_deps += [ "common_event_service:cesfwk_innerkits" ] +} sa_external_deps += firmware_external_deps sa_external_deps += sqlite_external_deps diff --git a/services/firmware/event/include/firmware_event_publish.h b/services/firmware/event/include/firmware_event_publish.h new file mode 100644 index 00000000..44b01dc3 --- /dev/null +++ b/services/firmware/event/include/firmware_event_publish.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FIRMWARE_EVENT_PUBLISH_H +#define FIRMWARE_EVENT_PUBLISH_H + +#include "update_helper.h" + +namespace OHOS { +namespace UpdateEngine { +class FirmwareEventPublish { +public: + static bool PublishSystemUpdate(const SystemUpdateInfo &systemUpdateInfo); +}; +} // namespace UpdateEngine +} // namespace OHOS +#endif // FIRMWARE_EVENT_PUBLISH_H \ No newline at end of file diff --git a/services/firmware/event/src/firmware_event_publish.cpp b/services/firmware/event/src/firmware_event_publish.cpp new file mode 100644 index 00000000..29bb56ff --- /dev/null +++ b/services/firmware/event/src/firmware_event_publish.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "firmware_event_publish.h" + +#include +#include +#include +#include +#include + +namespace OHOS { +namespace UpdateEngine { +const std::string SYSTEM_UPDATE_FOR_POLICY = "usual.event.DUE_SA_FIRMWARE_UPDATE_FOR_POLICY"; +const std::string FIRMWARE_EVENT_INFO_NAME = "version"; +const std::string FIRMWARE_EVENT_INFO_TYPE = "packageType"; +const std::string FIRMWARE_EVENT_INFO_CHECK_TIME = "firstReceivedTime"; +const std::string FIRMWARE_CHECK_RESULT_PERMISSION = "ohos.permission.UPDATE_SYSTEM"; + +bool FirmwareEventPublish::PublishSystemUpdate(const SystemUpdateInfo &systemUpdateInfo) +{ + OHOS::EventFwk::CommonEventPublishInfo publishInfo; + publishInfo.SetOrdered(false); + publishInfo.SetSubscriberPermissions({ FIRMWARE_CHECK_RESULT_PERMISSION }); + + OHOS::AAFwk::Want updateWant; + updateWant.SetAction(SYSTEM_UPDATE_FOR_POLICY); + updateWant.SetParam(FIRMWARE_EVENT_INFO_NAME, systemUpdateInfo.version); + updateWant.SetParam(FIRMWARE_EVENT_INFO_TYPE, systemUpdateInfo.packageType); + updateWant.SetParam(FIRMWARE_EVENT_INFO_CHECK_TIME, systemUpdateInfo.firstReceivedTime); + + OHOS::EventFwk::CommonEventData event(updateWant); + return OHOS::EventFwk::CommonEventManager::PublishCommonEvent(event, publishInfo, nullptr); +} +} // namespace UpdateEngine +} // namespace OHOS \ No newline at end of file diff --git a/services/firmware/event/src/firmware_event_publish_empty.cpp b/services/firmware/event/src/firmware_event_publish_empty.cpp new file mode 100644 index 00000000..4480d8ad --- /dev/null +++ b/services/firmware/event/src/firmware_event_publish_empty.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "firmware_event_publish.h" + +namespace OHOS { +namespace UpdateEngine { +bool FirmwareEventPublish::PublishSystemUpdate(const SystemUpdateInfo &systemUpdateInfo) +{ + return false; +} +} // namespace UpdateEngine +} // namespace OHOS \ No newline at end of file diff --git a/services/firmware/upgrade/data_processor/include/firmware_check_data_processor.h b/services/firmware/upgrade/data_processor/include/firmware_check_data_processor.h index bdc43c4b..c9b3d6f7 100644 --- a/services/firmware/upgrade/data_processor/include/firmware_check_data_processor.h +++ b/services/firmware/upgrade/data_processor/include/firmware_check_data_processor.h @@ -54,6 +54,7 @@ private: CombinationType GetCombinationType(); void BuildComponentSPath(); void BuildVersionDigest(NewVersionInfo &newVersionInfo, const std::vector &componentList); + void HandleNewVersionPublish(); private: std::vector componentList_; diff --git a/services/firmware/upgrade/data_processor/src/firmware_check_data_processor.cpp b/services/firmware/upgrade/data_processor/src/firmware_check_data_processor.cpp index 62de4e82..82ab79f4 100644 --- a/services/firmware/upgrade/data_processor/src/firmware_check_data_processor.cpp +++ b/services/firmware/upgrade/data_processor/src/firmware_check_data_processor.cpp @@ -25,6 +25,7 @@ #include "firmware_component_operator.h" #include "firmware_constant.h" #include "firmware_callback_utils.h" +#include "firmware_event_publish.h" #include "firmware_log.h" #include "firmware_task_operator.h" #include "device_adapter.h" @@ -149,6 +150,19 @@ void FirmwareCheckDataProcessor::HandleNewVersion() task.status = UpgradeStatus::CHECK_VERSION_SUCCESS; task.combinationType = GetCombinationType(); FirmwareTaskOperator().Insert(task); + + // 通知版本变更 + HandleNewVersionPublish(); +} + +void FirmwareCheckDataProcessor::HandleNewVersionPublish() +{ + SystemUpdateInfo systemUpdateInfo; + systemUpdateInfo.version = componentList_[0].targetBlDisplayVersionNumber; + systemUpdateInfo.packageType = "normal"; + systemUpdateInfo.firstReceivedTime = TimeUtils::GetTimestamp(); + bool ret = FirmwareEventPublish::PublishSystemUpdate(systemUpdateInfo); + FIRMWARE_LOGI("HandleNewVersionPublish ret %{public}d", ret); } void FirmwareCheckDataProcessor::BuildComponentSPath() -- Gitee