From 88f5770b18e433f197558b01b6403a5b408fcd97 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 2 Nov 2021 14:44:57 +0800 Subject: [PATCH 1/2] Fix bug Signed-off-by: zhaoyuan17 --- .../ans/core/include/ans_manager_interface.h | 6 + .../ans/core/include/ans_manager_proxy.h | 4 + .../ans/core/include/ans_manager_stub.h | 6 + .../ans/core/include/ans_notification.h | 17 + frameworks/ans/core/src/ans_manager_proxy.cpp | 64 + frameworks/ans/core/src/ans_manager_stub.cpp | 60 + frameworks/ans/core/src/ans_notification.cpp | 46 +- frameworks/ans/native/src/notification.cpp | 4 +- .../ans/native/src/notification_helper.cpp | 11 + .../ans/native/src/notification_request.cpp | 22 +- .../ans_innerkits_module_publish_test.cpp | 82 +- .../ans/native/include/notification_helper.h | 18 +- .../ans/native/include/notification_request.h | 22 +- interfaces/kits/napi/ans/include/cancel.h | 1 + interfaces/kits/napi/ans/include/remove.h | 1 + interfaces/kits/napi/ans/src/cancel.cpp | 105 +- interfaces/kits/napi/ans/src/common.cpp | 34 +- interfaces/kits/napi/ans/src/init.cpp | 2 + interfaces/kits/napi/ans/src/remove.cpp | 119 ++ .../include/advanced_notification_service.h | 4 + .../ans/src/advanced_notification_service.cpp | 89 +- .../advanced_notification_service_test.cpp | 60 +- test/BUILD.gn | 5 +- test/common/acts/BUILD.gn | 40 + .../acts/actsnotificationfuzztest/BUILD.gn | 107 ++ .../actsnotificationfuzztest.cpp | 51 + .../include/notificationfuzzconfigparser.h | 74 + .../include/notificationfuzztestmanager.h | 106 ++ .../include/notificationgetparam.h | 442 +++++ .../notificationfuzzconfig/config.json | 153 ++ .../notificationfuzztest/ohos_test.xml | 25 + .../src/notificationfuzztestmanager.cpp | 923 +++++++++++ .../src/notificationgetparam.cpp | 1433 +++++++++++++++++ 33 files changed, 4087 insertions(+), 49 deletions(-) create mode 100644 test/common/acts/BUILD.gn create mode 100755 test/common/acts/actsnotificationfuzztest/BUILD.gn create mode 100644 test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp create mode 100644 test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h create mode 100644 test/resource/notificationfuzztest/include/notificationfuzztestmanager.h create mode 100644 test/resource/notificationfuzztest/include/notificationgetparam.h create mode 100644 test/resource/notificationfuzztest/notificationfuzzconfig/config.json create mode 100644 test/resource/notificationfuzztest/ohos_test.xml create mode 100644 test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp create mode 100644 test/resource/notificationfuzztest/src/notificationgetparam.cpp diff --git a/frameworks/ans/core/include/ans_manager_interface.h b/frameworks/ans/core/include/ans_manager_interface.h index 9f71a1a09..7baefa8d0 100644 --- a/frameworks/ans/core/include/ans_manager_interface.h +++ b/frameworks/ans/core/include/ans_manager_interface.h @@ -104,6 +104,10 @@ public: virtual ErrCode IsAllowedNotify(bool &allowed) = 0; virtual ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) = 0; + virtual ErrCode CancelGroup(const std::string &groupName) = 0; + virtual ErrCode RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) = 0; + virtual ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) = 0; protected: @@ -158,6 +162,8 @@ protected: GET_CURRENT_APP_SORTING, IS_ALLOWED_NOTIFY, IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY, + CANCEL_GROUP, + REMOVE_GROUP_BY_BUNDLE, SHELL_DUMP, }; }; diff --git a/frameworks/ans/core/include/ans_manager_proxy.h b/frameworks/ans/core/include/ans_manager_proxy.h index 80214ca52..24a8105ca 100644 --- a/frameworks/ans/core/include/ans_manager_proxy.h +++ b/frameworks/ans/core/include/ans_manager_proxy.h @@ -93,6 +93,10 @@ public: ErrCode IsAllowedNotify(bool &allowed) override; ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override; + ErrCode CancelGroup(const std::string &groupName) override; + ErrCode RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) override; + ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) override; private: diff --git a/frameworks/ans/core/include/ans_manager_stub.h b/frameworks/ans/core/include/ans_manager_stub.h index f85ab6050..082bec359 100644 --- a/frameworks/ans/core/include/ans_manager_stub.h +++ b/frameworks/ans/core/include/ans_manager_stub.h @@ -98,6 +98,10 @@ public: virtual ErrCode IsSpecialBundleAllowedNotify( const sptr &bundleOption, bool &allowed) override; + virtual ErrCode CancelGroup(const std::string &groupName) override; + virtual ErrCode RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) override; + virtual ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) override; private: @@ -155,6 +159,8 @@ private: ErrCode HandleIsAllowedNotify(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply); ErrCode HandleShellDump(MessageParcel &data, MessageParcel &reply); + ErrCode HandleCancelGroup(MessageParcel &data, MessageParcel &reply); + ErrCode HandleRemoveGroupByBundle(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result); diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index 100bb3894..ce3893a34 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -593,6 +593,23 @@ public: */ ErrCode GetDisturbMode(NotificationConstant::DisturbMode &disturbMode); + /** + * Cancel the notification of the specified group of this application. + * + * @param groupName the specified group name. + * @return Returns cancel group result. + */ + ErrCode CancelGroup(const std::string &groupName); + + /** + * Remove the notification of the specified group of the specified application. + * + * @param bundleOption Indicates the bundle name and uid of the specified application. + * @param groupName the specified group name. + * @return Returns remove group by bundle result. + */ + ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName); + /** * Reset ans manager proxy when OnRemoteDied called. */ diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index b7ac0f7d0..5505d1e18 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -1744,6 +1744,70 @@ ErrCode AnsManagerProxy::IsSpecialBundleAllowedNotify(const sptr &bundleOption, const std::string &groupName) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[RemoveGroupByBundle] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(bundleOption)) { + ANS_LOGW("[RemoveGroupByBundle] fail:: write bundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(groupName)) { + ANS_LOGW("[RemoveGroupByBundle] fail: write groupName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(REMOVE_GROUP_BY_BUNDLE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGW("[RemoveGroupByBundle] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[RemoveGroupByBundle] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + ErrCode AnsManagerProxy::ShellDump(const std::string &dumpOption, std::vector &dumpInfo) { MessageParcel data; diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 551024700..8f5384383 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -176,6 +176,12 @@ const std::map bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGW("[HandleRemoveGroupByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string groupName; + if (!data.ReadString(groupName)) { + ANS_LOGW("[HandleRemoveGroupByBundle] fail: read groupName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveGroupByBundle(bundleOption, groupName); + + if (!reply.WriteInt32(result)) { + ANS_LOGW("[HandleRemoveGroupByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &reply) { std::string dumpOption; @@ -1512,6 +1560,18 @@ ErrCode AnsManagerStub::IsSpecialBundleAllowedNotify(const sptr &bundleOption, const std::string &groupName) +{ + ANS_LOGW("AnsManagerStub::RemoveGroupByBundle called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::ShellDump(const std::string &dumpOption, std::vector &dumpInfo) { ANS_LOGW("AnsManagerStub::ShellDump called!"); diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index da55aed92..74d77b835 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -165,7 +165,7 @@ ErrCode AnsNotification::GetNotificationSlotNumAsBundle(const NotificationBundle return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->GetSlotNumAsBundle(bo, num); } @@ -519,7 +519,7 @@ ErrCode AnsNotification::RemoveNotification( return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->RemoveNotification(bo, notificationId, label); } @@ -530,7 +530,7 @@ ErrCode AnsNotification::RemoveAllNotifications(const NotificationBundleOption & return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->RemoveAllNotifications(bo); } @@ -541,7 +541,7 @@ ErrCode AnsNotification::RemoveNotificationsByBundle(const NotificationBundleOpt return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->DeleteByBundle(bo); } @@ -567,7 +567,7 @@ ErrCode AnsNotification::GetNotificationSlotsForBundle( return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->GetSlotsByBundle(bo, slots); } @@ -579,7 +579,7 @@ ErrCode AnsNotification::UpdateNotificationSlots( return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->UpdateSlots(bo, slots); } @@ -591,7 +591,7 @@ ErrCode AnsNotification::UpdateNotificationSlotGroups( return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->UpdateSlotGroups(bo, groups); } @@ -626,7 +626,7 @@ ErrCode AnsNotification::IsAllowedNotify(const NotificationBundleOption &bundleO return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->IsSpecialBundleAllowedNotify(bo, allowed); } @@ -656,7 +656,7 @@ ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->SetNotificationsEnabledForSpecialBundle(deviceId, bo, enabled); } @@ -667,7 +667,7 @@ ErrCode AnsNotification::SetShowBadgeEnabledForBundle(const NotificationBundleOp return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->SetShowBadgeEnabledForBundle(bo, enabled); } @@ -678,7 +678,7 @@ ErrCode AnsNotification::GetShowBadgeEnabledForBundle(const NotificationBundleOp return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr bo(new NotificationBundleOption(bundleOption)); + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->GetShowBadgeEnabledForBundle(bo, enabled); } @@ -710,6 +710,28 @@ ErrCode AnsNotification::GetDisturbMode(NotificationConstant::DisturbMode &distu return ansManagerProxy_->GetDisturbMode(disturbMode); } +ErrCode AnsNotification::CancelGroup(const std::string &groupName) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return ansManagerProxy_->CancelGroup(groupName); +} + +ErrCode AnsNotification::RemoveGroupByBundle( + const NotificationBundleOption &bundleOption, const std::string &groupName) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return ansManagerProxy_->RemoveGroupByBundle(bo, groupName); +} + void AnsNotification::ResetAnsManagerProxy() { ANS_LOGI("enter"); @@ -754,7 +776,7 @@ bool AnsNotification::GetAnsManagerProxy() return false; } - recipient_ = new AnsManagerDeathRecipient(); + recipient_ = new (std::nothrow) AnsManagerDeathRecipient(); if (!recipient_) { ANS_LOGE("Failed to create death recipient"); return false; diff --git a/frameworks/ans/native/src/notification.cpp b/frameworks/ans/native/src/notification.cpp index c69e0864c..9e829789e 100644 --- a/frameworks/ans/native/src/notification.cpp +++ b/frameworks/ans/native/src/notification.cpp @@ -100,7 +100,7 @@ std::string Notification::GetGroup() const if (request_ == nullptr) { return ""; } - return request_->GetGroupValue(); + return request_->GetGroupName(); } int32_t Notification::GetId() const @@ -160,7 +160,7 @@ bool Notification::IsGroup() const if (request_ == nullptr) { return false; } - return !(request_->GetGroupValue() == ""); + return !(request_->GetGroupName() == ""); } bool Notification::IsFloatingIcon() const diff --git a/frameworks/ans/native/src/notification_helper.cpp b/frameworks/ans/native/src/notification_helper.cpp index 87d459c55..7b2ae30cb 100644 --- a/frameworks/ans/native/src/notification_helper.cpp +++ b/frameworks/ans/native/src/notification_helper.cpp @@ -305,5 +305,16 @@ ErrCode NotificationHelper::GetDisturbMode(NotificationConstant::DisturbMode &di { return DelayedSingleton::GetInstance()->GetDisturbMode(disturbMode); } + +ErrCode NotificationHelper::CancelGroup(const std::string &groupName) +{ + return DelayedSingleton::GetInstance()->CancelGroup(groupName); +} + +ErrCode NotificationHelper::RemoveGroupByBundle( + const NotificationBundleOption &bundleOption, const std::string &groupName) +{ + return DelayedSingleton::GetInstance()->RemoveGroupByBundle(bundleOption, groupName); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index b346882bd..801fb1eb0 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -74,7 +74,7 @@ NotificationRequest::NotificationRequest(const NotificationRequest &other) this->settingsText_ = other.settingsText_; this->creatorBundleName_ = other.creatorBundleName_; this->ownerBundleName_ = other.ownerBundleName_; - this->groupValue_ = other.groupValue_; + this->groupName_ = other.groupName_; this->statusBarText_ = other.statusBarText_; this->label_ = other.label_; this->shortcutId_ = other.shortcutId_; @@ -133,7 +133,7 @@ NotificationRequest &NotificationRequest::operator=(const NotificationRequest &o this->settingsText_ = other.settingsText_; this->creatorBundleName_ = other.creatorBundleName_; this->ownerBundleName_ = other.ownerBundleName_; - this->groupValue_ = other.groupValue_; + this->groupName_ = other.groupName_; this->statusBarText_ = other.statusBarText_; this->label_ = other.label_; this->shortcutId_ = other.shortcutId_; @@ -472,14 +472,14 @@ void NotificationRequest::SetGroupOverview(bool overView) groupOverview_ = overView; } -void NotificationRequest::SetGroupValue(const std::string &groupValue) +void NotificationRequest::SetGroupName(const std::string &groupName) { - groupValue_ = groupValue; + groupName_ = groupName; } -std::string NotificationRequest::GetGroupValue() const +std::string NotificationRequest::GetGroupName() const { - return groupValue_; + return groupName_; } bool NotificationRequest::IsOnlyLocal() const @@ -720,7 +720,7 @@ std::string NotificationRequest::Dump() ", creatorBundleName = " + creatorBundleName_ + ", creatorPid = " + std::to_string(static_cast(creatorPid_)) + ", creatorUid = " + std::to_string(static_cast(creatorUid_)) + - ", ownerBundleName = " + ownerBundleName_ + ", groupValue = " + groupValue_ + + ", ownerBundleName = " + ownerBundleName_ + ", groupName = " + groupName_ + ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ + ", sortingKey = " + sortingKey_ + ", groupAlertType = " + std::to_string(static_cast(groupAlertType_)) + @@ -824,8 +824,8 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const return false; } - if (!parcel.WriteString(groupValue_)) { - ANS_LOGE("Failed to write group value"); + if (!parcel.WriteString(groupName_)) { + ANS_LOGE("Failed to write group name"); return false; } @@ -1127,8 +1127,8 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) return false; } - if (!parcel.ReadString(groupValue_)) { - ANS_LOGE("Failed to read group value"); + if (!parcel.ReadString(groupName_)) { + ANS_LOGE("Failed to read group name"); return false; } diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index a1ba734cd..fb566027d 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -61,6 +61,8 @@ const int32_t CALLING_UID = 9999; const int32_t PIXEL_MAP_TEST_WIDTH = 32; const int32_t PIXEL_MAP_TEST_HEIGHT = 32; +const int32_t CANCELGROUP_NID = 10101; + std::mutex g_subscribe_mtx; std::mutex g_consumed_mtx; std::mutex g_unsubscribe_mtx; @@ -93,6 +95,7 @@ public: virtual void OnCanceled(const std::shared_ptr &request) override { + GTEST_LOG_(INFO) << "ANS_Interface_MT::OnCanceled request : " << request->GetNotificationRequest().Dump(); OnCanceledReceived = true; } @@ -347,7 +350,7 @@ private: EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType()); EXPECT_EQ(false, notificationRequest.IsColorEnabled()); EXPECT_EQ(false, notificationRequest.IsCountdownTimer()); - EXPECT_EQ("groupvalue", notificationRequest.GetGroupValue()); + EXPECT_EQ("groupvalue", notificationRequest.GetGroupName()); EXPECT_EQ(true, notificationRequest.IsOnlyLocal()); EXPECT_EQ("setting text", notificationRequest.GetSettingsText()); EXPECT_EQ(false, notificationRequest.IsShowStopwatch()); @@ -885,7 +888,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00900, Function req.SetNotificationId(CASE_NINE); req.SetColorEnabled(false); req.SetCountdownTimer(false); - req.SetGroupValue("groupvalue"); + req.SetGroupName("groupvalue"); req.SetOnlyLocal(true); req.SetSettingsText("setting text"); req.SetShowStopwatch(false); @@ -1133,7 +1136,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_07000, Function NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); - req.SetGroupValue("groupnotifcation"); + req.SetGroupName("groupnotifcation"); req.SetGroupOverview(true); req.SetNotificationId(CASE_SIXTEEN); req.SetGroupAlertType(NotificationRequest::GroupAlertType::ALL); @@ -1203,5 +1206,78 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ WaitOnUnsubscribeResult(); OnCanceledReceived = false; } + +/** + * @tc.number : ANS_FW_MT_CancelGroup_10100 + * @tc.name : CancelGroup_10100 + * @tc.desc : Cancel the notifications of the same group. + * @tc.expected : All notifications of the same group have been cancelled. + */ +HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_CancelGroup_10100, Function | MediumTest | Level1) +{ + NotificationSubscribeInfo info = NotificationSubscribeInfo(); + info.AddAppName("bundleName"); + + auto subscriber = TestAnsSubscriber(); + g_subscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); + WaitOnSubscribeResult(); + + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100::normalContentis::" << normalContent->Dump(); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + + NotificationRequest req; + req.SetContent(content); + req.SetSlotType(NotificationConstant::OTHER); + req.SetNotificationId(CANCELGROUP_NID); + req.SetLabel("CancelGroup_10100"); + req.SetGroupName("group10100"); + + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + OnConsumedReceived = false; + + GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call CancelGroup : effective parameters"; + EXPECT_EQ(0, NotificationHelper::CancelGroup("group10100")); + + sleep(SLEEP_TIME); + OnCanceledReceived = false; + + GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call CancelGroup : invalid parameters"; + EXPECT_EQ(0, NotificationHelper::CancelGroup("ngroup")); + + sleep(SLEEP_TIME); + OnCanceledReceived = false; + + req.SetOwnerBundleName("mybundlename"); + req.SetCreatorBundleName("mybundlename"); + g_consumed_mtx.unlock(); + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + OnConsumedReceived = false; + + NotificationBundleOption bo; + bo.SetBundleName("bundlename"); + GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call RemoveGroupByBundle : effective parameters"; + EXPECT_NE(0, NotificationHelper::RemoveGroupByBundle(bo, "group10100")); + + sleep(SLEEP_TIME); + OnCanceledReceived = false; + + GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call RemoveGroupByBundle : invalid parameters"; + EXPECT_NE(0, NotificationHelper::RemoveGroupByBundle(bo, "ngroup")); + + sleep(SLEEP_TIME); + OnCanceledReceived = false; + + g_unsubscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber, info)); + WaitOnUnsubscribeResult(); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/notification_helper.h b/interfaces/innerkits/ans/native/include/notification_helper.h index b6b5fbf65..f0873ff22 100644 --- a/interfaces/innerkits/ans/native/include/notification_helper.h +++ b/interfaces/innerkits/ans/native/include/notification_helper.h @@ -587,8 +587,24 @@ public: * @return Returns get disturb mode result. */ static ErrCode GetDisturbMode(NotificationConstant::DisturbMode &disturbMode); -}; + /** + * Cancel the notification of the specified group of this application. + * + * @param groupName the specified group name. + * @return Returns cancel group result. + */ + static ErrCode CancelGroup(const std::string &groupName); + + /** + * Remove the notification of the specified group of the specified application. + * + * @param bundleOption Indicates the bundle name and uid of the specified application. + * @param groupName the specified group name. + * @return Returns remove group by bundle result. + */ + static ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName); +}; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index 1536f675b..d5f6c81df 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -325,7 +325,7 @@ public: /** * Adds a NotificationActionButton to this notification. - * An operation button is usually placed next to the notification content by the system. + * An operation button is usually placed next to the notification content by the system. * Each action button must contain an icon, a title, and an WantAgent. When a notification is expanded, * a maximum of three action buttons can be displayed from left to right in the order they were added. * When the notification is collapsed, no action buttons will be displayed. @@ -530,8 +530,8 @@ public: /** * Sets whether to use this notification as the overview of its group. - * This method helps display the notifications that are assigned the same group value by calling - * setGroupValue(string) as one stack in the notification bar. + * This method helps display the notifications that are assigned the same group name by calling + * setGroupName(string) as one stack in the notification bar. * Each group requires only one group overview. After a notification is set as the group overview, * it becomes invisible if another notification in the same group is published. * @param overView Specifies whether to set this notification as the group overview. @@ -542,21 +542,21 @@ public: * Sets the group information for this notification. * If no groups are set for notifications, all notifications from the same application will appear * in the notification bar as one stack with the number of stacked notifications displayed. - * If notifications are grouped and there are multiple groups identified by different groupValue, - * notifications with different groupValue will appear in separate stacks. + * If notifications are grouped and there are multiple groups identified by different groupName, + * notifications with different groupName will appear in separate stacks. * Note that one of the notifications in a group must be set as the overview of its group by calling * setGroupOverview(bool), and other notifications are considered as child notifications. - * Otherwise, notifications will not be displayed as one group even if they are assigned the same groupValue by - * calling setGroupValue(string). - * @param groupValue Specifies whether to set this notification as the group overview. + * Otherwise, notifications will not be displayed as one group even if they are assigned the same groupName by + * calling setGroupName(string). + * @param groupName Specifies whether to set this notification as the group overview. */ - void SetGroupValue(const std::string &groupValue); + void SetGroupName(const std::string &groupName); /** * Obtains the group information about this notification. * @return the group information about this notification. */ - std::string GetGroupValue() const; + std::string GetGroupName() const; /** * Checks whether this notification is relevant only to the local device and cannot be displayed on remote devices. @@ -903,7 +903,7 @@ private: std::string settingsText_ {}; std::string creatorBundleName_ {}; std::string ownerBundleName_ {}; - std::string groupValue_ {}; + std::string groupName_ {}; std::string statusBarText_ {}; std::string label_ {}; std::string shortcutId_ {}; diff --git a/interfaces/kits/napi/ans/include/cancel.h b/interfaces/kits/napi/ans/include/cancel.h index 6d41052f8..219005d66 100644 --- a/interfaces/kits/napi/ans/include/cancel.h +++ b/interfaces/kits/napi/ans/include/cancel.h @@ -24,6 +24,7 @@ using namespace OHOS::Notification; napi_value Cancel(napi_env env, napi_callback_info info); napi_value CancelAll(napi_env env, napi_callback_info info); +napi_value CancelGroup(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/include/remove.h b/interfaces/kits/napi/ans/include/remove.h index 2e03ac5ac..fddba9010 100644 --- a/interfaces/kits/napi/ans/include/remove.h +++ b/interfaces/kits/napi/ans/include/remove.h @@ -25,6 +25,7 @@ using namespace OHOS::Notification; napi_value Remove(napi_env env, napi_callback_info info); napi_value RemoveAsBundle(napi_env env, napi_callback_info info); napi_value RemoveAll(napi_env env, napi_callback_info info); +napi_value RemoveGroupByBundle(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/src/cancel.cpp b/interfaces/kits/napi/ans/src/cancel.cpp index 71ea420be..3edad374c 100644 --- a/interfaces/kits/napi/ans/src/cancel.cpp +++ b/interfaces/kits/napi/ans/src/cancel.cpp @@ -20,6 +20,8 @@ namespace NotificationNapi { const int CANCEL_MAX_PARA = 3; const int CANCEL_ALL_MAX_PARA = 1; +const int CANCEL_GROUP_MAX_PARA = 2; +const int CANCEL_GROUP_MIN_PARA = 1; struct ParametersInfoCancel { int id = 0; @@ -35,6 +37,18 @@ struct AsyncCallbackInfoCancel { CallbackPromiseInfo info; }; +struct ParametersInfoCancelGroup { + std::string groupName = ""; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoCancelGroup { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + CallbackPromiseInfo info; + ParametersInfoCancelGroup params {}; +}; + napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, ParametersInfoCancel ¶s) { ANS_LOGI("enter"); @@ -77,7 +91,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, return Common::NapiGetNull(env); } -napi_value ParseParametersByCancelAll(const napi_env &env, const napi_callback_info &info, napi_ref &callback) +napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_ref &callback) { ANS_LOGI("enter"); @@ -96,6 +110,35 @@ napi_value ParseParametersByCancelAll(const napi_env &env, const napi_callback_i return Common::NapiGetNull(env); } +napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, ParametersInfoCancelGroup ¶s) +{ + ANS_LOGI("enter"); + + size_t argc = CANCEL_GROUP_MAX_PARA; + napi_value argv[CANCEL_GROUP_MAX_PARA] = {nullptr}; + napi_value thisVar = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + NAPI_ASSERT(env, argc >= CANCEL_GROUP_MIN_PARA, "Wrong number of arguments"); + + napi_valuetype valuetype = napi_undefined; + // argv[0]: groupName: string + NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], str, STR_MAX_SIZE - 1, &strLen)); + paras.groupName = str; + + // argv[1]: callback + if (argc >= CANCEL_GROUP_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[CANCEL_GROUP_MIN_PARA], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv[CANCEL_GROUP_MIN_PARA], 1, ¶s.callback); + } + + return Common::NapiGetNull(env); +} + napi_value Cancel(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -159,7 +202,7 @@ napi_value CancelAll(napi_env env, napi_callback_info info) ANS_LOGI("enter"); napi_ref callback = nullptr; - if (ParseParametersByCancelAll(env, info, callback) == nullptr) { + if (ParseParameters(env, info, callback) == nullptr) { return Common::NapiGetUndefined(env); } @@ -210,5 +253,63 @@ napi_value CancelAll(napi_env env, napi_callback_info info) } } +napi_value CancelGroup(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + + ParametersInfoCancelGroup params; + if (ParseParameters(env, info, params) == nullptr) { + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoCancelGroup *asynccallbackinfo = new (std::nothrow) + AsyncCallbackInfoCancelGroup {.env = env, .asyncWork = nullptr, .params = params}; + if (!asynccallbackinfo) { + return Common::JSParaError(env, params.callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "cancelGroup", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("CancelGroup napi_create_async_work start"); + AsyncCallbackInfoCancelGroup *asynccallbackinfo = (AsyncCallbackInfoCancelGroup *)data; + ANS_LOGI("asynccallbackinfo->params.groupName = %{public}s", asynccallbackinfo->params.groupName.c_str()); + asynccallbackinfo->info.errorCode = + NotificationHelper::CancelGroup(asynccallbackinfo->params.groupName); + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("CancelGroup napi_create_async_work end"); + AsyncCallbackInfoCancelGroup *asynccallbackinfo = (AsyncCallbackInfoCancelGroup *)data; + + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + + if (asynccallbackinfo->info.isCallback) { + return Common::NapiGetNull(env); + } else { + return promise; + } +} + } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 650e0935e..9f04afff1 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -77,7 +77,8 @@ static napi_value GetNotificationMultiLineContent( static napi_value GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, std::shared_ptr &multiLineContent); static napi_value GetNotificationExtraInfo(const napi_env &env, const napi_value &value, NotificationRequest &request); - +static napi_value GetNotificationGroupName( + const napi_env &env, const napi_value &value, NotificationRequest &request); Common::Common() {} @@ -411,6 +412,10 @@ napi_value Common::SetNotificationRequest( } } + // groupName?: string + napi_create_string_utf8(env, request->GetGroupName().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "groupName", value); + // readonly creatorBundleName?: string napi_create_string_utf8(env, request->GetCreatorBundleName().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "creatorBundleName", value); @@ -1141,6 +1146,11 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } + // groupName?: string + if (GetNotificationGroupName(env, value, request) == nullptr) { + return nullptr; + } + return Common::NapiGetNull(env); } @@ -1395,6 +1405,28 @@ napi_value GetNotificationExtraInfo(const napi_env &env, const napi_value &value return Common::NapiGetNull(env); } +napi_value GetNotificationGroupName(const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + + NAPI_CALL(env, napi_has_named_property(env, value, "groupName", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "groupName", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); + request.SetGroupName(str); + } + + return Common::NapiGetNull(env); +} + napi_value GetNotificationRemovalWantAgent(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); diff --git a/interfaces/kits/napi/ans/src/init.cpp b/interfaces/kits/napi/ans/src/init.cpp index 864e4a775..46ccbece6 100644 --- a/interfaces/kits/napi/ans/src/init.cpp +++ b/interfaces/kits/napi/ans/src/init.cpp @@ -47,6 +47,7 @@ napi_value NotificationInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getActiveNotificationCount", GetActiveNotificationCount), DECLARE_NAPI_FUNCTION("cancel", Cancel), DECLARE_NAPI_FUNCTION("cancelAll", CancelAll), + DECLARE_NAPI_FUNCTION("cancelGroup", CancelGroup), DECLARE_NAPI_FUNCTION("addSlot", AddSlot), DECLARE_NAPI_FUNCTION("addSlots", AddSlots), DECLARE_NAPI_FUNCTION("setSlotByBundle", SetSlotByBundle), @@ -56,6 +57,7 @@ napi_value NotificationInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getSlotsByBundle", GetSlotsByBundle), DECLARE_NAPI_FUNCTION("removeSlot", RemoveSlot), DECLARE_NAPI_FUNCTION("removeAllSlots", RemoveAllSlots), + DECLARE_NAPI_FUNCTION("removeGroupByBundle", RemoveGroupByBundle), DECLARE_NAPI_FUNCTION("enableNotification", EnableNotification), DECLARE_NAPI_FUNCTION("isNotificationEnabled", IsNotificationEnabled), DECLARE_NAPI_FUNCTION("displayBadge", DisplayBadge), diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index 90c71f2f2..3fa28b90f 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -29,6 +29,9 @@ const int REMOVE_ALL_WHEN_HAS_PARA_MIN_PARA = 1; const int REMOVE_BY_BUNDLE_AND_KEY_MIN_PARA = 2; const int REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA = 3; +const int REMOVE_GROUP_BY_BUNDLE_MIN_PARA = 2; +const int REMOVE_GROUP_BY_BUNDLE_MAX_PARA = 3; + struct BundleAndKeyInfo { BundleOption option; NotificationKey key; @@ -47,6 +50,19 @@ struct AsyncCallbackInfoRemove { CallbackPromiseInfo info; }; +struct RemoveParamsGroupByBundle { + BundleOption option; + std::string groupName = ""; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoRemoveGroupByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + RemoveParamsGroupByBundle params {}; + CallbackPromiseInfo info; +}; + napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, RemoveParams ¶ms) { ANS_LOGI("enter"); @@ -145,6 +161,45 @@ napi_value ParseParametersByRemoveAll(const napi_env &env, const napi_callback_i return Common::NapiGetNull(env); } +napi_value ParseParameters( + const napi_env &env, const napi_callback_info &info, RemoveParamsGroupByBundle ¶ms) +{ + ANS_LOGI("enter"); + + size_t argc = REMOVE_GROUP_BY_BUNDLE_MAX_PARA; + napi_value argv[REMOVE_GROUP_BY_BUNDLE_MAX_PARA] = {nullptr}; + napi_value thisVar = nullptr; + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + NAPI_ASSERT(env, argc >= REMOVE_GROUP_BY_BUNDLE_MIN_PARA, "Wrong number of arguments"); + + // argv[0]: bundle + NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); + auto retValue = Common::GetBundleOption(env, argv[0], params.option); + if (retValue == nullptr) { + ANS_LOGE("GetBundleOption failed."); + return nullptr; + } + + // argv[1]: groupName: string + NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[1], str, STR_MAX_SIZE - 1, &strLen)); + params.groupName = str; + + // argv[2]:callback + if (argc >= REMOVE_GROUP_BY_BUNDLE_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[REMOVE_GROUP_BY_BUNDLE_MIN_PARA], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv[REMOVE_GROUP_BY_BUNDLE_MIN_PARA], 1, ¶ms.callback); + } + + return Common::NapiGetNull(env); +} + napi_value Remove(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -275,5 +330,69 @@ napi_value RemoveAll(napi_env env, napi_callback_info info) } } +napi_value RemoveGroupByBundle(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + + RemoveParamsGroupByBundle params {}; + if (ParseParameters(env, info, params) == nullptr) { + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoRemoveGroupByBundle {.env = env, .asyncWork = nullptr, .params = params}; + if (!asynccallbackinfo) { + return Common::JSParaError(env, params.callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "removeGroupByBundle", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("RemoveGroupByBundle napi_create_async_work start"); + AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = (AsyncCallbackInfoRemoveGroupByBundle *)data; + NotificationBundleOption bundleOption; + bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); + bundleOption.SetUid(asynccallbackinfo->params.option.uid); + ANS_LOGI("asynccallbackinfo->params.option.bundle = %{public}s", + asynccallbackinfo->params.option.bundle.c_str()); + ANS_LOGI("asynccallbackinfo->params.option.uid = %{public}d", asynccallbackinfo->params.option.uid); + ANS_LOGI("asynccallbackinfo->params.groupName = %{public}s", asynccallbackinfo->params.groupName.c_str()); + asynccallbackinfo->info.errorCode = + NotificationHelper::RemoveGroupByBundle(bundleOption, asynccallbackinfo->params.groupName); + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("RemoveGroupByBundle napi_create_async_work end"); + AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = (AsyncCallbackInfoRemoveGroupByBundle *)data; + + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + + if (asynccallbackinfo->info.isCallback) { + return Common::NapiGetNull(env); + } else { + return promise; + } +} + } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 67445a147..c05bd30af 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -101,6 +101,10 @@ public: ErrCode IsAllowedNotify(bool &allowed) override; ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override; + ErrCode CancelGroup(const std::string &groupName) override; + ErrCode RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) override; + ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) override; // SystemEvent diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 3d8eb02a9..9f66fcf73 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -961,8 +961,13 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabledForBundle( } ErrCode result = ERR_OK; - handler_->PostSyncTask( - std::bind([&]() { result = NotificationPreferences::GetInstance().IsShowBadge(bundle, enabled); })); + handler_->PostSyncTask(std::bind([&]() { + result = NotificationPreferences::GetInstance().IsShowBadge(bundle, enabled); + if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { + result = ERR_OK; + enabled = false; + } + })); return result; } @@ -1636,5 +1641,85 @@ ErrCode AdvancedNotificationService::GetSlotNumAsBundle(const sptr bundleOption = GenerateBundleOption(); + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + handler_->PostSyncTask(std::bind([&]() { + std::vector> removeList; + for (auto record : notificationList_) { + if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && + (record->bundleOption->GetUid() == bundleOption->GetUid()) && + (record->request->GetGroupName() == groupName)) { + removeList.push_back(record); + } + } + + for (auto record : removeList) { + notificationList_.remove(record); + + if (record->notification != nullptr) { + int reason = NotificationConstant::APP_CANCEL_REASON_DELETE; + UpdateRecentNotification(record->notification, true, reason); + sptr sortingMap = GenerateSortingMap(); + NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, sortingMap, reason); + } + } + })); + + return ERR_OK; +} + +ErrCode AdvancedNotificationService::RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + if (!IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (bundleOption == nullptr || groupName.empty()) { + return ERR_ANS_INVALID_PARAM; + } + + sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + handler_->PostSyncTask(std::bind([&]() { + std::vector> removeList; + for (auto record : notificationList_) { + if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && + (record->bundleOption->GetUid() == bundle->GetUid()) && !record->request->IsUnremovable() && + (record->request->GetGroupName() == groupName)) { + removeList.push_back(record); + } + } + + for (auto record : removeList) { + notificationList_.remove(record); + + if (record->notification != nullptr) { + int reason = NotificationConstant::CANCEL_REASON_DELETE; + UpdateRecentNotification(record->notification, true, reason); + sptr sortingMap = GenerateSortingMap(); + NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, sortingMap, reason); + } + } + })); + + return ERR_OK; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index b54d4b57f..33d6ec5f8 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -618,14 +618,18 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02700, /** * @tc.number : AdvancedNotificationServiceTest_02800 * @tc.name : AMS_ANS_GetShowBadgeEnabledForBundle_0100 - * @tc.desc : Test GetShowBadgeEnabledForBundle function when no bundle + * @tc.desc : Test GetShowBadgeEnabledForBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02800, Function | SmallTest | Level1) { + EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true), + (int)ERR_OK); bool allow = false; EXPECT_EQ((int)advancedNotificationService_->GetShowBadgeEnabledForBundle( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow), - (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); + (int)ERR_OK); + EXPECT_TRUE(allow); } /** @@ -1068,7 +1072,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06900, bool allow = false; EXPECT_EQ((int)advancedNotificationService_->GetShowBadgeEnabledForBundle( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow), - (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); + (int)ERR_OK); } /** @@ -1385,5 +1389,55 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_ICON_OVER_SIZE); } +/** + * @tc.number : AdvancedNotificationServiceTest_10300 + * @tc.name : AMS_ANS_Cancel_By_Group_10300 + * @tc.desc : Cancel notification by group name. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, Function | SmallTest | Level1) +{ + sptr req = new NotificationRequest(1); + ASSERT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr normalContent = std::make_shared(); + ASSERT_NE(normalContent, nullptr); + normalContent->SetText("text"); + normalContent->SetTitle("title"); + std::shared_ptr content = std::make_shared(normalContent); + ASSERT_NE(content, nullptr); + req->SetContent(content); + std::string groupName = "group"; + req->SetGroupName(groupName); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK); + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), (int)ERR_OK); + SleepForFC(); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10400 + * @tc.name : AMS_ANS_Remove_By_Group_10400 + * @tc.desc : Remove notification by group name. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10400, Function | SmallTest | Level1) +{ + sptr req = new NotificationRequest(1); + ASSERT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr normalContent = std::make_shared(); + ASSERT_NE(normalContent, nullptr); + normalContent->SetText("text"); + normalContent->SetTitle("title"); + std::shared_ptr content = std::make_shared(normalContent); + ASSERT_NE(content, nullptr); + req->SetContent(content); + std::string groupName = "group"; + req->SetGroupName(groupName); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK); + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), (int)ERR_OK); + SleepForFC(); +} } // namespace Notification } // namespace OHOS diff --git a/test/BUILD.gn b/test/BUILD.gn index ab4862fc3..7f120ed9d 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -24,5 +24,8 @@ config("system_test_config") { group("systemtest") { testonly = true - deps = [ "resource\ansSTSlotGroupTest:ansSTSlotGroupTest" ] + deps = [ + "common\acts:actsnotificationtest", + "resource\ansSTSlotGroupTest:ansSTSlotGroupTest", + ] } diff --git a/test/common/acts/BUILD.gn b/test/common/acts/BUILD.gn new file mode 100644 index 000000000..e944f071f --- /dev/null +++ b/test/common/acts/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 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/ces_standard/event.gni") +import("//build/ohos.gni") + +config("ansfwk_kits_test_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//utils/native/base/include", + "//foundation/appexecfwk/standard/common/log/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + "//foundation/appexecfwk/standard/services/bundlemgr/include", + "//utils/system/safwk/native/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", + "${services_path}/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] +} + +group("actsnotificationtest") { + testonly = true + + deps = [ "actsnotificationfuzztest:actsnotificationfuzztest" ] +} diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn new file mode 100755 index 000000000..5ee78f9a7 --- /dev/null +++ b/test/common/acts/actsnotificationfuzztest/BUILD.gn @@ -0,0 +1,107 @@ +# Copyright (c) 2021 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/ans_standard/notification.gni") +import("//build/test.gni") + +module_output_path = "ans_standard/systemtest" + +ohos_systemtest("ActsNotificationFuzzTest") { + module_out_path = module_output_path + resource_config_file = + "${ans_standard_path}/test/resource/notificationfuzztest/ohos_test.xml" + + sources = [ + "${ans_standard_path}/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp", + "${ans_standard_path}/test/resource/notificationfuzztest/src/notificationgetparam.cpp", + "actsnotificationfuzztest.cpp", + ] + + configs = [ "${ans_standard_path}/test/common/acts:ansfwk_kits_test_config" ] + + include_dirs = [ + "//utils/native/base/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//base/notification/ans_standard/frameworks/ans/core/include", + "//base/notification/ans_standard/interfaces/innerkits/ans/native/include", + "//base/notification/ans_standard/services/ans/include", + "//third_party/json/single_include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include", + "//foundation/appexecfwk/standard/kits/appkit/native/app/include", + "//foundation/appexecfwk/adapter/interfaces/innerkits/appexecfwk_base/include", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include", + "//foundation/aafwk/standard/services/abilitymgr/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/appexecfwk/standard/kits/appkit/native/app/include/task", + "//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher/include/threading", + "//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher/include/dispatcher", + "//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher/include/task", + ] + + cflags = [] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", + "//base/notification/ans_standard/frameworks/ans/core:ans_core", + "//base/notification/ans_standard/frameworks/ans/native:ans_innerkits", + "//base/notification/ans_standard/frameworks/wantagent:native_wantagent", + "//base/notification/ans_standard/services/ans:ans_targets", + "//base/notification/ces_standard/frameworks/common:libevent_common", + "//base/notification/ces_standard/frameworks/native:cesfwk_innerkits", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/base:base", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + "//foundation/appexecfwk/standard/interfaces/innerkits/task_dispatcher:appkit_dispatcher_td", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + defines = [ + "APP_LOG_TAG = \"AnsFwkKitsTest\"", + "LOG_DOMAIN = 0xD002200", + ] + external_deps = [ + "aafwk_standard:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "appexecfwk_standard:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "native_appdatamgr:native_appdatafwk", + "native_appdatamgr:native_dataability", + "native_appdatamgr:native_rdb", + ] +} + +group("actsnotificationfuzztest") { + testonly = true + + deps = [ ":ActsNotificationFuzzTest" ] +} diff --git a/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp b/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp new file mode 100644 index 000000000..09ed283d0 --- /dev/null +++ b/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 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 "../../../resource/notificationfuzztest/include/notificationfuzztestmanager.h" + +#include + +using namespace testing::ext; +namespace OHOS { +namespace Notification { + +class ActsFuzzTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void ActsFuzzTest::SetUpTestCase() +{} + +void ActsFuzzTest::TearDownTestCase() +{} + +void ActsFuzzTest::SetUp() +{} + +void ActsFuzzTest::TearDown() +{} + +HWTEST_F(ActsFuzzTest, ACTS_FuzzTest_0100, Function | MediumTest | Level1) +{ + std::cout << "fuzztest start" << std::endl; + fuzzTestManager::GetInstance()->StartFuzzTest(); + std::cout << "fuzztest end" << std::endl; +} + +} // namespace EventFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h b/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h new file mode 100644 index 000000000..1c8c32c4c --- /dev/null +++ b/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 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 NOTIFICATION_FUZZ_CONFIG_PARSER_H +#define NOTIFICATION_FUZZ_CONFIG_PARSER_H + +#include "nlohmann/json.hpp" + +namespace OHOS { + +const std::string FUZZ_TEST_CONFIG_FILE_PATH{"/data/fuzztestconfig/config.json"}; + +const std::string FUZZ_TEST_MAIN_LOOP_KEY{"flag"}; + +struct FuzzTestData { + int32_t mainLoopFlag{0}; + std::vector methodVec{}; +}; + +class FuzzConfigParser { +public: + void ParseFromFile4FuzzTest(const std::string &path, FuzzTestData &ftd) + { + std::cout << __func__ << std::endl; + if (path.empty()) { + std::cout << __FUNCTION__ << " invalid file path, check!" << std::endl; + return; + } + + nlohmann::json jsonObj; + std::ifstream(path) >> jsonObj; + std::cout << path; + for (auto it = jsonObj.begin(); it != jsonObj.end(); ++it) { + if (!it.key().compare(FUZZ_TEST_MAIN_LOOP_KEY)) { + ftd.mainLoopFlag = it.value(); + continue; + } + + auto className = it.key(); + if (it->is_structured()) { + for (auto itm = it->begin(); itm != it->end(); ++itm) { + auto methodName = itm.key(); + + if (!(it->is_structured() && (it->size() != 0))) { + ftd.methodVec.push_back(className + methodName); + continue; + } + + std::string param{}; + for (auto itp = itm->begin(); itp != itm->end(); ++itp) { + auto tp = itp.value(); + param += tp; + } + ftd.methodVec.push_back(className + methodName + param); + } + } + } + } +}; + +} // namespace OHOS + +#endif // FUZZ_CONFIG_PARSER_H diff --git a/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h b/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h new file mode 100644 index 000000000..bb6fc825e --- /dev/null +++ b/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021 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 NOTIFICATION_FUZZTESTMANAGER_H +#define NOTIFICATION_FUZZTESTMANAGER_H + +#include +#include + +#include "nlohmann/json.hpp" +namespace OHOS { +namespace Notification { + +class fuzzTestManager { +public: + typedef std::shared_ptr Ptr; + ~fuzzTestManager() + {} + static Ptr GetInstance() + { + if (instance_ == nullptr) { + instance_ = std::shared_ptr(new fuzzTestManager); + } + return instance_; + } + + void StartFuzzTest(); + +private: + void SetJsonFunction(std::string); + void SetCycle(uint16_t cycle); + fuzzTestManager(); + fuzzTestManager(fuzzTestManager &) = delete; + fuzzTestManager &operator=(const fuzzTestManager &) = delete; + static Ptr instance_; + uint16_t cycle_{}; + std::unordered_map remainderMap_{}; + std::unordered_map> callFunctionMap_{}; + + const int COLOR_R = 100; + const int COLOR_G = 100; + const int COLOR_B = 100; + + void RegisterAsyncCommonEventResult(); + void RegisterCommonEventData(); + void RegisterCommonEventManager(); + void RegisterCommonEventPublishInfo(); + void RegisterCommonEventSubscribeInfo(); + void RegisterCommonEventSubscriber(); + void RegisterCommonEventSupport(); + void RegisterMatchingSkills(); + void RegisterDumper(); + void RegisterEventHandler(); + void RegisterEventQueue(); + void RegisterEventRunner(); + void RegisterFileDescriptorListener(); + void RegisterInnerEvent(); + void RegisterEventRunnerNativeImplement(); + void RegisterAbilityManager(); + void RegisterWantParams(); + void RegisterWant(); + void RegisterElementName(); + void RegisterBundleMgrProxy(); + + void RegisterOHOSApplication(); + void RegisterAbility(); + void RegisterDataAbilityHelper(); + void RegisterDataUriUtils(); + void RegisterLifeCycle(); + + void RegisterAbilityContext(); + void RegisterProcessInfo(); + + void RegisterNotificationHelper(); + void RegisterNotificationSorting(); + void RegisterNotificationSortingMap(); + void RegisterNotificationSubscribeInfo(); + void RegisterNotificationSubscriber(); + void RegisterWantAgentHelper(); + void RegisterLauncherService(); + void RegisterNapiBundlemgr(); + void RegisterIAbilityContinuation(); + void RegisterRevocable(); + void RegisterTaskDispatcher(); + void RegisterAbility_(); + void RegisterAbilityContext_(); + void RegisterContext(); + void RegisterAbilityLifecycleCallbacks(); + void RegisterIAbilityManager(); + friend class TestAnsSubscriber; +}; +} // namespace EventFwk +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/test/resource/notificationfuzztest/include/notificationgetparam.h b/test/resource/notificationfuzztest/include/notificationgetparam.h new file mode 100644 index 000000000..baa039a3b --- /dev/null +++ b/test/resource/notificationfuzztest/include/notificationgetparam.h @@ -0,0 +1,442 @@ +/* + * Copyright (c) 2021 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 NOTIFICATION_GET_PARAM_H +#define NOTIFICATION_GET_PARAM_H +#include +#include "ability.h" +#include "ability_handler.h" +#include "ability_manager.h" +#include "ability_manager_interface.h" +#include "async_common_event_result.h" +#include "bundle_info.h" +#include "common_event_manager.h" +#include "common_event_data.h" +#include "common_event_publish_info.h" +#include "common_event_subscribe_info.h" +#include "common_event_subscriber.h" +#include "common_event_support.h" +#include "data_uri_utils.h" +#include "element_name.h" +#include "event_handler.h" +#include "event_runner.h" +#include "inner_event.h" +#include "key_event.h" +#include "logger.h" +#include "matching_skills.h" +#include "module_info.h" +#include "native_implement_eventhandler.h" +#include "pac_map.h" +#include "parcel.h" +#include "patterns_matcher.h" +#include "uri.h" +#include "want.h" +#include "bundle_mgr_proxy.h" +#include "notification_sorting_map.h" +#include "notification_helper.h" +#include "want_agent_helper.h" +#include "notification.h" +#ifdef PRINT_LOG +#undef PRINT_LOG +#endif +#include "launcher_service.h" +#include "launcher_ability_info.h" +#include "task_dispatcher.h" +#include "base_task_dispatcher.h" +#include "spec_task_dispatcher.h" +#include "task_dispatcher_context.h" +#include "ability_manager_service.h" + +using Want = OHOS::AAFwk::Want; +namespace OHOS { +namespace Notification { +class TestDumper; +bool GetBoolParam(); +uint8_t GetU8Param(); +unsigned int GetUIntParam(); +uint16_t GetU16Param(); +uint32_t GetU32Param(); +uint64_t GetU64Param(); +int8_t GetS8Param(); +int16_t GetS16Param(); +int32_t GetS32Param(); +int64_t GetS64Param(); +char32_t GetChar32Param(); + +short GetShortParam(); +long GetLongParam(); +int GetIntParam(); +double GetDoubleParam(); +float GetFloatParam(); +char GetCharParam(); +char *GetCharArryParam(); +std::string GetStringParam(); +std::vector GetBoolVectorParam(); +std::vector GetShortVectorParam(); +std::vector GetLongVectorParam(); +std::vector GetIntVectorParam(); +std::vector GetFloatVectorParam(); +std::vector GetDoubleVectorParam(); +std::vector GetCharVectorParam(); +std::vector GetChar32VectorParam(); +std::vector GetStringVectorParam(); +template +std::vector GetUnsignVectorParam(); +std::vector GetS8VectorParam(); +std::vector GetS16VectorParam(); +std::vector GetS32VectorParam(); +std::vector GetS64VectorParam(); + +std::shared_ptr GetParamParcel(); +std::shared_ptr GetParamWant(); +std::vector> GetParamWantVector(); +OHOS::AAFwk::Operation GetParamOperation(); +std::shared_ptr GetParamAsyncCommonEventResult(); +std::shared_ptr GetParamCommonEventData(); +std::shared_ptr GetParamCommonEventManager(); +std::shared_ptr GetParamCommonEventPublishInfo(); +std::shared_ptr GetParamCommonEventSubscribeInfo(); +std::shared_ptr GetParamCommonEventSubscriber(); +std::shared_ptr GetParamCommonEventSupport(); +std::shared_ptr GetParamMatchingSkills(); +sptr GetParamSptrRemote(); +std::shared_ptr GetParamEventRunner(); +std::shared_ptr GetParamEventHandler(); +std::shared_ptr GetParamEventQueue(); +std::shared_ptr GetParamEventRunnerNativeImplement(); +std::shared_ptr GetParamFileDescriptorListener(); +std::shared_ptr GetParamLogger(); +OHOS::AppExecFwk::EventQueue::Priority GetParamPriority(); +TestDumper GetParamDumper(); +OHOS::AppExecFwk::InnerEvent::Pointer GetParamInnerEvent(); +OHOS::AppExecFwk::InnerEvent::Callback GetParamCallback(); +OHOS::AppExecFwk::InnerEvent::TimePoint GetParamTimePoint(); +OHOS::EventFwk::CommonEventSubscribeInfo::ThreadMode GetParamThreadMode(); + +std::shared_ptr GetParamAbilityContext(); +std::shared_ptr GetParamIAbilityEvent(); +sptr GetParamAbilityThread(); +std::shared_ptr GetParamAbilityHandler(); +std::shared_ptr GetParamAbilityStartSetting(); +std::shared_ptr GetParamAbility(); +std::shared_ptr GetParamOHOSApplication(); +std::shared_ptr GetParamKeyEvent(); +OHOS::Uri GetParamUri(); + +NativeRdb::ValuesBucket GetParamValuesBucket(); +OHOS::AppExecFwk::Configuration GetParamConfiguration(); +NativeRdb::DataAbilityPredicates GetParamDataAbilityPredicates(); +OHOS::AppExecFwk::PacMap GetParamPacMap(); +std::shared_ptr GetParamComponentContainer(); +sptr GetParamIAbilityConnection(); + +std::shared_ptr GetParamProcessInfo(); +std::shared_ptr GetParamDataUriUtils(); +std::shared_ptr GetParamDataAbilityHelper(); +std::shared_ptr GetParamLifeCycle(); +OHOS::AppExecFwk::LifeCycle::Event GetParamLifeCycleEvent(); +std::shared_ptr GetParamElementName(); +std::shared_ptr GetParamWantParams(); +std::shared_ptr GetParamAbilityManager(); +OHOS::AAFwk::PatternsMatcher GetParamPatternsMatcher(); +OHOS::AAFwk::MatchType GetParamMatchType(); +std::shared_ptr GetParamContext(); + +std::shared_ptr GetParamBundleMgrProxy(); +OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag(); +OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo(); +std::vector GetParamApplicationInfoVector(); +OHOS::AppExecFwk::BundleFlag GetParamBundleFlag(); +OHOS::AppExecFwk::BundleInfo GetParamBundleInfo(); +OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo(); +std::vector GetParamBundleInfoVector(); +OHOS::AppExecFwk::HapModuleInfo GetParamHapModuleInfo(); +OHOS::AppExecFwk::PermissionDef GetParamPermissionDef(); +std::vector GetParamPermissionDefVector(); +OHOS::AppExecFwk::IBundleMgr::Message GetParamIBundleMgrMessage(); +OHOS::MessageParcel GetParamMessageParcel(); +OHOS::AppExecFwk::DumpFlag GetParamDumpFlag(); +sptr GetParamICleanCacheCallback(); +sptr GetParamIBundleStatusCallback(); + +std::shared_ptr GetParamNotificationSorting(); +std::vector GetParamNotificationSortingVector(); +std::shared_ptr GetParamNotificationSortingMap(); +std::shared_ptr GetParamNotificationSlot(); +sptr GetParamNotificationSlotSptr(); +OHOS::Notification::NotificationConstant::SlotType GetParamSlotType(); +std::vector> GetParamNotificationSlotSptrVector(); +std::vector GetParamNotificationSlotVector(); +std::vector GetParamNotificationSlotGroupVector(); +sptr GetParamNotificationSlotGroup(); +std::vector> GetParamNotificationSlotGroupSptrVector(); +std::shared_ptr GetParamNotificationBundleOption(); +std::shared_ptr GetParamNotificationRequest(); +std::vector> GetParamNotificationRequestVector(); +sptr GetParamNotificationSortingMapSptr(); +OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel(); +std::shared_ptr GetParamNotificationSubscriber(); +std::shared_ptr GetParamNotificationSubscribeInfo(); +OHOS::Notification::NotificationConstant::DisturbMode GetParamDisturbMode(); + +std::shared_ptr GetParamWantAgentInfo(); +OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperationType(); +OHOS::Notification::WantAgent::WantAgentConstant::Flags GetParamFlags(); +std::vector GetParamFlagsVector(); + +std::shared_ptr GetParamNotification(); +sptr GetParamNotificationSptr(); +std::vector> GetParamNotificationSptrVector(); +std::shared_ptr GetParamPendingWant(); +std::shared_ptr GetParamWantAgent(); +std::shared_ptr GetParamCompletedCallback(); +std::shared_ptr GetParamTriggerInfo(); +std::shared_ptr GetParamCancelListener(); + +std::shared_ptr GetParamLauncherService(); +std::vector GetParamLauncherAbilityInfoVector(); +std::shared_ptr GetParamLauncherAbilityInfo(); +std::vector GetParamLauncherShortcutInfoVector(); +std::vector GetParamFormInfoVector(); +std::vector GetParamShortcutInfoVector(); +std::vector GetParamModuleUsageRecordVector(); +sptr GetParamOnPermissionChangedCallback(); + +std::shared_ptr GetParamTaskDispatcher(); +std::shared_ptr GetParamBaseTaskDispatcher(); +OHOS::AppExecFwk::TaskPriority GetParamTaskPriority(); +std::shared_ptr GetParamRunnable(); +std::shared_ptr GetParamGroup(); +std::shared_ptr> GetParamIteratableTask(); +OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResult(); +OHOS::AppExecFwk::MissionInformation GetParamMissionInformation(); +std::shared_ptr GetParamAbilityLifecycleCallbacks(); +std::shared_ptr GetParamIAbilityManager(); +class TestRemoteObject : public IRemoteObject { +public: + TestRemoteObject(); + ~TestRemoteObject(); + + int32_t GetObjectRefCount() override + { + return 0; + } + + int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override + { + return 0; + } + + bool IsProxyObject() const override + { + return true; + } + + bool CheckObjectLegality() const override + { + return true; + } + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool RemoveDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + sptr AsInterface() override + { + return nullptr; + } + + int Dump(int fd, const std::vector &args) override + { + return 0; + } + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; + +class TestCommonEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { +public: + TestCommonEventSubscriber(){}; + ~TestCommonEventSubscriber(){}; + virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) + { + printf("Fuzz Test Reveive Event\n"); + } +}; + +class TestDumper : public OHOS::AppExecFwk::Dumper { +public: + void Dump(const std::string &message) + { + return; + } + std::string GetTag() + { + return GetStringParam(); + } +}; + +class TestFileDescriptorListener : public OHOS::AppExecFwk::FileDescriptorListener { +public: + TestFileDescriptorListener() + {} + ~TestFileDescriptorListener() + {} +}; + +class TestIAbilityConnection : public OHOS::AAFwk::IAbilityConnection { +public: + void OnAbilityConnectDone( + const OHOS::AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override + {} + void OnAbilityDisconnectDone(const OHOS::AppExecFwk::ElementName &element, int resultCode) override + {} + virtual ~TestIAbilityConnection() + {} +}; + +class TestAbilityEvent : public OHOS::AppExecFwk::IAbilityEvent { +public: + virtual void OnBackPressed() + { + printf("Fuzz Test Back Pressed."); + } +}; + +class TestLogger : public OHOS::AppExecFwk::Logger { +public: + void Log(const std::string &line) + {} + virtual ~TestLogger() + {} +}; + +class TestICleanCacheCallback : public OHOS::AppExecFwk::ICleanCacheCallback { +public: + TestICleanCacheCallback() + {} + void OnCleanCacheFinished(bool succeeded) override + {} + virtual ~TestICleanCacheCallback() + {} +}; + +class TestIBundleStatusCallback : public OHOS::AppExecFwk::IBundleStatusCallback { +public: + TestIBundleStatusCallback() + {} + void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg, + const std::string &bundleName) override + {} + virtual ~TestIBundleStatusCallback() + {} +}; + +class TestAnsSubscriber : public OHOS::Notification::NotificationSubscriber { +public: + TestAnsSubscriber() + {} + ~TestAnsSubscriber() + {} + void OnSubscribeResult(OHOS::Notification::NotificationConstant::SubscribeResult result) override + { + std::cout << "TestAnsSubscriber OnSubscribeResult" << std::endl; + mutex_.unlock(); + } + void OnUnsubscribeResult(OHOS::Notification::NotificationConstant::SubscribeResult result) override + { + std::cout << "TestAnsSubscriber OnUnsubscribeResult" << std::endl; + mutex_.unlock(); + } + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDisturbModeChanged(int disturbMode) override + {} + void OnCanceled(const std::shared_ptr &request) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnConsumed(const std::shared_ptr &request) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + +private: + static std::mutex mutex_; +}; + +class TestCompletedCallback : public OHOS::Notification::WantAgent::CompletedCallback { + void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData, + const AAFwk::WantParams &resultExtras) override + {} +}; + +class TestCancelListener : public OHOS::Notification::WantAgent::CancelListener { +public: + void OnCancelled(int resultCode) override + {} +}; + +class TestOnPermissionChangedCallback : public OHOS::AppExecFwk::OnPermissionChangedCallback { +public: + void OnChanged(const int32_t uid) override + {} +}; + +class TestAbilityLifecycleCallbacks : public OHOS::AppExecFwk::AbilityLifecycleCallbacks { +public: + TestAbilityLifecycleCallbacks() = default; + virtual ~TestAbilityLifecycleCallbacks() = default; + virtual void OnAbilityStart(const std::shared_ptr &ability) + {} + virtual void OnAbilityInactive(const std::shared_ptr &ability) + {} + virtual void OnAbilityBackground(const std::shared_ptr &ability) + {} + virtual void OnAbilityForeground(const std::shared_ptr &ability) + {} + virtual void OnAbilityActive(const std::shared_ptr &ability) + {} + virtual void OnAbilityStop(const std::shared_ptr &ability) + {} + virtual void OnAbilitySaveState(const OHOS::AppExecFwk::PacMap &outState) + {} +}; +class WantSender : public OHOS::AAFwk::WantSenderStub { +public: + void Send(OHOS::AAFwk::SenderInfo &senderInfo) override + {} +}; +} // namespace Notification +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/resource/notificationfuzztest/notificationfuzzconfig/config.json b/test/resource/notificationfuzztest/notificationfuzzconfig/config.json new file mode 100644 index 000000000..ec41e6311 --- /dev/null +++ b/test/resource/notificationfuzztest/notificationfuzzconfig/config.json @@ -0,0 +1,153 @@ +{ + "flag": 10, + "NotificationSubscriber": { + "OnCanceledNotification": [], + "OnCanceledNotificationNotificationSortingMapint": [], + "OnSubscribeResult": [], + "OnConsumedNotification": [], + "OnConsumedNotificationNotificationSortingMap": [], + "OnUnsubscribeResultNotificationConstantSubscribeResult": [], + "OnUpdate": [], + "OnDied": [] + }, + "NotificationSubscribeInfo": { + "AddAppName": [], + "AddAppNames": [], + "GetAppNames": [] + }, + "NotificationSorting": { + "GetRanking": [], + "GetKey": [], + "GetImportance": [], + "GetSlot": [], + "GetVisiblenessOverride": [], + "IsDisplayBadge": [], + "IsHiddenNotification": [], + "GetGroupKeyOverride": [] + }, + "NotificationSortingMap": { + "GetKey": [], + "GetNotificationSorting": [] + }, + "NotificationHelper": { + "AddNotificationSlot": [], + "AddSlotByType": [], + "AddNotificationSlots": [], + "RemoveNotificationSlot": [], + "RemoveAllSlots": [], + "GetNotificationSlot": [], + "GetNotificationSlots": [], + "AddNotificationSlotGroup": [], + "AddNotificationSlotGroups": [], + "RemoveNotificationSlotGroup": [], + "GetNotificationSlotGroup": [], + "GetNotificationSlotGroups": [], + "GetNotificationSlotNumAsBundle": [], + "PublishNotificationNotificationRequest": [], + "PublishNotificationstringNotificationRequest": [], + "PublishNotificationNotificationRequeststring": [], + "CancelNotificationint32_t": [], + "CancelNotificationstringint32_t": [], + "CancelAllNotifications": [], + "GetActiveNotificationNums": [], + "GetActiveNotifications": [], + "GetCurrentAppSorting": [], + "SetNotificationAgent": [], + "GetNotificationAgent": [], + "CanPublishNotificationAsBundle": [], + "PublishNotificationAsBundle": [], + "SetNotificationBadgeNum": [], + "SetNotificationBadgeNumint32_t": [], + "IsAllowedNotifybool": [], + "AreNotificationsSuspended": [], + "HasNotificationPolicyAccessPermission": [], + "GetBundleImportance": [], + "SubscribeNotificationNotificationSubscriber": [], + "SubscribeNotificationNotificationSubscriberNotificationSubscribeInfo": [], + "UnSubscribeNotificationNotificationSubscriber": [], + "UnSubscribeNotificationNotificationSubscriberNotificationSubscribeInfo": [], + "RemoveNotificationstring": [], + "RemoveNotificationNotificationBundleOptionint32_tstring": [], + "RemoveAllNotifications": [], + "RemoveNotificationsByBundle": [], + "RemoveNotifications": [], + "GetNotificationSlotsForBundle": [], + "UpdateNotificationSlots": [], + "UpdateNotificationSlotGroups": [], + "GetAllActiveNotificationsNotification": [], + "GetAllActiveNotificationsstringNotification": [], + "IsAllowedNotify": [], + "SetNotificationsEnabledForAllBundles": [], + "SetNotificationsEnabledForDefaultBundle": [], + "SetNotificationsEnabledForSpecifiedBundle": [], + "SetShowBadgeEnabledForBundle": [], + "GetShowBadgeEnabledForBundle": [], + "GetShowBadgeEnabled": [], + "SetDisturbMode": [], + "GetDisturbMode": [] + }, + "WantAgentHelper": { + "GetWantAgentOHOSAppExecFwkContextWantAgentInfo": [], + "GetWantAgentWantAgentInfo": [], + "GetType": [], + "TriggerWantAgent": [], + "Cancel": [], + "JudgeEquality": [], + "GetHashCode": [], + "GetBundleName": [], + "GetUid": [], + "GetWant": [], + "RegisterCancelListener": [], + "UnregisterCancelListener": [] + }, + "LauncherService": { + "GetAbilityList": [], + "GetAbilityInfo": [], + "GetApplicationInfo": [], + "IsBundleEnabled": [], + "IsAbilityEnabled": [], + "GetShortcutInfos": [], + "RegisterCallback": [], + "UnRegisterCallback": [] + }, + "IAbilityContinuation": { + "OnStartContinuation": [], + "OnSaveData": [], + "OnRestoreData": [], + "OnCompleteContinuation": [] + }, + "Ability": { + "StartAbility": [], + "OnRequestPermissionsFromUserResult": [] + }, + "AbilityContext": { + "StartAbility": [] + }, + "Context": { + "VerifyPermission": [], + "VerifyCallingPermission": [], + "VerifySelfPermission": [], + "VerifyCallingOrSelfPermission": [], + "CanRequestPermission": [], + "RequestPermissionsFromUser": [], + "MoveMissionToEnd": [], + "SetMissionInformation": [], + "LockMission": [], + "UnlockMission": [], + "GetMissionId": [], + "GetUITaskDispatcher": [], + "GetMainTaskDispatcher": [], + "CreateParallelTaskDispatcher": [], + "CreateSerialTaskDispatcher": [], + "GetGlobalTaskDispatcher": [] + }, + "AbilityLifecycleCallbacks": { + "OnAbilityActive": [] + }, + "IAbilityManager": { + "MoveMissionToEnd": [], + "IsFirstInMission": [], + "PowerOn": [], + "PowerOff": [] + } +} \ No newline at end of file diff --git a/test/resource/notificationfuzztest/ohos_test.xml b/test/resource/notificationfuzztest/ohos_test.xml new file mode 100644 index 000000000..a2f6e1d46 --- /dev/null +++ b/test/resource/notificationfuzztest/ohos_test.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp new file mode 100644 index 000000000..8136a61a8 --- /dev/null +++ b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp @@ -0,0 +1,923 @@ +/* + * Copyright (c) 2021 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. + */ +#define private public +#define protected public + +#include "../include/notificationgetparam.h" +#include "../include/notificationfuzztestmanager.h" +#include "../include/notificationfuzzconfigparser.h" +#include "datetime_ex.h" + +#undef private +#undef protected +using namespace OHOS::AppExecFwk; +using namespace OHOS::EventFwk; +namespace OHOS { +namespace Notification { +std::shared_ptr fuzzTestManager::instance_ = nullptr; +// RegisterNotificationHelper +void fuzzTestManager::RegisterNotificationHelper() +{ + callFunctionMap_.emplace("NotificationHelperAddNotificationSlot", + []() { OHOS::Notification::NotificationHelper::AddNotificationSlot(*GetParamNotificationSlot()); }); + + callFunctionMap_.emplace("NotificationHelperAddSlotByType", + []() { OHOS::Notification::NotificationHelper::AddSlotByType(GetParamSlotType()); }); + + callFunctionMap_.emplace("NotificationHelperAddNotificationSlots", + []() { OHOS::Notification::NotificationHelper::AddNotificationSlots(GetParamNotificationSlotVector()); }); + + callFunctionMap_.emplace("NotificationHelperRemoveNotificationSlot", + []() { OHOS::Notification::NotificationHelper::RemoveNotificationSlot(GetParamSlotType()); }); + + callFunctionMap_.emplace( + "NotificationHelperRemoveAllSlots", []() { OHOS::Notification::NotificationHelper::RemoveAllSlots(); }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationSlot", []() { + sptr param = GetParamNotificationSlotSptr(); + OHOS::Notification::NotificationHelper::GetNotificationSlot(GetParamSlotType(), param); + }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationSlots", []() { + std::vector> param = GetParamNotificationSlotSptrVector(); + OHOS::Notification::NotificationHelper::GetNotificationSlots(param); + }); + + callFunctionMap_.emplace("NotificationHelperAddNotificationSlotGroup", + []() { OHOS::Notification::NotificationHelper::AddNotificationSlotGroup(*GetParamNotificationSlotGroup()); }); + + callFunctionMap_.emplace("NotificationHelperAddNotificationSlotGroups", []() { + OHOS::Notification::NotificationHelper::AddNotificationSlotGroups(GetParamNotificationSlotGroupVector()); + }); + + callFunctionMap_.emplace("NotificationHelperRemoveNotificationSlotGroup", + []() { OHOS::Notification::NotificationHelper::RemoveNotificationSlotGroup(GetStringParam()); }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationSlotGroup", []() { + sptr param = GetParamNotificationSlotGroup(); + OHOS::Notification::NotificationHelper::GetNotificationSlotGroup(GetStringParam(), param); + }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationSlotGroups", []() { + std::vector> param = GetParamNotificationSlotGroupSptrVector(); + OHOS::Notification::NotificationHelper::GetNotificationSlotGroups(param); + }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationSlotNumAsBundle", []() { + int param = GetIntParam(); + OHOS::Notification::NotificationHelper::GetNotificationSlotNumAsBundle( + *GetParamNotificationBundleOption(), param); + }); + + callFunctionMap_.emplace("NotificationHelperPublishNotificationNotificationRequest", + []() { OHOS::Notification::NotificationHelper::PublishNotification(*GetParamNotificationRequest()); }); + + callFunctionMap_.emplace("NotificationHelperPublishNotificationstringNotificationRequest", []() { + OHOS::Notification::NotificationHelper::PublishNotification(GetStringParam(), *GetParamNotificationRequest()); + }); + + callFunctionMap_.emplace("NotificationHelperPublishNotificationNotificationRequeststring", []() { + OHOS::Notification::NotificationHelper::PublishNotification(*GetParamNotificationRequest(), GetStringParam()); + }); + + callFunctionMap_.emplace("NotificationHelperCancelNotificationint32_t", + []() { OHOS::Notification::NotificationHelper::CancelNotification(GetS32Param()); }); + + callFunctionMap_.emplace("NotificationHelperCancelNotificationstringint32_t", + []() { OHOS::Notification::NotificationHelper::CancelNotification(GetStringParam(), GetS32Param()); }); + + callFunctionMap_.emplace("NotificationHelperCancelAllNotifications", + []() { OHOS::Notification::NotificationHelper::CancelAllNotifications(); }); + + callFunctionMap_.emplace("NotificationHelperGetActiveNotificationNums", []() { + int32_t notificationId = GetS32Param(); + OHOS::Notification::NotificationHelper::GetActiveNotificationNums(notificationId); + }); + + callFunctionMap_.emplace("NotificationHelperGetActiveNotifications", []() { + std::vector> param = GetParamNotificationRequestVector(); + OHOS::Notification::NotificationHelper::GetActiveNotifications(param); + }); + + callFunctionMap_.emplace("NotificationHelperGetCurrentAppSorting", []() { + sptr sortingMap = GetParamNotificationSortingMapSptr(); + OHOS::Notification::NotificationHelper::GetCurrentAppSorting(sortingMap); + }); + + callFunctionMap_.emplace("NotificationHelperSetNotificationAgent", + []() { OHOS::Notification::NotificationHelper::SetNotificationAgent(GetStringParam()); }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationAgent", []() { + std::string agent = GetStringParam(); + OHOS::Notification::NotificationHelper::GetNotificationAgent(agent); + }); + + callFunctionMap_.emplace("NotificationHelperCanPublishNotificationAsBundle", []() { + bool canPublish = GetBoolParam(); + OHOS::Notification::NotificationHelper::CanPublishNotificationAsBundle(GetStringParam(), canPublish); + }); + + callFunctionMap_.emplace("NotificationHelperPublishNotificationAsBundle", []() { + OHOS::Notification::NotificationHelper::PublishNotificationAsBundle( + GetStringParam(), *GetParamNotificationRequest()); + }); + + callFunctionMap_.emplace("NotificationHelperSetNotificationBadgeNum", + []() { OHOS::Notification::NotificationHelper::SetNotificationBadgeNum(); }); + + callFunctionMap_.emplace("NotificationHelperSetNotificationBadgeNumint32_t", []() { + int32_t num = GetS32Param(); + OHOS::Notification::NotificationHelper::SetNotificationBadgeNum(num); + }); + + callFunctionMap_.emplace("NotificationHelperIsAllowedNotify", []() { + bool allowed = GetBoolParam(); + OHOS::Notification::NotificationHelper::IsAllowedNotify(allowed); + }); + + callFunctionMap_.emplace("NotificationHelperAreNotificationsSuspended", []() { + bool suspended = GetBoolParam(); + OHOS::Notification::NotificationHelper::AreNotificationsSuspended(suspended); + }); + + callFunctionMap_.emplace("NotificationHelperHasNotificationPolicyAccessPermission", []() { + bool hasPermission = GetBoolParam(); + OHOS::Notification::NotificationHelper::HasNotificationPolicyAccessPermission(hasPermission); + }); + + callFunctionMap_.emplace("NotificationHelperGetBundleImportance", []() { + OHOS::Notification::NotificationSlot::NotificationLevel importance = GetParamNotificationLevel(); + OHOS::Notification::NotificationHelper::GetBundleImportance(importance); + }); + + callFunctionMap_.emplace("NotificationHelperSubscribeNotificationNotificationSubscriber", []() { + TestAnsSubscriber::mutex_.lock(); + std::shared_ptr subscriber = GetParamNotificationSubscriber(); + struct tm start = {0}; + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber); + struct tm end = {0}; + int64_t timeout = 0; + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex_.lock(); + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber); + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + }); + + callFunctionMap_.emplace( + "NotificationHelperSubscribeNotificationNotificationSubscriberNotificationSubscribeInfo", []() { + TestAnsSubscriber::mutex_.lock(); + std::shared_ptr subscriber = GetParamNotificationSubscriber(); + std::shared_ptr subscribeInfo = + GetParamNotificationSubscribeInfo(); + struct tm start = {0}; + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber, *subscribeInfo); + struct tm end = {0}; + int64_t timeout = 0; + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex_.lock(); + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber, *subscribeInfo); + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + }); + + callFunctionMap_.emplace("NotificationHelperUnSubscribeNotificationNotificationSubscriber", []() { + TestAnsSubscriber::mutex_.lock(); + std::shared_ptr subscriber = GetParamNotificationSubscriber(); + struct tm start = {0}; + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber); + struct tm end = {0}; + int64_t timeout = 0; + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex_.lock(); + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber); + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + }); + + callFunctionMap_.emplace( + "NotificationHelperUnSubscribeNotificationNotificationSubscriberNotificationSubscribeInfo", []() { + TestAnsSubscriber::mutex_.lock(); + std::shared_ptr subscriber = GetParamNotificationSubscriber(); + std::shared_ptr subscribeInfo = + GetParamNotificationSubscribeInfo(); + struct tm start = {0}; + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber, *subscribeInfo); + struct tm end = {0}; + int64_t timeout = 0; + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex_.lock(); + OHOS::GetSystemCurrentTime(&start); + OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber, *subscribeInfo); + while (!TestAnsSubscriber::mutex_.try_lock()) { + OHOS::GetSystemCurrentTime(&end); + timeout = OHOS::GetSecondsBetween(start, end); + if (timeout >= 5L) { + break; + } + } + TestAnsSubscriber::mutex_.unlock(); + }); + + callFunctionMap_.emplace("NotificationHelperRemoveNotificationstring", + []() { OHOS::Notification::NotificationHelper::RemoveNotification(GetStringParam()); }); + + callFunctionMap_.emplace("NotificationHelperRemoveNotificationNotificationBundleOptionint32_tstring", []() { + OHOS::Notification::NotificationHelper::RemoveNotification( + *GetParamNotificationBundleOption(), GetS32Param(), GetStringParam()); + }); + + callFunctionMap_.emplace("NotificationHelperRemoveAllNotifications", + []() { OHOS::Notification::NotificationHelper::RemoveAllNotifications(*GetParamNotificationBundleOption()); }); + + callFunctionMap_.emplace("NotificationHelperRemoveNotifications", + []() { OHOS::Notification::NotificationHelper::RemoveNotifications(); }); + + callFunctionMap_.emplace("NotificationHelperRemoveNotificationsByBundle", []() { + OHOS::Notification::NotificationHelper::RemoveNotificationsByBundle(*GetParamNotificationBundleOption()); + }); + + callFunctionMap_.emplace("NotificationHelperGetNotificationSlotsForBundle", []() { + std::vector> param = GetParamNotificationSlotSptrVector(); + OHOS::Notification::NotificationHelper::GetNotificationSlotsForBundle( + *GetParamNotificationBundleOption(), param); + }); + + callFunctionMap_.emplace("NotificationHelperUpdateNotificationSlots", []() { + OHOS::Notification::NotificationHelper::UpdateNotificationSlots( + *GetParamNotificationBundleOption(), GetParamNotificationSlotSptrVector()); + }); + + callFunctionMap_.emplace("NotificationHelperUpdateNotificationSlotGroups", []() { + OHOS::Notification::NotificationHelper::UpdateNotificationSlotGroups( + *GetParamNotificationBundleOption(), GetParamNotificationSlotGroupSptrVector()); + }); + + callFunctionMap_.emplace("NotificationHelperGetAllActiveNotificationsvectorsptrNotification", []() { + std::vector> notification = GetParamNotificationSptrVector(); + OHOS::Notification::NotificationHelper::GetAllActiveNotifications(notification); + }); + + callFunctionMap_.emplace("NotificationHelperGetAllActiveNotificationsstringNotification", []() { + std::vector> notification = GetParamNotificationSptrVector(); + OHOS::Notification::NotificationHelper::GetAllActiveNotifications(GetStringVectorParam(), notification); + }); + + callFunctionMap_.emplace("NotificationHelperIsAllowedNotify", []() { + bool param = GetBoolParam(); + OHOS::Notification::NotificationHelper::IsAllowedNotify(*GetParamNotificationBundleOption(), param); + }); + + callFunctionMap_.emplace("NotificationHelperSetNotificationsEnabledForAllBundles", []() { + OHOS::Notification::NotificationHelper::SetNotificationsEnabledForAllBundles(GetStringParam(), GetBoolParam()); + }); + + callFunctionMap_.emplace("NotificationHelperSetNotificationsEnabledForDefaultBundle", []() { + OHOS::Notification::NotificationHelper::SetNotificationsEnabledForDefaultBundle( + GetStringParam(), GetBoolParam()); + }); + + callFunctionMap_.emplace("NotificationHelperSetNotificationsEnabledForSpecifiedBundle", []() { + std::string param = GetStringParam(); + OHOS::Notification::NotificationHelper::SetNotificationsEnabledForSpecifiedBundle( + *GetParamNotificationBundleOption(), param, GetBoolParam()); + }); + + callFunctionMap_.emplace("NotificationHelperSetShowBadgeEnabledForBundle", []() { + OHOS::Notification::NotificationHelper::SetShowBadgeEnabledForBundle( + *GetParamNotificationBundleOption(), GetBoolParam()); + }); + + callFunctionMap_.emplace("NotificationHelperGetShowBadgeEnabledForBundle", []() { + bool param = GetBoolParam(); + OHOS::Notification::NotificationHelper::GetShowBadgeEnabledForBundle( + *GetParamNotificationBundleOption(), param); + }); + + callFunctionMap_.emplace("NotificationHelperGetShowBadgeEnabled", []() { + bool param = GetBoolParam(); + OHOS::Notification::NotificationHelper::GetShowBadgeEnabled(param); + }); + + callFunctionMap_.emplace("NotificationHelperSetDisturbMode", + []() { OHOS::Notification::NotificationHelper::SetDisturbMode(GetParamDisturbMode()); }); + + callFunctionMap_.emplace("NotificationHelperGetDisturbMode", []() { + OHOS::Notification::NotificationConstant::DisturbMode param = GetParamDisturbMode(); + OHOS::Notification::NotificationHelper::GetDisturbMode(param); + }); +} + +// RegisterNotificationSorting +void fuzzTestManager::RegisterNotificationSorting() +{ + callFunctionMap_.emplace("NotificationSortingGetRanking", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->GetRanking(); + }); + + callFunctionMap_.emplace("NotificationSortingGetKey", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->GetKey(); + }); + + callFunctionMap_.emplace("NotificationSortingGetImportance", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->GetImportance(); + }); + + callFunctionMap_.emplace("NotificationSortingGetSlot", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->GetSlot(); + }); + + callFunctionMap_.emplace("NotificationSortingGetVisiblenessOverride", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->GetVisiblenessOverride(); + }); + + callFunctionMap_.emplace("NotificationSortingIsDisplayBadge", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->IsDisplayBadge(); + }); + + callFunctionMap_.emplace("NotificationSortingIsHiddenNotification", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->IsHiddenNotification(); + }); + + callFunctionMap_.emplace("NotificationSortingGetGroupKeyOverride", []() { + std::shared_ptr temp = GetParamNotificationSorting(); + temp->GetGroupKeyOverride(); + }); +} + +// RegisterNotificationSortingMap +void fuzzTestManager::RegisterNotificationSortingMap() +{ + callFunctionMap_.emplace("NotificationSortingMapGetKey", []() { + std::shared_ptr temp = GetParamNotificationSortingMap(); + temp->GetKey(); + }); + + callFunctionMap_.emplace("NotificationSortingMapGetNotificationSorting", []() { + std::shared_ptr temp = GetParamNotificationSortingMap(); + const std::string key = GetStringParam(); + OHOS::Notification::NotificationSorting sorting = *(GetParamNotificationSorting().get()); + temp->GetNotificationSorting(key, sorting); + }); +} + +// RegisterNotificationSubscribeInfo +void fuzzTestManager::RegisterNotificationSubscribeInfo() +{ + callFunctionMap_.emplace("NotificationSubscribeInfoAddAppName", []() { + std::shared_ptr temp = GetParamNotificationSubscribeInfo(); + std::string appName = GetStringParam(); + temp->AddAppName(appName); + }); + + callFunctionMap_.emplace("NotificationSubscribeInfoAddAppNames", []() { + std::shared_ptr temp = GetParamNotificationSubscribeInfo(); + const std::vector appNames = GetStringVectorParam(); + temp->AddAppNames(appNames); + }); + + callFunctionMap_.emplace("NotificationSubscribeInfoGetAppNames", []() { + std::shared_ptr temp = GetParamNotificationSubscribeInfo(); + temp->GetAppNames(); + }); +} + +// RegisterNotificationSubscriber +void fuzzTestManager::RegisterNotificationSubscriber() +{ + callFunctionMap_.emplace("NotificationSubscriberOnCanceledNotification", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + temp->OnCanceled(GetParamNotification()); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnCanceledNotificationNotificationSortingMapdeleteReason", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + const std::shared_ptr request = GetParamNotification(); + const std::shared_ptr sortingMap = GetParamNotificationSortingMap(); + int deleteReason = GetIntParam(); + temp->OnCanceled(request, sortingMap, deleteReason); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnSubscribeResult", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + OHOS::Notification::NotificationConstant::SubscribeResult result = GetParamSubscribeResult(); + temp->OnSubscribeResult(result); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnConsumedNotification", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + const std::shared_ptr request = GetParamNotification(); + temp->OnConsumed(request); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnConsumedNotificationNotificationSortingMap", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + std::shared_ptr request = GetParamNotification(); + std::shared_ptr sortingMap = GetParamNotificationSortingMap(); + temp->OnConsumed(request, sortingMap); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnUnsubscribeResult", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + OHOS::Notification::NotificationConstant::SubscribeResult result = GetParamSubscribeResult(); + temp->OnUnsubscribeResult(result); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnUpdate", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + const std::shared_ptr sortingMap = GetParamNotificationSortingMap(); + temp->OnUpdate(sortingMap); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnDied", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + temp->OnDied(); + }); + + callFunctionMap_.emplace("NotificationSubscriberOnDisturbModeChanged", []() { + std::shared_ptr temp = GetParamNotificationSubscriber(); + int disturbMode = GetIntParam(); + temp->OnDisturbModeChanged(disturbMode); + }); +} + +// RegisterWantAgentHelper +void fuzzTestManager::RegisterWantAgentHelper() +{ + callFunctionMap_.emplace("WantAgentHelperGetWantAgentAppExecFwkparamsInfo", []() { + const std::shared_ptr context = GetParamContext(); + const OHOS::Notification::WantAgent::WantAgentInfo paramsInfo = *GetParamWantAgentInfo(); + OHOS::Notification::WantAgent::WantAgentHelper::GetWantAgent(context, paramsInfo); + }); + + callFunctionMap_.emplace("WantAgentHelperGetWantAgentparamsInfo", []() { + const OHOS::Notification::WantAgent::WantAgentInfo paramsInfo = *GetParamWantAgentInfo(); + OHOS::Notification::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + }); + + callFunctionMap_.emplace("WantAgentHelperGetType", []() { + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::GetType(agent); + }); + + callFunctionMap_.emplace("WantAgentHelperTriggerWantAgent", []() { + const std::shared_ptr context; + const std::shared_ptr agent = GetParamWantAgent(); + const std::shared_ptr callback = GetParamCompletedCallback(); + OHOS::Notification::WantAgent::TriggerInfo paramsInfo(*GetParamTriggerInfo()); + OHOS::Notification::WantAgent::WantAgentHelper::TriggerWantAgent(context, agent, callback, paramsInfo); + }); + + callFunctionMap_.emplace("WantAgentHelperCancel", []() { + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::Cancel(agent); + }); + + callFunctionMap_.emplace("WantAgentHelperJudgeEquality", []() { + const std::shared_ptr agent = GetParamWantAgent(); + const std::shared_ptr otherAgent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::JudgeEquality(agent, otherAgent); + }); + callFunctionMap_.emplace("WantAgentHelperGetHashCode", []() { + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::GetHashCode(agent); + }); + + callFunctionMap_.emplace("WantAgentHelperGetBundleName", []() { + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::GetBundleName(agent); + }); + + callFunctionMap_.emplace("WantAgentHelperGetUid", []() { + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::GetUid(agent); + }); + + callFunctionMap_.emplace("WantAgentHelperGetWant", []() { + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::GetWant(agent); + }); + + callFunctionMap_.emplace("WantAgentHelperRegisterCancelListener", []() { + const std::shared_ptr cancelListener; + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::RegisterCancelListener(cancelListener, agent); + }); + + callFunctionMap_.emplace("WantAgentHelperUnregisterCancelListener", []() { + const std::shared_ptr cancelListener = GetParamCancelListener(); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::Notification::WantAgent::WantAgentHelper::UnregisterCancelListener(cancelListener, agent); + }); +} + +// RegisterLauncherService +void fuzzTestManager::RegisterLauncherService() +{ + callFunctionMap_.emplace("LauncherServiceGetAbilityList", []() { + std::shared_ptr temp = GetParamLauncherService(); + const std::string bundleName = GetStringParam(); + const int userId = GetIntParam(); + std::vector launcherAbilityInfos = GetParamLauncherAbilityInfoVector(); + temp->GetAbilityList(bundleName, userId, launcherAbilityInfos); + }); + + callFunctionMap_.emplace("LauncherServiceGetAbilityInfo", []() { + std::shared_ptr temp = GetParamLauncherService(); + const Want want = *GetParamWant(); + const int userI = GetIntParam(); + OHOS::AppExecFwk::LauncherAbilityInfo launcherAbilityInfo = *GetParamLauncherAbilityInfo(); + temp->GetAbilityInfo(want, userI, launcherAbilityInfo); + }); + + callFunctionMap_.emplace("LauncherServiceGetApplicationInfo", []() { + std::shared_ptr temp = GetParamLauncherService(); + const std::string bundleName = GetStringParam(); + const ApplicationFlag flags = GetParamApplicationFlag(); + const int userId = GetIntParam(); + ApplicationInfo applicationInfo = GetParamApplicationInfo(); + temp->GetApplicationInfo(bundleName, flags, userId, applicationInfo); + }); + + callFunctionMap_.emplace("LauncherServiceIsBundleEnabled", []() { + std::shared_ptr temp = GetParamLauncherService(); + const std::string bundleName = GetStringParam(); + temp->IsBundleEnabled(bundleName); + }); + + callFunctionMap_.emplace("LauncherServiceIsAbilityEnabled", []() { + std::shared_ptr temp = GetParamLauncherService(); + const OHOS::AppExecFwk::AbilityInfo abilityInfo = GetParamAbilityInfo(); + temp->IsAbilityEnabled(abilityInfo); + }); + + callFunctionMap_.emplace("LauncherServiceGetShortcutInfos", []() { + std::shared_ptr temp = GetParamLauncherService(); + const std::string bundleName = GetStringParam(); + std::vector launcherShortcutInfo = GetParamLauncherShortcutInfoVector(); + temp->GetShortcutInfos(bundleName, launcherShortcutInfo); + }); + + callFunctionMap_.emplace("LauncherServiceRegisterCallback", []() { + std::shared_ptr temp = GetParamLauncherService(); + const sptr callback = GetParamIBundleStatusCallback(); + temp->RegisterCallback(callback); + }); + + callFunctionMap_.emplace("LauncherServiceUnRegisterCallback", []() { + std::shared_ptr temp = GetParamLauncherService(); + temp->UnRegisterCallback(); + }); +} + +// RegisterIAbilityContinuation +void fuzzTestManager::RegisterIAbilityContinuation() +{ + callFunctionMap_.emplace("IAbilityContinuationOnStartContinuation", []() { + std::shared_ptr temp = GetParamAbility(); + temp->OnStartContinuation(); + }); + + callFunctionMap_.emplace("IAbilityContinuationOnSaveData", []() { + std::shared_ptr temp = GetParamAbility(); + WantParams saveData = *GetParamWantParams(); + temp->OnSaveData(saveData); + }); + + callFunctionMap_.emplace("IAbilityContinuationOnRestoreData", []() { + std::shared_ptr temp = GetParamAbility(); + OHOS::AppExecFwk::WantParams restoreData = *GetParamWantParams(); + temp->OnRestoreData(restoreData); + }); + + callFunctionMap_.emplace("IAbilityContinuationOnCompleteContinuation", []() { + std::shared_ptr temp = GetParamAbility(); + int result = GetIntParam(); + temp->OnCompleteContinuation(result); + }); +} + +// RegisterAbility_ +void fuzzTestManager::RegisterAbility_() +{ + callFunctionMap_.emplace("AbilityOnRequestPermissionsFromUserResult", []() { + std::shared_ptr temp = GetParamAbility(); + int requestCode = GetIntParam(); + const std::vector permissions = GetStringVectorParam(); + const std::vector grantResults = GetIntVectorParam(); + temp->OnRequestPermissionsFromUserResult(requestCode, permissions, grantResults); + }); + + callFunctionMap_.emplace("AbilityStartAbility", []() { + std::shared_ptr temp = GetParamAbility(); + const Want want = *GetParamWant(); + temp->StartAbility(want); + }); +} + +// RegisterAbilityContext_ +void fuzzTestManager::RegisterAbilityContext_() +{ + callFunctionMap_.emplace("AbilityStartAbility", []() { + std::shared_ptr temp = GetParamAbility(); + const AAFwk::Want want = *GetParamWant(); + int requestCode = GetIntParam(); + temp->StartAbility(want, requestCode); + }); +} + +// RegisterContext +void fuzzTestManager::RegisterContext() +{ + callFunctionMap_.emplace("ContextVerifyPermission", []() { + std::shared_ptr temp = GetParamContext(); + const std::string permission = GetStringParam(); + int pid = GetIntParam(); + int uid = GetIntParam(); + temp->VerifyPermission(permission, pid, uid); + }); + + callFunctionMap_.emplace("ContextVerifyCallingPermission", []() { + std::shared_ptr temp = GetParamContext(); + const std::string permission = GetStringParam(); + temp->VerifyCallingPermission(permission); + }); + + callFunctionMap_.emplace("ContextVerifySelfPermission", []() { + std::shared_ptr temp = GetParamContext(); + const std::string permission = GetStringParam(); + temp->VerifySelfPermission(permission); + }); + + callFunctionMap_.emplace("ContextVerifyCallingOrSelfPermission", []() { + std::shared_ptr temp = GetParamContext(); + temp->VerifyCallingOrSelfPermission(GetStringParam()); + }); + + callFunctionMap_["ContextCanRequestPermission"] = []() { + std::shared_ptr temp = GetParamContext(); + const std::string permission = GetStringParam(); + temp->CanRequestPermission(permission); + }; + + callFunctionMap_["ContextRequestPermissionsFromUser"] = []() { + std::shared_ptr temp = GetParamContext(); + std::vector permissions = GetStringVectorParam(); + int requestCode = GetIntParam(); + temp->RequestPermissionsFromUser(permissions, requestCode); + }; + + callFunctionMap_["ContextMoveMissionToEnd"] = []() { + std::shared_ptr temp = GetParamContext(); + bool nonFirst = GetBoolParam(); + temp->MoveMissionToEnd(nonFirst); + }; + + callFunctionMap_["ContextSetMissionInformation"] = []() { + std::shared_ptr temp = GetParamContext(); + const MissionInformation missionInformation = GetParamMissionInformation(); + temp->SetMissionInformation(missionInformation); + }; + + callFunctionMap_["ContextSetLockMission"] = []() { + std::shared_ptr temp = GetParamContext(); + temp->LockMission(); + }; + + callFunctionMap_["ContextUnlockMission"] = []() { + std::shared_ptr temp = GetParamContext(); + temp->UnlockMission(); + }; + + callFunctionMap_["ContextGetMissionId"] = []() { + std::shared_ptr temp = GetParamContext(); + temp->GetMissionId(); + }; + + callFunctionMap_["ContextGetUITaskDispatcher"] = []() { + std::shared_ptr temp = GetParamContext(); + temp->GetUITaskDispatcher(); + }; + + callFunctionMap_["ContextGetMainTaskDispatcher"] = []() { + std::shared_ptr temp = GetParamContext(); + temp->GetMainTaskDispatcher(); + }; + + callFunctionMap_["ContextCreateParallelTaskDispatcher"] = []() { + std::shared_ptr temp = GetParamContext(); + const std::string name = GetStringParam(); + const TaskPriority priority = GetParamTaskPriority(); + temp->CreateParallelTaskDispatcher(name, priority); + }; + + callFunctionMap_["ContextCreateSerialTaskDispatcher"] = []() { + std::shared_ptr temp = GetParamContext(); + const std::string name = GetStringParam(); + const TaskPriority priority = GetParamTaskPriority(); + temp->CreateSerialTaskDispatcher(name, priority); + }; + + callFunctionMap_["ContextGetGlobalTaskDispatcher"] = []() { + std::shared_ptr temp = GetParamContext(); + const TaskPriority priority = GetParamTaskPriority(); + temp->GetGlobalTaskDispatcher(priority); + }; +} + +// RegisterAbilityLifecycleCallbacks +void fuzzTestManager::RegisterAbilityLifecycleCallbacks() +{ + callFunctionMap_.emplace("AbilityLifecycleCallbacksOnAbilityActive", []() { + std::shared_ptr temp = GetParamAbilityLifecycleCallbacks(); + const std::shared_ptr ability = GetParamAbility(); + temp->OnAbilityActive(ability); + }); +} + +// RegisterIAbilityManager +void fuzzTestManager::RegisterIAbilityManager() +{ + callFunctionMap_.emplace("IAbilityManagerMoveMissionToEnd", []() { + std::shared_ptr temp = GetParamIAbilityManager(); + const sptr token = GetParamSptrRemote(); + const bool nonFirs = GetBoolParam(); + temp->MoveMissionToEnd(token, nonFirs); + }); + + callFunctionMap_.emplace("IAbilityManagerIsFirstInMission", []() { + std::shared_ptr temp = GetParamIAbilityManager(); + const sptr token = GetParamSptrRemote(); + temp->IsFirstInMission(token); + }); + + callFunctionMap_.emplace("IAbilityManagerPowerOn", []() { + std::shared_ptr temp = GetParamIAbilityManager(); + temp->PowerOn(); + }); + + callFunctionMap_.emplace("IAbilityManagerPowerOff", []() { + std::shared_ptr temp = GetParamIAbilityManager(); + temp->PowerOff(); + }); +} + +fuzzTestManager::fuzzTestManager() +{ + RegisterNotificationHelper(); + RegisterNotificationSorting(); + RegisterNotificationSortingMap(); + RegisterNotificationSubscribeInfo(); + RegisterNotificationSubscriber(); + RegisterWantAgentHelper(); + RegisterLauncherService(); + RegisterIAbilityContinuation(); + RegisterAbility_(); + RegisterAbilityContext_(); + RegisterContext(); + RegisterAbilityLifecycleCallbacks(); + RegisterIAbilityManager(); +} + +void fuzzTestManager::SetJsonFunction(std::string functionName) +{ + remainderMap_.emplace(functionName, cycle_); +} + +void fuzzTestManager::SetCycle(uint16_t cycle) +{ + cycle_ = cycle; + for_each(remainderMap_.begin(), remainderMap_.end(), [cycle](std::unordered_map::reference temp) { + temp.second = cycle; + }); +} + +int GetRandomInt(int minNum, int maxNum) +{ + return GetU16Param() % (maxNum - minNum + 1) + minNum; +} + +void action(int a) +{ + std::cout << "Interrupt signal (" << a << ") received.\n"; +} + +void fuzzTestManager::StartFuzzTest() +{ + std::cout << __func__ << std::endl; + OHOS::FuzzConfigParser jsonParser; + OHOS::FuzzTestData tempData; + + std::cout << "parseFromFile start" << std::endl; + jsonParser.ParseFromFile4FuzzTest(FUZZ_TEST_CONFIG_FILE_PATH, tempData); + std::cout << "flag :" << tempData.mainLoopFlag << std::endl; + for_each(tempData.methodVec.begin(), tempData.methodVec.end(), [this](std::vector::reference s) { + SetJsonFunction(s); + }); + SetCycle(tempData.mainLoopFlag); + + std::vector index; + std::unordered_map::iterator it = remainderMap_.begin(); + while (it != remainderMap_.end()) { + if (it->second <= 0) { + it = remainderMap_.erase(it); + } else { + index.push_back(it->first); + it++; + } + } + + std::cout << remainderMap_.size() << "--------fuzz test start1111--------" << callFunctionMap_.size() << std::endl; + for (; remainderMap_.size() > 0;) { + std::string functionName; + int offset = GetRandomInt(0, index.size() - 1); + functionName = index[offset]; + if (callFunctionMap_.find(functionName) != callFunctionMap_.end()) { + std::cout << "call function : " << functionName << std::endl; + callFunctionMap_[functionName](); + std::cout << "function end :" << functionName << std::endl; + } else { + std::cout << "can't find function : " << functionName << std::endl; + } + remainderMap_[functionName]--; + if (remainderMap_[functionName] <= 0) { + remainderMap_.erase(functionName); + index.erase(index.begin() + offset); + }; + } + std::cout << remainderMap_.size() << "--------fuzz test end--------" << std::endl; +} +} // namespace Notification +} // namespace OHOS diff --git a/test/resource/notificationfuzztest/src/notificationgetparam.cpp b/test/resource/notificationfuzztest/src/notificationgetparam.cpp new file mode 100644 index 000000000..87af6a69d --- /dev/null +++ b/test/resource/notificationfuzztest/src/notificationgetparam.cpp @@ -0,0 +1,1433 @@ +/* + * Copyright (c) 2021 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/notificationgetparam.h" +#include +#include +#include +#include +#include +#include "abs_shared_result_set.h" +#include "data_ability_predicates.h" +#include "values_bucket.h" +using namespace std; +using namespace OHOS::AppExecFwk; +using namespace OHOS::EventFwk; +using Uri = OHOS::Uri; +namespace OHOS { +namespace Notification { +std::mutex TestAnsSubscriber::mutex_ = std::mutex(); +bool GetBoolParam() +{ + bool param; + if (GetIntParam() % 2 == 0) { + param = true; + } else { + param = false; + } + return param; +} + +size_t GenRandom(size_t min, size_t max) +{ + std::random_device rd; + static uniform_int_distribution u(min, max); + static default_random_engine e(rd()); + size_t param = u(e); + return param; +} + +int8_t GetS8Param() +{ + std::random_device rd; + static uniform_int_distribution u(INT8_MIN, INT8_MAX); + static default_random_engine e(rd()); + int8_t param = u(e); + return param; +} +int16_t GetS16Param() +{ + std::random_device rd; + static uniform_int_distribution u(INT16_MIN, INT16_MAX); + static default_random_engine e(rd()); + int16_t param = u(e); + return param; +} +int32_t GetS32Param() +{ + std::random_device rd; + static uniform_int_distribution u(INT32_MIN, INT32_MAX); + static default_random_engine e(rd()); + int32_t param = u(e); + return param; +} + +int64_t GetS64Param() +{ + std::random_device rd; + static uniform_int_distribution u(INT64_MIN, INT64_MAX); + static default_random_engine e(rd()); + int64_t param = u(e); + return param; +} + +template +T GetUnsignParam() +{ + std::random_device rd; + static uniform_int_distribution u; + static default_random_engine e(rd()); + T param = u(e); + return param; +} + +size_t GetSizeTParam() +{ + size_t param = GetUnsignParam(); + return param; +} + +uint8_t GetU8Param() +{ + uint8_t param = GetUnsignParam(); + return param; +} + +unsigned int GetUIntParam() +{ + unsigned int param = GetUnsignParam(); + return param; +} + +uint16_t GetU16Param() +{ + uint16_t param = GetUnsignParam(); + return param; +} + +uint32_t GetU32Param() +{ + uint32_t param = GetUnsignParam(); + return param; +} + +uint64_t GetU64Param() +{ + uint64_t param = GetUnsignParam(); + return param; +} + +short GetShortParam() +{ + std::random_device rd; + static uniform_int_distribution u(SHRT_MIN, SHRT_MAX); + static default_random_engine e(rd()); + short param = u(e); + return param; +} + +long GetLongParam() +{ + std::random_device rd; + static uniform_int_distribution u(LONG_MIN, LONG_MAX); + static default_random_engine e(rd()); + long param = u(e); + return param; +} + +int GetIntParam() +{ + std::random_device rd; + static uniform_int_distribution<> u(INT_MIN, INT_MAX); + static default_random_engine e(rd()); + int param = u(e); + return param; +} + +double GetDoubleParam() +{ + double param = 0; + std::random_device rd; + static uniform_real_distribution u(DBL_MIN, DBL_MAX); + static default_random_engine e(rd()); + param = u(e); + return param; +} + +float GetFloatParam() +{ + float param = 0; + std::random_device rd; + static uniform_real_distribution u(FLT_MIN, FLT_MAX); + static default_random_engine e(rd()); + param = u(e); + return param; +} + +char GetCharParam() +{ + std::random_device rd; + static uniform_int_distribution<> u(-128, 127); + static default_random_engine e(rd()); + char param = u(e); + return param; +} + +char32_t GetChar32Param() +{ + char32_t param = ' '; + std::random_device rd; + static uniform_int_distribution u; + static default_random_engine e(rd()); + param = u(e); + return param; +} + +char *GetCharArryParam() +{ + static char param[256]; + size_t len = 0; + string strparam = GetStringParam(); + if (!strparam.empty()) { + len = strparam.size() + 1; + if (len > sizeof(param)) { + len = sizeof(param) - 1; + } + + int ret = strcpy_s(param, len, strparam.c_str()); + if (ret == 0) { + return param; + } else { + return nullptr; + } + } else { + return nullptr; + } +} + +string GetStringParam() +{ + string param = ""; + char ch = GetCharParam(); + size_t len = GenRandom(0, 255); + while (len--) { + ch = GetCharParam(); + param += ch; + } + return param; +} + +template +vector GetUnsignVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + T t = GetUnsignParam(); + param.push_back(t); + } + return param; +} + +template +T GetClassParam() +{ + T param; + return param; +} + +std::vector GetBoolVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + int t = GetBoolParam(); + param.push_back(t); + } + return param; +} + +std::vector GetShortVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + short t = GetShortParam(); + param.push_back(t); + } + return param; +} + +std::vector GetLongVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + long t = GetLongParam(); + param.push_back(t); + } + return param; +} + +vector GetIntVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + int t = GetIntParam(); + param.push_back(t); + } + return param; +} + +std::vector GetFloatVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + float t = GetIntParam(); + param.push_back(t); + } + return param; +} + +std::vector GetDoubleVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + double t = GetIntParam(); + param.push_back(t); + } + return param; +} + +vector GetCharVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + char t = GetCharParam(); + param.push_back(t); + } + return param; +} + +vector GetChar32VectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + char32_t t = GetChar32Param(); + param.push_back(t); + } + return param; +} + +vector GetStringVectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + string t = GetStringParam(); + param.push_back(t); + } + return param; +} + +vector GetS8VectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + int8_t temp = GetS8Param(); + param.push_back(temp); + } + return param; +} + +vector GetS16VectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + int16_t temp = GetS16Param(); + param.push_back(temp); + } + return param; +} + +vector GetS32VectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + int32_t temp = GetS32Param(); + param.push_back(temp); + } + return param; +} + +vector GetS64VectorParam() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + int64_t temp = GetS64Param(); + param.push_back(temp); + } + return param; +} + +std::shared_ptr GetParamParcel() +{ + return make_shared(); +} +std::shared_ptr GetParamWant() +{ + return make_shared(); +} + +std::vector> GetParamWantVector() +{ + vector> param; + size_t len = GenRandom(0, 255); + while (len--) { + std::shared_ptr t = GetParamWant(); + param.push_back(t); + } + return param; +} + +OHOS::AAFwk::Operation GetParamOperation() +{ + return OHOS::AAFwk::Operation(); +} + +std::shared_ptr GetParamAsyncCommonEventResult() +{ + return make_shared( + GetIntParam(), GetStringParam(), GetBoolParam(), GetBoolParam(), GetParamSptrRemote()); +} + +std::shared_ptr GetParamCommonEventData() +{ + return make_shared(); +} + +std::shared_ptr GetParamCommonEventManager() +{ + return make_shared(); +} + +std::shared_ptr GetParamCommonEventPublishInfo() +{ + return make_shared(); +} + +std::shared_ptr GetParamCommonEventSubscribeInfo() +{ + return make_shared(); +} + +std::shared_ptr GetParamCommonEventSubscriber() +{ + return make_shared(); +} + +std::shared_ptr GetParamCommonEventSupport() +{ + return make_shared(); +} + +std::shared_ptr GetParamMatchingSkills() +{ + return make_shared(); +} + +sptr GetParamSptrRemote() +{ + return sptr(); +} + +std::shared_ptr GetParamEventRunner() +{ + return EventRunner::Create(GetCharArryParam()); +} + +std::shared_ptr GetParamEventHandler() +{ + return make_shared(GetParamEventRunner()); +} + +std::shared_ptr GetParamEventQueue() +{ + return make_shared(); +} + +std::shared_ptr GetParamEventRunnerNativeImplement() +{ + return make_shared(GetBoolParam()); +} + +std::shared_ptr GetParamFileDescriptorListener() +{ + return make_shared(); +} + +TestDumper GetParamDumper() +{ + return GetClassParam(); +} + +InnerEvent::Pointer GetParamInnerEvent() +{ + return InnerEvent::Get(GetU32Param(), GetS64Param()); +} + +CommonEventSubscribeInfo::ThreadMode GetParamThreadMode() +{ + switch (GetIntParam() % 4) { + case 0: + return CommonEventSubscribeInfo::ThreadMode::HANDLER; + break; + case 1: + return CommonEventSubscribeInfo::ThreadMode::POST; + break; + case 2: + return CommonEventSubscribeInfo::ThreadMode::ASYNC; + break; + case 3: + return CommonEventSubscribeInfo::ThreadMode::BACKGROUND; + break; + default: + return CommonEventSubscribeInfo::ThreadMode::HANDLER; + break; + } +} + +EventQueue::Priority GetParamPriority() +{ + switch (GetIntParam() % 4) { + case 0: + return EventQueue::Priority::IMMEDIATE; + break; + case 1: + return EventQueue::Priority::HIGH; + break; + case 2: + return EventQueue::Priority::LOW; + break; + case 3: + return EventQueue::Priority::IDLE; + break; + default: + return EventQueue::Priority::LOW; + break; + } +} + +std::shared_ptr GetParamLogger() +{ + return make_shared(); +} + +InnerEvent::Callback GetParamCallback() +{ + auto callback = []() { printf("Fuzz Test Inner Event Callback."); }; + return callback; +} + +OHOS::AppExecFwk::InnerEvent::TimePoint GetParamTimePoint() +{ + std::chrono::steady_clock::time_point param = std::chrono::steady_clock::now(); + return param; +} + +std::shared_ptr GetParamAbilityStartSetting() +{ + return AbilityStartSetting::GetEmptySetting(); +} + +sptr GetParamIAbilityConnection() +{ + return sptr(); +} + +std::shared_ptr GetParamAbilityContext() +{ + return make_shared(); +} +std::shared_ptr GetParamIAbilityEvent() +{ + return make_shared(); +} + +sptr GetParamAbilityThread() +{ + return sptr(); +} + +std::shared_ptr GetParamAbilityHandler() +{ + return make_shared(GetParamEventRunner(), GetParamAbilityThread()); +} + +std::shared_ptr GetParamAbility() +{ + return make_shared(); +} + +std::shared_ptr GetParamComponentContainer() +{ + return make_shared(); +} + +std::shared_ptr GetParamOHOSApplication() +{ + return make_shared(); +} + +std::shared_ptr GetParamKeyEvent() +{ + return make_shared(); +} + +OHOS::Uri GetParamUri() +{ + return OHOS::Uri(GetStringParam()); +} + +NativeRdb::ValuesBucket GetParamValuesBucket() +{ + if (GetBoolParam()) { + NativeRdb::ValuesBucket val; + val.PutNull(GetStringParam()); + return val; + } else { + return NativeRdb::ValuesBucket(); + } +} + +OHOS::AppExecFwk::Configuration GetParamConfiguration() +{ + if (GetBoolParam()) { + return OHOS::AppExecFwk::Configuration(GetStringParam()); + } else { + return OHOS::AppExecFwk::Configuration(); + } +} + +NativeRdb::DataAbilityPredicates GetParamDataAbilityPredicates() +{ + if (GetBoolParam()) { + return NativeRdb::DataAbilityPredicates(GetStringParam()); + } else { + return NativeRdb::DataAbilityPredicates(); + } +} + +OHOS::AppExecFwk::PacMap GetParamPacMap() +{ + return OHOS::AppExecFwk::PacMap(); +} + +std::shared_ptr GetParamProcessInfo() +{ + pid_t id = GetIntParam(); + if (GetBoolParam()) { + return make_shared(GetStringParam(), id); + } else { + return make_shared(); + } +} + +std::shared_ptr GetParamDataUriUtils() +{ + return make_shared(); +} + +std::shared_ptr GetParamContext() +{ + return make_shared(); +} + +std::shared_ptr GetParamLifeCycle() +{ + return make_shared(); +} + +OHOS::AppExecFwk::LifeCycle::Event GetParamLifeCycleEvent() +{ + switch (GetIntParam() % 7) { + case 0: + return OHOS::AppExecFwk::LifeCycle::Event::ON_ACTIVE; + break; + case 1: + return OHOS::AppExecFwk::LifeCycle::Event::ON_BACKGROUND; + break; + case 2: + return OHOS::AppExecFwk::LifeCycle::Event::ON_FOREGROUND; + break; + case 3: + return OHOS::AppExecFwk::LifeCycle::Event::ON_INACTIVE; + break; + case 4: + return OHOS::AppExecFwk::LifeCycle::Event::ON_START; + break; + case 5: + return OHOS::AppExecFwk::LifeCycle::Event::ON_STOP; + break; + case 6: + return OHOS::AppExecFwk::LifeCycle::Event::UNDEFINED; + break; + default: + return OHOS::AppExecFwk::LifeCycle::Event::ON_ACTIVE; + break; + } +} + +std::shared_ptr GetParamElementName() +{ + if (GetBoolParam()) { + return make_shared(GetStringParam(), GetStringParam(), GetStringParam()); + } else { + return make_shared(); + } +} + +std::shared_ptr GetParamWantParams() +{ + return make_shared(); +} + +std::shared_ptr GetParamAbilityManager() +{ + return make_shared(); +} + +OHOS::AAFwk::PatternsMatcher GetParamPatternsMatcher() +{ + return OHOS::AAFwk::PatternsMatcher(); +} + +OHOS::AAFwk::MatchType GetParamMatchType() +{ + switch (GetIntParam() % 4) { + case 0: + return OHOS::AAFwk::MatchType::DEFAULT; + break; + case 1: + return OHOS::AAFwk::MatchType::PREFIX; + break; + case 2: + return OHOS::AAFwk::MatchType::PATTERN; + break; + case 3: + return OHOS::AAFwk::MatchType::GLOBAL; + break; + default: + return OHOS::AAFwk::MatchType::DEFAULT; + break; + } +} + +std::shared_ptr GetParamBundleMgrProxy() +{ + return make_shared(GetParamSptrRemote()); +} + +OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag() +{ + if (GetBoolParam()) { + return OHOS::AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO; + } else { + return OHOS::AppExecFwk::ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMS; + } +} + +OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo() +{ + return OHOS::AppExecFwk::ApplicationInfo(); +} + +std::vector GetParamApplicationInfoVector() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::ApplicationInfo t = GetParamApplicationInfo(); + param.push_back(t); + } + return param; +} + +OHOS::AppExecFwk::BundleFlag GetParamBundleFlag() +{ + if (GetBoolParam()) { + return OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT; + } else { + return OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES; + } +} + +OHOS::AppExecFwk::BundleInfo GetParamBundleInfo() +{ + return OHOS::AppExecFwk::BundleInfo(); +} + +OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo() +{ + return OHOS::AppExecFwk::AbilityInfo(); +} + +OHOS::AppExecFwk::HapModuleInfo GetParamHapModuleInfo() +{ + return OHOS::AppExecFwk::HapModuleInfo(); +} + +OHOS::AppExecFwk::PermissionDef GetParamPermissionDef() +{ + return OHOS::AppExecFwk::PermissionDef(); +} + +std::vector GetParamPermissionDefVector() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::PermissionDef t = GetParamPermissionDef(); + param.push_back(t); + } + return param; +} + +OHOS::AppExecFwk::IBundleMgr::Message GetParamIBundleMgrMessage() +{ + return (OHOS::AppExecFwk::IBundleMgr::Message)(GetIntParam() % 36); +} + +OHOS::MessageParcel GetParamMessageParcel() +{ + return OHOS::MessageParcel(); +} + +OHOS::AppExecFwk::DumpFlag GetParamDumpFlag() +{ + switch (GetIntParam() % 3) { + case 0: + return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_LIST; + break; + case 1: + return OHOS::AppExecFwk::DumpFlag::DUMP_ALL_BUNDLE_INFO; + break; + case 2: + return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_INFO; + break; + default: + return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_LIST; + break; + } +} + +sptr GetParamICleanCacheCallback() +{ + return sptr(); +} + +sptr GetParamIBundleStatusCallback() +{ + return sptr(); +} + +std::shared_ptr GetParamDataAbilityHelper() +{ + return OHOS::AppExecFwk::DataAbilityHelper::Creator(std::make_shared()); +} + +std::shared_ptr GetParamNotificationSorting() +{ + return std::make_shared(); +} + +std::vector GetParamNotificationSortingVector() +{ + vector param{}; + size_t len = GenRandom(0, 255); + while (len--) { + NotificationSorting t; + param.push_back(t); + } + return param; +} + +std::shared_ptr GetParamNotificationSortingMap() +{ + if (GetBoolParam()) { + return std::make_shared(); + } else { + std::vector sortingList = GetParamNotificationSortingVector(); + return std::make_shared(sortingList); + } +} + +std::shared_ptr GetParamNotificationSlot() +{ + return std::make_shared(GetParamSlotType()); +} + +sptr GetParamNotificationSlotSptr() +{ + sptr param = + new OHOS::Notification::NotificationSlot(GetParamSlotType()); + return param; +} + +OHOS::Notification::NotificationConstant::SlotType GetParamSlotType() +{ + switch (GetIntParam() % 5) { + case 0: + return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + break; + case 1: + return OHOS::Notification::NotificationConstant::SlotType::SERVICE_REMINDER; + break; + case 2: + return OHOS::Notification::NotificationConstant::SlotType::CONTENT_INFORMATION; + break; + case 3: + return OHOS::Notification::NotificationConstant::SlotType::CUSTOM; + break; + case 4: + return OHOS::Notification::NotificationConstant::SlotType::OTHER; + break; + default: + return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + break; + } +} +std::vector> GetParamNotificationSlotSptrVector() +{ + vector> param; + size_t len = GenRandom(0, 255); + while (len--) { + sptr t = GetParamNotificationSlotSptr(); + param.push_back(t); + } + return param; +} + +std::vector GetParamNotificationSlotVector() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + NotificationSlot t = *GetParamNotificationSlot(); + param.push_back(t); + } + return param; +} + +std::vector GetParamNotificationSlotGroupVector() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::Notification::NotificationSlotGroup t = *GetParamNotificationSlotGroup(); + param.push_back(t); + } + return param; +} +sptr GetParamNotificationSlotGroup() +{ + sptr param = + new OHOS::Notification::NotificationSlotGroup(GetStringParam(), GetStringParam()); + return param; +} +std::vector> GetParamNotificationSlotGroupSptrVector() +{ + vector> param; + size_t len = GenRandom(0, 255); + while (len--) { + sptr t = GetParamNotificationSlotGroup(); + param.push_back(t); + } + return param; +} +std::shared_ptr GetParamNotificationBundleOption() +{ + if (GetBoolParam()) { + return std::make_shared(); + } else { + return std::make_shared(GetStringParam(), GetS32Param()); + } +} +std::shared_ptr GetParamNotificationRequest() +{ + switch (GetIntParam() % 3) { + case 0: + return std::make_shared(); + break; + case 1: + return std::make_shared(GetS32Param()); + break; + case 2: + return std::make_shared(GetParamContext(), GetS32Param()); + break; + default: + return std::make_shared(); + break; + } +} + +sptr GetParamNotificationRequestSptr() +{ + switch (GetIntParam() % 3) { + case 0: { + sptr param = new OHOS::Notification::NotificationRequest(); + return param; + } break; + case 1: { + sptr param = + new OHOS::Notification::NotificationRequest(GetS32Param()); + return param; + } break; + case 2: { + sptr param = + new OHOS::Notification::NotificationRequest(GetParamContext(), GetS32Param()); + return param; + } break; + default: { + sptr param = new OHOS::Notification::NotificationRequest(); + return param; + } break; + } +} + +std::vector> GetParamNotificationRequestVector() +{ + vector> param; + size_t len = GenRandom(0, 255); + while (len--) { + sptr t = GetParamNotificationRequestSptr(); + param.push_back(t); + } + return param; +} +sptr GetParamNotificationSortingMapSptr() +{ + sptr param; + if (GetBoolParam()) { + param = new OHOS::Notification::NotificationSortingMap(); + } else { + std::vector sortingList = GetParamNotificationSortingVector(); + param = new OHOS::Notification::NotificationSortingMap(sortingList); + } + return param; +} +OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel() +{ + switch (GetIntParam() % 6) { + case 0: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE; + break; + case 1: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_MIN; + break; + case 2: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_LOW; + break; + case 3: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_DEFAULT; + break; + case 4: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_HIGH; + break; + case 5: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_UNDEFINED; + break; + default: + return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE; + break; + } +} + +std::shared_ptr GetParamNotificationSubscriber() +{ + return std::make_shared(); +} + +std::shared_ptr GetParamNotificationSubscribeInfo() +{ + return std::make_shared(); +} + +OHOS::Notification::NotificationConstant::DisturbMode GetParamDisturbMode() +{ + switch (GetIntParam() % 5) { + case 0: + return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALARMS; + break; + case 1: + return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALL; + break; + case 2: + return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_NONE; + break; + case 3: + return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_PRIORITY; + break; + case 4: + return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_UNKNOWN; + break; + default: + return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALARMS; + break; + } +} +std::shared_ptr GetParamWantAgentInfo() +{ + switch (GetIntParam() % 3) { + case 0: + return std::make_shared(); + break; + case 1: { + std::vector> param = GetParamWantVector(); + return std::make_shared( + GetIntParam(), GetParamOperationType(), GetParamFlags(), param, GetParamWantParams()); + } break; + case 2: { + std::vector> param = GetParamWantVector(); + return std::make_shared( + GetIntParam(), GetParamOperationType(), GetParamFlagsVector(), param, GetParamWantParams()); + } break; + default: + return std::make_shared(); + break; + } +} + +OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperationType() +{ + switch (GetIntParam() % 6) { + case 0: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; + break; + case 1: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_ABILITY; + break; + case 2: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_ABILITIES; + break; + case 3: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_SERVICE; + break; + case 4: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT; + break; + case 5: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + break; + default: + return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; + break; + } +} +OHOS::Notification::WantAgent::WantAgentConstant::Flags GetParamFlags() +{ + switch (GetIntParam() % 10) { + case 0: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; + break; + case 1: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::NO_BUILD_FLAG; + break; + case 2: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::CANCEL_PRESENT_FLAG; + break; + case 3: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG; + break; + case 4: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG; + break; + case 5: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ELEMENT; + break; + case 6: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ACTION; + break; + case 7: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_URI; + break; + case 8: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ENTITIES; + break; + case 9: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_BUNDLE; + break; + default: + return OHOS::Notification::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; + break; + } +} +std::vector GetParamFlagsVector() +{ + vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::Notification::WantAgent::WantAgentConstant::Flags t = GetParamFlags(); + param.push_back(t); + } + return param; +} + +std::shared_ptr GetParamNotification() +{ + sptr param = GetParamNotificationRequestSptr(); + return std::make_shared(param); +} + +sptr GetParamNotificationSptr() +{ + sptr t = GetParamNotificationRequestSptr(); + sptr param = new OHOS::Notification::Notification(t); + return param; +} + +std::vector> GetParamNotificationSptrVector() +{ + std::vector> param; + size_t len = GenRandom(0, 255); + while (len--) { + sptr t = GetParamNotificationSptr(); + param.push_back(t); + } + return param; +} +std::shared_ptr GetParamPendingWant() +{ + sptr target = new WantSender(); + sptr whitelistToken = GetParamSptrRemote(); + if (GetBoolParam()) { + return std::make_shared(target); + } else { + return std::make_shared(target, whitelistToken); + } +} +std::shared_ptr GetParamWantAgent() +{ + if (GetBoolParam()) { + return std::make_shared(); + } else { + return std::make_shared(GetParamPendingWant()); + } +} +std::shared_ptr GetParamCompletedCallback() +{ + return std::make_shared(); +} +std::shared_ptr GetParamTriggerInfo() +{ + if (GetBoolParam()) { + return std::make_shared(); + } else { + return std::make_shared( + GetStringParam(), GetParamWantParams(), GetParamWant(), GetIntParam()); + } +} +std::shared_ptr GetParamCancelListener() +{ + return std::make_shared(); +} + +std::shared_ptr GetParamLauncherService() +{ + return make_shared(); +} +std::vector GetParamLauncherAbilityInfoVector() +{ + std::vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::LauncherAbilityInfo t; + param.push_back(t); + } + return param; +} +std::shared_ptr GetParamLauncherAbilityInfo() +{ + return make_shared(); +} +std::vector GetParamLauncherShortcutInfoVector() +{ + std::vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::LauncherShortcutInfo t; + param.push_back(t); + } + return param; +} +std::vector GetParamFormInfoVector() +{ + std::vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::FormInfo t; + param.push_back(t); + } + return param; +} +std::vector GetParamShortcutInfoVector() +{ + std::vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::ShortcutInfo t; + param.push_back(t); + } + return param; +} +std::vector GetParamModuleUsageRecordVector() +{ + std::vector param; + size_t len = GenRandom(0, 255); + while (len--) { + OHOS::AppExecFwk::ModuleUsageRecord t; + param.push_back(t); + } + return param; +} +sptr GetParamOnPermissionChangedCallback() +{ + return sptr(); +} + +std::shared_ptr GetParamTaskDispatcher() +{ + switch (GetIntParam() % 4) { + case 0: + return GetParamContext()->GetMainTaskDispatcher(); + break; + case 1: + return GetParamContext()->CreateParallelTaskDispatcher(GetStringParam(), GetParamTaskPriority()); + break; + case 2: + return GetParamContext()->CreateSerialTaskDispatcher(GetStringParam(), GetParamTaskPriority()); + break; + case 3: + return GetParamContext()->GetGlobalTaskDispatcher(GetParamTaskPriority()); + break; + default: + return GetParamContext()->GetMainTaskDispatcher(); + break; + } +} + +OHOS::AppExecFwk::TaskPriority GetParamTaskPriority() +{ + switch (GetIntParam() % 3) { + case 0: + return OHOS::AppExecFwk::TaskPriority::HIGH; + break; + case 1: + return OHOS::AppExecFwk::TaskPriority::DEFAULT; + break; + case 2: + return OHOS::AppExecFwk::TaskPriority::LOW; + break; + default: + return OHOS::AppExecFwk::TaskPriority::HIGH; + break; + } +} + +std::shared_ptr GetParamRunnable() +{ + return std::make_shared([]() { std::cout << "Start task runnable."; }); +} + +std::shared_ptr GetParamGroup() +{ + return std::make_shared(); +} + +std::shared_ptr> GetParamIteratableTask() +{ + return std::make_shared>([](long data) { std::cout << "Start IteratableTask."; }); +} + +OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResult() +{ + switch (GetIntParam() % 3) { + case 0: + return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS; + break; + case 1: + return OHOS::Notification::NotificationConstant::SubscribeResult::PREMISSION_FAIL; + break; + case 2: + return OHOS::Notification::NotificationConstant::SubscribeResult::RESOURCES_FAIL; + break; + default: + return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS; + break; + } +} + +OHOS::AppExecFwk::MissionInformation GetParamMissionInformation() +{ + return OHOS::AppExecFwk::MissionInformation(); +} + +std::shared_ptr GetParamAbilityLifecycleCallbacks() +{ + return std::make_shared(); +} + +std::shared_ptr GetParamBaseTaskDispatcher() +{ + std::shared_ptr context = + std::make_shared(); + std::shared_ptr config = + std::make_shared(GetStringParam(), GetParamTaskPriority()); + std::shared_ptr specTaskDispatcher = + std::make_shared(config, GetParamEventRunner()); + switch (GetIntParam() % 3) { + case 0: + return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority()); + break; + case 1: + return context->CreateParallelDispatcher(GetStringParam(), GetParamTaskPriority()); + break; + case 2: + return specTaskDispatcher; + break; + default: + return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority()); + ; + break; + } +} + +std::shared_ptr GetParamIAbilityManager() +{ + std::shared_ptr param = + DelayedSingleton::GetInstance(); + return param; +} + +} // namespace Notification +} // namespace OHOS -- Gitee From 42680ce2c005c7aecd527b4d44921778734f8bd8 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 2 Nov 2021 17:06:38 +0800 Subject: [PATCH 2/2] Fix codex Signed-off-by: zhaoyuan17 --- .../actsnotificationfuzztest.cpp | 2 +- .../include/notificationfuzztestmanager.h | 16 +- .../include/notificationgetparam.h | 27 ++- .../src/notificationfuzztestmanager.cpp | 42 ++-- .../src/notificationgetparam.cpp | 194 +++++++++--------- 5 files changed, 148 insertions(+), 133 deletions(-) diff --git a/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp b/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp index 09ed283d0..e0415252a 100644 --- a/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp +++ b/test/common/acts/actsnotificationfuzztest/actsnotificationfuzztest.cpp @@ -43,7 +43,7 @@ void ActsFuzzTest::TearDown() HWTEST_F(ActsFuzzTest, ACTS_FuzzTest_0100, Function | MediumTest | Level1) { std::cout << "fuzztest start" << std::endl; - fuzzTestManager::GetInstance()->StartFuzzTest(); + notificationFuzzTestManager::GetInstance()->StartFuzzTest(); std::cout << "fuzztest end" << std::endl; } diff --git a/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h b/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h index bb6fc825e..d56eee896 100644 --- a/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h +++ b/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h @@ -22,15 +22,15 @@ namespace OHOS { namespace Notification { -class fuzzTestManager { +class notificationFuzzTestManager { public: - typedef std::shared_ptr Ptr; - ~fuzzTestManager() + typedef std::shared_ptr Ptr; + ~notificationFuzzTestManager() {} static Ptr GetInstance() { if (instance_ == nullptr) { - instance_ = std::shared_ptr(new fuzzTestManager); + instance_ = std::shared_ptr(new notificationFuzzTestManager); } return instance_; } @@ -38,11 +38,11 @@ public: void StartFuzzTest(); private: - void SetJsonFunction(std::string); + void SetJsonFunction(std::string functionName); void SetCycle(uint16_t cycle); - fuzzTestManager(); - fuzzTestManager(fuzzTestManager &) = delete; - fuzzTestManager &operator=(const fuzzTestManager &) = delete; + notificationFuzzTestManager(); + notificationFuzzTestManager(notificationFuzzTestManager &) = delete; + notificationFuzzTestManager &operator=(const notificationFuzzTestManager &) = delete; static Ptr instance_; uint16_t cycle_{}; std::unordered_map remainderMap_{}; diff --git a/test/resource/notificationfuzztest/include/notificationgetparam.h b/test/resource/notificationfuzztest/include/notificationgetparam.h index baa039a3b..be9d1ec82 100644 --- a/test/resource/notificationfuzztest/include/notificationgetparam.h +++ b/test/resource/notificationfuzztest/include/notificationgetparam.h @@ -58,6 +58,19 @@ #include "task_dispatcher_context.h" #include "ability_manager_service.h" +const int INDEX_ZERO = 0; +const int INDEX_ONE = 1; +const int INDEX_TWO = 2; +const int INDEX_THREE = 3; +const int INDEX_FOUR = 4; +const int INDEX_FIVE = 5; +const int INDEX_SIX = 6; +const int INDEX_SEVEN = 7; +const int INDEX_EIGHT = 8; +const int INDEX_NINE = 9; +const int INDEX_TEN = 10; +const int MESSAGE_INDEX = 36; + using Want = OHOS::AAFwk::Want; namespace OHOS { namespace Notification { @@ -282,8 +295,10 @@ public: class TestCommonEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { public: - TestCommonEventSubscriber(){}; - ~TestCommonEventSubscriber(){}; + TestCommonEventSubscriber() + {} + ~TestCommonEventSubscriber() + {} virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) { printf("Fuzz Test Reveive Event\n"); @@ -364,14 +379,14 @@ public: {} ~TestAnsSubscriber() {} - void OnSubscribeResult(OHOS::Notification::NotificationConstant::SubscribeResult result) override + void OnConnected() override { - std::cout << "TestAnsSubscriber OnSubscribeResult" << std::endl; + std::cout << "TestAnsSubscriber OnConnected" << std::endl; mutex_.unlock(); } - void OnUnsubscribeResult(OHOS::Notification::NotificationConstant::SubscribeResult result) override + void OnDisconnected() override { - std::cout << "TestAnsSubscriber OnUnsubscribeResult" << std::endl; + std::cout << "TestAnsSubscriber OnDisconnected" << std::endl; mutex_.unlock(); } void OnDied() override diff --git a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp index 8136a61a8..50c541dea 100644 --- a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp +++ b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp @@ -26,9 +26,9 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::EventFwk; namespace OHOS { namespace Notification { -std::shared_ptr fuzzTestManager::instance_ = nullptr; +std::shared_ptr notificationFuzzTestManager::instance_ = nullptr; // RegisterNotificationHelper -void fuzzTestManager::RegisterNotificationHelper() +void notificationFuzzTestManager::RegisterNotificationHelper() { callFunctionMap_.emplace("NotificationHelperAddNotificationSlot", []() { OHOS::Notification::NotificationHelper::AddNotificationSlot(*GetParamNotificationSlot()); }); @@ -374,7 +374,7 @@ void fuzzTestManager::RegisterNotificationHelper() } // RegisterNotificationSorting -void fuzzTestManager::RegisterNotificationSorting() +void notificationFuzzTestManager::RegisterNotificationSorting() { callFunctionMap_.emplace("NotificationSortingGetRanking", []() { std::shared_ptr temp = GetParamNotificationSorting(); @@ -418,7 +418,7 @@ void fuzzTestManager::RegisterNotificationSorting() } // RegisterNotificationSortingMap -void fuzzTestManager::RegisterNotificationSortingMap() +void notificationFuzzTestManager::RegisterNotificationSortingMap() { callFunctionMap_.emplace("NotificationSortingMapGetKey", []() { std::shared_ptr temp = GetParamNotificationSortingMap(); @@ -434,7 +434,7 @@ void fuzzTestManager::RegisterNotificationSortingMap() } // RegisterNotificationSubscribeInfo -void fuzzTestManager::RegisterNotificationSubscribeInfo() +void notificationFuzzTestManager::RegisterNotificationSubscribeInfo() { callFunctionMap_.emplace("NotificationSubscribeInfoAddAppName", []() { std::shared_ptr temp = GetParamNotificationSubscribeInfo(); @@ -455,7 +455,7 @@ void fuzzTestManager::RegisterNotificationSubscribeInfo() } // RegisterNotificationSubscriber -void fuzzTestManager::RegisterNotificationSubscriber() +void notificationFuzzTestManager::RegisterNotificationSubscriber() { callFunctionMap_.emplace("NotificationSubscriberOnCanceledNotification", []() { std::shared_ptr temp = GetParamNotificationSubscriber(); @@ -472,8 +472,7 @@ void fuzzTestManager::RegisterNotificationSubscriber() callFunctionMap_.emplace("NotificationSubscriberOnSubscribeResult", []() { std::shared_ptr temp = GetParamNotificationSubscriber(); - OHOS::Notification::NotificationConstant::SubscribeResult result = GetParamSubscribeResult(); - temp->OnSubscribeResult(result); + temp->OnConnected(); }); callFunctionMap_.emplace("NotificationSubscriberOnConsumedNotification", []() { @@ -491,8 +490,7 @@ void fuzzTestManager::RegisterNotificationSubscriber() callFunctionMap_.emplace("NotificationSubscriberOnUnsubscribeResult", []() { std::shared_ptr temp = GetParamNotificationSubscriber(); - OHOS::Notification::NotificationConstant::SubscribeResult result = GetParamSubscribeResult(); - temp->OnUnsubscribeResult(result); + temp->OnDisconnected(); }); callFunctionMap_.emplace("NotificationSubscriberOnUpdate", []() { @@ -514,7 +512,7 @@ void fuzzTestManager::RegisterNotificationSubscriber() } // RegisterWantAgentHelper -void fuzzTestManager::RegisterWantAgentHelper() +void notificationFuzzTestManager::RegisterWantAgentHelper() { callFunctionMap_.emplace("WantAgentHelperGetWantAgentAppExecFwkparamsInfo", []() { const std::shared_ptr context = GetParamContext(); @@ -584,7 +582,7 @@ void fuzzTestManager::RegisterWantAgentHelper() } // RegisterLauncherService -void fuzzTestManager::RegisterLauncherService() +void notificationFuzzTestManager::RegisterLauncherService() { callFunctionMap_.emplace("LauncherServiceGetAbilityList", []() { std::shared_ptr temp = GetParamLauncherService(); @@ -643,7 +641,7 @@ void fuzzTestManager::RegisterLauncherService() } // RegisterIAbilityContinuation -void fuzzTestManager::RegisterIAbilityContinuation() +void notificationFuzzTestManager::RegisterIAbilityContinuation() { callFunctionMap_.emplace("IAbilityContinuationOnStartContinuation", []() { std::shared_ptr temp = GetParamAbility(); @@ -670,7 +668,7 @@ void fuzzTestManager::RegisterIAbilityContinuation() } // RegisterAbility_ -void fuzzTestManager::RegisterAbility_() +void notificationFuzzTestManager::RegisterAbility_() { callFunctionMap_.emplace("AbilityOnRequestPermissionsFromUserResult", []() { std::shared_ptr temp = GetParamAbility(); @@ -688,7 +686,7 @@ void fuzzTestManager::RegisterAbility_() } // RegisterAbilityContext_ -void fuzzTestManager::RegisterAbilityContext_() +void notificationFuzzTestManager::RegisterAbilityContext_() { callFunctionMap_.emplace("AbilityStartAbility", []() { std::shared_ptr temp = GetParamAbility(); @@ -699,7 +697,7 @@ void fuzzTestManager::RegisterAbilityContext_() } // RegisterContext -void fuzzTestManager::RegisterContext() +void notificationFuzzTestManager::RegisterContext() { callFunctionMap_.emplace("ContextVerifyPermission", []() { std::shared_ptr temp = GetParamContext(); @@ -798,7 +796,7 @@ void fuzzTestManager::RegisterContext() } // RegisterAbilityLifecycleCallbacks -void fuzzTestManager::RegisterAbilityLifecycleCallbacks() +void notificationFuzzTestManager::RegisterAbilityLifecycleCallbacks() { callFunctionMap_.emplace("AbilityLifecycleCallbacksOnAbilityActive", []() { std::shared_ptr temp = GetParamAbilityLifecycleCallbacks(); @@ -808,7 +806,7 @@ void fuzzTestManager::RegisterAbilityLifecycleCallbacks() } // RegisterIAbilityManager -void fuzzTestManager::RegisterIAbilityManager() +void notificationFuzzTestManager::RegisterIAbilityManager() { callFunctionMap_.emplace("IAbilityManagerMoveMissionToEnd", []() { std::shared_ptr temp = GetParamIAbilityManager(); @@ -834,7 +832,7 @@ void fuzzTestManager::RegisterIAbilityManager() }); } -fuzzTestManager::fuzzTestManager() +notificationFuzzTestManager::notificationFuzzTestManager() { RegisterNotificationHelper(); RegisterNotificationSorting(); @@ -851,12 +849,12 @@ fuzzTestManager::fuzzTestManager() RegisterIAbilityManager(); } -void fuzzTestManager::SetJsonFunction(std::string functionName) +void notificationFuzzTestManager::SetJsonFunction(std::string functionName) { remainderMap_.emplace(functionName, cycle_); } -void fuzzTestManager::SetCycle(uint16_t cycle) +void notificationFuzzTestManager::SetCycle(uint16_t cycle) { cycle_ = cycle; for_each(remainderMap_.begin(), remainderMap_.end(), [cycle](std::unordered_map::reference temp) { @@ -874,7 +872,7 @@ void action(int a) std::cout << "Interrupt signal (" << a << ") received.\n"; } -void fuzzTestManager::StartFuzzTest() +void notificationFuzzTestManager::StartFuzzTest() { std::cout << __func__ << std::endl; OHOS::FuzzConfigParser jsonParser; diff --git a/test/resource/notificationfuzztest/src/notificationgetparam.cpp b/test/resource/notificationfuzztest/src/notificationgetparam.cpp index 87af6a69d..f46a31178 100644 --- a/test/resource/notificationfuzztest/src/notificationgetparam.cpp +++ b/test/resource/notificationfuzztest/src/notificationgetparam.cpp @@ -13,11 +13,13 @@ * limitations under the License. */ #include "../include/notificationgetparam.h" + +#include +#include +#include #include #include -#include -#include -#include + #include "abs_shared_result_set.h" #include "data_ability_predicates.h" #include "values_bucket.h" @@ -31,7 +33,7 @@ std::mutex TestAnsSubscriber::mutex_ = std::mutex(); bool GetBoolParam() { bool param; - if (GetIntParam() % 2 == 0) { + if (GetIntParam() % INDEX_TWO == 0) { param = true; } else { param = false; @@ -498,17 +500,17 @@ InnerEvent::Pointer GetParamInnerEvent() CommonEventSubscribeInfo::ThreadMode GetParamThreadMode() { - switch (GetIntParam() % 4) { - case 0: + switch (GetIntParam() % INDEX_FOUR) { + case INDEX_ZERO: return CommonEventSubscribeInfo::ThreadMode::HANDLER; break; - case 1: + case INDEX_ONE: return CommonEventSubscribeInfo::ThreadMode::POST; break; - case 2: + case INDEX_TWO: return CommonEventSubscribeInfo::ThreadMode::ASYNC; break; - case 3: + case INDEX_THREE: return CommonEventSubscribeInfo::ThreadMode::BACKGROUND; break; default: @@ -519,17 +521,17 @@ CommonEventSubscribeInfo::ThreadMode GetParamThreadMode() EventQueue::Priority GetParamPriority() { - switch (GetIntParam() % 4) { - case 0: + switch (GetIntParam() % INDEX_FOUR) { + case INDEX_ZERO: return EventQueue::Priority::IMMEDIATE; break; - case 1: + case INDEX_ONE: return EventQueue::Priority::HIGH; break; - case 2: + case INDEX_TWO: return EventQueue::Priority::LOW; break; - case 3: + case INDEX_THREE: return EventQueue::Priority::IDLE; break; default: @@ -670,26 +672,26 @@ std::shared_ptr GetParamLifeCycle() OHOS::AppExecFwk::LifeCycle::Event GetParamLifeCycleEvent() { - switch (GetIntParam() % 7) { - case 0: + switch (GetIntParam() % INDEX_SEVEN) { + case INDEX_ZERO: return OHOS::AppExecFwk::LifeCycle::Event::ON_ACTIVE; break; - case 1: + case INDEX_ONE: return OHOS::AppExecFwk::LifeCycle::Event::ON_BACKGROUND; break; - case 2: + case INDEX_TWO: return OHOS::AppExecFwk::LifeCycle::Event::ON_FOREGROUND; break; - case 3: + case INDEX_THREE: return OHOS::AppExecFwk::LifeCycle::Event::ON_INACTIVE; break; - case 4: + case INDEX_FOUR: return OHOS::AppExecFwk::LifeCycle::Event::ON_START; break; - case 5: + case INDEX_FIVE: return OHOS::AppExecFwk::LifeCycle::Event::ON_STOP; break; - case 6: + case INDEX_SIX: return OHOS::AppExecFwk::LifeCycle::Event::UNDEFINED; break; default: @@ -724,17 +726,17 @@ OHOS::AAFwk::PatternsMatcher GetParamPatternsMatcher() OHOS::AAFwk::MatchType GetParamMatchType() { - switch (GetIntParam() % 4) { - case 0: + switch (GetIntParam() % INDEX_FOUR) { + case INDEX_ZERO: return OHOS::AAFwk::MatchType::DEFAULT; break; - case 1: + case INDEX_ONE: return OHOS::AAFwk::MatchType::PREFIX; break; - case 2: + case INDEX_TWO: return OHOS::AAFwk::MatchType::PATTERN; break; - case 3: + case INDEX_THREE: return OHOS::AAFwk::MatchType::GLOBAL; break; default: @@ -815,7 +817,7 @@ std::vector GetParamPermissionDefVector() OHOS::AppExecFwk::IBundleMgr::Message GetParamIBundleMgrMessage() { - return (OHOS::AppExecFwk::IBundleMgr::Message)(GetIntParam() % 36); + return (OHOS::AppExecFwk::IBundleMgr::Message)(GetIntParam() % MESSAGE_INDEX); } OHOS::MessageParcel GetParamMessageParcel() @@ -825,14 +827,14 @@ OHOS::MessageParcel GetParamMessageParcel() OHOS::AppExecFwk::DumpFlag GetParamDumpFlag() { - switch (GetIntParam() % 3) { - case 0: + switch (GetIntParam() % INDEX_THREE) { + case INDEX_ZERO: return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_LIST; break; - case 1: + case INDEX_ONE: return OHOS::AppExecFwk::DumpFlag::DUMP_ALL_BUNDLE_INFO; break; - case 2: + case INDEX_TWO: return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_INFO; break; default: @@ -863,7 +865,7 @@ std::shared_ptr GetParamNotificationSorting() std::vector GetParamNotificationSortingVector() { - vector param{}; + vector param; size_t len = GenRandom(0, 255); while (len--) { NotificationSorting t; @@ -896,20 +898,20 @@ sptr GetParamNotificationSlotSptr() OHOS::Notification::NotificationConstant::SlotType GetParamSlotType() { - switch (GetIntParam() % 5) { - case 0: + switch (GetIntParam() % INDEX_FIVE) { + case INDEX_ZERO: return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION; break; - case 1: + case INDEX_ONE: return OHOS::Notification::NotificationConstant::SlotType::SERVICE_REMINDER; break; - case 2: + case INDEX_TWO: return OHOS::Notification::NotificationConstant::SlotType::CONTENT_INFORMATION; break; - case 3: + case INDEX_THREE: return OHOS::Notification::NotificationConstant::SlotType::CUSTOM; break; - case 4: + case INDEX_FOUR: return OHOS::Notification::NotificationConstant::SlotType::OTHER; break; default: @@ -975,14 +977,14 @@ std::shared_ptr GetParamNotificati } std::shared_ptr GetParamNotificationRequest() { - switch (GetIntParam() % 3) { - case 0: + switch (GetIntParam() % INDEX_THREE) { + case INDEX_ZERO: return std::make_shared(); break; - case 1: + case INDEX_ONE: return std::make_shared(GetS32Param()); break; - case 2: + case INDEX_TWO: return std::make_shared(GetParamContext(), GetS32Param()); break; default: @@ -993,17 +995,17 @@ std::shared_ptr GetParamNotificationReq sptr GetParamNotificationRequestSptr() { - switch (GetIntParam() % 3) { - case 0: { + switch (GetIntParam() % INDEX_THREE) { + case INDEX_ZERO: { sptr param = new OHOS::Notification::NotificationRequest(); return param; } break; - case 1: { + case INDEX_ONE: { sptr param = new OHOS::Notification::NotificationRequest(GetS32Param()); return param; } break; - case 2: { + case INDEX_TWO: { sptr param = new OHOS::Notification::NotificationRequest(GetParamContext(), GetS32Param()); return param; @@ -1038,23 +1040,23 @@ sptr GetParamNotificationSortingMapS } OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel() { - switch (GetIntParam() % 6) { - case 0: + switch (GetIntParam() % INDEX_SIX) { + case INDEX_ZERO: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE; break; - case 1: + case INDEX_ONE: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_MIN; break; - case 2: + case INDEX_TWO: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_LOW; break; - case 3: + case INDEX_THREE: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_DEFAULT; break; - case 4: + case INDEX_FOUR: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_HIGH; break; - case 5: + case INDEX_FIVE: return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_UNDEFINED; break; default: @@ -1075,20 +1077,20 @@ std::shared_ptr GetParamNotificat OHOS::Notification::NotificationConstant::DisturbMode GetParamDisturbMode() { - switch (GetIntParam() % 5) { - case 0: + switch (GetIntParam() % INDEX_FIVE) { + case INDEX_ZERO: return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALARMS; break; - case 1: + case INDEX_ONE: return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALL; break; - case 2: + case INDEX_TWO: return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_NONE; break; - case 3: + case INDEX_THREE: return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_PRIORITY; break; - case 4: + case INDEX_FOUR: return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_UNKNOWN; break; default: @@ -1098,16 +1100,16 @@ OHOS::Notification::NotificationConstant::DisturbMode GetParamDisturbMode() } std::shared_ptr GetParamWantAgentInfo() { - switch (GetIntParam() % 3) { - case 0: + switch (GetIntParam() % INDEX_THREE) { + case INDEX_ZERO: return std::make_shared(); break; - case 1: { + case INDEX_ONE: { std::vector> param = GetParamWantVector(); return std::make_shared( GetIntParam(), GetParamOperationType(), GetParamFlags(), param, GetParamWantParams()); } break; - case 2: { + case INDEX_TWO: { std::vector> param = GetParamWantVector(); return std::make_shared( GetIntParam(), GetParamOperationType(), GetParamFlagsVector(), param, GetParamWantParams()); @@ -1120,23 +1122,23 @@ std::shared_ptr GetParamWantAgentI OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperationType() { - switch (GetIntParam() % 6) { - case 0: + switch (GetIntParam() % INDEX_SIX) { + case INDEX_ZERO: return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; break; - case 1: + case INDEX_ONE: return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_ABILITY; break; - case 2: + case INDEX_TWO: return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_ABILITIES; break; - case 3: + case INDEX_THREE: return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_SERVICE; break; - case 4: + case INDEX_FOUR: return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT; break; - case 5: + case INDEX_FIVE: return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; break; default: @@ -1146,35 +1148,35 @@ OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperatio } OHOS::Notification::WantAgent::WantAgentConstant::Flags GetParamFlags() { - switch (GetIntParam() % 10) { - case 0: + switch (GetIntParam() % INDEX_TEN) { + case INDEX_ZERO: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; break; - case 1: + case INDEX_ONE: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::NO_BUILD_FLAG; break; - case 2: + case INDEX_TWO: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::CANCEL_PRESENT_FLAG; break; - case 3: + case INDEX_THREE: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG; break; - case 4: + case INDEX_FOUR: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG; break; - case 5: + case INDEX_FIVE: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ELEMENT; break; - case 6: + case INDEX_SIX: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ACTION; break; - case 7: + case INDEX_SEVEN: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_URI; break; - case 8: + case INDEX_EIGHT: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ENTITIES; break; - case 9: + case INDEX_NINE: return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_BUNDLE; break; default: @@ -1317,17 +1319,17 @@ sptr GetParamOnPermissionChangedC std::shared_ptr GetParamTaskDispatcher() { - switch (GetIntParam() % 4) { - case 0: + switch (GetIntParam() % INDEX_FOUR) { + case INDEX_ZERO: return GetParamContext()->GetMainTaskDispatcher(); break; - case 1: + case INDEX_ONE: return GetParamContext()->CreateParallelTaskDispatcher(GetStringParam(), GetParamTaskPriority()); break; - case 2: + case INDEX_TWO: return GetParamContext()->CreateSerialTaskDispatcher(GetStringParam(), GetParamTaskPriority()); break; - case 3: + case INDEX_THREE: return GetParamContext()->GetGlobalTaskDispatcher(GetParamTaskPriority()); break; default: @@ -1339,13 +1341,13 @@ std::shared_ptr GetParamTaskDispatcher() OHOS::AppExecFwk::TaskPriority GetParamTaskPriority() { switch (GetIntParam() % 3) { - case 0: + case INDEX_ZERO: return OHOS::AppExecFwk::TaskPriority::HIGH; break; - case 1: + case INDEX_ONE: return OHOS::AppExecFwk::TaskPriority::DEFAULT; break; - case 2: + case INDEX_TWO: return OHOS::AppExecFwk::TaskPriority::LOW; break; default: @@ -1372,13 +1374,13 @@ std::shared_ptr> GetParamIteratableTask() OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResult() { switch (GetIntParam() % 3) { - case 0: + case INDEX_ZERO: return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS; break; - case 1: + case INDEX_ONE: return OHOS::Notification::NotificationConstant::SubscribeResult::PREMISSION_FAIL; break; - case 2: + case INDEX_TWO: return OHOS::Notification::NotificationConstant::SubscribeResult::RESOURCES_FAIL; break; default: @@ -1406,13 +1408,13 @@ std::shared_ptr GetParamBaseTaskDispatcher std::shared_ptr specTaskDispatcher = std::make_shared(config, GetParamEventRunner()); switch (GetIntParam() % 3) { - case 0: + case INDEX_ZERO: return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority()); break; - case 1: + case INDEX_ONE: return context->CreateParallelDispatcher(GetStringParam(), GetParamTaskPriority()); break; - case 2: + case INDEX_TWO: return specTaskDispatcher; break; default: -- Gitee