From 93c361a21aaad4ffab125cd655e1b50ca2bd56d2 Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Sat, 22 Feb 2025 15:14:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E9=80=9A=E7=9F=A5IDL?= =?UTF-8?q?=E5=8C=96=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhengzhuolan --- frameworks/ans/BUILD.gn | 54 +- .../IAnsDialogCallback.idl} | 30 +- frameworks/ans/IAnsSubscriber.idl | 36 + .../IAnsSubscriberLocalLiveView.idl} | 30 +- frameworks/ans/src/ans_dialog_host_client.cpp | 9 +- ...otification_local_live_view_subscriber.cpp | 15 +- .../ans/src/notification_subscriber.cpp | 95 +- frameworks/core/BUILD.gn | 3 +- .../include/ans_dialog_callback_interface.h | 62 - .../core/include/ans_manager_interface.h | 20 +- frameworks/core/include/ans_manager_proxy.h | 14 +- frameworks/core/include/ans_manager_stub.h | 16 +- .../core/include/ans_subscriber_interface.h | 122 - .../core/include/ans_subscriber_listener.h | 34 +- ...ans_subscriber_local_live_view_interface.h | 55 - .../ans_subscriber_local_live_view_proxy.h | 69 - .../ans_subscriber_local_live_view_stub.h | 66 - .../core/include/ans_subscriber_proxy.h | 135 - frameworks/core/include/ans_subscriber_stub.h | 143 - ..._callback_proxy.h => dialog_status_data.h} | 57 +- .../dialog_status_data.cpp} | 47 +- .../listener/ans_dialog_callback_proxy.cpp | 47 - .../src/listener/ans_subscriber_listener.cpp | 116 +- .../ans_subscriber_local_live_view_proxy.cpp | 119 - .../ans_subscriber_local_live_view_stub.cpp | 124 - .../src/listener/ans_subscriber_proxy.cpp | 454 --- .../core/src/listener/ans_subscriber_stub.cpp | 377 --- .../core/src/manager/ans_manager_proxy.cpp | 4 +- .../src/manager/ans_manager_proxy_bundle.cpp | 8 +- .../src/manager/ans_manager_proxy_disturb.cpp | 4 +- .../src/manager/ans_manager_proxy_slot.cpp | 4 +- .../manager/ans_manager_proxy_subscribe.cpp | 12 +- .../src/manager/ans_manager_stub_invalid.cpp | 4 +- frameworks/core/test/unittest/BUILD.gn | 3 +- .../ans_notification_branch_test.cpp | 1826 ++++++------ .../ans_subscriber_proxy_branch_test.cpp | 262 +- .../ans_subscriber_proxy_unit_test.cpp | 1154 +++----- .../ans_subscriber_stub_test/BUILD.gn | 52 - .../ans_subscriber_stub_unit_test.cpp | 575 ---- .../js/napi/src/js_ans_dialog_callback.cpp | 4 +- frameworks/reminder/BUILD.gn | 3 +- .../notification_local_live_view_subscriber.h | 8 +- .../inner_api/notification_subscriber.h | 34 +- .../ans_dialog_callback_native_interface.h | 4 +- .../kits/native/ans_dialog_host_client.h | 4 +- services/ans/BUILD.gn | 3 +- .../include/advanced_notification_service.h | 14 +- .../include/disturb_manager/disturb_manager.h | 2 +- .../ans/include/notification_dialog_manager.h | 13 +- ...ation_local_live_view_subscriber_manager.h | 19 +- .../include/notification_subscriber_manager.h | 18 +- .../ans/include/slot_manager/slot_manager.h | 4 +- .../advanced_notification_publish_service.cpp | 8 +- ...vanced_notification_subscriber_service.cpp | 8 +- services/ans/src/ans_manager_stub.cpp | 16 +- services/ans/src/ans_manager_stub_invalid.cpp | 14 +- .../ans/src/notification_dialog_manager.cpp | 8 +- ...ion_local_live_view_subscriber_manager.cpp | 18 +- .../src/notification_subscriber_manager.cpp | 46 +- ...nced_notification_publish_service_test.cpp | 4 +- .../advanced_notification_service_test.cpp | 4 +- .../test/unittest/ans_manager_stub_test.cpp | 4 +- .../mock/include/mock_ans_subscriber.h | 42 +- ...ocal_live_view_subscriber_manager_test.cpp | 6 +- ...ication_subscriber_manager_branch_test.cpp | 2460 ++++++++--------- .../notification_subscriber_manager_test.cpp | 6 +- .../advancednotificationservice_fuzzer.cpp | 10 +- .../ansmanagerstub_fuzzer.cpp | 868 +++--- .../ansmanagerstubannex_fuzzer.cpp | 860 +++--- .../ansmanagerstubannexthree_fuzzer.cpp | 844 +++--- .../anssubscriberproxy_fuzzer.cpp | 158 +- .../anssubscriberstub_fuzzer.cpp | 145 +- 72 files changed, 4592 insertions(+), 7324 deletions(-) rename frameworks/{core/src/listener/ans_dialog_callback_stub.cpp => ans/IAnsDialogCallback.idl} (41%) create mode 100644 frameworks/ans/IAnsSubscriber.idl rename frameworks/{core/src/listener/ans_dialog_callback_interface.cpp => ans/IAnsSubscriberLocalLiveView.idl} (46%) delete mode 100644 frameworks/core/include/ans_dialog_callback_interface.h delete mode 100644 frameworks/core/include/ans_subscriber_interface.h delete mode 100644 frameworks/core/include/ans_subscriber_local_live_view_interface.h delete mode 100644 frameworks/core/include/ans_subscriber_local_live_view_proxy.h delete mode 100644 frameworks/core/include/ans_subscriber_local_live_view_stub.h delete mode 100644 frameworks/core/include/ans_subscriber_proxy.h delete mode 100644 frameworks/core/include/ans_subscriber_stub.h rename frameworks/core/include/{ans_dialog_callback_proxy.h => dialog_status_data.h} (40%) rename frameworks/core/{include/ans_dialog_callback_stub.h => src/dialog_status_data.cpp} (44%) delete mode 100644 frameworks/core/src/listener/ans_dialog_callback_proxy.cpp delete mode 100644 frameworks/core/src/listener/ans_subscriber_local_live_view_proxy.cpp delete mode 100644 frameworks/core/src/listener/ans_subscriber_local_live_view_stub.cpp delete mode 100644 frameworks/core/src/listener/ans_subscriber_proxy.cpp delete mode 100644 frameworks/core/src/listener/ans_subscriber_stub.cpp delete mode 100644 frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn delete mode 100644 frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 822e942a1..26bf856c5 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/src/listener/ans_dialog_callback_stub.cpp b/frameworks/ans/IAnsDialogCallback.idl similarity index 41% rename from frameworks/core/src/listener/ans_dialog_callback_stub.cpp rename to frameworks/ans/IAnsDialogCallback.idl index ae3a2207d..20b04e2cb 100644 --- a/frameworks/core/src/listener/ans_dialog_callback_stub.cpp +++ 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,26 +14,7 @@ * 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; -} -} // namespace OHOS::Notification + 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 000000000..187cbf9ad --- /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_interface.cpp b/frameworks/ans/IAnsSubscriberLocalLiveView.idl similarity index 46% rename from frameworks/core/src/listener/ans_dialog_callback_interface.cpp rename to frameworks/ans/IAnsSubscriberLocalLiveView.idl index 3c02047a9..8517ab9d2 100644 --- a/frameworks/core/src/listener/ans_dialog_callback_interface.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,27 +13,9 @@ * limitations under the License. */ -#include "ans_dialog_callback_interface.h" - -#include "ans_log_wrapper.h" - -namespace OHOS::Notification { -bool DialogStatusData::Marshalling(Parcel& parcel) const -{ - if (!parcel.WriteInt32(status_)) { - ANS_LOGE("Failed to write status"); - return false; - } - return true; -} - -DialogStatusData* DialogStatusData::Unmarshalling(Parcel& parcel) -{ - DialogStatusData* data = new (std::nothrow) DialogStatusData( - static_cast(parcel.ReadInt32())); - if (data == nullptr) { - return nullptr; - } - return data; +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 05a4c4656..2fbc625f6 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 dcc4aaa63..fb909f252 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 15869f884..97dd5d669 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 c90cde0df..c4e7b5d74 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_interface.h b/frameworks/core/include/ans_dialog_callback_interface.h deleted file mode 100644 index c2a8cbdae..000000000 --- a/frameworks/core/include/ans_dialog_callback_interface.h +++ /dev/null @@ -1,62 +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_INTERFACE_H -#define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_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)) {} - - bool Marshalling(Parcel &parcel) const override; - 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 diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index c4489a7d2..7df2b8dbf 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 ab3317984..8450bd46f 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 1c6439957..998eb7604 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 57abde28c..000000000 --- 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 2a4ac37ae..81ad1ab37 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 4b24f5477..000000000 --- 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 0bc561259..000000000 --- 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 a7e9f1508..000000000 --- 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 435e0fb53..000000000 --- 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 35906d3b5..000000000 --- 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_proxy.h b/frameworks/core/include/dialog_status_data.h similarity index 40% rename from frameworks/core/include/ans_dialog_callback_proxy.h rename to frameworks/core/include/dialog_status_data.h index e626bd85b..930482ba0 100644 --- a/frameworks/core/include/ans_dialog_callback_proxy.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,26 +13,35 @@ * 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 + #ifndef BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_H + #define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_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)) {} + + bool Marshalling(Parcel &parcel) const override; + static DialogStatusData* Unmarshalling(Parcel &parcel); + + inline int32_t GetStatus() const { return status_; } + + private: + int32_t status_; + }; + } // namespace OHOS::Notification + + #endif // BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_INTERFACE_H + \ No newline at end of file diff --git a/frameworks/core/include/ans_dialog_callback_stub.h b/frameworks/core/src/dialog_status_data.cpp similarity index 44% rename from frameworks/core/include/ans_dialog_callback_stub.h rename to frameworks/core/src/dialog_status_data.cpp index e18c42917..07086dbe5 100644 --- a/frameworks/core/include/ans_dialog_callback_stub.h +++ 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,25 +13,28 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_STUB_H -#define BASE_NOTIFICATION_ANS_DIALOG_CALLBACK_STUB_H + #include "dialog_status_data.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 + #include "ans_log_wrapper.h" + + namespace OHOS::Notification { + bool DialogStatusData::Marshalling(Parcel& parcel) const + { + if (!parcel.WriteInt32(status_)) { + ANS_LOGE("Failed to write status"); + return false; + } + return true; + } + + DialogStatusData* DialogStatusData::Unmarshalling(Parcel& parcel) + { + DialogStatusData* data = new (std::nothrow) DialogStatusData( + static_cast(parcel.ReadInt32())); + if (data == nullptr) { + return nullptr; + } + 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 9764cb314..000000000 --- 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 886428c7a..1ab01234e 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 27e935805..000000000 --- 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 9317706df..000000000 --- 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 a2fa1276c..000000000 --- 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 4381035a3..000000000 --- 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 7926742a1..76a10b303 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 73bc9c18d..76281906a 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 6655bfa7c..8a1656e42 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 8b4e9ad34..ff18e3c90 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 19c90ad7b..75b4c8465 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 714317b6b..1ab914a33 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 f8305fd0d..63f51f43f 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 932308672..91ca73306 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,913 +1,913 @@ -/* - * Copyright (c) 2023-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_notification.h" -#include "ans_subscriber_proxy.h" -#include "ans_manager_interface.h" -#include "ans_manager_proxy.h" -#undef private -#undef protected -#include "ans_dialog_callback_interface.h" -#include "ans_inner_errors.h" -#include "ipc_types.h" -#include "notification.h" -#include "notification_request.h" -#include "singleton.h" -#include "notification_subscriber.h" - -extern void MockGetAnsManagerProxy(OHOS::sptr mockRet); - -using namespace testing; -using namespace testing::ext; -using namespace OHOS; -using namespace OHOS::Notification; - -namespace OHOS { -namespace Notification { -class MockAnsManagerInterface : public AnsManagerInterface { -public: - MockAnsManagerInterface() = default; - virtual ~MockAnsManagerInterface() - {}; - sptr AsObject() override - { - return nullptr; - } - - ErrCode Publish(const std::string &label, const sptr ¬ification) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode PublishNotificationForIndirectProxy(const sptr ¬ification) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode Cancel(int notificationId, const std::string &label, const std::string &instanceKey) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelAll(const std::string &instanceKey) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelAsBundle( - int32_t notificationId, const std::string &representativeBundle, int32_t userId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelAsBundle( - const sptr &bundleOption, int32_t notificationId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelAsBundle( - const sptr &bundleOption, int32_t notificationId, int32_t userId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode AddSlots(const std::vector> &slots) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveAllSlots() override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSlots(std::vector> &slots) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSlotNumAsBundle(const sptr &bundleOption, uint64_t &num) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetActiveNotifications(std::vector> ¬ifications, - const std::string &instanceKey) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetActiveNotificationNums(uint64_t &num) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetAllActiveNotifications(std::vector> ¬ifications) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSpecialActiveNotifications( - const std::vector &key, std::vector> ¬ifications) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode PublishAsBundle( - const sptr notification, const std::string &representativeBundle) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetNotificationBadgeNum(int num) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetBundleImportance(int &importance) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode HasNotificationPolicyAccessPermission(bool &granted) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode Delete(const std::string &key, int32_t removeReason) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveNotification(const sptr &bundleOption, int notificationId, - const std::string &label, int32_t removeReason) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveAllNotifications(const sptr &bundleOption) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveNotifications(const std::vector &hashcodes, int32_t removeReason) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DeleteByBundle(const sptr &bundleOption) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DeleteAll() override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSlotsByBundle( - const sptr &bundleOption, std::vector> &slots) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSlotByBundle( - const sptr &bundleOption, const NotificationConstant::SlotType &slotType, - sptr &slot) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode UpdateSlots( - const sptr &bundleOption, const std::vector> &slots) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RequestEnableNotification(const std::string &deviceId, - const sptr &callback, - const sptr &callerToken) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetNotificationsEnabledForSpecialBundle( - const std::string &deviceId, const sptr &bundleOption, bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetShowBadgeEnabledForBundle(const sptr &bundleOption, bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetShowBadgeEnabledForBundle(const sptr &bundleOption, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetShowBadgeEnabled(bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode Subscribe(const sptr &subscriber, - const sptr &info) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SubscribeSelf(const sptr &subscriber) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetAllNotificationEnabledBundles(std::vector &bundleOption)override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetTargetDeviceStatus(const std::string &deviceType, int32_t &status) - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetAllLiveViewEnabledBundles(std::vector &bundleOption) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetAllDistribuedEnabledBundles(const std::string& deviceType, - std::vector &bundleOption) override - { - return ERR_ANS_INVALID_PARAM; - } - - 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 - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsAllowedNotify(bool &allowed) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsAllowedNotifySelf(bool &allowed) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CanPopEnableNotificationDialog(const sptr &callback, - bool &canPop, std::string &bundleName) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveEnableNotificationDialog() override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetDoNotDisturbDate(const sptr &date) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetDoNotDisturbDate(sptr &date) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode AddDoNotDisturbProfiles(const std::vector> &profiles) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveDoNotDisturbProfiles(const std::vector> &profiles) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelGroup(const std::string &groupName, const std::string &instanceKey) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RemoveGroupByBundle( - const sptr &bundleOption, const std::string &groupName) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsDistributedEnabled(bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode EnableDistributed(bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode EnableDistributedByBundle(const sptr &bundleOption, bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode EnableDistributedSelf(bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsDistributedEnableByBundle(const sptr &bundleOption, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode PublishContinuousTaskNotification(const sptr &request) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DeleteAllByUser(const int32_t &userId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr &date) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, - std::vector &dumpInfo) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetBadgeNumberByBundle(const sptr& bundleOption, int32_t badgeNumber) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode RegisterPushCallback(const sptr &pushCallback, - const sptr ¬ificationCheckRequest) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode UnregisterPushCallback() override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetActiveNotificationByFilter(const sptr &bundleOption, - const int32_t notificationId, const std::string &label, std::vector extraInfoKeys, - sptr &request) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode TriggerLocalLiveView(const sptr &bundleOption, - const int32_t notificationId, const sptr &buttonOption) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetDistributedEnabledByBundle(const sptr &bundleOption, - const std::string &deviceType, const bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsDistributedEnabledByBundle(const sptr &bundleOption, - const std::string &deviceType, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetDistributedEnabledBySlot( - const NotificationConstant::SlotType &slotType, const std::string &deviceType, const bool enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode IsDistributedEnabledBySlot( - const NotificationConstant::SlotType &slotType, const std::string &deviceType, bool &enabled) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelAsBundleWithAgent(const sptr &bundleOption, const int32_t id) - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status, - const uint32_t controlFlag) - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile) - { - return ERR_ANS_INVALID_PARAM; - } - -#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED - ErrCode RegisterSwingCallback(const sptr &swingCallback) override - { - return ERR_ANS_INVALID_PARAM; - } -#endif - - ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DisableNotificationFeature(const sptr ¬ificationDisable) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DistributeOperation(const std::string &hashCode) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetNotificationRequestByHashCode( - const std::string& hashCode, sptr& notificationRequest) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode SetHashCodeRule(const uint32_t type) - { - return ERR_ANS_INVALID_PARAM; - } -}; - -class AnsNotificationBranchTest : public testing::Test { -public: - AnsNotificationBranchTest() {} - - virtual ~AnsNotificationBranchTest() {} - - static void SetUpTestCase(); - - static void TearDownTestCase(); - - void SetUp(); -}; - -void AnsNotificationBranchTest::SetUpTestCase() -{ - MockGetAnsManagerProxy(nullptr); -} - -void AnsNotificationBranchTest::TearDownTestCase() {} - -void AnsNotificationBranchTest::SetUp() {} - -/* - * @tc.name: RemoveNotifications_0100 - * @tc.desc: Test RemoveNotifications and hashcodes is empty - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0100, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - std::vector hashcodes; - int32_t removeReason = 1; - ErrCode ret = ansNotification->RemoveNotifications(hashcodes, removeReason); - EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); -} - -/* - * @tc.name: RemoveNotifications_0200 - * @tc.desc: 1.Test RemoveNotifications and hashcodes is not empty - * 2.GetAnsManagerProxy is false - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0200, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - std::string hashcode = "aa"; - std::vector hashcodes; - hashcodes.emplace_back(hashcode); - int32_t removeReason = 1; - ErrCode ret = ansNotification->RemoveNotifications(hashcodes, removeReason); - EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); -} - -/* - * @tc.name: RemoveNotifications_0300 - * @tc.desc: 1.Test RemoveNotifications and hashcodes is not empty - * 2.GetAnsManagerProxy is true - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0300, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - std::string hashcode = "aa"; - std::vector hashcodes; - hashcodes.emplace_back(hashcode); - int32_t removeReason = 1; - ansNotification->RemoveNotifications(hashcodes, removeReason); -} - -/* - * @tc.name: RegisterPushCallback_0100 - * @tc.desc: 1.Test RegisterPushCallback - * 2.GetAnsManagerProxy is false - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0100, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - sptr pushCallback = nullptr; - sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); - ErrCode ret = ansNotification->RegisterPushCallback(pushCallback, checkRequest); - EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); -} - -/* - * @tc.name: RegisterPushCallback_0200 - * @tc.desc: 1.Test RegisterPushCallback - * 2.GetAnsManagerProxy is true - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0200, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - sptr pushCallback = nullptr; - sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); - ansNotification->RegisterPushCallback(pushCallback, checkRequest); -} - -/* - * @tc.name: UnregisterPushCallback_0100 - * @tc.desc: 1.Test UnregisterPushCallback - * 2.GetAnsManagerProxy is false - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, UnregisterPushCallback_0100, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - ErrCode ret = ansNotification->UnregisterPushCallback(); - EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); -} - -/* - * @tc.name: UnregisterPushCallback_0200 - * @tc.desc: 1.Test UnregisterPushCallback - * 2.GetAnsManagerProxy is true - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationBranchTest, UnregisterPushCallback_0200, Function | MediumTest | Level1) -{ - auto ansNotification = std::make_shared(); - EXPECT_NE(ansNotification, nullptr); - ansNotification->UnregisterPushCallback(); -} - -/* - * @tc.name: CanPublishLiveViewContent_0100 - * @tc.desc: CanPublishLiveViewContent - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0100, Function | MediumTest | Level1) -{ - NotificationRequest request; - auto notification = std::make_shared(); - EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); -} - -/* - * @tc.name: CanPublishLiveViewContent_0110 - * @tc.desc: CanPublishLiveViewContent - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0110, Function | MediumTest | Level1) -{ - NotificationRequest request; - request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_BUTT); - auto content = std::make_shared(liveViewContent); - request.SetContent(content); - - auto notification = std::make_shared(); - EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); -} - -/* - * @tc.name: CanPublishLiveViewContent_0120 - * @tc.desc: CanPublishLiveViewContent - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0120, Function | MediumTest | Level1) -{ - NotificationRequest request; - request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - auto content = std::make_shared(liveViewContent); - request.SetContent(content); - - auto notification = std::make_shared(); - EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); -} - -/* - * @tc.name: CanPublishLiveViewContent_0130 - * @tc.desc: CanPublishLiveViewContent - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0130, Function | MediumTest | Level1) -{ - NotificationRequest request; - request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE); - auto content = std::make_shared(liveViewContent); - request.SetContent(content); - - auto notification = std::make_shared(); - EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); -} - -/* - * @tc.name: CanPublishLiveViewContent_0140 - * @tc.desc: CanPublishLiveViewContent - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0140, Function | MediumTest | Level1) -{ - NotificationRequest request; - request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - auto content = std::make_shared(liveViewContent); - request.SetContent(content); - request.notificationContent_ = nullptr; - - auto notification = std::make_shared(); - EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); -} - -/* - * @tc.name: CanPublishLiveViewContent_0150 - * @tc.desc: CanPublishLiveViewContent - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0150, Function | MediumTest | Level1) -{ - NotificationRequest request; - request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - auto liveViewContent = std::make_shared(); - auto content = std::make_shared(liveViewContent); - content->content_ = nullptr; - request.SetContent(content); - - auto notification = std::make_shared(); - EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); -} - -/* - * @tc.name: SetNotificationSlotFlagsAsBundle_0001 - * @tc.desc: SetNotificationSlotFlagsAsBundle - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, SetNotificationSlotFlagsAsBundle_0001, Function | MediumTest | Level1) -{ - NotificationBundleOption bundle; - uint32_t slotFlags = 1; - auto notification = std::make_shared(); - ErrCode ret = notification->SetNotificationSlotFlagsAsBundle(bundle, slotFlags); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = notification->GetNotificationSlotFlagsAsBundle(bundle, slotFlags); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); -} - -/* - * @tc.name: PublishNotification_0001 - * @tc.desc: PublishNotification - * @tc.type: FUNC - * @tc.require: issule - */ -HWTEST_F(AnsNotificationBranchTest, PublishNotification_0001, Function | MediumTest | Level1) -{ - auto notification = std::make_shared(); - MockGetAnsManagerProxy(new (std::nothrow) MockAnsManagerInterface()); - NotificationRequest req; - std::shared_ptr mediaContent = std::make_shared(); - auto content = std::make_shared(mediaContent); - content->content_ = nullptr; - req.SetContent(content); - - auto ret = notification->PublishNotification("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = notification->PublishNotificationAsBundle("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - - auto liveViewContent = std::make_shared(); - auto content1 = std::make_shared(liveViewContent); - content1->content_ = nullptr; - req.SetContent(content1); - req.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - ret = notification->PublishNotification("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = notification->PublishNotificationAsBundle("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); -} - -} // namespace Notification -} // namespace OHOS +/* + * 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 + * + * 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_notification.h" +#include "ans_subscriber_proxy.h" +#include "ans_manager_interface.h" +#include "ans_manager_proxy.h" +#undef private +#undef protected +#include "ians_dialog_callback.h" +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "notification.h" +#include "notification_request.h" +#include "singleton.h" +#include "notification_subscriber.h" + +extern void MockGetAnsManagerProxy(OHOS::sptr mockRet); + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +namespace OHOS { +namespace Notification { +class MockAnsManagerInterface : public AnsManagerInterface { +public: + MockAnsManagerInterface() = default; + virtual ~MockAnsManagerInterface() + {}; + sptr AsObject() override + { + return nullptr; + } + + ErrCode Publish(const std::string &label, const sptr ¬ification) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishNotificationForIndirectProxy(const sptr ¬ification) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Cancel(int notificationId, const std::string &label, const std::string &instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAll(const std::string &instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundle( + int32_t notificationId, const std::string &representativeBundle, int32_t userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundle( + const sptr &bundleOption, int32_t notificationId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundle( + const sptr &bundleOption, int32_t notificationId, int32_t userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddSlots(const std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveAllSlots() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlots(std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotNumAsBundle(const sptr &bundleOption, uint64_t &num) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetActiveNotifications(std::vector> ¬ifications, + const std::string &instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetActiveNotificationNums(uint64_t &num) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetAllActiveNotifications(std::vector> ¬ifications) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSpecialActiveNotifications( + const std::vector &key, std::vector> ¬ifications) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishAsBundle( + const sptr notification, const std::string &representativeBundle) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationBadgeNum(int num) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetBundleImportance(int &importance) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode HasNotificationPolicyAccessPermission(bool &granted) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Delete(const std::string &key, int32_t removeReason) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveNotification(const sptr &bundleOption, int notificationId, + const std::string &label, int32_t removeReason) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveAllNotifications(const sptr &bundleOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveNotifications(const std::vector &hashcodes, int32_t removeReason) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DeleteByBundle(const sptr &bundleOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DeleteAll() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotsByBundle( + const sptr &bundleOption, std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotByBundle( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode UpdateSlots( + const sptr &bundleOption, const std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RequestEnableNotification(const std::string &deviceId, + const sptr &callback, + const sptr &callerToken) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledForSpecialBundle( + const std::string &deviceId, const sptr &bundleOption, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetShowBadgeEnabledForBundle(const sptr &bundleOption, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetShowBadgeEnabledForBundle(const sptr &bundleOption, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetShowBadgeEnabled(bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Subscribe(const sptr &subscriber, + const sptr &info) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SubscribeSelf(const sptr &subscriber) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetAllNotificationEnabledBundles(std::vector &bundleOption)override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetTargetDeviceStatus(const std::string &deviceType, int32_t &status) + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetAllLiveViewEnabledBundles(std::vector &bundleOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetAllDistribuedEnabledBundles(const std::string& deviceType, + std::vector &bundleOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + 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 + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsAllowedNotify(bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsAllowedNotifySelf(bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CanPopEnableNotificationDialog(const sptr &callback, + bool &canPop, std::string &bundleName) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveEnableNotificationDialog() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDoNotDisturbDate(const sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDoNotDisturbDate(sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddDoNotDisturbProfiles(const std::vector> &profiles) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveDoNotDisturbProfiles(const std::vector> &profiles) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelGroup(const std::string &groupName, const std::string &instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnabled(bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode EnableDistributed(bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode EnableDistributedByBundle(const sptr &bundleOption, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode EnableDistributedSelf(bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnableByBundle(const sptr &bundleOption, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishContinuousTaskNotification(const sptr &request) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DeleteAllByUser(const int32_t &userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, + std::vector &dumpInfo) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetBadgeNumberByBundle(const sptr& bundleOption, int32_t badgeNumber) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode UnregisterPushCallback() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetActiveNotificationByFilter(const sptr &bundleOption, + const int32_t notificationId, const std::string &label, std::vector extraInfoKeys, + sptr &request) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode TriggerLocalLiveView(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDistributedEnabledBySlot( + const NotificationConstant::SlotType &slotType, const std::string &deviceType, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnabledBySlot( + const NotificationConstant::SlotType &slotType, const std::string &deviceType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundleWithAgent(const sptr &bundleOption, const int32_t id) + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status, + const uint32_t controlFlag) + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile) + { + return ERR_ANS_INVALID_PARAM; + } + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + ErrCode RegisterSwingCallback(const sptr &swingCallback) override + { + return ERR_ANS_INVALID_PARAM; + } +#endif + + ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DisableNotificationFeature(const sptr ¬ificationDisable) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DistributeOperation(const std::string &hashCode) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetNotificationRequestByHashCode( + const std::string& hashCode, sptr& notificationRequest) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetHashCodeRule(const uint32_t type) + { + return ERR_ANS_INVALID_PARAM; + } +}; + +class AnsNotificationBranchTest : public testing::Test { +public: + AnsNotificationBranchTest() {} + + virtual ~AnsNotificationBranchTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); +}; + +void AnsNotificationBranchTest::SetUpTestCase() +{ + MockGetAnsManagerProxy(nullptr); +} + +void AnsNotificationBranchTest::TearDownTestCase() {} + +void AnsNotificationBranchTest::SetUp() {} + +/* + * @tc.name: RemoveNotifications_0100 + * @tc.desc: Test RemoveNotifications and hashcodes is empty + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0100, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + std::vector hashcodes; + int32_t removeReason = 1; + ErrCode ret = ansNotification->RemoveNotifications(hashcodes, removeReason); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: RemoveNotifications_0200 + * @tc.desc: 1.Test RemoveNotifications and hashcodes is not empty + * 2.GetAnsManagerProxy is false + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0200, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + std::string hashcode = "aa"; + std::vector hashcodes; + hashcodes.emplace_back(hashcode); + int32_t removeReason = 1; + ErrCode ret = ansNotification->RemoveNotifications(hashcodes, removeReason); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RemoveNotifications_0300 + * @tc.desc: 1.Test RemoveNotifications and hashcodes is not empty + * 2.GetAnsManagerProxy is true + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0300, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + std::string hashcode = "aa"; + std::vector hashcodes; + hashcodes.emplace_back(hashcode); + int32_t removeReason = 1; + ansNotification->RemoveNotifications(hashcodes, removeReason); +} + +/* + * @tc.name: RegisterPushCallback_0100 + * @tc.desc: 1.Test RegisterPushCallback + * 2.GetAnsManagerProxy is false + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0100, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + sptr pushCallback = nullptr; + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ErrCode ret = ansNotification->RegisterPushCallback(pushCallback, checkRequest); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RegisterPushCallback_0200 + * @tc.desc: 1.Test RegisterPushCallback + * 2.GetAnsManagerProxy is true + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0200, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + sptr pushCallback = nullptr; + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ansNotification->RegisterPushCallback(pushCallback, checkRequest); +} + +/* + * @tc.name: UnregisterPushCallback_0100 + * @tc.desc: 1.Test UnregisterPushCallback + * 2.GetAnsManagerProxy is false + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, UnregisterPushCallback_0100, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + ErrCode ret = ansNotification->UnregisterPushCallback(); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnregisterPushCallback_0200 + * @tc.desc: 1.Test UnregisterPushCallback + * 2.GetAnsManagerProxy is true + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, UnregisterPushCallback_0200, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + ansNotification->UnregisterPushCallback(); +} + +/* + * @tc.name: CanPublishLiveViewContent_0100 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0100, Function | MediumTest | Level1) +{ + NotificationRequest request; + auto notification = std::make_shared(); + EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0110 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0110, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_BUTT); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0120 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0120, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0130 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0130, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0140 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0140, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + request.notificationContent_ = nullptr; + + auto notification = std::make_shared(); + EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0150 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0150, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + auto content = std::make_shared(liveViewContent); + content->content_ = nullptr; + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: SetNotificationSlotFlagsAsBundle_0001 + * @tc.desc: SetNotificationSlotFlagsAsBundle + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, SetNotificationSlotFlagsAsBundle_0001, Function | MediumTest | Level1) +{ + NotificationBundleOption bundle; + uint32_t slotFlags = 1; + auto notification = std::make_shared(); + ErrCode ret = notification->SetNotificationSlotFlagsAsBundle(bundle, slotFlags); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + ret = notification->GetNotificationSlotFlagsAsBundle(bundle, slotFlags); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: PublishNotification_0001 + * @tc.desc: PublishNotification + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, PublishNotification_0001, Function | MediumTest | Level1) +{ + auto notification = std::make_shared(); + MockGetAnsManagerProxy(new (std::nothrow) MockAnsManagerInterface()); + NotificationRequest req; + std::shared_ptr mediaContent = std::make_shared(); + auto content = std::make_shared(mediaContent); + content->content_ = nullptr; + req.SetContent(content); + + auto ret = notification->PublishNotification("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + ret = notification->PublishNotificationAsBundle("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + + auto liveViewContent = std::make_shared(); + auto content1 = std::make_shared(liveViewContent); + content1->content_ = nullptr; + req.SetContent(content1); + req.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + ret = notification->PublishNotification("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + ret = notification->PublishNotificationAsBundle("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +} // namespace Notification +} // namespace OHOS 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 831ecb7c3..95ed86009 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,163 +1,99 @@ -/* - * 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 "notification_request.h" -#include - -#define protected public -#define private public -#include "ans_subscriber_proxy.h" -#undef protected -#undef private -#include "ans_inner_errors.h" -#include "ipc_types.h" -#include "mock_i_remote_object.h" -#include "notification.h" - -using namespace testing; -using namespace testing::ext; -using namespace OHOS; -using namespace OHOS::Notification; - -class AnsSubscriberProxyBranchTest : public testing::Test { -public: - AnsSubscriberProxyBranchTest() {} - - virtual ~AnsSubscriberProxyBranchTest() {} - - static void SetUpTestCase(); - - static void TearDownTestCase(); - - void SetUp(); - - void TearDown(); -}; - -void AnsSubscriberProxyBranchTest::SetUpTestCase() {} - -void AnsSubscriberProxyBranchTest::TearDownTestCase() {} - -void AnsSubscriberProxyBranchTest::SetUp() {} - -void AnsSubscriberProxyBranchTest::TearDown() {} - -/* - * @tc.name: OnCanceledList_0100 - * @tc.desc: Test OnCanceledList function and notifications is empty - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnCanceledList_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; - sptr notificationMap = nullptr; - int32_t deleteReason = 1; - proxy->OnCanceledList(notifications, notificationMap, deleteReason); -} - -/* - * @tc.name: OnCanceledList_0200 - * @tc.desc: 1.Test OnCanceledList function and notifications is not empty - * 2.notificationMap is nullptr - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnCanceledList_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 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 = nullptr; - 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); -} +/* + * 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 + * + * 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 "notification_request.h" +#include + +#define protected public +#define private public +#include "ans_subscriber_proxy.h" +#undef protected +#undef private +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "mock_i_remote_object.h" +#include "notification.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsSubscriberProxyBranchTest : public testing::Test { +public: + AnsSubscriberProxyBranchTest() {} + + virtual ~AnsSubscriberProxyBranchTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsSubscriberProxyBranchTest::SetUpTestCase() {} + +void AnsSubscriberProxyBranchTest::TearDownTestCase() {} + +void AnsSubscriberProxyBranchTest::SetUp() {} + +void AnsSubscriberProxyBranchTest::TearDown() {} + +/* + * @tc.name: OnCanceledList_0100 + * @tc.desc: Test OnCanceledList function and notifications is empty + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnCanceledList_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; + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + int32_t deleteReason = 1; + proxy->OnCanceledList(notifications, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceledList_0200 + * @tc.desc: 1.Test OnCanceledList function and notifications is not empty + * 2.notificationMap is nullptr + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnCanceledList_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 request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + auto notification = OHOS::Notification::Notification(request); + std::vector notifications; + notifications.emplace_back(notification); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + int32_t deleteReason = 1; + proxy->OnCanceledList(notifications, notificationMap, deleteReason); +} 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 663e2332f..a5b700a36 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,705 +1,449 @@ -/* - * Copyright (c) 2022-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 "notification_request.h" -#include - -#define private public -#define protected public -#include "ans_subscriber_proxy.h" -#undef private -#undef protected -#include "ans_inner_errors.h" -#include "ipc_types.h" -#include "mock_i_remote_object.h" -#include "notification.h" - -using namespace testing; -using namespace testing::ext; -using namespace OHOS; -using namespace OHOS::Notification; - -class AnsSubscriberProxyUnitTest : public testing::Test { -public: - AnsSubscriberProxyUnitTest() {} - - virtual ~AnsSubscriberProxyUnitTest() {} - - static void SetUpTestCase(); - - static void TearDownTestCase(); - - void SetUp(); - - void TearDown(); -}; - -void AnsSubscriberProxyUnitTest::SetUpTestCase() {} - -void AnsSubscriberProxyUnitTest::TearDownTestCase() {} - -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 - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnConsumed_0400, 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); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - proxy->OnConsumed(notification, notificationMap); -} - -/* - * @tc.name: OnConsumed_0500 - * @tc.desc: test AnsSubscriberProxy's OnConsumed function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnConsumed_0500, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); - 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); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - 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 - * @tc.type: FUNC - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0300, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnConsumedList_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); - std::vector> notifications; - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - proxy->OnConsumedList(notifications, notificationMap); -} - -/* - * @tc.name: OnConsumedList_0400 - * @tc.desc: 1.Test OnConsumedList function and notifications is not empty - * 2.notificationMap is not nullptr - * @tc.type: FUNC - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0400, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, OnConsumedList_0400, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); - 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); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - proxy->OnConsumedList(notifications, notificationMap); -} - -/* - * @tc.name: OnCanceled_0400 - * @tc.desc: test AnsSubscriberProxy's OnCanceled function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnCanceled_0400, 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); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - int32_t deleteReason = 0; - proxy->OnCanceled(notification, notificationMap, deleteReason); -} - -/* - * @tc.name: OnCanceled_0500 - * @tc.desc: test AnsSubscriberProxy's OnCanceled function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnCanceled_0500, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); - 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); - sptr notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - 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 - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnUpdated_0100, 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 notificationMap = new (std::nothrow) NotificationSortingMap(); - ASSERT_NE(nullptr, notificationMap); - proxy->OnUpdated(notificationMap); -} - -/* - * @tc.name: OnUpdated_0200 - * @tc.desc: test AnsSubscriberProxy's OnUpdated function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnUpdated_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - 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); - 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 - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, 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 date = new (std::nothrow) NotificationDoNotDisturbDate(); - ASSERT_NE(nullptr, date); - proxy->OnDoNotDisturbDateChange(date); -} - -/* - * @tc.name: OnDoNotDisturbDateChange_0200 - * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - 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); - proxy->OnDoNotDisturbDateChange(date); -} - -/* - * @tc.name: OnEnabledNotificationChanged_0100 - * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, 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 callbackData = new (std::nothrow) EnabledNotificationCallbackData(); - ASSERT_NE(nullptr, callbackData); - proxy->OnEnabledNotificationChanged(callbackData); -} - -/* - * @tc.name: OnEnabledNotificationChanged_0200 - * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - 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); - proxy->OnEnabledNotificationChanged(callbackData); -} - -/* - * @tc.name: OnConnected_0100 - * @tc.desc: test AnsSubscriberProxy's OnConnected function - * @tc.type: FUNC - * @tc.require: issueI62D8C - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConnected_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnConnected_0100, 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); - proxy->OnConnected(); -} - -/* - * @tc.name: OnConnected_0200 - * @tc.desc: test AnsSubscriberProxy's OnConnected function - * @tc.type: FUNC - * @tc.require: #issueI62D8C - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnConnected_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnConnected_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - proxy->OnConnected(); -} - -/* - * @tc.name: OnDisconnected_0100 - * @tc.desc: test AnsSubscriberProxy's OnDisconnected function - * @tc.type: FUNC - * @tc.require: issueI62D8C - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnDisconnected_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnDisconnected_0100, 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); - proxy->OnDisconnected(); -} - -/* - * @tc.name: OnDisconnected_0200 - * @tc.desc: test AnsSubscriberProxy's OnDisconnected function - * @tc.type: FUNC - * @tc.require: issueI62D8C - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnDisconnected_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnDisconnected_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - proxy->OnDisconnected(); -} - -/* - * @tc.name: OnBadgeChanged_0100 - * @tc.desc: test AnsSubscriberProxy's OnBadgeChanged function - * @tc.type: FUNC - * @tc.require: #I6C2X9 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeChanged_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnBadgeChanged_0100, 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 badgeData = new (std::nothrow) BadgeNumberCallbackData(); - ASSERT_NE(nullptr, badgeData); - proxy->OnBadgeChanged(badgeData); -} - -/* - * @tc.name: OnBadgeChanged_0200 - * @tc.desc: test AnsSubscriberProxy's OnBadgeChanged function - * @tc.type: FUNC - * @tc.require: #I6C2X9 - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeChanged_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyUnitTest, OnBadgeChanged_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - 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); - proxy->OnBadgeChanged(badgeData); -} - -/** - * @tc.name: OnBadgeEnabledChanged_0100 - * @tc.desc: test OnBadgeEnabledChanged function with callback data, expect to invoke SendRequest function. - * @tc.type: FUNC - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0100, TestSize.Level1) -{ - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - 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); - proxy->OnBadgeEnabledChanged(callbackData); -} - -/** - * @tc.name: OnBadgeEnabledChanged_0200 - * @tc.desc: test OnBadgeEnabledChanged function with null callback data, expect not to invoke SendRequest function. - * @tc.type: FUNC - */ -HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0200, TestSize.Level1) -{ - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0).WillRepeatedly(DoAll(Return(NO_ERROR))); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr callbackData = nullptr; - proxy->OnBadgeEnabledChanged(callbackData); -} +/* + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_request.h" +#include + +#define private public +#define protected public +#include "ans_subscriber_proxy.h" +#undef private +#undef protected +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "mock_i_remote_object.h" +#include "notification.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsSubscriberProxyUnitTest : public testing::Test { +public: + AnsSubscriberProxyUnitTest() {} + + virtual ~AnsSubscriberProxyUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsSubscriberProxyUnitTest::SetUpTestCase() {} + +void AnsSubscriberProxyUnitTest::TearDownTestCase() {} + +void AnsSubscriberProxyUnitTest::SetUp() {} + +void AnsSubscriberProxyUnitTest::TearDown() {} + +/* + * @tc.name: OnConsumed_0400 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0400, 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); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + proxy->OnConsumed(notification, notificationMap); +} + +/* + * @tc.name: OnConsumed_0500 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + proxy->OnConsumed(notification, notificationMap); +} + +/* + * @tc.name: OnConsumedList_0300 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_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); + std::vector notifications; + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + proxy->OnConsumedList(notifications, notificationMap); +} + +/* + * @tc.name: OnConsumedList_0400 + * @tc.desc: 1.Test OnConsumedList function and notifications is not empty + * 2.notificationMap is not nullptr + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + auto notification = OHOS::Notification::Notification(request); + std::vector notifications; + notifications.emplace_back(notification); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + proxy->OnConsumedList(notifications, notificationMap); +} + +/* + * @tc.name: OnCanceled_0400 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0400, 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); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0500 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + auto notification = OHOS::Notification::Notification(request); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, notificationMap, deleteReason); +} + +/* + * @tc.name: OnUpdated_0100 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnUpdated_0100, 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); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + proxy->OnUpdated(notificationMap); +} + +/* + * @tc.name: OnUpdated_0200 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnUpdated_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto notificationMap = OHOS::Notification::NotificationSortingMap(); + proxy->OnUpdated(notificationMap); +} + +/* + * @tc.name: OnDoNotDisturbDateChange_0100 + * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, 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); + auto date = OHOS::Notification::NotificationDoNotDisturbDate(); + proxy->OnDoNotDisturbDateChange(date); +} + +/* + * @tc.name: OnDoNotDisturbDateChange_0200 + * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto date = OHOS::Notification::NotificationDoNotDisturbDate(); + proxy->OnDoNotDisturbDateChange(date); +} + +/* + * @tc.name: OnEnabledNotificationChanged_0100 + * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, 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); + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); + proxy->OnEnabledNotificationChanged(callbackData); +} + +/* + * @tc.name: OnEnabledNotificationChanged_0200 + * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); + proxy->OnEnabledNotificationChanged(callbackData); +} + +/* + * @tc.name: OnConnected_0100 + * @tc.desc: test AnsSubscriberProxy's OnConnected function + * @tc.type: FUNC + * @tc.require: issueI62D8C + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConnected_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConnected_0100, 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); + proxy->OnConnected(); +} + +/* + * @tc.name: OnConnected_0200 + * @tc.desc: test AnsSubscriberProxy's OnConnected function + * @tc.type: FUNC + * @tc.require: #issueI62D8C + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConnected_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConnected_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnConnected(); +} + +/* + * @tc.name: OnDisconnected_0100 + * @tc.desc: test AnsSubscriberProxy's OnDisconnected function + * @tc.type: FUNC + * @tc.require: issueI62D8C + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDisconnected_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDisconnected_0100, 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); + proxy->OnDisconnected(); +} + +/* + * @tc.name: OnDisconnected_0200 + * @tc.desc: test AnsSubscriberProxy's OnDisconnected function + * @tc.type: FUNC + * @tc.require: issueI62D8C + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDisconnected_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDisconnected_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnDisconnected(); +} + +/* + * @tc.name: OnBadgeChanged_0100 + * @tc.desc: test AnsSubscriberProxy's OnBadgeChanged function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeChanged_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnBadgeChanged_0100, 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); + auto badgeData = OHOS::Notification::BadgeNumberCallbackData(); + proxy->OnBadgeChanged(badgeData); +} + +/* + * @tc.name: OnBadgeChanged_0200 + * @tc.desc: test AnsSubscriberProxy's OnBadgeChanged function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeChanged_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnBadgeChanged_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto badgeData = OHOS::Notification::BadgeNumberCallbackData(); + proxy->OnBadgeChanged(badgeData); +} + +/** + * @tc.name: OnBadgeEnabledChanged_0100 + * @tc.desc: test OnBadgeEnabledChanged function with callback data, expect to invoke SendRequest function. + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0100, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto callbackData = OHOS::Notification::EnabledNotificationCallbackData(); + proxy->OnBadgeEnabledChanged(callbackData); +} + +/** + * @tc.name: OnBadgeEnabledChanged_0200 + * @tc.desc: test OnBadgeEnabledChanged function with null callback data, expect not to invoke SendRequest function. + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnBadgeEnabledChanged_0200, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + 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 82ddf4187..000000000 --- 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 15493b1fb..000000000 --- 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 cf8a3f964..6a9d55dcb 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 4598a3d8a..8fe7a57a1 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 b15f74160..73be44e93 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 37a16ce68..980b18875 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 2270081fd..7697d8fc8 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 633a39c8c..7f05bbe6b 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 6a75ef976..d3f7e70dd 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 2eecb813c..b6c27a8e8 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 ae9ba50f8..785cfd623 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 2d8b63877..798fe15e8 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 92f0f1329..87d0b4635 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 a1050547e..bc349bfb6 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 f13788280..440875574 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 9363e68e9..6c027c019 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 fd7cb707d..7f53b4333 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 7ac67ab53..30fd78e9c 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 76388b8de..8828868ee 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 ad69e9442..413373c51 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 b895f47fe..11f106727 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 80c7bc5d1..85314b305 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 4e5888816..a2f62f004 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 3dbca2c84..c4693a008 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 b3bff9055..8b61e14fa 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 21cb444ef..b0d0bdfa2 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 292da8ae8..636c3eb79 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 32d4f60cc..645a96260 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,1230 +1,1230 @@ -/* - * 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. - */ - -#include -#include - -#include "ans_inner_errors.h" -#include "ans_ut_constant.h" -#define private public -#define protected public -#include "advanced_notification_service.h" -#include "notification_subscriber_manager.h" -#undef private -#undef protected -#include "ans_inner_errors.h" -#include "mock_ipc_skeleton.h" - -extern void MockGetUserId(bool mockRet); -extern void MockGetBundleName(bool mockRet); -extern void MockGetNotificationSlotRet(bool mockRet); -extern void MockQueryForgroundOsAccountId(bool mockRet, uint8_t mockCase); - -using namespace OHOS::Security::AccessToken; -using namespace testing::ext; -namespace OHOS { -namespace Notification { -extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); -extern void MockIsSystemApp(bool isSystemApp); -extern void MockIsVerfyPermisson(bool isVerify); - -class NotificationSubscriberManagerBranchTest : public testing::Test { -public: - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number : NotificationSubscriberManager_00100 - * @tc.name : NotificationSubscriberManager_00100 - * @tc.desc : test NotifyConsumed function and notificationSubQueue_ == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00100, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - sptr notification = nullptr; - sptr notificationMap = nullptr; - notificationSubscriberManager->notificationSubQueue_ = nullptr; - notificationSubscriberManager->NotifyConsumed(notification, notificationMap); -} - -/** - * @tc.number : NotificationSubscriberManager_00200 - * @tc.name : NotificationSubscriberManager_00200 - * @tc.desc : test NotifyCanceled function and notificationSubQueue_ == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00200, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - sptr notification = nullptr; - sptr notificationMap = nullptr; - int32_t deleteReason = 1; - notificationSubscriberManager->notificationSubQueue_ = nullptr; - notificationSubscriberManager->NotifyCanceled(notification, notificationMap, deleteReason); -} - -/** - * @tc.number : NotificationSubscriberManager_00300 - * @tc.name : NotificationSubscriberManager_00300 - * @tc.desc : test NotifyUpdated function and notificationSubQueue_ == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00300, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - sptr notificationMap = nullptr; - notificationSubscriberManager->notificationSubQueue_ = nullptr; - notificationSubscriberManager->NotifyUpdated(notificationMap); -} - -/** - * @tc.number : NotificationSubscriberManager_00400 - * @tc.name : NotificationSubscriberManager_00400 - * @tc.desc : test NotifyDoNotDisturbDateChanged function and notificationSubQueue_ == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00400, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - sptr date = nullptr; - notificationSubscriberManager->notificationSubQueue_ = nullptr; - notificationSubscriberManager->NotifyDoNotDisturbDateChanged(0, date); -} - -/** - * @tc.number : NotificationSubscriberManager_00500 - * @tc.name : NotificationSubscriberManager_00500 - * @tc.desc : test NotifyEnabledNotificationChanged function and notificationSubQueue_ == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00500, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - sptr callbackData = nullptr; - notificationSubscriberManager->notificationSubQueue_ = nullptr; - notificationSubscriberManager->NotifyEnabledNotificationChanged(callbackData); -} - -/** - * @tc.number : NotificationSubscriberManager_00600 - * @tc.name : NotificationSubscriberManager_00600 - * @tc.desc : test OnRemoteDied function and record == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00600, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - wptr object = nullptr; - notificationSubscriberManager->OnRemoteDied(object); -} - -/** - * @tc.number : NotificationSubscriberManager_00700 - * @tc.name : NotificationSubscriberManager_00700 - * @tc.desc : test AddRecordInfo function and subscribeInfo == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00700, Function | SmallTest | Level1) -{ - std::shared_ptr notificationSubscriberManager = - std::make_shared(); - ASSERT_NE(nullptr, notificationSubscriberManager); - std::shared_ptr record = - notificationSubscriberManager->CreateSubscriberRecord(nullptr); - sptr subscribeInfo = nullptr; - notificationSubscriberManager->AddRecordInfo(record, subscribeInfo); -} - -/** - * @tc.number : NotificationSubscriberManager_00800 - * @tc.name : NotificationSubscriberManager_00800 - * @tc.desc : test RemoveSubscriberInner function and record == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_00800, Function | SmallTest | Level1) -{ - NotificationSubscriberManager notificationSubscriberManager; - sptr subscriber = nullptr; - sptr subscribeInfo = nullptr; - ASSERT_EQ(ERR_ANS_INVALID_PARAM, notificationSubscriberManager.RemoveSubscriberInner(subscriber, subscribeInfo)); -} - -/** - * @tc.number : AdvancedNotificationService_00200 - * @tc.name : AdvancedNotificationService_00200 - * @tc.desc : test ActiveNotificationDump function and userId != SUBSCRIBE_USER_INIT - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00200, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = 1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - advancedNotificationService.notificationList_.push_back(record); - MockGetUserId(false); - ASSERT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_00300 - * @tc.name : AdvancedNotificationService_00300 - * @tc.desc : test ActiveNotificationDump function and bundle != record->notification->GetBundleName(). - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00300, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - advancedNotificationService.notificationList_.push_back(record); - MockGetUserId(false); - MockGetBundleName(false); - ASSERT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED -/** - * @tc.number : AdvancedNotificationService_00400 - * @tc.name : AdvancedNotificationService_00400 - * @tc.desc : test ActiveNotificationDump function and record->deviceId is not empty. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00400, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - record->deviceId = ""; - advancedNotificationService.notificationList_.push_back(record); - MockGetUserId(false); - MockGetBundleName(false); - ASSERT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_00500 - * @tc.name : AdvancedNotificationService_00500 - * @tc.desc : test ActiveNotificationDump function and record->request->GetOwnerUid() > 0. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00500, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - int32_t uid = 1; - record->request->SetOwnerUid(uid); - record->deviceId = ""; - advancedNotificationService.notificationList_.push_back(record); - MockGetUserId(false); - MockGetBundleName(false); - ASSERT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_00600 - * @tc.name : AdvancedNotificationService_00600 - * @tc.desc : test ActiveNotificationDump function and record->request->GetOwnerUid() < 0. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00600, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - int32_t uid = -1; - record->request->SetOwnerUid(uid); - record->deviceId = ""; - advancedNotificationService.notificationList_.push_back(record); - MockGetUserId(false); - MockGetBundleName(false); - ASSERT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_00700 - * @tc.name : AdvancedNotificationService_00700 - * @tc.desc : test DistributedNotificationDump function and record->notification == nullptr. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00700, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = 1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = nullptr; - advancedNotificationService.notificationList_.push_back(record); - ASSERT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_00800 - * @tc.name : AdvancedNotificationService_00800 - * @tc.desc : test DistributedNotificationDump function and userId != SUBSCRIBE_USER_INIT. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00800, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = 1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - MockGetUserId(false); - advancedNotificationService.notificationList_.push_back(record); - ASSERT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_00900 - * @tc.name : AdvancedNotificationService_00900 - * @tc.desc : test DistributedNotificationDump function and bundle is not empty. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00900, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - MockGetUserId(false); - MockGetBundleName(false); - advancedNotificationService.notificationList_.push_back(record); - ASSERT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_01000 - * @tc.name : AdvancedNotificationService_01000 - * @tc.desc : test DistributedNotificationDump function and record->deviceId is empty. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01000, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->deviceId = ""; - MockGetUserId(false); - MockGetBundleName(false); - advancedNotificationService.notificationList_.push_back(record); - ASSERT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_01100 - * @tc.name : AdvancedNotificationService_01100 - * @tc.desc : test DistributedNotificationDump function and record->request->GetOwnerUid() > 0. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01100, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - int32_t uid = 1; - record->request->SetOwnerUid(uid); - record->deviceId = ""; - MockGetUserId(false); - MockGetBundleName(false); - advancedNotificationService.notificationList_.push_back(record); - ASSERT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationService_01200 - * @tc.name : AdvancedNotificationService_01200 - * @tc.desc : test DistributedNotificationDump function and record->request->GetOwnerUid() < 0. - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01200, Function | SmallTest | Level1) -{ - std::string bundle = ""; - int32_t userId = -1; - std::vector dumpInfo; - AdvancedNotificationService advancedNotificationService; - std::shared_ptr record = std::make_shared(); - record->notification = new Notification(); - record->request = new NotificationRequest(); - int32_t uid = -1; - record->request->SetOwnerUid(uid); - record->deviceId = ""; - MockGetUserId(false); - MockGetBundleName(false); - advancedNotificationService.notificationList_.push_back(record); - ASSERT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, 0, dumpInfo), ERR_OK); -} -#endif - -/** - * @tc.number : AdvancedNotificationService_01400 - * @tc.name : AdvancedNotificationService_01400 - * @tc.desc : Test PrepareNotificationRequest function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01400, Function | SmallTest | Level1) -{ - sptr req = new NotificationRequest(); - bool isAgentTrue = true; - req->SetIsAgentNotification(isAgentTrue); - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.PrepareNotificationRequest(req), ERR_ANS_INVALID_BUNDLE); -} - -/** - * @tc.number : AdvancedNotificationService_01500 - * @tc.name : AdvancedNotificationService_01500 - * @tc.desc : Test CancelAsBundle function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01500, Function | SmallTest | Level1) -{ - int32_t notificationId = 1; - std::string representativeBundle = ""; - int32_t userId = 2; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.CancelAsBundle(notificationId, representativeBundle, userId), - ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_01600 - * @tc.name : AdvancedNotificationService_01600 - * @tc.desc : Test AddSlots function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01600, Function | SmallTest | Level1) -{ - std::vector> slots; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.AddSlots(slots), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_01700 - * @tc.name : AdvancedNotificationService_01700 - * @tc.desc : Test Delete function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01700, Function | SmallTest | Level1) -{ - std::string key = ""; - int32_t removeReason = 1; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.Delete(key, removeReason), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_01800 - * @tc.name : AdvancedNotificationService_01800 - * @tc.desc : Test DeleteByBundle function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01800, Function | SmallTest | Level1) -{ - sptr bundleOption = new NotificationBundleOption(); - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.DeleteByBundle(bundleOption), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_01900 - * @tc.name : AdvancedNotificationService_01900 - * @tc.desc : Test DeleteAll function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01900, Function | SmallTest | Level1) -{ - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.DeleteAll(), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02000 - * @tc.name : AdvancedNotificationService_02000 - * @tc.desc : Test GetSlotsByBundle function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02000, Function | SmallTest | Level1) -{ - IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); - - sptr bundleOption = nullptr; - std::vector> slots; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.GetSlotsByBundle(bundleOption, slots), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02100 - * @tc.name : AdvancedNotificationService_02100 - * @tc.desc : Test UpdateSlots function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02100, Function | SmallTest | Level1) -{ - IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); - - sptr bundleOption = nullptr; - std::vector> slots; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.UpdateSlots(bundleOption, slots), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02200 - * @tc.name : AdvancedNotificationService_02200 - * @tc.desc : Test SetShowBadgeEnabledForBundle function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02200, Function | SmallTest | Level1) -{ - IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); - - sptr bundleOption = new NotificationBundleOption(); - bool enabled = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.SetShowBadgeEnabledForBundle(bundleOption, enabled), - ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02300 - * @tc.name : AdvancedNotificationService_02300 - * @tc.desc : Test GetShowBadgeEnabledForBundle function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02300, Function | SmallTest | Level1) -{ - IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); - - sptr bundleOption = nullptr; - bool enabled = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.GetShowBadgeEnabledForBundle(bundleOption, enabled), - ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02400 - * @tc.name : AdvancedNotificationService_02400 - * @tc.desc : Test Unsubscribe function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02400, Function | SmallTest | Level1) -{ - sptr subscriber = nullptr; - sptr info = nullptr; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.Unsubscribe(subscriber, info), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02500 - * @tc.name : AdvancedNotificationService_02500 - * @tc.desc : Test GetAllActiveNotifications function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02500, Function | SmallTest | Level1) -{ - std::vector> notifications; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.GetAllActiveNotifications(notifications), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02600 - * @tc.name : AdvancedNotificationService_02600 - * @tc.desc : Test GetSpecialActiveNotifications function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02600, Function | SmallTest | Level1) -{ - std::vector key; - std::vector> notifications; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ( - advancedNotificationService.GetSpecialActiveNotifications(key, notifications), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02700 - * @tc.name : AdvancedNotificationService_02700 - * @tc.desc : Test SetNotificationsEnabledForAllBundles function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02700, Function | SmallTest | Level1) -{ - std::string deviceId = ""; - bool enabled = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.SetNotificationsEnabledForAllBundles(deviceId, enabled), - ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_02800 - * @tc.name : AdvancedNotificationService_02800 - * @tc.desc : Test SetNotificationsEnabledForAllBundles function and GetActiveUserId is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02800, Function | SmallTest | Level1) -{ - std::string deviceId = ""; - bool enabled = true; - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - MockQueryForgroundOsAccountId(false, 1); - - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.SetNotificationsEnabledForAllBundles(deviceId, enabled), - ERR_ANS_GET_ACTIVE_USER_FAILED); -} - -/** - * @tc.number : AdvancedNotificationService_02900 - * @tc.name : AdvancedNotificationService_02900 - * @tc.desc : Test SetNotificationsEnabledForSpecialBundle function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02900, Function | SmallTest | Level1) -{ - std::string deviceId = ""; - sptr bundleOption = new NotificationBundleOption(); - bool enabled = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled), - ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_03000 - * @tc.name : AdvancedNotificationService_03000 - * @tc.desc : Test IsAllowedNotify function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_03000, Function | SmallTest | Level1) -{ - bool enabled = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.IsAllowedNotify(enabled), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_03100 - * @tc.name : AdvancedNotificationService_03100 - * @tc.desc : Test IsAllowedNotify function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_03100, Function | SmallTest | Level1) -{ - bool enabled = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - MockQueryForgroundOsAccountId(false, 1); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.IsAllowedNotify(enabled), ERR_ANS_GET_ACTIVE_USER_FAILED); -} - -/** - * @tc.number : AdvancedNotificationService_03200 - * @tc.name : AdvancedNotificationService_03200 - * @tc.desc : Test IsSpecialBundleAllowedNotify function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_03200, Function | SmallTest | Level1) -{ - sptr bundleOption = nullptr; - bool allowed = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); - MockIsSystemApp(false); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ( - advancedNotificationService.IsSpecialBundleAllowedNotify(bundleOption, allowed), ERR_ANS_NON_SYSTEM_APP); -} - -/** - * @tc.number : AdvancedNotificationService_03300 - * @tc.name : AdvancedNotificationService_03300 - * @tc.desc : Test IsSpecialBundleAllowedNotify function and targetBundle == nullptr - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_03300, Function | SmallTest | Level1) -{ - sptr bundleOption = nullptr; - bool allowed = true; - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ( - advancedNotificationService.IsSpecialBundleAllowedNotify(bundleOption, allowed), ERR_ANS_INVALID_BUNDLE); -} - -/** - * @tc.number : AdvancedNotificationService_03400 - * @tc.name : AdvancedNotificationService_03400 - * @tc.desc : Test IsSpecialBundleAllowedNotify function and GetActiveUserId is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_03400, Function | SmallTest | Level1) -{ - sptr bundleOption = new NotificationBundleOption(); - MockQueryForgroundOsAccountId(false, 1); - bool allowed = true; - - int32_t uid = 2; - bundleOption->SetUid(uid); - - MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); - AdvancedNotificationService advancedNotificationService; - ASSERT_EQ(advancedNotificationService.IsSpecialBundleAllowedNotify(bundleOption, allowed), - ERR_ANS_GET_ACTIVE_USER_FAILED); -} - -/** - * @tc.number : AdvancedNotificationService_03500 - * @tc.name : AdvancedNotificationService_03500 - * @tc.desc : Test RemoveNotification function and CheckPermission is false - */ -HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_03500, Function | SmallTest | Level1) -{ - sptr bundleOption = nullptr; - int32_t notificationId = 1; - std::string label = "