diff --git a/interfaces/inner_api/include/update_helper.h b/interfaces/inner_api/include/update_helper.h index 12a4a6ffaa2052ea39bcfc228a214b71285b51ac..9c736d003f9f0becfb03090254e4be41fabae6b1 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 df87f476bf635242c549ad70707ef348a5af70c6..7c0a558a5a68bdb783564ac2c81800f89c3e5fd7 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 0000000000000000000000000000000000000000..44b01dc3d4c416419bd9395a50fe21a81aa7854f --- /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 0000000000000000000000000000000000000000..29bb56ff145852db0133d0ec1f0a411b5b698fe2 --- /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 0000000000000000000000000000000000000000..4480d8ad78eb6d8c0a9d49ed5825678162fb2032 --- /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 bdc43c4b7cd89211b2786f8991cc49e1131ccfba..c9b3d6f739838d5c78869f75d5fcb5ee359a519d 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 62de4e82e46bc4544b2e13a9b16680403ecbef8a..82ab79f480fb687a8516b855a95e1adead285a03 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()