diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 686c3b44f79c73cd33a18eaa2621d0544d2b31bc..80a21b60fc19a8271b2afd250913596d6fff409b 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -46,6 +46,14 @@ idl_gen_interface("ans_subscriber_local_live_view_interface") { part_name = "distributed_notification_service" } +idl_gen_interface("ans_subscriber_interface") { + sources = [ "IAnsSubscriber.idl" ] + log_domainid = "0xD001203" + log_tag = "Ans" + subsystem_name = "notification" + part_name = "distributed_notification_service" +} + group("ans_client") { deps = [ ":ans_innerkits" ] } @@ -116,6 +124,19 @@ config("ans_subscriber_local_live_view_config") { configs = [ "${multimedia_path}/interfaces/innerkits:image_external_config" ] } +config("ans_subscriber_config") { + visibility = [ "./../../*" ] + + include_dirs = [ + "${inner_api_path}", + "${interfaces_path}/kits/native", + "${core_path}/common/include", + "${core_path}/include", + "${target_gen_dir}", + ] + configs = [ "${multimedia_path}/interfaces/innerkits:image_external_config" ] +} + ohos_source_set("swing_call_back_proxy") { sanitize = { integer_overflow = true @@ -181,8 +202,6 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/ans_notification.cpp", "${core_path}/src/dialog_status_data.cpp", "${core_path}/src/listener/ans_subscriber_listener.cpp", - "${core_path}/src/listener/ans_subscriber_proxy.cpp", - "${core_path}/src/listener/ans_subscriber_stub.cpp", "${core_path}/src/listener/swing_callback_service.cpp", "${core_path}/src/manager/ans_manager_death_recipient.cpp", "${core_path}/src/manager/ans_manager_proxy.cpp", @@ -251,6 +270,8 @@ ohos_shared_library("ans_innerkits") { ":ans_operation_callback_stub", ":ans_subscriber_local_live_view_proxy", ":ans_subscriber_local_live_view_stub", + ":ans_subscriber_proxy", + ":ans_subscriber_stub", ] external_deps = [ @@ -440,3 +461,65 @@ ohos_source_set("ans_subscriber_local_live_view_stub") { subsystem_name = "notification" part_name = "distributed_notification_service" } + +ohos_source_set("ans_subscriber_proxy") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + public_configs = [ ":ans_subscriber_config" ] + output_values = get_target_outputs(":ans_subscriber_interface") + sources = filter_include(output_values, [ "*_proxy.cpp" ]) + deps = [ ":ans_subscriber_interface" ] + external_deps = [ + "c_utils:utils", + "hicollie:libhicollie", + "hilog:libhilog", + "i18n:intl_util", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + public_external_deps = [ + "ability_runtime:wantagent_innerkits", + "image_framework:image_native", + ] + + subsystem_name = "notification" + part_name = "distributed_notification_service" +} + +ohos_source_set("ans_subscriber_stub") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + public_configs = [ ":ans_subscriber_config" ] + output_values = get_target_outputs(":ans_subscriber_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) + deps = [ ":ans_subscriber_interface" ] + external_deps = [ + "c_utils:utils", + "hicollie:libhicollie", + "hilog:libhilog", + "i18n:intl_util", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + public_external_deps = [ + "ability_runtime:wantagent_innerkits", + "image_framework:image_native", + ] + + subsystem_name = "notification" + part_name = "distributed_notification_service" +} diff --git a/frameworks/ans/IAnsSubscriber.idl b/frameworks/ans/IAnsSubscriber.idl new file mode 100644 index 0000000000000000000000000000000000000000..26c446aa28570ed125a77d4cde585e3988a04736 --- /dev/null +++ b/frameworks/ans/IAnsSubscriber.idl @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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. + */ + +sequenceable OHOS.Notification.Notification; +sequenceable OHOS.Notification.NotificationSortingMap; +sequenceable OHOS.Notification.NotificationDoNotDisturbDate; +sequenceable OHOS.Notification.EnabledNotificationCallbackData; +sequenceable OHOS.Notification.BadgeNumberCallbackData; +sequenceable OHOS.Notification.NotificationOperationInfo; +interface OHOS.Notification.IAnsSubscriber { + void OnConnected(); + void OnDisconnected(); + void OnConsumed([in] sptr notification, [in] sptr notificationMap); + void OnConsumed([in] sptr notification); + [ipcincapacity 520] void OnConsumedWithMaxCapacity([in] sptr notification, [in] sptr notificationMap); + [ipcincapacity 520] void OnConsumedWithMaxCapacity([in] sptr notification); + void OnConsumedList([in] sptr[] notifications, [in] sptr notificationMap); + void OnCanceled([in] sptr notification, [in] sptr notificationMap, [in] int deleteReason); + void OnCanceled([in] sptr notification, [in] int deleteReason); + [ipcincapacity 520] void OnCanceledWithMaxCapacity([in] sptr notification, [in] sptr notificationMap, [in] int deleteReason); + [ipcincapacity 520] void OnCanceledWithMaxCapacity([in] sptr notification, [in] int deleteReason); + void OnCanceledList([in] sptr[] notifications, [in] sptr notificationMap, [in] int deleteReason); + void OnUpdated([in] sptr notificationMap); + void OnDoNotDisturbDateChange([in] sptr date); + void OnEnabledNotificationChanged([in] sptr callbackData); + void OnBadgeChanged([in] sptr badgeData); + void OnBadgeEnabledChanged([in] sptr callbackData); + void OnApplicationInfoNeedChanged([in] String bundleName); + int OnOperationResponse([in] sptr operationInfo); +} diff --git a/frameworks/ans/src/notification_subscriber.cpp b/frameworks/ans/src/notification_subscriber.cpp index 0ae73181b6b16e0c226c4d3515915fdaf0b40a15..6fd51f541073169d231da97c76eead14af904ec0 100644 --- a/frameworks/ans/src/notification_subscriber.cpp +++ b/frameworks/ans/src/notification_subscriber.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -114,7 +114,7 @@ NotificationSubscriber::SubscriberImpl::SubscriberImpl(NotificationSubscriber &s recipient_ = new (std::nothrow) DeathRecipient(*this); }; -void NotificationSubscriber::SubscriberImpl::OnConnected() +ErrCode NotificationSubscriber::SubscriberImpl::OnConnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); sptr proxy = GetAnsManagerProxy(); @@ -123,9 +123,10 @@ void NotificationSubscriber::SubscriberImpl::OnConnected() ANS_LOGD("%s, Add death recipient.", __func__); } subscriber_.OnConnected(); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnDisconnected() +ErrCode NotificationSubscriber::SubscriberImpl::OnDisconnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); sptr proxy = GetAnsManagerProxy(); @@ -134,32 +135,51 @@ void NotificationSubscriber::SubscriberImpl::OnDisconnected() ANS_LOGD("%s, Remove death recipient.", __func__); } subscriber_.OnDisconnected(); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnConsumed( +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); std::shared_ptr sharedNotification = std::make_shared(*notification); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED if (!subscriber_.ProcessSyncDecision(subscriber_.GetDeviceType(), sharedNotification)) { - return; + return ERR_OK; } #endif subscriber_.OnConsumed( sharedNotification, std::make_shared(*notificationMap)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnConsumedList(const std::vector> ¬ifications, +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumed(const sptr ¬ification) +{ + return OnConsumed(notification, nullptr); +} + +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumedWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap) +{ + return OnConsumed(notification, notificationMap); +} + +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumedWithMaxCapacity(const sptr ¬ification) +{ + return OnConsumed(notification, nullptr); +} + +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumedList(const std::vector> ¬ifications, const sptr ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); for (auto notification : notifications) { OnConsumed(notification, notificationMap); } + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnCanceled( +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); @@ -170,6 +190,25 @@ void NotificationSubscriber::SubscriberImpl::OnCanceled( subscriber_.OnCanceled(std::make_shared(*notification), std::make_shared(*notificationMap), deleteReason); } + return ERR_OK; +} + +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceled( + const sptr ¬ification, int32_t deleteReason) +{ + return OnCanceled(notification, nullptr, deleteReason); +} + +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceledWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) +{ + return OnCanceled(notification, notificationMap, deleteReason); +} + +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceledWithMaxCapacity( + const sptr ¬ification, int32_t deleteReason) +{ + return OnCanceled(notification, nullptr, deleteReason); } void NotificationSubscriber::SubscriberImpl::OnBatchCanceled(const std::vector> ¬ifications, @@ -189,58 +228,65 @@ void NotificationSubscriber::SubscriberImpl::OnBatchCanceled(const std::vector> ¬ifications, +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceledList(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber_.HasOnBatchCancelCallback()) { OnBatchCanceled(notifications, notificationMap, deleteReason); - return; + return ERR_OK; } for (auto notification : notifications) { OnCanceled(notification, notificationMap, deleteReason); } + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnUpdated(const sptr ¬ificationMap) +ErrCode NotificationSubscriber::SubscriberImpl::OnUpdated(const sptr ¬ificationMap) { subscriber_.OnUpdate(std::make_shared(*notificationMap)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnDoNotDisturbDateChange(const sptr &date) +ErrCode NotificationSubscriber::SubscriberImpl::OnDoNotDisturbDateChange(const sptr &date) { subscriber_.OnDoNotDisturbDateChange(std::make_shared(*date)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnEnabledNotificationChanged( +ErrCode NotificationSubscriber::SubscriberImpl::OnEnabledNotificationChanged( const sptr &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); subscriber_.OnEnabledNotificationChanged(std::make_shared(*callbackData)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnBadgeChanged(const sptr &badgeData) +ErrCode NotificationSubscriber::SubscriberImpl::OnBadgeChanged(const sptr &badgeData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); subscriber_.OnBadgeChanged(std::make_shared(*badgeData)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnBadgeEnabledChanged( +ErrCode NotificationSubscriber::SubscriberImpl::OnBadgeEnabledChanged( const sptr &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); subscriber_.OnBadgeEnabledChanged(callbackData); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnApplicationInfoNeedChanged( +ErrCode NotificationSubscriber::SubscriberImpl::OnApplicationInfoNeedChanged( const std::string& bundleName) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); subscriber_.OnApplicationInfoNeedChanged(bundleName); + return ERR_OK; } ErrCode NotificationSubscriber::SubscriberImpl::OnOperationResponse( - const sptr &operationInfo) + const sptr &operationInfo, int32_t& funcResult) { return subscriber_.OnOperationResponse(std::make_shared(*operationInfo)); } diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index e7ec9899bd12c122bd3b48bd863ae5e8c2475ab7..4859292863d882fd4e62eaa66bc2b7f2de37aadf 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -20,7 +20,7 @@ #include #include "ians_dialog_callback.h" -#include "ans_subscriber_interface.h" +#include "ians_subscriber.h" #include "ians_subscriber_local_live_view.h" #include "iremote_broker.h" #include "notification_bundle_option.h" @@ -467,7 +467,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode Subscribe(const sptr &subscriber, + virtual ErrCode Subscribe(const sptr &subscriber, const sptr &info) = 0; /** @@ -476,7 +476,7 @@ public: * @param subscriber Indicates the subscriber. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SubscribeSelf(const sptr &subscriber) = 0; + virtual ErrCode SubscribeSelf(const sptr &subscriber) = 0; /** * @brief Subscribes local live view notifications. @@ -496,7 +496,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual ErrCode Unsubscribe( - const sptr &subscriber, const sptr &info) = 0; + const sptr &subscriber, const sptr &info) = 0; /** * @brief Checks whether this device is allowed to publish notifications. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index a3f8d7e7409f8b72512215551dd7f6b0fa2872ad..9b658694ce656f70b59730a985143310ad88af45 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -446,7 +446,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode Subscribe(const sptr &subscriber, + ErrCode Subscribe(const sptr &subscriber, const sptr &info) override; /** @@ -456,7 +456,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SubscribeSelf(const sptr &subscriber) override; + ErrCode SubscribeSelf(const sptr &subscriber) override; /** * @brief Subscribes notifications. @@ -475,7 +475,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode Unsubscribe(const sptr &subscriber, + ErrCode Unsubscribe(const sptr &subscriber, const sptr &info) override; /** diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 516f4ff64e1ed6084cd52c9c63927f1005174ba0..21a4745b3e0694845886006fe8ddb5a9d84afa7f 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -452,7 +452,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual ErrCode Subscribe( - const sptr &subscriber, const sptr &info) override; + const sptr &subscriber, const sptr &info) override; /** * @brief Subscribes notifications self. @@ -460,7 +460,7 @@ public: * @param subscriber Indicates the subscriber. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SubscribeSelf(const sptr &subscriber) override; + virtual ErrCode SubscribeSelf(const sptr &subscriber) override; virtual ErrCode SubscribeLocalLiveView( const sptr &subscriber, @@ -474,7 +474,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual ErrCode Unsubscribe( - const sptr &subscriber, const sptr &info) override; + const sptr &subscriber, const sptr &info) override; /** * @brief Checks whether this device is allowed to publish notifications. diff --git a/frameworks/core/include/ans_subscriber_interface.h b/frameworks/core/include/ans_subscriber_interface.h deleted file mode 100644 index 9a512c28a8268774eac4c3d5e8d02e66ba1b86c3..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_interface.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2021-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_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_INTERFACE_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_INTERFACE_H - -#include "iremote_broker.h" - -#include "badge_number_callback_data.h" -#include "enabled_notification_callback_data.h" -#include "notification.h" -#include "notification_constant.h" -#include "notification_do_not_disturb_date.h" -#include "notification_request.h" -#include "notification_sorting.h" -#include "notification_sorting_map.h" -#include "notification_operation_info.h" - -namespace OHOS { -namespace Notification { -class AnsSubscriberInterface : public IRemoteBroker { -public: - AnsSubscriberInterface() = default; - virtual ~AnsSubscriberInterface() override = default; - DISALLOW_COPY_AND_MOVE(AnsSubscriberInterface); - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberInterface"); - - /** - * @brief The callback function for the subscriber to establish a connection. - */ - virtual void OnConnected() = 0; - - /** - * @brief The callback function for subscriber disconnected. - */ - virtual void OnDisconnected() = 0; - - /** - * @brief The callback function on a notification published. - * - * @param notification Indicates the consumed notification. - * @param notificationMap Indicates the NotificationSortingMap object. - */ - virtual void OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) = 0; - - virtual void OnConsumedList( - const std::vector> ¬ifications, const sptr ¬ificationMap) = 0; - - /** - * @brief The callback function on a notification canceled. - * - * @param notification Indicates the canceled notification. - * @param notificationMap Indicates the NotificationSortingMap object. - * @param deleteReason Indicates the delete reason. - */ - virtual void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, - int32_t deleteReason) = 0; - - virtual void OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) = 0; - - /** - * @brief The callback function on the notifications updated. - * - * @param notificationMap Indicates the NotificationSortingMap object. - */ - virtual void OnUpdated(const sptr ¬ificationMap) = 0; - - /** - * @brief The callback function on the do not disturb date changed. - * - * @param date Indicates the NotificationDoNotDisturbDate object. - */ - virtual void OnDoNotDisturbDateChange(const sptr &date) = 0; - - /** - * @brief The callback function on the notification enabled flag changed. - * - * @param callbackData Indicates the EnabledNotificationCallbackData object. - */ - virtual void OnEnabledNotificationChanged(const sptr &callbackData) = 0; - - /** - * @brief The callback function on the badge number changed. - * - * @param badgeData Indicates the BadgeNumberCallbackData object. - */ - virtual void OnBadgeChanged(const sptr &badgeData) = 0; - - /** - * @brief The callback function on the badge enabled state changed. - * - * @param callbackData Indicates the EnabledNotificationCallbackData object. - */ - virtual void OnBadgeEnabledChanged(const sptr &callbackData) = 0; - - virtual void OnApplicationInfoNeedChanged(const std::string& bundleName) = 0; - - /** - * @brief The callback function on the response. - * - * @param notification Indicates the received Notification object. - */ - virtual ErrCode OnOperationResponse(const sptr& operationInfo) = 0; -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_INTERFACE_H diff --git a/frameworks/core/include/ans_subscriber_listener.h b/frameworks/core/include/ans_subscriber_listener.h index d30fa5b2a0a2d12e31d3f363860e11bf9e69e2c3..2ae48915576dc5c1e84a781126eb378fb455f3bd 100644 --- a/frameworks/core/include/ans_subscriber_listener.h +++ b/frameworks/core/include/ans_subscriber_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -30,38 +30,52 @@ public: SubscriberListener(const std::shared_ptr &subscriber); ~SubscriberListener(); - void OnConnected() override; + ErrCode OnConnected() override; - void OnDisconnected() override; + ErrCode OnDisconnected() override; - void OnConsumed( + ErrCode OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; - void OnConsumedList(const std::vector> ¬ifications, + ErrCode OnConsumed(const sptr ¬ification) override; + + ErrCode OnConsumedWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap) override; + + ErrCode OnConsumedWithMaxCapacity(const sptr ¬ification) override; + + ErrCode OnConsumedList(const std::vector> ¬ifications, const sptr ¬ificationMap) override; - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, + ErrCode OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) override; - void OnCanceledList(const std::vector> ¬ifications, + ErrCode OnCanceled(const sptr ¬ification, int32_t deleteReason) override; + + ErrCode OnCanceledWithMaxCapacity(const sptr ¬ification, + const sptr ¬ificationMap, int32_t deleteReason) override; + + ErrCode OnCanceledWithMaxCapacity(const sptr ¬ification, int32_t deleteReason) override; + + ErrCode OnCanceledList(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason) override; void OnBatchCanceled(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason); - void OnUpdated(const sptr ¬ificationMap) override; + ErrCode OnUpdated(const sptr ¬ificationMap) override; - void OnDoNotDisturbDateChange(const sptr &date) override; + ErrCode OnDoNotDisturbDateChange(const sptr &date) override; - void OnEnabledNotificationChanged(const sptr &callbackData) override; + ErrCode OnEnabledNotificationChanged(const sptr &callbackData) override; - void OnBadgeChanged(const sptr &badgeData) override; + ErrCode OnBadgeChanged(const sptr &badgeData) override; - void OnBadgeEnabledChanged(const sptr &callbackData) override; + ErrCode OnBadgeEnabledChanged(const sptr &callbackData) override; - void OnApplicationInfoNeedChanged(const std::string& bundleName) override; + ErrCode OnApplicationInfoNeedChanged(const std::string& bundleName) override; - ErrCode OnOperationResponse(const sptr& operationInfo) override; + ErrCode OnOperationResponse(const sptr& operationInfo, int32_t& funcResult) override; public: std::weak_ptr subscriber_; diff --git a/frameworks/core/include/ans_subscriber_proxy.h b/frameworks/core/include/ans_subscriber_proxy.h deleted file mode 100644 index 0fdfc332faa0b7d6d64bb30f4211c10efef867be..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_proxy.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2021-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_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_PROXY_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_PROXY_H - -#include "ans_subscriber_interface.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace Notification { -class AnsSubscriberProxy : public IRemoteProxy { -public: - AnsSubscriberProxy() = delete; - explicit AnsSubscriberProxy(const sptr &impl); - ~AnsSubscriberProxy() override; - DISALLOW_COPY_AND_MOVE(AnsSubscriberProxy); - - /** - * @brief The callback function for the subscriber to establish a connection. - */ - void OnConnected() override; - - /** - * @brief The callback function for subscriber disconnected. - */ - void OnDisconnected() override; - - /** - * @brief The callback function on a notification published. - * - * @param notification Indicates the consumed notification. - * @param notificationMap Indicates the NotificationSortingMap object. - */ - void OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) override; - - void OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) override; - - /** - * @brief The callback function on a notification canceled. - * - * @param notification Indicates the canceled notification. - * @param deleteReason Indicates the delete reason. - */ - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, - int32_t deleteReason) override; - - void OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) override; - - /** - * @brief The callback function on the notifications updated. - * - * @param notificationMap Indicates the NotificationSortingMap object. - */ - void OnUpdated(const sptr ¬ificationMap) override; - - /** - * @brief The callback function on the do not disturb date changed. - * - * @param date Indicates the NotificationDoNotDisturbDate object. - */ - void OnDoNotDisturbDateChange(const sptr &date) override; - - /** - * @brief The callback function on the notification enabled flag changed. - * - * @param callbackData Indicates the EnabledNotificationCallbackData object. - */ - void OnEnabledNotificationChanged(const sptr &callbackData) override; - - /** - * @brief The callback function on the badge number changed. - * - * @param badgeData Indicates the BadgeNumberCallbackData object. - */ - void OnBadgeChanged(const sptr &badgeData) override; - - /** - * @brief The callback function on the badge enabled state changed. - * - * @param callbackData Indicates the EnabledNotificationCallbackData object. - */ - void OnBadgeEnabledChanged(const sptr &callbackData) override; - - void OnApplicationInfoNeedChanged(const std::string& bundleName) override; - - /** - * @brief The callback function on the response. - * - * @param notification Indicates the received Notification object. - */ - ErrCode OnOperationResponse(const sptr& operationInfo) override; - -private: - ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, - MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator delegator_; - - template - bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) - { - if (!data.WriteInt32(parcelableVector.size())) { - ANS_LOGE("write ParcelableVector size failed"); - return false; - } - - for (auto &parcelable : parcelableVector) { - if (!data.WriteStrongParcelable(parcelable)) { - ANS_LOGE("write ParcelableVector failed"); - return false; - } - } - return true; - } -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_PROXY_H diff --git a/frameworks/core/include/ans_subscriber_stub.h b/frameworks/core/include/ans_subscriber_stub.h deleted file mode 100644 index 1c81f61bc862f0ad976b9d3cd3860ab172b448f6..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_stub.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2021-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_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H - -#include "ans_subscriber_interface.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace Notification { -class AnsSubscriberStub : public IRemoteStub { -public: - AnsSubscriberStub(); - ~AnsSubscriberStub() override; - DISALLOW_COPY_AND_MOVE(AnsSubscriberStub); - - /** - * @brief Handle remote request. - * - * @param data Indicates the input parcel. - * @param reply Indicates the output parcel. - * @param option Indicates the message option. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int32_t OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - - /** - * @brief The callback function for the subscriber to establish a connection. - */ - void OnConnected() override; - - /** - * @brief The callback function for subscriber disconnected. - */ - void OnDisconnected() override; - - /** - * @brief The callback function on a notification published. - * - * @param notification Indicates the consumed notification. - * @param notificationMap Indicates the NotificationSortingMap object. - */ - void OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) override; - - void OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) override; - - /** - * @brief The callback function on a notification canceled. - * - * @param notification Indicates the canceled notification. - * @param notificationMap Indicates the NotificationSortingMap object. - * @param deleteReason Indicates the delete reason. - */ - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, - int32_t deleteReason) override; - - void OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) override; - - /** - * @brief The callback function on the notifications updated. - * - * @param notificationMap Indicates the NotificationSortingMap object. - */ - void OnUpdated(const sptr ¬ificationMap) override; - - /** - * @brief The callback function on the do not disturb date changed. - * - * @param date Indicates the NotificationDoNotDisturbDate object. - */ - void OnDoNotDisturbDateChange(const sptr &date) override; - - /** - * @brief The callback function on the notification enabled flag changed. - * - * @param callbackData Indicates the EnabledNotificationCallbackData object. - */ - void OnEnabledNotificationChanged(const sptr &callbackData) override; - - /** - * @brief The callback function on the badge number changed. - * - * @param badgeData Indicates the BadgeNumberCallbackData object. - */ - void OnBadgeChanged(const sptr &badgeData) override; - - /** - * @brief The callback function on the badge enabled state changed. - * - * @param callbackData Indicates the EnabledNotificationCallbackData object. - */ - void OnBadgeEnabledChanged(const sptr &callbackData) override; - - void OnApplicationInfoNeedChanged(const std::string& bundleName) override; - - /** - * @brief The callback function on the response. - * - * @param notification Indicates the received Notification object. - */ - ErrCode OnOperationResponse(const sptr& operationInfo) override; - -private: - - ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnDoNotDisturbDateChange(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnEnabledNotificationChanged(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnBadgeChanged(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnBadgeEnabledChanged(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnApplicationInfoNeedChanged(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnResponse(MessageParcel &data, MessageParcel &reply); - - template - bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data); -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H diff --git a/frameworks/core/src/listener/ans_subscriber_listener.cpp b/frameworks/core/src/listener/ans_subscriber_listener.cpp index f3594628365a6d9658a966db69c24a1902c03c3d..466683cf6e6f67ce629474f8b2bd0003a3691978 100644 --- a/frameworks/core/src/listener/ans_subscriber_listener.cpp +++ b/frameworks/core/src/listener/ans_subscriber_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -28,66 +28,86 @@ SubscriberListener::SubscriberListener(const std::shared_ptrOnConnected(); + return ERR_OK; } -void SubscriberListener::OnDisconnected() +ErrCode SubscriberListener::OnDisconnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnDisconnected(); + return ERR_OK; } -void SubscriberListener::OnConsumed( +ErrCode SubscriberListener::OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } std::shared_ptr sharedNotification = std::make_shared(*notification); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED if (!subscriber->ProcessSyncDecision(subscriber->GetDeviceType(), sharedNotification)) { - return; + return ERR_INVALID_OPERATION; } #endif subscriber->OnConsumed( sharedNotification, std::make_shared(*notificationMap)); + return ERR_OK; } -void SubscriberListener::OnConsumedList(const std::vector> ¬ifications, +ErrCode SubscriberListener::OnConsumed(const sptr ¬ification) +{ + return OnConsumed(notification, nullptr); +} + +ErrCode SubscriberListener::OnConsumedWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap) +{ + return OnConsumed(notification, notificationMap); +} + +ErrCode SubscriberListener::OnConsumedWithMaxCapacity(const sptr ¬ification) +{ + return OnConsumed(notification, nullptr); +} + +ErrCode SubscriberListener::OnConsumedList(const std::vector> ¬ifications, const sptr ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); for (auto notification : notifications) { OnConsumed(notification, notificationMap); } + return ERR_OK; } -void SubscriberListener::OnCanceled( +ErrCode SubscriberListener::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } if (notificationMap == nullptr) { subscriber->OnCanceled(std::make_shared(*notification), @@ -96,6 +116,23 @@ void SubscriberListener::OnCanceled( subscriber->OnCanceled(std::make_shared(*notification), std::make_shared(*notificationMap), deleteReason); } + return ERR_OK; +} + +ErrCode SubscriberListener::OnCanceled(const sptr ¬ification, int32_t deleteReason) +{ + return OnCanceled(notification, nullptr, deleteReason); +} + +ErrCode SubscriberListener::OnCanceledWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) +{ + return OnCanceled(notification, notificationMap, deleteReason); +} + +ErrCode SubscriberListener::OnCanceledWithMaxCapacity(const sptr ¬ification, int32_t deleteReason) +{ + return OnCanceled(notification, nullptr, deleteReason); } void SubscriberListener::OnBatchCanceled(const std::vector> ¬ifications, @@ -119,92 +156,100 @@ void SubscriberListener::OnBatchCanceled(const std::vector> & } } -void SubscriberListener::OnCanceledList(const std::vector> ¬ifications, +ErrCode SubscriberListener::OnCanceledList(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } if (subscriber->HasOnBatchCancelCallback()) { OnBatchCanceled(notifications, notificationMap, deleteReason); - return; + return ERR_INVALID_DATA; } for (auto notification : notifications) { OnCanceled(notification, notificationMap, deleteReason); } + return ERR_OK; } -void SubscriberListener::OnUpdated(const sptr ¬ificationMap) +ErrCode SubscriberListener::OnUpdated(const sptr ¬ificationMap) { auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnUpdate(std::make_shared(*notificationMap)); + return ERR_OK; } -void SubscriberListener::OnDoNotDisturbDateChange(const sptr &date) +ErrCode SubscriberListener::OnDoNotDisturbDateChange(const sptr &date) { auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnDoNotDisturbDateChange(std::make_shared(*date)); + return ERR_OK; } -void SubscriberListener::OnEnabledNotificationChanged( +ErrCode SubscriberListener::OnEnabledNotificationChanged( const sptr &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnEnabledNotificationChanged(std::make_shared(*callbackData)); + return ERR_OK; } -void SubscriberListener::OnBadgeChanged(const sptr &badgeData) +ErrCode SubscriberListener::OnBadgeChanged(const sptr &badgeData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnBadgeChanged(std::make_shared(*badgeData)); + return ERR_OK; } -void SubscriberListener::OnBadgeEnabledChanged( +ErrCode SubscriberListener::OnBadgeEnabledChanged( const sptr &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnBadgeEnabledChanged(callbackData); + return ERR_OK; } -void SubscriberListener::OnApplicationInfoNeedChanged(const std::string& bundleName) +ErrCode SubscriberListener::OnApplicationInfoNeedChanged(const std::string& bundleName) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGW("OnApplicationInfoNeedChanged SubscriberListener 1."); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGE("Subscriber is nullptr"); - return; + return ERR_INVALID_DATA; } subscriber->OnApplicationInfoNeedChanged(bundleName); + return ERR_OK; } -ErrCode SubscriberListener::OnOperationResponse(const sptr& operationInfo) +ErrCode SubscriberListener::OnOperationResponse( + const sptr& operationInfo, int32_t& funcResult) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); @@ -214,7 +259,8 @@ ErrCode SubscriberListener::OnOperationResponse(const sptr sharedNotification = std::make_shared(*operationInfo); - return subscriber->OnOperationResponse(sharedNotification); + funcResult = subscriber->OnOperationResponse(sharedNotification); + return funcResult; } } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/listener/ans_subscriber_proxy.cpp b/frameworks/core/src/listener/ans_subscriber_proxy.cpp deleted file mode 100644 index e1ba775b82efc7fcbcfd23b58ce99e314be5f23c..0000000000000000000000000000000000000000 --- a/frameworks/core/src/listener/ans_subscriber_proxy.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/* - * Copyright (c) 2021-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 "ans_subscriber_proxy.h" - -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "message_option.h" -#include "message_parcel.h" - -namespace OHOS { -namespace Notification { -AnsSubscriberProxy::AnsSubscriberProxy(const sptr &impl) : IRemoteProxy(impl) -{} - -AnsSubscriberProxy::~AnsSubscriberProxy() -{} - -ErrCode AnsSubscriberProxy::InnerTransact( - NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply) -{ - auto remote = Remote(); - if (remote == nullptr) { - ANS_LOGE("[InnerTransact] fail: get Remote fail code %{public}u", code); - return ERR_DEAD_OBJECT; - } - - int32_t err = remote->SendRequest(static_cast(code), data, reply, flags); - switch (err) { - case NO_ERROR: { - return ERR_OK; - } - case DEAD_OBJECT: { - ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code); - return ERR_DEAD_OBJECT; - } - default: { - ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code); - return ERR_ANS_TRANSACT_FAILED; - } - } -} - -void AnsSubscriberProxy::OnConnected() -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnConnected] fail: write interface token failed."); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONNECTED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnConnected] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnDisconnected() -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnDisconnected] fail: write interface token failed."); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_DISCONNECTED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnDisconnected] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) -{ - if (notification == nullptr) { - ANS_LOGE("[OnConsumed] fail: notification is nullptr."); - return; - } - - MessageParcel data; - if (notification->GetNotificationRequestPoint()->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnConsumed] fail: set max capacity failed."); - return; - } - } - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnConsumed] fail: write interface token failed."); - return; - } - - if (!data.WriteParcelable(notification)) { - ANS_LOGE("[OnConsumed] fail: write notification failed."); - return; - } - - if (!data.WriteBool(notificationMap != nullptr)) { - ANS_LOGE("[OnConsumed] fail: write existMap failed"); - return; - } - - if (notificationMap != nullptr) { - if (!data.WriteParcelable(notificationMap)) { - ANS_LOGE("[OnConsumed] fail: write notificationMap failed"); - return; - } - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONSUMED_MAP, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnConsumed] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) -{ - ANS_LOGD("Start consumed list in proxy."); - if (notifications.empty() || notificationMap == nullptr) { - ANS_LOGE("Invalid notification to consumed."); - return; - } - - MessageParcel data; - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnConsumedList] fail: set max capacity failed."); - } - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return; - } - - if (!WriteParcelableVector(notifications, data)) { - ANS_LOGE("Write notifications failed"); - return; - } - - if (!data.WriteBool(notificationMap != nullptr)) { - ANS_LOGE("Write existMap failed"); - return; - } - - if (notificationMap != nullptr) { - if (!data.WriteParcelable(notificationMap)) { - ANS_LOGE("Write notificationMap failed"); - return; - } - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONSUMED_LIST_MAP, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("Transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnCanceled( - const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) -{ - if (notification == nullptr) { - ANS_LOGE("[OnCanceled] fail: notification is nullptr."); - return; - } - - MessageParcel data; - if (notification->GetNotificationRequestPoint()->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnCanceled] fail: set max capacity failed."); - return; - } - } - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnCanceled] fail: write interface token failed."); - return; - } - - if (!data.WriteParcelable(notification)) { - ANS_LOGE("[OnCanceled] fail: write notification failed."); - return; - } - - if (!data.WriteBool(notificationMap != nullptr)) { - ANS_LOGE("[OnCanceled] fail: write existMap failed"); - return; - } - - if (notificationMap != nullptr) { - if (!data.WriteParcelable(notificationMap)) { - ANS_LOGE("[OnCanceled] fail: write notificationMap failed"); - return; - } - } - - if (!data.WriteInt32(deleteReason)) { - ANS_LOGE("[OnCanceled] fail: write deleteReason failed."); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CANCELED_MAP, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnCanceled] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) -{ - if (notifications.empty()) { - ANS_LOGE("Notifications is empty."); - return; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return; - } - - for (size_t i = 0; i < notifications.size(); i ++) { - sptr notification = notifications[i]; - notification->GetNotificationRequestPoint()->SetBigIcon(nullptr); - notification->GetNotificationRequestPoint()->SetLittleIcon(nullptr); - notification->GetNotificationRequestPoint()->SetOverlayIcon(nullptr); - } - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnConsumedList] fail: set max capacity failed."); - } - if (!WriteParcelableVector(notifications, data)) { - ANS_LOGE("Write notifications failed"); - return; - } - - if (!data.WriteBool(notificationMap != nullptr)) { - ANS_LOGE("Write existMap failed"); - return; - } - - if (notificationMap != nullptr) { - if (!data.WriteParcelable(notificationMap)) { - ANS_LOGE("Write notificationMap failed"); - return; - } - } - - if (!data.WriteInt32(deleteReason)) { - ANS_LOGE("Write deleteReason failed."); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CANCELED_LIST_MAP, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("Transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnUpdated(const sptr ¬ificationMap) -{ - if (notificationMap == nullptr) { - ANS_LOGE("[OnUpdated] fail: notificationMap is empty."); - return; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnUpdated] fail: write interface token failed."); - return; - } - - if (!data.WriteParcelable(notificationMap)) { - ANS_LOGE("[OnUpdated] fail: write notificationMap failed."); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_UPDATED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnUpdated] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnDoNotDisturbDateChange(const sptr &date) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnDoNotDisturbDateChange] fail: write interface token failed."); - return; - } - - if (!data.WriteParcelable(date)) { - ANS_LOGE("[OnDoNotDisturbDateChange] fail: write date failed"); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_DND_DATE_CHANGED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnDoNotDisturbDateChange] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnEnabledNotificationChanged(const sptr &callbackData) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnEnabledNotificationChanged] fail: write interface token failed."); - return; - } - - if (!data.WriteParcelable(callbackData)) { - ANS_LOGE("[OnEnabledNotificationChanged] fail: write callbackData failed"); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_ENABLED_NOTIFICATION_CHANGED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnEnabledNotificationChanged] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnBadgeChanged(const sptr &badgeData) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("[OnBadgeChanged] fail: write interface token failed."); - return; - } - - if (!data.WriteParcelable(badgeData)) { - ANS_LOGE("[OnBadgeChanged] fail: write badgeData failed"); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_BADGE_CHANGED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnBadgeChanged] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} - -void AnsSubscriberProxy::OnBadgeEnabledChanged(const sptr &callbackData) -{ - if (callbackData == nullptr) { - ANS_LOGE("Callback data is nullptr."); - return; - } - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return; - } - - if (!data.WriteParcelable(callbackData)) { - ANS_LOGE("Write callback data failed."); - return; - } - - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_BADGE_ENABLED_CHANGED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("Transact error code is: %{public}d.", result); - return; - } -} - -void AnsSubscriberProxy::OnApplicationInfoNeedChanged(const std::string& bundleName) -{ - MessageParcel data; - ANS_LOGE("OnApplicationInfoNeedChanged AnsSubscriberProxy 1."); - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return; - } - - if (!data.WriteString(bundleName)) { - ANS_LOGE("Write bundleName failed."); - return; - } - - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_APPLICATION_INFO_NEED_CHANGED, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("Transact error code is: %{public}d.", result); - return; - } -} - -ErrCode AnsSubscriberProxy::OnOperationResponse(const sptr& operationInfo) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (!data.WriteParcelable(operationInfo)) { - ANS_LOGE("Write operationInfo failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_RESPONSE_LISTENER, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("Transact error code is: %{public}d.", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANS_LOGE("AnsSubscriberProxy onresponse fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/core/src/listener/ans_subscriber_stub.cpp b/frameworks/core/src/listener/ans_subscriber_stub.cpp deleted file mode 100644 index ce1ebf68d1588037a6b9dc449da2ead9f937a541..0000000000000000000000000000000000000000 --- a/frameworks/core/src/listener/ans_subscriber_stub.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2021-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 "ans_subscriber_stub.h" - -#include "ans_const_define.h" -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "message_option.h" -#include "message_parcel.h" -#include "parcel.h" - -namespace OHOS { -namespace Notification { -AnsSubscriberStub::AnsSubscriberStub() {} - -AnsSubscriberStub::~AnsSubscriberStub() {} - -int32_t AnsSubscriberStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &flags) -{ - std::u16string descriptor = AnsSubscriberStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - ANS_LOGE("[OnRemoteRequest] fail: invalid interface token!"); - return OBJECT_NULL; - } - ErrCode result = NO_ERROR; - switch (code) { - case static_cast(NotificationInterfaceCode::ON_CONNECTED): { - result = HandleOnConnected(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_DISCONNECTED): { - result = HandleOnDisconnected(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_CONSUMED_MAP): { - result = HandleOnConsumedMap(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_CONSUMED_LIST_MAP): { - result = HandleOnConsumedListMap(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_CANCELED_MAP): { - result = HandleOnCanceledMap(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_CANCELED_LIST_MAP): { - result = HandleOnCanceledListMap(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_UPDATED): { - result = HandleOnUpdated(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_DND_DATE_CHANGED): { - result = HandleOnDoNotDisturbDateChange(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_ENABLED_NOTIFICATION_CHANGED): { - result = HandleOnEnabledNotificationChanged(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_BADGE_CHANGED): { - result = HandleOnBadgeChanged(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_BADGE_ENABLED_CHANGED): { - result = HandleOnBadgeEnabledChanged(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_APPLICATION_INFO_NEED_CHANGED): { - result = HandleOnApplicationInfoNeedChanged(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::ON_RESPONSE_LISTENER): { - result = HandleOnResponse(data, reply); - break; - } - default: { - ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); - } - } - return result; -} - -ErrCode AnsSubscriberStub::HandleOnConnected(MessageParcel &data, MessageParcel &reply) -{ - OnConnected(); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnDisconnected(MessageParcel &data, MessageParcel &reply) -{ - OnDisconnected(); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply) -{ - sptr notification = data.ReadParcelable(); - if (!notification) { - ANS_LOGW("[HandleOnConsumedMap] fail: notification ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - bool existMap = false; - if (!data.ReadBool(existMap)) { - ANS_LOGW("[HandleOnConsumedMap] fail: read existMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr notificationMap = nullptr; - if (existMap) { - notificationMap = data.ReadParcelable(); - if (notificationMap == nullptr) { - ANS_LOGW("[HandleOnConsumedMap] fail: read NotificationSortingMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - OnConsumed(notification, notificationMap); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply) -{ - ANS_LOGD("Start handle notifications in consumed list."); - - std::vector> notifications; - if (!ReadParcelableVector(notifications, data)) { - ANS_LOGE("read notifications failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - bool existMap = false; - if (!data.ReadBool(existMap)) { - ANS_LOGE("read existMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr notificationMap = nullptr; - if (existMap) { - notificationMap = data.ReadParcelable(); - if (notificationMap == nullptr) { - ANS_LOGE("read NotificationSortingMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - OnConsumedList(notifications, notificationMap); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply) -{ - sptr notification = data.ReadParcelable(); - if (!notification) { - ANS_LOGE("[HandleOnCanceledMap] fail: notification ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - bool existMap = false; - if (!data.ReadBool(existMap)) { - ANS_LOGE("[HandleOnCanceledMap] fail: read existMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr notificationMap = nullptr; - if (existMap) { - notificationMap = data.ReadParcelable(); - if (notificationMap == nullptr) { - ANS_LOGE("[HandleOnCanceledMap] fail: read NotificationSortingMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - int32_t reason = 0; - if (!data.ReadInt32(reason)) { - ANS_LOGE("[HandleOnCanceledMap] fail: read reason failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - OnCanceled(notification, notificationMap, reason); - return ERR_OK; -} - - -ErrCode AnsSubscriberStub::HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply) -{ - std::vector> notifications; - if (!ReadParcelableVector(notifications, data)) { - ANS_LOGE("read notifications failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - bool existMap = false; - if (!data.ReadBool(existMap)) { - ANS_LOGE("read existMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr notificationMap = nullptr; - if (existMap) { - notificationMap = data.ReadParcelable(); - if (notificationMap == nullptr) { - ANS_LOGE("read NotificationSortingMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - int32_t reason = 0; - if (!data.ReadInt32(reason)) { - ANS_LOGE("read reason failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - OnCanceledList(notifications, notificationMap, reason); - return ERR_OK; -} - - -template -bool AnsSubscriberStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - ANS_LOGE("read infoSize failed"); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadStrongParcelable(); - if (info == nullptr) { - ANS_LOGE("read Parcelable infos failed."); - return false; - } - parcelableInfos.emplace_back(info); - } - - return true; -} - -ErrCode AnsSubscriberStub::HandleOnUpdated(MessageParcel &data, MessageParcel &reply) -{ - sptr notificationMap = data.ReadParcelable(); - if (!notificationMap) { - ANS_LOGE("[HandleOnUpdated] fail: notificationMap ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - OnUpdated(notificationMap); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnDoNotDisturbDateChange(MessageParcel &data, MessageParcel &reply) -{ - sptr date = data.ReadParcelable(); - if (!date) { - ANS_LOGE("[HandleOnDoNotDisturbDateChange] fail: date ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - OnDoNotDisturbDateChange(date); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnEnabledNotificationChanged(MessageParcel &data, MessageParcel &reply) -{ - sptr callbackData = data.ReadParcelable(); - if (!callbackData) { - ANS_LOGE("[HandleOnEnabledNotificationChanged] fail: callbackData ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - OnEnabledNotificationChanged(callbackData); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnBadgeChanged(MessageParcel &data, MessageParcel &reply) -{ - sptr callbackData = data.ReadParcelable(); - if (!callbackData) { - ANS_LOGE("[HandleOnBadgeChanged] fail: callbackData ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - OnBadgeChanged(callbackData); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnBadgeEnabledChanged(MessageParcel &data, MessageParcel &reply) -{ - sptr callbackData = data.ReadParcelable(); - if (callbackData == nullptr) { - ANS_LOGE("Read callback data failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - OnBadgeEnabledChanged(callbackData); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnApplicationInfoNeedChanged(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName; - if (!data.ReadString(bundleName)) { - ANS_LOGE("[HandleGetAllDistribuedEnabledBundles] fail: read deviceType failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - OnApplicationInfoNeedChanged(bundleName); - return ERR_OK; -} - -ErrCode AnsSubscriberStub::HandleOnResponse(MessageParcel &data, MessageParcel &reply) -{ - sptr operationInfo = data.ReadParcelable(); - if (!operationInfo) { - ANS_LOGE("notification ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - ErrCode result = OnOperationResponse(operationInfo); - if (!reply.WriteInt32(result)) { - ANS_LOGE("write result failed, ErrCode=%{public}d", result); - return ERR_ANS_PARCELABLE_FAILED; - } - return ERR_OK; -} - -void AnsSubscriberStub::OnConnected() {} - -void AnsSubscriberStub::OnDisconnected() {} - -void AnsSubscriberStub::OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) -{} - -void AnsSubscriberStub::OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) -{} - -void AnsSubscriberStub::OnCanceled( - const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) -{} - -void AnsSubscriberStub::OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) -{} - -void AnsSubscriberStub::OnUpdated(const sptr ¬ificationMap) {} - -void AnsSubscriberStub::OnDoNotDisturbDateChange(const sptr &date) {} - -void AnsSubscriberStub::OnEnabledNotificationChanged(const sptr &callbackData) {} - -void AnsSubscriberStub::OnBadgeChanged(const sptr &badgeData) {} - -void AnsSubscriberStub::OnBadgeEnabledChanged(const sptr &callbackData) {} - -void AnsSubscriberStub::OnApplicationInfoNeedChanged(const std::string& bundleName) {} - -ErrCode AnsSubscriberStub::OnOperationResponse(const sptr& operationInfo) { return 0; } -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp b/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp index c3ab868e0988924f4020290a99c6e9783796369a..75b4c84652fa7eb66ee053cf4e620684654824c8 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp @@ -155,7 +155,7 @@ ErrCode AnsManagerProxy::RemoveNotifications(const std::vector &key return result; } -ErrCode AnsManagerProxy::Subscribe(const sptr &subscriber, +ErrCode AnsManagerProxy::Subscribe(const sptr &subscriber, const sptr &info) { if (subscriber == nullptr) { @@ -202,7 +202,7 @@ ErrCode AnsManagerProxy::Subscribe(const sptr &subscribe return result; } -ErrCode AnsManagerProxy::SubscribeSelf(const sptr &subscriber) +ErrCode AnsManagerProxy::SubscribeSelf(const sptr &subscriber) { if (subscriber == nullptr) { ANS_LOGE("[SubscribeSelf] fail: subscriber is empty."); @@ -291,7 +291,7 @@ ErrCode AnsManagerProxy::SubscribeLocalLiveView(const sptr &subscriber, const sptr &info) + const sptr &subscriber, const sptr &info) { if (subscriber == nullptr) { ANS_LOGE("[Unsubscribe] fail: subscriber is empty."); diff --git a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp index 684c1c706649fcf9471f794aa0f075224393abde..da265c1433407f277ceecdf77c4e285544fd0ba6 100644 --- a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp @@ -312,14 +312,14 @@ ErrCode AnsManagerStub::GetShowBadgeEnabled(bool &enabled) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::Subscribe(const sptr &subscriber, +ErrCode AnsManagerStub::Subscribe(const sptr &subscriber, const sptr &info) { ANS_LOGE("AnsManagerStub::Subscribe called!"); return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscriber) +ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscriber) { ANS_LOGE("AnsManagerStub::SubscribeSelf called!"); return ERR_INVALID_OPERATION; @@ -332,7 +332,7 @@ ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, +ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, const sptr &info) { ANS_LOGE("AnsManagerStub::Unsubscribe called!"); diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index f8305fd0d5d30f1757c544fd63fea4ef0158fa9c..1cc7baa087461b28750e666e179d7d8578ed14e7 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -23,7 +23,6 @@ group("unittest") { "ans_notification_test:unittest", "ans_subscriber_proxy_branch_test:unittest", "ans_subscriber_proxy_test:unittest", - "ans_subscriber_stub_test:unittest", "swing_callback_test:unittest", ] } diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index 2a56973b06b754339f13f46153daaffa3c7f13de..886be6d9b93f1326937ed323b61229ee1c61462d 100644 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -264,13 +264,13 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode Subscribe(const sptr &subscriber, + ErrCode Subscribe(const sptr &subscriber, const sptr &info) override { return ERR_ANS_INVALID_PARAM; } - ErrCode SubscribeSelf(const sptr &subscriber) override + ErrCode SubscribeSelf(const sptr &subscriber) override { return ERR_ANS_INVALID_PARAM; } @@ -303,7 +303,7 @@ public: } ErrCode Unsubscribe( - const sptr &subscriber, const sptr &info) override + const sptr &subscriber, const sptr &info) override { return ERR_ANS_INVALID_PARAM; } diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp index 831ecb7c3554a1d772acf6b305f91942ab7635f4..a6ca4ec6d8e857bdb949778a03c45f39df33c825 100755 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -121,43 +121,3 @@ HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0300, Function | MediumTes int32_t deleteReason = 1; proxy->OnCanceledList(notifications, notificationMap, deleteReason); } - -/* - * @tc.name: WriteParcelableVector_0100 - * @tc.desc: Test WriteParcelableVector function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, WriteParcelableVector_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, WriteParcelableVector_0100, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - std::vector> notifications; - MessageParcel data; - proxy->WriteParcelableVector(notifications, data); -} - -/* - * @tc.name: WriteParcelableVector_0200 - * @tc.desc: Test WriteParcelableVector function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, WriteParcelableVector_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, WriteParcelableVector_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); - std::vector> notifications; - notifications.emplace_back(notification); - MessageParcel data; - proxy->WriteParcelableVector(notifications, data); -} diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp index 663e2332f5f040085144f8b90e794fea871a0821..3cc8f4a652cb352dc083e45dbd47b520a4012748 100644 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * 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 @@ -54,95 +54,6 @@ void AnsSubscriberProxyUnitTest::SetUp() {} void AnsSubscriberProxyUnitTest::TearDown() {} -/* - * @tc.name: InnerTransactTest_0100 - * @tc.desc: test if AnsSubscriberProxy's InnerTransact function executed as expected in normal case. - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, InnerTransactTest_0100, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(NO_ERROR))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - uint32_t code = 0; - MessageOption flags; - MessageParcel data; - MessageParcel reply; - ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); - EXPECT_EQ(ERR_OK, res); -} - -/* - * @tc.name: InnerTransactTest_0200 - * @tc.desc: test AnsSubscriberProxy's InnerTransact function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, InnerTransactTest_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(DEAD_OBJECT))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - uint32_t code = 0; - MessageOption flags; - MessageParcel data; - MessageParcel reply; - ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); - EXPECT_EQ(ERR_DEAD_OBJECT, res); -} - -/* - * @tc.name: InnerTransactTest_0300 - * @tc.desc: test AnsSubscriberProxy's InnerTransact function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0300, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, InnerTransactTest_0300, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(-1))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - uint32_t code = 0; - MessageOption flags; - MessageParcel data; - MessageParcel reply; - ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); - EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, res); -} - -/* - * @tc.name: InnerTransactTest_0400 - * @tc.desc: test AnsSubscriberProxy's InnerTransact function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0400, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, InnerTransactTest_0400, TestSize.Level1"; - std::shared_ptr proxy = std::make_shared(nullptr); - ASSERT_NE(nullptr, proxy); - uint32_t code = 0; - MessageOption flags; - MessageParcel data; - MessageParcel reply; - ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); - EXPECT_EQ(ERR_DEAD_OBJECT, res); -} - /* * @tc.name: OnConsumed_0400 * @tc.desc: test AnsSubscriberProxy's OnConsumed function @@ -207,7 +118,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0600, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0600, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); @@ -250,7 +161,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0100, Function | MediumTest << "AnsSubscriberProxyBranchTest, OnConsumedList_0100, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; @@ -268,7 +179,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0200, Function | MediumTest << "AnsSubscriberProxyBranchTest, OnConsumedList_0200, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr request = @@ -291,7 +202,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0300, Function | MediumTest << "AnsSubscriberProxyBranchTest, OnConsumedList_0300, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; @@ -388,7 +299,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0600, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnCanceled_0600, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); @@ -473,7 +384,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnOnUpdated_0300, Function | MediumTest | L << "AnsSubscriberProxyUnitTest, OnOnUpdated_0300, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); proxy->OnUpdated(nullptr); @@ -697,7 +608,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0200, TestSize.Level1 { sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0).WillRepeatedly(DoAll(Return(NO_ERROR))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr callbackData = nullptr; diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn deleted file mode 100644 index bfaa8ca29c504cd7d4d5e5721055e2afe47bf602..0000000000000000000000000000000000000000 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2022-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. - -import("//base/notification/distributed_notification_service/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = - "${component_name}/distributed_notification_service/unittest" - -ohos_unittest("ans_subscriber_stub_test") { - module_out_path = module_output_path - include_dirs = [ - "${core_path}/include", - "../mock/", - ] - - sources = [ "ans_subscriber_stub_unit_test.cpp" ] - - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:wantagent_innerkits", - "c_utils:utils", - "googletest:gmock_main", - "hilog:libhilog", - "image_framework:image_native", - "ipc:ipc_single", - "relational_store:native_rdb", - ] - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - -group("unittest") { - testonly = true - deps = [] - - deps += [ ":ans_subscriber_stub_test" ] -} diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp deleted file mode 100644 index 15493b1fb5f8ebc97dee9814214e099620286006..0000000000000000000000000000000000000000 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright (c) 2021-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 - -#define private public -#define protected public -#include "ans_subscriber_stub.h" -#include "ans_subscriber_proxy.h" -#include "ans_inner_errors.h" -#include "ans_notification.h" -#undef private -#undef protected - -#include "message_option.h" -#include "message_parcel.h" -#include "parcel.h" -#include "mock_i_remote_object.h" - -using namespace testing; -using namespace testing::ext; -namespace OHOS { -namespace Notification { -class AnsSubscriberStubUnitTest : public testing::Test { -public: - AnsSubscriberStubUnitTest() {} - - virtual ~AnsSubscriberStubUnitTest() {} - - static void SetUpTestCase(); - - static void TearDownTestCase(); - - void SetUp() override; - - void TearDown() override; - - sptr stub_; -}; - -void AnsSubscriberStubUnitTest::SetUpTestCase() -{ -} - -void AnsSubscriberStubUnitTest::TearDownTestCase() -{ -} - -void AnsSubscriberStubUnitTest::SetUp() -{ - stub_ = new AnsSubscriberStub(); -} - -void AnsSubscriberStubUnitTest::TearDown() -{ -} - -/** -* @tc.name: OnRemoteRequest01 -* @tc.desc: test descriptor check failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest01, Function | MediumTest | Level1) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool bRet = data.WriteInterfaceToken(u"error descriptor"); - EXPECT_TRUE(bRet) << "write token error"; - uint32_t code = static_cast(NotificationInterfaceCode::ON_CONNECTED); - - ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(res, OBJECT_NULL) << "descriptor error"; -} - -/** -* @tc.name: OnRemoteRequest02 -* @tc.desc: test code error -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); - - - uint32_t code = static_cast(static_cast(NotificationInterfaceCode::ON_BADGE_ENABLED_CHANGED) + 1); - - ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); - EXPECT_TRUE(res != NO_ERROR); -} - -/** -* @tc.name: OnRemoteRequest04 -* @tc.desc: test ON_CONNECTED success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest04, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); - uint32_t code = static_cast(NotificationInterfaceCode::ON_CONNECTED); - ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(res, NO_ERROR); -} - -/** -* @tc.name: HandleOnConnected -* @tc.desc: test HandleOnConnected success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConnected, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnConnected(data, reply); - EXPECT_EQ(res, ERR_OK); -} - -/** -* @tc.name: HandleOnDisconnected -* @tc.desc: test HandleOnDisconnected success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDisconnected, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnDisconnected(data, reply); - EXPECT_EQ(res, ERR_OK); -} - -/** -* @tc.name: HandleOnConsumedMap01 -* @tc.desc: test notification failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnConsumedMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedMap02 -* @tc.desc: test read existMap failed -* @tc.type: Fun -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - - ErrCode res = stub_->HandleOnConsumedMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedMap03 -* @tc.desc: test read NotificationSortingMap failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap03, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - bool existMap = true; - data.WriteBool(existMap); - - ErrCode res = stub_->HandleOnConsumedMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedMap04 -* @tc.desc: test HandleOnConsumedMap success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap04, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - bool existMap = true; - data.WriteBool(existMap); - sptr notificationSortingMap = new NotificationSortingMap(); - data.WriteParcelable(notificationSortingMap); - - ErrCode res = stub_->HandleOnConsumedMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedListMap01 -* @tc.desc: test notification failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnConsumedListMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedListMap02 -* @tc.desc: test read existMap failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - std::vector> notifications; - notifications.emplace_back(notification); - - sptr remoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, remoteObject); - std::shared_ptr proxy = std::make_shared(remoteObject); - ASSERT_NE(nullptr, proxy); - bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); - EXPECT_EQ(isWriteNotificationsSucc, true); - - ErrCode res = stub_->HandleOnConsumedListMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedListMap03 -* @tc.desc: test read NotificationSortingMap failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap03, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - std::vector> notifications; - notifications.emplace_back(notification); - - sptr remoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, remoteObject); - std::shared_ptr proxy = std::make_shared(remoteObject); - ASSERT_NE(nullptr, proxy); - bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); - EXPECT_EQ(isWriteNotificationsSucc, true); - - bool existMap = true; - data.WriteBool(existMap); - - ErrCode res = stub_->HandleOnConsumedListMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnConsumedListMap04 -* @tc.desc: test HandleOnConsumedListMap success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap04, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - std::vector> notifications; - notifications.emplace_back(notification); - - sptr remoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, remoteObject); - std::shared_ptr proxy = std::make_shared(remoteObject); - ASSERT_NE(nullptr, proxy); - bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); - EXPECT_EQ(isWriteNotificationsSucc, true); - - bool existMap = true; - data.WriteBool(existMap); - sptr notificationSortingMap = new NotificationSortingMap(); - data.WriteParcelable(notificationSortingMap); - - ErrCode res = stub_->HandleOnConsumedListMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnCanceledMap01 -* @tc.desc: test notification failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnCanceledMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnCanceledMap02 -* @tc.desc: test read existMap failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - - ErrCode res = stub_->HandleOnCanceledMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnCanceledMap03 -* @tc.desc: test read NotificationSortingMap failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap03, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - bool existMap = true; - data.WriteBool(existMap); - - ErrCode res = stub_->HandleOnCanceledMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnCanceledMap04 -* @tc.desc: test read reason failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap04, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - bool existMap = true; - data.WriteBool(existMap); - sptr notificationSortingMap = new NotificationSortingMap(); - data.WriteParcelable(notificationSortingMap); - - ErrCode res = stub_->HandleOnCanceledMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnCanceledMap05 -* @tc.desc: test HandleOnCanceledMap success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap05, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notification = new Notification(); - data.WriteParcelable(notification); - bool existMap = true; - data.WriteBool(existMap); - sptr notificationSortingMap = new NotificationSortingMap(); - data.WriteParcelable(notificationSortingMap); - int32_t reason = 0; - data.WriteInt32(reason); - - ErrCode res = stub_->HandleOnCanceledMap(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnUpdated01 -* @tc.desc: test notificationMap failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnUpdated01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnUpdated(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnUpdated02 -* @tc.desc: test HandleOnUpdated success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnUpdated02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notificationMap = new NotificationSortingMap(); - data.WriteParcelable(notificationMap); - - ErrCode res = stub_->HandleOnUpdated(data, reply); - EXPECT_EQ(res, ERR_OK); -} - -/** -* @tc.name: HandleOnDoNotDisturbDateChange01 -* @tc.desc: test callbackData failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDoNotDisturbDateChange01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnDoNotDisturbDateChange(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnDoNotDisturbDateChange02 -* @tc.desc: test HandleOnDoNotDisturbDateChange success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDoNotDisturbDateChange02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notifcallbackDataication = new EnabledNotificationCallbackData(); - data.WriteParcelable(notifcallbackDataication); - - ErrCode res = stub_->HandleOnDoNotDisturbDateChange(data, reply); - EXPECT_EQ(res, ERR_OK); -} - -/** -* @tc.name: HandleOnEnabledNotificationChanged01 -* @tc.desc: test callbackData failed -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnEnabledNotificationChanged01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnEnabledNotificationChanged(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** -* @tc.name: HandleOnEnabledNotificationChanged02 -* @tc.desc: test HandleOnEnabledNotificationChanged success -* @tc.type: Fun -*/ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnEnabledNotificationChanged02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr notifcallbackDataication = new EnabledNotificationCallbackData(); - data.WriteParcelable(notifcallbackDataication); - - ErrCode res = stub_->HandleOnEnabledNotificationChanged(data, reply); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.name: HandleOnBadgeChanged01 - * @tc.desc: test callbackData failed - * @tc.type: Fun - * @tc.require: #I6C2X9 - */ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnBadgeChanged01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - ErrCode res = stub_->HandleOnBadgeChanged(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandleOnBadgeChanged02 - * @tc.desc: test HandleOnBadgeChanged success - * @tc.type: Fun - * @tc.require: #I6C2X9 - */ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnBadgeChanged02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - sptr badgeData = new BadgeNumberCallbackData(); - data.WriteParcelable(badgeData); - - ErrCode res = stub_->HandleOnBadgeChanged(data, reply); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.name: HandleOnBadgeEnabledChanged01 - * @tc.desc: test HandleOnBadgeEnabledChanged with empty callback data, expect error code ERR_ANS_PARCELABLE_FAILED. - * @tc.type: Fun - */ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnBadgeEnabledChanged01, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - ErrCode res = stub_->HandleOnBadgeChanged(data, reply); - EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandleOnBadgeEnabledChanged02 - * @tc.desc: test HandleOnBadgeEnabledChanged success with valid parameters, expect error code ERR_OK. - * @tc.type: Fun - */ -HWTEST_F(AnsSubscriberStubUnitTest, HandleOnBadgeEnabledChanged02, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - std::string bundleName = "bundleName"; - int32_t uid = 123456; - bool enabled = false; - sptr callbackData = new EnabledNotificationCallbackData(bundleName, uid, enabled); - data.WriteParcelable(callbackData); - ErrCode res = stub_->HandleOnBadgeChanged(data, reply); - EXPECT_EQ(res, ERR_OK); -} -} -} diff --git a/frameworks/reminder/BUILD.gn b/frameworks/reminder/BUILD.gn index 128cdc86c00d3f7d6104fa926c7c61c30e576f70..cad0d54d8848bb7ee9480abd0ff7d20d814f0806 100644 --- a/frameworks/reminder/BUILD.gn +++ b/frameworks/reminder/BUILD.gn @@ -59,6 +59,7 @@ ohos_shared_library("reminder_innerkits") { ":reminder_innerkits_public_config", "${frameworks_path}/ans:ans_innerkits_config", "${frameworks_path}/ans:ans_subscriber_local_live_view_config", + "${frameworks_path}/ans:ans_subscriber_config", ] output_values = get_target_outputs(":reminder_service_interface") sources = [ diff --git a/interfaces/inner_api/notification_subscriber.h b/interfaces/inner_api/notification_subscriber.h index ef339d2a1349453aa3c4215915141b5dd6328320..1f4b43ebb041a0d3250acf226973022d3a8503b8 100644 --- a/interfaces/inner_api/notification_subscriber.h +++ b/interfaces/inner_api/notification_subscriber.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -156,38 +156,52 @@ private: SubscriberImpl(NotificationSubscriber &subscriber); ~SubscriberImpl() {}; - void OnConnected() override; + ErrCode OnConnected() override; - void OnDisconnected() override; + ErrCode OnDisconnected() override; - void OnConsumed( + ErrCode OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; - void OnConsumedList(const std::vector> ¬ifications, + ErrCode OnConsumed(const sptr ¬ification) override; + + ErrCode OnConsumedWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap) override; + + ErrCode OnConsumedWithMaxCapacity(const sptr ¬ification) override; + + ErrCode OnConsumedList(const std::vector> ¬ifications, const sptr ¬ificationMap) override; - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, + ErrCode OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) override; - void OnCanceledList(const std::vector> ¬ifications, + ErrCode OnCanceled(const sptr ¬ification, int32_t deleteReason) override; + + ErrCode OnCanceledWithMaxCapacity(const sptr ¬ification, + const sptr ¬ificationMap, int32_t deleteReason) override; + + ErrCode OnCanceledWithMaxCapacity(const sptr ¬ification, int32_t deleteReason) override; + + ErrCode OnCanceledList(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason) override; void OnBatchCanceled(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason); - void OnUpdated(const sptr ¬ificationMap) override; + ErrCode OnUpdated(const sptr ¬ificationMap) override; - void OnDoNotDisturbDateChange(const sptr &date) override; + ErrCode OnDoNotDisturbDateChange(const sptr &date) override; - void OnEnabledNotificationChanged(const sptr &callbackData) override; + ErrCode OnEnabledNotificationChanged(const sptr &callbackData) override; - void OnBadgeChanged(const sptr &badgeData) override; + ErrCode OnBadgeChanged(const sptr &badgeData) override; - void OnBadgeEnabledChanged(const sptr &callbackData) override; + ErrCode OnBadgeEnabledChanged(const sptr &callbackData) override; - void OnApplicationInfoNeedChanged(const std::string& bundleName) override; + ErrCode OnApplicationInfoNeedChanged(const std::string& bundleName) override; - ErrCode OnOperationResponse(const sptr &operationInfo) override; + ErrCode OnOperationResponse(const sptr &operationInfo, int32_t& funcResult) override; sptr GetAnsManagerProxy(); diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 3d0b0fa52e95285bb0ed28b5f7aadc5f676b507d..31340968d5585f763ec71562f2ece828bcaebe6f 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -523,7 +523,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode Subscribe(const sptr &subscriber, + ErrCode Subscribe(const sptr &subscriber, const sptr &info) override; /** @@ -532,7 +532,7 @@ public: * @param subscriber Indicates the subscriber. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SubscribeSelf(const sptr &subscriber) override; + ErrCode SubscribeSelf(const sptr &subscriber) override; /** * @brief Subscribes notifications. @@ -551,7 +551,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode Unsubscribe(const sptr &subscriber, + ErrCode Unsubscribe(const sptr &subscriber, const sptr &info) override; /** diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index 8da6bcdcb71a13c36b45266e6950311c52d3b04d..61156a03d5279130e7d4ad1e8f802d213fda1011 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -28,7 +28,7 @@ #include "refbase.h" #include "singleton.h" -#include "ans_subscriber_interface.h" +#include "ians_subscriber.h" #include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" @@ -48,7 +48,7 @@ public: * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ - ErrCode AddSubscriber(const sptr &subscriber, + ErrCode AddSubscriber(const sptr &subscriber, const sptr &subscribeInfo); /** @@ -59,7 +59,7 @@ public: * @return Indicates the result code. */ ErrCode RemoveSubscriber( - const sptr &subscriber, const sptr &subscribeInfo); + const sptr &subscriber, const sptr &subscribeInfo); /** * @brief Notify all subscribers on counsumed. @@ -157,16 +157,16 @@ public: private: void NotifyApplicationInfochangedInner(const std::string& bundleName); std::shared_ptr FindSubscriberRecord(const wptr &object); - std::shared_ptr FindSubscriberRecord(const sptr &subscriber); - std::shared_ptr CreateSubscriberRecord(const sptr &subscriber); + std::shared_ptr FindSubscriberRecord(const sptr &subscriber); + std::shared_ptr CreateSubscriberRecord(const sptr &subscriber); void AddRecordInfo( std::shared_ptr &record, const sptr &subscribeInfo); void RemoveRecordInfo( std::shared_ptr &record, const sptr &subscribeInfo); ErrCode AddSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo); + const sptr &subscriber, const sptr &subscribeInfo); ErrCode RemoveSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo); + const sptr &subscriber, const sptr &subscribeInfo); void NotifyConsumedInner( const sptr ¬ification, const sptr ¬ificationMap); @@ -190,7 +190,7 @@ private: std::list> subscriberRecordList_ {}; std::shared_ptr runner_ {}; std::shared_ptr handler_ {}; - sptr ansSubscriberProxy_ {}; + sptr ansSubscriberProxy_ {}; sptr recipient_ {}; std::shared_ptr notificationSubQueue_ = nullptr; std::function &)> onSubscriberAddCallback_ = nullptr; diff --git a/services/ans/src/advanced_notification_subscriber_service.cpp b/services/ans/src/advanced_notification_subscriber_service.cpp index fd7cb707d6a088d07c1402c25d0716bf4bf81353..7f53b43331c43a1a64845972bfb6491d163f97d1 100644 --- a/services/ans/src/advanced_notification_subscriber_service.cpp +++ b/services/ans/src/advanced_notification_subscriber_service.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 @@ -42,7 +42,7 @@ namespace OHOS { namespace Notification { ErrCode AdvancedNotificationService::Subscribe( - const sptr &subscriber, const sptr &info) + const sptr &subscriber, const sptr &info) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s", __FUNCTION__); @@ -81,7 +81,7 @@ ErrCode AdvancedNotificationService::Subscribe( return errCode; } -ErrCode AdvancedNotificationService::SubscribeSelf(const sptr &subscriber) +ErrCode AdvancedNotificationService::SubscribeSelf(const sptr &subscriber) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s", __FUNCTION__); @@ -133,7 +133,7 @@ ErrCode AdvancedNotificationService::SubscribeSelf(const sptr &subscriber, const sptr &info) + const sptr &subscriber, const sptr &info) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s", __FUNCTION__); diff --git a/services/ans/src/ans_manager_stub.cpp b/services/ans/src/ans_manager_stub.cpp index 35e42d0329452cb0b2fc220e40585d3272b20117..64132e5b3facf6274a87582166139eed2c1ee066 100644 --- a/services/ans/src/ans_manager_stub.cpp +++ b/services/ans/src/ans_manager_stub.cpp @@ -1487,7 +1487,7 @@ ErrCode AnsManagerStub::HandleSubscribe(MessageParcel &data, MessageParcel &repl } } - ErrCode result = Subscribe(iface_cast(subscriber), info); + ErrCode result = Subscribe(iface_cast(subscriber), info); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleSubscribe] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1503,7 +1503,7 @@ ErrCode AnsManagerStub::HandleSubscribeSelf(MessageParcel &data, MessageParcel & return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = SubscribeSelf(iface_cast(subscriber)); + ErrCode result = SubscribeSelf(iface_cast(subscriber)); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleSubscribeSelf] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1572,7 +1572,7 @@ ErrCode AnsManagerStub::HandleUnsubscribe(MessageParcel &data, MessageParcel &re } } - ErrCode result = Unsubscribe(iface_cast(subscriber), info); + ErrCode result = Unsubscribe(iface_cast(subscriber), info); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleUnsubscribe] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; diff --git a/services/ans/src/ans_manager_stub_invalid.cpp b/services/ans/src/ans_manager_stub_invalid.cpp index 34b86061e93fb83b3d2dc75914841c48c2dcca55..3167f6f2d8ff73321aab33530468bb5de152e328 100644 --- a/services/ans/src/ans_manager_stub_invalid.cpp +++ b/services/ans/src/ans_manager_stub_invalid.cpp @@ -312,14 +312,14 @@ ErrCode AnsManagerStub::GetShowBadgeEnabled(bool &enabled) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::Subscribe(const sptr &subscriber, +ErrCode AnsManagerStub::Subscribe(const sptr &subscriber, const sptr &info) { ANS_LOGE("AnsManagerStub::Subscribe called!"); return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscriber) +ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscriber) { ANS_LOGE("AnsManagerStub::SubscribeSelf called!"); return ERR_INVALID_OPERATION; @@ -332,7 +332,7 @@ ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, +ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, const sptr &info) { ANS_LOGE("AnsManagerStub::Unsubscribe called!"); diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 151a6fd366d87c2a06d85fa818f5e7f9f1f0fc55..6f12aaa6a6b93256345824fb0243a306e040f1c6 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -39,7 +39,7 @@ namespace OHOS { namespace Notification { struct NotificationSubscriberManager::SubscriberRecord { - sptr subscriber {nullptr}; + sptr subscriber {nullptr}; std::set bundleList_ {}; bool subscribedAll {false}; int32_t userId {SUBSCRIBE_USER_INIT}; @@ -79,7 +79,7 @@ void NotificationSubscriberManager::ResetFfrtQueue() } ErrCode NotificationSubscriberManager::AddSubscriber( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber == nullptr) { @@ -142,7 +142,7 @@ ErrCode NotificationSubscriberManager::AddSubscriber( } ErrCode NotificationSubscriberManager::RemoveSubscriber( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber == nullptr) { @@ -356,7 +356,7 @@ std::shared_ptr NotificationSub } std::shared_ptr NotificationSubscriberManager::FindSubscriberRecord( - const sptr &subscriber) + const sptr &subscriber) { auto iter = subscriberRecordList_.begin(); @@ -369,7 +369,7 @@ std::shared_ptr NotificationSub } std::shared_ptr NotificationSubscriberManager::CreateSubscriberRecord( - const sptr &subscriber) + const sptr &subscriber) { std::shared_ptr record = std::make_shared(); if (record != nullptr) { @@ -426,7 +426,7 @@ void NotificationSubscriberManager::RemoveRecordInfo( } ErrCode NotificationSubscriberManager::AddSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); std::shared_ptr record = FindSubscriberRecord(subscriber); @@ -460,7 +460,7 @@ ErrCode NotificationSubscriberManager::AddSubscriberInner( } ErrCode NotificationSubscriberManager::RemoveSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); std::shared_ptr record = FindSubscriberRecord(subscriber); @@ -512,7 +512,16 @@ void NotificationSubscriberManager::NotifyConsumedInner( record, notification, wearableFlag, headsetFlag, keyNodeFlag); continue; } + + if (notificationMap != nullptr && notification->GetNotificationRequestPoint()->IsCommonLiveView()) { + record->subscriber->OnConsumedWithMaxCapacity(notification, notificationMap); + } else if (notificationMap != nullptr && !notification->GetNotificationRequestPoint()->IsCommonLiveView()) { record->subscriber->OnConsumed(notification, notificationMap); + } else if (notificationMap == nullptr && notification->GetNotificationRequestPoint()->IsCommonLiveView()) { + record->subscriber->OnConsumedWithMaxCapacity(notification); + } else { + record->subscriber->OnConsumed(notification); + } NotificationSubscriberManager::IsDeviceFlag(record, notification, wearableFlag, headsetFlag, keyNodeFlag); } } @@ -590,7 +599,15 @@ void NotificationSubscriberManager::NotifyCanceledInner( for (auto record : subscriberRecordList_) { ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); if (IsSubscribedBysubscriber(record, notification)) { - record->subscriber->OnCanceled(notification, notificationMap, deleteReason); + if (notificationMap != nullptr && notification->GetNotificationRequestPoint()->IsCommonLiveView()) { + record->subscriber->OnCanceledWithMaxCapacity(notification, notificationMap, deleteReason); + } else if (notificationMap != nullptr && !notification->GetNotificationRequestPoint()->IsCommonLiveView()) { + record->subscriber->OnCanceled(notification, notificationMap, deleteReason); + } else if (notificationMap == nullptr && notification->GetNotificationRequestPoint()->IsCommonLiveView()) { + record->subscriber->OnCanceledWithMaxCapacity(notification, deleteReason); + } else { + record->subscriber->OnCanceled(notification, deleteReason); + } } } } @@ -888,13 +905,14 @@ ErrCode NotificationSubscriberManager::DistributeOperation(const sptrsubmit_h(std::bind([&]() { for (const auto& record : subscriberRecordList_) { if (record == nullptr) { continue; } if (record->needNotifyResponse && record->subscriber != nullptr) { - result = record->subscriber->OnOperationResponse(operationInfo); + result = record->subscriber->OnOperationResponse(operationInfo, funcResult); return; } result = ERR_ANS_DISTRIBUTED_OPERATION_FAILED; diff --git a/services/ans/test/unittest/mock/include/mock_ans_subscriber.h b/services/ans/test/unittest/mock/include/mock_ans_subscriber.h index 42c9cc3cdd281ac6ca7b20f16a48c63cb4c752fb..f87247f4716b93a9881bdbe4307c0c98e7e7a101 100644 --- a/services/ans/test/unittest/mock/include/mock_ans_subscriber.h +++ b/services/ans/test/unittest/mock/include/mock_ans_subscriber.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-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,11 +17,11 @@ #define BASE_NOTIFICATION_MOCK_ANS_SUBCRIBER_OBJECT_H #include "gmock/gmock.h" -#include "ans_subscriber_interface.h" +#include "ians_subscriber.h" namespace OHOS { namespace Notification { -class MockAnsSubscriber : public AnsSubscriberInterface { +class MockAnsSubscriber : public IAnsSubscriber { public: MockAnsSubscriber() {} ~MockAnsSubscriber() {} @@ -30,35 +30,56 @@ public: { return nullptr; } - void OnConnected() override {}; + ErrCode OnConnected() override { return ERR_OK; }; - void OnDisconnected() override {}; + ErrCode OnDisconnected() override { return ERR_OK; }; - void OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) override {}; + ErrCode OnConsumed( + const sptr ¬ification, + const sptr ¬ificationMap) override { return ERR_OK; }; - MOCK_METHOD(void, OnConsumedList, (const std::vector> ¬ifications, + ErrCode OnConsumed(const sptr ¬ification) override { return ERR_OK; }; + + ErrCode OnConsumedWithMaxCapacity( + const sptr ¬ification, + const sptr ¬ificationMap) override { return ERR_OK; }; + + ErrCode OnConsumedWithMaxCapacity(const sptr ¬ification) override { return ERR_OK; }; + + MOCK_METHOD(ErrCode, OnConsumedList, (const std::vector> ¬ifications, const sptr ¬ificationMap)); - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, - int32_t deleteReason) override {}; + ErrCode OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, + int32_t deleteReason) override { return ERR_OK; }; + + ErrCode OnCanceled(const sptr ¬ification, int32_t deleteReason) override { return ERR_OK; }; + + ErrCode OnCanceledWithMaxCapacity( + const sptr ¬ification, const sptr ¬ificationMap, + int32_t deleteReason) override { return ERR_OK; }; + + ErrCode OnCanceledWithMaxCapacity( + const sptr ¬ification, int32_t deleteReason) override { return ERR_OK; }; - void OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) override {}; + ErrCode OnCanceledList(const std::vector> ¬ifications, + const sptr ¬ificationMap, int32_t deleteReason) override { return ERR_OK; }; - void OnUpdated(const sptr ¬ificationMap) override {}; + ErrCode OnUpdated(const sptr ¬ificationMap) override { return ERR_OK; }; - void OnDoNotDisturbDateChange(const sptr &date) override {}; + ErrCode OnDoNotDisturbDateChange(const sptr &date) override { return ERR_OK; }; - void OnEnabledNotificationChanged(const sptr &callbackData) override {}; + ErrCode OnEnabledNotificationChanged( + const sptr &callbackData) override { return ERR_OK; }; - void OnBadgeChanged(const sptr &badgeData) override {}; + ErrCode OnBadgeChanged(const sptr &badgeData) override { return ERR_OK; }; - void OnBadgeEnabledChanged(const sptr &callbackData) override {}; + ErrCode OnBadgeEnabledChanged( + const sptr &callbackData) override { return ERR_OK; }; - void OnApplicationInfoNeedChanged(const std::string& bundleName) override {}; + ErrCode OnApplicationInfoNeedChanged(const std::string& bundleName) override { return ERR_OK; }; - ErrCode OnOperationResponse(const sptr& operationInfo) { return 0; } + ErrCode OnOperationResponse( + const sptr& operationInfo, int32_t& funcResult) override { return 0; } }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp index 5adfd6448d5e7e04138d25d0110581342609a53f..56a7780fbde7d6a9f3729cf1f5a4ac98dde72eff 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -164,7 +164,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_ HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00800, Function | SmallTest | Level1) { NotificationSubscriberManager notificationSubscriberManager; - sptr subscriber = nullptr; + sptr subscriber = nullptr; sptr subscribeInfo = nullptr; ASSERT_EQ(ERR_ANS_INVALID_PARAM, notificationSubscriberManager.RemoveSubscriberInner(subscriber, subscribeInfo)); } @@ -598,7 +598,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02 */ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02400, Function | SmallTest | Level1) { - sptr subscriber = nullptr; + sptr subscriber = nullptr; sptr info = nullptr; MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); diff --git a/services/ans/test/unittest/notification_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_test.cpp index 1a366c4346fd1058f3a039a320b4b97ac65280df..06c5b57f8db5f95ff69146451f95eb07a62973cd 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 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 @@ -113,12 +113,12 @@ private: static std::shared_ptr notificationSubscriberManager_; static TestAnsSubscriber testAnsSubscriber_; - static sptr subscriber_; + static sptr subscriber_; }; std::shared_ptr NotificationSubscriberManagerTest::notificationSubscriberManager_ = nullptr; -sptr NotificationSubscriberManagerTest::subscriber_ = nullptr; +sptr NotificationSubscriberManagerTest::subscriber_ = nullptr; void NotificationSubscriberManagerTest::SetUpTestCase() { @@ -353,7 +353,7 @@ HWTEST_F(NotificationSubscriberManagerTest, BatchNotifyConsumed_001, Function | notifications.emplace_back(notification); std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -382,7 +382,7 @@ HWTEST_F(NotificationSubscriberManagerTest, AddSubscriber_001, Function | SmallT MockGetOsAccountLocalIdFromUid(false, 0); NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); ASSERT_EQ(notificationSubscriberManager.AddSubscriber( subscriber, nullptr), (int)ERR_ANS_INVALID_PARAM); @@ -397,7 +397,7 @@ HWTEST_F(NotificationSubscriberManagerTest, AddSubscriber_002, Function | SmallT { NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); sptr info(new NotificationSubscribeInfo()); @@ -426,7 +426,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsSubscribedBysubscriber_001, Functi sptr notification(new Notification(request)); std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr record = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -448,7 +448,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsSubscribedBysubscriber_002, Functi sptr notification(new Notification(request)); std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr record = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -469,7 +469,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsSubscribedBysubscriber_003, Functi sptr notification(new Notification(request)); std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr record = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -507,7 +507,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumed_001, Function | Small sptr notification(new Notification(request)); std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -527,7 +527,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumed_001, Function | Small HWTEST_F(NotificationSubscriberManagerTest, NotifyBadgeEnabledChanged_001, Function | SmallTest | Level1) { std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); ASSERT_EQ(notificationSubscriberManager_->AddSubscriber(subscriber, nullptr), (int)ERR_OK); @@ -557,7 +557,7 @@ HWTEST_F(NotificationSubscriberManagerTest, ConsumeRecordFilter_001, Function | sptr notification(new Notification(request)); std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr record = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -586,7 +586,7 @@ HWTEST_F(NotificationSubscriberManagerTest, ConsumeRecordFilter_002, Function | NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); std::shared_ptr record = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -609,7 +609,7 @@ HWTEST_F(NotificationSubscriberManagerTest, ConsumeRecordFilter_003, Function | NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); std::shared_ptr record = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -660,7 +660,7 @@ HWTEST_F(NotificationSubscriberManagerTest, BatchNotifyCanceledInner_001, Functi notifications.push_back(notificationLocal); //build subscriber std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -687,7 +687,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyDoNotDisturbDateChangedInner_0 //build subscriber std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -715,7 +715,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyEnabledNotificationChangedInne //build subscriber std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -741,7 +741,7 @@ HWTEST_F(NotificationSubscriberManagerTest, SetBadgeNumber_001, Function | Small //build subscriber std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -767,7 +767,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyApplicationInfoNeedChanged_001 { //build subscriber std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); @@ -810,7 +810,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_001, Function | SmallTe sptr notification(new Notification(request)); NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); std::shared_ptr subscriberRecord = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -851,7 +851,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_002, Function | SmallTe NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); std::shared_ptr subscriberRecord = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -892,7 +892,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_003, Function | SmallTe NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); std::shared_ptr subscriberRecord = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -937,7 +937,7 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceFlag_004, Function | SmallTe NotificationSubscriberManager notificationSubscriberManager; std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); std::shared_ptr subscriberRecord = notificationSubscriberManager.CreateSubscriberRecord(subscriber); @@ -974,7 +974,7 @@ HWTEST_F(NotificationSubscriberManagerTest, DistributeOperation_001, Function | sptr operationInfo(new NotificationOperationInfo); //build subscriber std::shared_ptr testAnsSubscriber = std::make_shared(); - sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); + sptr subscriber(new (std::nothrow) SubscriberListener(testAnsSubscriber)); auto isCallback = testAnsSubscriber->GetCallBack(); ASSERT_FALSE(isCallback); diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index 86161c0d2b068aaa0a513dd33bad4108303a44b3..529de7b1f8e068fae2cf4782ee804f9f7e098a2d 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -100,10 +100,7 @@ namespace OHOS { service->SetShowBadgeEnabledForBundle(bundleOption, enabled); service->GetShowBadgeEnabledForBundle(bundleOption, enabled); service->GetShowBadgeEnabled(enabled); - sptr subscriber = new Notification::AnsSubscriberStub(); sptr info = new Notification::NotificationSubscribeInfo(); - service->Subscribe(subscriber, info); - service->Unsubscribe(subscriber, info); bool allowed = fuzzData->ConsumeBool(); service->IsAllowedNotify(allowed); service->IsAllowedNotifySelf(bundleOption, allowed); @@ -143,9 +140,7 @@ namespace OHOS { int32_t badgeNum = fuzzData->ConsumeIntegral(); service->SetBadgeNumber(badgeNum, fuzzData->ConsumeRandomLengthString()); sptr dialogCallback = new Notification::AnsDialogCallbackProxy(nullptr); - sptr callerToken = new Notification::AnsSubscriberStub(); std::shared_ptr groupInfo; - service->RequestEnableNotification(stringData, dialogCallback, callerToken); bool enable = fuzzData->ConsumeBool(); std::string bundleName = fuzzData->ConsumeRandomLengthString(); std::string phoneNumber = fuzzData->ConsumeRandomLengthString(); diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index bf942d4cbaef2a6feb4e32057bdb6b030e2eb00f..81bc13fb854342f7f1b533145e068e68340715fa 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -74,7 +74,6 @@ namespace OHOS { sptr buttonOption = new Notification::NotificationButtonOption(); - sptr subscriber = new Notification::AnsSubscriberStub(); sptr info = new Notification::NotificationSubscribeInfo(); sptr slot = new Notification::NotificationSlot(); @@ -182,11 +181,7 @@ namespace OHOS { datas.WriteParcelable(bundleOption); ansManagerStub.HandleUpdateSlots(datas, reply); datas.WriteString(stringData); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); - if (boolData) { - datas.WriteRemoteObject(subscriber); - } ansManagerStub.HandleRequestEnableNotification(datas, reply); datas.WriteString(stringData); datas.WriteBool(boolData); @@ -204,22 +199,18 @@ namespace OHOS { datas.WriteParcelable(bundleOption); ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); } ansManagerStub.HandleSubscribe(datas, reply); - datas.WriteRemoteObject(subscriber); ansManagerStub.HandleSubscribeSelf(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); } datas.WriteBool(boolData); ansManagerStub.HandleSubscribeLocalLiveView(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); @@ -227,7 +218,6 @@ namespace OHOS { ansManagerStub.HandleUnsubscribe(datas, reply); ansManagerStub.HandleIsAllowedNotify(datas, reply); ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); - datas.WriteRemoteObject(subscriber); ansManagerStub.HandleCanPopEnableNotificationDialog(datas, reply); ansManagerStub.HandleRemoveEnableNotificationDialog(datas, reply); datas.WriteParcelable(bundleOption); diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index f8fcc2b8ab1ca2564ecc538f836088d65a0bd5ec..665a291b1d4f1bdd72833bcaec4a8aff225ac806 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -75,7 +75,6 @@ namespace OHOS { sptr buttonOption = new Notification::NotificationButtonOption(); - sptr subscriber = new Notification::AnsSubscriberStub(); sptr info = new Notification::NotificationSubscribeInfo(); sptr slot = new Notification::NotificationSlot(); @@ -183,11 +182,7 @@ namespace OHOS { datas.WriteParcelable(bundleOption); ansManagerStub.HandleUpdateSlots(datas, reply); datas.WriteString(stringData); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); - if (boolData) { - datas.WriteRemoteObject(subscriber); - } ansManagerStub.HandleRequestEnableNotification(datas, reply); datas.WriteString(stringData); datas.WriteBool(boolData); @@ -205,22 +200,18 @@ namespace OHOS { datas.WriteParcelable(bundleOption); ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); } ansManagerStub.HandleSubscribe(datas, reply); - datas.WriteRemoteObject(subscriber); ansManagerStub.HandleSubscribeSelf(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); } datas.WriteBool(boolData); ansManagerStub.HandleSubscribeLocalLiveView(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); @@ -228,7 +219,6 @@ namespace OHOS { ansManagerStub.HandleUnsubscribe(datas, reply); ansManagerStub.HandleIsAllowedNotify(datas, reply); ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); - datas.WriteRemoteObject(subscriber); ansManagerStub.HandleCanPopEnableNotificationDialog(datas, reply); ansManagerStub.HandleRemoveEnableNotificationDialog(datas, reply); datas.WriteParcelable(bundleOption); diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index 5b01834338cf357b091b93fe1f9a37a51d71f95b..91aa5894232498a140dd44d0624b96fa8dab0fb2 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -67,7 +67,6 @@ namespace OHOS { sptr buttonOption = new Notification::NotificationButtonOption(); - sptr subscriber = new Notification::AnsSubscriberStub(); sptr info = new Notification::NotificationSubscribeInfo(); sptr slot = new Notification::NotificationSlot(); @@ -173,11 +172,7 @@ namespace OHOS { datas.WriteParcelable(bundleOption); ansManagerStub.HandleUpdateSlots(datas, reply); datas.WriteString(stringData); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); - if (boolData) { - datas.WriteRemoteObject(subscriber); - } ansManagerStub.HandleRequestEnableNotification(datas, reply); datas.WriteString(stringData); datas.WriteBool(boolData); @@ -195,22 +190,18 @@ namespace OHOS { datas.WriteParcelable(bundleOption); ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); } ansManagerStub.HandleSubscribe(datas, reply); - datas.WriteRemoteObject(subscriber); ansManagerStub.HandleSubscribeSelf(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); } datas.WriteBool(boolData); ansManagerStub.HandleSubscribeLocalLiveView(datas, reply); - datas.WriteRemoteObject(subscriber); datas.WriteBool(boolData); if (boolData) { datas.WriteParcelable(info); @@ -218,7 +209,6 @@ namespace OHOS { ansManagerStub.HandleUnsubscribe(datas, reply); ansManagerStub.HandleIsAllowedNotify(datas, reply); ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); - datas.WriteRemoteObject(subscriber); ansManagerStub.HandleCanPopEnableNotificationDialog(datas, reply); ansManagerStub.HandleRemoveEnableNotificationDialog(datas, reply); datas.WriteParcelable(bundleOption); diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp index dc2addf2fdf6a013b65283197a89fe4b4be01ea1..fb84e2729beab9235cae233d8c183483352b097c 100644 --- a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp +++ b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -29,13 +29,10 @@ namespace OHOS { { sptr impl; Notification::AnsSubscriberProxy ansSubscriberProxy(impl); - uint32_t code = fdp->ConsumeIntegral(); MessageParcel datas; MessageParcel reply; MessageOption flags; - // test InnerTransact function - ansSubscriberProxy.InnerTransact(static_cast(code), - flags, datas, reply); + int32_t funcResult = -1; // test InnerTransact function ansSubscriberProxy.OnConnected(); // test InnerTransact function @@ -61,7 +58,7 @@ namespace OHOS { ansSubscriberProxy.OnApplicationInfoNeedChanged("com.test.demo"); // test OnResponse function sptr operationInfo = new Notification::NotificationOperationInfo(); - ansSubscriberProxy.OnOperationResponse(operationInfo); + ansSubscriberProxy.OnOperationResponse(operationInfo, funcResult); return true; } } diff --git a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp index 656cfdcb8f3618797c36942a1bc9947ca1c336f0..7d13c6ffdc2a62e3320de44d905b297fe8b32f55 100644 --- a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp +++ b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp @@ -15,8 +15,6 @@ #define private public #define protected public -#include "ans_subscriber_stub.h" -#include "ans_subscriber_local_live_view_stub.h" #undef private #undef protected #include "ans_permission_def.h" @@ -27,60 +25,9 @@ namespace OHOS { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) { - Notification::AnsSubscriberStub ansSubscriberStub; - uint32_t code = fdp->ConsumeIntegral(); MessageParcel datas; MessageParcel reply; MessageOption flags; - // test OnRemoteRequest function - ansSubscriberStub.OnRemoteRequest(code, datas, reply, flags); - // test HandleOnConnected function - ansSubscriberStub.HandleOnConnected(datas, reply); - // test HandleOnDisconnected function - ansSubscriberStub.HandleOnDisconnected(datas, reply); - // test HandleOnConsumedMap function - ansSubscriberStub.HandleOnConsumedMap(datas, reply); - // test HandleOnCanceledMap function - ansSubscriberStub.HandleOnCanceledMap(datas, reply); - // test HandleOnUpdated function - ansSubscriberStub.HandleOnUpdated(datas, reply); - // test HandleOnDoNotDisturbDateChange function - ansSubscriberStub.HandleOnDoNotDisturbDateChange(datas, reply); - // test HandleOnEnabledNotificationChanged function - ansSubscriberStub.HandleOnEnabledNotificationChanged(datas, reply); - // test HandleOnApplicationInfoNeedChanged function - ansSubscriberStub.HandleOnApplicationInfoNeedChanged(datas, reply); - // test HandleOnResponse function - ansSubscriberStub.HandleOnResponse(datas, reply); - // test OnConnected function - ansSubscriberStub.OnConnected(); - // test OnDisconnected function - ansSubscriberStub.OnDisconnected(); - // test OnConsumed function - sptr notification = new Notification::Notification(); - sptr notificationMap = new Notification::NotificationSortingMap(); - ansSubscriberStub.OnConsumed(notification, notificationMap); - // test OnCanceled function - int32_t deleteReason = 1; - ansSubscriberStub.OnCanceled(notification, notificationMap, deleteReason); - ansSubscriberStub.OnApplicationInfoNeedChanged("com.test.demo"); - sptr operationInfo = new Notification::NotificationOperationInfo(); - ansSubscriberStub.OnOperationResponse(operationInfo); - // test OnUpdated function - ansSubscriberStub.OnUpdated(notificationMap); - // test OnDoNotDisturbDateChange function - sptr date = new Notification::NotificationDoNotDisturbDate(); - ansSubscriberStub.OnDoNotDisturbDateChange(date); - // test OnEnabledNotificationChanged function - sptr callbackData = new Notification::EnabledNotificationCallbackData(); - // test HandleOnBadgeEnabledChanged function - ansSubscriberStub.HandleOnBadgeEnabledChanged(datas, reply); - // test HandleOnConsumedListMap function - ansSubscriberStub.HandleOnConsumedListMap(datas, reply); - // test HandleOnBadgeChanged function - ansSubscriberStub.HandleOnBadgeChanged(datas, reply); - // test HandleOnCanceledListMap function - ansSubscriberStub.HandleOnCanceledListMap(datas, reply); return true; } }