diff --git a/frameworks/core/src/common_event_listener.cpp b/frameworks/core/src/common_event_listener.cpp index 54334609..9e481859 100644 --- a/frameworks/core/src/common_event_listener.cpp +++ b/frameworks/core/src/common_event_listener.cpp @@ -172,8 +172,8 @@ void CommonEventListener::Stop() EVENT_LOGE("commonEventSubscriber_ == nullptr"); return; } - EVENT_LOGD("event size: %{public}u", - (uint32_t)commonEventSubscriber_->GetSubscribeInfo().GetMatchingSkills().CountEntities()); + EVENT_LOGD("event size: %{public}zu", + commonEventSubscriber_->GetSubscribeInfo().GetMatchingSkills().CountEvent()); if (CommonEventSubscribeInfo::HANDLER == commonEventSubscriber_->GetSubscribeInfo().GetThreadMode()) { EVENT_LOGD("stop listener in HANDLER mode"); return; diff --git a/services/include/common_event_manager_service.h b/services/include/common_event_manager_service.h index 5a416aba..5aca8735 100644 --- a/services/include/common_event_manager_service.h +++ b/services/include/common_event_manager_service.h @@ -16,12 +16,13 @@ #ifndef FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_H #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_H -#include #include "common_event_stub.h" #include "event_handler.h" #include "ffrt.h" #include "inner_common_event_manager.h" #include "nocopyable.h" +#include "refbase.h" +#include namespace OHOS { namespace EventFwk { @@ -29,6 +30,7 @@ enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; class CommonEventManagerService : public CommonEventStub { public: + static sptr GetInstance(); CommonEventManagerService(); virtual ~CommonEventManagerService(); /** @@ -170,6 +172,9 @@ private: void GetHidumpInfo(const std::vector &args, std::string &result); private: + static sptr instance_; + static std::mutex instanceMutex_; + std::shared_ptr innerCommonEventManager_; ServiceRunningState serviceRunningState_ = ServiceRunningState::STATE_NOT_START; std::shared_ptr runner_; diff --git a/services/include/common_event_manager_service_ability.h b/services/include/common_event_manager_service_ability.h index ed2d461f..00d3a2b9 100644 --- a/services/include/common_event_manager_service_ability.h +++ b/services/include/common_event_manager_service_ability.h @@ -16,6 +16,7 @@ #ifndef FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_ABILITY_H #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_ABILITY_H +#include "refbase.h" #include "system_ability.h" #include "common_event_manager_service.h" @@ -45,7 +46,7 @@ private: DECLARE_SYSTEM_ABILITY(CommonEventManagerServiceAbility); private: - std::shared_ptr service_; + sptr service_; }; } // namespace EventFwk } // namespace OHOS diff --git a/services/src/common_event_manager_service.cpp b/services/src/common_event_manager_service.cpp index a25bb84a..46d82a86 100644 --- a/services/src/common_event_manager_service.cpp +++ b/services/src/common_event_manager_service.cpp @@ -26,9 +26,12 @@ #include "ipc_skeleton.h" #include "parameters.h" #include "publish_manager.h" +#include "refbase.h" #include "system_ability_definition.h" #include "xcollie/watchdog.h" #include "ces_inner_error_code.h" +#include +#include namespace OHOS { namespace EventFwk { @@ -38,6 +41,22 @@ const std::string NOTIFICATION_CES_CHECK_SA_PERMISSION = "notification.ces.check using namespace OHOS::Notification; +sptr CommonEventManagerService::instance_; +std::mutex CommonEventManagerService::instanceMutex_; + +sptr CommonEventManagerService::GetInstance() +{ + std::lock_guard lock(instanceMutex_); + if (instance_ == nullptr) { + instance_ = new (std::nothrow) CommonEventManagerService(); + if (instance_ == nullptr) { + EVENT_LOGE("Failed to create CommonEventManagerService instance."); + return nullptr; + } + } + return instance_; +} + CommonEventManagerService::CommonEventManagerService() : serviceRunningState_(ServiceRunningState::STATE_NOT_START), runner_(nullptr), diff --git a/services/src/common_event_manager_service_ability.cpp b/services/src/common_event_manager_service_ability.cpp index 6d8fb7bb..0c14ed3c 100644 --- a/services/src/common_event_manager_service_ability.cpp +++ b/services/src/common_event_manager_service_ability.cpp @@ -15,7 +15,9 @@ #include "common_event_manager_service_ability.h" +#include "common_event_manager_service.h" #include "event_log_wrapper.h" +#include namespace OHOS { namespace EventFwk { @@ -38,14 +40,14 @@ void CommonEventManagerServiceAbility::OnStart() return; } - service_ = DelayedSingleton::GetInstance(); + service_ = CommonEventManagerService::GetInstance(); ErrCode errorCode = service_->Init(); if (errorCode != ERR_OK) { EVENT_LOGE("Failed to init the commonEventManagerService instance."); return; } - if (!Publish(service_.get())) { + if (!Publish(service_)) { EVENT_LOGE("Failed to publish CommonEventManagerService to SystemAbilityMgr"); return; } diff --git a/services/test/moduletest/common_event_services_module_test/common_event_services_module_test.cpp b/services/test/moduletest/common_event_services_module_test/common_event_services_module_test.cpp index 6f144dbb..4ef8eee6 100644 --- a/services/test/moduletest/common_event_services_module_test/common_event_services_module_test.cpp +++ b/services/test/moduletest/common_event_services_module_test/common_event_services_module_test.cpp @@ -77,7 +77,7 @@ sptr cesModuleTest::commonEventManagerService_ = null void cesModuleTest::SetUpTestCase() { - commonEventManagerService_ = new CommonEventManagerService(); + commonEventManagerService_ = CommonEventManagerService::GetInstance(); commonEventManagerService_->Init(); bundleObject = new OHOS::AppExecFwk::MockBundleMgrService(); diff --git a/services/test/unittest/common_event_manager_service_ability_test/common_event_manager_service_ability_test.cpp b/services/test/unittest/common_event_manager_service_ability_test/common_event_manager_service_ability_test.cpp index fcfc2ada..0a3ef08b 100755 --- a/services/test/unittest/common_event_manager_service_ability_test/common_event_manager_service_ability_test.cpp +++ b/services/test/unittest/common_event_manager_service_ability_test/common_event_manager_service_ability_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "refbase.h" #include #include #define private public @@ -63,7 +64,7 @@ HWTEST_F(CommonEventManagerServiceAbilityTest, CommonEventManagerServiceAbility_ std::shared_ptr commonEventManagerServiceAbility = std::make_shared(systemAbilityId, runOnCreate); ASSERT_NE(nullptr, commonEventManagerServiceAbility); - commonEventManagerServiceAbility->service_ = std::make_shared(); + commonEventManagerServiceAbility->service_ = sptr(); commonEventManagerServiceAbility->OnStart(); GTEST_LOG_(INFO) << "CommonEventManagerServiceAbility_0100 end"; } diff --git a/test/systemtest/common/ces/common_event_services_system_test/BUILD.gn b/test/systemtest/common/ces/common_event_services_system_test/BUILD.gn index 84c81814..c5b8a128 100644 --- a/test/systemtest/common/ces/common_event_services_system_test/BUILD.gn +++ b/test/systemtest/common/ces/common_event_services_system_test/BUILD.gn @@ -17,6 +17,14 @@ import("//build/test.gni") module_output_path = "common_event_service/systemtest" ohos_systemtest("cesSystemTest") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path sources = [ "common_event_services_system_test.cpp" ] diff --git a/tools/test/systemtest/cem/BUILD.gn b/tools/test/systemtest/cem/BUILD.gn index 3cec2f7b..2fbed0d7 100644 --- a/tools/test/systemtest/cem/BUILD.gn +++ b/tools/test/systemtest/cem/BUILD.gn @@ -49,6 +49,14 @@ ohos_systemtest("common_event_command_dump_system_test") { } ohos_systemtest("common_event_command_publish_system_test") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } module_out_path = module_output_path include_dirs = [ "${ability_runtime_path}/tools/test/systemtest/aa" ]