diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 822e942a14714afc06013ea21210b419470f57ed..26bf856c5422a79308e5115ad7ea030dc8f53b94 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -12,8 +12,30 @@ # limitations under the License. import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") +idl_gen_interface("ans_dialog_callback_interface") { + src_idl = rebase_path("IAnsDialogCallback.idl") + hitrace = "HITRACE_TAG_ABILITY_MANAGER" + log_domainid = "0xD003900" + log_tag = "Notification" +} + +idl_gen_interface("ans_subscriber_interface") { + src_idl = rebase_path("IAnsSubscriber.idl") + hitrace = "HITRACE_TAG_ABILITY_MANAGER" + log_domainid = "0xD003900" + log_tag = "Notification" +} + +idl_gen_interface("ans_subscriber_local_live_view_interface") { + src_idl = rebase_path("IAnsSubscriberLocalLiveView.idl") + hitrace = "HITRACE_TAG_ABILITY_MANAGER" + log_domainid = "0xD003900" + log_tag = "Notification" +} + group("ans_client") { deps = [ ":ans_innerkits" ] } @@ -27,6 +49,7 @@ config("ans_innerkits_public_config") { "${core_path}/common/include", "${core_path}/include", "//third_party/json/single_include", + "${target_gen_dir}", ] configs = [ "${multimedia_path}/interfaces/innerkits:image_external_config" ] } @@ -44,18 +67,19 @@ ohos_shared_library("ans_innerkits") { include_dirs = [ "${inner_api_path}" ] + output_values = get_target_outputs(":ans_dialog_callback_interface") + + subscriber_output_values = get_target_outputs(":ans_subscriber_interface") + + subscriber_local_live_view_output_values = + get_target_outputs(":ans_subscriber_local_live_view_interface") + sources = [ "${core_path}/common/src/ans_convert_enum.cpp", "${core_path}/src/ans_image_util.cpp", "${core_path}/src/ans_notification.cpp", - "${core_path}/src/listener/ans_dialog_callback_interface.cpp", - "${core_path}/src/listener/ans_dialog_callback_proxy.cpp", - "${core_path}/src/listener/ans_dialog_callback_stub.cpp", + "${core_path}/src/dialog_status_data.cpp", "${core_path}/src/listener/ans_subscriber_listener.cpp", - "${core_path}/src/listener/ans_subscriber_local_live_view_proxy.cpp", - "${core_path}/src/listener/ans_subscriber_local_live_view_stub.cpp", - "${core_path}/src/listener/ans_subscriber_proxy.cpp", - "${core_path}/src/listener/ans_subscriber_stub.cpp", "${core_path}/src/listener/swing_callback_proxy.cpp", "${core_path}/src/listener/swing_callback_stub.cpp", "${core_path}/src/manager/ans_manager_death_recipient.cpp", @@ -113,10 +137,23 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/push_promise_callback.cpp", ] + sources += filter_include(output_values, [ "*.cpp" ]) + + sources += filter_include(subscriber_output_values, [ "*.cpp" ]) + + sources += + filter_include(subscriber_local_live_view_output_values, [ "*.cpp" ]) + public_configs = [ ":ans_innerkits_public_config" ] defines = [] + deps = [ + ":ans_dialog_callback_interface", + ":ans_subscriber_interface", + ":ans_subscriber_local_live_view_interface", + ] + external_deps = [ "ability_base:want", "ability_base:zuri", @@ -128,6 +165,7 @@ ohos_shared_library("ans_innerkits") { "eventhandler:libeventhandler", "hicollie:libhicollie", "hilog:libhilog", + "hitrace:hitrace_meter", "i18n:intl_util", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/frameworks/core/include/ans_dialog_callback_stub.h b/frameworks/ans/IAnsDialogCallback.idl similarity index 44% rename from frameworks/core/include/ans_dialog_callback_stub.h rename to frameworks/ans/IAnsDialogCallback.idl index e18c4291799c4ba41217b166259ef3ec5e024cf9..20b04e2cb212de9d7a73aaa4d6728652af4a4809 100644 --- a/frameworks/core/include/ans_dialog_callback_stub.h +++ b/frameworks/ans/IAnsDialogCallback.idl @@ -1,5 +1,6 @@ + /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -13,25 +14,7 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_STUB_H -#define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_STUB_H - -#include "ans_dialog_callback_interface.h" - -#include - -#include "iremote_stub.h" - -namespace OHOS::Notification { -class AnsDialogCallbackStub : public IRemoteStub { -public: - AnsDialogCallbackStub() = default; - ~AnsDialogCallbackStub() override = default; - DISALLOW_COPY_AND_MOVE(AnsDialogCallbackStub); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) override; -}; -} // namespace OHOS::Notification - -#endif // BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_STUB_H + sequenceable OHOS.Notification.DialogStatusData; + interface OHOS.Notification.IAnsDialogCallback { + void OnDialogStatusChanged([in] DialogStatusData statusData); + } \ No newline at end of file diff --git a/frameworks/ans/IAnsSubscriber.idl b/frameworks/ans/IAnsSubscriber.idl new file mode 100644 index 0000000000000000000000000000000000000000..187cbf9add3f86a27de8b728f670a60318505320 --- /dev/null +++ b/frameworks/ans/IAnsSubscriber.idl @@ -0,0 +1,36 @@ +/* + * 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; + interface OHOS.Notification.IAnsSubscriber { + void OnConnected(); + void OnDisconnected(); + void OnConsumed([in] Notification notification, [in] NotificationSortingMap notificationMap); + void OnConsumedList([in] Notification[] notifications, [in] NotificationSortingMap notificationMap); + void OnCanceled([in] Notification notification, [in] NotificationSortingMap notificationMap, [in] int deleteReason); + void OnCanceledList([in] Notification[] notifications, [in] NotificationSortingMap notificationMap, [in] int deleteReason); + void OnUpdated([in] NotificationSortingMap notificationMap); + void OnDoNotDisturbDateChange([in] NotificationDoNotDisturbDate date); + void OnEnabledNotificationChanged([in] EnabledNotificationCallbackData callbackData); + void OnBadgeChanged([in] BadgeNumberCallbackData badgeData); + void OnBadgeEnabledChanged([in] EnabledNotificationCallbackData callbackData); + void OnApplicationInfoNeedChanged([in] String bundleName); + void OnResponse([in] Notification notification); + } + \ No newline at end of file diff --git a/frameworks/core/src/listener/ans_dialog_callback_stub.cpp b/frameworks/ans/IAnsSubscriberLocalLiveView.idl similarity index 41% rename from frameworks/core/src/listener/ans_dialog_callback_stub.cpp rename to frameworks/ans/IAnsSubscriberLocalLiveView.idl index ae3a2207d08b842bde7853253cab3aad950be872..8517ab9d23af99e8e5577a19fe2c7b78339db503 100644 --- a/frameworks/core/src/listener/ans_dialog_callback_stub.cpp +++ b/frameworks/ans/IAnsSubscriberLocalLiveView.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -13,26 +13,9 @@ * limitations under the License. */ -#include "ans_dialog_callback_stub.h" - -#include "ans_log_wrapper.h" - -namespace OHOS::Notification { -int32_t AnsDialogCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - if (code != AnsDialogCallback::ON_DIALOG_STATUS_CHANGED || - data.ReadInterfaceToken() != AnsDialogCallback::GetDescriptor()) { - ANS_LOGE("Invalid request."); - return ERR_INVALID_STATE; - } - - std::unique_ptr result(data.ReadParcelable()); - if (result == nullptr) { - ANS_LOGE("DialogStatusData is nullptr"); - return ERR_INVALID_STATE; - } - OnDialogStatusChanged(*result); - return ERR_NONE; +sequenceable OHOS.Notification.NotificationButtonOption; +interface OHOS.Notification.IAnsSubscriberLocalLiveView { + [oneway] void OnConnected(); + [oneway] void OnDisconnected(); + [oneway] void OnResponse([in] int notificationId, [in] NotificationButtonOption buttonOption); } -} // namespace OHOS::Notification diff --git a/frameworks/ans/src/ans_dialog_host_client.cpp b/frameworks/ans/src/ans_dialog_host_client.cpp index 05a4c465608c6efe6f46bdd424eda57ab106c981..2fbc625f60a3fdd5948bc100ae56a2ee23c66077 100644 --- a/frameworks/ans/src/ans_dialog_host_client.cpp +++ b/frameworks/ans/src/ans_dialog_host_client.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 @@ -54,18 +54,19 @@ bool AnsDialogHostClient::SetDialogCallbackInterface( return true; } -void AnsDialogHostClient::OnDialogStatusChanged(const DialogStatusData& statusData) +ErrCode AnsDialogHostClient::OnDialogStatusChanged(const DialogStatusData &statusData) { ANS_LOGD("enter"); if (dialogCallbackInterface_ == nullptr) { ANS_LOGE("AnsDialogCallbackNativeInterface is null."); - return; + return ERR_OK; } if (hasBeenCalled.exchange(true)) { ANS_LOGE("Has been called."); - return; + return ERR_INVALID_DATA; } dialogCallbackInterface_->ProcessDialogStatusChanged(statusData); AnsDialogHostClient::Destroy(); + return ERR_OK; } } // namespace OHOS::Notification diff --git a/frameworks/ans/src/notification_local_live_view_subscriber.cpp b/frameworks/ans/src/notification_local_live_view_subscriber.cpp index dcc4aaa637d87b1b202a22679708a09ee3aba1a4..fb909f25237300e176c140d5566666da593509f8 100644 --- a/frameworks/ans/src/notification_local_live_view_subscriber.cpp +++ b/frameworks/ans/src/notification_local_live_view_subscriber.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 @@ -40,7 +40,7 @@ NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::SubscriberLoca recipient_ = new (std::nothrow) DeathRecipient(*this); }; -void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnConnected() +ErrCode NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnConnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); sptr proxy = GetAnsManagerProxy(); @@ -49,9 +49,10 @@ void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnConnect ANS_LOGD("%s, Add death recipient.", __func__); } subscriber_.OnConnected(); + return ERR_OK; } -void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnDisconnected() +ErrCode NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnDisconnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); sptr proxy = GetAnsManagerProxy(); @@ -60,13 +61,15 @@ void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnDisconn ANS_LOGD("%s, Remove death recipient.", __func__); } subscriber_.OnDisconnected(); + return ERR_OK; } -void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnResponse(int32_t notificationId, - sptr buttonOption) +ErrCode NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnResponse(int32_t notificationId, + const NotificationButtonOption &buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - subscriber_.OnResponse(notificationId, buttonOption); + subscriber_.OnResponse(notificationId, new (std::nothrow) NotificationButtonOption(buttonOption)); + return ERR_OK; } sptr NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::GetAnsManagerProxy() diff --git a/frameworks/ans/src/notification_subscriber.cpp b/frameworks/ans/src/notification_subscriber.cpp index 15869f884d6e4e661862a356a5a0ec3827c89fe7..97dd5d66961008cdd437e07edd82252cc008d790 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,62 +114,66 @@ 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(); if (proxy != nullptr) { proxy->AsObject()->AddDeathRecipient(recipient_); ANS_LOGD("%s, Add death recipient.", __func__); + return ERR_OK; } subscriber_.OnConnected(); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnDisconnected() +ErrCode NotificationSubscriber::SubscriberImpl::OnDisconnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); sptr proxy = GetAnsManagerProxy(); if (proxy != nullptr) { proxy->AsObject()->RemoveDeathRecipient(recipient_); ANS_LOGD("%s, Remove death recipient.", __func__); + return ERR_OK; } subscriber_.OnDisconnected(); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumed( + const Notification ¬ification, const NotificationSortingMap ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - std::shared_ptr sharedNotification = std::make_shared(*notification); + 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)); + sharedNotification, std::make_shared(notificationMap)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) +ErrCode NotificationSubscriber::SubscriberImpl::OnConsumedList(const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); for (auto notification : notifications) { OnConsumed(notification, notificationMap); } + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnCanceled( - const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceled( + const Notification ¬ification, const NotificationSortingMap ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - if (notificationMap == nullptr) { - subscriber_.OnCanceled(std::make_shared(*notification), - std::make_shared(), deleteReason); - } else { - subscriber_.OnCanceled(std::make_shared(*notification), - std::make_shared(*notificationMap), deleteReason); - } + subscriber_.OnCanceled(std::make_shared(notification), + std::make_shared(), deleteReason); + subscriber_.OnCanceled(std::make_shared(notification), + std::make_shared(notificationMap), deleteReason); + return ERR_OK; } void NotificationSubscriber::SubscriberImpl::OnBatchCanceled(const std::vector> ¬ifications, @@ -189,59 +193,74 @@ void NotificationSubscriber::SubscriberImpl::OnBatchCanceled(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) +ErrCode NotificationSubscriber::SubscriberImpl::OnCanceledList(const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + std::vector> notificationVector; + for (auto& notification : notifications) { + auto notificationSptr = sptr::MakeSptr(notification); + notificationVector.emplace_back(notificationSptr); + } + const std::vector> cnotifications = notificationVector; + auto notificationMapsPtr = sptr::MakeSptr(); if (subscriber_.HasOnBatchCancelCallback()) { - OnBatchCanceled(notifications, notificationMap, deleteReason); - return; + OnBatchCanceled(cnotifications, notificationMapsPtr, deleteReason); + 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 NotificationSortingMap ¬ificationMap) { - subscriber_.OnUpdate(std::make_shared(*notificationMap)); + subscriber_.OnUpdate(std::make_shared(notificationMap)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnDoNotDisturbDateChange(const sptr &date) +ErrCode NotificationSubscriber::SubscriberImpl::OnDoNotDisturbDateChange(const NotificationDoNotDisturbDate &date) { - subscriber_.OnDoNotDisturbDateChange(std::make_shared(*date)); + subscriber_.OnDoNotDisturbDateChange(std::make_shared(date)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnEnabledNotificationChanged( - const sptr &callbackData) +ErrCode NotificationSubscriber::SubscriberImpl::OnEnabledNotificationChanged( + const EnabledNotificationCallbackData &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - subscriber_.OnEnabledNotificationChanged(std::make_shared(*callbackData)); + subscriber_.OnEnabledNotificationChanged(std::make_shared(callbackData)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnBadgeChanged(const sptr &badgeData) +ErrCode NotificationSubscriber::SubscriberImpl::OnBadgeChanged(const BadgeNumberCallbackData &badgeData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - subscriber_.OnBadgeChanged(std::make_shared(*badgeData)); + subscriber_.OnBadgeChanged(std::make_shared(badgeData)); + return ERR_OK; } -void NotificationSubscriber::SubscriberImpl::OnBadgeEnabledChanged( - const sptr &callbackData) +ErrCode NotificationSubscriber::SubscriberImpl::OnBadgeEnabledChanged( + const EnabledNotificationCallbackData &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - subscriber_.OnBadgeEnabledChanged(callbackData); + auto shard_callbackData = sptr::MakeSptr(); + subscriber_.OnBadgeEnabledChanged(shard_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::OnResponse(const sptr ¬ification) +ErrCode NotificationSubscriber::SubscriberImpl::OnResponse(const Notification ¬ification) { - return subscriber_.OnResponse(std::make_shared(*notification)); + return subscriber_.OnResponse(std::make_shared(notification)); } sptr NotificationSubscriber::SubscriberImpl::GetAnsManagerProxy() diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index c90cde0df5c4e2f3db1097db92281fcb978990a9..c4e7b5d74d44ceee3902c763087d331a6ac9fb69 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -30,6 +30,7 @@ ohos_shared_library("ans_core") { "${core_path}/src/ans_notification.cpp", "${core_path}/src/ans_subscriber_proxy.cpp", "${core_path}/src/ans_subscriber_stub.cpp", + "${core_path}/src/dialog_status_data.cpp", "${frameworks_module_ans_path}/src/badge_number_callback_data.cpp", "${frameworks_module_ans_path}/src/enabled_notification_callback_data.cpp", "${frameworks_module_ans_path}/src/message_user.cpp", diff --git a/frameworks/core/include/ans_dialog_callback_proxy.h b/frameworks/core/include/ans_dialog_callback_proxy.h deleted file mode 100644 index e626bd85b01b5d8ecb6233878e6dcfd22fca01af..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_dialog_callback_proxy.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_PROXY_H -#define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_PROXY_H - -#include "ans_dialog_callback_interface.h" - -#include "iremote_proxy.h" - -namespace OHOS::Notification { -class AnsDialogCallbackProxy : public IRemoteProxy { -public: - explicit AnsDialogCallbackProxy(const sptr &impl) - : IRemoteProxy(impl) {} - ~AnsDialogCallbackProxy() override = default; - DISALLOW_COPY_AND_MOVE(AnsDialogCallbackProxy); - - void OnDialogStatusChanged(const DialogStatusData& statusData) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::Notification - -#endif // BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_PROXY_H diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index c4489a7d2208de4635a25b301c9fe2da096c386c..7df2b8dbf04c14b5d8c9df343ee9cceb8a149947 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.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 @@ -19,9 +19,9 @@ #include #include -#include "ans_dialog_callback_interface.h" -#include "ans_subscriber_interface.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "ians_dialog_callback.h" +#include "ians_subscriber.h" +#include "ians_subscriber_local_live_view.h" #include "iremote_broker.h" #include "notification_bundle_option.h" #include "notification_constant.h" @@ -383,7 +383,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual ErrCode RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) = 0; /** @@ -447,7 +447,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; /** @@ -456,7 +456,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. @@ -465,7 +465,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SubscribeLocalLiveView(const sptr &subscriber, + virtual ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNative) = 0; /** @@ -476,7 +476,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. @@ -500,7 +500,7 @@ public: * @param canPop True if can pop enable notification dialog * @return Returns is canPop result. */ - virtual ErrCode CanPopEnableNotificationDialog(const sptr &callback, + virtual ErrCode CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) = 0; /** diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index ab3317984202b31b4e650aa41db6daecbba6bfbe..8450bd46f73256c881662c3f4eeb7900f2c5c316 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.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 @@ -370,7 +370,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) override; /** @@ -434,7 +434,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; /** @@ -444,7 +444,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. @@ -453,7 +453,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SubscribeLocalLiveView(const sptr &subscriber, + ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNative) override; /** @@ -463,7 +463,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; /** @@ -488,7 +488,7 @@ public: * @param canPop True if can pop enable notification dialog * @return Returns is canPop result. */ - ErrCode CanPopEnableNotificationDialog(const sptr &callback, + ErrCode CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) override; /** diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 1c6439957d4b680cf5b1d324843bda93b4ce9597..998eb7604832c256e9b1f6d06ae760636c6e78f7 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.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 @@ -20,8 +20,8 @@ #include #include "ans_manager_interface.h" -#include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" +#include "ians_subscriber_local_live_view.h" #include "iremote_stub.h" namespace OHOS { @@ -373,7 +373,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) override; /** @@ -440,7 +440,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. @@ -448,10 +448,10 @@ 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, + const sptr &subscriber, const sptr &info, const bool isNative) override; /** @@ -462,7 +462,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. @@ -486,7 +486,7 @@ public: * @param canPop True if can pop enable notification dialog * @return Returns is canPop result. */ - ErrCode CanPopEnableNotificationDialog(const sptr &callback, + ErrCode CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) override; /** diff --git a/frameworks/core/include/ans_subscriber_interface.h b/frameworks/core/include/ans_subscriber_interface.h deleted file mode 100644 index 57abde28c2a1fb993a1f9b44225e7b12423e08e8..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_interface.h +++ /dev/null @@ -1,122 +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" - -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 OnResponse(const sptr ¬ification) = 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 2a4ac37aeee50ab78c527aae8428d70d96198fce..81ad1ab379297f984194ee26789db371fe35ba90 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,38 @@ public: SubscriberListener(const std::shared_ptr &subscriber); ~SubscriberListener(); - void OnConnected() override; + ErrCode OnConnected() override; - void OnDisconnected() override; + ErrCode OnDisconnected() override; - void OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) override; + ErrCode OnConsumed( + const Notification ¬ification, const NotificationSortingMap ¬ificationMap) override; - void OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) override; + ErrCode OnConsumedList(const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap) override; - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, + ErrCode OnCanceled(const Notification ¬ification, const NotificationSortingMap ¬ificationMap, int32_t deleteReason) override; - void OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) override; + ErrCode OnCanceledList(const std::vector ¬ifications, + const NotificationSortingMap ¬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 NotificationSortingMap ¬ificationMap) override; - void OnDoNotDisturbDateChange(const sptr &date) override; + ErrCode OnDoNotDisturbDateChange(const NotificationDoNotDisturbDate &date) override; - void OnEnabledNotificationChanged(const sptr &callbackData) override; + ErrCode OnEnabledNotificationChanged(const EnabledNotificationCallbackData &callbackData) override; - void OnBadgeChanged(const sptr &badgeData) override; + ErrCode OnBadgeChanged(const BadgeNumberCallbackData &badgeData) override; - void OnBadgeEnabledChanged(const sptr &callbackData) override; + ErrCode OnBadgeEnabledChanged(const EnabledNotificationCallbackData &callbackData) override; - void OnApplicationInfoNeedChanged(const std::string& bundleName) override; + ErrCode OnApplicationInfoNeedChanged(const std::string& bundleName) override; - ErrCode OnResponse(const sptr ¬ification) override; + ErrCode OnResponse(const Notification ¬ification) override; public: std::weak_ptr subscriber_; diff --git a/frameworks/core/include/ans_subscriber_local_live_view_interface.h b/frameworks/core/include/ans_subscriber_local_live_view_interface.h deleted file mode 100644 index 4b24f5477073630597f9532e23f2364273d5d356..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_local_live_view_interface.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_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" - -namespace OHOS { -namespace Notification { -class AnsSubscriberLocalLiveViewInterface : public IRemoteBroker { -public: - AnsSubscriberLocalLiveViewInterface() = default; - virtual ~AnsSubscriberLocalLiveViewInterface() override = default; - DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewInterface); - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberLocalLiveViewInterface"); - - /** - * @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; - - virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H diff --git a/frameworks/core/include/ans_subscriber_local_live_view_proxy.h b/frameworks/core/include/ans_subscriber_local_live_view_proxy.h deleted file mode 100644 index 0bc561259a9c4496627baf37de86f4b74e98a527..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_local_live_view_proxy.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H - -#include "ans_subscriber_local_live_view_interface.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace Notification { -class AnsSubscriberLocalLiveViewProxy : public IRemoteProxy { -public: - AnsSubscriberLocalLiveViewProxy() = delete; - explicit AnsSubscriberLocalLiveViewProxy(const sptr &impl); - ~AnsSubscriberLocalLiveViewProxy() override; - DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewProxy); - - /** - * @brief The callback function for the subscriber to establish a connection. - */ - void OnConnected() override; - - /** - * @brief The callback function for subscriber disconnected. - */ - void OnDisconnected() override; - - void OnResponse(int32_t notificationId, sptr buttonOption) 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_LOCAL_LIVE_VIEW_PROXY_H diff --git a/frameworks/core/include/ans_subscriber_local_live_view_stub.h b/frameworks/core/include/ans_subscriber_local_live_view_stub.h deleted file mode 100644 index a7e9f15087097fa7b78bd113c825fe5ab5c07b24..0000000000000000000000000000000000000000 --- a/frameworks/core/include/ans_subscriber_local_live_view_stub.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H - -#include "ans_subscriber_local_live_view_interface.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace Notification { -class AnsSubscriberLocalLiveViewStub : public IRemoteStub { -public: - AnsSubscriberLocalLiveViewStub(); - ~AnsSubscriberLocalLiveViewStub() override; - DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewStub); - - /** - * @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; - - void OnResponse(int32_t notificationId, sptr buttonOption) override; - -private: - - ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnDisconnected(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_LOCAL_LIVE_VIEW_STUB_H diff --git a/frameworks/core/include/ans_subscriber_proxy.h b/frameworks/core/include/ans_subscriber_proxy.h deleted file mode 100644 index 435e0fb53b1a28f4b0d96aa0f8632bbacfc4e8da..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 OnResponse(const sptr ¬ification) 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 35906d3b541b604952f7c68527b9c3925b5d2738..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 OnResponse(const sptr ¬ification) 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/include/ans_dialog_callback_interface.h b/frameworks/core/include/dialog_status_data.h similarity index 62% rename from frameworks/core/include/ans_dialog_callback_interface.h rename to frameworks/core/include/dialog_status_data.h index c2a8cbdaeef89d1c0f7cd975c234674c66196b0e..de09c13f6e11d406267f925ca38600f3a60dacbb 100644 --- a/frameworks/core/include/ans_dialog_callback_interface.h +++ b/frameworks/core/include/dialog_status_data.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -13,22 +13,20 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_H -#define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_H - +#ifndef BASE_NOTIFICATION_DIALOG_STATUS_DATA_H +#define BASE_NOTIFICATION_DIALOG_STATUS_DATA_H + #include "iremote_broker.h" - + #include "nocopyable.h" #include "parcel.h" - namespace OHOS::Notification { - + enum class EnabledDialogStatus { ALLOW_CLICKED, DENY_CLICKED, CRASHED }; - class DialogStatusData : public Parcelable { public: explicit DialogStatusData(EnabledDialogStatus status): status_(static_cast(status)) {} @@ -37,26 +35,10 @@ public: static DialogStatusData* Unmarshalling(Parcel &parcel); inline int32_t GetStatus() const { return status_; } - + private: int32_t status_; }; - -class AnsDialogCallback : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsDialogCallback"); - - AnsDialogCallback() = default; - ~AnsDialogCallback() override = default; - DISALLOW_COPY_AND_MOVE(AnsDialogCallback); - - virtual void OnDialogStatusChanged(const DialogStatusData& statusData) = 0; - - enum { - // ipc id for OnDialogStatusChanged - ON_DIALOG_STATUS_CHANGED = 1, - }; -}; } // namespace OHOS::Notification - -#endif // BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_H +#endif // BASE_NOTIFICATION_DIALOG_STATUS_DATA_H + \ No newline at end of file diff --git a/frameworks/core/src/listener/ans_dialog_callback_interface.cpp b/frameworks/core/src/dialog_status_data.cpp similarity index 92% rename from frameworks/core/src/listener/ans_dialog_callback_interface.cpp rename to frameworks/core/src/dialog_status_data.cpp index 3c02047a9d9b3c42054e48cc35fe3dc223e7bc5e..f3c0f540dc0ec8b0b124fad1505b2bff1ed88336 100644 --- a/frameworks/core/src/listener/ans_dialog_callback_interface.cpp +++ b/frameworks/core/src/dialog_status_data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "ans_dialog_callback_interface.h" +#include "dialog_status_data.h" #include "ans_log_wrapper.h" - + namespace OHOS::Notification { bool DialogStatusData::Marshalling(Parcel& parcel) const { @@ -26,7 +26,7 @@ bool DialogStatusData::Marshalling(Parcel& parcel) const } return true; } - + DialogStatusData* DialogStatusData::Unmarshalling(Parcel& parcel) { DialogStatusData* data = new (std::nothrow) DialogStatusData( @@ -37,3 +37,4 @@ DialogStatusData* DialogStatusData::Unmarshalling(Parcel& parcel) return data; } } // namespace OHOS::Notification + \ No newline at end of file diff --git a/frameworks/core/src/listener/ans_dialog_callback_proxy.cpp b/frameworks/core/src/listener/ans_dialog_callback_proxy.cpp deleted file mode 100644 index 9764cb3140800a1a2fa1fa8ef932008f1ba15c96..0000000000000000000000000000000000000000 --- a/frameworks/core/src/listener/ans_dialog_callback_proxy.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ans_dialog_callback_proxy.h" - -#include "ans_log_wrapper.h" - -namespace OHOS::Notification { -void AnsDialogCallbackProxy::OnDialogStatusChanged(const DialogStatusData& statusData) -{ - ANS_LOGD("enter"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsDialogCallback::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return; - } - if (!data.WriteParcelable(&statusData)) { - ANS_LOGE("Write statusData failed."); - return; - } - - sptr remote = Remote(); - if (remote == nullptr) { - ANS_LOGE("Remote is NULL"); - return; - } - - MessageParcel reply; - MessageOption option; - int error = remote->SendRequest(ON_DIALOG_STATUS_CHANGED, data, reply, option); - if (error != ERR_OK) { - ANS_LOGE("SendRequest fail, error: %{public}d", error); - } -} -} // namespace OHOS::Notification diff --git a/frameworks/core/src/listener/ans_subscriber_listener.cpp b/frameworks/core/src/listener/ans_subscriber_listener.cpp index 886428c7a1e1572a8c59a9296df52e29c179b739..1ab01234e82cfa49f0b5c519a2c6d69ace839be0 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,74 +28,76 @@ 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_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } subscriber->OnDisconnected(); + return ERR_OK; } -void SubscriberListener::OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) +ErrCode SubscriberListener::OnConsumed( + const Notification ¬ification, const NotificationSortingMap ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } - std::shared_ptr sharedNotification = std::make_shared(*notification); + 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)); + sharedNotification, std::make_shared(notificationMap)); + return ERR_OK; } -void SubscriberListener::OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) +ErrCode SubscriberListener::OnConsumedList(const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); for (auto notification : notifications) { OnConsumed(notification, notificationMap); } + return ERR_OK; } -void SubscriberListener::OnCanceled( - const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) +ErrCode SubscriberListener::OnCanceled( + const Notification ¬ification, const NotificationSortingMap ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; - } - if (notificationMap == nullptr) { - subscriber->OnCanceled(std::make_shared(*notification), - std::make_shared(), deleteReason); - } else { - subscriber->OnCanceled(std::make_shared(*notification), - std::make_shared(*notificationMap), deleteReason); + return ERR_OK; } + subscriber->OnCanceled(std::make_shared(notification), + std::make_shared(), deleteReason); + subscriber->OnCanceled(std::make_shared(notification), + std::make_shared(notificationMap), deleteReason); + return ERR_OK; } void SubscriberListener::OnBatchCanceled(const std::vector> ¬ifications, @@ -119,92 +121,107 @@ void SubscriberListener::OnBatchCanceled(const std::vector> & } } -void SubscriberListener::OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) +ErrCode SubscriberListener::OnCanceledList(const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap, int32_t deleteReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; + } + std::vector> notificationVector; + for (auto& notification : notifications) { + auto notificationSptr = sptr::MakeSptr(notification); + notificationVector.emplace_back(notificationSptr); } + const std::vector> cnotifications = notificationVector; + auto notificationMapsPtr = sptr::MakeSptr(); if (subscriber->HasOnBatchCancelCallback()) { - OnBatchCanceled(notifications, notificationMap, deleteReason); - return; + OnBatchCanceled(cnotifications, notificationMapsPtr, deleteReason); + return ERR_OK; } for (auto notification : notifications) { OnCanceled(notification, notificationMap, deleteReason); } + return ERR_OK; } -void SubscriberListener::OnUpdated(const sptr ¬ificationMap) +ErrCode SubscriberListener::OnUpdated(const NotificationSortingMap ¬ificationMap) { auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } - subscriber->OnUpdate(std::make_shared(*notificationMap)); + subscriber->OnUpdate(std::make_shared(notificationMap)); + return ERR_OK; } -void SubscriberListener::OnDoNotDisturbDateChange(const sptr &date) +ErrCode SubscriberListener::OnDoNotDisturbDateChange(const NotificationDoNotDisturbDate &date) { auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } - subscriber->OnDoNotDisturbDateChange(std::make_shared(*date)); + subscriber->OnDoNotDisturbDateChange(std::make_shared(date)); + return ERR_OK; } -void SubscriberListener::OnEnabledNotificationChanged( - const sptr &callbackData) +ErrCode SubscriberListener::OnEnabledNotificationChanged( + const EnabledNotificationCallbackData &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } - subscriber->OnEnabledNotificationChanged(std::make_shared(*callbackData)); + subscriber->OnEnabledNotificationChanged(std::make_shared(callbackData)); + return ERR_OK; } -void SubscriberListener::OnBadgeChanged(const sptr &badgeData) +ErrCode SubscriberListener::OnBadgeChanged(const BadgeNumberCallbackData &badgeData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } - subscriber->OnBadgeChanged(std::make_shared(*badgeData)); + subscriber->OnBadgeChanged(std::make_shared(badgeData)); + return ERR_OK; } -void SubscriberListener::OnBadgeEnabledChanged( - const sptr &callbackData) +ErrCode SubscriberListener::OnBadgeEnabledChanged( + const EnabledNotificationCallbackData &callbackData) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); + auto shard_callbackData = sptr::MakeSptr(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } - subscriber->OnBadgeEnabledChanged(callbackData); + subscriber->OnBadgeEnabledChanged(shard_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_LOGE("OnApplicationInfoNeedChanged SubscriberListener 1."); auto subscriber = subscriber_.lock(); if (subscriber == nullptr) { ANS_LOGW("Subscriber is nullptr"); - return; + return ERR_OK; } subscriber->OnApplicationInfoNeedChanged(bundleName); + return ERR_OK; } -ErrCode SubscriberListener::OnResponse(const sptr ¬ification) +ErrCode SubscriberListener::OnResponse(const Notification ¬ification) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); auto subscriber = subscriber_.lock(); @@ -212,8 +229,9 @@ ErrCode SubscriberListener::OnResponse(const sptr ¬ification) ANS_LOGW("Subscriber is nullptr"); return ERR_OK; } - std::shared_ptr sharedNotification = std::make_shared(*notification); + std::shared_ptr sharedNotification = std::make_shared(notification); return subscriber->OnResponse(sharedNotification); + return ERR_OK; } } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/listener/ans_subscriber_local_live_view_proxy.cpp b/frameworks/core/src/listener/ans_subscriber_local_live_view_proxy.cpp deleted file mode 100644 index 27e93580597d2ffd3419bf723eca96b3cfdad08f..0000000000000000000000000000000000000000 --- a/frameworks/core/src/listener/ans_subscriber_local_live_view_proxy.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ans_subscriber_local_live_view_proxy.h" - -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "message_option.h" -#include "message_parcel.h" - -namespace OHOS { -namespace Notification { -AnsSubscriberLocalLiveViewProxy::AnsSubscriberLocalLiveViewProxy( - const sptr &impl) : IRemoteProxy(impl) -{} - -AnsSubscriberLocalLiveViewProxy::~AnsSubscriberLocalLiveViewProxy() -{} - -ErrCode AnsSubscriberLocalLiveViewProxy::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 AnsSubscriberLocalLiveViewProxy::OnConnected() -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberLocalLiveViewProxy::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 AnsSubscriberLocalLiveViewProxy::OnDisconnected() -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberLocalLiveViewProxy::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 AnsSubscriberLocalLiveViewProxy::OnResponse(int32_t notificationId, sptr buttonOption) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberLocalLiveViewProxy::GetDescriptor())) { - ANS_LOGE("[OnResponse] fail: write interface token failed."); - return; - } - - if (!data.WriteInt32(notificationId)) { - ANS_LOGE("[OnResponse] fail: write notificationId failed"); - return; - } - - if (!data.WriteParcelable(buttonOption)) { - ANS_LOGE("[OnResponse] fail: write buttonName failed"); - return; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ON_RESPONSE, option, data, reply); - if (result != ERR_OK) { - ANS_LOGE("[OnResponse] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); - return; - } -} -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/core/src/listener/ans_subscriber_local_live_view_stub.cpp b/frameworks/core/src/listener/ans_subscriber_local_live_view_stub.cpp deleted file mode 100644 index 9317706df60160b061f47f6f2c3f3306b260c0a6..0000000000000000000000000000000000000000 --- a/frameworks/core/src/listener/ans_subscriber_local_live_view_stub.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ans_subscriber_local_live_view_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 "notification_bundle_option.h" -#include "notification_button_option.h" -#include "parcel.h" -#include "refbase.h" -#include - -namespace OHOS { -namespace Notification { -AnsSubscriberLocalLiveViewStub::AnsSubscriberLocalLiveViewStub() {} - -AnsSubscriberLocalLiveViewStub::~AnsSubscriberLocalLiveViewStub() {} - -int32_t AnsSubscriberLocalLiveViewStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &flags) -{ - std::u16string descriptor = AnsSubscriberLocalLiveViewStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - ANS_LOGW("[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_RESPONSE): { - result = HandleOnResponse(data, reply); - break; - } - default: { - ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); - } - } - return result; -} - -ErrCode AnsSubscriberLocalLiveViewStub::HandleOnConnected(MessageParcel &data, MessageParcel &reply) -{ - OnConnected(); - return ERR_OK; -} - -ErrCode AnsSubscriberLocalLiveViewStub::HandleOnDisconnected(MessageParcel &data, MessageParcel &reply) -{ - OnDisconnected(); - return ERR_OK; -} - -template -bool AnsSubscriberLocalLiveViewStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - ANS_LOGE("read Parcelable size 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 AnsSubscriberLocalLiveViewStub::HandleOnResponse(MessageParcel &data, MessageParcel &reply) -{ - int32_t notificationId = 0; - if (!data.ReadInt32(notificationId)) { - ANS_LOGE("[HandleOnResponse] fail : read notificationId failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - sptr buttonOption = nullptr; - buttonOption = data.ReadParcelable(); - if (buttonOption == nullptr) { - ANS_LOGE("[HandleOnResponse] fail : read buttonOption failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - OnResponse(notificationId, buttonOption); - return ERR_OK; -} - -void AnsSubscriberLocalLiveViewStub::OnConnected() {} - -void AnsSubscriberLocalLiveViewStub::OnDisconnected() {} - -void AnsSubscriberLocalLiveViewStub::OnResponse(int32_t notificationId, sptr buttonOption) {} -} // 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 a2fa1276c3ebe331f7e650aa1cd3c0ad23c75277..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 callback data 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::OnResponse(const sptr ¬ification) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (!data.WriteParcelable(notification)) { - ANS_LOGE("Write notification 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 4381035a31f68d108588e8a4a1e7386637d1b8c2..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_LOGW("[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_LOGW("[HandleOnCanceledMap] fail: notification ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - bool existMap = false; - if (!data.ReadBool(existMap)) { - ANS_LOGW("[HandleOnCanceledMap] fail: read existMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - sptr notificationMap = nullptr; - if (existMap) { - notificationMap = data.ReadParcelable(); - if (notificationMap == nullptr) { - ANS_LOGW("[HandleOnCanceledMap] fail: read NotificationSortingMap failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - - int32_t reason = 0; - if (!data.ReadInt32(reason)) { - ANS_LOGW("[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 Parcelable size 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_LOGW("[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_LOGW("[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_LOGW("[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_LOGW("[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 notification = data.ReadParcelable(); - if (!notification) { - ANS_LOGW("notification ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - ErrCode result = OnResponse(notification); - 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::OnResponse(const sptr &request) { return 0; } -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/core/src/manager/ans_manager_proxy.cpp b/frameworks/core/src/manager/ans_manager_proxy.cpp index 7926742a13796643c29621532c6fec5a3b078e40..76a10b303a6f1b7223c79a98172a589111ace91a 100644 --- a/frameworks/core/src/manager/ans_manager_proxy.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy.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 @@ -18,7 +18,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "ians_subscriber_local_live_view.h" #include "distributed_notification_service_ipc_interface_code.h" #include "message_option.h" #include "message_parcel.h" diff --git a/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp b/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp index 73bc9c18d7717eff8156510da88aa17937853dbd..76281906a4e59f5684ab8c9306e603a3a900b7a8 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_bundle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,7 +18,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "ians_subscriber_local_live_view.h" #include "distributed_notification_service_ipc_interface_code.h" #include "message_option.h" #include "message_parcel.h" @@ -116,7 +116,7 @@ ErrCode AnsManagerProxy::HasNotificationPolicyAccessPermission(bool &granted) } ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) { ANS_LOGD("enter"); @@ -442,7 +442,7 @@ ErrCode AnsManagerProxy::IsAllowedNotifySelf(bool &allowed) return result; } -ErrCode AnsManagerProxy::CanPopEnableNotificationDialog(const sptr &callback, +ErrCode AnsManagerProxy::CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) { MessageParcel data; diff --git a/frameworks/core/src/manager/ans_manager_proxy_disturb.cpp b/frameworks/core/src/manager/ans_manager_proxy_disturb.cpp index 6655bfa7cd69e0516070c950134609f6d1dace40..8a1656e42b1f8c91aab9ee76da7673fdb14e6b5f 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_disturb.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_disturb.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 @@ -18,7 +18,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "ians_subscriber_local_live_view.h" #include "distributed_notification_service_ipc_interface_code.h" #include "message_option.h" #include "message_parcel.h" diff --git a/frameworks/core/src/manager/ans_manager_proxy_slot.cpp b/frameworks/core/src/manager/ans_manager_proxy_slot.cpp index 8b4e9ad34514c1a237f7a8284f30a617d0629d93..ff18e3c90c35c920d5794cbcb7d84f0f823803e5 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_slot.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_slot.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 @@ -18,7 +18,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "ians_subscriber_local_live_view.h" #include "distributed_notification_service_ipc_interface_code.h" #include "message_option.h" #include "message_parcel.h" diff --git a/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp b/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp index 19c90ad7b2b30baf3d2e6b4aa0cc8061b35390a5..75b4c84652fa7eb66ee053cf4e620684654824c8 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_subscribe.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_subscribe.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 @@ -18,8 +18,8 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" +#include "ians_subscriber_local_live_view.h" #include "message_option.h" #include "message_parcel.h" #include "parcel.h" @@ -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."); @@ -237,7 +237,7 @@ ErrCode AnsManagerProxy::SubscribeSelf(const sptr &subsc return result; } -ErrCode AnsManagerProxy::SubscribeLocalLiveView(const sptr &subscriber, +ErrCode AnsManagerProxy::SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNative) { if (subscriber == nullptr) { @@ -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 714317b6bf5e5f5afbab6e8f26a3422480059e64..1ab914a33e2adcb4c99ee6f5c0d0ad5e8be41317 100644 --- a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/manager/ans_manager_stub_invalid.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 @@ -312,7 +312,7 @@ ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscr return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, +ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNative) { ANS_LOGE("AnsManagerStub::SubscribeLocalLiveView called!"); diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index f8305fd0d5d30f1757c544fd63fea4ef0158fa9c..63f51f43f88e0ef9e59aff88b188164eb6318892 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -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 9323086722a6cbe5d5a54a6c0d00f9dd1f5bea24..01d827f5dd75089120400582a7c17d310ae0fc2b 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 @@ -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 @@ -23,7 +23,7 @@ #include "ans_manager_proxy.h" #undef private #undef protected -#include "ans_dialog_callback_interface.h" +#include "ians_dialog_callback.h" #include "ans_inner_errors.h" #include "ipc_types.h" #include "notification.h" @@ -222,7 +222,7 @@ public: } ErrCode RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) override { return ERR_ANS_INVALID_PARAM; @@ -259,13 +259,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; } @@ -291,14 +291,14 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode SubscribeLocalLiveView(const sptr &subscriber, + ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNatives) override { return ERR_ANS_INVALID_PARAM; } ErrCode Unsubscribe( - const sptr &subscriber, const sptr &info) override + const sptr &subscriber, const sptr &info) override { return ERR_ANS_INVALID_PARAM; } @@ -313,7 +313,7 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode CanPopEnableNotificationDialog(const sptr &callback, + ErrCode CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) 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..bfe4433e6333e8d41bf9cfae8518383f32afd1f9 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 @@ -68,8 +68,8 @@ HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0100, Function | MediumTes ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::vector> notifications; - sptr notificationMap = nullptr; + std::vector notifications; + auto notificationMap = OHOS::Notification::NotificationSortingMap(); int32_t deleteReason = 1; proxy->OnCanceledList(notifications, notificationMap, deleteReason); } @@ -90,74 +90,10 @@ HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0200, Function | MediumTes std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - std::vector> notifications; + auto notification = OHOS::Notification::Notification(request); + std::vector notifications; notifications.emplace_back(notification); - sptr notificationMap = nullptr; + auto notificationMap = OHOS::Notification::NotificationSortingMap(); int32_t deleteReason = 1; proxy->OnCanceledList(notifications, notificationMap, deleteReason); } - -/* - * @tc.name: OnCanceledList_0300 - * @tc.desc: 1.Test OnCanceledList function and notifications is not empty - * 2.notificationMap is not nullptr - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0300, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnCanceledList_0300, 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 request = new (std::nothrow) OHOS::Notification::NotificationRequest(); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - std::vector> notifications; - notifications.emplace_back(notification); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - 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..745415ddc39a981024eed151e11b7a03856df5af 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 @@ -161,11 +72,8 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Le sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); ASSERT_NE(nullptr, request); - sptr notification = - new (std::nothrow) OHOS::Notification::Notification(request); - ASSERT_NE(nullptr, notification); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); proxy->OnConsumed(notification, notificationMap); } @@ -187,99 +95,11 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Le sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); ASSERT_NE(nullptr, request); - sptr notification = - new (std::nothrow) OHOS::Notification::Notification(request); - ASSERT_NE(nullptr, notification); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); proxy->OnConsumed(notification, notificationMap); } -/* - * @tc.name: OnConsumed_0600 - * @tc.desc: test AnsSubscriberProxy's OnConsumed function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0600, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnConsumed_0600, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - proxy->OnConsumed(nullptr, notificationMap); -} - -/* - * @tc.name: OnConsumed_0700 - * @tc.desc: test AnsSubscriberProxy's OnConsumed function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0700, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnConsumed_0700, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr request = - new (std::nothrow) OHOS::Notification::NotificationRequest(); - ASSERT_NE(nullptr, request); - sptr notification = - new (std::nothrow) OHOS::Notification::Notification(request); - ASSERT_NE(nullptr, notification); - proxy->OnConsumed(notification, nullptr); -} - -/* - * @tc.name: OnConsumedList_0100 - * @tc.desc: Test OnConsumedList function and notifications is empty - * @tc.type: FUNC - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnConsumedList_0100, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - std::vector> notifications; - proxy->OnConsumedList(notifications, nullptr); -} - -/* - * @tc.name: OnConsumedList_0200 - * @tc.desc: Test OnConsumedList function and notifications is empty - * @tc.type: FUNC - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnConsumedList_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr request = - new (std::nothrow) OHOS::Notification::NotificationRequest(); - ASSERT_NE(nullptr, request); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - std::vector> notifications; - notifications.emplace_back(notification); - proxy->OnConsumedList(notifications, nullptr); -} - /* * @tc.name: OnConsumedList_0300 * @tc.desc: Test OnConsumedList function and notifications is empty @@ -294,8 +114,8 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0300, Function | MediumTest EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::vector> notifications; - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + std::vector notifications; + auto notificationMap = OHOS::Notification::NotificationSortingMap(); proxy->OnConsumedList(notifications, notificationMap); } @@ -317,10 +137,10 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0400, Function | MediumTest sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); ASSERT_NE(nullptr, request); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - std::vector> notifications; + auto notification = OHOS::Notification::Notification(request); + std::vector notifications; notifications.emplace_back(notification); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); proxy->OnConsumedList(notifications, notificationMap); } @@ -342,10 +162,8 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Le sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); ASSERT_NE(nullptr, request); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - ASSERT_NE(nullptr, notification); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); int32_t deleteReason = 0; proxy->OnCanceled(notification, notificationMap, deleteReason); } @@ -368,59 +186,12 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Le sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); ASSERT_NE(nullptr, request); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - ASSERT_NE(nullptr, notification); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); int32_t deleteReason = 0; proxy->OnCanceled(notification, notificationMap, deleteReason); } -/* - * @tc.name: OnCanceled_0600 - * @tc.desc: test AnsSubscriberProxy's OnCanceled function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0600, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnCanceled_0600, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - int32_t deleteReason = 0; - proxy->OnCanceled(nullptr, notificationMap, deleteReason); -} - -/* - * @tc.name: OnCanceled_0700 - * @tc.desc: test AnsSubscriberProxy's OnCanceled function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0700, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnCanceled_0700, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr request = - new (std::nothrow) OHOS::Notification::NotificationRequest(); - ASSERT_NE(nullptr, request); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); - ASSERT_NE(nullptr, notification); - int32_t deleteReason = 0; - proxy->OnCanceled(notification, nullptr, deleteReason); -} - /* * @tc.name: OnUpdated_0100 * @tc.desc: test AnsSubscriberProxy's OnUpdated function @@ -436,8 +207,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0100, Function | MediumTest | Lev EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); proxy->OnUpdated(notificationMap); } @@ -456,29 +226,10 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0200, Function | MediumTest | Lev EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); proxy->OnUpdated(notificationMap); } -/* - * @tc.name: OnOnUpdated_0300 - * @tc.desc: test AnsSubscriberProxy's OnUpdated function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnOnUpdated_0300, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnOnUpdated_0300, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - proxy->OnUpdated(nullptr); -} - /* * @tc.name: OnDoNotDisturbDateChange_0100 * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function @@ -494,8 +245,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, Function | M EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr date = new (std::nothrow) NotificationDoNotDisturbDate(); - ASSERT_NE(nullptr, date); + auto date = OHOS::Notification::NotificationDoNotDisturbDate(); proxy->OnDoNotDisturbDateChange(date); } @@ -514,8 +264,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, Function | M EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr date = new (std::nothrow) NotificationDoNotDisturbDate(); - ASSERT_NE(nullptr, date); + auto date = OHOS::Notification::NotificationDoNotDisturbDate(); proxy->OnDoNotDisturbDateChange(date); } @@ -534,8 +283,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, Function 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 = new (std::nothrow) EnabledNotificationCallbackData(); - ASSERT_NE(nullptr, callbackData); + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); proxy->OnEnabledNotificationChanged(callbackData); } @@ -554,8 +302,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, Function EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr callbackData = new (std::nothrow) EnabledNotificationCallbackData(); - ASSERT_NE(nullptr, callbackData); + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); proxy->OnEnabledNotificationChanged(callbackData); } @@ -646,8 +393,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeChanged_0100, Function | MediumTest EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr badgeData = new (std::nothrow) BadgeNumberCallbackData(); - ASSERT_NE(nullptr, badgeData); + auto badgeData = OHOS::Notification::BadgeNumberCallbackData(); proxy->OnBadgeChanged(badgeData); } @@ -666,8 +412,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeChanged_0200, Function | MediumTest EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr badgeData = new (std::nothrow) BadgeNumberCallbackData(); - ASSERT_NE(nullptr, badgeData); + auto badgeData = OHOS::Notification::BadgeNumberCallbackData(); proxy->OnBadgeChanged(badgeData); } @@ -683,8 +428,7 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0100, TestSize.Level1 EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr callbackData = new (std::nothrow) EnabledNotificationCallbackData(); - ASSERT_NE(nullptr, callbackData); + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); proxy->OnBadgeEnabledChanged(callbackData); } @@ -700,6 +444,6 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0200, TestSize.Level1 EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr callbackData = nullptr; + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); proxy->OnBadgeEnabledChanged(callbackData); } 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 82ddf4187a85c924864699839b513d0c59fa7511..0000000000000000000000000000000000000000 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn +++ /dev/null @@ -1,52 +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}/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/js/napi/src/js_ans_dialog_callback.cpp b/frameworks/js/napi/src/js_ans_dialog_callback.cpp index cf8a3f9645b2ec249cf0f932c2b7183567671aea..6a9d55dcb40b974e953899fa684a40d0986f14f4 100644 --- a/frameworks/js/napi/src/js_ans_dialog_callback.cpp +++ b/frameworks/js/napi/src/js_ans_dialog_callback.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 @@ -17,7 +17,7 @@ #include -#include "ans_dialog_callback_interface.h" +#include "ians_dialog_callback.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" diff --git a/frameworks/reminder/BUILD.gn b/frameworks/reminder/BUILD.gn index 4598a3d8a248ec03a903ed4e8971f412b54f1629..8fe7a57a1299b12cd2972811bb24ef7006cf4156 100644 --- a/frameworks/reminder/BUILD.gn +++ b/frameworks/reminder/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -73,6 +73,7 @@ ohos_shared_library("reminder_innerkits") { deps = [ ":reminder_service_interface", "${frameworks_path}/ans:ans_client", + "${frameworks_path}/ans:ans_innerkits", ] external_deps = [ diff --git a/interfaces/inner_api/notification_local_live_view_subscriber.h b/interfaces/inner_api/notification_local_live_view_subscriber.h index b15f741603f6c390d419f964f71e794ceb8349ce..73be44e9346b792a8d3f71cdc0205603f02433e2 100644 --- a/interfaces/inner_api/notification_local_live_view_subscriber.h +++ b/interfaces/inner_api/notification_local_live_view_subscriber.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -67,11 +67,11 @@ private: SubscriberLocalLiveViewImpl(NotificationLocalLiveViewSubscriber &subscriber); ~SubscriberLocalLiveViewImpl() {}; - void OnConnected() override; + ErrCode OnConnected() override; - void OnDisconnected() override; + ErrCode OnDisconnected() override; - void OnResponse(int32_t notificationId, sptr buttonOption) override; + ErrCode OnResponse(int32_t notificationId, const NotificationButtonOption &buttonOption) override; sptr GetAnsManagerProxy(); diff --git a/interfaces/inner_api/notification_subscriber.h b/interfaces/inner_api/notification_subscriber.h index 37a16ce68d201e5b743c703e9f6c758d969c689d..980b188759625ab2ce9fcbd1f5a535b11736939b 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 @@ -155,38 +155,38 @@ private: SubscriberImpl(NotificationSubscriber &subscriber); ~SubscriberImpl() {}; - void OnConnected() override; + ErrCode OnConnected() override; - void OnDisconnected() override; + ErrCode OnDisconnected() override; - void OnConsumed( - const sptr ¬ification, const sptr ¬ificationMap) override; + ErrCode OnConsumed( + const Notification ¬ification, const NotificationSortingMap ¬ificationMap) override; - void OnConsumedList(const std::vector> ¬ifications, - const sptr ¬ificationMap) override; + ErrCode OnConsumedList(const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap) override; - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, + ErrCode OnCanceled(const Notification ¬ification, const NotificationSortingMap ¬ificationMap, int32_t deleteReason) override; - void OnCanceledList(const std::vector> ¬ifications, - const sptr ¬ificationMap, int32_t deleteReason) override; + ErrCode OnCanceledList(const std::vector ¬ifications, + const NotificationSortingMap ¬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 NotificationSortingMap ¬ificationMap) override; - void OnDoNotDisturbDateChange(const sptr &date) override; + ErrCode OnDoNotDisturbDateChange(const NotificationDoNotDisturbDate &date) override; - void OnEnabledNotificationChanged(const sptr &callbackData) override; + ErrCode OnEnabledNotificationChanged(const EnabledNotificationCallbackData &callbackData) override; - void OnBadgeChanged(const sptr &badgeData) override; + ErrCode OnBadgeChanged(const BadgeNumberCallbackData &badgeData) override; - void OnBadgeEnabledChanged(const sptr &callbackData) override; + ErrCode OnBadgeEnabledChanged(const EnabledNotificationCallbackData &callbackData) override; - void OnApplicationInfoNeedChanged(const std::string& bundleName) override; + ErrCode OnApplicationInfoNeedChanged(const std::string& bundleName) override; - ErrCode OnResponse(const sptr ¬ification) override; + ErrCode OnResponse(const Notification ¬ification) override; sptr GetAnsManagerProxy(); diff --git a/interfaces/kits/native/ans_dialog_callback_native_interface.h b/interfaces/kits/native/ans_dialog_callback_native_interface.h index 2270081fd3a697d631c8df8fa393ddeaa691fa05..7697d8fc848cd76f4210f2077b2889021f2a045a 100644 --- a/interfaces/kits/native/ans_dialog_callback_native_interface.h +++ b/interfaces/kits/native/ans_dialog_callback_native_interface.h @@ -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 @@ -16,7 +16,7 @@ #ifndef BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_NATIVE_INTERFACE_H #define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_NATIVE_INTERFACE_H -#include "ans_dialog_callback_interface.h" +#include "ians_dialog_callback.h" #include "nocopyable.h" namespace OHOS::Notification { diff --git a/interfaces/kits/native/ans_dialog_host_client.h b/interfaces/kits/native/ans_dialog_host_client.h index 633a39c8cdea72627b425efd32b028fd46ae65b4..7f05bbe6b700422024035f7ea90928a50088ab2b 100644 --- a/interfaces/kits/native/ans_dialog_host_client.h +++ b/interfaces/kits/native/ans_dialog_host_client.h @@ -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 @@ -36,7 +36,7 @@ public: virtual ~AnsDialogHostClient() = default; DISALLOW_COPY_AND_MOVE(AnsDialogHostClient); - void OnDialogStatusChanged(const DialogStatusData& statusData) override; + ErrCode OnDialogStatusChanged(const DialogStatusData &statusData) override; private: inline static sptr instance_ = nullptr; diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 6a75ef97698b1c98acf95cd42a89ca3cf655c8e3..d3f7e70ddfbea3f686633a8cc82874cf2293425d 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -56,6 +56,7 @@ ohos_source_set("ans_service_sources") { "${services_path}/ans/include/notification_extension", "${services_path}/ans/include/utils", "${services_path}/ans/include/slot_manager", + "${inner_api_path}", ] defines = [] diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 2eecb813c555395d89f94bb6499aeff35cebee7b..b6c27a8e8293aeac1f398ae49ab09bb0d7f8a9fe 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.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 @@ -440,7 +440,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) override; /** @@ -504,7 +504,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; /** @@ -513,7 +513,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. @@ -522,7 +522,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SubscribeLocalLiveView(const sptr &subscriber, + ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNative) override; /** @@ -532,7 +532,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; /** @@ -557,7 +557,7 @@ public: * @param canPop True if can pop enable notification dialog * @return Returns is canPop result. */ - ErrCode CanPopEnableNotificationDialog(const sptr &callback, + ErrCode CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) override; /** diff --git a/services/ans/include/disturb_manager/disturb_manager.h b/services/ans/include/disturb_manager/disturb_manager.h index ae9ba50f8899984cdcf2792d1a51ad195640b8e5..785cfd623caef32f0488119d49d0151bbf8a7362 100644 --- a/services/ans/include/disturb_manager/disturb_manager.h +++ b/services/ans/include/disturb_manager/disturb_manager.h @@ -20,9 +20,9 @@ #include #include "ans_manager_interface.h" -#include "ans_subscriber_local_live_view_interface.h" #include "base_manager.h" #include "distributed_notification_service_ipc_interface_code.h" +#include "ians_subscriber_local_live_view.h" #include "iremote_stub.h" #include "singleton.h" diff --git a/services/ans/include/notification_dialog_manager.h b/services/ans/include/notification_dialog_manager.h index 2d8b6387723dc14f33af1c7140a9e6b777a81575..798fe15e840c71309579017500f5fa57377a1030 100644 --- a/services/ans/include/notification_dialog_manager.h +++ b/services/ans/include/notification_dialog_manager.h @@ -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 @@ -26,7 +26,7 @@ #include "common_event_subscribe_info.h" #include "refbase.h" -#include "ans_dialog_callback_interface.h" +#include "ians_dialog_callback.h" #include "ans_inner_errors.h" namespace OHOS::Notification { @@ -73,7 +73,7 @@ public: struct DialogInfo { sptr bundleOption; // When multi devices are going to be supported, a deviceId need to be stored - sptr callback; + sptr callback; }; /** @@ -83,7 +83,7 @@ public: */ ErrCode RequestEnableNotificationDailog( const sptr& bundle, - const sptr& callback, + const sptr& callback, const sptr& callerToken ); @@ -100,7 +100,7 @@ public: * AddDialogInfo * @return ERR_OK when add Dialog successfully */ - ErrCode AddDialogInfo(const sptr& bundle, const sptr& callback); + ErrCode AddDialogInfo(const sptr& bundle, const sptr& callback); /* * RemoveDialogInfoByBundleOption @@ -117,7 +117,8 @@ private: static bool SetHasPoppedDialog(const sptr& bundleOption, bool hasPopped); // bundle need to be not null - bool AddDialogInfoIfNotExist(const sptr& bundle, const sptr& callback); + bool AddDialogInfoIfNotExist(const sptr& bundle, + const sptr& callback); sptr GetBundleOptionByBundleName(const std::string& bundleName, const int32_t& uid); void RemoveAllDialogInfos(std::list>& dialogInfosRemoved); diff --git a/services/ans/include/notification_local_live_view_subscriber_manager.h b/services/ans/include/notification_local_live_view_subscriber_manager.h index 92f0f13296c9bf2e9b777ac2924bf9f6052a350b..87d0b463546b1a98957ab31ec4767fa98b31021a 100644 --- a/services/ans/include/notification_local_live_view_subscriber_manager.h +++ b/services/ans/include/notification_local_live_view_subscriber_manager.h @@ -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 @@ -24,11 +24,12 @@ #include "event_handler.h" #include "event_runner.h" #include "ffrt.h" +#include "ians_subscriber_local_live_view.h" #include "nocopyable.h" #include "refbase.h" #include "singleton.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "notification.h" #include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" @@ -46,7 +47,7 @@ public: * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ - ErrCode AddLocalLiveViewSubscriber(const sptr &subscriber, + ErrCode AddLocalLiveViewSubscriber(const sptr &subscriber, const sptr &subscribeInfo); /** @@ -56,7 +57,7 @@ public: * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ - ErrCode RemoveLocalLiveViewSubscriber(const sptr &subscriber, + ErrCode RemoveLocalLiveViewSubscriber(const sptr &subscriber, const sptr &subscribeInfo); /** @@ -85,14 +86,14 @@ private: std::shared_ptr FindSubscriberRecord(const wptr &object); std::shared_ptr FindSubscriberRecord( - const sptr &subscriber); + const sptr &subscriber); std::shared_ptr CreateSubscriberRecord( - const sptr &subscriber, + const sptr &subscriber, const sptr &bundleOption); - ErrCode AddSubscriberInner(const sptr &subscriber, + ErrCode AddSubscriberInner(const sptr &subscriber, const sptr &bundleOption); - ErrCode RemoveSubscriberInner(const sptr &subscriber, + ErrCode RemoveSubscriberInner(const sptr &subscriber, const sptr &subscribeInfo); void NotifyTriggerResponseInner(const sptr ¬ification, @@ -103,7 +104,7 @@ private: std::list> buttonRecordList_ {}; std::shared_ptr runner_ {}; std::shared_ptr handler_ {}; - sptr ansSubscriberProxy_ {}; + sptr ansSubscriberProxy_ {}; sptr recipient_ {}; std::shared_ptr notificationButtonQueue_ = nullptr; diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index a1050547e3e0d8f9e5e78af8fb6ba60945558a82..bc349bfb69c5c7e001da393a50d81d34db87c774 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/include/slot_manager/slot_manager.h b/services/ans/include/slot_manager/slot_manager.h index f13788280dc711ec50cd9a3e5bac191094382bf3..44087557434a8fe08ceb7d3df58c7febf68fd349 100644 --- a/services/ans/include/slot_manager/slot_manager.h +++ b/services/ans/include/slot_manager/slot_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 @@ -20,9 +20,9 @@ #include #include "ans_manager_interface.h" -#include "ans_subscriber_local_live_view_interface.h" #include "base_manager.h" #include "distributed_notification_service_ipc_interface_code.h" +#include "ians_subscriber_local_live_view.h" #include "iremote_stub.h" #include "singleton.h" diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 9363e68e9abb9d33f9dbc8a2735ea0898def06d7..6c027c019f6cb9f32a55a2810f7156b49d1bf05e 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.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 @@ -997,7 +997,7 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabled(bool &enabled) } ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -1223,7 +1223,7 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(bool &allowed) } ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( - const sptr &callback, bool &canPop, std::string &bundleName) + const sptr &callback, bool &canPop, std::string &bundleName) { ANS_LOGD("%{public}s", __FUNCTION__); canPop = false; @@ -2643,7 +2643,7 @@ ErrCode AdvancedNotificationService::SetBadgeNumberByBundle( } ErrCode AdvancedNotificationService::SubscribeLocalLiveView( - const sptr &subscriber, + const sptr &subscriber, const sptr &info, const bool isNative) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); 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 7ac67ab53f495995f1cb29ec5191e51f3c513ab3..30fd78e9cc5e2503e73e72d7b1022fce10835bc4 100644 --- a/services/ans/src/ans_manager_stub.cpp +++ b/services/ans/src/ans_manager_stub.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 @@ -17,7 +17,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" +#include "ians_subscriber_local_live_view.h" #include "disturb_manager.h" #include "message_option.h" #include "message_parcel.h" @@ -1284,7 +1284,7 @@ ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, Mes callerToken = data.ReadRemoteObject(); } - ErrCode result = RequestEnableNotification(deviceId, iface_cast(callback), callerToken); + ErrCode result = RequestEnableNotification(deviceId, iface_cast(callback), callerToken); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleRequestEnableNotification] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1448,7 +1448,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; @@ -1464,7 +1464,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; @@ -1502,7 +1502,7 @@ ErrCode AnsManagerStub::HandleSubscribeLocalLiveView(MessageParcel &data, Messag } ErrCode result = - SubscribeLocalLiveView(iface_cast(subscriber), info, isNative); + SubscribeLocalLiveView(iface_cast(subscriber), info, isNative); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleSubscribeLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1533,7 +1533,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; @@ -1582,7 +1582,7 @@ ErrCode AnsManagerStub::HandleCanPopEnableNotificationDialog(MessageParcel &data } bool canPop = false; std::string bundleName; - ErrCode result = CanPopEnableNotificationDialog(iface_cast(callback), canPop, bundleName); + ErrCode result = CanPopEnableNotificationDialog(iface_cast(callback), canPop, bundleName); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleCanPopEnableNotificationDialog] 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 76388b8de7ed583b95a3550b6b31311e5e471ddb..8828868eec27ccc164eb4984e0515b71b05ba219 100644 --- a/services/ans/src/ans_manager_stub_invalid.cpp +++ b/services/ans/src/ans_manager_stub_invalid.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 @@ -262,7 +262,7 @@ ErrCode AnsManagerStub::UpdateSlots( } ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, - const sptr &callback, + const sptr &callback, const sptr &callerToken) { ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); @@ -306,27 +306,27 @@ 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; } -ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, +ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, const sptr &info, const bool isNative) { ANS_LOGE("AnsManagerStub::SubscribeLocalLiveView called!"); return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, +ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, const sptr &info) { ANS_LOGE("AnsManagerStub::Unsubscribe called!"); @@ -345,7 +345,7 @@ ErrCode AnsManagerStub::IsAllowedNotifySelf(bool &allowed) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::CanPopEnableNotificationDialog(const sptr &callback, +ErrCode AnsManagerStub::CanPopEnableNotificationDialog(const sptr &callback, bool &canPop, std::string &bundleName) { ANS_LOGE("AnsManagerStub::CanPopEnableNotificationDialog called!"); diff --git a/services/ans/src/notification_dialog_manager.cpp b/services/ans/src/notification_dialog_manager.cpp index ad69e94423175369dce95fd121d0443020ee0a2e..413373c5178ec707232bb7151244d47d69383590 100644 --- a/services/ans/src/notification_dialog_manager.cpp +++ b/services/ans/src/notification_dialog_manager.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 @@ -87,7 +87,7 @@ bool NotificationDialogManager::Init() ErrCode NotificationDialogManager::RequestEnableNotificationDailog( const sptr& bundle, - const sptr& callback, + const sptr& callback, const sptr& callerToken) { if (bundle == nullptr || callback == nullptr) { @@ -144,7 +144,7 @@ ErrCode NotificationDialogManager::OnBundleEnabledStatusChanged( } ErrCode NotificationDialogManager::AddDialogInfo(const sptr& bundle, - const sptr& callback) + const sptr& callback) { if (!AddDialogInfoIfNotExist(bundle, callback)) { return ERR_ANS_DIALOG_IS_POPPING; @@ -154,7 +154,7 @@ ErrCode NotificationDialogManager::AddDialogInfo(const sptr& bundle, - const sptr& callback) + const sptr& callback) { std::lock_guard lock(dialogsMutex_); std::string name = bundle->GetBundleName(); diff --git a/services/ans/src/notification_local_live_view_subscriber_manager.cpp b/services/ans/src/notification_local_live_view_subscriber_manager.cpp index b895f47fe20db8ea8b7aa689680bd86215799ad9..11f106727420d6d226d354376a7ccc85a2aec99f 100644 --- a/services/ans/src/notification_local_live_view_subscriber_manager.cpp +++ b/services/ans/src/notification_local_live_view_subscriber_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,7 +34,7 @@ namespace OHOS { namespace Notification { struct NotificationLocalLiveViewSubscriberManager::LocalLiveViewSubscriberRecord { - sptr subscriber {nullptr}; + sptr subscriber {nullptr}; std::string bundleName {}; int32_t userId {SUBSCRIBE_USER_INIT}; }; @@ -65,7 +65,7 @@ void NotificationLocalLiveViewSubscriberManager::ResetFfrtQueue() } ErrCode NotificationLocalLiveViewSubscriberManager::AddLocalLiveViewSubscriber( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber == nullptr) { @@ -103,7 +103,7 @@ ErrCode NotificationLocalLiveViewSubscriberManager::AddLocalLiveViewSubscriber( } ErrCode NotificationLocalLiveViewSubscriberManager::RemoveLocalLiveViewSubscriber( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber == nullptr) { @@ -180,7 +180,7 @@ std::shared_ptr NotificationLocalLiveViewSubscriberManager::FindSubscriberRecord( - const sptr &subscriber) + const sptr &subscriber) { auto iter = buttonRecordList_.begin(); @@ -193,7 +193,7 @@ std::shared_ptr NotificationLocalLiveViewSubscriberManager::CreateSubscriberRecord( - const sptr &subscriber, + const sptr &subscriber, const sptr &bundleOption) { std::shared_ptr record = std::make_shared(); @@ -210,7 +210,7 @@ std::shared_ptr &subscriber, const sptr &bundleOption) + const sptr &subscriber, const sptr &bundleOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); std::shared_ptr record = FindSubscriberRecord(subscriber); @@ -232,7 +232,7 @@ ErrCode NotificationLocalLiveViewSubscriberManager::AddSubscriberInner( } ErrCode NotificationLocalLiveViewSubscriberManager::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); @@ -274,7 +274,7 @@ void NotificationLocalLiveViewSubscriberManager::NotifyTriggerResponseInner( ANS_LOGD("%{public}s record->userId = <%{public}d>, bundlename <%{public}s>", __FUNCTION__, record->userId, record->bundleName.c_str()); if (record->bundleName == bundleName && record->userId == sendUserId) { - record->subscriber->OnResponse(notification->GetId(), buttonOption); + record->subscriber->OnResponse(notification->GetId(), *buttonOption); } } } diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 80c7bc5d1b5f99564c267cdc17d1cb4d1605f8ac..85314b3057a51d7fba8749a8cce3e1bb70c1b5f7 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) { @@ -130,7 +130,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) { @@ -344,7 +344,7 @@ std::shared_ptr NotificationSub } std::shared_ptr NotificationSubscriberManager::FindSubscriberRecord( - const sptr &subscriber) + const sptr &subscriber) { auto iter = subscriberRecordList_.begin(); @@ -357,7 +357,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) { @@ -414,7 +414,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); @@ -448,7 +448,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); @@ -495,12 +495,12 @@ void NotificationSubscriberManager::NotifyConsumedInner( ANS_LOGE("ReadParcelable failed."); continue; } - record->subscriber->OnConsumed(notificationStub, notificationMap); + record->subscriber->OnConsumed(*notificationStub, *notificationMap); NotificationSubscriberManager::IsDeviceFlag( record, notification, wearableFlag, headsetFlag, keyNodeFlag); continue; } - record->subscriber->OnConsumed(notification, notificationMap); + record->subscriber->OnConsumed(*notification, *notificationMap); NotificationSubscriberManager::IsDeviceFlag(record, notification, wearableFlag, headsetFlag, keyNodeFlag); } } @@ -541,7 +541,7 @@ void NotificationSubscriberManager::BatchNotifyConsumedInner(const std::vectoruserId = <%{public}d>", record->userId); - std::vector> currNotifications; + std::vector currNotifications; for (size_t i = 0; i < notifications.size(); i ++) { sptr notification = notifications[i]; if (notification == nullptr) { @@ -551,7 +551,7 @@ void NotificationSubscriberManager::BatchNotifyConsumedInner(const std::vectorsubscriber != nullptr) { NotificationSubscriberManager::IsDeviceFlag( record, notification, wearableFlag, headsetFlag, keyNodeFlag); @@ -562,7 +562,7 @@ void NotificationSubscriberManager::BatchNotifyConsumedInner(const std::vector", currNotifications.size()); if (record->subscriber != nullptr) { - record->subscriber->OnConsumedList(currNotifications, notificationMap); + record->subscriber->OnConsumedList(currNotifications, *notificationMap); } } } @@ -584,7 +584,7 @@ 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); + record->subscriber->OnCanceled(*notification, *notificationMap, deleteReason); } } @@ -667,7 +667,7 @@ void NotificationSubscriberManager::BatchNotifyCanceledInner(const std::vectoruserId = <%{public}d>", record->userId); - std::vector> currNotifications; + std::vector currNotifications; for (size_t i = 0; i < notifications.size(); i ++) { sptr notification = notifications[i]; if (notification == nullptr) { @@ -691,13 +691,13 @@ void NotificationSubscriberManager::BatchNotifyCanceledInner(const std::vector", currNotifications.size()); if (record->subscriber != nullptr) { - record->subscriber->OnCanceledList(currNotifications, notificationMap, deleteReason); + record->subscriber->OnCanceledList(currNotifications, *notificationMap, deleteReason); } } } @@ -706,7 +706,7 @@ void NotificationSubscriberManager::BatchNotifyCanceledInner(const std::vector ¬ificationMap) { for (auto record : subscriberRecordList_) { - record->subscriber->OnUpdated(notificationMap); + record->subscriber->OnUpdated(*notificationMap); } } @@ -716,7 +716,7 @@ void NotificationSubscriberManager::NotifyDoNotDisturbDateChangedInner(const int for (auto record : subscriberRecordList_) { if (record->userId == SUBSCRIBE_USER_ALL || IsSystemUser(record->userId) || IsSystemUser(userId) || record->userId == userId) { - record->subscriber->OnDoNotDisturbDateChange(date); + record->subscriber->OnDoNotDisturbDateChange(*date); } } } @@ -729,7 +729,7 @@ void NotificationSubscriberManager::NotifyBadgeEnabledChangedInner( for (auto record : subscriberRecordList_) { if (record->userId == SUBSCRIBE_USER_ALL || IsSystemUser(record->userId) || IsSystemUser(userId) || record->userId == userId) { - record->subscriber->OnBadgeEnabledChanged(callbackData); + record->subscriber->OnBadgeEnabledChanged(*callbackData); } } } @@ -747,7 +747,7 @@ void NotificationSubscriberManager::NotifyEnabledNotificationChangedInner( for (auto record : subscriberRecordList_) { if (record->userId == SUBSCRIBE_USER_ALL || IsSystemUser(record->userId) || IsSystemUser(userId) || record->userId == userId) { - record->subscriber->OnEnabledNotificationChanged(callbackData); + record->subscriber->OnEnabledNotificationChanged(*callbackData); } } } @@ -765,7 +765,7 @@ void NotificationSubscriberManager::SetBadgeNumber(const sptruserId == SUBSCRIBE_USER_ALL || IsSystemUser(record->userId) || IsSystemUser(userId) || record->userId == userId) { ANS_LOGD("SetBadgeNumber instanceKey: %{public}s", badgeData->GetAppInstanceKey().c_str()); - record->subscriber->OnBadgeChanged(badgeData); + record->subscriber->OnBadgeChanged(*badgeData); } } }; @@ -893,7 +893,7 @@ ErrCode NotificationSubscriberManager::DistributeOperation(const sptrneedNotifyResponse && record->subscriber != nullptr) { - result = record->subscriber->OnResponse(notification); + result = record->subscriber->OnResponse(*notification); return; } result = ERR_ANS_DISTRIBUTED_OPERATION_FAILED; diff --git a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp index 4e5888816464787664136b3586c58be9ad4f1006..a2f62f00411d699b469102e6eb32c06606bc00e9 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1108,7 +1108,7 @@ HWTEST_F(AnsPublishServiceTest, PublishRemoveDuplicateEvent_00003, Function | Sm */ HWTEST_F(AnsPublishServiceTest, CanPopEnableNotificationDialog_001, Function | SmallTest | Level1) { - sptr callback = nullptr; + sptr callback = nullptr; bool canPop = false; std::string bundleName = ""; ErrCode result = advancedNotificationService_->CanPopEnableNotificationDialog(callback, canPop, bundleName); diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 3dbca2c84aeb7cdef90510778c0dfeefc6280f81..c4693a008107353763f26b09c76aa91dfe1f6e8b 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_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 @@ -816,7 +816,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); std::string deviceId = "DeviceId"; - sptr callback = nullptr; + sptr callback = nullptr; sptr callerToken = nullptr; ASSERT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, callback, callerToken), (int)ERR_ANS_INVALID_PARAM); diff --git a/services/ans/test/unittest/ans_manager_stub_test.cpp b/services/ans/test/unittest/ans_manager_stub_test.cpp index b3bff905598ae5bf9f938cae1b7fb49e02d162f6..8b61e14fa81a8b486a1b152e7cdd9c12c7318136 100644 --- a/services/ans/test/unittest/ans_manager_stub_test.cpp +++ b/services/ans/test/unittest/ans_manager_stub_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 @@ -3927,7 +3927,7 @@ HWTEST_F(AnsManagerStubTest, UpdateSlots01, Function | SmallTest | Level1) HWTEST_F(AnsManagerStubTest, RequestEnableNotification01, Function | SmallTest | Level1) { std::string deviceId = "this is deviceId"; - sptr callback = nullptr; + sptr callback = nullptr; sptr callerToken = nullptr; ErrCode result = ansManagerStub_->RequestEnableNotification(deviceId, callback, callerToken); EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); 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 21cb444ef765110ddaa9c6a114ab1a5dfc2f7459..b0d0bdfa22c4626fcc76b1a8611b7a1077b9e736 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,37 @@ 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 Notification ¬ification, + const NotificationSortingMap ¬ificationMap) override { return ERR_OK; }; - MOCK_METHOD(void, OnConsumedList, (const std::vector> ¬ifications, - const sptr ¬ificationMap)); + MOCK_METHOD(ErrCode, OnConsumedList, (const std::vector ¬ifications, + const NotificationSortingMap ¬ificationMap)); - void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, - int32_t deleteReason) override {}; + ErrCode OnCanceled(const Notification ¬ification, const NotificationSortingMap ¬ificationMap, + 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 NotificationSortingMap ¬ificationMap, int32_t deleteReason) override { return ERR_OK; }; - void OnUpdated(const sptr ¬ificationMap) override {}; + ErrCode OnUpdated(const NotificationSortingMap ¬ificationMap) override { return ERR_OK; }; - void OnDoNotDisturbDateChange(const sptr &date) override {}; + ErrCode OnDoNotDisturbDateChange(const NotificationDoNotDisturbDate &date) override { return ERR_OK; }; - void OnEnabledNotificationChanged(const sptr &callbackData) override {}; + ErrCode OnEnabledNotificationChanged( + const EnabledNotificationCallbackData &callbackData) override { return ERR_OK; }; - void OnBadgeChanged(const sptr &badgeData) override {}; + ErrCode OnBadgeChanged(const BadgeNumberCallbackData &badgeData) override { return ERR_OK; }; - void OnBadgeEnabledChanged(const sptr &callbackData) override {}; + ErrCode OnBadgeEnabledChanged( + const EnabledNotificationCallbackData &callbackData) override { return ERR_OK; }; - void OnApplicationInfoNeedChanged(const std::string& bundleName) override {}; + ErrCode OnApplicationInfoNeedChanged(const std::string& bundleName) override { return ERR_OK; }; - ErrCode OnResponse(const sptr ¬ification) { return 0; } + ErrCode OnResponse(const Notification ¬ification) { return 0; } }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp index 292da8ae8f1ba84637178daacd317d3eb7b0e377..636c3eb79bf4dadca70ac5ec853b9a582baaaa52 100644 --- a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_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 @@ -49,14 +49,14 @@ private: static std::shared_ptr notificationLocalLiveViewSubscriberManager_; static TestAnsSubscriber testAnsSubscriber_; - static sptr subscriber_; + static sptr subscriber_; }; std::shared_ptr NotificationLocalLiveViewSubscriberManagerTest::notificationLocalLiveViewSubscriberManager_ = nullptr; NotificationLocalLiveViewSubscriberManagerTest::TestAnsSubscriber NotificationLocalLiveViewSubscriberManagerTest::testAnsSubscriber_; -sptr +sptr NotificationLocalLiveViewSubscriberManagerTest::subscriber_ = nullptr; void NotificationLocalLiveViewSubscriberManagerTest::SetUpTestCase() 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 32d4f60ccb5d439e893756b863496c7588b63be8..56690c97c5cd165b5e43a04e40bd2af356b94cf3 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)); } @@ -572,7 +572,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 d5b9e47e67ace7500931ee9eb4dde9a1981c315d..c0a460b17b9105596f41ce5d38a5712367142971 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 @@ -71,12 +71,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() { diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index 55f6f9b6c19ce78401af595941f74a818a0c60ac..3896ba99cf11f76a62d65e3258f63194d194e153 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.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 @@ -100,10 +100,6 @@ 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); @@ -142,10 +138,8 @@ namespace OHOS { service->GetSyncNotificationEnabledWithoutApp(userId, enabled); int32_t badgeNum = fuzzData->ConsumeIntegral(); service->SetBadgeNumber(badgeNum, fuzzData->ConsumeRandomLengthString()); - sptr dialogCallback = new Notification::AnsDialogCallbackProxy(nullptr); - sptr callerToken = new Notification::AnsSubscriberStub(); + sptr dialogCallback = new Notification::AnsDialogCallbackProxy(nullptr); 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 c33f84bed4c09a89e05f3766be29428cd66546c3..2568d343405c4e63e12cdf62135b63e01f1946d4 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.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 @@ -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); @@ -377,7 +367,7 @@ namespace OHOS { ansManagerStub.DeleteAll(); ansManagerStub.GetSlotsByBundle(bundleOption, slots); ansManagerStub.UpdateSlots(bundleOption, slots); - sptr dialogCallback = nullptr; + sptr dialogCallback = nullptr; sptr callerToken = nullptr; ansManagerStub.RequestEnableNotification(stringData, dialogCallback, callerToken); bool enabled = fuzzData->ConsumeBool(); diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index 27a365c7fec6f49d35e46d330b1167466db630dc..d7f787713c94d64bb32807c21065cd1b37be7fcb 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.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 @@ -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); @@ -373,7 +363,7 @@ namespace OHOS { ansManagerStub.DeleteAll(); ansManagerStub.GetSlotsByBundle(bundleOption, slots); ansManagerStub.UpdateSlots(bundleOption, slots); - sptr dialogCallback = nullptr; + sptr dialogCallback = nullptr; sptr callerToken = nullptr; ansManagerStub.RequestEnableNotification(stringData, dialogCallback, callerToken); bool enabled = fuzzData->ConsumeBool(); diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index 0637f8fcc1658f9ebcfc63192492f4580ec3f28a..d3523ef054c5686b14061499642d12cb3ee227d1 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.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 @@ -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); @@ -365,7 +355,7 @@ namespace OHOS { ansManagerStub.DeleteAll(); ansManagerStub.GetSlotsByBundle(bundleOption, slots); ansManagerStub.UpdateSlots(bundleOption, slots); - sptr dialogCallback = nullptr; + sptr dialogCallback = nullptr; sptr callerToken = nullptr; ansManagerStub.RequestEnableNotification(stringData, dialogCallback, callerToken); bool enabled = fuzzData->ConsumeBool(); diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp index 02d54175053bea4e45c2994c86569b97adfa7160..91545b959e11c2d0bc0f3cd0dc9162d9706347c7 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,22 +29,18 @@ 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); - // test InnerTransact function ansSubscriberProxy.OnConnected(); // test InnerTransact function ansSubscriberProxy.OnDisconnected(); sptr request = new Notification::NotificationRequest(); // test InnerTransact function - sptr notification = new Notification::Notification(request); + auto notification = Notification::Notification(request); - sptr notificationMap = new Notification::NotificationSortingMap(); + auto notificationMap = Notification::NotificationSortingMap(); ansSubscriberProxy.OnConsumed(notification, notificationMap); // test OnCanceled function int32_t deleteReason = 1; @@ -52,10 +48,10 @@ namespace OHOS { // test OnCanceled function ansSubscriberProxy.OnUpdated(notificationMap); // test OnCanceled function - sptr date = new Notification::NotificationDoNotDisturbDate(); + auto date = Notification::NotificationDoNotDisturbDate(); ansSubscriberProxy.OnDoNotDisturbDateChange(date); // test OnEnabledNotificationChanged function - sptr callbackData = new Notification::EnabledNotificationCallbackData(); + auto callbackData = Notification::EnabledNotificationCallbackData(); ansSubscriberProxy.OnEnabledNotificationChanged(callbackData); // test OnApplicationInfoNeedChanged function ansSubscriberProxy.OnApplicationInfoNeedChanged("com.test.demo"); diff --git a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp index c78d08017586f830f73f3e0d76bf1b6af2042165..203aba626d6a3a71457f0d19983e3b7ee2d42b7e 100644 --- a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp +++ b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_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 @@ -24,73 +24,6 @@ #include "notification_request.h" #include -namespace OHOS { - bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) - { - Notification::AnsSubscriberStub ansSubscriberStub; - Notification::AnsSubscriberLocalLiveViewStub ansSubscriberLocalLiveViewStub; - 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"); - ansSubscriberStub.OnResponse(notification); - // 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 HandleOnResponse function - ansSubscriberLocalLiveViewStub.HandleOnResponse(datas, reply); - // test HandleOnConsumedListMap function - ansSubscriberStub.HandleOnConsumedListMap(datas, reply); - // test HandleOnDisconnected function - ansSubscriberLocalLiveViewStub.HandleOnDisconnected(datas, reply); - // test HandleOnBadgeChanged function - ansSubscriberStub.HandleOnBadgeChanged(datas, reply); - // test HandleOnCanceledListMap function - ansSubscriberStub.HandleOnCanceledListMap(datas, reply); - // test HandleOnConnected function - ansSubscriberLocalLiveViewStub.HandleOnConnected(datas, reply); - return true; - } -} - /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { @@ -101,7 +34,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION }; SystemHapTokenGet(requestPermission); - FuzzedDataProvider fdp(data, size); - OHOS::DoSomethingInterestingWithMyAPI(&fdp); return 0; }