diff --git a/services/reminder/BUILD.gn b/services/reminder/BUILD.gn index 7e7ca514265a388bdc5dec209abaad88c14d7cda..1a14104e9e0c9b5f456742c78e35f9c8d547265f 100644 --- a/services/reminder/BUILD.gn +++ b/services/reminder/BUILD.gn @@ -51,16 +51,13 @@ ohos_source_set("reminder_service_sources") { defines = [] sources = [ - "src/reminder_access_token_helper.cpp", "src/reminder_agent_service.cpp", "src/reminder_agent_service_ability.cpp", "src/reminder_bundle_manager_helper.cpp", - "src/reminder_config_change_observer.cpp", "src/reminder_data_manager.cpp", "src/reminder_data_manager_inner.cpp", "src/reminder_datashare_helper.cpp", "src/reminder_event_manager.cpp", - "src/reminder_os_account_manager_helper.cpp", "src/reminder_store.cpp", "src/reminder_store_strategy.cpp", "src/reminder_table.cpp", diff --git a/services/reminder/include/reminder_access_token_helper.h b/services/reminder/include/reminder_access_token_helper.h deleted file mode 100644 index ea0afa2257250858bbf2f22409b53da9eb55ac5b..0000000000000000000000000000000000000000 --- a/services/reminder/include/reminder_access_token_helper.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2022 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_ACCESS_TOKEN_HELPER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_ACCESS_TOKEN_HELPER_H - -#include -#include "refbase.h" - -#include "accesstoken_kit.h" - -namespace OHOS { -namespace Notification { -class ReminderAccessTokenHelper { -public: - static bool IsSystemApp(); - static bool VerifyNativeToken(const OHOS::Security::AccessToken::AccessTokenID &callerToken); -private: -}; -} // namespace Notification -} // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_ACCESS_TOKEN_HELPER_H \ No newline at end of file diff --git a/services/reminder/include/reminder_agent_service.h b/services/reminder/include/reminder_agent_service.h index 19c33bbe37e2dd26c3994f99411eaf423352a6bb..1d5aa272545dde0c2930b2d67d2398089f48ea14 100644 --- a/services/reminder/include/reminder_agent_service.h +++ b/services/reminder/include/reminder_agent_service.h @@ -126,11 +126,6 @@ private: */ bool IsSystemApp(); - /** - * @brief Get client bundle name. - */ - std::string GetClientBundleName(const int32_t callingUid); - private: std::mutex unloadMutex_; // for tryUnloadTask_ ffrt::task_handle tryUnloadTask_ {nullptr}; diff --git a/services/reminder/include/reminder_bundle_manager_helper.h b/services/reminder/include/reminder_bundle_manager_helper.h index 9763f19e8b70d0f984612957b566fc383f2db4ff..995e3e147a1333922e6f2f89a3be5a681091a3c9 100644 --- a/services/reminder/include/reminder_bundle_manager_helper.h +++ b/services/reminder/include/reminder_bundle_manager_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -16,28 +16,26 @@ #ifndef NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H #define NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H -#include #include #include +#include "singleton.h" #include "bundle_mgr_interface.h" -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "refbase.h" #include "remote_death_recipient.h" -#include "singleton.h" -namespace OHOS { -namespace Notification { -class ReminderBundleManagerHelper : public DelayedSingleton { +namespace OHOS::Notification { +class ReminderBundleManagerHelper : public DelayedRefSingleton { public: + ReminderBundleManagerHelper(); + ~ReminderBundleManagerHelper(); + /** * @brief Obtains the bundle name base on the specified uid. * * @param uid Indicates the specified uid. * @return Returns the bundle name. */ - std::string GetBundleNameByUid(int32_t uid); + std::string GetBundleNameByUid(const int32_t uid); /** * @brief Obtains the default uid. @@ -46,19 +44,19 @@ public: * @param userId Indicates the user id. * @return Returns the uid. */ - int32_t GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId); + int32_t GetDefaultUidByBundleName(const std::string& bundle, const int32_t userId); /** * @brief Obtains bundle info by bundle name. * * @param bundleName Indicates the bundle name. * @param flag Indicates the bundle flag. - * @param bundleInfo Indicates the bundle info. * @param userId Indicates the user id. + * @param bundleInfo Indicates the bundle info. * @return Returns the check result. */ - bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, - int32_t userId, AppExecFwk::BundleInfo &bundleInfo); + bool GetBundleInfo(const std::string& bundleName, const AppExecFwk::BundleFlag flag, + const int32_t userId, AppExecFwk::BundleInfo& bundleInfo); /** * @brief Obtains the app index by uid. @@ -70,16 +68,12 @@ public: private: void Connect(); void Disconnect(); - - void OnRemoteDied(const wptr &object); + void OnRemoteDied(const wptr& object); private: - sptr bundleMgr_ = nullptr; - std::mutex connectionMutex_; - sptr deathRecipient_ = nullptr; - - DECLARE_DELAYED_SINGLETON(ReminderBundleManagerHelper) + std::mutex mutex_; // for bundleMgr_ + sptr bundleMgr_ {nullptr}; + sptr deathRecipient_ {nullptr}; }; -} // namespace Notification -} // namespace OHOS +} // namespace OHOS::Notification #endif // NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H diff --git a/services/reminder/include/reminder_config_change_observer.h b/services/reminder/include/reminder_config_change_observer.h deleted file mode 100644 index 982b7ddb1fffef61c9ae26bd9daf4fa2ffdc938c..0000000000000000000000000000000000000000 --- a/services/reminder/include/reminder_config_change_observer.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H - -#include "configuration_observer_stub.h" - -namespace OHOS { -namespace Notification { - -/** - * @brief Listening system language change, when the system language changes, - * notify ReminderDataManager. -*/ -class ReminderConfigChangeObserver final : public AppExecFwk::ConfigurationObserverStub { -public: - ReminderConfigChangeObserver() = default; - ~ReminderConfigChangeObserver() = default; - -public: - void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; - -private: - std::string languageInfo_; -}; -} // namespace Notification -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/services/reminder/include/reminder_data_manager.h b/services/reminder/include/reminder_data_manager.h index 3d22df0c9b0c5c7f8b15404f4a2f32b722da8bf3..81221bfb374ed1da80161bfe07c9156386e2e4f5 100644 --- a/services/reminder/include/reminder_data_manager.h +++ b/services/reminder/include/reminder_data_manager.h @@ -29,7 +29,6 @@ #include "reminder_request_adaptation.h" #include "reminder_store.h" #include "reminder_timer_info.h" -#include "reminder_config_change_observer.h" #include "datashare_predicates.h" #include "datashare_values_bucket.h" #include "app_mgr_interface.h" diff --git a/services/reminder/include/reminder_event_manager.h b/services/reminder/include/reminder_event_manager.h index 4f1cae6276fa8a9fb6c81c265ba2bb4423f08d28..b347324cc7c8d412f4f58edbfd3f2028a9f2922c 100644 --- a/services/reminder/include/reminder_event_manager.h +++ b/services/reminder/include/reminder_event_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -17,85 +17,86 @@ #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H #include "common_event_subscriber.h" -#include "reminder_data_manager.h" -#include "system_ability_status_change_stub.h" #include "notification_subscriber.h" +#include "configuration_observer_stub.h" +#include "system_ability_status_change_stub.h" -#include - -namespace OHOS { -namespace Notification { +namespace OHOS::Notification { class ReminderEventManager { public: - explicit ReminderEventManager(std::shared_ptr &reminderDataManager); - virtual ~ReminderEventManager() {}; - ReminderEventManager(ReminderEventManager &other) = delete; - ReminderEventManager& operator = (const ReminderEventManager &other) = delete; + ReminderEventManager() = default; + ~ReminderEventManager() = default; + ReminderEventManager(ReminderEventManager& other) = delete; + ReminderEventManager& operator = (const ReminderEventManager& other) = delete; + +public: + void Init(); private: - void init(std::shared_ptr &reminderDataManager) const; - void SubscribeSystemAbility(std::shared_ptr &reminderDataManager) const; + void SubscribeEvent(); + void SubscribeSystemAbility(const int32_t systemAbilityId); class ReminderEventSubscriber : public EventFwk::CommonEventSubscriber { public: - ReminderEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, - std::shared_ptr &reminderDataManager); - virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); + ReminderEventSubscriber(const EventFwk::CommonEventSubscribeInfo& subscriberInfo); -private: - sptr GetBundleOption(const OHOS::EventFwk::Want &want) const; - int32_t GetUid(const OHOS::EventFwk::Want &want) const; - void HandlePackageRemove(const EventFwk::Want &want) const; - void HandleProcessDied(const EventFwk::Want &want) const; - std::shared_ptr reminderDataManager_ = nullptr; + void OnReceiveEvent(const EventFwk::CommonEventData& data) override; }; -class ReminderEventCustomSubscriber : public EventFwk::CommonEventSubscriber { +class ReminderCustomEventSubscriber : public EventFwk::CommonEventSubscriber { public: - ReminderEventCustomSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, - std::shared_ptr &reminderDataManager); - virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); + ReminderCustomEventSubscriber(const EventFwk::CommonEventSubscribeInfo& subscriberInfo); -private: - std::shared_ptr reminderDataManager_ = nullptr; + void OnReceiveEvent(const EventFwk::CommonEventData& data) override; }; -class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { +class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { public: - explicit SystemAbilityStatusChangeListener(std::shared_ptr &reminderDataManager); - ~SystemAbilityStatusChangeListener() {}; - virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; -private: - std::shared_ptr reminderDataManager_ = nullptr; + SystemAbilityStatusChangeListener() = default; + ~SystemAbilityStatusChangeListener() = default; + + void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; }; class ReminderNotificationSubscriber : public NotificationSubscriber { public: - explicit ReminderNotificationSubscriber(std::shared_ptr &reminderDataManager); - ~ReminderNotificationSubscriber() override; - void OnConnected() override; - void OnDisconnected() override; - void OnCanceled(const std::shared_ptr &request, - const std::shared_ptr &sortingMap, int deleteReason) override; - void OnConsumed(const std::shared_ptr &request, - const std::shared_ptr &sortingMap) override; - void OnUpdate(const std::shared_ptr &sortingMap) override; - void OnDied() override; + ReminderNotificationSubscriber() = default; + ~ReminderNotificationSubscriber() override = default; + + void OnConnected() override {} + void OnDisconnected() override {} + void OnCanceled(const std::shared_ptr& request, + const std::shared_ptr& sortingMap, int deleteReason) override; + void OnConsumed(const std::shared_ptr& request, + const std::shared_ptr& sortingMap) override {} + void OnUpdate(const std::shared_ptr& sortingMap) override {} + void OnDied() override {} void OnDoNotDisturbDateChange( - const std::shared_ptr &date) override; + const std::shared_ptr& date) override {} void OnEnabledNotificationChanged( - const std::shared_ptr &callbackData) override; - void OnBadgeChanged(const std::shared_ptr &badgeData) override; - void OnBadgeEnabledChanged(const sptr &callbackData) override; - void OnBatchCanceled(const std::vector> &requestList, - const std::shared_ptr &sortingMap, int32_t deleteReason) override; -private: - std::shared_ptr reminderDataManager_ = nullptr; + const std::shared_ptr& callbackData) override {} + void OnBadgeChanged(const std::shared_ptr& badgeData) override {} + void OnBadgeEnabledChanged(const sptr& callbackData) override {} + void OnBatchCanceled(const std::vector>& requestList, + const std::shared_ptr& sortingMap, int32_t deleteReason) override {} +}; }; - static std::shared_ptr subscriber_; +/** + * @brief Listening system language change, when the system language changes, + * notify ReminderDataManager. + */ +class ReminderConfigChangeObserver final : public AppExecFwk::ConfigurationObserverStub { +public: + ReminderConfigChangeObserver() = default; + ~ReminderConfigChangeObserver() = default; + +public: + void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override; + +private: + std::string languageInfo_; }; -} // namespace OHOS -} // namespace Notification +} // namespace OHOS::Notification #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H diff --git a/services/reminder/include/reminder_os_account_manager_helper.h b/services/reminder/include/reminder_os_account_manager_helper.h deleted file mode 100644 index 16f4433571cb3da9c08a4c50b219f10b6a085a09..0000000000000000000000000000000000000000 --- a/services/reminder/include/reminder_os_account_manager_helper.h +++ /dev/null @@ -1,55 +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 DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_OS_ACCOUNT_MANAGER_HELPER_H -#define DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_OS_ACCOUNT_MANAGER_HELPER_H - -#include "errors.h" -#include "singleton.h" -#include - -namespace OHOS { -namespace Notification { -class ReminderOsAccountManagerHelper : public DelayedSingleton { -public: - - ReminderOsAccountManagerHelper() = default; - ~ReminderOsAccountManagerHelper() = default; - - /** - * @brief Get OsAccountManagerHelper instance object. - */ - static ReminderOsAccountManagerHelper &GetInstance(); - - /** - * Gets operating system account local ID from uid. - * - * @param uid Indicates the uid. - * @param id Indicates the account ID. - * @return Returns result code. - */ - ErrCode GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &id); - - /** - * Gets operating system account local ID from current active. - * - * @param id Indicates the current active account ID. - * @return Returns result code. - */ - ErrCode GetCurrentActiveUserId(int32_t &id); -}; -} // namespace OHOS -} // namespace Notification -#endif // DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_OS_ACCOUNT_MANAGER_HELPER_H \ No newline at end of file diff --git a/services/reminder/include/reminder_utils.h b/services/reminder/include/reminder_utils.h index eedd2121dd626368a1cd6877b52fdf6fd693de1e..40d93dc3cc13ab40ffe1f5da946b8a5ef80ebdf3 100644 --- a/services/reminder/include/reminder_utils.h +++ b/services/reminder/include/reminder_utils.h @@ -16,36 +16,15 @@ #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_UTILS_H #include "ans_log_wrapper.h" -#include "reminder_bundle_manager_helper.h" -#include - namespace OHOS { namespace Notification { -inline std::string GetClientBundleNameByUid(int32_t callingUid) -{ - std::string bundle; - - std::shared_ptr bundleManager = ReminderBundleManagerHelper::GetInstance(); - if (bundleManager != nullptr) { - bundle = bundleManager->GetBundleNameByUid(callingUid); - } - - return bundle; -} - -inline std::string GetClientBundleName() -{ - return GetClientBundleNameByUid(IPCSkeleton::GetCallingUid()); -} - inline int64_t GetCurrentTime() { auto now = std::chrono::system_clock::now(); auto duration = std::chrono::duration_cast(now.time_since_epoch()); return duration.count(); } - } // namespace Notification } // namespace OHOS #endif \ No newline at end of file diff --git a/services/reminder/src/reminder_access_token_helper.cpp b/services/reminder/src/reminder_access_token_helper.cpp deleted file mode 100644 index 4410cb0e6d3005517d35c7921ea86c5653325c9c..0000000000000000000000000000000000000000 --- a/services/reminder/src/reminder_access_token_helper.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 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 "reminder_access_token_helper.h" - -#include "ans_log_wrapper.h" -#include "ipc_skeleton.h" -#include "tokenid_kit.h" -#include "reminder_utils.h" - -using namespace OHOS::Security::AccessToken; - -namespace OHOS { -namespace Notification { -bool ReminderAccessTokenHelper::IsSystemApp() -{ - AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); - ATokenTypeEnum type = AccessTokenKit::GetTokenTypeFlag(tokenId); - if (type == ATokenTypeEnum::TOKEN_HAP) { - uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); - if (Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { - return true; - } - } - return false; -} - -bool ReminderAccessTokenHelper::VerifyNativeToken(const AccessTokenID &callerToken) -{ - ATokenTypeEnum tokenType = AccessTokenKit::GetTokenTypeFlag(callerToken); - return (tokenType == ATokenTypeEnum::TOKEN_NATIVE); -} -} // namespace Notification -} // namespace OHOS diff --git a/services/reminder/src/reminder_agent_service.cpp b/services/reminder/src/reminder_agent_service.cpp index 99ff3881feb167fe7f016482e9bf8d041e42e853..b14966e5fd228cd9b0e886c6c5855ade52354df3 100644 --- a/services/reminder/src/reminder_agent_service.cpp +++ b/services/reminder/src/reminder_agent_service.cpp @@ -74,7 +74,7 @@ ErrCode ReminderAgentService::PublishReminder(const ReminderRequest& reminder, i return ERR_REMINDER_PERMISSION_DENIED; } int32_t callingUid = IPCSkeleton::GetCallingUid(); - std::string bundleName = GetClientBundleName(callingUid); + std::string bundleName = ReminderBundleManagerHelper::GetInstance().GetBundleNameByUid(callingUid); bool isAllowUseReminder = false; NotificationHelper::AllowUseReminder(bundleName, isAllowUseReminder); if (!isAllowUseReminder) { @@ -135,7 +135,7 @@ ErrCode ReminderAgentService::CancelAllReminders() return ERR_NO_INIT; } int32_t callingUid = IPCSkeleton::GetCallingUid(); - std::string bundleName = GetClientBundleName(callingUid); + std::string bundleName = ReminderBundleManagerHelper::GetInstance().GetBundleNameByUid(callingUid); int32_t userId = -1; AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); ErrCode ret = rdm->CancelAllReminders(bundleName, userId, callingUid); @@ -236,7 +236,7 @@ void ReminderAgentService::TryUnloadService() tryUnloadTask_ = nullptr; return; } - ANSR_LOGD("do unload task"); + ANSR_LOGD("call."); ChangeReminderAgentLoadConfig(REMINDER_AGENT_SERVICE_UNLOAD_STATE); auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrProxy == nullptr) { @@ -308,19 +308,14 @@ ErrCode ReminderAgentService::InitReminderRequest(sptr& reminde ANSR_LOGE("Failed to get active user id."); return ERR_REMINDER_INVALID_PARAM; } - std::shared_ptr bundleMgr = ReminderBundleManagerHelper::GetInstance(); - if (nullptr == bundleMgr) { - ANSR_LOGE("Failed to bundle manager."); - return ERR_REMINDER_INVALID_PARAM; - } std::string bundleName = bundle; int32_t uid = callingUid; if (wantAgentName != bundle && wantAgentName != "") { bundleName = wantAgentName; - uid = bundleMgr->GetDefaultUidByBundleName(bundleName, activeUserId); + uid = ReminderBundleManagerHelper::GetInstance().GetDefaultUidByBundleName(bundleName, activeUserId); } else if (maxWantAgentName != bundle && maxWantAgentName != "") { bundleName = maxWantAgentName; - uid = bundleMgr->GetDefaultUidByBundleName(bundleName, activeUserId); + uid = ReminderBundleManagerHelper::GetInstance().GetDefaultUidByBundleName(bundleName, activeUserId); } // Only system applications can proxy other applications to send notifications bool isSystemApp = IsSystemApp(); @@ -355,14 +350,4 @@ bool ReminderAgentService::IsSystemApp() uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId); } - -std::string ReminderAgentService::GetClientBundleName(const int32_t callingUid) -{ - std::string bundleName; - std::shared_ptr bundleMgr = ReminderBundleManagerHelper::GetInstance(); - if (bundleMgr != nullptr) { - bundleName = bundleMgr->GetBundleNameByUid(callingUid); - } - return bundleName; -} } // namespace OHOS::Notification diff --git a/services/reminder/src/reminder_bundle_manager_helper.cpp b/services/reminder/src/reminder_bundle_manager_helper.cpp index c9cb370236944ff18551197e482e28227d1bd731..b1430dc1b4fe5f0e6027a08aeb391d73bb93c039 100644 --- a/services/reminder/src/reminder_bundle_manager_helper.cpp +++ b/services/reminder/src/reminder_bundle_manager_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -15,34 +15,28 @@ #include "reminder_bundle_manager_helper.h" -#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" #include "iservice_registry.h" #include "os_account_manager.h" +#include "if_system_ability_manager.h" #include "system_ability_definition.h" -#include "ans_const_define.h" -#include "ans_log_wrapper.h" - -namespace OHOS { -namespace Notification { +namespace OHOS::Notification { ReminderBundleManagerHelper::ReminderBundleManagerHelper() { deathRecipient_ = new (std::nothrow) RemoteDeathRecipient(std::bind(&ReminderBundleManagerHelper::OnRemoteDied, this, std::placeholders::_1)); - if (deathRecipient_ == nullptr) { - ANS_LOGE("Failed to create RemoteDeathRecipient instance"); - } } ReminderBundleManagerHelper::~ReminderBundleManagerHelper() { - std::lock_guard lock(connectionMutex_); + std::lock_guard locker(mutex_); Disconnect(); } -void ReminderBundleManagerHelper::OnRemoteDied(const wptr &object) +void ReminderBundleManagerHelper::OnRemoteDied(const wptr& object) { - std::lock_guard lock(connectionMutex_); + std::lock_guard locker(mutex_); Disconnect(); } @@ -57,12 +51,10 @@ void ReminderBundleManagerHelper::Connect() if (systemAbilityManager == nullptr) { return; } - sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (remoteObject == nullptr) { return; } - bundleMgr_ = iface_cast(remoteObject); if (bundleMgr_ != nullptr) { bundleMgr_->AsObject()->AddDeathRecipient(deathRecipient_); @@ -77,50 +69,37 @@ void ReminderBundleManagerHelper::Disconnect() } } -std::string ReminderBundleManagerHelper::GetBundleNameByUid(int32_t uid) +std::string ReminderBundleManagerHelper::GetBundleNameByUid(const int32_t uid) { - std::string bundle; - - std::lock_guard lock(connectionMutex_); - + std::lock_guard locker(mutex_); Connect(); - + std::string bundle; if (bundleMgr_ != nullptr) { std::string identity = IPCSkeleton::ResetCallingIdentity(); bundleMgr_->GetNameForUid(uid, bundle); IPCSkeleton::SetCallingIdentity(identity); } - return bundle; } -int32_t ReminderBundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) +int32_t ReminderBundleManagerHelper::GetDefaultUidByBundleName(const std::string& bundle, const int32_t userId) { - int32_t uid = -1; - - std::lock_guard lock(connectionMutex_); - + std::lock_guard locker(mutex_); Connect(); - + int32_t uid = -1; if (bundleMgr_ != nullptr) { std::string identity = IPCSkeleton::ResetCallingIdentity(); uid = bundleMgr_->GetUidByBundleName(bundle, userId); - if (uid < 0) { - ANS_LOGW("get invalid uid of bundle %{public}s in userId %{public}d", bundle.c_str(), userId); - } IPCSkeleton::SetCallingIdentity(identity); } - return uid; } -bool ReminderBundleManagerHelper::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, - int32_t userId, AppExecFwk::BundleInfo &bundleInfo) +bool ReminderBundleManagerHelper::GetBundleInfo(const std::string& bundleName, const AppExecFwk::BundleFlag flag, + const int32_t userId, AppExecFwk::BundleInfo& bundleInfo) { - std::lock_guard lock(connectionMutex_); - + std::lock_guard locker(mutex_); Connect(); - if (bundleMgr_ == nullptr) { return false; } @@ -134,9 +113,9 @@ bool ReminderBundleManagerHelper::GetBundleInfo(const std::string &bundleName, c int32_t ReminderBundleManagerHelper::GetAppIndexByUid(const int32_t uid) { - int32_t appIndex = 0; - std::lock_guard lock(connectionMutex_); + std::lock_guard locker(mutex_); Connect(); + int32_t appIndex = 0; if (nullptr == bundleMgr_) { return appIndex; } @@ -146,6 +125,4 @@ int32_t ReminderBundleManagerHelper::GetAppIndexByUid(const int32_t uid) IPCSkeleton::SetCallingIdentity(identity); return appIndex; } - -} // namespace Notification -} // namespace OHOS +} // namespace OHOS::Notification diff --git a/services/reminder/src/reminder_config_change_observer.cpp b/services/reminder/src/reminder_config_change_observer.cpp deleted file mode 100644 index e0efc126f43ced17feba72877f0bc78fb9817cca..0000000000000000000000000000000000000000 --- a/services/reminder/src/reminder_config_change_observer.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 "reminder_config_change_observer.h" - -#include "ans_log_wrapper.h" -#include "reminder_data_manager.h" - -namespace OHOS { -namespace Notification { - -void ReminderConfigChangeObserver::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) -{ - ANSR_LOGD("OnConfigurationUpdated."); - auto reminderDataMgr = ReminderDataManager::GetInstance(); - if (reminderDataMgr == nullptr) { - ANSR_LOGW("Reminder data manager is nullptr"); - return; - } - std::string newLanguageInfo = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); - if (!newLanguageInfo.empty() && newLanguageInfo != languageInfo_) { - ANSR_LOGD("language change: %{public}s -> %{public}s", languageInfo_.c_str(), newLanguageInfo.c_str()); - reminderDataMgr->OnLanguageChanged(); - languageInfo_ = newLanguageInfo; - } -} - -} // namespace Notification -} // namespace OHOS diff --git a/services/reminder/src/reminder_data_manager.cpp b/services/reminder/src/reminder_data_manager.cpp index 50d44a7c4b319a420fcc10c5c87c4dcc5fb40da9..80ddf41c1a97ebaadf6d415a362d101341c05c5b 100644 --- a/services/reminder/src/reminder_data_manager.cpp +++ b/services/reminder/src/reminder_data_manager.cpp @@ -25,7 +25,6 @@ #include "ipc_skeleton.h" #include "notification_slot.h" #include "os_account_manager.h" -#include "reminder_os_account_manager_helper.h" #include "reminder_event_manager.h" #include "time_service_client.h" #include "singleton.h" @@ -617,7 +616,8 @@ std::shared_ptr ReminderDataManager::InitInstance() if (REMINDER_DATA_MANAGER == nullptr) { REMINDER_DATA_MANAGER = std::make_shared(); REMINDER_DATA_MANAGER->Init(); - ReminderEventManager reminderEventManager(REMINDER_DATA_MANAGER); + ReminderEventManager reminderEventManager; + reminderEventManager.Init(); } return REMINDER_DATA_MANAGER; } @@ -916,7 +916,7 @@ bool ReminderDataManager::ShouldAlert(const sptr &reminder) con } int32_t reminderId = reminder->GetReminderId(); int32_t userId = -1; - ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(reminder->GetUid(), userId); + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(reminder->GetUid(), userId); if (currentUserId_ != userId) { ANSR_LOGD("The reminder (reminderId=%{public}d) is silent for not in active user, " \ "current user id: %{private}d, reminder user id: %{private}d", reminderId, currentUserId_, userId); @@ -1461,7 +1461,7 @@ void ReminderDataManager::CheckReminderTime(std::vector>& void ReminderDataManager::InitUserId() { currentUserId_ = MAIN_USER_ID; - ReminderOsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(currentUserId_); + AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId_); } bool ReminderDataManager::RegisterConfigurationObserver() @@ -1520,7 +1520,7 @@ bool ReminderDataManager::CheckIsSameApp(const sptr &reminder, std::string bundleName = reminder->GetCreatorBundleName(); int32_t uid = reminder->GetCreatorUid(); if (uid == -1) { - uid = ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, reminder->GetUserId()); + uid = ReminderBundleManagerHelper::GetInstance().GetDefaultUidByBundleName(bundleName, reminder->GetUserId()); } return uid == callingUid; } @@ -1530,9 +1530,9 @@ bool ReminderDataManager::IsBelongToSameApp(const int32_t uidSrc, { bool result = uidSrc == uidTar; int32_t userIdSrc = -1; - ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uidSrc, userIdSrc); + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uidSrc, userIdSrc); int32_t userIdTar = -1; - ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uidTar, userIdTar); + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uidTar, userIdTar); result = result && (userIdSrc == userIdTar); return result; } @@ -1939,7 +1939,7 @@ void ReminderDataManager::ClickReminder(const OHOS::EventFwk::Want &want) abilityWant.SetElement(element); abilityWant.SetUri(wantInfo->uri); abilityWant.SetParams(wantInfo->parameters); - int32_t appIndex = ReminderBundleManagerHelper::GetInstance()->GetAppIndexByUid(reminder->GetUid()); + int32_t appIndex = ReminderBundleManagerHelper::GetInstance().GetAppIndexByUid(reminder->GetUid()); abilityWant.SetParam("ohos.extra.param.key.appCloneIndex", appIndex); auto client = AppExecFwk::AbilityManagerClient::GetInstance(); @@ -1958,7 +1958,7 @@ std::shared_ptr ReminderDataManager::GetResou const int32_t uid) { AppExecFwk::BundleInfo bundleInfo; - if (!ReminderBundleManagerHelper::GetInstance()->GetBundleInfo(bundleName, + if (!ReminderBundleManagerHelper::GetInstance().GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, uid, bundleInfo)) { ANSR_LOGE("GetBundleInfo[%{public}s][%{public}d] fail.", bundleName.c_str(), uid); return nullptr; diff --git a/services/reminder/src/reminder_datashare_helper.cpp b/services/reminder/src/reminder_datashare_helper.cpp index 66c2b07a384bcd09b482d527b6931dcb7a8f13f8..0ee797b433757087a7aa6c70dd3da761828242e2 100644 --- a/services/reminder/src/reminder_datashare_helper.cpp +++ b/services/reminder/src/reminder_datashare_helper.cpp @@ -185,9 +185,9 @@ void ReminderDataShareHelper::StartDataExtension(const int32_t reason) void ReminderDataShareHelper::UpdateCalendarUid() { - uid_ = ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(ReminderCalendarShareTable::NAME, + uid_ = ReminderBundleManagerHelper::GetInstance().GetDefaultUidByBundleName(ReminderCalendarShareTable::NAME, curUserId_); - dataUid_ = ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName( + dataUid_ = ReminderBundleManagerHelper::GetInstance().GetDefaultUidByBundleName( ReminderCalendarShareTable::DATA_NAME, curUserId_); } diff --git a/services/reminder/src/reminder_event_manager.cpp b/services/reminder/src/reminder_event_manager.cpp index 89aab69764e212234483a6faf3531606c443baa8..abe7dfd409a8d2f2649e53f2946dbda20dca88b5 100644 --- a/services/reminder/src/reminder_event_manager.cpp +++ b/services/reminder/src/reminder_event_manager.cpp @@ -16,34 +16,32 @@ #include "reminder_event_manager.h" #include "ans_log_wrapper.h" -#include "bundle_constants.h" -#include "bundle_mgr_interface.h" -#include "common_event_manager.h" -#include "common_event_support.h" +#include "reminder_data_manager.h" #include "reminder_bundle_manager_helper.h" -#include "if_system_ability_manager.h" + #include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" #include "notification_helper.h" -#include "string_ex.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "system_ability_definition.h" +#include "if_system_ability_manager.h" -using namespace OHOS::EventFwk; -namespace OHOS { -namespace Notification { -static const std::string NOTIFICATION_LABEL = "REMINDER_AGENT"; -static constexpr const char* UNLOCK_SCREEN_EVENT = "common.event.UNLOCK_SCREEN"; -std::shared_ptr ReminderEventManager::subscriber_ - = nullptr; +namespace OHOS::Notification { +namespace { +constexpr const char* UNLOCK_SCREEN_EVENT = "common.event.UNLOCK_SCREEN"; +} -ReminderEventManager::ReminderEventManager(std::shared_ptr &reminderDataManager) +void ReminderEventManager::Init() { - init(reminderDataManager); + SubscribeEvent(); + SubscribeSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + SubscribeSystemAbility(APP_MGR_SERVICE_ID); + SubscribeSystemAbility(ABILITY_MGR_SERVICE_ID); } -void ReminderEventManager::init(std::shared_ptr &reminderDataManager) const +void ReminderEventManager::SubscribeEvent() { - MatchingSkills customMatchingSkills; + EventFwk::MatchingSkills customMatchingSkills; customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); @@ -51,223 +49,177 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION); customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT); customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLICK_ALERT); - CommonEventSubscribeInfo customSubscriberInfo(customMatchingSkills); + EventFwk::CommonEventSubscribeInfo customSubscriberInfo(customMatchingSkills); customSubscriberInfo.SetPermission("ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); customSubscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); - auto customSubscriber = std::make_shared(customSubscriberInfo, reminderDataManager); - - MatchingSkills matchingSkills; - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIME_CHANGED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); - CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto customSubscriber = std::make_shared(customSubscriberInfo); + + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); - auto subscriber = std::make_shared(subscriberInfo, reminderDataManager); + auto subscriber = std::make_shared(subscriberInfo); - MatchingSkills screenMatchingSkills; + EventFwk::MatchingSkills screenMatchingSkills; screenMatchingSkills.AddEvent(UNLOCK_SCREEN_EVENT); - CommonEventSubscribeInfo screenSubscriberInfo(screenMatchingSkills); + EventFwk::CommonEventSubscribeInfo screenSubscriberInfo(screenMatchingSkills); screenSubscriberInfo.SetPublisherBundleName(AppExecFwk::Constants::SCENE_BOARD_BUNDLE_NAME); - auto screenSubscriber = std::make_shared(screenSubscriberInfo, reminderDataManager); + auto screenSubscriber = std::make_shared(screenSubscriberInfo); std::string identity = IPCSkeleton::ResetCallingIdentity(); - if (CommonEventManager::SubscribeCommonEvent(subscriber) && - CommonEventManager::SubscribeCommonEvent(customSubscriber) && - CommonEventManager::SubscribeCommonEvent(screenSubscriber)) { - ANSR_LOGD("SubscribeCommonEvent ok"); + if (EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber) && + EventFwk::CommonEventManager::SubscribeCommonEvent(customSubscriber) && + EventFwk::CommonEventManager::SubscribeCommonEvent(screenSubscriber)) { + ANSR_LOGD("SubscribeCommonEvent ok."); } else { - ANSR_LOGD("SubscribeCommonEvent fail"); + ANSR_LOGW("SubscribeCommonEvent failed."); } IPCSkeleton::SetCallingIdentity(identity); - subscriber_ = std::make_shared(reminderDataManager); - if (NotificationHelper::SubscribeNotification(*subscriber_) != ERR_OK) { - ANSR_LOGD("SubscribeNotification failed"); + auto notificationSubscriber = std::make_shared(); + if (NotificationHelper::SubscribeNotification(*notificationSubscriber) != ERR_OK) { + ANSR_LOGW("SubscribeNotification failed."); } - - SubscribeSystemAbility(reminderDataManager); } -void ReminderEventManager::SubscribeSystemAbility(std::shared_ptr &reminderDataManager) const +void ReminderEventManager::SubscribeSystemAbility(const int32_t systemAbilityId) { sptr statusChangeListener - = new (std::nothrow) SystemAbilityStatusChangeListener(reminderDataManager); + = new (std::nothrow) SystemAbilityStatusChangeListener(); if (statusChangeListener == nullptr) { - ANSR_LOGE("Failed to create statusChangeListener due to no memory."); - return; - } - // app mgr - sptr appMgrStatusChangeListener - = new (std::nothrow) SystemAbilityStatusChangeListener(reminderDataManager); - if (appMgrStatusChangeListener == nullptr) { - ANSR_LOGE("Failed to create appMgrStatusChangeListener due to no memory."); - return; - } - // ability mgr - sptr abilityMgrStatusListener - = new (std::nothrow) SystemAbilityStatusChangeListener(reminderDataManager); - if (abilityMgrStatusListener == nullptr) { - ANSR_LOGE("Failed to create abilityMgrStatusListener due to no memory."); + ANSR_LOGW("Failed to create SystemAbilityStatusChangeListener."); return; } - sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrProxy == nullptr) { - ANSR_LOGD("samgrProxy is null"); + ANSR_LOGW("GetSystemAbilityManager failed."); return; } - int32_t ret = samgrProxy->SubscribeSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, statusChangeListener); - if (ret != ERR_OK) { - ANSR_LOGE("subscribe system ability id: %{public}d failed", BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - } - ret = samgrProxy->SubscribeSystemAbility(APP_MGR_SERVICE_ID, appMgrStatusChangeListener); - if (ret != ERR_OK) { - ANSR_LOGE("subscribe system ability id: %{public}d failed", APP_MGR_SERVICE_ID); - } - ret = samgrProxy->SubscribeSystemAbility(ABILITY_MGR_SERVICE_ID, abilityMgrStatusListener); + int32_t ret = samgrProxy->SubscribeSystemAbility(systemAbilityId, statusChangeListener); if (ret != ERR_OK) { - ANSR_LOGE("subscribe system ability id: %{public}d failed", ABILITY_MGR_SERVICE_ID); + ANSR_LOGW("SubscribeSystemAbility id: %{public}d failed.", systemAbilityId); } } ReminderEventManager::ReminderEventSubscriber::ReminderEventSubscriber( - const CommonEventSubscribeInfo &subscriberInfo, - std::shared_ptr &reminderDataManager) : CommonEventSubscriber(subscriberInfo) -{ - reminderDataManager_ = reminderDataManager; -} - -ReminderEventManager::ReminderEventCustomSubscriber::ReminderEventCustomSubscriber( - const CommonEventSubscribeInfo &subscriberInfo, - std::shared_ptr &reminderDataManager) : CommonEventSubscriber(subscriberInfo) -{ - reminderDataManager_ = reminderDataManager; -} + const EventFwk::CommonEventSubscribeInfo& subscriberInfo) : CommonEventSubscriber(subscriberInfo) +{} -void ReminderEventManager::ReminderEventCustomSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) +void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& data) { - Want want = data.GetWant(); + auto manager = ReminderDataManager::GetInstance(); + if (manager == nullptr) { + return; + } + EventFwk::Want want = data.GetWant(); std::string action = want.GetAction(); - ANSR_LOGI("Recieved common event:%{public}s", action.c_str()); - if (action == ReminderRequest::REMINDER_EVENT_ALARM_ALERT) { - reminderDataManager_->ShowActiveReminder(want); + ANSR_LOGD("Recieved common event:%{public}s.", action.c_str()); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || + action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED) { + AppExecFwk::ElementName ele = want.GetElement(); + std::string bundleName = ele.GetBundleName(); + int32_t userId = want.GetIntParam(AppExecFwk::Constants::USER_ID, -1); + int32_t uid = want.GetIntParam(AppExecFwk::Constants::UID, -1); + manager->CancelAllReminders(bundleName, userId, uid); return; } - if (action == ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT) { - reminderDataManager_->TerminateAlerting(want); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED) { + AppExecFwk::ElementName ele = want.GetElement(); + std::string bundleName = ele.GetBundleName(); + int32_t userId = want.GetIntParam(AppExecFwk::Constants::USER_ID, -1); + int32_t uid = ReminderBundleManagerHelper::GetInstance().GetDefaultUidByBundleName(bundleName, userId); + manager->OnProcessDiedLocked(uid); return; } - if (action == ReminderRequest::REMINDER_EVENT_CLOSE_ALERT) { - reminderDataManager_->CloseReminder(want, true); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED) { + manager->RefreshRemindersDueToSysTimeChange(ReminderDataManager::TIME_ZONE_CHANGE); return; } - if (action == ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT) { - reminderDataManager_->SnoozeReminder(want); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED) { + manager->RefreshRemindersDueToSysTimeChange(ReminderDataManager::DATE_TIME_CHANGE); return; } - if (action == ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT) { - reminderDataManager_->HandleCustomButtonClick(want); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { + manager->OnUserSwitch(data.GetCode()); return; } - if (action == ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION) { - reminderDataManager_->CloseReminder(want, false, false); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { + manager->OnUserRemove(data.GetCode()); return; } - if (action == ReminderRequest::REMINDER_EVENT_CLICK_ALERT) { - reminderDataManager_->ClickReminder(want); + if (action.compare(UNLOCK_SCREEN_EVENT) == 0) { + manager->OnUnlockScreen(); return; } } -void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) +ReminderEventManager::ReminderCustomEventSubscriber::ReminderCustomEventSubscriber( + const EventFwk::CommonEventSubscribeInfo& subscriberInfo) : CommonEventSubscriber(subscriberInfo) +{} + +void ReminderEventManager::ReminderCustomEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& data) { - Want want = data.GetWant(); - std::string action = want.GetAction(); - ANSR_LOGD("Recieved common event:%{public}s", action.c_str()); - if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { - HandlePackageRemove(want); + auto manager = ReminderDataManager::GetInstance(); + if (manager == nullptr) { return; } - if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED) { - HandlePackageRemove(want); + EventFwk::Want want = data.GetWant(); + std::string action = want.GetAction(); + ANSR_LOGI("Recieved common event:%{public}s.", action.c_str()); + if (action == ReminderRequest::REMINDER_EVENT_ALARM_ALERT) { + manager->ShowActiveReminder(want); return; } - if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED) { - HandleProcessDied(want); + if (action == ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT) { + manager->TerminateAlerting(want); return; } - if (action == CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED) { - reminderDataManager_->RefreshRemindersDueToSysTimeChange(ReminderDataManager::TIME_ZONE_CHANGE); + if (action == ReminderRequest::REMINDER_EVENT_CLOSE_ALERT) { + manager->CloseReminder(want, true); return; } - if (action == CommonEventSupport::COMMON_EVENT_TIME_CHANGED) { - reminderDataManager_->RefreshRemindersDueToSysTimeChange(ReminderDataManager::DATE_TIME_CHANGE); + if (action == ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT) { + manager->SnoozeReminder(want); return; } - if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { - reminderDataManager_->OnUserSwitch(data.GetCode()); + if (action == ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT) { + manager->HandleCustomButtonClick(want); return; } - if (action == CommonEventSupport::COMMON_EVENT_USER_REMOVED) { - reminderDataManager_->OnUserRemove(data.GetCode()); + if (action == ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION) { + manager->CloseReminder(want, false, false); return; } - if (action.compare(UNLOCK_SCREEN_EVENT) == 0) { - reminderDataManager_->OnUnlockScreen(); + if (action == ReminderRequest::REMINDER_EVENT_CLICK_ALERT) { + manager->ClickReminder(want); + return; } } -void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(const EventFwk::Want &want) const -{ - OHOS::AppExecFwk::ElementName ele = want.GetElement(); - std::string bundleName = ele.GetBundleName(); - int32_t userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); - int32_t uid = want.GetIntParam(OHOS::AppExecFwk::Constants::UID, -1); - reminderDataManager_->CancelAllReminders(bundleName, userId, uid); -} - -void ReminderEventManager::ReminderEventSubscriber::HandleProcessDied(const EventFwk::Want &want) const -{ - int32_t uid = GetUid(want); - reminderDataManager_->OnProcessDiedLocked(uid); -} - -int32_t ReminderEventManager::ReminderEventSubscriber::GetUid( - const OHOS::EventFwk::Want &want) const -{ - OHOS::AppExecFwk::ElementName ele = want.GetElement(); - std::string bundleName = ele.GetBundleName(); - int32_t userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); - int32_t uid = ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, userId); - ANSR_LOGD("bundleName=%{public}s, userId=%{private}d, uid=%{public}d", bundleName.c_str(), userId, uid); - return uid; -} - -ReminderEventManager::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener( - std::shared_ptr &reminderDataManager) -{ - reminderDataManager_ = reminderDataManager; -} - void ReminderEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility( int32_t systemAbilityId, const std::string& deviceId) { - ANSR_LOGD("OnAddSystemAbilityInner"); + auto manager = ReminderDataManager::GetInstance(); + if (manager == nullptr) { + return; + } switch (systemAbilityId) { case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: - ANSR_LOGD("OnAddSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); - reminderDataManager_->OnBundleMgrServiceStart(); + ANSR_LOGD("AddSystemAbility: BUNDLE_MGR_SERVICE_SYS_ABILITY_ID."); + manager->OnBundleMgrServiceStart(); break; case APP_MGR_SERVICE_ID: - ANSR_LOGD("OnAddSystemAbilityInner: APP_MGR_SERVICE"); + ANSR_LOGD("AddSystemAbility: APP_MGR_SERVICE_ID."); break; case ABILITY_MGR_SERVICE_ID: - ANSR_LOGD("OnAddSystemAbilityInner ABILITY_MGR_SERVICE_ID"); - reminderDataManager_->OnAbilityMgrServiceStart(); + ANSR_LOGD("AddSystemAbility ABILITY_MGR_SERVICE_ID."); + manager->OnAbilityMgrServiceStart(); break; default: break; @@ -277,38 +229,29 @@ void ReminderEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility void ReminderEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( int32_t systemAbilityId, const std::string& deviceId) { - ANSR_LOGD("OnRemoveSystemAbilityInner"); + auto manager = ReminderDataManager::GetInstance(); + if (manager == nullptr) { + return; + } switch (systemAbilityId) { case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: - ANSR_LOGD("OnRemoveSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); + ANSR_LOGD("RemoveSystemAbility: BUNDLE_MGR_SERVICE_SYS_ABILITY_ID."); break; case APP_MGR_SERVICE_ID: - ANSR_LOGD("OnRemoveSystemAbilityInner: APP_MGR_SERVICE"); - reminderDataManager_->OnRemoveAppMgr(); + ANSR_LOGD("RemoveSystemAbility: APP_MGR_SERVICE_ID."); + manager->OnRemoveAppMgr(); break; case ABILITY_MGR_SERVICE_ID: - ANSR_LOGD("OnRemoveSystemAbilityInner ABILITY_MGR_SERVICE_ID"); + ANSR_LOGD("RemoveSystemAbility ABILITY_MGR_SERVICE_ID."); break; default: break; } } -ReminderEventManager::ReminderNotificationSubscriber::ReminderNotificationSubscriber( - std::shared_ptr &reminderDataManager) -{ - reminderDataManager_ = reminderDataManager; -} - -ReminderEventManager::ReminderNotificationSubscriber::~ReminderNotificationSubscriber() {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnConnected() {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnDisconnected() {} - void ReminderEventManager::ReminderNotificationSubscriber::OnCanceled( - const std::shared_ptr ¬ification, - const std::shared_ptr &sortingMap, int deleteReason) + const std::shared_ptr& notification, + const std::shared_ptr& sortingMap, int deleteReason) { // Note: Don't modify param notification if (deleteReason != NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE) { @@ -320,40 +263,30 @@ void ReminderEventManager::ReminderNotificationSubscriber::OnCanceled( NotificationRequest request = notification->GetNotificationRequest(); std::string label = request.GetLabel(); int64_t autoDeletedTime = request.GetAutoDeletedTime(); - if (autoDeletedTime <= 0 || label != NOTIFICATION_LABEL) { + if (autoDeletedTime <= 0 || label.compare(ReminderRequest::NOTIFICATION_LABEL) != 0) { return; } - if (reminderDataManager_ == nullptr) { + auto manager = ReminderDataManager::GetInstance(); + if (manager == nullptr) { return; } int32_t notificationId = request.GetNotificationId(); int32_t uid = request.GetOwnerUid() == 0 ? request.GetCreatorUid() : request.GetOwnerUid(); - reminderDataManager_->HandleAutoDeleteReminder(notificationId, uid, autoDeletedTime); + manager->HandleAutoDeleteReminder(notificationId, uid, autoDeletedTime); } -void ReminderEventManager::ReminderNotificationSubscriber::OnConsumed(const std::shared_ptr ¬ification, - const std::shared_ptr &sortingMap) {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnUpdate( - const std::shared_ptr &sortingMap) {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnDied() {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnDoNotDisturbDateChange( - const std::shared_ptr &date) {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnEnabledNotificationChanged( - const std::shared_ptr &callbackData) {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnBadgeChanged( - const std::shared_ptr &badgeData) {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnBadgeEnabledChanged( - const sptr &callbackData) {} - -void ReminderEventManager::ReminderNotificationSubscriber::OnBatchCanceled( - const std::vector> &requestList, - const std::shared_ptr &sortingMap, int32_t deleteReason) {} -} // namespace OHOS -} // namespace Notification +void ReminderConfigChangeObserver::OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) +{ + auto manager = ReminderDataManager::GetInstance(); + if (manager == nullptr) { + return; + } + std::string newLanguageInfo = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); + if (!newLanguageInfo.empty() && newLanguageInfo != languageInfo_) { + ANSR_LOGD("Language change: %{public}s -> %{public}s.", languageInfo_.c_str(), newLanguageInfo.c_str()); + manager->OnLanguageChanged(); + languageInfo_ = newLanguageInfo; + } +} +} // namespace OHOS::Notification diff --git a/services/reminder/src/reminder_os_account_manager_helper.cpp b/services/reminder/src/reminder_os_account_manager_helper.cpp deleted file mode 100644 index f0abf089f66d804a9cfee6581548d9c7cd4fa3d3..0000000000000000000000000000000000000000 --- a/services/reminder/src/reminder_os_account_manager_helper.cpp +++ /dev/null @@ -1,53 +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. - */ - -#include "reminder_os_account_manager_helper.h" -#include "ans_log_wrapper.h" -#include "ans_inner_errors.h" -#include "errors.h" -#include "ipc_skeleton.h" - -#include "os_account_constants.h" -#include "os_account_info.h" -#include "os_account_manager.h" -#include - -namespace OHOS { -namespace Notification { -ReminderOsAccountManagerHelper &ReminderOsAccountManagerHelper::GetInstance() -{ - return DelayedRefSingleton::GetInstance(); -} -ErrCode ReminderOsAccountManagerHelper::GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &userId) -{ - int32_t ret = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); - if (ret != ERR_OK) { - ANS_LOGE("Get userId failed, uid = <%{public}d>, code is %{public}d", uid, ret); - return ret; - } - ANS_LOGD("Get userId Success, uid = <%{public}d> userId = <%{public}d>", uid, userId); - return ret; -} - -ErrCode ReminderOsAccountManagerHelper::GetCurrentActiveUserId(int32_t &id) -{ - int32_t ret = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(id); - if (ret != ERR_OK) { - ANS_LOGE("Failed to call OsAccountManager::GetForegroundOsAccountLocalId, code is %{public}d", ret); - } - return ret; -} -} -} diff --git a/services/reminder/test/unittest/BUILD.gn b/services/reminder/test/unittest/BUILD.gn index 9f1f4990a09ffbbde7102fb4a9087dabb63b6e4a..d0aa6c25f9e5c212549a9e6c04c466698c5defe1 100644 --- a/services/reminder/test/unittest/BUILD.gn +++ b/services/reminder/test/unittest/BUILD.gn @@ -31,8 +31,6 @@ ohos_unittest("reminder_unit_test") { defines = [] sources = [ - "mock/mock_access_token_helper.cpp", - "mock/mock_bundle_manager_helper.cpp", "mock/mock_ipc.cpp", "reminder_data_manager_test.cpp", ] @@ -169,80 +167,34 @@ ohos_unittest("reminder_agent_service_test") { part_name = "${component_name}" } -ohos_unittest("reminder_access_token_helper_test") { - module_out_path = module_output_path - include_dirs = [ - ".", - "include", - "/${services_path}/reminder/include", - "${services_path}/reminder/test/unittest/mock/include", - ] - - sources = [ - "${services_path}/reminder/src/reminder_access_token_helper.cpp", - "${services_path}/reminder/test/unittest/mock/mock_accesstoken_kit.cpp", - "access_token_helper_test/access_token_helper_test.cpp", - ] - - deps = [ "${frameworks_module_reminder_path}:reminder_innerkits" ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "access_token:libtokenid_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hitrace:hitrace_meter", - "hitrace:libhitracechain", - "image_framework:image_native", - "init:libbegetutil", - "ipc:ipc_core", - "kv_store:distributeddata_inner", - "os_account:os_account_innerkits", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "time_service:time_client", - ] - - if (player_framework) { - external_deps += [ "player_framework:media_client" ] - defines = [ "PLAYER_FRAMEWORK_ENABLE" ] +ohos_unittest("reminder_event_manager_test") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false } - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - -ohos_unittest("reminder_bundle_manager_helper_branch_test") { module_out_path = module_output_path include_dirs = [ ".", "include", "/${services_path}/reminder/include", "${services_path}/reminder/test/unittest/mock/include", - "bundle_manager_helper_branch_test/include", ] sources = [ - "bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp", - "bundle_manager_helper_branch_test/mock_service_registry.cpp", + "${services_path}/reminder/src/reminder_event_manager.cpp", + "mock/mock_notification_helper.cpp", + "mock/mock_reminder_bundle_manager_helper.cpp", + "mock/mock_reminder_data_manager.cpp", + "reminder_event_manager_test.cpp", ] deps = [ + "${frameworks_module_ans_path}:ans_innerkits", "${frameworks_module_reminder_path}:reminder_innerkits", - "${services_path}/reminder:libreminder", ] external_deps = [ @@ -252,15 +204,19 @@ ohos_unittest("reminder_bundle_manager_helper_branch_test") { "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "hitrace:libhitracechain", "image_framework:image_native", + "init:libbegetutil", "ipc:ipc_core", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", @@ -270,10 +226,6 @@ ohos_unittest("reminder_bundle_manager_helper_branch_test") { "time_service:time_client", ] - if (player_framework) { - external_deps += [ "player_framework:media_client" ] - defines = [ "PLAYER_FRAMEWORK_ENABLE" ] - } cflags = [ "-Dprivate=public", "-Dprotected=public", @@ -282,7 +234,15 @@ ohos_unittest("reminder_bundle_manager_helper_branch_test") { part_name = "${component_name}" } -ohos_unittest("reminder_os_account_manager_helper_test") { +ohos_unittest("reminder_bundle_manager_helper_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 = [ ".", @@ -291,7 +251,10 @@ ohos_unittest("reminder_os_account_manager_helper_test") { "${services_path}/reminder/test/unittest/mock/include", ] - sources = [ "os_account_manager_helper_test.cpp" ] + sources = [ + "mock/mock_service_registry.cpp", + "reminder_bundle_manager_helper_test.cpp", + ] deps = [ "${frameworks_module_reminder_path}:reminder_innerkits", @@ -323,10 +286,6 @@ ohos_unittest("reminder_os_account_manager_helper_test") { "time_service:time_client", ] - if (player_framework) { - external_deps += [ "player_framework:media_client" ] - defines = [ "PLAYER_FRAMEWORK_ENABLE" ] - } cflags = [ "-Dprivate=public", "-Dprotected=public", @@ -355,10 +314,7 @@ ohos_unittest("reminder_service_test") { defines = [] sources = [ - "mock/mock_access_token_helper.cpp", "mock/mock_accesstoken_kit.cpp", - "mock/mock_bundle_manager_helper.cpp", - "mock/mock_bundle_mgr.cpp", "mock/mock_ipc.cpp", "mock/mock_os_account_manager.cpp", "reminder_store_test.cpp", @@ -514,11 +470,10 @@ ohos_unittest("reminder_agent_service_ability_test") { group("unittest") { testonly = true deps = [ - ":reminder_access_token_helper_test", ":reminder_agent_service_ability_test", ":reminder_agent_service_test", - ":reminder_bundle_manager_helper_branch_test", - ":reminder_os_account_manager_helper_test", + ":reminder_bundle_manager_helper_test", + ":reminder_event_manager_test", ":reminder_service_test", ":reminder_unit_test", ] diff --git a/services/reminder/test/unittest/access_token_helper_test/access_token_helper_test.cpp b/services/reminder/test/unittest/access_token_helper_test/access_token_helper_test.cpp deleted file mode 100644 index 0109d29ad0b7b511ad19dc467cfb03e82c675241..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/access_token_helper_test/access_token_helper_test.cpp +++ /dev/null @@ -1,90 +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. - */ - -#include -#include -#include "accesstoken_kit.h" -#include "reminder_access_token_helper.h" -#include "ans_log_wrapper.h" -#include "ipc_skeleton.h" -#include "mock_accesstoken_kit.h" -using namespace testing::ext; -using namespace OHOS::Security::AccessToken; - -namespace OHOS { -namespace Notification { -class AccessTokenHelperTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - - std::shared_ptr stub_; -}; - -void AccessTokenHelperTest::SetUpTestCase() -{ -} - -void AccessTokenHelperTest::TearDownTestCase() -{ -} - -void AccessTokenHelperTest::SetUp() -{ - stub_ = std::make_shared(); -} - -void AccessTokenHelperTest::TearDown() -{ -} - -/** - * @tc.number : AccessTokenHelperTest - * @tc.name : VerifyNativeToken_00100 - * @tc.desc : VerifyNativeToken success - */ -HWTEST_F(AccessTokenHelperTest, VerifyNativeToken_00100, Function | SmallTest | Level1) -{ - AccessTokenID tokenID = 0; - MockAccesstokenKit::MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - EXPECT_TRUE(stub_->VerifyNativeToken(tokenID)); -} - -/** - * @tc.number : AccessTokenHelperTest - * @tc.name : IsSystemApp_00100 - * @tc.desc : IsSystemApp Token Type TOKEN_NATIVE - */ -HWTEST_F(AccessTokenHelperTest, IsSystemApp_00100, Function | SmallTest | Level1) -{ - MockAccesstokenKit::MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - EXPECT_FALSE(stub_->IsSystemApp()); -} - -/** - * @tc.number : AccessTokenHelperTest - * @tc.name : IsSystemApp_00200 - * @tc.desc : IsSystemApp Token Type TOKEN_HAP - */ -HWTEST_F(AccessTokenHelperTest, IsSystemApp_00200, Function | SmallTest | Level1) -{ - MockAccesstokenKit::MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - EXPECT_TRUE(stub_->IsSystemApp()); -} - -} // namespace Notification -} // namespace OHOS diff --git a/services/reminder/test/unittest/bundle_manager_helper_test.cpp b/services/reminder/test/unittest/bundle_manager_helper_test.cpp deleted file mode 100644 index 54d4cc3113e38a607aa43a95ff70eab61b272a37..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/bundle_manager_helper_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021-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 -#include - -#include "reminder_bundle_manager_helper.h" - -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -using namespace testing::ext; -namespace OHOS { -namespace Notification { -class BundleManagerHelperTest : public testing::Test { -public: - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number : BundleManagerHelperTest_00100 - * @tc.name : ANS_GetBundleNameByUid_0100 - * @tc.desc : Test GetBundleNameByUid function - */ -HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00100, Function | SmallTest | Level1) -{ - pid_t callingUid = IPCSkeleton::GetCallingUid(); - std::shared_ptr bundleManager = ReminderBundleManagerHelper::GetInstance(); - ASSERT_EQ(bundleManager->GetBundleNameByUid(callingUid), "bundleName"); -} - -} // namespace Notification -} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/include/mock_bundle_mgr.h b/services/reminder/test/unittest/mock/include/mock_bundle_mgr.h deleted file mode 100644 index 3d94cc6651f691a8352964cf5c697494d652ddd1..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/mock/include/mock_bundle_mgr.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023-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 BASE_NOTIFICATION_MOCK_BUNDLE_MANAGER_H -#define BASE_NOTIFICATION_MOCK_BUNDLE_MANAGER_H - -#include "bundle_info.h" -#include "iremote_proxy.h" -#include "bundle_mgr_interface.h" - -namespace OHOS { -class MockBundleMgr { -public: - static void MockIsNonBundleName(bool isNonBundleName); - static void MockDistributedNotificationEnabled(bool isNonBundleName); -}; - -namespace AppExecFwk { -class BundleMgrProxy : public IRemoteProxy { -public: - explicit BundleMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} - virtual ~BundleMgrProxy() {} - - ErrCode GetNameForUid(const int uid, std::string &name) override; - bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, - BundleInfo &bundleInfo, int32_t userId) override; - int GetUidByBundleName(const std::string &bundleName, const int userId) override; - bool GetApplicationInfo( - const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) override; -}; -} // namespace AppExecFwk -} // namespace OHOS - -#endif // MOCK_OHOS_EDM_MOCK_BUNDLE_MANAGER_H diff --git a/services/reminder/test/unittest/mock/include/mock_notification_helper.h b/services/reminder/test/unittest/mock/include/mock_notification_helper.h index 802fe8c38ab376c613a1b823e1269f6e052f74eb..bb1e992d14b49552ba197013225c5e4aa3c19c17 100644 --- a/services/reminder/test/unittest/mock/include/mock_notification_helper.h +++ b/services/reminder/test/unittest/mock/include/mock_notification_helper.h @@ -23,6 +23,8 @@ class MockNotificationHelper { public: static void MockIsAllowUseReminder(const bool isAllowUseReminder); static void MockIsAllowedNotify(const bool isAllowedNotify, const int32_t ret); + static void MockSubscribeNotification(const int32_t ret); + static void MockSubscribeCommonEvent(const bool ret); }; } // namespace OHOS::Notification diff --git a/services/reminder/test/unittest/bundle_manager_helper_branch_test/include/mock_service_registry.h b/services/reminder/test/unittest/mock/include/mock_service_registry.h old mode 100755 new mode 100644 similarity index 62% rename from services/reminder/test/unittest/bundle_manager_helper_branch_test/include/mock_service_registry.h rename to services/reminder/test/unittest/mock/include/mock_service_registry.h index f8b73331204058fe507aedf629c3a0157c9c3477..59c88531dd26c59d516a7f7d13167cf552247a1b --- a/services/reminder/test/unittest/bundle_manager_helper_branch_test/include/mock_service_registry.h +++ b/services/reminder/test/unittest/mock/include/mock_service_registry.h @@ -1,28 +1,24 @@ -/* - * 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 BASE_NOTIFICATION_MOCK_ISERVICE_REGISTRY_H -#define BASE_NOTIFICATION_MOCK_ISERVICE_REGISTRY_H -#include "iservice_registry.h" - -#include "ipc_skeleton.h" -#include "iremote_object.h" -namespace OHOS { -class MockServiceRegistry { -public: - static void MockGetSystemAbilityManager(bool mockRet); -}; - -} // namespace OHOS -#endif +/* + * Copyright (c) 2024-2025 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 BASE_NOTIFICATION_REMINDER_MOCK_ISERVICE_REGISTRY_H +#define BASE_NOTIFICATION_REMINDER_MOCK_ISERVICE_REGISTRY_H + +namespace OHOS::Notification { +class MockServiceRegistry { +public: + static void MockGetSystemAbilityManager(const bool ret); +}; +} // namespace OHOS::Notification +#endif diff --git a/services/reminder/test/unittest/mock/mock_access_token_helper.cpp b/services/reminder/test/unittest/mock/mock_access_token_helper.cpp deleted file mode 100644 index 5bc5dfd6099b8cd1db065db06523b9892652046f..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/mock/mock_access_token_helper.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2022 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 "reminder_access_token_helper.h" -#include "reminder_ut_constant.h" -#include "ipc_skeleton.h" - -namespace OHOS { -namespace Notification { - -bool ReminderAccessTokenHelper::VerifyNativeToken(const Security::AccessToken::AccessTokenID &callerToken) -{ - return callerToken == NATIVE_TOKEN; -} - -bool ReminderAccessTokenHelper::IsSystemApp() -{ - Security::AccessToken::AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); - if (tokenId == NATIVE_TOKEN) { - return true; - } - return false; -} - -} // namespace Notification -} // namespace OHOS \ No newline at end of file diff --git a/services/reminder/test/unittest/mock/mock_bundle_manager_helper.cpp b/services/reminder/test/unittest/mock/mock_bundle_manager_helper.cpp deleted file mode 100644 index 96f711816bb104d8025287260359e10db15c850b..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/mock/mock_bundle_manager_helper.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "reminder_bundle_manager_helper.h" - -#include "reminder_ut_constant.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace Notification { -ReminderBundleManagerHelper::ReminderBundleManagerHelper() -{} - -ReminderBundleManagerHelper::~ReminderBundleManagerHelper() -{} - -void ReminderBundleManagerHelper::OnRemoteDied(const wptr &object) -{} - -std::string ReminderBundleManagerHelper::GetBundleNameByUid(int uid) -{ - return (uid == NON_BUNDLE_NAME_UID) ? "" : "bundleName"; -} - -int ReminderBundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) -{ - if (userId == 0) { - return -1; - } else { - return NON_SYSTEM_APP_UID; - } -} - -void ReminderBundleManagerHelper::Connect() -{} - -void ReminderBundleManagerHelper::Disconnect() -{} - -} // namespace Notification -} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/mock_bundle_mgr.cpp b/services/reminder/test/unittest/mock/mock_bundle_mgr.cpp deleted file mode 100644 index f07f45d2e77a8ebc587ddfbe2b121c68ccf2e16b..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/mock/mock_bundle_mgr.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2023-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 "mock_bundle_mgr.h" - -#include -#include -#include "reminder_ut_constant.h" -namespace { -bool g_isNonBundleName = false; -bool g_isEnable = true; -} - -namespace OHOS { - -void MockBundleMgr::MockIsNonBundleName(bool isNonBundleName) -{ - g_isNonBundleName = isNonBundleName; -} - -void MockBundleMgr::MockDistributedNotificationEnabled(bool isEnable) -{ - g_isEnable = isEnable; -} -namespace AppExecFwk { -ErrCode BundleMgrProxy::GetNameForUid(const int uid, std::string &name) -{ - name = g_isNonBundleName ? "": "bundleName"; - return ERR_OK; -} - -bool BundleMgrProxy::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, - int32_t userId) -{ - return true; -} - -int BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int userId) -{ - if (userId == 0) { - return -1; - } else { - return Notification::NON_SYSTEM_APP_UID; - } -} - -bool BundleMgrProxy::GetApplicationInfo( - const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) -{ - appInfo.distributedNotificationEnabled = g_isEnable; - return true; -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/mock_notification_helper.cpp b/services/reminder/test/unittest/mock/mock_notification_helper.cpp index 3058d8f269bb985cb9a4b16c331b04cac40f6f52..754fcc29721098dc00a822a712e0bc39bd8fe3ed 100644 --- a/services/reminder/test/unittest/mock/mock_notification_helper.cpp +++ b/services/reminder/test/unittest/mock/mock_notification_helper.cpp @@ -16,14 +16,18 @@ #include "mock_notification_helper.h" #include "notification_helper.h" +#include "common_event_manager.h" -namespace OHOS::Notification { +namespace OHOS { namespace { bool g_mockIsAllowUseReminder = true; bool g_mockIsAllowedNotify = true; +bool g_mockSubscribeCommonEventRet = true; int32_t g_mockIsAllowedNotifyRet = 0; +int32_t g_mockSubscribeNotificationRet = 0; } +namespace Notification { void MockNotificationHelper::MockIsAllowUseReminder(const bool isAllowUseReminder) { g_mockIsAllowUseReminder = isAllowUseReminder; @@ -35,6 +39,16 @@ void MockNotificationHelper::MockIsAllowedNotify(const bool isAllowedNotify, con g_mockIsAllowedNotifyRet = ret; } +void MockNotificationHelper::MockSubscribeNotification(const int32_t ret) +{ + g_mockSubscribeNotificationRet = ret; +} + +void MockNotificationHelper::MockSubscribeCommonEvent(const bool ret) +{ + g_mockSubscribeCommonEventRet = ret; +} + ErrCode NotificationHelper::AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) { isAllowUseReminder = g_mockIsAllowUseReminder; @@ -46,4 +60,17 @@ ErrCode NotificationHelper::IsAllowedNotify(const NotificationBundleOption& bund allowed = g_mockIsAllowedNotify; return g_mockIsAllowedNotifyRet; } -} // namespace OHOS::Notification \ No newline at end of file + +ErrCode NotificationHelper::SubscribeNotification(const NotificationSubscriber& subscriber) +{ + return g_mockSubscribeNotificationRet; +} +} + +namespace EventFwk { +bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr& subscriber) +{ + return g_mockSubscribeCommonEventRet; +} +} +} // namespace OHOS \ No newline at end of file diff --git a/services/reminder/test/unittest/mock/mock_reminder_data_manager.cpp b/services/reminder/test/unittest/mock/mock_reminder_data_manager.cpp index 409e4bf391fd80275848f159f65e986e9ba96503..ff3c91ee5554df2d08626cd4fb89fdecf79afd03 100644 --- a/services/reminder/test/unittest/mock/mock_reminder_data_manager.cpp +++ b/services/reminder/test/unittest/mock/mock_reminder_data_manager.cpp @@ -125,4 +125,56 @@ int32_t ReminderDataManager::QueryActiveReminderCount() { return g_mockQueryActiveReminderCountRet; } + +void ReminderDataManager::OnProcessDiedLocked(const int32_t callingUid) +{} + +void ReminderDataManager::RefreshRemindersDueToSysTimeChange(uint8_t type) +{} + +void ReminderDataManager::OnUserSwitch(const int32_t& userId) +{} + +void ReminderDataManager::OnUserRemove(const int32_t& userId) +{} + +void ReminderDataManager::OnUnlockScreen() +{} + +void ReminderDataManager::ShowActiveReminder(const EventFwk::Want& want) +{} + +void ReminderDataManager::TerminateAlerting(const EventFwk::Want& want) +{} + +void ReminderDataManager::CloseReminder(const sptr& reminder, bool cancelNotification) +{} + +void ReminderDataManager::SnoozeReminder(const EventFwk::Want& want) +{} + +void ReminderDataManager::HandleCustomButtonClick(const EventFwk::Want& want) +{} + +void ReminderDataManager::CloseReminder(const EventFwk::Want& want, bool cancelNotification, bool isButtonClick) +{} + +void ReminderDataManager::ClickReminder(const EventFwk::Want& want) +{} + +void ReminderDataManager::OnBundleMgrServiceStart() +{} + +void ReminderDataManager::OnAbilityMgrServiceStart() +{} + +void ReminderDataManager::OnRemoveAppMgr() +{} + +void ReminderDataManager::HandleAutoDeleteReminder(const int32_t notificationId, const int32_t uid, + const int64_t autoDeletedTime) +{} + +void ReminderDataManager::OnLanguageChanged() +{} } // namespace OHOS::Notification \ No newline at end of file diff --git a/services/reminder/test/unittest/bundle_manager_helper_branch_test/mock_service_registry.cpp b/services/reminder/test/unittest/mock/mock_service_registry.cpp old mode 100755 new mode 100644 similarity index 82% rename from services/reminder/test/unittest/bundle_manager_helper_branch_test/mock_service_registry.cpp rename to services/reminder/test/unittest/mock/mock_service_registry.cpp index c9ffe49a59ac62f7ba95bfbb379130de88ee5456..b9c5a9a907c941d475a0f8d0474daca9a0e3379d --- a/services/reminder/test/unittest/bundle_manager_helper_branch_test/mock_service_registry.cpp +++ b/services/reminder/test/unittest/mock/mock_service_registry.cpp @@ -1,43 +1,46 @@ -/* - * Copyright (c) 2022 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 "iservice_registry.h" - -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "mock_service_registry.h" - -namespace { - bool g_mockGetSystemAbilityManagerRet = true; -} - -namespace OHOS { -sptr SystemAbilityManagerClient::GetSystemAbilityManager() -{ - if (false == g_mockGetSystemAbilityManagerRet) { - if (systemAbilityManager_ != nullptr) { - return systemAbilityManager_; - } - sptr registryObject = IPCSkeleton::GetContextObject(); - systemAbilityManager_ = iface_cast(registryObject); - return systemAbilityManager_; - } - return nullptr; -} -void MockServiceRegistry::MockGetSystemAbilityManager(bool mockRet) -{ - g_mockGetSystemAbilityManagerRet = mockRet; -} -} // namespace OHOS +/* + * Copyright (c) 2022-2025 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 "mock_service_registry.h" + +#include "ipc_skeleton.h" +#include "iremote_object.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace { + bool g_mockGetSystemAbilityManagerRet = true; +} + +namespace Notification { +void MockServiceRegistry::MockGetSystemAbilityManager(const bool ret) +{ + g_mockGetSystemAbilityManagerRet = ret; +} +} + +sptr SystemAbilityManagerClient::GetSystemAbilityManager() +{ + if (!g_mockGetSystemAbilityManagerRet) { + if (systemAbilityManager_ != nullptr) { + return systemAbilityManager_; + } + sptr registryObject = IPCSkeleton::GetContextObject(); + systemAbilityManager_ = iface_cast(registryObject); + return systemAbilityManager_; + } + return nullptr; +} +} // namespace OHOS diff --git a/services/reminder/test/unittest/os_account_manager_helper_test.cpp b/services/reminder/test/unittest/os_account_manager_helper_test.cpp deleted file mode 100644 index 38c892916826ba562a4412b74d99d842f2f1da82..0000000000000000000000000000000000000000 --- a/services/reminder/test/unittest/os_account_manager_helper_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include - -#include "reminder_os_account_manager_helper.h" -#include "accesstoken_kit.h" - - -using namespace testing::ext; -namespace OHOS { -namespace Notification { -class ReminderOsAccountManagerHelperTest : public testing::Test { -public: - static void SetUpTestSuite() {}; - static void TearDownTestSuite() {}; - void SetUp() override {}; - void TearDown() override {}; -}; - -/** - * @tc.number : GetOsAccountLocalIdFromUid_00100 - * @tc.name : GetOsAccountLocalIdFromUid_00100 - * @tc.desc : test GetOsAccountLocalIdFromUid function - */ -HWTEST_F(ReminderOsAccountManagerHelperTest, GetOsAccountLocalIdFromUid_00100, Function | SmallTest | Level1) -{ - int32_t userId = -1; - const int uid = 0; - ASSERT_EQ(ERR_OK, ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId)); -} - -/** - * @tc.number : GetCurrentActiveUserId_00100 - * @tc.name : GetCurrentActiveUserId_00100 - * @tc.desc : test GetCurrentActiveUserId function - */ -HWTEST_F(ReminderOsAccountManagerHelperTest, GetCurrentActiveUserId_00100, Function | SmallTest | Level1) -{ - int32_t userId = -1; - ASSERT_EQ(ERR_OK, ReminderOsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId)); -} -} -} \ No newline at end of file diff --git a/services/reminder/test/unittest/reminder_agent_service_test.cpp b/services/reminder/test/unittest/reminder_agent_service_test.cpp index f7b0343b3a2c86ecd126b6b8be88b7b56045ff09..605533d1eaee8b6ceb4133aaa13a87c864ef2be3 100644 --- a/services/reminder/test/unittest/reminder_agent_service_test.cpp +++ b/services/reminder/test/unittest/reminder_agent_service_test.cpp @@ -423,18 +423,4 @@ HWTEST_F(ReminderAgentServiceTest, ReminderAgentServiceTest_015, Function | Smal MockAccesstokenKit::MockIsSystemApp(true); EXPECT_EQ(reminderAgentService_->IsSystemApp(), true); } - -/** - * @tc.name: ReminderAgentServiceTest_016 - * @tc.desc: Test GetClientBundleName function - * @tc.type: FUNC - * @tc.require: issueI5S4VP - */ -HWTEST_F(ReminderAgentServiceTest, ReminderAgentServiceTest_016, Function | SmallTest | Level1) -{ - MockReminderBundleManagerHelper::MockGetBundleNameByUid("test"); - EXPECT_EQ(reminderAgentService_->GetClientBundleName(1), "test"); - MockReminderBundleManagerHelper::MockGetBundleNameByUid(""); - EXPECT_EQ(reminderAgentService_->GetClientBundleName(1), ""); -} } // namespace OHOS::Notification diff --git a/services/reminder/test/unittest/bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp b/services/reminder/test/unittest/reminder_bundle_manager_helper_test.cpp old mode 100755 new mode 100644 similarity index 42% rename from services/reminder/test/unittest/bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp rename to services/reminder/test/unittest/reminder_bundle_manager_helper_test.cpp index 1999aac1f4edc5c0711a6fd008a65fc897e3c3cb..e95d34f6f2fcaf0b5a2543008370a3894db20cc0 --- a/services/reminder/test/unittest/bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp +++ b/services/reminder/test/unittest/reminder_bundle_manager_helper_test.cpp @@ -1,157 +1,177 @@ -/* - * Copyright (c) 2022 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 -#include - -#include "reminder_ut_constant.h" -#include "reminder_bundle_manager_helper.h" -#include "mock_service_registry.h" - -using namespace testing::ext; -namespace OHOS { -namespace Notification { -class BundleManagerHelperBranchTest : public testing::Test { -public: - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number : BundleManagerHelper_00100 - * @tc.name : BundleManagerHelper_00100 - * @tc.desc : test GetBundleNameByUid function and bundleMgr_ != nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelperTest_00100, Function | SmallTest | Level1) -{ - ReminderBundleManagerHelper bundleManagerHelper; - MockServiceRegistry::MockGetSystemAbilityManager(false); - int32_t uid = 1; - ASSERT_EQ("", bundleManagerHelper.GetBundleNameByUid(uid)); -} - -/** - * @tc.number : BundleManagerHelper_00200 - * @tc.name : BundleManagerHelper_00200 - * @tc.desc : test GetBundleNameByUid function and bundleMgr_ == nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_00200, Function | SmallTest | Level1) -{ - ReminderBundleManagerHelper bundleManagerHelper; - MockServiceRegistry::MockGetSystemAbilityManager(true); - int32_t uid = 1; - ASSERT_EQ("", bundleManagerHelper.GetBundleNameByUid(uid)); -} - -/** - * @tc.number : BundleManagerHelper_00800 - * @tc.name : BundleManagerHelper_00800 - * @tc.desc : test Connect function and systemAbilityManager is nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_00800, Function | SmallTest | Level1) -{ - std::shared_ptr bundleManagerHelper = std::make_shared(); - ASSERT_NE(nullptr, bundleManagerHelper); - MockServiceRegistry::MockGetSystemAbilityManager(true); - bundleManagerHelper->Connect(); -} - -/** - * @tc.number : BundleManagerHelper_00900 - * @tc.name : BundleManagerHelper_00900 - * @tc.desc : test Connect function and systemAbilityManager is not nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_00900, Function | SmallTest | Level1) -{ - std::shared_ptr bundleManagerHelper = std::make_shared(); - ASSERT_NE(nullptr, bundleManagerHelper); - MockServiceRegistry::MockGetSystemAbilityManager(false); - // test Connect and bundleMgr_ == nullptr - bundleManagerHelper->Connect(); -} - -/** - * @tc.number : BundleManagerHelper_01000 - * @tc.name : BundleManagerHelper_01000 - * @tc.desc : test Connect function and bundleMgr_ != nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01000, Function | SmallTest | Level1) -{ - std::shared_ptr bundleManagerHelper = std::make_shared(); - ASSERT_NE(nullptr, bundleManagerHelper); - MockServiceRegistry::MockGetSystemAbilityManager(false); - bundleManagerHelper->Connect(); - // test Connect and bundleMgr_ != nullptr - bundleManagerHelper->Connect(); -} - -/** - * @tc.number : BundleManagerHelper_01100 - * @tc.name : BundleManagerHelper_01100 - * @tc.desc : test Disconnect function and bundleMgr_ != nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01100, Function | SmallTest | Level1) -{ - std::shared_ptr bundleManagerHelper = std::make_shared(); - ASSERT_NE(nullptr, bundleManagerHelper); - MockServiceRegistry::MockGetSystemAbilityManager(false); - bundleManagerHelper->Connect(); - bundleManagerHelper->Disconnect(); -} - -/** - * @tc.number : BundleManagerHelper_01200 - * @tc.name : BundleManagerHelper_01200 - * @tc.desc : test Disconnect function and bundleMgr_ == nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01200, Function | SmallTest | Level1) -{ - std::shared_ptr bundleManagerHelper = std::make_shared(); - ASSERT_NE(nullptr, bundleManagerHelper); - bundleManagerHelper->Disconnect(); -} - -/** - * @tc.number : BundleManagerHelper_01300 - * @tc.name : BundleManagerHelper_01300 - * @tc.desc : test GetDefaultUidByBundleName function and bundleMgr_ == nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01300, Function | SmallTest | Level1) -{ - ReminderBundleManagerHelper bundleManagerHelper; - MockServiceRegistry::MockGetSystemAbilityManager(true); - std::string bundle = "aa"; - int32_t userId = 1; - ASSERT_EQ(-1, bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId)); -} - -/** - * @tc.number : BundleManagerHelper_01400 - * @tc.name : BundleManagerHelper_01400 - * @tc.desc : test GetDefaultUidByBundleName function and bundleMgr_ != nullptr - */ -HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01400, Function | SmallTest | Level1) -{ - ReminderBundleManagerHelper bundleManagerHelper; - MockServiceRegistry::MockGetSystemAbilityManager(false); - std::string bundle = "aa"; - int32_t userId = 1; - ASSERT_EQ(-1, bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId)); -} - -} // namespace Notification -} // namespace OHOS +/* + * Copyright (c) 2022-2025 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 + +#include "reminder_bundle_manager_helper.h" + +#include "mock_service_registry.h" + +using namespace testing::ext; +namespace OHOS::Notification { +class ReminderBundleManagerHelperTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.number : ReminderBundleManagerHelperTest_001 + * @tc.name : ReminderBundleManagerHelperTest_001 + * @tc.desc : test Connect function and systemAbilityManager is nullptr + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_001, Function | SmallTest | Level1) +{ + auto bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockServiceRegistry::MockGetSystemAbilityManager(true); + bundleManagerHelper->Connect(); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_002 + * @tc.name : ReminderBundleManagerHelperTest_002 + * @tc.desc : test Connect function and systemAbilityManager is not nullptr + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_002, Function | SmallTest | Level1) +{ + auto bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockServiceRegistry::MockGetSystemAbilityManager(false); + // test Connect and bundleMgr_ == nullptr + bundleManagerHelper->Connect(); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_003 + * @tc.name : ReminderBundleManagerHelperTest_003 + * @tc.desc : test Connect function and bundleMgr_ != nullptr + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_003, Function | SmallTest | Level1) +{ + auto bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockServiceRegistry::MockGetSystemAbilityManager(false); + bundleManagerHelper->Connect(); + // test Connect and bundleMgr_ != nullptr + bundleManagerHelper->Connect(); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_004 + * @tc.name : ReminderBundleManagerHelperTest_004 + * @tc.desc : test Disconnect function and bundleMgr_ != nullptr + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_004, Function | SmallTest | Level1) +{ + auto bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockServiceRegistry::MockGetSystemAbilityManager(false); + bundleManagerHelper->Connect(); + bundleManagerHelper->Disconnect(); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_005 + * @tc.name : ReminderBundleManagerHelperTest_005 + * @tc.desc : test Disconnect function and bundleMgr_ == nullptr + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_005, Function | SmallTest | Level1) +{ + auto bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + bundleManagerHelper->Disconnect(); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_006 + * @tc.name : ReminderBundleManagerHelperTest_006 + * @tc.desc : test GetBundleNameByUid function + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_006, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + int32_t uid = 1; + // bundleMgr_ == nullptr + MockServiceRegistry::MockGetSystemAbilityManager(true); + ASSERT_EQ("", bundleManagerHelper.GetBundleNameByUid(uid)); + + // bundleMgr_ != nullptr + MockServiceRegistry::MockGetSystemAbilityManager(false); + ASSERT_EQ("", bundleManagerHelper.GetBundleNameByUid(uid)); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_007 + * @tc.name : ReminderBundleManagerHelperTest_007 + * @tc.desc : test GetDefaultUidByBundleName function + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_007, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + std::string bundle = "aa"; + int32_t userId = 1; + // bundleMgr_ == nullptr + MockServiceRegistry::MockGetSystemAbilityManager(true); + ASSERT_EQ(-1, bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId)); + + // bundleMgr_ != nullptr + MockServiceRegistry::MockGetSystemAbilityManager(false); + ASSERT_EQ(-1, bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId)); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_008 + * @tc.name : ReminderBundleManagerHelperTest_008 + * @tc.desc : test GetDefaultUidByBundleName function + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_008, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + std::string bundle = "aa"; + int32_t uid = 1; + AppExecFwk::BundleInfo bundleInfo; + // bundleMgr_ == nullptr + MockServiceRegistry::MockGetSystemAbilityManager(true); + ASSERT_EQ(false, bundleManagerHelper.GetBundleInfo(bundle, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, + uid, bundleInfo)); + + // bundleMgr_ != nullptr + MockServiceRegistry::MockGetSystemAbilityManager(false); + ASSERT_EQ(false, bundleManagerHelper.GetBundleInfo(bundle, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, + uid, bundleInfo)); +} + +/** + * @tc.number : ReminderBundleManagerHelperTest_009 + * @tc.name : ReminderBundleManagerHelperTest_009 + * @tc.desc : test GetAppIndexByUid function + */ +HWTEST_F(ReminderBundleManagerHelperTest, ReminderBundleManagerHelperTest_009, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + int32_t uid = 1; + // bundleMgr_ == nullptr + MockServiceRegistry::MockGetSystemAbilityManager(true); + ASSERT_EQ(0, bundleManagerHelper.GetAppIndexByUid(uid)); + + // bundleMgr_ != nullptr + MockServiceRegistry::MockGetSystemAbilityManager(false); + ASSERT_EQ(0, bundleManagerHelper.GetAppIndexByUid(uid)); +} +} // namespace OHOS::Notification + \ No newline at end of file diff --git a/services/reminder/test/unittest/reminder_data_manager_test.cpp b/services/reminder/test/unittest/reminder_data_manager_test.cpp index d9ace6bbbf855a2f35640a956f9d114079d6cf17..50f96ce3e61b02e17cbdb2595358d0cc47c40949 100644 --- a/services/reminder/test/unittest/reminder_data_manager_test.cpp +++ b/services/reminder/test/unittest/reminder_data_manager_test.cpp @@ -31,7 +31,6 @@ #include "ability_manager_client.h" #include "mock_ipc_skeleton.h" #include "reminder_datashare_helper.h" -#include "reminder_config_change_observer.h" #include "reminder_calendar_share_table.h" #include "reminder_timer_info.h" @@ -531,7 +530,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_001, Level1) matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); CommonEventSubscribeInfo subscriberInfo(matchingSkills); - auto subscriber = std::make_shared(subscriberInfo, manager); + auto subscriber = std::make_shared(subscriberInfo); EventFwk::CommonEventData data; Want want; want.SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); @@ -586,7 +585,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_001, Level1) HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_002, Level1) { auto statusChangeListener - = std::make_shared(manager); + = std::make_shared(); statusChangeListener->OnAddSystemAbility(0, ""); statusChangeListener->OnRemoveSystemAbility(0, ""); system("rm -rf /data/service/el1/public/notification/"); @@ -859,13 +858,12 @@ HWTEST_F(ReminderDataManagerTest, ReminderEventManager_001, Level1) matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); CommonEventSubscribeInfo subscriberInfo(matchingSkills); - auto subscriber = std::make_shared(subscriberInfo, manager); + auto subscriber = std::make_shared(subscriberInfo); EventFwk::Want want; want.SetParam(ReminderRequest::PARAM_REMINDER_ID, 0); AppExecFwk::ElementName element("", "test", "EntryAbility"); want.SetElement(element); - subscriber->HandlePackageRemove(want); EXPECT_TRUE(manager != nullptr); } @@ -878,7 +876,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderEventManager_001, Level1) HWTEST_F(ReminderDataManagerTest, ReminderEventManager_002, Level1) { auto statusChangeListener - = std::make_shared(manager); + = std::make_shared(); statusChangeListener->OnAddSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, ""); statusChangeListener->OnAddSystemAbility(APP_MGR_SERVICE_ID, ""); statusChangeListener->OnAddSystemAbility(ABILITY_MGR_SERVICE_ID, ""); @@ -907,7 +905,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_005, Level1) customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT); customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLICK_ALERT); CommonEventSubscribeInfo subscriberInfo(customMatchingSkills); - auto subscriber = std::make_shared(subscriberInfo, manager); + auto subscriber = std::make_shared(subscriberInfo); EventFwk::CommonEventData data; Want want; want.SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); @@ -944,7 +942,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_005, Level1) HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_006, Level1) { std::shared_ptr data; - ReminderEventManager::ReminderNotificationSubscriber subscriber(data); + ReminderEventManager::ReminderNotificationSubscriber subscriber; subscriber.OnCanceled(nullptr, nullptr, NotificationConstant::PACKAGE_REMOVE_REASON_DELETE); subscriber.OnCanceled(nullptr, nullptr, NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); sptr request = new NotificationRequest(); diff --git a/services/reminder/test/unittest/reminder_event_manager_test.cpp b/services/reminder/test/unittest/reminder_event_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d76d22ec8827bbfd08ac684c15035af34eddd6fa --- /dev/null +++ b/services/reminder/test/unittest/reminder_event_manager_test.cpp @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2024-2025 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 + +#include "reminder_data_manager.h" +#include "reminder_event_manager.h" + +#include "common_event_support.h" +#include "mock_notification_helper.h" +#include "mock_reminder_data_manager.h" + +using namespace testing::ext; +namespace OHOS::Notification { +class ReminderEventManagerTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: ReminderEventManagerTest_001 + * @tc.desc: test ReminderEventManager::Init function + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_001, Level1) +{ + ReminderDataManager::InitInstance(); + auto manager = std::make_shared(); + manager->Init(); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_002 + * @tc.desc: test ReminderEventManager::SubscribeEvent function + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_002, Level1) +{ + auto manager = std::make_shared(); + MockNotificationHelper::MockSubscribeCommonEvent(false); + manager->SubscribeEvent(); + MockNotificationHelper::MockSubscribeCommonEvent(true); + manager->SubscribeEvent(); + MockNotificationHelper::MockSubscribeNotification(-1); + manager->SubscribeEvent(); + MockNotificationHelper::MockSubscribeNotification(ERR_OK); + manager->SubscribeEvent(); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_003 + * @tc.desc: test ReminderEventManager::SubscribeSystemAbility function + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_003, Level1) +{ + auto manager = std::make_shared(); + manager->SubscribeSystemAbility(APP_MGR_SERVICE_ID); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_004 + * @tc.desc: test ReminderEventSubscriber::OnReceiveEvent function + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_004, Level1) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto subscriber = std::make_shared(subscriberInfo); + + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); + data.SetWant(want); + auto manager = std::move(ReminderDataManager::REMINDER_DATA_MANAGER); + subscriber->OnReceiveEvent(data); + + ReminderDataManager::REMINDER_DATA_MANAGER = std::move(manager); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction("common.event.UNLOCK_SCREEN"); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + EXPECT_TRUE(subscriber != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_005 + * @tc.desc: test ReminderCustomEventSubscriber::OnReceiveEvent function + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_005, Level1) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto subscriber = std::make_shared(subscriberInfo); + + EventFwk::CommonEventData data; + EventFwk::Want want; + want.SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + data.SetWant(want); + auto manager = std::move(ReminderDataManager::REMINDER_DATA_MANAGER); + subscriber->OnReceiveEvent(data); + + ReminderDataManager::REMINDER_DATA_MANAGER = std::move(manager); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_CLICK_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + EXPECT_TRUE(subscriber != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_006 + * @tc.desc: test SystemAbilityStatusChangeListener + * @tc.type: FUNC + * @tc.require: issue#I9IIDE + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_006, Level1) +{ + auto listener = std::make_shared(); + // test OnAddSystemAbility + auto manager = std::move(ReminderDataManager::REMINDER_DATA_MANAGER); + listener->OnAddSystemAbility(-1, ""); + ReminderDataManager::REMINDER_DATA_MANAGER = std::move(manager); + listener->OnAddSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, ""); + listener->OnAddSystemAbility(APP_MGR_SERVICE_ID, ""); + listener->OnAddSystemAbility(ABILITY_MGR_SERVICE_ID, ""); + listener->OnAddSystemAbility(-1, ""); + + // test OnRemoveSystemAbility + manager = std::move(ReminderDataManager::REMINDER_DATA_MANAGER); + listener->OnRemoveSystemAbility(-1, ""); + ReminderDataManager::REMINDER_DATA_MANAGER = std::move(manager); + listener->OnRemoveSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, ""); + listener->OnRemoveSystemAbility(APP_MGR_SERVICE_ID, ""); + listener->OnRemoveSystemAbility(ABILITY_MGR_SERVICE_ID, ""); + listener->OnRemoveSystemAbility(-1, ""); + EXPECT_TRUE(listener != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_007 + * @tc.desc: test ReminderNotificationSubscriber::OnCanceled test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_007, Level1) +{ + ReminderEventManager::ReminderNotificationSubscriber subscriber; + // test deleteReason + subscriber.OnCanceled(nullptr, nullptr, NotificationConstant::PACKAGE_REMOVE_REASON_DELETE); + // test notification + subscriber.OnCanceled(nullptr, nullptr, NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); + // test autoDeletedTime + sptr request = new NotificationRequest(); + std::shared_ptr notification = std::make_shared(request); + subscriber.OnCanceled(notification, nullptr, NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); + request->SetAutoDeletedTime(100); + // test label + subscriber.OnCanceled(notification, nullptr, NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); + request->SetLabel("REMINDER_AGENT"); + // test manager + auto manager = std::move(ReminderDataManager::REMINDER_DATA_MANAGER); + subscriber.OnCanceled(notification, nullptr, NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); + ReminderDataManager::REMINDER_DATA_MANAGER = std::move(manager); + subscriber.OnCanceled(notification, nullptr, NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); + EXPECT_TRUE(manager == nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_008 + * @tc.desc: test ReminderConfigChangeObserver::OnConfigurationUpdated function + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderEventManagerTest, ReminderEventManagerTest_008, Level1) +{ + ReminderConfigChangeObserver observer; + AppExecFwk::Configuration config; + // test manager == nullptr + auto manager = std::move(ReminderDataManager::REMINDER_DATA_MANAGER); + observer.OnConfigurationUpdated(config); + ReminderDataManager::REMINDER_DATA_MANAGER = std::move(manager); + // test languageInfo + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, ""); + observer.OnConfigurationUpdated(config); + config.RemoveItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); + config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, "test"); + observer.languageInfo_ = "test"; + observer.OnConfigurationUpdated(config); + observer.languageInfo_ = "1111"; + observer.OnConfigurationUpdated(config); + EXPECT_TRUE(manager == nullptr); +} +} // namespace OHOS::Notification