From bdec35eec3f643cd6fc40c64f96e02f72e80378a Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Tue, 8 Oct 2024 14:21:55 +0800 Subject: [PATCH 1/5] optimization Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 10 ++ interfaces/inner_api/reminder_request.h | 6 + services/ans/include/reminder_data_manager.h | 5 - services/ans/include/reminder_store.h | 7 +- services/ans/src/reminder_data_manager.cpp | 132 ++++--------------- services/ans/src/reminder_store.cpp | 19 +-- 6 files changed, 52 insertions(+), 127 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 7b7494047..7d6971b07 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -1825,6 +1825,16 @@ uint8_t ReminderRequest::GetRepeatDaysOfWeek() const return repeatDaysOfWeek_; } +sptr ReminderRequest::GetNotificationOption() const +{ + return notificationOption_; +} + +void ReminderRequest::SetNotificationOption(const sptr& option) +{ + notificationOption_ = option; +} + void ReminderRequest::SetRepeatDaysOfWeek(bool set, const std::vector &daysOfWeek) { if (daysOfWeek.size() == 0) { diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 642f2d918..5548a3fa9 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -900,6 +900,10 @@ public: */ uint8_t GetRepeatDaysOfWeek() const; + sptr GetNotificationOption() const; + + void SetNotificationOption(const sptr& option); + /** * @brief When system language change, will call this function. * need load resource to update button title @@ -1133,6 +1137,8 @@ private: std::string wantAgentStr_{}; std::string maxWantAgentStr_{}; + + sptr notificationOption_ {nullptr}; }; } // namespace Reminder } // namespace OHOS diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 817446e95..2e9237617 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -686,11 +686,6 @@ private: */ std::vector> showedReminderVector_; - /** - * Map used to record all the bundle information of the reminders in system. - */ - std::map> notificationBundleOptionMap_; - /** * This timer is used to control the triggerTime of next reminder. */ diff --git a/services/ans/include/reminder_store.h b/services/ans/include/reminder_store.h index ac81e8e25..4665fce41 100644 --- a/services/ans/include/reminder_store.h +++ b/services/ans/include/reminder_store.h @@ -18,7 +18,6 @@ #include -#include "notification_bundle_option.h" #include "reminder_request.h" #include "rdb_errno.h" #include "rdb_helper.h" @@ -37,7 +36,7 @@ public: int32_t Delete(const int32_t reminderId); int32_t Delete(const std::string& pkg, const int32_t userId, const int32_t uid); int32_t DeleteUser(const int32_t userId); - int32_t UpdateOrInsert(const sptr& reminder, const sptr& bundleOption); + int32_t UpdateOrInsert(const sptr& reminder); int32_t GetMaxId(); std::vector> GetAllValidReminders(); @@ -74,8 +73,8 @@ private: int32_t InitData(); int32_t DeleteBase(const std::string& deleteCondition); int32_t Delete(const std::string& baseCondition, const std::string& assoConditon); - int32_t Insert(const sptr& reminder, const sptr& bundleOption); - int32_t Update(const sptr& reminder, const sptr& bundleOption); + int32_t Insert(const sptr& reminder); + int32_t Update(const sptr& reminder); bool IsReminderExist(const sptr& reminder); std::vector> GetReminders(const std::string& queryCondition); diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index c1284e204..1c82e215a 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -253,12 +253,6 @@ void ReminderDataManager::CancelRemindersImplLocked(const std::string &packageNa } for (auto vit = reminderVector_.begin(); vit != reminderVector_.end();) { int32_t reminderId = (*vit)->GetReminderId(); - auto mit = notificationBundleOptionMap_.find(reminderId); - if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Get bundle option occur error, reminderId=%{public}d", reminderId); - ++vit; - continue; - } if (IsMatched(*vit, packageName, userId, uid)) { if ((*vit)->IsAlerting()) { StopAlertingReminder(*vit); @@ -266,7 +260,6 @@ void ReminderDataManager::CancelRemindersImplLocked(const std::string &packageNa CancelNotification(*vit); RemoveFromShowedReminders(*vit); vit = reminderVector_.erase(vit); - notificationBundleOptionMap_.erase(mit); totalCount_--; continue; } @@ -329,7 +322,7 @@ void ReminderDataManager::CancelNotification(const sptr &remind ANSR_LOGE("Cancel notification fail"); return; } - sptr bundleOption = FindNotificationBundleOption(reminder->GetReminderId()); + sptr bundleOption = reminder->GetNotificationOption(); advancedNotificationService_->CancelPreparedNotification(notification->GetNotificationId(), ReminderRequest::NOTIFICATION_LABEL, bundleOption, NotificationConstant::APP_CANCEL_REMINDER_REASON_DELETE); } @@ -407,15 +400,7 @@ void ReminderDataManager::OnProcessDiedLocked(const sptr lock(ReminderDataManager::SHOW_MUTEX); for (auto it = showedReminderVector_.begin(); it != showedReminderVector_.end(); ++it) { int32_t reminderId = (*it)->GetReminderId(); - auto mit = notificationBundleOptionMap_.find(reminderId); - if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGD("Not get bundle option, the reminder may has been cancelled, reminderId=%{public}d", reminderId); - CancelNotification(*it); - showedReminderVector_.erase(it); - --it; - continue; - } - if (mit->second->GetBundleName() != bundleName || mit->second->GetUid() != uid) { + if ((*it)->GetBundleName() != bundleName || (*it)->GetUid() != uid) { continue; } if ((*it)->IsAlerting()) { @@ -438,14 +423,8 @@ void ReminderDataManager::InitTimerInfo(std::shared_ptr &shar sharedTimerInfo->SetRepeat(false); sharedTimerInfo->SetInterval(0); - auto mit = notificationBundleOptionMap_.find(reminderRequest->GetReminderId()); - if (mit == notificationBundleOptionMap_.end()) { - ANS_LOGE("Failed to get bundle information. reminderId=%{public}d", - reminderRequest->GetReminderId()); - return; - } - sharedTimerInfo->SetBundleName(mit->second->GetBundleName()); - sharedTimerInfo->SetUid(mit->second->GetUid()); + sharedTimerInfo->SetBundleName(reminderRequest->GetBundleName()); + sharedTimerInfo->SetUid(reminderRequest->GetUid()); // The systemtimer type will be set TIMER_TYPE_INEXACT_REMINDER&&EXACT if reminder type is CALENDAR or TIMER, // and set WAKEUP&&EXACT if ALARM. @@ -618,7 +597,7 @@ void ReminderDataManager::CloseRemindersByGroupId(const int32_t &oldReminderId, if (IsMatchedForGroupIdAndPkgName(reminder, packageName, groupId)) { reminder->SetExpired(true); reminder->SetStateToInActive(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); ResetStates(TimerType::TRIGGER_TIMER); ANSR_LOGD("Cancel reminders by groupid, reminder is %{public}s", reminder->Dump().c_str()); } @@ -642,7 +621,7 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b } reminder->OnClose(true); RemoveFromShowedReminders(reminder); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); if (cancelNotification) { CancelNotification(reminder); } @@ -702,11 +681,7 @@ void ReminderDataManager::UpdateAppDatabase(const sptr &reminde return; } // init default dstBundleName - std::string dstBundleName; - auto mit = notificationBundleOptionMap_.find(reminder->GetReminderId()); - if (mit != notificationBundleOptionMap_.end()) { - dstBundleName = mit->second->GetBundleName(); - } + std::string dstBundleName = reminder->GetBundleName(); GenDstBundleName(dstBundleName, actionButtonMap.at(actionButtonType).dataShareUpdate->uri); DataShare::CreateOptions options; @@ -870,7 +845,7 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde return; } int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = FindNotificationBundleOption(reminderId); + sptr bundleOption = reminder->GetNotificationOption(); sptr notificationRequest = reminder->GetNotificationRequest(); if (bundleOption == nullptr) { ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); @@ -885,7 +860,7 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde // Set the notification SoundEnabled and VibrationEnabled by soltType advancedNotificationService_->SetRequestBySlotType(notificationRequest, bundleOption); advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::UpdateAndSaveReminderLocked( @@ -904,12 +879,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( reminder->SetExpired(true); } int32_t reminderId = reminder->GetReminderId(); - auto ret = notificationBundleOptionMap_.insert( - std::pair>(reminderId, bundleOption)); - if (!ret.second) { - ANSR_LOGE("Containers add to map error"); - return; - } + reminder->SetNotificationOption(bundleOption); reminderVector_.push_back(reminder); totalCount_++; store_->UpdateOrInsert(reminder, bundleOption); @@ -926,7 +896,7 @@ bool ReminderDataManager::ShouldAlert(const sptr &reminder) con return false; } int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = FindNotificationBundleOption(reminderId); + sptr bundleOption = reminder->GetNotificationOption(); if (bundleOption == nullptr) { ANSR_LOGD("The reminder (reminderId=%{public}d) is silent", reminderId); return false; @@ -1103,7 +1073,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co ANSR_LOGD("Show the reminder(Play sound: %{public}d), %{public}s", static_cast(isNeedToPlaySound), reminder->Dump().c_str()); int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = FindNotificationBundleOption(reminderId); + sptr bundleOption = reminder->GetNotificationOption(); sptr notificationRequest = reminder->GetNotificationRequest(); if (bundleOption == nullptr) { ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); @@ -1112,13 +1082,13 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co if (advancedNotificationService_ == nullptr) { ANSR_LOGE("ShowReminder fail"); reminder->OnShow(false, isSysTimeChanged, false); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return; } if (!IsAllowedNotify(reminder)) { ANSR_LOGE("Not allow to notify."); reminder->OnShow(false, isSysTimeChanged, false); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return; } ReportSysEvent(reminder); @@ -1147,7 +1117,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } HandleSameNotificationIdShowing(reminder); } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); if (isNeedToStartNext) { StartRecentReminder(); @@ -1156,12 +1126,6 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co void ReminderDataManager::UpdateNotification(const sptr &reminder, bool isSnooze) { - int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = FindNotificationBundleOption(reminderId); - if (bundleOption == nullptr) { - ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); - return; - } if (isSnooze) { reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, "snooze"); } else { @@ -1205,10 +1169,10 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) StopTimerLocked(TimerType::ALERTING_TIMER); } reminder->OnSnooze(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); // 2) Show the notification dialog in the systemUI - sptr bundleOption = FindNotificationBundleOption(reminderId); + sptr bundleOption = reminder->GetNotificationOption(); sptr notificationRequest = reminder->GetNotificationRequest(); if (bundleOption == nullptr) { ANSR_LOGW("snoozeReminder, invalid bundle option"); @@ -1242,14 +1206,14 @@ void ReminderDataManager::StartRecentReminder() { std::lock_guard locker(ReminderDataManager::ACTIVE_MUTEX); activeReminder_->OnStop(); - store_->UpdateOrInsert(activeReminder_, FindNotificationBundleOption(activeReminderId_)); + store_->UpdateOrInsert(activeReminder_); } StopTimerLocked(TimerType::TRIGGER_TIMER); } ANSR_LOGI("Start recent reminder"); StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); reminder->OnStart(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -1274,13 +1238,7 @@ std::string ReminderDataManager::Dump() const if ((*it)->IsExpired()) { continue; } - int32_t reminderId = (*it)->GetReminderId(); - auto mit = notificationBundleOptionMap_.find(reminderId); - if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Dump get notificationBundleOption(reminderId=%{public}d) fail", reminderId); - continue; - } - std::string bundleName = mit->second->GetBundleName(); + std::string bundleName = (*it)->GetBundleName(); auto val = bundleNameMap.find(bundleName); if (val == bundleNameMap.end()) { std::vector> reminders; @@ -1340,12 +1298,6 @@ sptr ReminderDataManager::GetRecentReminderLocked() } int32_t reminderId = (*it)->GetReminderId(); ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); - auto mit = notificationBundleOptionMap_.find(reminderId); - if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Remove notificationBundleOption(reminderId=%{public}d) fail", reminderId); - } else { - notificationBundleOptionMap_.erase(mit); - } it = reminderVector_.erase(it); totalCount_--; store_->Delete(reminderId); @@ -1395,10 +1347,10 @@ sptr ReminderDataManager::HandleRefreshReminder(const uint8_t & if (triggerTimeBefore != triggerTimeAfter || reminder->GetReminderId() == alertingReminderId_) { CloseReminder(reminder, true); } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return nullptr; } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return reminder; } @@ -1408,12 +1360,6 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrGetNotificationId(); ANSR_LOGD("HandleSameNotificationIdShowing notificationId=%{public}d", notificationId); int32_t curReminderId = reminder->GetReminderId(); - auto mit = notificationBundleOptionMap_.find(curReminderId); - if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Error occur when get bundle option, reminderId=%{public}d", curReminderId); - return; - } - for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { int32_t tmpId = (*it)->GetReminderId(); if (tmpId == curReminderId) { @@ -1422,18 +1368,14 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrIsShowing()) { continue; } - sptr bundleOption = FindNotificationBundleOption(tmpId); - if (bundleOption == nullptr) { - ANSR_LOGW("Get notificationBundleOption(reminderId=%{public}d) fail", tmpId); - continue; - } - if (notificationId == (*it)->GetNotificationId() && IsBelongToSameApp(bundleOption, mit->second)) { + if (notificationId == (*it)->GetNotificationId() && + IsBelongToSameApp((*it)->GetNotificationOption(), reminder->GetNotificationOption())) { if ((*it)->IsAlerting()) { StopAlertingReminder(*it); } (*it)->OnSameNotificationIdCovered(); RemoveFromShowedReminders(*it); - store_->UpdateOrInsert((*it), FindNotificationBundleOption((*it)->GetReminderId())); + store_->UpdateOrInsert((*it)); } } } @@ -1562,14 +1504,8 @@ bool ReminderDataManager::IsAllowedNotify(const sptr &reminder) if (reminder == nullptr) { return false; } - int32_t reminderId = reminder->GetReminderId(); - auto mit = notificationBundleOptionMap_.find(reminderId); - if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Get bundle option occur error, reminderId=%{public}d", reminderId); - return false; - } bool isAllowed = false; - ErrCode errCode = advancedNotificationService_->IsSpecialBundleAllowedNotify(mit->second, isAllowed); + ErrCode errCode = advancedNotificationService_->IsSpecialBundleAllowedNotify(reminder->GetNotificationOption(), isAllowed); if (errCode != ERR_OK) { ANSR_LOGE("Failed to call IsSpecialBundleAllowedNotify, errCode=%{public}d", errCode); return false; @@ -1623,12 +1559,7 @@ void ReminderDataManager::LoadReminderFromDb() bundleOption->SetBundleName((*it)->GetBundleName()); bundleOption->SetUid((*it)->GetUid()); int32_t reminderId = (*it)->GetReminderId(); - auto ret = notificationBundleOptionMap_.insert( - std::pair>(reminderId, bundleOption)); - if (!ret.second) { - ANSR_LOGE("Containers add to map error"); - continue; - } + (*it)->SetNotificationOption(bundleOption); } totalCount_ = static_cast(reminderVector_.size()); ReminderRequest::GLOBAL_ID = store_->GetMaxId() + 1; @@ -1705,7 +1636,7 @@ std::string ReminderDataManager::GetSoundUri(const sptr &remind ANSR_LOGE("Ans instance is null."); return uri.GetSchemeSpecificPart(); } - sptr bundle = FindNotificationBundleOption(reminder->GetReminderId()); + sptr bundle = reminder->GetNotificationOption(); std::vector> slots; ErrCode errCode = advancedNotificationService_->GetSlotsByBundle(bundle, slots); if (errCode != ERR_OK) { @@ -1794,13 +1725,6 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) ++it; } } - auto it = notificationBundleOptionMap_.find(reminderId); - if (it == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Remove notificationBundleOption(reminderId=%{public}d) fail", reminderId); - } else { - ANSR_LOGD("Containers(map) remove. reminderId=%{public}d", reminderId); - notificationBundleOptionMap_.erase(it); - } } void ReminderDataManager::StartTimerLocked(const sptr &reminderRequest, TimerType type) diff --git a/services/ans/src/reminder_store.cpp b/services/ans/src/reminder_store.cpp index 1ee399dc5..287f26eef 100644 --- a/services/ans/src/reminder_store.cpp +++ b/services/ans/src/reminder_store.cpp @@ -208,11 +208,6 @@ void ReminderStore::ReminderStoreDataCallBack::InsertNewReminders(NativeRdb::Rdb { for (auto reminder : reminders) { int64_t rowId = STATE_FAIL; - sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - if (bundleOption == nullptr) { - continue; - } - bundleOption->SetBundleName(reminder->GetBundleName()); NativeRdb::ValuesBucket baseValues; ReminderStrategy::AppendValuesBucket(reminder, baseValues, true); @@ -376,20 +371,16 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteUser(const int3 } int32_t ReminderStore::UpdateOrInsert( - const sptr& reminder, const sptr& bundleOption) + const sptr& reminder) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - if (bundleOption == nullptr) { - ANSR_LOGE("BundleOption is null."); - return STATE_FAIL; - } if (IsReminderExist(reminder)) { - return Update(reminder, bundleOption); + return Update(reminder); } else { - return Insert(reminder, bundleOption); + return Insert(reminder); } } @@ -591,7 +582,7 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::str } int32_t ReminderStore::Insert( - const sptr& reminder, const sptr& bundleOption) + const sptr& reminder) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); @@ -648,7 +639,7 @@ int32_t ReminderStore::Insert( } int32_t ReminderStore::Update( - const sptr& reminder, const sptr& bundleOption) + const sptr& reminder) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); -- Gitee From a8ea7edab9d1e905b4dc3ff504b34eacfc224b83 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 14 Oct 2024 17:29:12 +0800 Subject: [PATCH 2/5] optimize reminder store Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 10 +- .../test/unittest/reminder_request_test.cpp | 56 +- .../ans/test/unittest/reminder_store_test.cpp | 28 +- interfaces/inner_api/reminder_request.h | 10 +- interfaces/inner_api/reminder_request_alarm.h | 1 + .../inner_api/reminder_request_calendar.h | 1 + interfaces/inner_api/reminder_request_timer.h | 3 +- services/ans/include/reminder_data_manager.h | 8 - services/ans/include/reminder_store.h | 42 +- .../ans/include/reminder_store_strategy.h | 193 +++-- ...advanced_notification_reminder_service.cpp | 4 +- services/ans/src/reminder_data_manager.cpp | 35 +- services/ans/src/reminder_store.cpp | 278 ++----- services/ans/src/reminder_store_strategy.cpp | 690 ++++++------------ .../unittest/reminder_data_manager_test.cpp | 40 +- .../reminderrequest_fuzzer.cpp | 4 +- .../reminderstore_fuzzer.cpp | 2 +- .../reminderstoreannex_fuzzer.cpp | 5 +- 18 files changed, 521 insertions(+), 889 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 7d6971b07..38e0d8da6 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -228,12 +228,12 @@ void ReminderRequest::SetExpired(bool isExpired) isExpired_ = isExpired; } -void ReminderRequest::InitCreatorBundleName(const std::string &creatorBundleName) +void ReminderRequest::SetCreatorBundleName(const std::string &creatorBundleName) { creatorBundleName_ = creatorBundleName; } -void ReminderRequest::InitCreatorUid(const int32_t creatorUid) +void ReminderRequest::SetCreatorUid(const int32_t creatorUid) { creatorUid_ = creatorUid; } @@ -249,17 +249,17 @@ void ReminderRequest::InitReminderId() ANSR_LOGI("reminderId_=%{public}d", reminderId_); } -void ReminderRequest::InitUserId(const int32_t &userId) +void ReminderRequest::SetUserId(const int32_t &userId) { userId_ = userId; } -void ReminderRequest::InitUid(const int32_t &uid) +void ReminderRequest::SetUid(const int32_t &uid) { uid_ = uid; } -void ReminderRequest::InitBundleName(const std::string &bundleName) +void ReminderRequest::SetBundleName(const std::string &bundleName) { bundleName_ = bundleName; } diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 0489d7cbb..6b2252b51 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1118,12 +1118,12 @@ HWTEST_F(ReminderRequestTest, AddActionButtons_00001, Function | SmallTest | Lev } /** - * @tc.name: InitUserId_00001 - * @tc.desc: Test InitUserId parameters. + * @tc.name: SetUserId_00001 + * @tc.desc: Test SetUserId parameters. * @tc.type: FUNC * @tc.require: issueI65R21 */ -HWTEST_F(ReminderRequestTest, InitUserId_00001, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, SetUserId_00001, Function | SmallTest | Level1) { std::shared_ptr reminderRequestChild = std::make_shared(); ASSERT_NE(nullptr, reminderRequestChild); @@ -1132,8 +1132,8 @@ HWTEST_F(ReminderRequestTest, InitUserId_00001, Function | SmallTest | Level1) std::string function = "this is function"; int32_t userId = 1; int32_t uid = 2; - reminderRequestChild->InitUserId(userId); - reminderRequestChild->InitUid(uid); + reminderRequestChild->SetUserId(userId); + reminderRequestChild->SetUid(uid); reminderRequestChild->SetState(deSet, newState, function); uint8_t result1 = reminderRequestChild->GetState(); EXPECT_EQ(result1, 2); @@ -1160,8 +1160,8 @@ HWTEST_F(ReminderRequestTest, OnStart_00001, Function | SmallTest | Level1) std::string function = "this is function"; int32_t userId = 1; int32_t uid = 2; - reminderRequestChild->InitUserId(userId); - reminderRequestChild->InitUid(uid); + reminderRequestChild->SetUserId(userId); + reminderRequestChild->SetUid(uid); reminderRequestChild->SetState(deSet, newState, function); reminderRequestChild->OnStart(); reminderRequestChild->OnStop(); @@ -1724,30 +1724,30 @@ HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1) } /** - * @tc.name: InitBundleName_00001 - * @tc.desc: Test InitBundleName with normal parameters. + * @tc.name: SetBundleName_00001 + * @tc.desc: Test SetBundleName with normal parameters. * @tc.type: FUNC * @tc.require: issueI89858 */ -HWTEST_F(ReminderRequestTest, InitBundleName_00001, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, SetBundleName_00001, Function | SmallTest | Level1) { auto rrc = std::make_shared(); std::string bundleName = "com.example.myapplication"; - rrc->InitBundleName(bundleName); + rrc->SetBundleName(bundleName); EXPECT_EQ(rrc->GetBundleName(), bundleName); } /** - * @tc.name: InitBundleName_00002 - * @tc.desc: Test InitBundleName with special parameters. + * @tc.name: SetBundleName_00002 + * @tc.desc: Test SetBundleName with special parameters. * @tc.type: FUNC * @tc.require: issueI89858 */ -HWTEST_F(ReminderRequestTest, InitBundleName_00002, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, SetBundleName_00002, Function | SmallTest | Level1) { auto rrc = std::make_shared(); std::string bundleName = "com.example.myapplication.~!@#$%^&*()"; - rrc->InitBundleName(bundleName); + rrc->SetBundleName(bundleName); EXPECT_EQ(rrc->GetBundleName(), bundleName); } @@ -1819,30 +1819,30 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00300, Function | SmallTe } /** - * @tc.name: InitCreatorBundleName_00001 - * @tc.desc: Test InitCreatorBundleName with normal parameters. + * @tc.name: SetCreatorBundleName_00001 + * @tc.desc: Test SetCreatorBundleName with normal parameters. * @tc.type: FUNC * @tc.require: issue#I8R55M */ -HWTEST_F(ReminderRequestTest, InitCreatorBundleName_00001, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, SetCreatorBundleName_00001, Function | SmallTest | Level1) { auto rrc = std::make_shared(); std::string bundleName = "com.example.myapplication"; - rrc->InitCreatorBundleName(bundleName); + rrc->SetCreatorBundleName(bundleName); EXPECT_EQ(rrc->GetCreatorBundleName(), bundleName); } /** - * @tc.name: InitCreatorBundleName_00002 - * @tc.desc: Test InitCreatorBundleName with special parameters. + * @tc.name: SetCreatorBundleName_00002 + * @tc.desc: Test SetCreatorBundleName with special parameters. * @tc.type: FUNC * @tc.require: issue#I8R55M */ -HWTEST_F(ReminderRequestTest, InitCreatorBundleName_00002, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, SetCreatorBundleName_00002, Function | SmallTest | Level1) { auto rrc = std::make_shared(); std::string bundleName = "com.example.myapplication.~!@#$%^&*()"; - rrc->InitCreatorBundleName(bundleName); + rrc->SetCreatorBundleName(bundleName); EXPECT_EQ(rrc->GetCreatorBundleName(), bundleName); } @@ -2145,18 +2145,18 @@ HWTEST_F(ReminderRequestTest, RecoverActionButtonJsonMode_00003, Function | Smal } /** - * @tc.name: InitCreatorUid_00001 - * @tc.desc: Test InitCreatorUid. + * @tc.name: SetCreatorUid_00001 + * @tc.desc: Test SetCreatorUid. * @tc.type: FUNC * @tc.require: issue#I94VJT */ -HWTEST_F(ReminderRequestTest, InitCreatorUid_00001, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, SetCreatorUid_00001, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - rrc->InitCreatorUid(100); + rrc->SetCreatorUid(100); EXPECT_EQ(rrc->GetCreatorUid(), 100); - rrc->InitCreatorUid(-1); + rrc->SetCreatorUid(-1); EXPECT_EQ(rrc->GetCreatorUid(), -1); } } diff --git a/frameworks/ans/test/unittest/reminder_store_test.cpp b/frameworks/ans/test/unittest/reminder_store_test.cpp index d50879009..8a0bdcae6 100644 --- a/frameworks/ans/test/unittest/reminder_store_test.cpp +++ b/frameworks/ans/test/unittest/reminder_store_test.cpp @@ -201,14 +201,14 @@ HWTEST_F(ReminderStoreTest, GetMaxId_00001, Function | SmallTest | Level1) /** * @tc.name: GetAllValidReminders_00001 - * @tc.desc: Test GetAllValidReminders parameters. + * @tc.desc: Test GetAllReminders parameters. * @tc.type: FUNC * @tc.require: issueI5VB6V */ HWTEST_F(ReminderStoreTest, GetAllValidReminders_00001, Function | SmallTest | Level1) { ReminderStore reminderStore; - std::vector> ret = reminderStore.GetAllValidReminders(); + std::vector> ret = reminderStore.GetAllReminders(); EXPECT_EQ(ret.size(), 0); } @@ -353,7 +353,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00001, Function | SmallTes sptr bundleOption = new NotificationBundleOption("test", 101); reminderStore.UpdateOrInsert(reminder, bundleOption); - auto reminders = reminderStore.GetAllValidReminders(); + auto reminders = reminderStore.GetAllReminders(); bool succeed = false; for (auto each : reminders) { if (each->reminderId_ != reminder->reminderId_) { @@ -378,7 +378,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00001, Function | SmallTes succeed = true; break; } - reminderStore.Delete(reminder->reminderId_); + reminderStore.Delete(reminder->reminderId_, reminder->reminderType_); EXPECT_EQ(succeed, true); ClearStore(); } @@ -414,7 +414,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00002, Function | SmallTes sptr bundleOption = new NotificationBundleOption("test", 101); reminderStore.UpdateOrInsert(reminder, bundleOption); - auto reminders = reminderStore.GetAllValidReminders(); + auto reminders = reminderStore.GetAllReminders(); bool succeed = false; for (auto each : reminders) { if (each->reminderId_ != reminder->reminderId_) { @@ -437,7 +437,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00002, Function | SmallTes succeed = true; break; } - reminderStore.Delete(reminder->reminderId_); + reminderStore.Delete(reminder->reminderId_, reminder->reminderType_); EXPECT_EQ(succeed, true); ClearStore(); } @@ -469,7 +469,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00003, Function | SmallTes sptr bundleOption = new NotificationBundleOption("test", 101); reminderStore.UpdateOrInsert(reminder, bundleOption); - auto reminders = reminderStore.GetAllValidReminders(); + auto reminders = reminderStore.GetAllReminders(); bool succeed = false; for (auto each : reminders) { if (each->reminderId_ != reminder->reminderId_) { @@ -485,7 +485,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00003, Function | SmallTes succeed = true; break; } - reminderStore.Delete(reminder->reminderId_); + reminderStore.Delete(reminder->reminderId_, reminder->reminderType_); EXPECT_EQ(succeed, true); ClearStore(); } @@ -510,7 +510,7 @@ HWTEST_F(ReminderStoreTest, ReminderAlarmStrategyTest_00001, Function | SmallTes sptr bundleOption = new NotificationBundleOption("test", 101); reminderStore.UpdateOrInsert(reminder, bundleOption); - auto reminders = reminderStore.GetAllValidReminders(); + auto reminders = reminderStore.GetAllReminders(); bool succeed = false; for (auto each : reminders) { if (each->reminderId_ != reminder->reminderId_) { @@ -524,7 +524,7 @@ HWTEST_F(ReminderStoreTest, ReminderAlarmStrategyTest_00001, Function | SmallTes succeed = true; break; } - reminderStore.Delete(reminder->reminderId_); + reminderStore.Delete(reminder->reminderId_, reminder->reminderType_); EXPECT_EQ(succeed, true); ClearStore(); } @@ -559,7 +559,7 @@ HWTEST_F(ReminderStoreTest, ReminderCalendarStrategyTest_00001, Function | Small sptr bundleOption = new NotificationBundleOption("test", 101); reminderStore.UpdateOrInsert(reminder, bundleOption); - auto reminders = reminderStore.GetAllValidReminders(); + auto reminders = reminderStore.GetAllReminders(); bool succeed = false; for (auto each : reminders) { if (each->reminderId_ != reminder->reminderId_) { @@ -580,7 +580,7 @@ HWTEST_F(ReminderStoreTest, ReminderCalendarStrategyTest_00001, Function | Small succeed = true; break; } - reminderStore.Delete(reminder->reminderId_); + reminderStore.Delete(reminder->reminderId_, reminder->reminderType_); EXPECT_EQ(succeed, true); ClearStore(); } @@ -612,7 +612,7 @@ HWTEST_F(ReminderStoreTest, ReminderCalendarStrategyTest_00002, Function | Small sptr bundleOption = new NotificationBundleOption("test", 101); reminderStore.UpdateOrInsert(reminder, bundleOption); - auto reminders = reminderStore.GetAllValidReminders(); + auto reminders = reminderStore.GetAllReminders(); bool succeed = false; for (auto each : reminders) { if (each->reminderId_ != reminder->reminderId_) { @@ -628,7 +628,7 @@ HWTEST_F(ReminderStoreTest, ReminderCalendarStrategyTest_00002, Function | Small succeed = true; break; } - reminderStore.Delete(reminder->reminderId_); + reminderStore.Delete(reminder->reminderId_, reminder->reminderType_); EXPECT_EQ(succeed, true); ClearStore(); } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 5548a3fa9..bddbd1238 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -481,14 +481,14 @@ public: * * @param creatorBundleName Indicates the creator bundle name which the reminder belong to */ - void InitCreatorBundleName(const std::string &creatorBundleName); + void SetCreatorBundleName(const std::string &creatorBundleName); /** * @brief Inites reminder creator uid when publish reminder success. * * @param uid Indicates the creator uid which the reminder belong to */ - void InitCreatorUid(const int32_t creatorUid); + void SetCreatorUid(const int32_t creatorUid); /** * @brief Inits reminder id when publish reminder success. @@ -505,7 +505,7 @@ public: * * @param userId Indicates the userId which the reminder belong to. */ - void InitUserId(const int32_t &userId); + void SetUserId(const int32_t &userId); /** * @brief Inites reminder uid when publish reminder success. @@ -515,14 +515,14 @@ public: * * @param uid Indicates the uid which the reminder belong to. */ - void InitUid(const int32_t &uid); + void SetUid(const int32_t &uid); /** * @brief Inites reminder bundle name when publish reminder success. * * @param bundleName Indicates the bundle name which the reminder belong to */ - void InitBundleName(const std::string &bundleName); + void SetBundleName(const std::string &bundleName); /** * @brief Check the reminder is alerting or not. diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h index e9f01d922..271f426ca 100644 --- a/interfaces/inner_api/reminder_request_alarm.h +++ b/interfaces/inner_api/reminder_request_alarm.h @@ -47,6 +47,7 @@ public: * @param reminderId Indicates reminder id. */ explicit ReminderRequestAlarm(int32_t reminderId) : ReminderRequest(reminderId) {}; + explicit ReminderRequestAlarm(ReminderType type) : ReminderRequest(type) {}; /** * @brief Copy construct from an exist reminder. diff --git a/interfaces/inner_api/reminder_request_calendar.h b/interfaces/inner_api/reminder_request_calendar.h index 6e2ff9dbc..258cde72e 100644 --- a/interfaces/inner_api/reminder_request_calendar.h +++ b/interfaces/inner_api/reminder_request_calendar.h @@ -59,6 +59,7 @@ public: * @param reminderId Indicates reminder id. */ explicit ReminderRequestCalendar(int32_t reminderId) : ReminderRequest(reminderId) {}; + explicit ReminderRequestCalendar(ReminderType type) : ReminderRequest(type) {}; explicit ReminderRequestCalendar(const ReminderRequestCalendar &other); ReminderRequestCalendar& operator = (const ReminderRequestCalendar &other); diff --git a/interfaces/inner_api/reminder_request_timer.h b/interfaces/inner_api/reminder_request_timer.h index 527b65cbe..5272fa538 100644 --- a/interfaces/inner_api/reminder_request_timer.h +++ b/interfaces/inner_api/reminder_request_timer.h @@ -39,7 +39,8 @@ public: * * @param reminderId Indicates reminder id. */ - explicit ReminderRequestTimer(int32_t reminderId) : ReminderRequest(reminderId) {}; + explicit ReminderRequestTimer(int32_t reminderId) : ReminderRequest(reminderId) {} + explicit ReminderRequestTimer(ReminderType type) : ReminderRequest(type) {}; /** * @brief Copy construct from an exist reminder. diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 2e9237617..c6c608270 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -418,14 +418,6 @@ private: */ sptr FindReminderRequestLocked(const int32_t &reminderId, const std::string &pkgName); - /** - * Find bundle option from {@link notificationBundleOptionMap_} by reminder id. - * - * @param reminderId Indicates the reminder id. - * @return pointer of NotificationBundleOption or nullptr. - */ - sptr FindNotificationBundleOption(const int32_t &reminderId) const; - /** * Obtains the recent reminder which is not expired from reminder vector. * diff --git a/services/ans/include/reminder_store.h b/services/ans/include/reminder_store.h index 4665fce41..6daa8d815 100644 --- a/services/ans/include/reminder_store.h +++ b/services/ans/include/reminder_store.h @@ -18,7 +18,7 @@ #include -#include "reminder_request.h" +#include "reminder_store_strategy.h" #include "rdb_errno.h" #include "rdb_helper.h" #include "rdb_open_callback.h" @@ -33,33 +33,38 @@ public: public: int32_t Init(); - int32_t Delete(const int32_t reminderId); - int32_t Delete(const std::string& pkg, const int32_t userId, const int32_t uid); - int32_t DeleteUser(const int32_t userId); + + /** + * @brief Delete reminder by reminder id, reminder type. + */ + int32_t Delete(const int32_t reminderId, const int32_t type); + /** + * @brief Delete reminder by bundle name, user id, uid. + */ + int32_t Delete(const std::string& bundleName, const int32_t userId, const int32_t uid); + /** + * @brief Delete reminder by user id. + */ + int32_t Delete(const int32_t userId); + /** + * @brief Update if the reminder exists, otherwise insert. + */ int32_t UpdateOrInsert(const sptr& reminder); + /** + * @brief Select all reminders. + */ + std::vector> GetAllReminders(); int32_t GetMaxId(); - std::vector> GetAllValidReminders(); public: - static void GetUInt8Val(const std::shared_ptr& resultSet, - const std::string& name, uint8_t& value); - static void GetUInt16Val(const std::shared_ptr& resultSet, - const std::string& name, uint16_t& value); static void GetInt32Val(const std::shared_ptr& resultSet, const std::string& name, int32_t& value); - static void GetInt64Val(const std::shared_ptr& resultSet, - const std::string& name, int64_t& value); - static void GetUInt64Val(const std::shared_ptr& resultSet, - const std::string& name, uint64_t& value); - static void GetStringVal(const std::shared_ptr& resultSet, - const std::string& name, std::string& value); - static const int32_t STATE_OK; - static const int32_t STATE_FAIL; + static constexpr int32_t STATE_OK = 0; + static constexpr int32_t STATE_FAIL = -1; static const std::string REMINDER_DB_DIR; static const std::string REMINDER_DB_NAME; - static const std::string REMINDER_DB_TABLE; private: /** @@ -86,6 +91,7 @@ private: private: std::shared_ptr rdbStore_ = nullptr; + std::unordered_map> strategy_; private: class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { diff --git a/services/ans/include/reminder_store_strategy.h b/services/ans/include/reminder_store_strategy.h index 0d0ccefb6..933396f32 100644 --- a/services/ans/include/reminder_store_strategy.h +++ b/services/ans/include/reminder_store_strategy.h @@ -15,179 +15,154 @@ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H -#include -#include - #include "reminder_request.h" -#include "rdb_store.h" +#include "result_set.h" +#include "values_bucket.h" namespace OHOS { namespace Notification { -class ReminderStrategy { +class ReminderBaseStrategy { public: - /** - * @brief Gets the value from rdb result. - * - * @param resultSet the rdb result. - * @param name the column name in rdb. - * @param value the column value in rdb. - */ - template - static void GetRdbValue(const std::shared_ptr& resultSet, - const std::string& name, T& value); + ReminderBaseStrategy() = default; + virtual ~ReminderBaseStrategy() = default; -public: /** - * @brief Persist the reminder to the database. + * @brief Store the reminder to the database. */ - static void AppendValuesBucket(const sptr& reminder, - NativeRdb::ValuesBucket &values, const bool oldVersion = false); + virtual void StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, + NativeRdb::ValuesBucket& values) = 0; /** - * @brief Restore the reminder from the database(old version rdb). + * @brief Restore the reminder from the database. */ - static void RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + virtual sptr RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) = 0; /** - * @brief Restore the reminder from the database. + * @brief Get table name. */ - static void RecoverFromDb(sptr& reminder, const std::shared_ptr& resultSet); + virtual std::string GetTableName() = 0; -private: /** - * @brief Recovery time related fields from the database(old version rdb). + * @brief Get table columns. */ - static void RecoverTimeFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + virtual std::string GetTableColumns() = 0; + +protected: /** - * @brief Recovery id related fields from the database(old version rdb). + * @brief Store the reminder to the database(base). */ - static void RecoverIdFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + void StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& values); + /** - * @brief Recovery context related from the database(old version rdb). + * @brief Restore the reminder from the database(base). */ - static void RecoverContextFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + void RestoreFromRdb(sptr& reminder, const std::shared_ptr& results); +private: /** - * @brief Recovery time related fields from the database. + * @brief Restore the time related fields from the database. */ - static void RecoverTimeFromDb(sptr& reminder, - const std::shared_ptr& resultSet); + void RestoreTime(sptr& reminder, const std::shared_ptr& results); /** - * @brief Recovery id related fields from the database. + * @brief Restore the id related fields from the database. */ - static void RecoverIdFromDb(sptr& reminder, - const std::shared_ptr& resultSet); + void RestoreId(sptr& reminder, const std::shared_ptr& results); /** - * @brief Recovery context related from the database. + * @brief Restore the context related from the database. */ - static void RecoverContextFromDb(sptr& reminder, - const std::shared_ptr& resultSet); + void RestoreContext(sptr& reminder, const std::shared_ptr& results); }; -class ReminderTimerStrategy { +class ReminderTimerStrategy : public ReminderBaseStrategy { public: + ReminderTimerStrategy() = default; + ~ReminderTimerStrategy() = default; + + /** + * @brief Store the reminder to the database. + */ + void StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, + NativeRdb::ValuesBucket& values) override; + /** - * @brief Persist the reminder to the database. + * @brief Restore the reminder from the database. */ - static void AppendValuesBucket(const sptr& reminder, - NativeRdb::ValuesBucket& values); + sptr RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) override; /** - * @brief Restore the reminder from the database(old version rdb). + * @brief Get table name. */ - static void RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + std::string GetTableName() override; /** - * @brief Restore the reminder from the database. + * @brief Get table columns. */ - static void RecoverFromDb(sptr& reminder, const std::shared_ptr& baseResult, - const std::shared_ptr& resultSet); + std::string GetTableColumns() override; }; -class ReminderAlarmStrategy { +class ReminderAlarmStrategy : public ReminderBaseStrategy { public: + ReminderAlarmStrategy() = default; + ~ReminderAlarmStrategy() = default; + /** - * @brief Persist the reminder to the database. + * @brief Store the reminder to the database. */ - static void AppendValuesBucket(const sptr &reminder, NativeRdb::ValuesBucket &values); + void StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, + NativeRdb::ValuesBucket& values) override; /** - * @brief Restore the reminder from the database(old version rdb). + * @brief Restore the reminder from the database. */ - static void RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + sptr RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) override; /** - * @brief Restore the reminder from the database. + * @brief Get table name. + */ + std::string GetTableName() override; + + /** + * @brief Get table columns. */ - static void RecoverFromDb(sptr& reminder, const std::shared_ptr& baseResult, - const std::shared_ptr& resultSet); + std::string GetTableColumns() override; }; -class ReminderCalendarStrategy { +class ReminderCalendarStrategy : public ReminderBaseStrategy { public: + ReminderCalendarStrategy() = default; + ~ReminderCalendarStrategy() = default; + /** - * @brief Persist the reminder to the database. + * @brief Store the reminder to the database. */ - static void AppendValuesBucket(const sptr &reminder, NativeRdb::ValuesBucket &values); + void StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, + NativeRdb::ValuesBucket& values) override; /** - * @brief Restore the reminder from the database(old version rdb). + * @brief Restore the reminder from the database. */ - static void RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet); + sptr RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) override; /** - * @brief Restore the reminder from the database. + * @brief Get table name. + */ + std::string GetTableName() override; + + /** + * @brief Get table columns. */ - static void RecoverFromDb(sptr& reminder, const std::shared_ptr& baseResult, - const std::shared_ptr& resultSet); + std::string GetTableColumns() override; private: - static void RecoverTime(sptr& reminder, const std::shared_ptr& resultSet); + /** + * @brief Restore the time related fields from the database. + */ + void RestoreTime(sptr& reminder, const std::shared_ptr& results); }; - -template -void ReminderStrategy::GetRdbValue(const std::shared_ptr& resultSet, - const std::string& name, T& value) -{ - value = T(); - int32_t columnIndex = -1; - resultSet->GetColumnIndex(name, columnIndex); - if (columnIndex == -1) { - ANSR_LOGE("the column %{public}s does not exsit.", name.c_str()); - return; - } - - if constexpr (std::is_same_v) { - resultSet->GetString(columnIndex, value); - } else if constexpr (std::is_same_v) { - resultSet->GetLong(columnIndex, value); - } else if constexpr (std::is_same_v) { - int64_t t = 0; - resultSet->GetLong(columnIndex, t); - value = static_cast(t); - } else if constexpr (std::is_same_v) { - resultSet->GetInt(columnIndex, value); - } else if constexpr (std::is_same_v) { - int32_t t = 0; - resultSet->GetInt(columnIndex, t); - value = static_cast(t); - } else if constexpr (std::is_same_v) { - int32_t t = 0; - resultSet->GetInt(columnIndex, t); - value = static_cast(t); - } else if constexpr (std::is_same_v) { - int32_t t = 0; - resultSet->GetInt(columnIndex, t); - value = static_cast(t); - } -} } // namespace Notification } // namespace OHOS #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H \ No newline at end of file diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index c6ff8843a..cfc64da69 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -70,8 +70,8 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ANSR_LOGD("is system app: %{public}d", AccessTokenHelper::IsSystemApp()); reminder->SetSystemApp(AccessTokenHelper::IsSystemApp()); sptr notificationRequest = reminder->GetNotificationRequest(); - reminder->InitCreatorBundleName(bundle); - reminder->InitCreatorUid(IPCSkeleton::GetCallingUid()); + reminder->SetCreatorBundleName(bundle); + reminder->SetCreatorUid(IPCSkeleton::GetCallingUid()); if (reminder->GetWantAgentInfo() == nullptr || reminder->GetMaxScreenWantAgentInfo() == nullptr) { ANSR_LOGE("wantagent info is nullptr"); return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 134922989..781a7856d 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -179,7 +179,7 @@ ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint std::lock_guard locker(ReminderDataManager::MUTEX); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); calendar->AddExcludeDate(date); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } return ERR_OK; } @@ -196,7 +196,7 @@ ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, std::lock_guard locker(ReminderDataManager::MUTEX); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); calendar->DelExcludeDates(); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } return ERR_OK; } @@ -266,7 +266,7 @@ void ReminderDataManager::CancelRemindersImplLocked(const std::string &packageNa ++vit; } if (packageName == ALL_PACKAGES) { - store_->DeleteUser(userId); + store_->Delete(userId); } else { store_->Delete(packageName, userId, uid); } @@ -411,7 +411,7 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrUpdateOrInsert((*it), bundleOption); + store_->UpdateOrInsert((*it)); } } @@ -434,7 +434,7 @@ void ReminderDataManager::InitTimerInfo(std::shared_ptr &shar reminderRequest->GetReminderType() == ReminderRequest::ReminderType::TIMER)) { #ifdef DEVICE_STANDBY_ENABLE // Get allow list. - std::string name = mit->second->GetBundleName(); + std::string name = reminderRequest->GetBundleName(); std::vector allowInfoList; DevStandbyMgr::StandbyServiceClient::GetInstance().GetAllowList(DevStandbyMgr::AllowType::TIMER, allowInfoList, REASON_APP_API); @@ -539,17 +539,6 @@ sptr ReminderDataManager::FindReminderRequestLocked( return reminder; } -sptr ReminderDataManager::FindNotificationBundleOption(const int32_t &reminderId) const -{ - auto it = notificationBundleOptionMap_.find(reminderId); - if (it == notificationBundleOptionMap_.end()) { - ANSR_LOGW("Failed to get bundle option."); - return nullptr; - } else { - return it->second; - } -} - bool ReminderDataManager::cmp(sptr &reminderRequest, sptr &other) { return reminderRequest->GetTriggerTimeInMilli() < other->GetTriggerTimeInMilli(); @@ -870,9 +859,9 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( reminder->InitReminderId(); int32_t userId = -1; OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); - reminder->InitUserId(userId); - reminder->InitUid(bundleOption->GetUid()); - reminder->InitBundleName(bundleOption->GetBundleName()); + reminder->SetUserId(userId); + reminder->SetUid(bundleOption->GetUid()); + reminder->SetBundleName(bundleOption->GetBundleName()); if (reminder->GetTriggerTimeInMilli() == ReminderRequest::INVALID_LONG_LONG_VALUE) { ANSR_LOGW("now publish reminder is expired. reminder is =%{public}s", reminder->Dump().c_str()); @@ -882,7 +871,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( reminder->SetNotificationOption(bundleOption); reminderVector_.push_back(reminder); totalCount_++; - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::SetService(sptr &advancedNotificationService) @@ -1300,7 +1289,7 @@ sptr ReminderDataManager::GetRecentReminderLocked() ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); it = reminderVector_.erase(it); totalCount_--; - store_->Delete(reminderId); + store_->Delete(reminderId, (*it)->GetReminderType()); } return nullptr; } @@ -1540,7 +1529,7 @@ bool ReminderDataManager::IsBelongToSameApp(const sptr void ReminderDataManager::LoadReminderFromDb() { std::lock_guard lock(ReminderDataManager::MUTEX); - std::vector> existReminders = store_->GetAllValidReminders(); + std::vector> existReminders = store_->GetAllReminders(); reminderVector_ = existReminders; ANSR_LOGD("LoadReminderFromDb, reminder size=%{public}zu", reminderVector_.size()); for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { @@ -1712,7 +1701,7 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); it = reminderVector_.erase(it); totalCount_--; - store_->Delete(reminderId); + store_->Delete(reminderId, (*it)->GetReminderType()); break; } else { ++it; diff --git a/services/ans/src/reminder_store.cpp b/services/ans/src/reminder_store.cpp index 287f26eef..4f7ab12fb 100644 --- a/services/ans/src/reminder_store.cpp +++ b/services/ans/src/reminder_store.cpp @@ -41,8 +41,6 @@ const int32_t REMINDER_RDB_VERSION_V6 = 6; const int32_t REMINDER_RDB_VERSION = 7; } -const int32_t ReminderStore::STATE_OK = 0; -const int32_t ReminderStore::STATE_FAIL = -1; const std::string ReminderStore::REMINDER_DB_DIR = "/data/service/el1/public/notification/"; const std::string ReminderStore::REMINDER_DB_NAME = "notification.db"; @@ -293,47 +291,41 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Init() ANSR_LOGE("ReminderStore init fail, errCode %{public}d.", errCode); return STATE_FAIL; } + + strategy_.emplace(static_cast(ReminderRequest::ReminderType::TIMER), + std::make_shared()); + strategy_.emplace(static_cast(ReminderRequest::ReminderType::CALENDAR), + std::make_shared()); + strategy_.emplace(static_cast(ReminderRequest::ReminderType::ALARM), + std::make_shared()); return InitData(); } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const int32_t reminderId) +int32_t ReminderStore::Delete(const int32_t reminderId, const int32_t type) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } + auto iter = strategy_.find(type); + if (iter == strategy_.end() || iter->second == nullptr) { + ANSR_LOGW("Not find the reminder type[%{public}d] strategy.", type); + return STATE_FAIL; + } + std::string condition = ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminderId); rdbStore_->BeginTransaction(); int32_t delRows = STATE_FAIL; - std::vector whereArgs; - int32_t ret = rdbStore_->Delete(delRows, ReminderBaseTable::TABLE_NAME, condition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderBaseTable::TABLE_NAME.c_str(), reminderId); - rdbStore_->RollBack(); - return STATE_FAIL; - } - delRows = STATE_FAIL; - ret = rdbStore_->Delete(delRows, ReminderAlarmTable::TABLE_NAME, condition, whereArgs); + int32_t ret = rdbStore_->Delete(delRows, ReminderBaseTable::TABLE_NAME, condition); if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderAlarmTable::TABLE_NAME.c_str(), reminderId); + ANSR_LOGE("Delete from reminder_base failed, reminderId:%{public}d.", reminderId); rdbStore_->RollBack(); return STATE_FAIL; } delRows = STATE_FAIL; - ret = rdbStore_->Delete(delRows, ReminderCalendarTable::TABLE_NAME, condition, whereArgs); + ret = rdbStore_->Delete(delRows, iter->second->GetTableName(), condition); if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderCalendarTable::TABLE_NAME.c_str(), reminderId); - rdbStore_->RollBack(); - return STATE_FAIL; - } - delRows = STATE_FAIL; - ret = rdbStore_->Delete(delRows, ReminderTimerTable::TABLE_NAME, condition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderTimerTable::TABLE_NAME.c_str(), reminderId); + ANSR_LOGE("Delete from reminder_* failed, reminderId:%{public}d.", reminderId); rdbStore_->RollBack(); return STATE_FAIL; } @@ -341,14 +333,13 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const int32_t return STATE_OK; } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::string& pkg, const int32_t userId, - const int32_t uid) +int32_t ReminderStore::Delete(const std::string& bundleName, const int32_t userId, const int32_t uid) { std::string assoConditon = "(SELECT " + ReminderBaseTable::REMINDER_ID + " FROM " + ReminderBaseTable::TABLE_NAME - + " WHERE " + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::PACKAGE_NAME + " = '" + pkg + + " WHERE " + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::PACKAGE_NAME + " = '" + bundleName + "' AND " + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::USER_ID + " = " + std::to_string(userId); - std::string baseCondtion = ReminderBaseTable::PACKAGE_NAME + " = '" + pkg + "' AND " + std::string baseCondtion = ReminderBaseTable::PACKAGE_NAME + " = '" + bundleName + "' AND " + ReminderBaseTable::USER_ID + " = " + std::to_string(userId); if (uid != -1) { @@ -360,7 +351,7 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::str return Delete(baseCondtion, assoConditon); } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteUser(const int32_t userId) +int32_t ReminderStore::Delete(const int32_t userId) { std::string assoConditon = "(SELECT " + ReminderBaseTable::REMINDER_ID + " FROM " + ReminderBaseTable::TABLE_NAME + " WHERE " + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::USER_ID + " = " @@ -370,11 +361,10 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteUser(const int3 return Delete(baseCondtion, assoConditon); } -int32_t ReminderStore::UpdateOrInsert( - const sptr& reminder) +int32_t ReminderStore::UpdateOrInsert(const sptr& reminder) { - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); + if (rdbStore_ == nullptr || reminder == nullptr) { + ANSR_LOGE("Rdb store is not initialized or reminder is nullptr."); return STATE_FAIL; } if (IsReminderExist(reminder)) { @@ -384,6 +374,15 @@ int32_t ReminderStore::UpdateOrInsert( } } +std::vector> ReminderStore::GetAllReminders() +{ + std::string sql = "SELECT " + ReminderBaseTable::SELECT_COLUMNS + " FROM " + + ReminderBaseTable::TABLE_NAME + " WHERE " + + ReminderBaseTable::IS_EXPIRED + " = 'false' ORDER BY " + + ReminderBaseTable::TRIGGER_TIME + " ASC"; + return GetReminders(sql); +} + int32_t ReminderStore::GetMaxId() { if (rdbStore_ == nullptr) { @@ -414,32 +413,6 @@ int32_t ReminderStore::GetMaxId() return maxId; } -__attribute__((no_sanitize("cfi"))) std::vector> ReminderStore::GetAllValidReminders() -{ - std::string sql = "SELECT " + ReminderBaseTable::SELECT_COLUMNS + " FROM " - + ReminderBaseTable::TABLE_NAME + " WHERE " - + ReminderBaseTable::IS_EXPIRED + " = 'false' ORDER BY " - + ReminderBaseTable::TRIGGER_TIME + " ASC"; - ANSR_LOGD("GetAllValidReminders sql =%{public}s", sql.c_str()); - return GetReminders(sql); -} - -void ReminderStore::GetUInt8Val(const std::shared_ptr& resultSet, - const std::string& name, uint8_t& value) -{ - int32_t val; - GetInt32Val(resultSet, name, val); - value = static_cast(val); -} - -void ReminderStore::GetUInt16Val(const std::shared_ptr& resultSet, - const std::string& name, uint16_t& value) -{ - int32_t val; - GetInt32Val(resultSet, name, val); - value = static_cast(val); -} - void ReminderStore::GetInt32Val(const std::shared_ptr& resultSet, const std::string& name, int32_t& value) { @@ -453,39 +426,6 @@ void ReminderStore::GetInt32Val(const std::shared_ptr& res resultSet->GetInt(columnIndex, value); } -void ReminderStore::GetInt64Val(const std::shared_ptr& resultSet, - const std::string& name, int64_t& value) -{ - value = 0; - int32_t columnIndex = -1; - resultSet->GetColumnIndex(name, columnIndex); - if (columnIndex == -1) { - ANSR_LOGE("the column %{public}s does not exsit.", name.c_str()); - return; - } - resultSet->GetLong(columnIndex, value); -} - -void ReminderStore::GetUInt64Val(const std::shared_ptr& resultSet, - const std::string& name, uint64_t& value) -{ - int64_t val; - GetInt64Val(resultSet, name, val); - value = static_cast(val); -} - -void ReminderStore::GetStringVal(const std::shared_ptr& resultSet, - const std::string& name, std::string& value) -{ - int32_t columnIndex = -1; - resultSet->GetColumnIndex(name, columnIndex); - if (columnIndex == -1) { - ANSR_LOGE("the column %{public}s does not exsit.", name.c_str()); - return; - } - resultSet->GetString(columnIndex, value); -} - __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::InitData() { ANSR_LOGD("Reminder data init."); @@ -581,117 +521,79 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::str return STATE_OK; } -int32_t ReminderStore::Insert( - const sptr& reminder) +int32_t ReminderStore::Insert(const sptr& reminder) { - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); + int32_t type = static_cast(reminder->GetReminderType()); + auto iter = strategy_.find(type); + if (iter == strategy_.end() || iter->second == nullptr) { + ANSR_LOGW("Not find the reminder type[%{public}d] strategy.", type); return STATE_FAIL; } - int64_t rowId = STATE_FAIL; NativeRdb::ValuesBucket baseValues; - ReminderStrategy::AppendValuesBucket(reminder, baseValues); - + NativeRdb::ValuesBucket values; + iter->second->StoreToRdb(reminder, baseValues, values); + rdbStore_->BeginTransaction(); - // insert reminder_base + int64_t rowId = STATE_FAIL; + int32_t reminderId = reminder->GetReminderId(); + // insert to reminder_base int32_t ret = rdbStore_->Insert(rowId, ReminderBaseTable::TABLE_NAME, baseValues); if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Insert reminder_base operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + ANSR_LOGE("Insert reminder_base failed, result:%{public}d, reminderId:%{public}d.", ret, reminderId); rdbStore_->RollBack(); return STATE_FAIL; } - - // insert reminder_alarm or reminder_calendar - NativeRdb::ValuesBucket values; + + // insert reminder_* rowId = STATE_FAIL; - switch (reminder->GetReminderType()) { - case ReminderRequest::ReminderType::CALENDAR: { - ReminderCalendarStrategy::AppendValuesBucket(reminder, values); - ret = rdbStore_->Insert(rowId, ReminderCalendarTable::TABLE_NAME, values); - break; - } - case ReminderRequest::ReminderType::ALARM: { - ReminderAlarmStrategy::AppendValuesBucket(reminder, values); - ret = rdbStore_->Insert(rowId, ReminderAlarmTable::TABLE_NAME, values); - break; - } - case ReminderRequest::ReminderType::TIMER: { - ReminderTimerStrategy::AppendValuesBucket(reminder, values); - ret = rdbStore_->Insert(rowId, ReminderTimerTable::TABLE_NAME, values); - break; - } - default: { - ANSR_LOGE("Insert reminder_base operation failed, unkown type."); - ret = STATE_FAIL; - break; - } - } + ret = rdbStore_->Insert(rowId, iter->second->GetTableName(), values); if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Insert operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + ANSR_LOGE("Insert reminder_* failed, result:%{public}d, reminderId:%{public}d.", ret, reminderId); rdbStore_->RollBack(); return STATE_FAIL; } rdbStore_->Commit(); - ANSR_LOGD("Insert successfully, reminderId=%{public}d.", reminder->GetReminderId()); + ANSR_LOGD("Insert successfully, reminderId:%{public}d.", reminderId); return STATE_OK; } -int32_t ReminderStore::Update( - const sptr& reminder) +int32_t ReminderStore::Update(const sptr& reminder) { - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); + int32_t type = static_cast(reminder->GetReminderType()); + auto iter = strategy_.find(type); + if (iter == strategy_.end() || iter->second == nullptr) { + ANSR_LOGW("Not find the reminder type[%{public}d] strategy.", type); return STATE_FAIL; } - int32_t rowId = STATE_FAIL; NativeRdb::ValuesBucket baseValues; - ReminderStrategy::AppendValuesBucket(reminder, baseValues); + NativeRdb::ValuesBucket values; + iter->second->StoreToRdb(reminder, baseValues, values); std::string updateCondition = ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); rdbStore_->BeginTransaction(); + int32_t rowId = STATE_FAIL; + int32_t reminderId = reminder->GetReminderId(); // update reminder_base std::vector whereArgs; int32_t ret = rdbStore_->Update(rowId, ReminderBaseTable::TABLE_NAME, baseValues, updateCondition, whereArgs); if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Update reminder_base operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + ANSR_LOGE("Update reminder_base failed, result:%{public}d, reminderId:%{public}d.", ret, reminderId); rdbStore_->RollBack(); return STATE_FAIL; } - // update reminder_alarm or reminder_calendar - NativeRdb::ValuesBucket values; + // update reminder_* rowId = STATE_FAIL; - switch (reminder->GetReminderType()) { - case ReminderRequest::ReminderType::CALENDAR: - ReminderCalendarStrategy::AppendValuesBucket(reminder, values); - ret = rdbStore_->Update(rowId, ReminderCalendarTable::TABLE_NAME, values, updateCondition, whereArgs); - break; - case ReminderRequest::ReminderType::ALARM: - ReminderAlarmStrategy::AppendValuesBucket(reminder, values); - ret = rdbStore_->Update(rowId, ReminderAlarmTable::TABLE_NAME, values, updateCondition, whereArgs); - break; - case ReminderRequest::ReminderType::TIMER: - ReminderTimerStrategy::AppendValuesBucket(reminder, values); - ret = rdbStore_->Update(rowId, ReminderTimerTable::TABLE_NAME, values, updateCondition, whereArgs); - break; - default: - ANSR_LOGE("Insert reminder_base operation failed, unkown type."); - ret = STATE_FAIL; - break; - } + ret = rdbStore_->Update(rowId, iter->second->GetTableName(), values, updateCondition, whereArgs); if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Update operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + ANSR_LOGE("Update reminder_* failed, result:%{public}d, reminderId:%{public}d.", ret, reminderId); rdbStore_->RollBack(); return STATE_FAIL; } rdbStore_->Commit(); - ANSR_LOGD("Update successfully, reminderId=%{public}d.", reminder->GetReminderId()); + ANSR_LOGD("Update successfully, reminderId:%{public}d.", reminderId); return STATE_OK; } @@ -734,43 +636,23 @@ std::vector> ReminderStore::GetReminders(const std::string return reminders; } -sptr ReminderStore::BuildReminder(const std::shared_ptr& resultBase) +sptr ReminderStore::BuildReminder(const std::shared_ptr& baseResults) { - int32_t reminderId; - int32_t reminderType; - GetInt32Val(resultBase, ReminderBaseTable::REMINDER_ID, reminderId); - GetInt32Val(resultBase, ReminderBaseTable::REMINDER_TYPE, reminderType); - - sptr reminder = nullptr; - std::shared_ptr resultSet; - switch (reminderType) { - case (static_cast(ReminderRequest::ReminderType::TIMER)): { - reminder = new (std::nothrow) ReminderRequestTimer(reminderId); - resultSet = Query(ReminderTimerTable::TABLE_NAME, ReminderTimerTable::SELECT_COLUMNS, reminderId); - ReminderTimerStrategy::RecoverFromDb(reminder, resultBase, resultSet); - break; - } - case (static_cast(ReminderRequest::ReminderType::CALENDAR)): { - reminder = new (std::nothrow) ReminderRequestCalendar(reminderId); - resultSet = Query(ReminderCalendarTable::TABLE_NAME, ReminderCalendarTable::SELECT_COLUMNS, reminderId); - ReminderCalendarStrategy::RecoverFromDb(reminder, resultBase, resultSet); - break; - } - case (static_cast(ReminderRequest::ReminderType::ALARM)): { - reminder = new (std::nothrow) ReminderRequestAlarm(reminderId); - resultSet = Query(ReminderAlarmTable::TABLE_NAME, ReminderAlarmTable::SELECT_COLUMNS, reminderId); - ReminderAlarmStrategy::RecoverFromDb(reminder, resultBase, resultSet); - break; - } - default: { - ANSR_LOGE("ReminderType from database is error, reminderType %{public}d.", reminderType); - break; - } + int32_t type = static_cast(ReminderRequest::ReminderType::INVALID); + GetInt32Val(baseResults, ReminderBaseTable::REMINDER_TYPE, type); + auto iter = strategy_.find(type); + if (iter == strategy_.end() || iter->second == nullptr) { + ANSR_LOGW("Not find the reminder type[%{public}d] strategy.", type); + return nullptr; } - if (reminder != nullptr) { - ANSR_LOGI("BuildReminder success."); - } else { - ANSR_LOGW("BuildReminder fail."); + + int32_t reminderId = 0; + GetInt32Val(baseResults, ReminderBaseTable::REMINDER_ID, reminderId); + std::shared_ptr results = Query(iter->second->GetTableName(), + iter->second->GetTableColumns(), reminderId); + sptr reminder = iter->second->RestoreFromRdb(baseResults, results); + if (reminder == nullptr) { + ANSR_LOGW("Restore reminder[%{public}d] failed.", reminderId); } return reminder; } diff --git a/services/ans/src/reminder_store_strategy.cpp b/services/ans/src/reminder_store_strategy.cpp index 814d85d3b..4275be5aa 100644 --- a/services/ans/src/reminder_store_strategy.cpp +++ b/services/ans/src/reminder_store_strategy.cpp @@ -16,18 +16,54 @@ #include "reminder_store_strategy.h" #include "ans_log_wrapper.h" -#include "reminder_store.h" #include "reminder_table.h" -#include "reminder_table_old.h" #include "reminder_request_alarm.h" #include "reminder_request_timer.h" #include "reminder_request_calendar.h" namespace OHOS { namespace Notification { -void ReminderStrategy::AppendValuesBucket(const sptr& reminder, - NativeRdb::ValuesBucket &values, const bool oldVersion) +namespace { +template +void GetRdbValue(const std::shared_ptr& resultSet, + const std::string& name, T& value) { + value = T(); + int32_t columnIndex = -1; + resultSet->GetColumnIndex(name, columnIndex); + if (columnIndex == -1) { + ANSR_LOGW("The column %{public}s does not exsit.", name.c_str()); + return; + } + + if constexpr (std::is_same_v) { + resultSet->GetString(columnIndex, value); + } else if constexpr (std::is_same_v) { + resultSet->GetLong(columnIndex, value); + } else if constexpr (std::is_same_v) { + int64_t t = 0; + resultSet->GetLong(columnIndex, t); + value = static_cast(t); + } else if constexpr (std::is_same_v) { + resultSet->GetInt(columnIndex, value); + } else if constexpr (std::is_same_v) { + int32_t t = 0; + resultSet->GetInt(columnIndex, t); + value = static_cast(t); + } else if constexpr (std::is_same_v) { + int32_t t = 0; + resultSet->GetInt(columnIndex, t); + value = static_cast(t); + } else if constexpr (std::is_same_v) { + int32_t t = 0; + resultSet->GetInt(columnIndex, t); + value = static_cast(t); + } +} +} +void ReminderBaseStrategy::StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& values) +{ + // already check the reminder not nullptr before calling values.PutInt(ReminderBaseTable::REMINDER_ID, reminder->GetReminderId()); values.PutString(ReminderBaseTable::PACKAGE_NAME, reminder->GetBundleName()); values.PutInt(ReminderBaseTable::USER_ID, reminder->GetUserId()); @@ -52,16 +88,11 @@ void ReminderStrategy::AppendValuesBucket(const sptr& reminder, values.PutString(ReminderBaseTable::SNOOZE_CONTENT, reminder->GetSnoozeContent()); values.PutString(ReminderBaseTable::EXPIRED_CONTENT, reminder->GetExpiredContent()); - if (oldVersion) { - values.PutString(ReminderBaseTable::WANT_AGENT, reminder->GetWantAgentStr()); - values.PutString(ReminderBaseTable::MAX_SCREEN_WANT_AGENT, reminder->GetMaxWantAgentStr()); - } else { - std::string wantInfoStr; - std::string maxWantInfoStr; - reminder->SerializeWantAgent(wantInfoStr, maxWantInfoStr); - values.PutString(ReminderBaseTable::WANT_AGENT, wantInfoStr); - values.PutString(ReminderBaseTable::MAX_SCREEN_WANT_AGENT, maxWantInfoStr); - } + std::string wantInfoStr; + std::string maxWantInfoStr; + reminder->SerializeWantAgent(wantInfoStr, maxWantInfoStr); + values.PutString(ReminderBaseTable::WANT_AGENT, wantInfoStr); + values.PutString(ReminderBaseTable::MAX_SCREEN_WANT_AGENT, maxWantInfoStr); values.PutString(ReminderBaseTable::TAP_DISMISSED, reminder->IsTapDismissed() ? "true" : "false"); values.PutLong(ReminderBaseTable::AUTO_DELETED_TIME, reminder->GetAutoDeletedTime()); @@ -71,578 +102,333 @@ void ReminderStrategy::AppendValuesBucket(const sptr& reminder, values.PutInt(ReminderBaseTable::CREATOR_UID, reminder->GetCreatorUid()); } -void ReminderStrategy::RecoverTimeFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) -{ - uint64_t reminderTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::REMINDER_TIME, reminderTime); - reminder->SetReminderTimeInMilli(reminderTime); - - uint64_t triggerTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::TRIGGER_TIME, triggerTime); - reminder->SetTriggerTimeInMilli(triggerTime); - - uint64_t timeInterval = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::TIME_INTERVAL, timeInterval); - reminder->SetTimeInterval(timeInterval); - - uint8_t snoozeTimes = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::SNOOZE_TIMES, snoozeTimes); - reminder->SetSnoozeTimes(snoozeTimes); - - uint8_t dynamicSnoozeTimes = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::DYNAMIC_SNOOZE_TIMES, dynamicSnoozeTimes); - reminder->SetSnoozeTimesDynamic(dynamicSnoozeTimes); - - uint64_t ringDuration = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::RING_DURATION, ringDuration); - reminder->SetRingDuration(ringDuration); - - int64_t autoDeletedTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::AUTO_DELETED_TIME, autoDeletedTime); - reminder->SetAutoDeletedTime(autoDeletedTime); -} - -void ReminderStrategy::RecoverIdFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) -{ - int32_t reminderId = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::REMINDER_ID, reminderId); - reminder->SetReminderId(reminderId); - - int32_t userId = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::USER_ID, userId); - reminder->InitUserId(userId); - - int32_t uid = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::UID, uid); - reminder->InitUid(uid); - - int32_t reminderType = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::REMINDER_TYPE, reminderType); - reminder->SetReminderType(ReminderRequest::ReminderType(reminderType)); - - int32_t slotType = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::SLOT_ID, slotType); - reminder->SetSlotType(NotificationConstant::SlotType(slotType)); - - int32_t snoozeSlotType = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::SNOOZE_SLOT_ID, snoozeSlotType); - reminder->SetSnoozeSlotType(NotificationConstant::SlotType(snoozeSlotType)); - - int32_t notificationId = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::NOTIFICATION_ID, notificationId); - reminder->SetNotificationId(notificationId); - - std::string groupId; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::GROUP_ID, groupId); - reminder->SetGroupId(groupId); -} - -void ReminderStrategy::RecoverContextFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) -{ - std::string bundleName; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::PKG_NAME, bundleName); - reminder->InitBundleName(bundleName); - - std::string title; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::TITLE, title); - reminder->SetTitle(title); - - std::string content; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CONTENT, content); - reminder->SetContent(content); - - std::string snoozeContent; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::SNOOZE_CONTENT, snoozeContent); - reminder->SetSnoozeContent(snoozeContent); - - std::string expiredContent; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::EXPIRED_CONTENT, expiredContent); - reminder->SetExpiredContent(expiredContent); - - std::string customButtonUri; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CUSTOM_BUTTON_URI, customButtonUri); - reminder->SetCustomButtonUri(customButtonUri); - - std::string customRingUri; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CUSTOM_RING_URI, customRingUri); - reminder->SetCustomRingUri(customRingUri); - - std::string creatorBundleName; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CREATOR_BUNDLE_NAME, creatorBundleName); - reminder->InitCreatorBundleName(creatorBundleName); -} - -void ReminderStrategy::RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) +void ReminderBaseStrategy::RestoreFromRdb(sptr& reminder, + const std::shared_ptr& results) { - if (reminder == nullptr || resultSet == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; - } + // already check the reminder and the results not nullptr before calling + RestoreTime(reminder, results); + RestoreId(reminder, results); + RestoreContext(reminder, results); - ReminderStrategy::RecoverTimeFromOldVersion(reminder, resultSet); - ReminderStrategy::RecoverIdFromOldVersion(reminder, resultSet); - ReminderStrategy::RecoverContextFromOldVersion(reminder, resultSet); + uint8_t state = 0; + GetRdbValue(results, ReminderBaseTable::STATE, state); + reminder->SetState(state); std::string isSystemApp; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::SYS_APP, isSystemApp); + GetRdbValue(results, ReminderBaseTable::SYSTEM_APP, isSystemApp); reminder->SetSystemApp(isSystemApp == "true" ? true : false); std::string isExpired; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::IS_EXPIRED, isExpired); + GetRdbValue(results, ReminderBaseTable::IS_EXPIRED, isExpired); reminder->SetExpired(isExpired == "true" ? true : false); std::string actionButtons; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::ACTION_BUTTON_INFO, actionButtons); + GetRdbValue(results, ReminderBaseTable::ACTION_BUTTON_INFO, actionButtons); reminder->DeserializeButtonInfo(actionButtons); - uint8_t state = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::STATE, state); - reminder->SetState(state); - - uint8_t repeatDaysOfWeek = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); - reminder->SetRepeatDaysOfWeek(repeatDaysOfWeek); - + reminder->InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent std::string wantAgent; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::AGENT, wantAgent); - reminder->SetWantAgentStr(wantAgent); + GetRdbValue(results, ReminderBaseTable::WANT_AGENT, wantAgent); + reminder->DeserializeWantAgent(wantAgent, 0); - std::string maxScreenWantAgent; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::MAX_SCREEN_AGENT, maxScreenWantAgent); - reminder->SetMaxWantAgentStr(maxScreenWantAgent); + std::string maxWantAgent; + GetRdbValue(results, ReminderBaseTable::MAX_SCREEN_WANT_AGENT, maxWantAgent); + reminder->DeserializeWantAgent(maxWantAgent, 1); std::string tapDismissed; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::TAP_DISMISSED, tapDismissed); + GetRdbValue(results, ReminderBaseTable::TAP_DISMISSED, tapDismissed); reminder->SetTapDismissed(tapDismissed == "true" ? true : false); } -void ReminderStrategy::RecoverTimeFromDb(sptr& reminder, - const std::shared_ptr& resultSet) +void ReminderBaseStrategy::RestoreTime(sptr& reminder, + const std::shared_ptr& results) { uint64_t reminderTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::REMINDER_TIME, reminderTime); + GetRdbValue(results, ReminderBaseTable::REMINDER_TIME, reminderTime); reminder->SetReminderTimeInMilli(reminderTime); uint64_t triggerTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TRIGGER_TIME, triggerTime); + GetRdbValue(results, ReminderBaseTable::TRIGGER_TIME, triggerTime); reminder->SetTriggerTimeInMilli(triggerTime); uint64_t timeInterval = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TIME_INTERVAL, timeInterval); + GetRdbValue(results, ReminderBaseTable::TIME_INTERVAL, timeInterval); reminder->SetTimeInterval(timeInterval); uint8_t snoozeTimes = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SNOOZE_TIMES, snoozeTimes); + GetRdbValue(results, ReminderBaseTable::SNOOZE_TIMES, snoozeTimes); reminder->SetSnoozeTimes(snoozeTimes); uint8_t dynamicSnoozeTimes = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::DYNAMIC_SNOOZE_TIMES, dynamicSnoozeTimes); + GetRdbValue(results, ReminderBaseTable::DYNAMIC_SNOOZE_TIMES, dynamicSnoozeTimes); reminder->SetSnoozeTimesDynamic(dynamicSnoozeTimes); uint64_t ringDuration = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::RING_DURATION, ringDuration); + GetRdbValue(results, ReminderBaseTable::RING_DURATION, ringDuration); reminder->SetRingDuration(ringDuration); int64_t autoDeletedTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::AUTO_DELETED_TIME, autoDeletedTime); + GetRdbValue(results, ReminderBaseTable::AUTO_DELETED_TIME, autoDeletedTime); reminder->SetAutoDeletedTime(autoDeletedTime); } -void ReminderStrategy::RecoverIdFromDb(sptr& reminder, - const std::shared_ptr& resultSet) +void ReminderBaseStrategy::RestoreId(sptr& reminder, + const std::shared_ptr& results) { int32_t reminderId = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::REMINDER_ID, reminderId); + GetRdbValue(results, ReminderBaseTable::REMINDER_ID, reminderId); reminder->SetReminderId(reminderId); int32_t userId = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::USER_ID, userId); - reminder->InitUserId(userId); + GetRdbValue(results, ReminderBaseTable::USER_ID, userId); + reminder->SetUserId(userId); int32_t uid = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::UID, uid); - reminder->InitUid(uid); - - int32_t reminderType = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::REMINDER_TYPE, reminderType); - reminder->SetReminderType(ReminderRequest::ReminderType(reminderType)); + GetRdbValue(results, ReminderBaseTable::UID, uid); + reminder->SetUid(uid); int32_t slotType = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SLOT_ID, slotType); + GetRdbValue(results, ReminderBaseTable::SLOT_ID, slotType); reminder->SetSlotType(NotificationConstant::SlotType(slotType)); int32_t snoozeSlotType = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SNOOZE_SLOT_ID, snoozeSlotType); + GetRdbValue(results, ReminderBaseTable::SNOOZE_SLOT_ID, snoozeSlotType); reminder->SetSnoozeSlotType(NotificationConstant::SlotType(snoozeSlotType)); int32_t notificationId = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::NOTIFICATION_ID, notificationId); + GetRdbValue(results, ReminderBaseTable::NOTIFICATION_ID, notificationId); reminder->SetNotificationId(notificationId); std::string groupId; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::GROUP_ID, groupId); + GetRdbValue(results, ReminderBaseTable::GROUP_ID, groupId); reminder->SetGroupId(groupId); int32_t creatorUid; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_UID, creatorUid); - reminder->InitCreatorUid(creatorUid); + GetRdbValue(results, ReminderBaseTable::CREATOR_UID, creatorUid); + reminder->SetCreatorUid(creatorUid); } -void ReminderStrategy::RecoverContextFromDb(sptr& reminder, - const std::shared_ptr& resultSet) +void ReminderBaseStrategy::RestoreContext(sptr& reminder, + const std::shared_ptr& results) { std::string bundleName; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::PACKAGE_NAME, bundleName); - reminder->InitBundleName(bundleName); + GetRdbValue(results, ReminderBaseTable::PACKAGE_NAME, bundleName); + reminder->SetBundleName(bundleName); std::string customButtonUri; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CUSTOM_BUTTON_URI, customButtonUri); + GetRdbValue(results, ReminderBaseTable::CUSTOM_BUTTON_URI, customButtonUri); reminder->SetCustomButtonUri(customButtonUri); std::string title; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TITLE, title); + GetRdbValue(results, ReminderBaseTable::TITLE, title); reminder->SetTitle(title); std::string content; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CONTENT, content); + GetRdbValue(results, ReminderBaseTable::CONTENT, content); reminder->SetContent(content); std::string snoozeContent; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SNOOZE_CONTENT, snoozeContent); + GetRdbValue(results, ReminderBaseTable::SNOOZE_CONTENT, snoozeContent); reminder->SetSnoozeContent(snoozeContent); std::string expiredContent; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::EXPIRED_CONTENT, expiredContent); + GetRdbValue(results, ReminderBaseTable::EXPIRED_CONTENT, expiredContent); reminder->SetExpiredContent(expiredContent); std::string customRingUri; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CUSTOM_RING_URI, customRingUri); + GetRdbValue(results, ReminderBaseTable::CUSTOM_RING_URI, customRingUri); reminder->SetCustomRingUri(customRingUri); std::string creatorBundleName; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_BUNDLE_NAME, creatorBundleName); - reminder->InitCreatorBundleName(creatorBundleName); + GetRdbValue(results, ReminderBaseTable::CREATOR_BUNDLE_NAME, creatorBundleName); + reminder->SetCreatorBundleName(creatorBundleName); } -void ReminderStrategy::RecoverFromDb(sptr& reminder, - const std::shared_ptr& resultSet) -{ - if (reminder == nullptr || resultSet == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; - } - ReminderStrategy::RecoverTimeFromDb(reminder, resultSet); - ReminderStrategy::RecoverIdFromDb(reminder, resultSet); - ReminderStrategy::RecoverContextFromDb(reminder, resultSet); - - uint8_t state = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::STATE, state); - reminder->SetState(state); - - std::string isSystemApp; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SYSTEM_APP, isSystemApp); - reminder->SetSystemApp(isSystemApp == "true" ? true : false); - - std::string isExpired; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::IS_EXPIRED, isExpired); - reminder->SetExpired(isExpired == "true" ? true : false); - - std::string actionButtons; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::ACTION_BUTTON_INFO, actionButtons); - reminder->DeserializeButtonInfo(actionButtons); - - reminder->InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent - std::string wantAgent; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::WANT_AGENT, wantAgent); - reminder->DeserializeWantAgent(wantAgent, 0); - - std::string maxWantAgent; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::MAX_SCREEN_WANT_AGENT, maxWantAgent); - reminder->DeserializeWantAgent(maxWantAgent, 1); - - std::string tapDismissed; - ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TAP_DISMISSED, tapDismissed); - reminder->SetTapDismissed(tapDismissed == "true" ? true : false); -} - -void ReminderTimerStrategy::AppendValuesBucket(const sptr& reminder, +void ReminderTimerStrategy::StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, NativeRdb::ValuesBucket& values) { - uint64_t seconds = 0; - if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) { - ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); - seconds = timer->GetInitInfo(); - } + ReminderBaseStrategy::StoreToRdb(reminder, baseValues); + // already check the reminder not nullptr and type is timer before calling + ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); values.PutInt(ReminderTimerTable::REMINDER_ID, reminder->GetReminderId()); - values.PutLong(ReminderTimerTable::TRIGGER_SECOND, seconds); + values.PutLong(ReminderTimerTable::TRIGGER_SECOND, timer->GetInitInfo()); values.PutLong(ReminderTimerTable::START_DATE_TIME, 0); values.PutLong(ReminderTimerTable::END_DATE_TIME, 0); } -void ReminderTimerStrategy::RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) +sptr ReminderTimerStrategy::RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) { - if (resultSet == nullptr || reminder == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; + if (baseResults == nullptr || results == nullptr) { + ANSR_LOGW("ResultSet is nullptr."); + return nullptr; } - ReminderStrategy::RecoverFromOldVersion(reminder, resultSet); + sptr reminder = sptr::MakeSptr(ReminderRequest::ReminderType::TIMER); + ReminderBaseStrategy::RestoreFromRdb(reminder, baseResults); + ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); + + uint64_t seconds = 0; + GetRdbValue(results, ReminderTimerTable::TRIGGER_SECOND, seconds); + timer->SetInitInfo(seconds); + return reminder; } -void ReminderTimerStrategy::RecoverFromDb(sptr& reminder, - const std::shared_ptr& baseResult, const std::shared_ptr& resultSet) +std::string ReminderTimerStrategy::GetTableName() { - if (resultSet == nullptr || reminder == nullptr || baseResult == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; - } - ReminderStrategy::RecoverFromDb(reminder, baseResult); - if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) { - ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); - uint64_t seconds; - ReminderStrategy::GetRdbValue(resultSet, ReminderTimerTable::TRIGGER_SECOND, seconds); - timer->SetInitInfo(seconds); - } + return ReminderTimerTable::TABLE_NAME; } -void ReminderAlarmStrategy::AppendValuesBucket(const sptr& reminder, +std::string ReminderTimerStrategy::GetTableColumns() +{ + return ReminderTimerTable::SELECT_COLUMNS; +} + +void ReminderAlarmStrategy::StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, NativeRdb::ValuesBucket& values) { - uint8_t hour = 0; - uint8_t minute = 0; - uint8_t repeatDaysOfWeek = 0; - if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) { - ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); - hour = alarm->GetHour(); - minute = alarm->GetMinute(); - repeatDaysOfWeek = alarm->GetRepeatDaysOfWeek(); - } + ReminderBaseStrategy::StoreToRdb(reminder, baseValues); + // already check the reminder not nullptr and type is alarm before calling + ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); values.PutInt(ReminderAlarmTable::REMINDER_ID, reminder->GetReminderId()); - values.PutInt(ReminderAlarmTable::ALARM_HOUR, hour); - values.PutInt(ReminderAlarmTable::ALARM_MINUTE, minute); - values.PutInt(ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); + values.PutInt(ReminderAlarmTable::ALARM_HOUR, alarm->GetHour()); + values.PutInt(ReminderAlarmTable::ALARM_MINUTE, alarm->GetMinute()); + values.PutInt(ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, alarm->GetRepeatDaysOfWeek()); } -void ReminderAlarmStrategy::RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) +sptr ReminderAlarmStrategy::RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) { - if (resultSet == nullptr || reminder == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; + if (baseResults == nullptr || results == nullptr) { + ANSR_LOGW("ResultSet is nullptr."); + return nullptr; } - ReminderStrategy::RecoverFromOldVersion(reminder, resultSet); + sptr reminder = sptr::MakeSptr(ReminderRequest::ReminderType::ALARM); + ReminderBaseStrategy::RestoreFromRdb(reminder, baseResults); + ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); - if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) { - ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); - uint8_t hour = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::ALARM_HOUR, hour); - alarm->SetHour(hour); + uint8_t hour = 0; + GetRdbValue(results, ReminderAlarmTable::ALARM_HOUR, hour); + alarm->SetHour(hour); - uint8_t minute = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::ALARM_MINUTE, minute); - alarm->SetMinute(minute); - } + uint8_t minute = 0; + GetRdbValue(results, ReminderAlarmTable::ALARM_MINUTE, minute); + alarm->SetMinute(minute); + + uint8_t repeatDaysOfWeek = 0; + GetRdbValue(results, ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); + alarm->SetRepeatDaysOfWeek(repeatDaysOfWeek); + return reminder; } -void ReminderAlarmStrategy::RecoverFromDb(sptr& reminder, - const std::shared_ptr& baseResult, const std::shared_ptr& resultSet) +std::string ReminderAlarmStrategy::GetTableName() { - if (resultSet == nullptr || reminder == nullptr || baseResult == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; - } - ReminderStrategy::RecoverFromDb(reminder, baseResult); - if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) { - ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); - uint8_t hour = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderAlarmTable::ALARM_HOUR, hour); - alarm->SetHour(hour); - - uint8_t minute = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderAlarmTable::ALARM_MINUTE, minute); - alarm->SetMinute(minute); - - uint8_t repeatDaysOfWeek = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); - alarm->SetRepeatDaysOfWeek(repeatDaysOfWeek); - } + return ReminderAlarmTable::TABLE_NAME; +} + +std::string ReminderAlarmStrategy::GetTableColumns() +{ + return ReminderAlarmTable::SELECT_COLUMNS; } -void ReminderCalendarStrategy::AppendValuesBucket(const sptr& reminder, +void ReminderCalendarStrategy::StoreToRdb(const sptr& reminder, NativeRdb::ValuesBucket& baseValues, NativeRdb::ValuesBucket& values) { - uint16_t firstDesignateYear = 0; - uint8_t firstDesignateMonth = 0; - uint8_t firstDesignateDay = 0; - uint64_t dateTime = 0; + ReminderBaseStrategy::StoreToRdb(reminder, baseValues); + // already check the reminder not nullptr and type is calendar before calling + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + values.PutInt(ReminderCalendarTable::REMINDER_ID, reminder->GetReminderId()); + values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_YEAR, calendar->GetFirstDesignateYear()); + values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_MONTH, calendar->GetFirstDesignageMonth()); + values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_DAY, calendar->GetFirstDesignateDay()); + values.PutLong(ReminderCalendarTable::CALENDAR_DATE_TIME, calendar->GetDateTime()); + values.PutLong(ReminderCalendarTable::CALENDAR_END_DATE_TIME, calendar->GetEndDateTime()); + values.PutLong(ReminderCalendarTable::CALENDAR_LAST_DATE_TIME, calendar->GetLastStartDateTime()); + values.PutInt(ReminderCalendarTable::REPEAT_DAYS, calendar->GetRepeatDay()); + values.PutInt(ReminderCalendarTable::REPEAT_MONTHS, calendar->GetRepeatMonth()); + values.PutInt(ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, calendar->GetRepeatDaysOfWeek()); + values.PutString(ReminderCalendarTable::RRULE_WANT_AGENT, calendar->SerializationRRule()); + values.PutString(ReminderCalendarTable::EXCLUDE_DATES, calendar->SerializationExcludeDates()); +} + +sptr ReminderCalendarStrategy::RestoreFromRdb(const std::shared_ptr& baseResults, + const std::shared_ptr& results) +{ + if (baseResults == nullptr || results == nullptr) { + ANSR_LOGW("ResultSet is nullptr."); + return nullptr; + } + sptr reminder = sptr::MakeSptr(ReminderRequest::ReminderType::CALENDAR); + ReminderBaseStrategy::RestoreFromRdb(reminder, baseResults); + RestoreTime(reminder, results); + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + uint32_t repeatDay = 0; + GetRdbValue(results, ReminderCalendarTable::REPEAT_DAYS, repeatDay); + calendar->SetRepeatDay(repeatDay); + uint16_t repeatMonth = 0; + GetRdbValue(results, ReminderCalendarTable::REPEAT_MONTHS, repeatMonth); + calendar->SetRepeatMonth(repeatMonth); + uint8_t repeatDaysOfWeek = 0; - uint64_t endDateTime = 0; - uint64_t lastStartDateTime = 0; + GetRdbValue(results, ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); + calendar->SetRepeatDaysOfWeek(repeatDaysOfWeek); + std::string rruleWantAgent; + GetRdbValue(results, ReminderCalendarTable::RRULE_WANT_AGENT, rruleWantAgent); + calendar->DeserializationRRule(rruleWantAgent); + std::string excludeDates; - if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { - ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - if (calendar != nullptr) { - repeatDay = calendar->GetRepeatDay(); - repeatMonth = calendar->GetRepeatMonth(); - firstDesignateYear = calendar->GetFirstDesignateYear(); - firstDesignateMonth = calendar->GetFirstDesignageMonth(); - firstDesignateDay = calendar->GetFirstDesignateDay(); - dateTime = calendar->GetDateTime(); - repeatDaysOfWeek = calendar->GetRepeatDaysOfWeek(); - endDateTime = calendar->GetEndDateTime(); - lastStartDateTime = calendar->GetLastStartDateTime(); - rruleWantAgent = calendar->SerializationRRule(); - excludeDates = calendar->SerializationExcludeDates(); - } - } - values.PutInt(ReminderCalendarTable::REMINDER_ID, reminder->GetReminderId()); - values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_YEAR, firstDesignateYear); - values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth); - values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_DAY, firstDesignateDay); - values.PutLong(ReminderCalendarTable::CALENDAR_DATE_TIME, dateTime); - values.PutLong(ReminderCalendarTable::CALENDAR_END_DATE_TIME, endDateTime); - values.PutLong(ReminderCalendarTable::CALENDAR_LAST_DATE_TIME, lastStartDateTime); - values.PutInt(ReminderCalendarTable::REPEAT_DAYS, repeatDay); - values.PutInt(ReminderCalendarTable::REPEAT_MONTHS, repeatMonth); - values.PutInt(ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); - values.PutString(ReminderCalendarTable::RRULE_WANT_AGENT, rruleWantAgent); - values.PutString(ReminderCalendarTable::EXCLUDE_DATES, excludeDates); + GetRdbValue(results, ReminderCalendarTable::EXCLUDE_DATES, excludeDates); + calendar->DeserializationExcludeDates(excludeDates); + return reminder; } -void ReminderCalendarStrategy::RecoverFromOldVersion(sptr& reminder, - const std::shared_ptr& resultSet) +std::string ReminderCalendarStrategy::GetTableName() { - if (resultSet == nullptr || reminder == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; - } - ReminderStrategy::RecoverFromOldVersion(reminder, resultSet); - if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { - ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - uint32_t repeatDay = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::REPEAT_DAYS, repeatDay); - calendar->SetRepeatDay(repeatDay); - - uint16_t repeatMonth = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::REPEAT_MONTHS, repeatMonth); - calendar->SetRepeatMonth(repeatMonth); - - uint16_t firstDesignateYear = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::FIRST_DESIGNATE_YEAR, firstDesignateYear); - calendar->SetFirstDesignateYear(firstDesignateYear); - - uint8_t firstDesignateMonth = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth); - calendar->SetFirstDesignageMonth(firstDesignateMonth); - - uint8_t firstDesignateDay = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::FIRST_DESIGNATE_DAY, firstDesignateDay); - calendar->SetFirstDesignateDay(firstDesignateDay); - - uint16_t year = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CALENDAR_YEAR, year); - calendar->SetYear(year); - - uint8_t month = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CALENDAR_MONTH, month); - calendar->SetMonth(month); - - uint8_t day = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CALENDAR_DAY, day); - calendar->SetDay(day); - - uint8_t hour = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CALENDAR_HOUR, hour); - calendar->SetHour(hour); - - uint8_t minute = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderTable::CALENDAR_MINUTE, minute); - calendar->SetMinute(minute); - } + return ReminderCalendarTable::TABLE_NAME; } -void ReminderCalendarStrategy::RecoverTime(sptr& reminder, - const std::shared_ptr& resultSet) +std::string ReminderCalendarStrategy::GetTableColumns() { - if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { - ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - - uint16_t firstDesignateYear = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_YEAR, - firstDesignateYear); - calendar->SetFirstDesignateYear(firstDesignateYear); - - uint8_t firstDesignateMonth = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_MONTH, - firstDesignateMonth); - calendar->SetFirstDesignageMonth(firstDesignateMonth); - - uint8_t firstDesignateDay = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_DAY, - firstDesignateDay); - calendar->SetFirstDesignateDay(firstDesignateDay); - - uint64_t dateTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::CALENDAR_DATE_TIME, dateTime); - calendar->SetDateTime(dateTime); - - uint64_t endDateTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::CALENDAR_END_DATE_TIME, endDateTime); - if (endDateTime != 0 && endDateTime >= dateTime) { - calendar->SetEndDateTime(endDateTime); - } else { - calendar->SetEndDateTime(dateTime); - } - - uint64_t lastStartDateTime = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::CALENDAR_LAST_DATE_TIME, - lastStartDateTime); - if (lastStartDateTime == 0) { - calendar->SetLastStartDateTime(dateTime); - } else { - calendar->SetLastStartDateTime(lastStartDateTime); - } - } + return ReminderCalendarTable::SELECT_COLUMNS; } -void ReminderCalendarStrategy::RecoverFromDb(sptr& reminder, - const std::shared_ptr& baseResult, const std::shared_ptr& resultSet) +void ReminderCalendarStrategy::RestoreTime(sptr& reminder, + const std::shared_ptr& results) { - if (resultSet == nullptr || reminder == nullptr || baseResult == nullptr) { - ANSR_LOGE("ResultSet is null or reminder is null"); - return; + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + + uint16_t firstDesignateYear = 0; + GetRdbValue(results, ReminderCalendarTable::FIRST_DESIGNATE_YEAR, firstDesignateYear); + calendar->SetFirstDesignateYear(firstDesignateYear); + + uint8_t firstDesignateMonth = 0; + GetRdbValue(results, ReminderCalendarTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth); + calendar->SetFirstDesignageMonth(firstDesignateMonth); + + uint8_t firstDesignateDay = 0; + GetRdbValue(results, ReminderCalendarTable::FIRST_DESIGNATE_DAY, firstDesignateDay); + calendar->SetFirstDesignateDay(firstDesignateDay); + + uint64_t dateTime = 0; + GetRdbValue(results, ReminderCalendarTable::CALENDAR_DATE_TIME, dateTime); + calendar->SetDateTime(dateTime); + + uint64_t endDateTime = 0; + GetRdbValue(results, ReminderCalendarTable::CALENDAR_END_DATE_TIME, endDateTime); + if (endDateTime != 0 && endDateTime >= dateTime) { + calendar->SetEndDateTime(endDateTime); + } else { + calendar->SetEndDateTime(dateTime); } - ReminderStrategy::RecoverFromDb(reminder, baseResult); - ReminderCalendarStrategy::RecoverTime(reminder, resultSet); - if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { - ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - - uint32_t repeatDay = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::REPEAT_DAYS, repeatDay); - calendar->SetRepeatDay(repeatDay); - - uint16_t repeatMonth = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::REPEAT_MONTHS, repeatMonth); - calendar->SetRepeatMonth(repeatMonth); - - uint8_t repeatDaysOfWeek = 0; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek); - calendar->SetRepeatDaysOfWeek(repeatDaysOfWeek); - - std::string rruleWantAgent; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::RRULE_WANT_AGENT, rruleWantAgent); - calendar->DeserializationRRule(rruleWantAgent); - - std::string excludeDates; - ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::EXCLUDE_DATES, excludeDates); - calendar->DeserializationExcludeDates(excludeDates); + + uint64_t lastStartDateTime = 0; + GetRdbValue(results, ReminderCalendarTable::CALENDAR_LAST_DATE_TIME, lastStartDateTime); + if (lastStartDateTime == 0) { + calendar->SetLastStartDateTime(dateTime); + } else { + calendar->SetLastStartDateTime(lastStartDateTime); } } } diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index 85e78560d..20eab6d7b 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -423,7 +423,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_016, Level1) std::shared_ptr buttonDataShareUpdate1 = std::make_shared(); reminder1->SetSystemApp(true); - reminder1->InitUserId(100); + reminder1->SetUserId(100); buttonDataShareUpdate1->uri = "datashareTest://com.acts.dataShareTest"; buttonDataShareUpdate1->equalTo = "namestringli" "iddouble3.0statusbooltrue"; @@ -653,12 +653,12 @@ HWTEST_F(ReminderDataManagerTest, IsBelongToSameAppTest_001, Level1) HWTEST_F(ReminderDataManagerTest, CheckIsSameAppTest_001, Level1) { sptr reminder = new ReminderRequestTimer(10); - reminder->InitCreatorBundleName("test"); - reminder->InitUserId(-1); + reminder->SetCreatorBundleName("test"); + reminder->SetUserId(-1); sptr option = new NotificationBundleOption("test", -1); EXPECT_TRUE(manager->CheckIsSameApp(reminder, option)); - reminder->InitCreatorBundleName("test1"); + reminder->SetCreatorBundleName("test1"); EXPECT_FALSE(manager->CheckIsSameApp(reminder, option)); } @@ -725,15 +725,15 @@ HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); sptr reminder = new ReminderRequestCalendar(10); - reminder->InitCreatorBundleName("test1"); - reminder->InitUserId(-1); + reminder->SetCreatorBundleName("test1"); + reminder->SetUserId(-1); reminder->reminderId_ = 100; manager->reminderVector_.push_back(reminder); sptr option = new NotificationBundleOption("test", -1); result = manager->CheckExcludeDateParam(100, option); EXPECT_TRUE(result == nullptr); - reminder->InitCreatorBundleName("test"); + reminder->SetCreatorBundleName("test"); reminder->reminderType_ = ReminderRequest::ReminderType::TIMER; result = manager->CheckExcludeDateParam(100, option); EXPECT_TRUE(result == nullptr); @@ -841,19 +841,19 @@ HWTEST_F(ReminderDataManagerTest, CancelAllReminders_00001, Level1) HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) { sptr reminder1 = new ReminderRequestTimer(static_cast(50)); - reminder1->InitCreatorBundleName("test_getvalid"); - reminder1->InitCreatorUid(98765); - reminder1->InitBundleName("test_getvalid"); - reminder1->InitUid(98765); + reminder1->SetCreatorBundleName("test_getvalid"); + reminder1->SetCreatorUid(98765); + reminder1->SetBundleName("test_getvalid"); + reminder1->SetUid(98765); sptr option1 = new NotificationBundleOption("test_getvalid", 98765); manager->PublishReminder(reminder1, option1); reminder1->SetExpired(false); sptr reminder2 = new ReminderRequestTimer(51); - reminder2->InitCreatorBundleName("test_getvalid"); - reminder2->InitCreatorUid(98765); - reminder2->InitBundleName("test_getvalid"); - reminder2->InitUid(98765); + reminder2->SetCreatorBundleName("test_getvalid"); + reminder2->SetCreatorUid(98765); + reminder2->SetBundleName("test_getvalid"); + reminder2->SetUid(98765); reminder2->SetExpired(true); sptr option2 = new NotificationBundleOption("test_getvalid", 98765); manager->PublishReminder(reminder2, option2); @@ -872,11 +872,11 @@ HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) HWTEST_F(ReminderDataManagerTest, IsMatched_00001, Level1) { sptr reminder = new ReminderRequestTimer(50); - reminder->InitCreatorBundleName("test_IsMatched"); - reminder->InitCreatorUid(98765); - reminder->InitBundleName("test_IsMatched"); - reminder->InitUid(98765); - reminder->InitUserId(100); + reminder->SetCreatorBundleName("test_IsMatched"); + reminder->SetCreatorUid(98765); + reminder->SetBundleName("test_IsMatched"); + reminder->SetUid(98765); + reminder->SetUserId(100); bool ret = manager->IsMatched(reminder, "test_IsMatched", 101, 98765); EXPECT_EQ(ret, false); ret = manager->IsMatched(reminder, "allPackages", 100, 98765); diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp index 8cc3dfb7a..9785205b4 100644 --- a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp @@ -43,8 +43,8 @@ namespace OHOS { bool enabled = *data % ENABLE; reminderRequest.SetExpired(enabled); reminderRequest.InitReminderId(); - reminderRequest.InitUserId(reminderId); - reminderRequest.InitUid(reminderId); + reminderRequest.SetUserId(reminderId); + reminderRequest.SetUid(reminderId); reminderRequest.IsExpired(); reminderRequest.IsShowing(); reminderRequest.OnClose(enabled); diff --git a/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp index 2d334cc51..e7dff2891 100644 --- a/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp +++ b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp @@ -28,8 +28,8 @@ namespace OHOS { int32_t oldVersion = static_cast(GetU32Data(data)); reminderStore.Init(); reminderStore.InitData(); + reminderStore.Delete(oldVersion, oldVersion); reminderStore.Delete(oldVersion); - reminderStore.DeleteUser(oldVersion); reminderStore.Delete(stringData, oldVersion, oldVersion); return reminderStore.DeleteBase(stringData); } diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp index 9d691c582..074346e63 100644 --- a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp @@ -27,8 +27,8 @@ namespace OHOS { // test GetReminders function std::string queryCondition(data); reminderStore.GetReminders(queryCondition); - // test GetAllValidReminders function - reminderStore.GetAllValidReminders(); + // test GetAllReminders function + reminderStore.GetAllReminders(); // test Query function reminderStore.Query(queryCondition); // test GetInt32Val function @@ -37,7 +37,6 @@ namespace OHOS { int32_t value = static_cast(GetU32Data(data)); reminderStore.GetInt32Val(resultSet, name, value); std::string value1(data); - reminderStore.GetStringVal(resultSet, name, value1); return true; } } -- Gitee From f7575438cf664d61f37c572f1f242f913375a2d8 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 30 Oct 2024 17:15:15 +0800 Subject: [PATCH 3/5] update Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 382 ++++----- .../reminder_request_branch_test.cpp | 6 +- .../test/unittest/reminder_request_test.cpp | 12 +- .../napi/include/reminder/reminder_common.h | 2 +- .../js/napi/src/reminder/reminder_common.cpp | 6 +- interfaces/inner_api/reminder_request.h | 726 +++++++++--------- .../unittest/reminder_data_manager_test.cpp | 8 +- .../reminderrequest_fuzzer.cpp | 4 +- 8 files changed, 512 insertions(+), 634 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 04866895e..aed3e648a 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -31,33 +31,33 @@ namespace OHOS { namespace Notification { namespace { -const int32_t BASE_YEAR = 1900; -const int32_t SINGLE_BUTTON_INVALID = 0; -const int32_t SINGLE_BUTTON_JSONSTRING = 0; -const int32_t SINGLE_BUTTON_ONLY_ONE = 1; -const int32_t SINGLE_BUTTON_MIN_LEN = 2; -const int32_t SINGLE_BUTTON_MAX_LEN = 4; -const int32_t BUTTON_TYPE_INDEX = 0; -const int32_t BUTTON_TITLE_INDEX = 1; -const int32_t BUTTON_PKG_INDEX = 2; -const int32_t BUTTON_ABILITY_INDEX = 3; -const int32_t WANT_AGENT_URI_INDEX = 2; -const int32_t INDENT = -1; +constexpr int32_t BASE_YEAR = 1900; +constexpr int32_t SINGLE_BUTTON_INVALID = 0; +constexpr int32_t SINGLE_BUTTON_JSONSTRING = 0; +constexpr int32_t SINGLE_BUTTON_ONLY_ONE = 1; +constexpr int32_t SINGLE_BUTTON_MIN_LEN = 2; +constexpr int32_t SINGLE_BUTTON_MAX_LEN = 4; +constexpr int32_t BUTTON_TYPE_INDEX = 0; +constexpr int32_t BUTTON_TITLE_INDEX = 1; +constexpr int32_t BUTTON_PKG_INDEX = 2; +constexpr int32_t BUTTON_ABILITY_INDEX = 3; +constexpr int32_t WANT_AGENT_URI_INDEX = 2; +constexpr int32_t INDENT = -1; } int32_t ReminderRequest::GLOBAL_ID = 0; -const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0; -const uint16_t ReminderRequest::INVALID_U16_VALUE = 0; -const uint16_t ReminderRequest::MILLI_SECONDS = 1000; -const uint16_t ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS = 1000; -const uint32_t ReminderRequest::MIN_TIME_INTERVAL_IN_MILLI = 5 * 60 * 1000; -const uint8_t ReminderRequest::INVALID_U8_VALUE = 0; -const uint8_t ReminderRequest::REMINDER_STATUS_INACTIVE = 0; -const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; -const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; -const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; -const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; -const uint8_t ReminderRequest::TIME_HOUR_OFFSET = 12; +constexpr uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0; +constexpr uint16_t ReminderRequest::INVALID_U16_VALUE = 0; +constexpr uint16_t ReminderRequest::MILLI_SECONDS = 1000; +constexpr uint16_t ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS = 1000; +constexpr uint32_t ReminderRequest::MIN_TIME_INTERVAL_IN_MILLI = 5 * 60 * 1000; +constexpr uint8_t ReminderRequest::INVALID_U8_VALUE = 0; +constexpr uint8_t ReminderRequest::REMINDER_STATUS_INACTIVE = 0; +constexpr uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; +constexpr uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; +constexpr uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; +constexpr uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; +constexpr uint8_t ReminderRequest::TIME_HOUR_OFFSET = 12; const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT"; const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT"; const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT"; @@ -74,11 +74,11 @@ const std::string ReminderRequest::SEP_WANT_AGENT = ""; const std::string ReminderRequest::SEP_BUTTON_VALUE_TYPE = ""; const std::string ReminderRequest::SEP_BUTTON_VALUE = ""; const std::string ReminderRequest::SEP_BUTTON_VALUE_BLOB = ""; -const uint8_t ReminderRequest::DAYS_PER_WEEK = 7; -const uint8_t ReminderRequest::MONDAY = 1; -const uint8_t ReminderRequest::SUNDAY = 7; -const uint8_t ReminderRequest::HOURS_PER_DAY = 24; -const uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600; +constexpr uint8_t ReminderRequest::DAYS_PER_WEEK = 7; +constexpr uint8_t ReminderRequest::MONDAY = 1; +constexpr uint8_t ReminderRequest::SUNDAY = 7; +constexpr uint8_t ReminderRequest::HOURS_PER_DAY = 24; +constexpr uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600; template void GetJsonValue(const nlohmann::json& root, const std::string& name, T& value) @@ -112,37 +112,91 @@ ReminderRequest::ReminderRequest() InitServerObj(); } -ReminderRequest::ReminderRequest(const ReminderRequest &other) -{ - this->content_ = other.content_; - this->expiredContent_ = other.expiredContent_; - this->snoozeContent_ = other.snoozeContent_; - this->displayContent_ = other.displayContent_; - this->title_ = other.title_; - this->isExpired_ = other.isExpired_; - this->isSystemApp_ = other.isSystemApp_; - this->snoozeTimes_ = other.snoozeTimes_; - this->snoozeTimesDynamic_ = other.snoozeTimesDynamic_; - this->state_ = other.state_; - this->notificationId_ = other.notificationId_; - this->reminderId_ = other.reminderId_; - this->reminderTimeInMilli_ = other.reminderTimeInMilli_; - this->ringDurationInMilli_ = other.ringDurationInMilli_; - this->triggerTimeInMilli_ = other.triggerTimeInMilli_; - this->timeIntervalInMilli_ = other.timeIntervalInMilli_; - this->reminderType_ = other.reminderType_; - this->slotType_ = other.slotType_; - this->snoozeSlotType_ = other.snoozeSlotType_; - this->notificationRequest_ = other.notificationRequest_; - this->wantAgentInfo_ = other.wantAgentInfo_; - this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; - this->actionButtonMap_ = other.actionButtonMap_; - this->tapDismissed_= other.tapDismissed_; - this->autoDeletedTime_ = other.autoDeletedTime_; - this->customButtonUri_ = other.customButtonUri_; - this->groupId_ = other.groupId_; - this->customRingUri_ = other.customRingUri_; - this->creatorBundleName_ = other.creatorBundleName_; +ReminderRequest::ReminderRequest(const ReminderRequest& other) +{ + content_ = other.content_; + expiredContent_ = other.expiredContent_; + snoozeContent_ = other.snoozeContent_; + displayContent_ = other.displayContent_; + title_ = other.title_; + isExpired_ = other.isExpired_; + isSystemApp_ = other.isSystemApp_; + snoozeTimes_ = other.snoozeTimes_; + snoozeTimesDynamic_ = other.snoozeTimesDynamic_; + state_ = other.state_; + notificationId_ = other.notificationId_; + reminderId_ = other.reminderId_; + reminderTimeInMilli_ = other.reminderTimeInMilli_; + ringDurationInMilli_ = other.ringDurationInMilli_; + triggerTimeInMilli_ = other.triggerTimeInMilli_; + timeIntervalInMilli_ = other.timeIntervalInMilli_; + reminderType_ = other.reminderType_; + slotType_ = other.slotType_; + snoozeSlotType_ = other.snoozeSlotType_; + notificationRequest_ = other.notificationRequest_; + wantAgentInfo_ = other.wantAgentInfo_; + maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; + actionButtonMap_ = other.actionButtonMap_; + tapDismissed_= other.tapDismissed_; + autoDeletedTime_ = other.autoDeletedTime_; + customButtonUri_ = other.customButtonUri_; + groupId_ = other.groupId_; + customRingUri_ = other.customRingUri_; + creatorBundleName_ = other.creatorBundleName_; +} + +bool ReminderRequest::Marshalling(Parcel& parcel) const +{ + // write string + WRITE_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, snoozeContent_, "snoozeContent"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, title_, "title"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->abilityName, "wantAgentInfo's abilityName"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->pkgName, "wantAgentInfo's pkgName"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->uri, "wantAgentInfo's uri"); + if (!MarshallingWantParameters(parcel, wantAgentInfo_->parameters)) { + ANSR_LOGE("Failed to write wantAgentInfo's parameters"); + return false; + } + WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); + + // write bool + WRITE_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); + WRITE_BOOL_RETURN_FALSE_LOG(parcel, tapDismissed_, "tapDismissed"); + + // write int + WRITE_INT64_RETURN_FALSE_LOG(parcel, autoDeletedTime_, "autoDeletedTime"); + WRITE_INT32_RETURN_FALSE_LOG(parcel, reminderId_, "reminderId"); + WRITE_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); + + WRITE_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); + WRITE_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); + WRITE_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); + WRITE_UINT64_RETURN_FALSE_LOG(parcel, reminderTimeInMilli_, "reminderTimeInMilli"); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); + + // write enum + uint8_t reminderType = static_cast(reminderType_); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); + + int32_t slotType = static_cast(slotType_); + WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); + + int32_t snoozeSlotType = static_cast(snoozeSlotType_); + WRITE_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); + + if (!MarshallingActionButton(parcel)) { + return false; + } + return true; } ReminderRequest::ReminderRequest(int32_t reminderId) @@ -192,13 +246,12 @@ std::string ReminderRequest::Dump() const "]"; } -ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type, - const std::string &resource, const std::shared_ptr &buttonWantAgent, +void ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type, + const std::string &resource, const std::shared_ptr &buttonWantAgent, const std::shared_ptr &buttonDataShareUpdate) { if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE) && (type != ActionButtonType::CUSTOM)) { ANSR_LOGI("Button type is not support: %{public}d.", static_cast(type)); - return *this; } ActionButtonInfo actionButtonInfo; actionButtonInfo.type = type; @@ -208,19 +261,16 @@ ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, cons actionButtonInfo.dataShareUpdate = buttonDataShareUpdate; actionButtonMap_.insert(std::pair(type, actionButtonInfo)); - return *this; } -ReminderRequest& ReminderRequest::SetContent(const std::string &content) +void ReminderRequest::SetContent(const std::string &content) { content_ = content; - return *this; } -ReminderRequest& ReminderRequest::SetExpiredContent(const std::string &expiredContent) +void ReminderRequest::SetExpiredContent(const std::string &expiredContent) { expiredContent_ = expiredContent; - return *this; } void ReminderRequest::SetExpired(bool isExpired) @@ -497,7 +547,7 @@ void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) GetJsonValue(root, "title", title); std::string resource; GetJsonValue(root, "resource", resource); - auto buttonWantAgent = std::make_shared(); + auto buttonWantAgent = std::make_shared(); if (root.contains("wantAgent") && !root["wantAgent"].empty()) { nlohmann::json wantAgent = root["wantAgent"]; GetJsonValue(wantAgent, "pkgName", buttonWantAgent->pkgName); @@ -533,7 +583,7 @@ void ReminderRequest::DeserializeButtonInfo(const std::string& buttonInfoStr) ANSR_LOGW("RecoverButton fail"); return; } - auto buttonWantAgent = std::make_shared(); + auto buttonWantAgent = std::make_shared(); if (singleButton.size() == SINGLE_BUTTON_MAX_LEN) { buttonWantAgent->pkgName = singleButton.at(BUTTON_PKG_INDEX); buttonWantAgent->abilityName = singleButton.at(BUTTON_ABILITY_INDEX); @@ -598,7 +648,7 @@ void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, c break; } case MAX_WANT_AGENT_FLAG: { - auto maxScreenWantAgentInfo = std::make_shared(); + auto maxScreenWantAgentInfo = std::make_shared(); maxScreenWantAgentInfo->pkgName = pkgName; maxScreenWantAgentInfo->abilityName = abilityName; SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); @@ -636,7 +686,7 @@ void ReminderRequest::DeserializeWantAgent(const std::string &wantAgentInfo, con break; } case 1: { - auto maxScreenWantAgentInfo = std::make_shared(); + auto maxScreenWantAgentInfo = std::make_shared(); maxScreenWantAgentInfo->pkgName = info.at(0); maxScreenWantAgentInfo->abilityName = info.at(1); SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); @@ -649,57 +699,49 @@ void ReminderRequest::DeserializeWantAgent(const std::string &wantAgentInfo, con } } -ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( - const std::shared_ptr &maxScreenWantAgentInfo) +void ReminderRequest::SetMaxScreenWantAgentInfo( + const std::shared_ptr &maxScreenWantAgentInfo) { maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; - return *this; } -ReminderRequest& ReminderRequest::SetNotificationId(int32_t notificationId) +void ReminderRequest::SetNotificationId(int32_t notificationId) { notificationId_ = notificationId; - return *this; } -ReminderRequest& ReminderRequest::SetGroupId(const std::string &groupId) +void ReminderRequest::SetGroupId(const std::string &groupId) { groupId_ = groupId; - return *this; } -ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType) +void ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType) { slotType_ = slotType; - return *this; } -ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) +void ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) { snoozeSlotType_ = snoozeSlotType; - return *this; } -ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) +void ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) { snoozeContent_ = snoozeContent; - return *this; } -ReminderRequest& ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) +void ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) { snoozeTimes_ = snoozeTimes; SetSnoozeTimesDynamic(snoozeTimes); - return *this; } -ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) +void ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) { snoozeTimesDynamic_ = snooziTimes; - return *this; } -ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) +void ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) { if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); @@ -715,13 +757,11 @@ ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInS timeIntervalInMilli_ = timeIntervalInMilli; } } - return *this; } -ReminderRequest& ReminderRequest::SetTitle(const std::string &title) +void ReminderRequest::SetTitle(const std::string &title) { title_ = title; - return *this; } void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli) @@ -729,12 +769,11 @@ void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli) triggerTimeInMilli_ = triggerTimeInMilli; } -ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) +void ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) { if (wantAgentInfo != nullptr) { wantAgentInfo_ = wantAgentInfo; } - return *this; } bool ReminderRequest::ShouldShowImmediately() const @@ -755,51 +794,16 @@ std::map R return actionButtonMap_; } -std::string ReminderRequest::GetCreatorBundleName() const -{ - return creatorBundleName_; -} - -int32_t ReminderRequest::GetCreatorUid() const -{ - return creatorUid_; -} - -std::string ReminderRequest::GetContent() const -{ - return content_; -} - -std::string ReminderRequest::GetExpiredContent() const -{ - return expiredContent_; -} - -std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const +std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const { return maxScreenWantAgentInfo_; } -int32_t ReminderRequest::GetNotificationId() const -{ - return notificationId_; -} - -std::string ReminderRequest::GetGroupId() const -{ - return groupId_; -} - sptr ReminderRequest::GetNotificationRequest() const { return notificationRequest_; } -int32_t ReminderRequest::GetReminderId() const -{ - return reminderId_; -} - uint64_t ReminderRequest::GetReminderTimeInMilli() const { return reminderTimeInMilli_; @@ -815,21 +819,10 @@ void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) reminderTimeInMilli_ = reminderTimeInMilli; } -ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) +void ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) { uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); - return *this; -} - -NotificationConstant::SlotType ReminderRequest::GetSlotType() const -{ - return slotType_; -} - -NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const -{ - return snoozeSlotType_; } std::string ReminderRequest::GetSnoozeContent() const @@ -857,36 +850,11 @@ uint64_t ReminderRequest::GetTimeInterval() const return timeIntervalInMilli_ / MILLI_SECONDS; } -std::string ReminderRequest::GetTitle() const -{ - return title_; -} - uint64_t ReminderRequest::GetTriggerTimeInMilli() const { return triggerTimeInMilli_; } -int32_t ReminderRequest::GetUserId() const -{ - return userId_; -} - -int32_t ReminderRequest::GetUid() const -{ - return uid_; -} - -std::string ReminderRequest::GetBundleName() const -{ - return bundleName_; -} - -void ReminderRequest::SetReminderType(const ReminderType type) -{ - reminderType_ = type; -} - void ReminderRequest::SetState(const uint8_t state) { state_ = state; @@ -962,16 +930,6 @@ std::shared_ptr ReminderRequest::GetWantAgentInf return wantAgentInfo_; } -ReminderRequest::ReminderType ReminderRequest::GetReminderType() const -{ - return reminderType_; -} - -uint16_t ReminderRequest::GetRingDuration() const -{ - return ringDurationInMilli_ / MILLI_SECONDS; -} - bool ReminderRequest::UpdateNextReminder() { return false; @@ -1095,60 +1053,6 @@ bool ReminderRequest::MarshallingWantParameters(Parcel& parcel, const AAFwk::Wan return true; } -bool ReminderRequest::Marshalling(Parcel &parcel) const -{ - // write string - WRITE_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, snoozeContent_, "snoozeContent"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, title_, "title"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->abilityName, "wantAgentInfo's abilityName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->pkgName, "wantAgentInfo's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->uri, "wantAgentInfo's uri"); - if (!MarshallingWantParameters(parcel, wantAgentInfo_->parameters)) { - ANSR_LOGE("Failed to write wantAgentInfo's parameters"); - return false; - } - WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); - - // write bool - WRITE_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); - WRITE_BOOL_RETURN_FALSE_LOG(parcel, tapDismissed_, "tapDismissed"); - - // write int - WRITE_INT64_RETURN_FALSE_LOG(parcel, autoDeletedTime_, "autoDeletedTime"); - WRITE_INT32_RETURN_FALSE_LOG(parcel, reminderId_, "reminderId"); - WRITE_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); - - WRITE_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, reminderTimeInMilli_, "reminderTimeInMilli"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); - - // write enum - uint8_t reminderType = static_cast(reminderType_); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); - - int32_t slotType = static_cast(slotType_); - WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); - - int32_t snoozeSlotType = static_cast(snoozeSlotType_); - WRITE_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); - - if (!MarshallingActionButton(parcel)) { - return false; - } - return true; -} - ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) { auto objptr = new (std::nothrow) ReminderRequest(); @@ -1183,7 +1087,7 @@ bool ReminderRequest::ReadActionButtonFromParcel(Parcel& parcel) info.type = type; info.title = title; info.resource = resource; - info.wantAgent = std::make_shared(); + info.wantAgent = std::make_shared(); if (info.wantAgent == nullptr) { return false; } @@ -1298,7 +1202,7 @@ void ReminderRequest::InitServerObj() { wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; + maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; } bool ReminderRequest::IsAlerting() const @@ -1835,16 +1739,6 @@ uint8_t ReminderRequest::GetRepeatDaysOfWeek() const return repeatDaysOfWeek_; } -sptr ReminderRequest::GetNotificationOption() const -{ - return notificationOption_; -} - -void ReminderRequest::SetNotificationOption(const sptr& option) -{ - notificationOption_ = option; -} - void ReminderRequest::SetRepeatDaysOfWeek(bool set, const std::vector &daysOfWeek) { if (daysOfWeek.size() == 0) { diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp b/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp index 4d4e655f8..1251e5a90 100644 --- a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp @@ -234,7 +234,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00400, Function | EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); - reminderRequest->maxScreenWantAgentInfo_ = std::make_shared(); + reminderRequest->maxScreenWantAgentInfo_ = std::make_shared(); ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::MAX_SCREEN_WANT_AGENT; std::string extra = "aa"; reminderRequest->UpdateNotificationRequest(type, extra); @@ -318,7 +318,7 @@ HWTEST_F(ReminderRequestBranchTest, GetButtonInfo_00200, Function | SmallTest | ReminderRequest::ActionButtonInfo info; info.type = ReminderRequest::ActionButtonType::SNOOZE; info.title = title; - info.wantAgent = std::make_shared(); + info.wantAgent = std::make_shared(); info.wantAgent->pkgName = pkgName; info.wantAgent->abilityName = abilityName; reminderRequest->actionButtonMap_.insert( @@ -446,7 +446,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00500, Function | SmallTest ReminderRequest::ActionButtonInfo info; info.type = ReminderRequest::ActionButtonType::SNOOZE; info.title = title; - info.wantAgent = std::make_shared(); + info.wantAgent = std::make_shared(); info.wantAgent->pkgName = pkgName; info.wantAgent->abilityName = abilityName; reminderRequest->actionButtonMap_.insert( diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 6b2252b51..33a7d825f 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -822,8 +822,8 @@ HWTEST_F(ReminderRequestTest, StringSplit_00002, Function | SmallTest | Level1) */ HWTEST_F(ReminderRequestTest, SetMaxScreenWantAgentInfo_00001, Function | SmallTest | Level1) { - std::shared_ptr maxScreenWantAgentInfo = - std::make_shared(); + std::shared_ptr maxScreenWantAgentInfo = + std::make_shared(); auto rrc = std::make_shared(); rrc->SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); EXPECT_EQ(rrc->GetMaxScreenWantAgentInfo(), maxScreenWantAgentInfo); @@ -1075,8 +1075,8 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00004, Function | SmallTest | Leve std::string resource = "CLOSE"; Notification::ReminderRequest::ActionButtonType type2 = Notification::ReminderRequest::ActionButtonType::CLOSE; - std::shared_ptr buttonWantAgent = - std::make_shared(); + std::shared_ptr buttonWantAgent = + std::make_shared(); std::shared_ptr buttonDataShareUpdate = std::make_shared(); reminderRequestChild->SetActionButton(title, type2, resource, buttonWantAgent, buttonDataShareUpdate); @@ -1096,8 +1096,8 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00005, Function | SmallTest | Leve std::string resource = "SNOOZE"; Notification::ReminderRequest::ActionButtonType type3 = Notification::ReminderRequest::ActionButtonType::SNOOZE; - std::shared_ptr buttonWantAgent = - std::make_shared(); + std::shared_ptr buttonWantAgent = + std::make_shared(); std::shared_ptr buttonDataShareUpdate = std::make_shared(); reminderRequestChild->SetActionButton(title, type3, resource, buttonWantAgent, buttonDataShareUpdate); diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 09ba9b97f..9584f99f2 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -192,7 +192,7 @@ private: static napi_value GetCallbackErrorValue(napi_env env, const int32_t errCode, const std::string errMsg); static void GetButtonWantAgent(const napi_env &env, const napi_value &value, - std::shared_ptr& reminder, std::shared_ptr& wantAgent); + std::shared_ptr& reminder, std::shared_ptr& wantAgent); static void GetButtonDataShareUpdate(const napi_env &env, const napi_value &value, std::shared_ptr& buttonDataShareUpdate); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index e55bcd25d..05f30e00d 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -105,7 +105,7 @@ void ReminderCommon::HandleActionButtonTitle(const napi_env &env, const napi_val } std::string title(str); - auto buttonWantAgent = std::make_shared(); + auto buttonWantAgent = std::make_shared(); if (ReminderRequest::ActionButtonType(buttonType) == ReminderRequest::ActionButtonType::CUSTOM) { GetButtonWantAgent(env, actionButton, reminder, buttonWantAgent); } @@ -131,7 +131,7 @@ bool ReminderCommon::IsSelfSystemApp() } void ReminderCommon::GetButtonWantAgent(const napi_env &env, const napi_value &value, - std::shared_ptr& reminder, std::shared_ptr& buttonWantAgent) + std::shared_ptr& reminder, std::shared_ptr& buttonWantAgent) { char str[NotificationNapi::STR_MAX_SIZE] = {0}; napi_value wantAgent = nullptr; @@ -409,7 +409,7 @@ void ReminderCommon::GenMaxScreenWantAgent( char str[NotificationNapi::STR_MAX_SIZE] = {0}; napi_value maxScreenWantAgent = nullptr; if (GetObject(env, value, ReminderAgentNapi::MAX_SCREEN_WANT_AGENT, maxScreenWantAgent)) { - auto maxScreenWantAgentInfo = std::make_shared(); + auto maxScreenWantAgentInfo = std::make_shared(); if (GetStringUtf8(env, maxScreenWantAgent, ReminderAgentNapi::MAX_SCREEN_WANT_AGENT_PKG, str, NotificationNapi::STR_MAX_SIZE)) { maxScreenWantAgentInfo->pkgName = str; diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 37f0d93e8..9ebd8c42e 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -16,13 +16,12 @@ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_H -#include -#include +#include -#include "notification_bundle_option.h" -#include "notification_constant.h" -#include "notification_request.h" #include "want_params.h" +#include "notification_request.h" +#include "notification_constant.h" +#include "notification_bundle_option.h" namespace OHOS { namespace Notification { @@ -153,20 +152,17 @@ public: /** * @brief Indicates that this action button is used to close reminder's notification. * It always works well, whether the application is running at the time. - * */ CLOSE, /** - * @brief Indicates that this action button is used to snooze reminder. + * @brief Indicates that this action button is used to snooze reminder's notification. * It always work well, whether the application is running at the time. - * */ SNOOZE, /** * @brief Indicates that this action button is custom. - * */ CUSTOM, INVALID @@ -201,16 +197,22 @@ public: HM }; - struct ButtonWantAgent { - std::string pkgName = ""; - std::string abilityName = ""; + /** + * @brief Want agent information. Indicates the package and the ability to switch to. + */ + struct WantAgentInfo { + std::string pkgName; + std::string abilityName; + std::string uri; + AAFwk::WantParams parameters; }; struct ButtonDataShareUpdate { - std::string uri = ""; - std::string equalTo = ""; - std::string valuesBucket = ""; + std::string uri; + std::string equalTo; + std::string valuesBucket; }; + /** * @brief Attributes of action button. */ @@ -223,17 +225,17 @@ public: /** * Content show on the button. */ - std::string title = ""; + std::string title; /** * resource key(for language) */ - std::string resource = ""; + std::string resource; /** * The ability that is redirected to when the button is clicked. */ - std::shared_ptr wantAgent; + std::shared_ptr wantAgent; /** * The ability that is updata App rdb. @@ -241,288 +243,456 @@ public: std::shared_ptr dataShareUpdate; }; +public: /** - * @brief Want agent information. Indicates the package and the ability to switch to. + * @brief Copy construct from an exist reminder. + * + * @param Indicates the exist reminder. */ - struct WantAgentInfo { - std::string pkgName = ""; - std::string abilityName = ""; - std::string uri = ""; - AAFwk::WantParams parameters; - }; + explicit ReminderRequest(const ReminderRequest& other); + ReminderRequest& operator =(const ReminderRequest& other); - struct MaxScreenAgentInfo { - std::string pkgName = ""; - std::string abilityName = ""; - }; + virtual ~ReminderRequest() override = default; /** - * @brief Copy construct from an exist reminder. + * @brief Marshal a ReminderRequest object into a Parcel. * - * @param Indicates the exist reminder. + * @param parcel the object into the parcel. */ - explicit ReminderRequest(const ReminderRequest &other); + virtual bool Marshalling(Parcel& parcel) const override; /** - * @brief This constructor should only be used in background proxy service process - * when reminder instance recovery from database. + * @brief Unmarshal object from a Parcel. * - * @param reminderId Indicates reminder id. + * @return the ReminderRequest. */ - explicit ReminderRequest(int32_t reminderId); - ReminderRequest& operator = (const ReminderRequest &other); - virtual ~ReminderRequest() override {}; + static ReminderRequest *Unmarshalling(Parcel& parcel); + virtual bool ReadFromParcel(Parcel& parcel); +public: /** - * @brief Marshal a NotificationRequest object into a Parcel. - * - * @param parcel the object into the parcel + * @brief Obtains reminder type. */ - virtual bool Marshalling(Parcel &parcel) const override; + ReminderType GetReminderType() const + { + return reminderType_; + } /** - * @brief Unmarshal object from a Parcel. - * - * @return the NotificationRequest + * @brief Obtains reminder id. */ - static ReminderRequest *Unmarshalling(Parcel &parcel); - virtual bool ReadFromParcel(Parcel &parcel); + int32_t GetReminderId() const + { + return reminderId_; + } /** - * @brief If the reminder is showing on the notification panel, it should not be removed automatically. - * - * @return true if it can be removed automatically. + * @brief Obtains user id. */ - bool CanRemove() const; + int32_t GetUserId() const + { + return userId_; + } - bool CanShow() const; + /** + * @brief Obtains uid. + */ + int32_t GetUid() const + { + return uid_; + } /** - * @brief Obtains all the information of the reminder. - * - * @return Information of the reminder. + * @brief Obtains creator uid. */ - std::string Dump() const; + int32_t GetCreatorUid() const + { + return creatorUid_; + } /** - * @brief Obtains the configured action buttons. - * - * @return map of action buttons. + * @brief Obtains bundle name. */ - std::map GetActionButtons() const; + std::string GetBundleName() const + { + return bundleName_; + } /** - * @brief Obtains creator bundle name - * - * @return creator bundle name + * @brief Obtains creator bundle name. */ - std::string GetCreatorBundleName() const; + std::string GetCreatorBundleName() const + { + return creatorBundleName_; + } /** - * @brief Obtains creator uid - * - * @return creator uid + * @brief Obtains title. */ - int32_t GetCreatorUid() const; + std::string GetTitle() const + { + return title_; + } /** * @brief Obtains the configured content. - * - * @return content text. */ - std::string GetContent() const; + std::string GetContent() const + { + return content_; + } /** * @brief Obtains the configured expired content. + */ + std::string GetExpiredContent() const + { + return expiredContent_; + } + + /** + * @brief Obtains notification id. + */ + int32_t GetNotificationId() const + { + return notificationId_; + } + + /** + * @brief Obtains group id. + */ + std::string GetGroupId() const + { + return groupId_; + } + + /** + * @brief Obtains the ringing or vibration duration configured for this reminder. + */ + uint16_t GetRingDuration() const + { + return ringDurationInMilli_ / MILLI_SECONDS; + } + + /** + * @brief Obtains slot type. + */ + NotificationConstant::SlotType GetSlotType() const + { + return slotType_; + } + + /** + * @brief Obtains snoozeSlot type. + */ + NotificationConstant::SlotType GetSnoozeSlotType() const + { + return snoozeSlotType_; + } + + /** + * @brief Obtains want agent information. * - * @return expired content text. + * @return want agent information. */ - std::string GetExpiredContent() const; + std::shared_ptr GetWantAgentInfo() const; - std::shared_ptr GetMaxScreenWantAgentInfo() const; + std::shared_ptr GetMaxScreenWantAgentInfo() const; + + uint64_t GetReminderTimeInMilli() const; + + std::string GetSnoozeContent() const; + + uint8_t GetSnoozeTimes() const; + + uint8_t GetSnoozeTimesDynamic() const; + + uint8_t GetState() const; /** - * @brief Obtains notification id. + * @brief Obtains the Time Interval in seconds. + */ + uint64_t GetTimeInterval() const; + + /** + * @brief Obtains trigger time in milli. + */ + uint64_t GetTriggerTimeInMilli() const; + + /** + * @brief Obtains autoDeletedTime. + */ + int64_t GetAutoDeletedTime() const; + + /** + * @brief Gets custom button uri. + */ + std::string GetCustomButtonUri() const; + + /** + * @brief Gets custom ring uri. + */ + std::string GetCustomRingUri() const; + + /** + * @brief Obtains the configured action buttons. + */ + std::unordered_map GetActionButtons() const; + + /** + * @brief Sets reminder id. * - * @return notification id. + * @param reminderId Indicates reminder id. */ - int32_t GetNotificationId() const; + void SetReminderId(const int32_t reminderId); /** - * @brief Obtains group id. + * @brief Inits reminder userId when publish reminder success. + * + * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the + * package has been removed, and the bundleOption can not be create with correct uid. so we need to record + * the user id, and use it to judge which user the reminder belong to. * - * @return group id. + * @param userId Indicates the userId which the reminder belong to. */ - std::string GetGroupId() const; + void SetUserId(const int32_t userId); /** - * @brief Obtains notification request. + * @brief Inites reminder uid when publish reminder success. * - * @return notification request instance. + * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be + * ready. So we need to record the uid in order to create correct bundleOption. + * + * @param uid Indicates the uid which the reminder belong to. */ - sptr GetNotificationRequest() const; + void SetUid(const int32_t uid); /** - * @brief Obtains reminder id. + * @brief Inites reminder creator uid when publish reminder success. * - * @return reminder id. + * @param creatorUid Indicates the creator uid which the reminder belong to. */ - int32_t GetReminderId() const; + void SetCreatorUid(const int32_t creatorUid); - uint64_t GetReminderTimeInMilli() const; + /** + * @brief Inites reminder bundle name when publish reminder success. + * + * @param bundleName Indicates the bundle name which the reminder belong to. + */ + void SetBundleName(const std::string& bundleName); /** - * @brief Obtains reminder type. + * @brief Inites reminder creator bundle name when publish reminder success. * - * @return reminder type. + * @param creatorBundleName Indicates the creator bundle name which the reminder belong to. */ - ReminderType GetReminderType() const; + void SetCreatorBundleName(const std::string& creatorBundleName); /** - * @brief Obtains the ringing or vibration duration configured for this reminder. + * @brief Sets reminder content. * - * @return uint16_t The ringing or vibration duration in seconds. + * @param content Indicates content text. */ - uint16_t GetRingDuration() const; + void SetContent(const std::string& content); /** - * @brief Obtains slot type. + * @brief Sets reminder is expired or not. * - * @return slot type. + * @param isExpired Indicates the reminder is expired or not. */ - NotificationConstant::SlotType GetSlotType() const; + void SetExpired(bool isExpired); /** - * @brief Obtains snoozeSlot type. + * @brief Sets expired content. * - * @return snoozeSlot type. + * @param expiredContent Indicates expired content. */ - NotificationConstant::SlotType GetSnoozeSlotType() const; + void SetExpiredContent(const std::string &expiredContent); - std::string GetSnoozeContent() const; - uint8_t GetSnoozeTimes() const; - uint8_t GetSnoozeTimesDynamic() const; - uint8_t GetState() const; + void SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo); /** - * @brief Obtains the Time Interval in seconds. + * @brief Sets action button. * - * @return uint64_t Time Interval in seconds. + * @param title Indicates the title of the button. + * @param type Indicates the type of the button. + * @param resource Indicates the resource of the button. + * @return Current reminder self. */ - uint64_t GetTimeInterval() const; + void SetActionButton(const std::string &title, const ActionButtonType &type, + const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr, + const std::shared_ptr &buttonDataShareUpdate = nullptr); /** - * @brief Obtains title. + * @brief Sets notification id. * - * @return title. + * @param notificationId Indicates notification id. + * @return Current reminder self. */ - std::string GetTitle() const; + void SetNotificationId(int32_t notificationId); /** - * @brief Obtains trigger time in milli. + * @brief Sets group id. * - * @return trigger time. + * @param notificationId Indicates group id. + * @return Current reminder self. */ - uint64_t GetTriggerTimeInMilli() const; + void SetGroupId(const std::string &groupId); - int32_t GetUserId() const; - int32_t GetUid() const; + void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); /** - * @brief Obtains bundle name + * @brief Sets the ringing or vibration duration for this reminder, in seconds. * - * @return bundle name + * @param ringDurationInSeconds Indicates the duration. The default is 1 second. + * @return Current reminder self. */ - std::string GetBundleName() const; + void SetRingDuration(const uint64_t ringDurationInSeconds); /** - * @brief Set the reminder type. + * @brief Sets slot type. * - * @param reminderType the reminder type. + * @param slotType Indicates slot type. */ - void SetReminderType(const ReminderType type); + void SetSlotType(const NotificationConstant::SlotType &slotType); + void SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); + void SetSnoozeContent(const std::string &snoozeContent); /** - * @brief Set the reminder state. + * @brief Set the number of snooze times for this reminder. * - * @param state the reminder state. + * @note If the value of snoozeTimes is less than or equals to 0, this reminder is a one-shot + * reminder and will not be snoozed. + * + * It the value of snoozeTimes is greater than 0, for example, snoozeTimes=3, this reminder + * will be snoozed three times after the first alarm, that is, this reminder will be triggered + * for four times. + * + * This method does not take affect on the reminders for countdown timers. + * + * @param snoozeTimes Indicates the number of times that the reminder will be snoozed. */ - void SetState(const uint8_t state); + void SetSnoozeTimes(const uint8_t snoozeTimes); + + void SetSnoozeTimesDynamic(const uint8_t snooziTimes); /** - * @brief Set the reminder repeat days of week. + * @brief Sets the Time Interval for this reminder, in seconds. The default value is 0. * - * @param state the reminder repeat days of week. + * @note The minimum snooze interval is 5 minute. If the snooze interval is set to a value greater + * than 0 and less than 5 minutes, the system converts it to 5 minutes by default. + * + * This method does not take effect on the reminders for countdown timers. + * + * @param timeIntervalInSeconds Indicates the snooze interval to set. If the value is less or equals to 0, + * the reminder will not be snoozed. */ - void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); + void SetTimeInterval(const uint64_t timeIntervalInSeconds); /** - * @brief Set the app system. + * @brief Sets title. * + * @param title Indicates title. */ - void SetSystemApp(bool isSystem); + void SetTitle(const std::string &title); /** - * @brief Check the app is system or not. + * @brief Sets trigger time. * - * @return true is the app is system. + * @param triggerTimeInMilli Indicates trigger time in milli. */ - bool IsSystemApp() const; + void SetTriggerTimeInMilli(uint64_t triggerTimeInMilli); /** - * @brief Obtains want agent information. + * @brief Sets want agent information. * - * @return want agent information. + * @param wantAgentInfo Indicates want agent information. */ - std::shared_ptr GetWantAgentInfo() const; + void SetWantAgentInfo(const std::shared_ptr &wantAgentInfo); /** - * @brief Inites reminder creator bundle name when publish reminder success. + * @brief Sets tapDismissed. * - * @param creatorBundleName Indicates the creator bundle name which the reminder belong to + * @param tapDismissed Indicates tapDismissed. */ - void SetCreatorBundleName(const std::string &creatorBundleName); + void SetTapDismissed(bool tapDismissed); /** - * @brief Inites reminder creator uid when publish reminder success. + * @brief Sets autoDeletedTime. * - * @param uid Indicates the creator uid which the reminder belong to + * @param autoDeletedTime Indicates autoDeletedTime. */ - void SetCreatorUid(const int32_t creatorUid); + void SetAutoDeletedTime(int64_t autoDeletedTime); /** - * @brief Inits reminder id when publish reminder success. - * Assign a unique reminder id for each reminder. + * @brief Sets custom button uri. + * + * @param uri Indicates uri. */ - void InitReminderId(); + void SetCustomButtonUri(const std::string &uri); + + /** + * @brief Sets custom ring uri. + * + * @param uri Indicates uri. + */ + void SetCustomRingUri(const std::string &uri); /** - * @brief Inits reminder userId when publish reminder success. + * @brief If the reminder is showing on the notification panel, it should not be removed automatically. * - * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the - * package has been removed, and the bundleOption can not be create with correct uid. so we need to record - * the user id, and use it to judge which user the reminder belong to. + * @return true if it can be removed automatically. + */ + bool CanRemove() const; + + bool CanShow() const; + + /** + * @brief Obtains all the information of the reminder. * - * @param userId Indicates the userId which the reminder belong to. + * @return Information of the reminder. */ - void SetUserId(const int32_t &userId); + std::string Dump() const; /** - * @brief Inites reminder uid when publish reminder success. + * @brief Obtains notification request. * - * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be - * ready. So we need to record the uid in order to create correct bundleOption. + * @return notification request instance. + */ + sptr GetNotificationRequest() const; + + /** + * @brief Set the reminder state. * - * @param uid Indicates the uid which the reminder belong to. + * @param state the reminder state. */ - void SetUid(const int32_t &uid); + void SetState(const uint8_t state); /** - * @brief Inites reminder bundle name when publish reminder success. + * @brief Set the reminder repeat days of week. + * + * @param state the reminder repeat days of week. + */ + void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); + + /** + * @brief Set the app system. * - * @param bundleName Indicates the bundle name which the reminder belong to */ - void SetBundleName(const std::string &bundleName); + void SetSystemApp(bool isSystem); + + /** + * @brief Check the app is system or not. + * + * @return true is the app is system. + */ + bool IsSystemApp() const; + + /** + * @brief Inits reminder id when publish reminder success. + * Assign a unique reminder id for each reminder. + */ + void InitReminderId(); /** * @brief Check the reminder is alerting or not. @@ -627,142 +797,6 @@ public: */ virtual bool OnTimeZoneChange(); - /** - * @brief Sets action button. - * - * @param title Indicates the title of the button. - * @param type Indicates the type of the button. - * @param resource Indicates the resource of the button. - * @return Current reminder self. - */ - ReminderRequest& SetActionButton(const std::string &title, const ActionButtonType &type, - const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr, - const std::shared_ptr &buttonDataShareUpdate = nullptr); - - /** - * @brief Sets reminder content. - * - * @param content Indicates content text. - * @return Current reminder self. - */ - ReminderRequest& SetContent(const std::string &content); - - /** - * @brief Sets reminder is expired or not. - * - * @param isExpired Indicates the reminder is expired or not. - */ - void SetExpired(bool isExpired); - - /** - * @brief Sets expired content. - * - * @param expiredContent Indicates expired content. - * @return Current reminder self. - */ - ReminderRequest& SetExpiredContent(const std::string &expiredContent); - - ReminderRequest& SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo); - - /** - * @brief Sets notification id. - * - * @param notificationId Indicates notification id. - * @return Current reminder self. - */ - ReminderRequest& SetNotificationId(int32_t notificationId); - - /** - * @brief Sets group id. - * - * @param notificationId Indicates group id. - * @return Current reminder self. - */ - ReminderRequest& SetGroupId(const std::string &groupId); - - /** - * @brief Sets reminder id. - * - * @param reminderId Indicates reminder id. - */ - void SetReminderId(int32_t reminderId); - - void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); - - /** - * @brief Sets the ringing or vibration duration for this reminder, in seconds. - * - * @param ringDurationInSeconds Indicates the duration. The default is 1 second. - * @return Current reminder self. - */ - ReminderRequest& SetRingDuration(const uint64_t ringDurationInSeconds); - - /** - * @brief Sets slot type. - * - * @param slotType Indicates slot type. - * @return Current reminder self. - */ - ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType); - ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); - ReminderRequest& SetSnoozeContent(const std::string &snoozeContent); - - /** - * @brief Set the number of snooze times for this reminder. - * - * @note If the value of snoozeTimes is less than or equals to 0, this reminder is a one-shot - * reminder and will not be snoozed. - * - * It the value of snoozeTimes is greater than 0, for example, snoozeTimes=3, this reminder - * will be snoozed three times after the first alarm, that is, this reminder will be triggered - * for four times. - * - * This method does not take affect on the reminders for countdown timers. - * - * @param snoozeTimes Indicates the number of times that the reminder will be snoozed. - * @return ReminderRequest& Current reminder self. - */ - ReminderRequest& SetSnoozeTimes(const uint8_t snoozeTimes); - - ReminderRequest& SetSnoozeTimesDynamic(const uint8_t snooziTimes); - - /** - * @brief Sets the Time Interval for this reminder, in seconds. The default value is 0. - * - * @note The minimum snooze interval is 5 minute. If the snooze interval is set to a value greater - * than 0 and less than 5 minutes, the system converts it to 5 minutes by default. - * - * This method does not take effect on the reminders for countdown timers. - * - * @param timeIntervalInSeconds Indicates the snooze interval to set. If the value is less or equals to 0, - * the reminder will not be snoozed. - * @return ReminderRequest& Current reminder self. - */ - ReminderRequest& SetTimeInterval(const uint64_t timeIntervalInSeconds); - - /** - * @brief Sets title. - * - * @param title Indicates title. - * @return Current reminder self. - */ - ReminderRequest& SetTitle(const std::string &title); - - /** - * @brief Sets trigger time. - * - * @param triggerTimeInMilli Indicates trigger time in milli. - */ - void SetTriggerTimeInMilli(uint64_t triggerTimeInMilli); - - /** - * @brief Sets want agent information. - * - * @param wantAgentInfo Indicates want agent information. - * @return Current reminder self. - */ - ReminderRequest& SetWantAgentInfo(const std::shared_ptr &wantAgentInfo); - bool ShouldShowImmediately() const; /** @@ -814,13 +848,6 @@ public: void SetMaxWantAgentStr(const std::string& maxWantStr); std::string GetMaxWantAgentStr(); - /** - * @brief Sets tapDismissed. - * - * @param tapDismissed Indicates tapDismissed. - */ - void SetTapDismissed(bool tapDismissed); - /** * @brief Gets tapDismissed. * @@ -828,48 +855,6 @@ public: */ bool IsTapDismissed() const; - /** - * @brief Sets autoDeletedTime. - * - * @param autoDeletedTime Indicates autoDeletedTime. - */ - void SetAutoDeletedTime(int64_t autoDeletedTime); - - /** - * @brief Gets autoDeletedTime. - * - * @return AutoDeletedTime. - */ - int64_t GetAutoDeletedTime() const; - - /** - * @brief Sets custom button uri. - * - * @param uri Indicates uri. - */ - void SetCustomButtonUri(const std::string &uri); - - /** - * @brief Gets custom button uri. - * - * @return custom button uri. - */ - std::string GetCustomButtonUri() const; - - /** - * @brief Gets custom ring uri. - * - * @return custom ring uri. - */ - std::string GetCustomRingUri() const; - - /** - * @brief Sets custom ring uri. - * - * @param uri Indicates uri. - */ - void SetCustomRingUri(const std::string &uri); - /** * @brief Gets notification bundle option. */ @@ -910,10 +895,6 @@ public: */ uint8_t GetRepeatDaysOfWeek() const; - sptr GetNotificationOption() const; - - void SetNotificationOption(const sptr& option); - /** * @brief When system language change, will call this function. * need load resource to update button title @@ -1108,47 +1089,50 @@ private: static const std::string SEP_BUTTON_MULTI; static const std::string SEP_WANT_AGENT; - std::string content_ {}; - std::string expiredContent_ {}; - std::string snoozeContent_ {}; - std::string displayContent_ {}; - std::string title_ {}; - std::string bundleName_ {}; bool isExpired_ {false}; + bool isSystemApp_ {false}; + bool tapDismissed_ {true}; + uint8_t snoozeTimes_ {0}; uint8_t snoozeTimesDynamic_ {0}; uint8_t state_ {0}; + ReminderType reminderType_ {ReminderType::INVALID}; + int32_t notificationId_ {0}; - std::string groupId_ {}; int32_t reminderId_ {-1}; int32_t userId_ {-1}; int32_t uid_ {-1}; - bool isSystemApp_ {false}; - bool tapDismissed_ {true}; - int64_t autoDeletedTime_ {0}; - std::string customButtonUri_ {}; - std::string customRingUri_ {}; - std::string creatorBundleName_ {}; int32_t creatorUid_ {-1}; + NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; + NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; - // Indicates the reminder has been shown in the past time. - // When the reminder has been created but not showed, it is equals to 0. + int64_t autoDeletedTime_ {0}; uint64_t reminderTimeInMilli_ {0}; uint64_t ringDurationInMilli_ {MILLI_SECONDS}; uint64_t triggerTimeInMilli_ {0}; uint64_t timeIntervalInMilli_ {0}; - ReminderType reminderType_ {ReminderType::INVALID}; - NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; - NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; - sptr notificationRequest_ = nullptr; - std::shared_ptr wantAgentInfo_ = nullptr; - std::shared_ptr maxScreenWantAgentInfo_ = nullptr; - std::map actionButtonMap_ {}; - std::string wantAgentStr_{}; - std::string maxWantAgentStr_{}; + std::string content_; + std::string expiredContent_; + std::string snoozeContent_; + std::string displayContent_; + std::string title_; + std::string bundleName_; + std::string groupId_; + std::string customButtonUri_; + std::string customRingUri_; + std::string creatorBundleName_; + std::string wantAgentStr_; + std::string maxWantAgentStr_; + + // Indicates the reminder has been shown in the past time. + // When the reminder has been created but not showed, it is equals to 0. + sptr notificationRequest_; + sptr notificationOption_; + std::shared_ptr wantAgentInfo_; + std::shared_ptr maxScreenWantAgentInfo_; - sptr notificationOption_ {nullptr}; + std::unordered_map actionButtonMap_; }; } // namespace Reminder } // namespace OHOS diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index 19edf0fd9..852875a4f 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -390,8 +390,8 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_016, Level1) // not SystemApp std::vector daysOfWeek; sptr reminder = new ReminderRequestAlarm(0, 1, daysOfWeek); - std::shared_ptr buttonWantAgent = - std::make_shared(); + std::shared_ptr buttonWantAgent = + std::make_shared(); std::shared_ptr buttonDataShareUpdate = std::make_shared(); reminder->SetSystemApp(false); @@ -418,8 +418,8 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_016, Level1) // update datashare sptr reminder1 = new ReminderRequestAlarm(2, 3, daysOfWeek); - std::shared_ptr buttonWantAgent1 = - std::make_shared(); + std::shared_ptr buttonWantAgent1 = + std::make_shared(); std::shared_ptr buttonDataShareUpdate1 = std::make_shared(); reminder1->SetSystemApp(true); diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp index 9785205b4..00f0d2ddb 100644 --- a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp @@ -65,8 +65,8 @@ namespace OHOS { reminderRequest.OnTerminate(); reminderRequest.OnTimeZoneChange(); reminderRequest.StringSplit(stringData, stringData); - std::shared_ptr< Notification::ReminderRequest::MaxScreenAgentInfo> maxScreenWantAgentInfo = - std::make_shared< Notification::ReminderRequest::MaxScreenAgentInfo>(); + std::shared_ptr< Notification::ReminderRequest::WantAgentInfo> maxScreenWantAgentInfo = + std::make_shared< Notification::ReminderRequest::WantAgentInfo>(); reminderRequest.SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); reminderRequest.SetNotificationId(reminderId); uint8_t typed = *data % SLOT_TYPE_NUM; -- Gitee From 9b172795139db1739c850bac05b3d80590656099 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 6 Nov 2024 21:41:56 +0800 Subject: [PATCH 4/5] update Signed-off-by: gaojiaqi --- .../core/include/ans_manager_interface.h | 57 - frameworks/core/include/ans_manager_proxy.h | 59 - frameworks/core/include/ans_manager_stub.h | 64 - .../reminder/include/ans_notification.h | 1216 +++ .../include/reminder_manager_interface.h | 105 + .../reminder/include/reminder_manager_proxy.h | 95 + .../reminder/include/reminder_manager_stub.h | 115 + .../src}/ans_manager_proxy_reminder.cpp | 0 frameworks/reminder/src/ans_manager_stub.cpp | 2650 ++++++ .../reminder/src/ans_manager_stub_invalid.cpp | 663 ++ frameworks/reminder/src/ans_notification.cpp | 2028 +++++ .../src/ans_notification_branch_test.cpp | 882 ++ .../{ans => reminder}/src/reminder_helper.cpp | 0 .../src/reminder_request.cpp | 0 .../src/reminder_request_alarm.cpp | 0 .../src/reminder_request_calendar.cpp | 0 .../src/reminder_request_timer.cpp | 0 .../test/ans_manager_proxy_unit_test.cpp | 7981 +++++++++++++++++ .../reminder/test/ans_manager_stub_test.cpp | 5417 +++++++++++ .../test/ans_notification_unit_test.cpp | 1615 ++++ .../test}/reminder_helper_test.cpp | 330 +- .../test}/reminder_request_alarm_test.cpp | 0 .../mock_reminder_request.cpp | 0 .../reminder_request_branch_test.cpp | 0 .../test}/reminder_request_calendar_test.cpp | 0 .../test}/reminder_request_test.cpp | 0 .../test}/reminder_request_timer_test.cpp | 0 .../test}/reminder_store_test.cpp | 0 28 files changed, 22932 insertions(+), 345 deletions(-) create mode 100644 frameworks/reminder/include/ans_notification.h create mode 100644 frameworks/reminder/include/reminder_manager_interface.h create mode 100644 frameworks/reminder/include/reminder_manager_proxy.h create mode 100644 frameworks/reminder/include/reminder_manager_stub.h rename frameworks/{core/src/manager => reminder/src}/ans_manager_proxy_reminder.cpp (100%) create mode 100644 frameworks/reminder/src/ans_manager_stub.cpp create mode 100644 frameworks/reminder/src/ans_manager_stub_invalid.cpp create mode 100644 frameworks/reminder/src/ans_notification.cpp create mode 100644 frameworks/reminder/src/ans_notification_branch_test.cpp rename frameworks/{ans => reminder}/src/reminder_helper.cpp (100%) rename frameworks/{ans => reminder}/src/reminder_request.cpp (100%) rename frameworks/{ans => reminder}/src/reminder_request_alarm.cpp (100%) rename frameworks/{ans => reminder}/src/reminder_request_calendar.cpp (100%) rename frameworks/{ans => reminder}/src/reminder_request_timer.cpp (100%) create mode 100644 frameworks/reminder/test/ans_manager_proxy_unit_test.cpp create mode 100644 frameworks/reminder/test/ans_manager_stub_test.cpp create mode 100644 frameworks/reminder/test/ans_notification_unit_test.cpp rename frameworks/{ans/test/unittest => reminder/test}/reminder_helper_test.cpp (96%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_request_alarm_test.cpp (100%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_request_branch_test/mock_reminder_request.cpp (100%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_request_branch_test/reminder_request_branch_test.cpp (100%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_request_calendar_test.cpp (100%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_request_test.cpp (100%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_request_timer_test.cpp (100%) rename frameworks/{ans/test/unittest => reminder/test}/reminder_store_test.cpp (100%) diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 2a1ae2880..f31277450 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -652,63 +652,6 @@ public: */ virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) = 0; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode PublishReminder(sptr &reminder) = 0; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelReminder(const int32_t reminderId) = 0; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelAllReminders() = 0; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 0; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode DelExcludeDates(const int32_t reminderId) = 0; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 0; - /** * @brief Checks whether this device is support template. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 2c6afcea9..17bb37ffa 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -649,63 +649,6 @@ public: */ ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode DelExcludeDates(const int32_t reminderId) override; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; - /** * @brief Checks Whether the specified users is allowed to publish notifications. * @@ -996,8 +939,6 @@ private: return true; } static inline BrokerDelegator delegator_; - - ErrCode ReadReminders(uint8_t &count, MessageParcel &reply, std::vector> &reminders); }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index bdd0e5bbd..cbf994c58 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -642,63 +642,6 @@ public: */ virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode DelExcludeDates(const int32_t reminderId) override; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; - /** * @brief Checks whether this device is support template. * @@ -1012,13 +955,6 @@ private: ErrCode HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply); ErrCode HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); ErrCode HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); - ErrCode HandlePublishReminder(MessageParcel &data, MessageParcel &reply); - ErrCode HandleCancelReminder(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetValidReminders(MessageParcel &data, MessageParcel &reply); - ErrCode HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply); - ErrCode HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply); - ErrCode HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/reminder/include/ans_notification.h b/frameworks/reminder/include/ans_notification.h new file mode 100644 index 000000000..8f032b49c --- /dev/null +++ b/frameworks/reminder/include/ans_notification.h @@ -0,0 +1,1216 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H + +#include +#include + +#include "ans_dialog_host_client.h" +#include "ans_manager_interface.h" +#include "ans_subscriber_listener.h" +#include "notification_subscriber.h" +#include "notification_local_live_view_subscriber.h" +#include "want_params.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "swing_callback_stub.h" +#endif + +namespace OHOS { +namespace Notification { +class AnsNotification { +public: + /** + * @brief Creates a notification slot. + * @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot + * for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to + * call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the + * notification published can have all the characteristics set in the NotificationSlot. After a notification slot is + * created by using this method, only the name and description of the notification slot can be changed. Changes to + * the other attributes, such as the vibration status and notification tone, will no longer take effect. + * + * @param slot Indicates the notification slot to be created, which is set by NotificationSlot. + * This parameter must be specified. + * @return Returns add notification slot result. + */ + ErrCode AddNotificationSlot(const NotificationSlot &slot); + + /** + * @brief Adds a notification slot by type. + * + * @param slotType Indicates the notification slot type to be added. + * @return Returns add notification slot result. + */ + ErrCode AddSlotByType(const NotificationConstant::SlotType &slotType); + + /** + * @brief Creates multiple notification slots. + * + * @param slots Indicates the notification slots to create. + * @return Returns add notification slots result. + */ + ErrCode AddNotificationSlots(const std::vector &slots); + + /** + * @brief Deletes a created notification slot based on the slot ID. + * + * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot + * This parameter must be specified. + * @return Returns remove notification slot result. + */ + ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); + + /** + * @brief Deletes all notification slots. + * + * @return Returns remove all slots result. + */ + ErrCode RemoveAllSlots(); + + /** + * @brief Queries a created notification slot. + * + * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This + * parameter must be specified. + * @param slot Indicates the created NotificationSlot. + * @return Returns the get notification slot result. + */ + ErrCode GetNotificationSlot(const NotificationConstant::SlotType &slotType, sptr &slot); + + /** + * @brief Obtains all notification slots of this application. + * + * @param slots Indicates the created NotificationSlot. + * @return Returns all notification slots of this application. + */ + ErrCode GetNotificationSlots(std::vector> &slots); + + /** + * @brief Obtains number of slot. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param num Indicates number of slot. + * @return Returns get slot number by bundle result. + */ + ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num); + + /** + * @brief Obtains slotFlags of bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotFlags Indicates slotFlags of bundle. + * @return Returns get slotflags by bundle result. + */ + ErrCode GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags); + + /** + * @brief Set slotFlags of bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotFlags Indicates slotFlags of bundle. + * @return Returns set slotflags by bundle result. + */ + ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags); + + + /** + * @brief Publishes a notification with a specified label. + * @note If a notification with the same ID has been published by the current application and has not been deleted, + * this method will update the notification. + * + * @param label Indicates the label of the notification to publish. + * @param request Indicates the NotificationRequest object for setting the notification content. + * This parameter must be specified. + * @return Returns publish notification result. + */ + ErrCode PublishNotification(const std::string &label, const NotificationRequest &request); + + /** + * @brief Publishes a notification. + * @note If a notification with the same ID has been published by the current application and has not been deleted, + * this method will update the notification. + * + * @param request Indicates the NotificationRequest object for setting the notification content. + * This parameter must be specified. + * @return Returns publish notification result. + */ + ErrCode PublishNotificationForIndirectProxy(const NotificationRequest &request); + + /** + * @brief Cancels a published notification. + * + * @param notificationId Indicates the unique notification ID in the application. + * The value must be the ID of a published notification. + * Otherwise, this method does not take effect. + * @return Returns cancel notification result. + */ + ErrCode CancelNotification(int32_t notificationId); + + /** + * @brief Cancels a published notification matching the specified label and notificationId. + * + * @param label Indicates the label of the notification to cancel. + * @param notificationId Indicates the ID of the notification to cancel. + * @return Returns cancel notification result. + */ + ErrCode CancelNotification(const std::string &label, int32_t notificationId); + + /** + * @brief Cancels all the published notifications. + * @note To cancel a specified notification, see CancelNotification(int32_t). + * + * @return Returns cancel all notifications result. + */ + ErrCode CancelAllNotifications(); + + /** + * @brief Cancels a published agent notification. + * + * @param notificationId Indicates the unique notification ID in the application. + * The value must be the ID of a published notification. + * Otherwise, this method does not take effect. + * @param representativeBundle Indicates the name of application bundle your application is representing. + * @param userId Indicates the specific user. + * @return Returns cancel notification result. + */ + ErrCode CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId); + + /** + * @brief Cancels a published agent notification. + * + * @param bundleOption Indicates the bundle of application your application is representing. + * @param notificationId Indicates the unique notification ID in the application. + * The value must be the ID of a published notification. + * Otherwise, this method does not take effect. + * @return Returns cancel notification result. + */ + ErrCode CancelAsBundle(const NotificationBundleOption &bundleOption, int32_t notificationId); + + /** + * @brief Obtains the number of active notifications of the current application in the system. + * + * @param num Indicates the number of active notifications of the current application. + * @return Returns get active notification nums result. + */ + ErrCode GetActiveNotificationNums(uint64_t &num); + + /** + * @brief Obtains active notifications of the current application in the system. + * + * @param request Indicates active NotificationRequest objects of the current application. + * @return Returns get active notifications result. + */ + ErrCode GetActiveNotifications(std::vector> &request); + + /** + * @brief Checks whether your application has permission to publish notifications by calling + * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the + * given representativeBundle. + * + * @param representativeBundle Indicates the name of application bundle your application is representing. + * @param canPublish Indicates whether your application has permission to publish notifications. + * @return Returns can publish notification as bundle result. + */ + ErrCode CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish); + + /** + * @brief Publishes a notification in the name of a specified application bundle. + * @note If the notification to be published has the same ID as a published notification that has not been canceled, + * the existing notification will be replaced by the new one. + * + * @param request Indicates the NotificationRequest object for setting the notification content. + * This parameter must be specified. + * @param representativeBundle Indicates the name of the application bundle that allows your application to publish + * notifications for it by calling setNotificationAgent. + * @return Returns publish notification as bundle result. + */ + ErrCode PublishNotificationAsBundle(const std::string &representativeBundle, const NotificationRequest &request); + + /** + * @brief Sets the number of active notifications of the current application as the number to be displayed on the + * notification badge. + * + * @return Returns set notification badge num result. + */ + ErrCode SetNotificationBadgeNum(); + + /** + * @brief Sets the number to be displayed on the notification badge of the application. + * + * @param num Indicates the number to display. A negative number indicates that the badge setting remains unchanged. + * The value 0 indicates that no badge is displayed on the application icon. + * If the value is greater than 99, 99+ will be displayed. + * @return Returns set notification badge num result. + */ + ErrCode SetNotificationBadgeNum(int32_t num); + + /** + * @brief Checks whether this application has permission to publish notifications. The caller must have + * system permissions to call this method. + * + * @param allowed True if this application has the permission; returns false otherwise + * @return Returns is allowed notify result. + */ + ErrCode IsAllowedNotify(bool &allowed); + + /** + * @brief Checks whether this application has permission to publish notifications. + * + * @param allowed True if this application has the permission; returns false otherwise + * @return Returns is allowed notify result. + */ + ErrCode IsAllowedNotifySelf(bool &allowed); + + /** + * @brief Checks whether this application can pop enable notification dialog. + * + * @param canPop True if can pop enable notification dialog + * @return Returns is canPop result. + */ + ErrCode CanPopEnableNotificationDialog(sptr &hostClient, + bool &canPop, std::string &bundleName); + + /** + * @brief remove enable notification dialog. + * + * @return Returns remove dialog result. + */ + ErrCode RemoveEnableNotificationDialog(); + + /** + * @brief Allows the current application to publish notifications on a specified device. + * + * @param deviceId Indicates the ID of the device running the application. At present, this parameter can + * only be null or an empty string, indicating the current device. + * @return Returns set notifications enabled for default bundle result. + */ + ErrCode RequestEnableNotification(std::string &deviceId, + sptr &hostClient, + sptr &callerToken); + + /** + * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. + * + * @param hasPermission True if this application is suspended; returns false otherwise. + * @return Returns has notification policy access permission. + */ + ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission); + + /** + * @brief Obtains the importance level of this application. + * + * @param importance the importance level of this application, which can be LEVEL_NONE, + LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED. + * @return Returns get bundle importance result + */ + ErrCode GetBundleImportance(NotificationSlot::NotificationLevel &importance); + + /** + * @brief Subscribes to notifications from all applications. This method can be called only by applications + * with required system permissions. + * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. To subscribe to notifications published only by specified sources, for example, notifications from + * certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} + * method. + * @deprecated This function is deprecated, + * use 'SubscribeNotification(const std::shared_ptr &subscriber)'. + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeNotification(const NotificationSubscriber &subscriber); + + /** + * @brief Subscribes to notifications from all applications. This method can be called only by applications + * with required system permissions. + * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. To subscribe to notifications published only by specified sources, for example, notifications from + * certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} + * method. + * + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeNotification(const std::shared_ptr &subscriber); + + /** + * @brief Subscribes to notifications from the appliaction self. + * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. + * @deprecated This function is deprecated, + * use 'SubscribeNotificationSelf(const std::shared_ptr &subscriber)'. + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeNotificationSelf(const NotificationSubscriber &subscriber); + + /** + * @brief Subscribes to notifications from the appliaction self. + * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. + * + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeNotificationSelf(const std::shared_ptr &subscriber); + + /** + * @brief Subscribes liveView notification. This method can be called only by applications + * with required system permissions. + * @note To subscribe to a notification, inherit the {NotificationLocalLiveViewSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * + * @param subscriber Indicates the {NotificationLocalLiveViewSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber, + const bool isNative = true); + + /** + * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only + * by applications with required system permissions. + * @note After {subscribeInfo} is specified, a subscriber receives only the notifications that + * meet the filter criteria specified by {subscribeInfo}. + * To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. To subscribe to and receive all notifications, call the + * {SubscribeNotification(NotificationSubscriber)} method. + * @deprecated This function is deprecated, + * use 'SubscribeNotification(const std::shared_ptr &subscriber, + * const std::shared_ptr &subscribeInfo)'. + * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. + * For details, see {NotificationSubscriber}. + * @param subscribeInfo Indicates the filters for specified notification sources, including application name, + * user ID, or device name. This parameter is optional. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeNotification( + const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo); + + /** + * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only + * by applications with required system permissions. + * @note After {subscribeInfo} is specified, a subscriber receives only the notifications that + * meet the filter criteria specified by {subscribeInfo}. + * To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. To subscribe to and receive all notifications, call the + * {SubscribeNotification(NotificationSubscriber)} method. + * + * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. + * For details, see {NotificationSubscriber}. + * @param subscribeInfo Indicates the filters for specified notification sources, including application name, + * user ID, or device name. This parameter is optional. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeNotification(const std::shared_ptr &subscriber, + const sptr &subscribeInfo); + + /** + * @brief Unsubscribes from all notifications. This method can be called only by applications with required + * system permissions. + * @note Generally, you subscribe to a notification by calling the + * {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application + * to receive a notification any longer, unsubscribe from that notification using this method. + * You can unsubscribe from only those notifications that your application has subscribed to. + * To unsubscribe from notifications published only by specified sources, for example, + * notifications from certain applications, call the + * {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method. + * @deprecated This function is deprecated, + * use 'UnSubscribeNotification(const std::shared_ptr &subscriber)'. + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns unsubscribe notification result. + */ + ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber); + + /** + * @brief Unsubscribes from all notifications. This method can be called only by applications with required + * system permissions. + * @note Generally, you subscribe to a notification by calling the + * {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application + * to receive a notification any longer, unsubscribe from that notification using this method. + * You can unsubscribe from only those notifications that your application has subscribed to. + * To unsubscribe from notifications published only by specified sources, for example, + * notifications from certain applications, call the + * {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method. + * + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns unsubscribe notification result. + */ + ErrCode UnSubscribeNotification(const std::shared_ptr &subscriber); + + /** + * @brief Unsubscribes from all notifications based on the filtering criteria. This method can be called + * only by applications with required system permissions. + * @note A subscriber will no longer receive the notifications from specified notification sources. + * + * @deprecated This function is deprecated, + * use 'UnSubscribeNotification(const std::shared_ptr &subscriber, + * const std::shared_ptr &subscribeInfo)'. + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @param subscribeInfo Indicates the filters for , including application name, + * user ID, or device name. This parameter is optional. + * @return Returns unsubscribe notification result. + */ + ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo); + + /** + * @brief Unsubscribes from all notifications based on the filtering criteria. This method can be called + * only by applications with required system permissions. + * @note A subscriber will no longer receive the notifications from specified notification sources. + * + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @param subscribeInfo Indicates the filters for , including application name, + * user ID, or device name. This parameter is optional. + * @return Returns unsubscribe notification result. + */ + ErrCode UnSubscribeNotification(const std::shared_ptr &subscriber, + const sptr &subscribeInfo); + + /** + * @brief Trigger the local live view after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localLiveView result. + */ + ErrCode TriggerLocalLiveView(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const NotificationButtonOption &buttonOption); + + /** + * @brief Removes a specified removable notification of other applications. + * @note Your application must have platform signature to use this method. + * + * @param key Indicates the key of the notification to remove. + * @param removeReason Indicates the reason of remove notification. + * @return Returns remove notification result. + */ + ErrCode RemoveNotification(const std::string &key, int32_t removeReason); + + /** + * @brief Removes a specified removable notification of other applications. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed. + * @param notificationId Indicates the id of the notification to remove. + * @param label Indicates the label of the notification to remove. + * @param removeReason Indicates the reason of remove notification. + * @return Returns remove notification result. + */ + ErrCode RemoveNotification(const NotificationBundleOption &bundleOption, const int32_t notificationId, + const std::string &label, int32_t removeReason); + + /** + * @brief Removes a specified removable notification of other applications. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed. + * @return Returns remove notification result. + */ + ErrCode RemoveAllNotifications(const NotificationBundleOption &bundleOption); + + ErrCode RemoveNotifications(const std::vector hashcodes, int32_t removeReason); + + /** + * @brief Removes all removable notifications of a specified bundle. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed. + * @return Returns remove notifications result. + */ + ErrCode RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption); + + /** + * @brief Removes all removable notifications in the system. + * @note Your application must have platform signature to use this method. + * + * @return Returns remove notifications result. + */ + ErrCode RemoveNotifications(); + + /** + * @brief Obtains all notification slots belonging to the specified bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slots Indicates a list of notification slots. + * @return Returns get notification slots for bundle result. + */ + ErrCode GetNotificationSlotsForBundle( + const NotificationBundleOption &bundleOption, std::vector> &slots); + + /** + * @brief Obtains notification slot belonging to the specified bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot. + * @param slot Indicates a notification slot. + * @return Returns get notification slots for bundle result. + */ + ErrCode GetNotificationSlotForBundle( + const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot); + + /** + * @brief Updates all notification slots for the specified bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slots Indicates a list of new notification slots. + * @return Returns update notification slots for bundle result. + */ + ErrCode UpdateNotificationSlots( + const NotificationBundleOption &bundleOption, const std::vector> &slots); + + /** + * @brief Obtains all active notifications in the current system. The caller must have system permissions to + * call this method. + * + * @param notification Indicates all active notifications of this application. + * @return Returns get all active notifications + */ + ErrCode GetAllActiveNotifications(std::vector> ¬ification); + + /** + * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method + * to obtain particular active notifications, you must have received the notifications and obtained the key + * via {Notification::GetKey()}. + * + * @param key Indicates the key array for querying corresponding active notifications. + * If this parameter is null, this method returns all active notifications in the system. + * @param notification Indicates the set of active notifications corresponding to the specified key. + * @return Returns get all active notifications result. + */ + ErrCode GetAllActiveNotifications( + const std::vector key, std::vector> ¬ification); + + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * @param filter + * @param extraInfo + * @return + */ + ErrCode GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request); + + /** + * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies + * the current application, no permission is required for calling this method. If bundle specifies another + * application, the caller must have system permissions. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param allowed True if the application has permissions; returns false otherwise. + * @return Returns is allowed notify result. + */ + ErrCode IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed); + + /** + * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must + * have system permissions to call this method. + * + * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only + * be null or an empty string, indicating the current device. + * @param enabled Specifies whether to allow all applications to publish notifications. The value true + * indicates that notifications are allowed, and the value false indicates that notifications are not + * allowed. + * @return Returns set notifications enabled for all bundles result. + */ + ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled); + + /** + * @brief Sets whether to allow the current application to publish notifications on a specified device. The caller + * must have system permissions to call this method. + * + * @param deviceId Indicates the ID of the device running the application. At present, this parameter can + * only be null or an empty string, indicating the current device. + * @param enabled Specifies whether to allow the current application to publish notifications. The value + * true indicates that notifications are allowed, and the value false indicates that + * notifications are not allowed. + * @return Returns set notifications enabled for default bundle result. + */ + ErrCode SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled); + + /** + * @brief Sets whether to allow a specified application to publish notifications on a specified device. The caller + * must have system permissions to call this method. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only + * be null or an empty string, indicating the current device. + * @param enabled Specifies whether to allow the given application to publish notifications. The value + * true indicates that notifications are allowed, and the value false indicates that notifications + * are not allowed. + * @return Returns set notifications enabled for specified bundle result. + */ + ErrCode SetNotificationsEnabledForSpecifiedBundle( + const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled); + + /** + * @brief Sets whether to allow a specified application to to show badge. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param enabled Specifies whether to allow the given application to show badge. + * @return Returns set result. + */ + ErrCode SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled); + + /** + * @brief Obtains the flag that whether to allow a specified application to to show badge. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param enabled Specifies whether to allow the given application to show badge. + * @return Returns get result. + */ + ErrCode GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled); + + /** + * @brief Obtains the flag that whether to allow the current application to to show badge. + * + * @param enabled Specifies whether to allow the given application to show badge. + * @return Returns get result. + */ + ErrCode GetShowBadgeEnabled(bool &enabled); + + /** + * @brief Cancels 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); + + /** + * @brief Removes the notification of the specified group of the specified application. + * + * @param bundleOption Indicates the bundle name and uid of the specified application. + * @param groupName Indicates the specified group name. + * @return Returns remove group by bundle result. + */ + ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName); + + /** + * @brief Sets the do not disturb time. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbDate Indicates the do not disturb time to set. + * @return Returns set do not disturb time result. + */ + ErrCode SetDoNotDisturbDate(const NotificationDoNotDisturbDate &doNotDisturbDate); + + /** + * @brief Obtains the do not disturb time. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbDate Indicates the do not disturb time to get. + * @return Returns set do not disturb time result. + */ + ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate); + + /** + * @brief Add the do not disturb profiles. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbProfiles Indicates the do not disturb profiles to add. + * @return Returns add do not disturb profiles result. + */ + ErrCode AddDoNotDisturbProfiles(const std::vector> &profiles); + + /** + * @brief Remove the do not disturb profiles. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbProfiles Indicates the do not disturb profiles to remove. + * @return Returns remove do not disturb profiles result. + */ + ErrCode RemoveDoNotDisturbProfiles(const std::vector> &profiles); + + /** + * @brief Obtains the flag that whether to support do not disturb mode. + * + * @param doesSupport Specifies whether to support do not disturb mode. + * @return Returns check result. + */ + ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport); + + /** + * @brief Is coming call need silent in do not disturb mode. + * + * @param phoneNumber the calling format number. + * @return Returns silent in do not disturb mode. + */ + ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType); + + /** + * @brief Checks if the device supports distributed notification. + * + * @param enabled True if the device supports distributed notification; false otherwise. + * @return Returns is distributed enabled result. + */ + ErrCode IsDistributedEnabled(bool &enabled); + + /** + * @brief Sets whether the device supports distributed notifications. + * + * @param enable Specifies whether to enable the device to support distributed notification. + * The value true indicates that the device is enabled to support distributed notifications, and + * the value false indicates that the device is forbidden to support distributed notifications. + * @return Returns enable distributed result. + */ + ErrCode EnableDistributed(const bool enabled); + + /** + * @brief Sets whether an application supports distributed notifications. + * + * @param bundleOption Indicates the bundle name and uid of an application. + * @param enabled Specifies whether to enable an application to support distributed notification. + * The value true indicates that the application is enabled to support distributed notifications, + * and the value false indicates that the application is forbidden to support distributed + * notifications. + * @return Returns enable distributed by bundle result. + */ + ErrCode EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled); + + /** + * @brief Sets whether this application supports distributed notifications. + * + * @param enabled Specifies whether to enable this application to support distributed notification. + * The value true indicates that this application is enabled to support distributed notifications, + * and the value false indicates that this application is forbidden to support distributed + * notifications. + * @return Returns enable distributed self result. + */ + ErrCode EnableDistributedSelf(const bool enabled); + + /** + * @brief Checks whether an application supports distributed notifications. + * + * @param bundleOption Indicates the bundle name and uid of an application. + * @param enabled True if the application supports distributed notification; false otherwise. + * @return Returns is distributed enabled by bundle result. + */ + ErrCode IsDistributedEnableByBundle(const NotificationBundleOption &bundleOption, bool &enabled); + + /** + * @brief Obtains the device remind type. + * @note Your application must have system signature to call this method. + * + * @param remindType Indicates the device remind type to get. + * @return Returns get device reminder type result. + */ + ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType); + + /** + * @brief Publishes a continuous task notification. + * + * @param request Indicates the NotificationRequest object for setting the notification content. + * This parameter must be specified. + * @return Returns publish continuous task notification result. + */ + ErrCode PublishContinuousTaskNotification(const NotificationRequest &request); + + /** + * @brief Cancels a published continuous task notification matching the specified label and notificationId. + * + * @param label Indicates the label of the continuous task notification to cancel. + * @param notificationId Indicates the ID of the continuous task notification to cancel. + * @return Returns cancel continuous task notification result. + */ + ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId); + + /** + * @brief Obtains whether the template is supported by the system. + * + * @param support whether is it a system supported template. + * @return Returns check result. + */ + ErrCode IsSupportTemplate(const std::string &templateName, bool &support); + + /** + * @brief Resets ans manager proxy when OnRemoteDied called. + */ + void ResetAnsManagerProxy(); + + /** + * @brief try to reconnect ans SA when SA manager OnAddSystemAbility called. + */ + void Reconnect(); + + /** + * @brief Publishes a scheduled reminder. + * + * @param reminder Indicates a reminder. + * @return Returns publish result. + */ + ErrCode PublishReminder(ReminderRequest &reminder); + + /** + * @brief Cancels a specified reminder. + * + * @param reminderId Indicates reminder Id. + * @return Returns cancel result. + */ + ErrCode CancelReminder(const int32_t reminderId); + + /** + * @brief Cancels all reminders of current third part application. + * + * @return Returns cancel result. + */ + ErrCode CancelAllReminders(); + + /** + * @brief Obtains all valid reminder notifications set by the current application. + * + * @param[out] validReminders Indicates the vector to store the result. + * @return Returns get valid reminders result. + */ + ErrCode GetValidReminders(std::vector> &validReminders); + + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId); + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); + + /** + * @brief Checks whether this application has permission to publish notifications under the user. + * + * @param userId Indicates the userId of the application. + * @param allowed True if the application has permissions; returns false otherwise. + * @return Returns get allowed result. + */ + ErrCode IsAllowedNotify(const int32_t &userId, bool &allowed); + + /** + * @brief Sets the do not disturb time on a specified user. + * @note Your application must have system signature to call this method. + * + * @param userId Indicates the specific user. + * @param doNotDisturbDate Indicates the do not disturb time to set. + * @return Returns set do not disturb time result. + */ + ErrCode SetDoNotDisturbDate(const int32_t &userId, const NotificationDoNotDisturbDate &doNotDisturbDate); + + /** + * @brief Obtains the do not disturb time on a specified user. + * @note Your application must have system signature to call this method. + * + * @param userId Indicates the specific user. + * @param doNotDisturbDate Indicates the do not disturb time to get. + * @return Returns set do not disturb time result. + */ + ErrCode GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate); + + /** + * Set whether the application slot is enabled. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotType Indicates type of slot. + * @param enable the type of slot enabled. + * @param isForceControl Indicates whether the slot is affected by the notification switch. + * @return Returns get slot number by bundle result. + */ + ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); + + /** + * Obtains whether the application slot is enabled. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotType Indicates type of slot. + * @param enable the type of slot enabled to get. + * @return Returns get slot number by bundle result. + */ + ErrCode GetEnabledForBundleSlot( + const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled); + + /** + * Obtains whether the current application slot is enabled. + * + * @param slotType Indicates type of slot. + * @param enable the type of slot enabled to get. + * @return Returns get enabled result. + */ + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); + + /** + * @brief Obtains specific datas via specified dump option. + * + * @param cmd Indicates the specified dump command. + * @param bundle Indicates the specified bundle name. + * @param userId Indicates the specified userId. + * @param recvUserId Indicates the specified receiver userId. + * @param dumpInfo Indicates the container containing datas. + * @return Returns check result. + */ + ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, + std::vector &dumpInfo); + + /** + * @brief Set whether to sync notifications to devices that do not have the app installed. + * + * @param userId Indicates the specific user. + * @param enabled Allow or disallow sync notifications. + * @return Returns set enabled result. + */ + ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled); + + /** + * @brief Obtains whether to sync notifications to devices that do not have the app installed. + * + * @param userId Indicates the specific user. + * @param enabled Allow or disallow sync notifications. + * @return Returns get enabled result. + */ + ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled); + + /** + * @brief Set badge number. + * + * @param badgeNumber The badge number. + * @return Returns set badge number result. + */ + ErrCode SetBadgeNumber(int32_t badgeNumber); + + /** + * @brief Set badge number by bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param badgeNumber The badge number. + * @return Returns set badge number by bundle result. + */ + ErrCode SetBadgeNumberByBundle(const NotificationBundleOption &bundleOption, int32_t badgeNumber); + + /** + * @brief Obtains allow notification application list. + * + * @param bundleOption Indicates the bundle bundleOption. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetAllNotificationEnabledBundles(std::vector &bundleOption); + + /** + * @brief Register Push Callback. + * + * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check + * @return Returns register PushCallback result. + */ + ErrCode RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest); + + /** + * @brief Unregister Push Callback. + * + * @return Returns unregister push Callback result. + */ + ErrCode UnregisterPushCallback(); + + /** + * @brief Set agent relationship. + * + * @param key Indicates storing agent relationship if the value is "PROXY_PKG". + * @param value Indicates key-value pair of agent relationship. + * @return Returns set result. + */ + ErrCode SetAdditionConfig(const std::string &key, const std::string &value); + + /** + * @brief Sets whether to allow a specified application to publish notifications cross + * device collaboration. The caller must have system permissions to call this method. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param deviceType Indicates the type of the device running the application. + * @param enabled Specifies whether to allow the given application to publish notifications. The value + * true indicates that notifications are allowed, and the value false indicates that notifications + * are not allowed. + * @return Returns set notifications enabled for specified bundle result. + */ + ErrCode SetDistributedEnabledByBundle( + const NotificationBundleOption &bundleOption, const std::string &deviceType, const bool enabled); + + /** + * @brief get whether to allow a specified application to publish notifications cross + * device collaboration. The caller must have system permissions to call this method. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param deviceType Indicates the type of the device running the application. + * @param enabled Specifies whether to allow the given application to publish notifications. The value + * true indicates that notifications are allowed, and the value false indicates that notifications + * are not allowed. + * @return Returns set notifications enabled for specified bundle result. + */ + ErrCode IsDistributedEnabledByBundle( + const NotificationBundleOption &bundleOption, const std::string &deviceType, bool &enabled); + + /** + * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders + * + * @param deviceType Indicates the type of the device running the application. + * @param enabled Specifies whether to allow the given application to publish notifications. + * The value true indicates that notifications are allowed, and the value + * false indicates that notifications are not allowed. + * @return Returns set notifications enabled for specified bundle result. + */ + ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled); + + /** + * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders + * + * @param deviceType Indicates the type of the device running the application. + * @param enabled Specifies whether to allow the given application to publish notifications. + * The value true indicates that notifications are allowed, and the value + * false indicates that notifications are not allowed. + * @return Returns set notifications enabled for specified bundle result. + */ + ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled); + + /** + * @brief Cancels a published agent notification. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param id Indicates the unique notification ID in the application. + * @return Returns cancel result. + */ + ErrCode CancelAsBundleWithAgent(const NotificationBundleOption &bundleOption, const int32_t id); + + /** + * @brief Set the status of the target device. + * + * @param deviceType Type of the device whose status you want to set. + * @param status The status. + * @return Returns set result. + */ + ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status); + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + /** + * @brief Register Swing swingCbFunc. + * + * @param swingCallback swingCbFunc. + * @return Returns register swingCbFunc result. + */ + ErrCode RegisterSwingCallback(const std::function swingCbFunc); +#endif + + /** + * @brief Get do not disturb profile by id. + * + * @param id Profile id. + * @param status Indicates the NotificationDoNotDisturbProfile objects. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile); + + /** + * @brief Ans service died, OnRemoteDied called. + */ + void OnServiceDied(); +private: + /** + * @brief Gets Ans Manager proxy. + * + * @return Returns true if succeed; returns false otherwise. + */ + sptr GetAnsManagerProxy(); + + /** + * @brief Checks if the MediaContent can be published. + * + * @param request Indicates the specified request. + * @return Returns true if the MediaContent can be published; returns false otherwise. + */ + bool CanPublishMediaContent(const NotificationRequest &request) const; + + /** + * @brief Checks whether the picture size exceeds the limit. + * + * @param request Indicates the specified request. + * @return Returns the ErrCode. + */ + ErrCode CheckImageSize(const NotificationRequest &request); + + /** + * @brief Checks whether the notification doesn't support distribution. + * + * @param type Indicates the specified NotificationContent::Type. + * @return Returns true if the notification doesn't support distribution; returns false otherwise. + */ + bool IsNonDistributedNotificationType(const NotificationContent::Type &type); + + /** + * @brief Checks if the LiveViewContent can be published. + * + * @param request Indicates the specified request. + * @return Returns true if the MediaContent can be published; returns false otherwise. + */ + bool CanPublishLiveViewContent(const NotificationRequest &request) const; + + bool IsValidTemplate(const NotificationRequest &request) const; + bool IsValidDelayTime(const NotificationRequest &request) const; + void CreateSubscribeListener(const std::shared_ptr &subscriber, + sptr &listener); + +private: + std::mutex subscriberMutex_; + std::map, sptr> subscribers_; +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + sptr swingCallBackStub_; +#endif +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H diff --git a/frameworks/reminder/include/reminder_manager_interface.h b/frameworks/reminder/include/reminder_manager_interface.h new file mode 100644 index 000000000..8fde26928 --- /dev/null +++ b/frameworks/reminder/include/reminder_manager_interface.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_INTERFACE_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_INTERFACE_H + +#include +#include + +#include "ans_dialog_callback_interface.h" +#include "ans_subscriber_interface.h" +#include "ans_subscriber_local_live_view_interface.h" +#include "iremote_broker.h" +#include "notification_bundle_option.h" +#include "notification_constant.h" +#include "notification_do_not_disturb_date.h" +#include "notification_do_not_disturb_profile.h" +#include "notification_request.h" +#include "notification_slot.h" +#include "notification_subscribe_info.h" +#include "reminder_request.h" + +namespace OHOS { +namespace Notification { +class AnsManagerInterface : public IRemoteBroker { +public: + AnsManagerInterface() = default; + virtual ~AnsManagerInterface() = default; + DISALLOW_COPY_AND_MOVE(AnsManagerInterface); + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsManagerInterface"); + + /** + * @brief Publishes a reminder notification. + * + * @param reminder Identifies the reminder notification request that needs to be published. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode PublishReminder(sptr &reminder) = 0; + + /** + * @brief Cancel a reminder notifications. + * + * @param reminderId Identifies the reminders id that needs to be canceled. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode CancelReminder(const int32_t reminderId) = 0; + + /** + * @brief Get all valid reminder notifications. + * + * @param reminders Identifies the list of all valid notifications. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; + + /** + * @brief Cancel all reminder notifications. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode CancelAllReminders() = 0; + + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 0; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode DelExcludeDates(const int32_t reminderId) = 0; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 0; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_INTERFACE_H diff --git a/frameworks/reminder/include/reminder_manager_proxy.h b/frameworks/reminder/include/reminder_manager_proxy.h new file mode 100644 index 000000000..ebc153b5b --- /dev/null +++ b/frameworks/reminder/include/reminder_manager_proxy.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H + +#include "ans_manager_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_proxy.h" +#include "want_params.h" + +namespace OHOS { +namespace Notification { +class AnsManagerProxy : public IRemoteProxy { +public: + AnsManagerProxy() = delete; + explicit AnsManagerProxy(const sptr &impl); + ~AnsManagerProxy() override; + DISALLOW_COPY_AND_MOVE(AnsManagerProxy); + + /** + * @brief Publishes a reminder notification. + * + * @param reminder Identifies the reminder notification request that needs to be published. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode PublishReminder(sptr &reminder) override; + + /** + * @brief Cancel a reminder notifications. + * + * @param reminderId Identifies the reminders id that needs to be canceled. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode CancelReminder(const int32_t reminderId) override; + + /** + * @brief Get all valid reminder notifications. + * + * @param reminders Identifies the list of all valid notifications. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetValidReminders(std::vector> &reminders) override; + + /** + * @brief Cancel all reminder notifications. + * + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode CancelAllReminders() override; + + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId) override; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; + + ErrCode ReadReminders(uint8_t &count, MessageParcel &reply, std::vector> &reminders); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H diff --git a/frameworks/reminder/include/reminder_manager_stub.h b/frameworks/reminder/include/reminder_manager_stub.h new file mode 100644 index 000000000..e640cd359 --- /dev/null +++ b/frameworks/reminder/include/reminder_manager_stub.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_STUB_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_STUB_H + +#include +#include + +#include "ans_manager_interface.h" +#include "ans_subscriber_local_live_view_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Notification { +class AnsManagerStub : public IRemoteStub { +public: + AnsManagerStub(); + ~AnsManagerStub() override; + DISALLOW_COPY_AND_MOVE(AnsManagerStub); + + /** + * @brief Handle remote request. + * + * @param data Indicates the input parcel. + * @param reply Indicates the output parcel. + * @param option Indicates the message option. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + /** + * @brief Publishes a reminder notification. + * + * @param reminder Identifies the reminder notification request that needs to be published. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode PublishReminder(sptr &reminder) override; + + /** + * @brief Cancel a reminder notifications. + * + * @param reminderId Identifies the reminders id that needs to be canceled. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode CancelReminder(const int32_t reminderId) override; + + /** + * @brief Get all valid reminder notifications. + * + * @param reminders Identifies the list of all valid notifications. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetValidReminders(std::vector> &reminders) override; + + /** + * @brief Cancel all reminder notifications. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode CancelAllReminders() override; + + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode DelExcludeDates(const int32_t reminderId) override; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; + +private: + ErrCode HandlePublishReminder(MessageParcel &data, MessageParcel &reply); + ErrCode HandleCancelReminder(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetValidReminders(MessageParcel &data, MessageParcel &reply); + ErrCode HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply); + ErrCode HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply); + ErrCode HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_STUB_H diff --git a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp b/frameworks/reminder/src/ans_manager_proxy_reminder.cpp similarity index 100% rename from frameworks/core/src/manager/ans_manager_proxy_reminder.cpp rename to frameworks/reminder/src/ans_manager_proxy_reminder.cpp diff --git a/frameworks/reminder/src/ans_manager_stub.cpp b/frameworks/reminder/src/ans_manager_stub.cpp new file mode 100644 index 000000000..ded5e9a92 --- /dev/null +++ b/frameworks/reminder/src/ans_manager_stub.cpp @@ -0,0 +1,2650 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_manager_stub.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_subscriber_local_live_view_interface.h" +#include "message_option.h" +#include "message_parcel.h" +#include "notification_bundle_option.h" +#include "notification_button_option.h" +#include "parcel.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" + +namespace OHOS { +namespace Notification { +AnsManagerStub::AnsManagerStub() {} + +AnsManagerStub::~AnsManagerStub() {} + +int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags) +{ + std::u16string descriptor = AnsManagerStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + ANS_LOGE("[OnRemoteRequest] fail: invalid interface token!"); + return OBJECT_NULL; + } + ErrCode result = NO_ERROR; + switch (code) { + case static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION): { + result = HandlePublish(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION_INDIRECTPROXY): { + result = HandlePublishNotificationForIndirectProxy(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_NOTIFICATION): { + result = HandleCancel(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_ALL_NOTIFICATIONS): { + result = HandleCancelAll(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_OPTION): { + result = HandleCancelAsBundleOption(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_AND_USER): { + result = HandleCancelAsBundleAndUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE): { + result = HandleCancelAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ADD_SLOT_BY_TYPE): { + result = HandleAddSlotByType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ADD_SLOTS): { + result = HandleAddSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_SLOT_BY_TYPE): { + result = HandleRemoveSlotByType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_ALL_SLOTS): { + result = HandleRemoveAllSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOT_BY_TYPE): { + result = HandleGetSlotByType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOTS): { + result = HandleGetSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOT_NUM_AS_BUNDLE): { + result = HandleGetSlotNumAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATIONS): { + result = HandleGetActiveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_NUMS): { + result = HandleGetActiveNotificationNums(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ALL_ACTIVE_NOTIFICATIONS): { + result = HandleGetAllActiveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SPECIAL_ACTIVE_NOTIFICATIONS): { + result = HandleGetSpecialActiveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER): { + result = HandleGetActiveNotificationByFilter(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CAN_PUBLISH_AS_BUNDLE): { + result = HandleCanPublishAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_AS_BUNDLE): { + result = HandlePublishAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_BADGE_NUM): { + result = HandleSetNotificationBadgeNum(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_BUNDLE_IMPORTANCE): { + result = HandleGetBundleImportance(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_NOTIFICATION_POLICY_ACCESS_GRANTED): { + result = HandleIsNotificationPolicyAccessGranted(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION): { + result = HandleRemoveNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_ALL_NOTIFICATIONS): { + result = HandleRemoveAllNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATIONS_BY_KEYS): { + result = HandleRemoveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION): { + result = HandleDelete(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION_BY_BUNDLE): { + result = HandleDeleteByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS): { + result = HandleDeleteAll(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOTS_BY_BUNDLE): { + result = HandleGetSlotsByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UPDATE_SLOTS): { + result = HandleUpdateSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION): { + result = HandleRequestEnableNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE): { + result = HandleSetNotificationsEnabledForBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE): { + result = HandleSetNotificationsEnabledForAllBundles(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE): { + result = HandleSetNotificationsEnabledForSpecialBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE): { + result = HandleSetShowBadgeEnabledForBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE): { + result = HandleGetShowBadgeEnabledForBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED): { + result = HandleGetShowBadgeEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION): { + result = HandleSubscribe(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION): { + result = HandleUnsubscribe(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_ALLOWED_NOTIFY): { + result = HandleIsAllowedNotify(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_ALLOWED_NOTIFY_SELF): { + result = HandleIsAllowedNotifySelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CAN_POP_ENABLE_NOTIFICATION_DIALOG): { + result = HandleCanPopEnableNotificationDialog(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_ENABLE_NOTIFICATION_DIALOG): { + result = HandleRemoveEnableNotificationDialog(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY): { + result = HandleIsSpecialBundleAllowedNotify(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE): { + result = HandleSetDoNotDisturbDate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE): { + result = HandleGetDoNotDisturbDate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DOES_SUPPORT_DO_NOT_DISTURB_MODE): { + result = HandleDoesSupportDoNotDisturbMode(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_NEED_SILENT_IN_DO_NOT_DISTURB_MODE): { + result = HandleIsNeedSilentInDoNotDisturbMode(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_GROUP): { + result = HandleCancelGroup(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE): { + result = HandleRemoveGroupByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED): { + result = HandleIsDistributedEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED): { + result = HandleEnableDistributed(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_BY_BUNDLE): { + result = HandleEnableDistributedByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_SELF): { + result = HandleEnableDistributedSelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED_BY_BUNDLE): { + result = HandleIsDistributedEnableByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DEVICE_REMIND_TYPE): { + result = HandleGetDeviceRemindType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SHELL_DUMP): { + result = HandleShellDump(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_CONTINUOUS_TASK_NOTIFICATION): { + result = HandlePublishContinuousTaskNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION): { + result = HandleCancelContinuousTaskNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_REMINDER): { + result = HandlePublishReminder(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_REMINDER): { + result = HandleCancelReminder(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS): { + result = HandleCancelAllReminders(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS): { + result = HandleGetValidReminders(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE): { + result = HandleIsSupportTemplate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_SPECIAL_USER_ALLOWED_NOTIFY): { + result = HandleIsSpecialUserAllowedNotifyByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER): { + result = HandleSetNotificationsEnabledByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER): { + result = HandleDeleteAllByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER): { + result = HandleSetDoNotDisturbDateByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER): { + result = HandleGetDoNotDisturbDateByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT): { + result = HandleSetEnabledForBundleSlot(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT): { + result = HandleGetEnabledForBundleSlot(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT_SELF): { + result = HandleGetEnabledForBundleSlotSelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_DISTRIBUTED_ENABLED_BY_BUNDLE): { + result = HandleSetDistributedEnabledByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DISTRIBUTED_ENABLED_BY_BUNDLE): { + result = HandleIsDistributedEnabledByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SMART_REMINDER_ENABLED): { + result = HandleSetSmartReminderEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SMART_REMINDER_ENABLED): { + result = HandleIsSmartReminderEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP): { + result = HandleDistributedSetEnabledWithoutApp(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP): { + result = HandleDistributedGetEnabledWithoutApp(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_BADGE_NUMBER): { + result = HandleSetBadgeNumber(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_BADGE_NUMBER_BY_BUNDLE): { + result = HandleSetBadgeNumberByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ALL_NOTIFICATION_ENABLE_STATUS): { + result = HandleGetAllNotificationEnableStatus(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REGISTER_PUSH_CALLBACK): { + result = HandleRegisterPushCallback(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UNREGISTER_PUSH_CALLBACK): { + result = HandleUnregisterPushCallback(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION): { + result = HandleSubscribeLocalLiveView(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION): { + result = HandleTriggerLocalLiveView(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION_SELF): { + result = HandleSubscribeSelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE): { + result = HandleSetSlotFlagsAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE): { + result = HandleGetSlotFlagsAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_AGENT_RELATIONSHIP): { + result = HandleSetAdditionConfig(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_WITH_AGENT): { + result = HandleCancelAsBundleWithAgent(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOT_BY_BUNDLE): { + result = HandleGetSlotByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ADD_DO_NOTDISTURB_PROFILES): { + result = HandleAddDoNotDisturbProfiles(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_DO_NOT_DISTURB_PROFILES): { + result = HandleRemoveDoNotDisturbProfiles(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_TARGET_DEVICE_STATUS): { + result = HandleSetTargetDeviceStatus(data, reply); + break; + } +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + case static_cast(NotificationInterfaceCode::REGISTER_SWING_CALLBACK): { + result = HandleRegisterSwingCallback(data, reply); + break; + } +#endif + case static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER): { + result = HandleAddExcludeDate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER): { + result = HandleDelExcludeDates(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER): { + result = HandleGetExcludeDates(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE): { + result = HandleGetDoNotDisturbProfile(data, reply); + break; + } + default: { + ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); + } + } + if (SUCCEEDED(result)) { + return NO_ERROR; + } + + ANS_LOGE("[OnRemoteRequest] fail: Failed to call interface %{public}u, err:%{public}d", code, result); + return result; +} + +ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply) +{ + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandlePublish] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr notification = data.ReadParcelable(); + if (!notification) { + ANS_LOGE("[HandlePublish] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = Publish(label, notification); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublish] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishNotificationForIndirectProxy(MessageParcel &data, MessageParcel &reply) +{ + sptr notification = data.ReadParcelable(); + if (!notification) { + ANS_LOGE("[HandlePublishNotificationForIndirectProxy] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishNotificationForIndirectProxy(notification); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublishNotificationForIndirectProxy] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancel(MessageParcel &data, MessageParcel &reply) +{ + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancel] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleCancel] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t instanceKey = 0; + if (!data.ReadInt32(instanceKey)) { + ANS_LOGE("[HandleCancel] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = Cancel(notificationId, label, instanceKey); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancel] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAll(MessageParcel &data, MessageParcel &reply) +{ + int32_t instanceKey = 0; + if (!data.ReadInt32(instanceKey)) { + ANS_LOGE("[HandleCancelAll] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelAll(instanceKey); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAll] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundleOption(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleCancelAsBundle] fail: read BundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + ErrCode result = CancelAsBundle(bundleOption, notificationId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundle(MessageParcel &data, MessageParcel &reply) +{ + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string representativeBundle; + if (!data.ReadString(representativeBundle)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read representativeBundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t userId = 0; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read userId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelAsBundle(notificationId, representativeBundle, userId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundleAndUser(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleCancelAsBundle] fail: read BundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t userId = 0; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read userId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + ErrCode result = CancelAsBundle(bundleOption, notificationId, userId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleAddSlotByType(MessageParcel &data, MessageParcel &reply) +{ + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + ErrCode result = AddSlotByType(slotType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleAddSlotByType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleAddSlots(MessageParcel &data, MessageParcel &reply) +{ + std::vector> slots; + if (!ReadParcelableVector(slots, data)) { + ANS_LOGE("[HandleAddSlots] fail: read slotsSize failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + ErrCode result = AddSlots(slots); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleAddSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveSlotByType(MessageParcel &data, MessageParcel &reply) +{ + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + + ErrCode result = RemoveSlotByType(slotType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveSlotByType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveAllSlots(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = RemoveAllSlots(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveAllSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlots(MessageParcel &data, MessageParcel &reply) +{ + std::vector> slots; + ErrCode result = GetSlots(slots); + if (!WriteParcelableVector(slots, reply, result)) { + ANS_LOGE("[HandleGetSlots] fail: write slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotByType(MessageParcel &data, MessageParcel &reply) +{ + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + + sptr slot = nullptr; + ErrCode result = GetSlotByType(slotType, slot); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotByType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(slot)) { + ANS_LOGE("[HandleGetSlotByType] fail: write slot failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotNumAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotNumAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + uint64_t num = 0; + ErrCode result = GetSlotNumAsBundle(bundleOption, num); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotNumAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint64(num)) { + ANS_LOGE("[HandleGetSlotNumAsBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t slotFlags = 0; + if (!data.ReadInt32(slotFlags)) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSlotFlagsAsBundle(bundleOption, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + uint32_t slotFlags = 0; + ErrCode result = GetSlotFlagsAsBundle(bundleOption, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint32(slotFlags)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply) +{ + int32_t instanceKey = 0; + if (!data.ReadInt32(instanceKey)) { + ANS_LOGE("[HandleGetActiveNotifications] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + std::vector> notifications; + ErrCode result = GetActiveNotifications(notifications, instanceKey); + if (!WriteParcelableVector(notifications, reply, result)) { + ANS_LOGE("[HandleGetActiveNotifications] fail: write notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply) +{ + uint64_t num = 0; + ErrCode result = GetActiveNotificationNums(num); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetActiveNotificationNums] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint64(num)) { + ANS_LOGE("[HandleGetActiveNotificationNums] fail: write num failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply) +{ + std::vector> notifications; + ErrCode result = GetAllActiveNotifications(notifications); + if (!WriteParcelableVector(notifications, reply, result)) { + ANS_LOGE("[HandleGetAllActiveNotifications] fail: write notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply) +{ + std::vector key; + if (!data.ReadStringVector(&key)) { + ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: read key failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector> notifications; + ErrCode result = GetSpecialActiveNotifications(key, notifications); + if (!WriteParcelableVector(notifications, reply, result)) { + ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: write notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetActiveNotificationByFilter(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector extraInfoKeys; + if (!data.ReadStringVector(&extraInfoKeys)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read extraInfoKeys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr request; + ErrCode result = GetActiveNotificationByFilter(bundleOption, notificationId, label, extraInfoKeys, request); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(request)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply) +{ + std::string representativeBundle; + if (!data.ReadString(representativeBundle)) { + ANS_LOGE("[HandleCanPublishAsBundle] fail: read representativeBundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool canPublish = false; + ErrCode result = CanPublishAsBundle(representativeBundle, canPublish); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCanPublishAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(canPublish)) { + ANS_LOGE("[HandleCanPublishAsBundle] fail: write canPublish failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr notification = data.ReadParcelable(); + if (!notification) { + ANS_LOGE("[HandlePublishAsBundle] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string representativeBundle; + if (!data.ReadString(representativeBundle)) { + ANS_LOGE("[HandlePublishAsBundle] fail: read representativeBundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishAsBundle(notification, representativeBundle); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublishAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationBadgeNum(MessageParcel &data, MessageParcel &reply) +{ + int32_t num = 0; + if (!data.ReadInt32(num)) { + ANS_LOGE("[HandleSetNotificationBadgeNum] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationBadgeNum(num); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationBadgeNum] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetBundleImportance(MessageParcel &data, MessageParcel &reply) +{ + int32_t importance = 0; + ErrCode result = GetBundleImportance(importance); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetBundleImportance] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(importance)) { + ANS_LOGE("[HandleGetBundleImportance] fail: write importance failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) +{ + sptr date = data.ReadParcelable(); + if (date == nullptr) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: read date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDoNotDisturbDate(date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) +{ + sptr date = nullptr; + + ErrCode result = GetDoNotDisturbDate(date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(date)) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) +{ + bool support = false; + + ErrCode result = DoesSupportDoNotDisturbMode(support); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(support)) { + ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write doesSupport failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsNeedSilentInDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) +{ + std::string phoneNumber; + if (!data.ReadString(phoneNumber)) { + ANS_LOGE("[HandleIsNeedSilentInDoNotDisturbMode] fail: read phoneNumber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t callerType = 0; + if (!data.ReadInt32(callerType)) { + ANS_LOGE("[HandleIsNeedSilentInDoNotDisturbMode] fail: read callerType failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsNeedSilentInDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply) +{ + sptr request = data.ReadParcelable(); + if (!request) { + ANS_LOGE("[HandlePublishContinuousTaskNotification] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishContinuousTaskNotification(request); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublishContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply) +{ + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelContinuousTaskNotification(label, notificationId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply) +{ + bool granted = false; + ErrCode result = HasNotificationPolicyAccessPermission(granted); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsNotificationPolicyAccessGranted] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(granted)) { + ANS_LOGE("[HandleIsNotificationPolicyAccessGranted] fail: write granted failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleTriggerLocalLiveView(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr buttonOption = data.ReadStrongParcelable(); + if (buttonOption == nullptr) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read button failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = TriggerLocalLiveView(bundleOption, notificationId, buttonOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveNotification(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleRemoveNotification] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleRemoveNotification] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleRemoveNotification] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t removeReason = 0; + if (!data.ReadInt32(removeReason)) { + ANS_LOGE("[HandleRemoveNotification] fail: read removeReason failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveNotification(bundleOption, notificationId, label, removeReason); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveAllNotifications(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleRemoveAllNotifications] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveAllNotifications(bundleOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveAllNotifications] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveNotifications(MessageParcel &data, MessageParcel &reply) +{ + int32_t keysSize = 0; + if (!data.ReadInt32(keysSize)) { + ANS_LOGE("read keys size failed."); + return false; + } + + std::vector keys; + if (!data.ReadStringVector(&keys)) { + ANS_LOGE("read keys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t removeReason = 0; + if (!data.ReadInt32(removeReason)) { + ANS_LOGE("read removeReason failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveNotifications(keys, removeReason); + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + + +ErrCode AnsManagerStub::HandleDelete(MessageParcel &data, MessageParcel &reply) +{ + std::string key; + if (!data.ReadString(key)) { + ANS_LOGE("[HandleDelete] fail: read key failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t removeReason = 0; + if (!data.ReadInt32(removeReason)) { + ANS_LOGE("[HandleDelete] fail: read removeReason failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = Delete(key, removeReason); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDelete] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDeleteByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleDeleteByBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = DeleteByBundle(bundleOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDeleteByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDeleteAll(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = DeleteAll(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDeleteAll] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotsByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotsByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector> slots; + ErrCode result = GetSlotsByBundle(bundleOption, slots); + if (!WriteParcelableVector(slots, reply, result)) { + ANS_LOGE("[HandleGetSlotsByBundle] fail: write slots failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + + sptr slot = nullptr; + ErrCode result = GetSlotByBundle(bundleOption, slotType, slot); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(slot)) { + ANS_LOGE("[HandleGetSlotByBundle] fail: write slot failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleUpdateSlots(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleUpdateSlots] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector> slots; + if (!ReadParcelableVector(slots, data)) { + ANS_LOGE("[HandleUpdateSlots] fail: read slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = UpdateSlots(bundleOption, slots); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleUpdateSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleRequestEnableNotification] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr callback = data.ReadRemoteObject(); + if (callback == nullptr) { + ANS_LOGE("[HandleRequestEnableNotification] fail: read callback failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool hasCallerToken = false; + if (!data.ReadBool(hasCallerToken)) { + ANS_LOGE("fail: read hasCallerToken failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr callerToken = nullptr; + if (hasCallerToken) { + callerToken = data.ReadRemoteObject(); + } + + ErrCode result = RequestEnableNotification(deviceId, iface_cast(callback), callerToken); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRequestEnableNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledForBundle(deviceId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledForAllBundles(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledForAllBundles(deviceId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledForSpecialBundle(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: write result failed, ErrCode=%{public}d", + result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetShowBadgeEnabledForBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = GetShowBadgeEnabledForBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetShowBadgeEnabled(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + ErrCode result = GetShowBadgeEnabled(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetShowBadgeEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetShowBadgeEnabled] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSubscribe(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribe] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleSubscribe] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleSubscribe] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + ErrCode result = Subscribe(iface_cast(subscriber), info); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribe] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSubscribeSelf(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribeSelf] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SubscribeSelf(iface_cast(subscriber)); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribeSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + bool isNative = false; + if (!data.ReadBool(isNative)) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read isNative failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = + SubscribeLocalLiveView(iface_cast(subscriber), info, isNative); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleUnsubscribe(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleUnsubscribe] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleUnsubscribe] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleUnsubscribe] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + ErrCode result = Unsubscribe(iface_cast(subscriber), info); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleUnsubscribe] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsAllowedNotify(MessageParcel &data, MessageParcel &reply) +{ + bool allowed = false; + ErrCode result = IsAllowedNotify(allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsAllowedNotify] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[HandleIsAllowedNotify] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsAllowedNotifySelf(MessageParcel &data, MessageParcel &reply) +{ + bool allowed = false; + ErrCode result = IsAllowedNotifySelf(allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsAllowedNotifySelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[HandleIsAllowedNotifySelf] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCanPopEnableNotificationDialog(MessageParcel &data, MessageParcel &reply) +{ + sptr callback = data.ReadRemoteObject(); + if (callback == nullptr) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: read callback failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + bool canPop = false; + std::string bundleName; + ErrCode result = CanPopEnableNotificationDialog(iface_cast(callback), canPop, bundleName); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(canPop)) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: write canPop failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!reply.WriteString(bundleName)) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: write bundleName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveEnableNotificationDialog(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = RemoveEnableNotificationDialog(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveEnableNotificationDialog] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool allowed = false; + ErrCode result = IsSpecialBundleAllowedNotify(bundleOption, allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelGroup(MessageParcel &data, MessageParcel &reply) +{ + std::string groupName; + if (!data.ReadString(groupName)) { + ANS_LOGE("[HandleCancelGroup] fail: read groupName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t instanceKey = 0; + if (!data.ReadInt32(instanceKey)) { + ANS_LOGE("[HandleCancelGroup] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelGroup(groupName, instanceKey); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelGroup] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveGroupByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleRemoveGroupByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string groupName; + if (!data.ReadString(groupName)) { + ANS_LOGE("[HandleRemoveGroupByBundle] fail: read groupName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveGroupByBundle(bundleOption, groupName); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveGroupByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsDistributedEnabled(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + ErrCode result = IsDistributedEnabled(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsDistributedEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsDistributedEnabled] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleEnableDistributed(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleEnableDistributed] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = EnableDistributed(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleEnableDistributed] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleEnableDistributedByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleEnableDistributedByBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleEnableDistributedByBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = EnableDistributedByBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleEnableDistributedByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleEnableDistributedSelf(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleEnableDistributedSelf] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = EnableDistributedSelf(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleEnableDistributedSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsDistributedEnableByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = IsDistributedEnableByBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply) +{ + auto rType{ NotificationConstant::RemindType::NONE }; + ErrCode result = GetDeviceRemindType(rType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetDeviceRemindType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(static_cast(rType))) { + ANS_LOGE("[HandleGetDeviceRemindType] fail: write remind type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &reply) +{ + std::string cmd; + if (!data.ReadString(cmd)) { + ANS_LOGE("[HandleShellDump] fail: read cmd failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + std::string bundle; + if (!data.ReadString(bundle)) { + ANS_LOGE("[HandleShellDump] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t userId; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleShellDump] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t recvUserId; + if (!data.ReadInt32(recvUserId)) { + ANS_LOGE("[HandleShellDump] fail: read recvUserId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + std::vector notificationsInfo; + ErrCode result = ShellDump(cmd, bundle, userId, recvUserId, notificationsInfo); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetRecentNotificationsInfo] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteStringVector(notificationsInfo)) { + ANS_LOGE("[HandleGetRecentNotificationsInfo] fail: write notificationsInfo failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishReminder(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandlePublishReminder"); + uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); + if (!data.ReadUint8(typeInfo)) { + ANSR_LOGE("Failed to read reminder type"); + return ERR_ANS_PARCELABLE_FAILED; + } + ReminderRequest::ReminderType reminderType = static_cast(typeInfo); + sptr reminder; + if (ReminderRequest::ReminderType::ALARM == reminderType) { + ANSR_LOGD("Publish alarm"); + reminder = data.ReadParcelable(); + } else if (ReminderRequest::ReminderType::TIMER == reminderType) { + ANSR_LOGD("Publish timer"); + reminder = data.ReadParcelable(); + } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { + ANSR_LOGD("Publish calendar"); + reminder = data.ReadParcelable(); + } else { + ANSR_LOGE("Reminder type invalid"); + return ERR_ANS_INVALID_PARAM; + } + if (!reminder) { + ANSR_LOGE("Reminder ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishReminder(reminder); + + if (!reply.WriteInt32(reminder->GetReminderId())) { + ANSR_LOGE("Write back reminderId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleCancelReminder(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleCancelReminder"); + int32_t reminderId = -1; + if (!data.ReadInt32(reminderId)) { + ANSR_LOGE("Read reminder id failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelReminder(reminderId); + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = CancelAllReminders(); + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleGetValidReminders"); + std::vector> validReminders; + ErrCode result = GetValidReminders(validReminders); + + ANSR_LOGD("Write back size=%{public}zu", validReminders.size()); + if (!reply.WriteUint8(static_cast(validReminders.size()))) { + ANSR_LOGE("Write back reminder count failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + for (auto it = validReminders.begin(); it != validReminders.end(); ++it) { + sptr reminder = (*it); + uint8_t reminderType = static_cast(reminder->GetReminderType()); + ANSR_LOGD("ReminderType=%{public}d", reminderType); + if (!reply.WriteUint8(reminderType)) { + ANSR_LOGW("Write reminder type failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!reply.WriteParcelable(reminder)) { + ANSR_LOGW("Write reminder parcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleAddExcludeDate"); + int32_t reminderId = -1; + if (!data.ReadInt32(reminderId)) { + ANSR_LOGE("Read reminder id failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + uint64_t date = 0; + if (!data.ReadUint64(date)) { + ANSR_LOGE("Read exclude date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = AddExcludeDate(reminderId, date); + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleDelExcludeDates"); + int32_t reminderId = -1; + if (!data.ReadInt32(reminderId)) { + ANSR_LOGE("Read reminder id failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = DelExcludeDates(reminderId); + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleGetExcludeDates"); + int32_t reminderId = -1; + if (!data.ReadInt32(reminderId)) { + ANSR_LOGE("Read reminder id failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector dates; + ErrCode result = GetExcludeDates(reminderId, dates); + ANSR_LOGD("Write back size=%{public}zu", dates.size()); + if (!reply.WriteUint8(static_cast(dates.size()))) { + ANSR_LOGE("Write back exclude date count failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + for (const auto date : dates) { + if (!reply.WriteUint64(date)) { + ANSR_LOGW("Write exclude date failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply) +{ + std::string templateName; + if (!data.ReadString(templateName)) { + ANS_LOGE("[HandleIsSupportTemplate] fail: read template name failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + bool support = false; + ErrCode result = IsSupportTemplate(templateName, support); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsSupportTemplate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!reply.WriteBool(support)) { + ANS_LOGE("[HandleIsSupportTemplate] fail: write support failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool allowed = false; + ErrCode result = IsSpecialUserAllowedNotify(userId, allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledByUser(userId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDeleteAllByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleDeleteAllByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = DeleteAllByUser(userId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDeleteAllByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr date = data.ReadParcelable(); + if (date == nullptr) { + ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDoNotDisturbDate(userId, date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr date = nullptr; + ErrCode result = GetDoNotDisturbDate(userId, date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(date)) { + ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool isForceControl = false; + if (!data.ReadBool(isForceControl)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read isForceControl failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + ErrCode result = GetEnabledForBundleSlot(bundleOption, slotType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply) +{ + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + ErrCode result = GetEnabledForBundleSlotSelf(slotType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSyncNotificationEnabledWithoutApp(userId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDistributedGetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = GetSyncNotificationEnabledWithoutApp(userId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleSetBadgeNumber"); + int32_t badgeNumber = -1; + if (!data.ReadInt32(badgeNumber)) { + ANSR_LOGE("Read badge number failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t instanceKey = -1; + if (!data.ReadInt32(instanceKey)) { + ANSR_LOGE("Read instance key failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetBadgeNumber(badgeNumber, instanceKey); + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write badge number failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleSetBadgeNumberByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("Called."); + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("Read bundle option failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t badgeNumber = 0; + if (!data.ReadInt32(badgeNumber)) { + ANS_LOGE("Read badge number failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetBadgeNumberByBundle(bundleOption, badgeNumber); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleGetAllNotificationEnableStatus(MessageParcel &data, MessageParcel &reply) +{ + std::vector bundleOption; + ErrCode result = GetAllNotificationEnabledBundles(bundleOption); + int32_t vectorSize = bundleOption.size(); + if (vectorSize > MAX_STATUS_VECTOR_NUM) { + ANS_LOGE("Bundle bundleOption vector is over size."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(vectorSize)) { + ANS_LOGE("Write bundleOption size failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + for (const auto &item : bundleOption) { + if (!reply.WriteParcelable(&item)) { + ANS_LOGE("Write bundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRegisterPushCallback(MessageParcel &data, MessageParcel &reply) +{ + sptr pushCallBack = data.ReadRemoteObject(); + if (pushCallBack == nullptr) { + ANS_LOGE("fail: read JSPushCallBack failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr notificationCheckRequest = data.ReadParcelable(); + if (notificationCheckRequest == nullptr) { + ANS_LOGE("fail: read notificationCheckRequest failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RegisterPushCallback(pushCallBack, notificationCheckRequest); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = UnregisterPushCallback(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleAddDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply) +{ + std::vector> profiles; + if (!ReadParcelableVector(profiles, data)) { + ANS_LOGE("Read profiles failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (profiles.size() > MAX_STATUS_VECTOR_NUM) { + ANS_LOGE("The profiles is exceeds limit."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = AddDoNotDisturbProfiles(profiles); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode is %{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetDistributedEnabledByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: write result failed, ErrCode=%{public}d", + result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply) +{ + std::vector> profiles; + if (!ReadParcelableVector(profiles, data)) { + ANS_LOGE("Read profiles failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (profiles.size() > MAX_STATUS_VECTOR_NUM) { + ANS_LOGE("The profiles is exceeds limit."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = RemoveDoNotDisturbProfiles(profiles); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode is %{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsDistributedEnabledByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetAdditionConfig(MessageParcel &data, MessageParcel &reply) +{ + std::string key; + if (!data.ReadString(key)) { + ANS_LOGE("Failed to read key."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string value; + if (!data.ReadString(value)) { + ANS_LOGE("Failed to read value."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetAdditionConfig(key, value); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Failed to write result, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleSetSmartReminderEnabled(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleSetSmartReminderEnabled] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetSmartReminderEnabled] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSmartReminderEnabled(deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetSmartReminderEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundleWithAgent(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("Read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t id = 0; + if (!data.ReadInt32(id)) { + ANS_LOGE("Read notification id failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelAsBundleWithAgent(bundleOption, id); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleIsSmartReminderEnabled(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleIsSmartReminderEnabled] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = IsSmartReminderEnabled(deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsSmartReminderEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsSmartReminderEnabled] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetTargetDeviceStatus(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleSetTargetDeviceStatus] fail: read deviceType failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t status = 0; + if (!data.ReadInt32(status)) { + ANS_LOGE("[HandleSetTargetDeviceStatus] fail: read status failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetTargetDeviceStatus(deviceType, status); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetTargetDeviceStatus] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply) +{ + int32_t profileId = data.ReadInt32(); + sptr profile = nullptr; + ErrCode result = GetDoNotDisturbProfile(profileId, profile); + if (!reply.WriteInt32(result)) { + ANS_LOGE("HandleGetDoNotDisturbProfile write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(profile)) { + ANS_LOGE("HandleGetDoNotDisturbProfile write slot failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + return ERR_OK; +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +ErrCode AnsManagerStub::HandleRegisterSwingCallback(MessageParcel &data, MessageParcel &reply) +{ + sptr swingCallBack = data.ReadRemoteObject(); + if (swingCallBack == nullptr) { + ANS_LOGE("fail: read SwingCallBack failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RegisterSwingCallback(swingCallBack); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} +#endif +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/reminder/src/ans_manager_stub_invalid.cpp b/frameworks/reminder/src/ans_manager_stub_invalid.cpp new file mode 100644 index 000000000..e447bad8a --- /dev/null +++ b/frameworks/reminder/src/ans_manager_stub_invalid.cpp @@ -0,0 +1,663 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_manager_stub.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "message_option.h" +#include "message_parcel.h" +#include "parcel.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" + +namespace OHOS { +namespace Notification { +ErrCode AnsManagerStub::Publish(const std::string &label, const sptr ¬ification) +{ + ANS_LOGE("AnsManagerStub::Publish called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishNotificationForIndirectProxy(const sptr ¬ification) +{ + ANS_LOGE("AnsManagerStub::PublishNotificationForIndirectProxy called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Cancel(int notificationId, const std::string &label, int32_t instanceKey) +{ + ANS_LOGE("AnsManagerStub::Cancel called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAll(int32_t instanceKey) +{ + ANS_LOGE("AnsManagerStub::CancelAll called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId) +{ + ANS_LOGE("AnsManagerStub::CancelAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundle(const sptr &bundleOption, int32_t notificationId) +{ + ANS_LOGE("AnsManagerStub::CancelAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundle( + const sptr &bundleOption, int32_t notificationId, int32_t userId) +{ + ANS_LOGE("AnsManagerStub::CancelAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddSlotByType(NotificationConstant::SlotType slotType) +{ + ANS_LOGE("AnsManagerStub::AddSlotByType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddSlots(const std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::AddSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveSlotByType(const NotificationConstant::SlotType &slotType) +{ + ANS_LOGE("AnsManagerStub::RemoveSlotByType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveAllSlots() +{ + ANS_LOGE("AnsManagerStub::RemoveAllSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) +{ + ANS_LOGE("AnsManagerStub::GetSlotByType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlots(std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::GetSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotNumAsBundle(const sptr &bundleOption, uint64_t &num) +{ + ANS_LOGE("AnsManagerStub::GetSlotNumAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetActiveNotifications( + std::vector> ¬ifications, int32_t instanceKey) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetActiveNotificationNums(uint64_t &num) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotificationNums called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetAllActiveNotifications(std::vector> ¬ifications) +{ + ANS_LOGE("AnsManagerStub::GetAllActiveNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSpecialActiveNotifications( + const std::vector &key, std::vector> ¬ifications) +{ + ANS_LOGE("AnsManagerStub::GetSpecialActiveNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotificationByFilter called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) +{ + ANS_LOGE("AnsManagerStub::CanPublishAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishAsBundle( + const sptr notification, const std::string &representativeBundle) +{ + ANS_LOGE("AnsManagerStub::PublishAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationBadgeNum(int num) +{ + ANS_LOGE("AnsManagerStub::SetNotificationBadgeNum called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetBundleImportance(int &importance) +{ + ANS_LOGE("AnsManagerStub::GetBundleImportance called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) +{ + ANS_LOGE("AnsManagerStub::GetSlotFlagsAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) +{ + ANS_LOGE("AnsManagerStub::SetSlotFlagsAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::HasNotificationPolicyAccessPermission(bool &granted) +{ + ANS_LOGE("AnsManagerStub::HasNotificationPolicyAccessPermission called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::TriggerLocalLiveView(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) +{ + ANS_LOGE("AnsManagerStub::TriggerLocalLiveView called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveNotification(const sptr &bundleOption, + int notificationId, const std::string &label, int32_t removeReason) +{ + ANS_LOGE("AnsManagerStub::RemoveNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveAllNotifications(const sptr &bundleOption) +{ + ANS_LOGE("AnsManagerStub::RemoveAllNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveNotifications(const std::vector &keys, int32_t removeReason) +{ + ANS_LOGD("called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Delete(const std::string &key, int32_t removeReason) +{ + ANS_LOGE("AnsManagerStub::Delete called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DeleteByBundle(const sptr &bundleOption) +{ + ANS_LOGE("AnsManagerStub::DeleteByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DeleteAll() +{ + ANS_LOGE("AnsManagerStub::DeleteAll called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotsByBundle( + const sptr &bundleOption, std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::GetSlotsByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotByBundle( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot) +{ + ANS_LOGE("AnsManagerStub::GetSlotByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::UpdateSlots( + const sptr &bundleOption, const std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::UpdateSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, + const sptr &callback, + const sptr &callerToken) +{ + ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledForBundle(const std::string &bundle, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForAllBundles called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledForSpecialBundle( + const std::string &deviceId, const sptr &bundleOption, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForSpecialBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetShowBadgeEnabledForBundle(const sptr &bundleOption, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetShowBadgeEnabledForBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetShowBadgeEnabledForBundle(const sptr &bundleOption, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetShowBadgeEnabledForBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetShowBadgeEnabled(bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetShowBadgeEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Subscribe(const sptr &subscriber, + const sptr &info) +{ + ANS_LOGE("AnsManagerStub::Subscribe called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscriber) +{ + ANS_LOGE("AnsManagerStub::SubscribeSelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, + const sptr &info, const bool isNative) +{ + ANS_LOGE("AnsManagerStub::SubscribeLocalLiveView called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, + const sptr &info) +{ + ANS_LOGE("AnsManagerStub::Unsubscribe called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsAllowedNotify(bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsAllowedNotify called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsAllowedNotifySelf(bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsAllowedNotifySelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CanPopEnableNotificationDialog(const sptr &callback, + bool &canPop, std::string &bundleName) +{ + ANS_LOGE("AnsManagerStub::CanPopEnableNotificationDialog called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveEnableNotificationDialog() +{ + ANS_LOGE("AnsManagerStub::RemoveEnableNotificationDialog called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsSpecialBundleAllowedNotify called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelGroup(const std::string &groupName, int32_t instanceKey) +{ + ANS_LOGE("AnsManagerStub::CancelGroup called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) +{ + ANS_LOGE("AnsManagerStub::RemoveGroupByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetDoNotDisturbDate(const sptr &date) +{ + ANS_LOGE("AnsManagerStub::SetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbDate(sptr &date) +{ + ANS_LOGE("AnsManagerStub::GetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddDoNotDisturbProfiles(const std::vector> &profiles) +{ + ANS_LOGD("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveDoNotDisturbProfiles(const std::vector> &profiles) +{ + ANS_LOGD("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + ANS_LOGE("AnsManagerStub::DoesSupportDoNotDisturbMode called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) +{ + ANS_LOGE("AnsManagerStub::IsNeedSilentInDoNotDisturbMode called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsDistributedEnabled(bool &enabled) +{ + ANS_LOGE("AnsManagerStub::IsDistributedEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::EnableDistributed(bool enabled) +{ + ANS_LOGE("AnsManagerStub::EnableDistributed called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::EnableDistributedByBundle(const sptr &bundleOption, bool enabled) +{ + ANS_LOGE("AnsManagerStub::EnableDistributedByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::EnableDistributedSelf(bool enabled) +{ + ANS_LOGE("AnsManagerStub::EnableDistributedSelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsDistributedEnableByBundle(const sptr &bundleOption, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::IsDistributedEnableByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDeviceRemindType(NotificationConstant::RemindType &remindType) +{ + ANS_LOGE("AnsManagerStub::GetDeviceRemindType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishContinuousTaskNotification(const sptr &request) +{ + ANS_LOGE("AnsManagerStub::PublishContinuousTaskNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGE("AnsManagerStub::CancelContinuousTaskNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishReminder(sptr &reminder) +{ + ANS_LOGE("AnsManagerStub::PublishReminder called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelReminder(const int32_t reminderId) +{ + ANS_LOGE("AnsManagerStub::CancelReminder called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetValidReminders(std::vector> &reminders) +{ + ANS_LOGE("AnsManagerStub::getValidReminders called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAllReminders() +{ + ANS_LOGE("AnsManagerStub::cancelAllReminders called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t date) +{ + ANS_LOGE("AnsManagerStub::AddExcludeDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DelExcludeDates(const int32_t reminderId) +{ + ANS_LOGE("AnsManagerStub::DelExcludeDates called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetExcludeDates(const int32_t reminderId, std::vector& dates) +{ + ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSupportTemplate(const std::string &templateName, bool &support) +{ + ANS_LOGE("AnsManagerStub::IsSupportTemplate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsSpecialUserAllowedNotify called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledByUser called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DeleteAllByUser(const int32_t &userId) +{ + ANS_LOGE("AnsManagerStub::DeleteAllByUser called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetDoNotDisturbDate(const int32_t &userId, const sptr &date) +{ + ANS_LOGE("AnsManagerStub::SetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbDate(const int32_t &userId, sptr &date) +{ + ANS_LOGE("AnsManagerStub::GetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) +{ + ANS_LOGE("AnsManagerStub::SetEnabledForBundleSlot called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetEnabledForBundleSlot( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetEnabledForBundleSlot called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetEnabledForBundleSlotSelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, + int32_t recvUserId, std::vector &dumpInfo) +{ + ANS_LOGE("AnsManagerStub::ShellDump called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetSyncNotificationEnabledWithoutApp called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetSyncNotificationEnabledWithoutApp called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) +{ + ANS_LOGE("AnsManagerStub::SetBadgeNumber called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetBadgeNumberByBundle(const sptr &bundleOption, int32_t badgeNumber) +{ + ANS_LOGD("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetAllNotificationEnabledBundles(std::vector &bundleOption) +{ + ANS_LOGE("AnsManagerStub::GetAllNotificationEnabledBundles called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) +{ + ANS_LOGE("RegisterPushCallback called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::UnregisterPushCallback() +{ + ANS_LOGE("UnregisterPushCallback called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, const bool enabled) +{ + ANS_LOGE("SetDistributedEnabledByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, bool &enabled) +{ + ANS_LOGE("IsDistributedEnabledByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) +{ + ANS_LOGE("SetSmartReminderEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) +{ + ANS_LOGE("IsSmartReminderEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetAdditionConfig(const std::string &key, const std::string &value) +{ + ANS_LOGE("Called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundleWithAgent(const sptr &bundleOption, const int32_t id) +{ + ANS_LOGE("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) +{ + ANS_LOGE("SetTargetDeviceStatus called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbProfile(int32_t id, sptr &profile) +{ + ANS_LOGE("GetDoNotDisturbProfile called!"); + return ERR_INVALID_OPERATION; +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +ErrCode AnsManagerStub::RegisterSwingCallback(const sptr& swingCallback) +{ + ANS_LOGE("RegisterSwingCallback called!"); + return ERR_INVALID_OPERATION; +} +#endif +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/reminder/src/ans_notification.cpp b/frameworks/reminder/src/ans_notification.cpp new file mode 100644 index 000000000..00fb37e7e --- /dev/null +++ b/frameworks/reminder/src/ans_notification.cpp @@ -0,0 +1,2028 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_notification.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_manager_death_recipient.h" +#include "ans_manager_proxy.h" +#include "hitrace_meter_adapter.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "notification_button_option.h" +#include "notification_local_live_view_subscriber.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" +#include "system_ability_definition.h" +#include "unique_fd.h" + +#include +#include + +namespace OHOS { +namespace Notification { +namespace { +const int32_t MAX_RETRY_TIME = 30; +const int32_t SLEEP_TIME = 1000; +const uint32_t MAX_PUBLISH_DELAY_TIME = 5; +const int32_t DEFAULT_INSTANCE_KEY = -1; +const std::string DOWNLOAD_TITLE = "title"; +const std::string DOWNLOAD_FILENAME = "fileName"; +} +ErrCode AnsNotification::AddNotificationSlot(const NotificationSlot &slot) +{ + std::vector slots; + slots.push_back(slot); + return AddNotificationSlots(slots); +} + +ErrCode AnsNotification::AddSlotByType(const NotificationConstant::SlotType &slotType) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->AddSlotByType(slotType); +} + +ErrCode AnsNotification::AddNotificationSlots(const std::vector &slots) +{ + if (slots.size() == 0) { + ANS_LOGE("Failed to add notification slots because input slots size is 0."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + std::vector> slotsSptr; + for (auto it = slots.begin(); it != slots.end(); ++it) { + sptr slot = new (std::nothrow) NotificationSlot(*it); + if (slot == nullptr) { + ANS_LOGE("Failed to create NotificationSlot ptr."); + return ERR_ANS_NO_MEMORY; + } + slotsSptr.emplace_back(slot); + } + + return proxy->AddSlots(slotsSptr); +} + +ErrCode AnsNotification::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) +{ + ANS_LOGI("enter RemoveNotificationSlot,slotType:%{public}d", slotType); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RemoveSlotByType(slotType); +} + +ErrCode AnsNotification::RemoveAllSlots() +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RemoveAllSlots(); +} + +ErrCode AnsNotification::GetNotificationSlot( + const NotificationConstant::SlotType &slotType, sptr &slot) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetSlotByType(slotType, slot); +} + +ErrCode AnsNotification::GetNotificationSlots(std::vector> &slots) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetSlots(slots); +} + +ErrCode AnsNotification::GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->GetSlotNumAsBundle(bo, num); +} + +ErrCode AnsNotification::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, + uint32_t &slotFlags) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->GetSlotFlagsAsBundle(bo, slotFlags); +} + +ErrCode AnsNotification::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, + uint32_t slotFlags) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->SetSlotFlagsAsBundle(bo, slotFlags); +} + +ErrCode AnsNotification::PublishNotification(const NotificationRequest &request) +{ + ANS_LOGD("enter"); + return PublishNotification(std::string(), request); +} + +ErrCode AnsNotification::PublishNotification(const std::string &label, const NotificationRequest &request) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + ANS_LOGD("enter"); + + if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) { + ANS_LOGE("Refuse to publish the notification without valid content"); + return ERR_ANS_INVALID_PARAM; + } + + if (!IsValidTemplate(request) || !IsValidDelayTime(request)) { + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishMediaContent(request)) { + ANS_LOGE("Refuse to publish the notification because the series numbers actions not match those assigned to " + "added action buttons."); + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishLiveViewContent(request)) { + ANS_LOGE("Refuse to publish the notification without valid live view content."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Failed to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr reqPtr = new (std::nothrow) NotificationRequest(request); + if (reqPtr == nullptr) { + ANS_LOGE("Create notificationRequest ptr fail."); + return ERR_ANS_NO_MEMORY; + } + + if (IsNonDistributedNotificationType(reqPtr->GetNotificationType())) { + reqPtr->SetDistributed(false); + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + reqPtr->SetCreatorInstanceKey(instanceKey); + + return proxy->Publish(label, reqPtr); +} + +ErrCode AnsNotification::PublishNotificationForIndirectProxy(const NotificationRequest &request) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + ANS_LOGD("enter"); + + if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) { + ANS_LOGE("Refuse to publish the notification without valid content"); + return ERR_ANS_INVALID_PARAM; + } + + if (!IsValidTemplate(request) || !IsValidDelayTime(request)) { + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishMediaContent(request)) { + ANS_LOGE("Refuse to publish the notification because the series numbers actions not match those assigned to " + "added action buttons."); + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishLiveViewContent(request)) { + ANS_LOGE("Refuse to publish the notification without valid live view content."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Failed to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr reqPtr = new (std::nothrow) NotificationRequest(request); + if (reqPtr == nullptr) { + ANS_LOGE("Create notificationRequest ptr fail."); + return ERR_ANS_NO_MEMORY; + } + + if (IsNonDistributedNotificationType(reqPtr->GetNotificationType())) { + reqPtr->SetDistributed(false); + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + reqPtr->SetCreatorInstanceKey(instanceKey); + + return proxy->PublishNotificationForIndirectProxy(reqPtr); +} + +ErrCode AnsNotification::CancelNotification(int32_t notificationId) +{ + return CancelNotification("", notificationId); +} + +ErrCode AnsNotification::CancelNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGI("enter CancelNotification,notificationId:%{public}d", notificationId); + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return proxy->Cancel(notificationId, label, instanceKey); +} + +ErrCode AnsNotification::CancelAllNotifications() +{ + ANS_LOGI("CancelAllNotifications called."); + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return proxy->CancelAll(instanceKey); +} + +ErrCode AnsNotification::CancelAsBundle( + int32_t notificationId, const std::string &representativeBundle, int32_t userId) +{ + ANS_LOGI("enter CancelAsBundle,notificationId:%{public}d", notificationId); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CancelAsBundle(notificationId, representativeBundle, userId); +} + +ErrCode AnsNotification::CancelAsBundle( + const NotificationBundleOption &bundleOption, int32_t notificationId) +{ + ANS_LOGI("enter CancelAsBundle,notificationId:%{public}d", notificationId); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->CancelAsBundle(bo, notificationId); +} + +ErrCode AnsNotification::GetActiveNotificationNums(uint64_t &num) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetActiveNotificationNums(num); +} + +ErrCode AnsNotification::GetActiveNotifications(std::vector> &request) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return proxy->GetActiveNotifications(request, instanceKey); +} + +ErrCode AnsNotification::CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish) +{ + if (representativeBundle.empty()) { + ANS_LOGW("Input representativeBundle is empty"); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CanPublishAsBundle(representativeBundle, canPublish); +} + +ErrCode AnsNotification::PublishNotificationAsBundle( + const std::string &representativeBundle, const NotificationRequest &request) +{ + if (representativeBundle.empty()) { + ANS_LOGE("Refuse to publish the notification whit invalid representativeBundle"); + return ERR_ANS_INVALID_PARAM; + } + + if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) { + ANS_LOGE("Refuse to publish the notification without effective content"); + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishMediaContent(request)) { + ANS_LOGE("Refuse to publish the notification because the sequence numbers actions not match those assigned to " + "added action buttons."); + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishLiveViewContent(request)) { + ANS_LOGE("Refuse to publish the notification without valid live view content."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture overtake the limit"); + return checkErr; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr reqPtr = new (std::nothrow) NotificationRequest(request); + if (reqPtr == nullptr) { + ANS_LOGE("Failed to create NotificationRequest ptr"); + return ERR_ANS_NO_MEMORY; + } + if (IsNonDistributedNotificationType(reqPtr->GetNotificationType())) { + reqPtr->SetDistributed(false); + } + return proxy->PublishAsBundle(reqPtr, representativeBundle); +} + +ErrCode AnsNotification::SetNotificationBadgeNum() +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t num = -1; + return proxy->SetNotificationBadgeNum(num); +} + +ErrCode AnsNotification::SetNotificationBadgeNum(int32_t num) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->SetNotificationBadgeNum(num); +} + +ErrCode AnsNotification::IsAllowedNotify(bool &allowed) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->IsAllowedNotify(allowed); +} + +ErrCode AnsNotification::IsAllowedNotifySelf(bool &allowed) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->IsAllowedNotifySelf(allowed); +} + +ErrCode AnsNotification::CanPopEnableNotificationDialog(sptr &hostClient, + bool &canPop, std::string &bundleName) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CanPopEnableNotificationDialog(hostClient, canPop, bundleName); +} + +ErrCode AnsNotification::RemoveEnableNotificationDialog() +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RemoveEnableNotificationDialog(); +} + +ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId, + sptr &hostClient, + sptr &callerToken) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RequestEnableNotification(deviceId, hostClient, callerToken); +} + +ErrCode AnsNotification::HasNotificationPolicyAccessPermission(bool &hasPermission) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->HasNotificationPolicyAccessPermission(hasPermission); +} + +ErrCode AnsNotification::GetBundleImportance(NotificationSlot::NotificationLevel &importance) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t importanceTemp; + ErrCode ret = proxy->GetBundleImportance(importanceTemp); + if ((NotificationSlot::LEVEL_NONE <= importanceTemp) && (importanceTemp <= NotificationSlot::LEVEL_HIGH)) { + importance = static_cast(importanceTemp); + } else { + importance = NotificationSlot::LEVEL_UNDEFINED; + } + return ret; +} + +ErrCode AnsNotification::SubscribeNotification(const NotificationSubscriber &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + return proxy->Subscribe(subscriberSptr, nullptr); +} + +ErrCode AnsNotification::SubscribeNotificationSelf(const NotificationSubscriber &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to subscribeSelf with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + return proxy->SubscribeSelf(subscriberSptr); +} + +ErrCode AnsNotification::SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber, + const bool isNative) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + return proxy->SubscribeLocalLiveView(subscriberSptr, nullptr, isNative); +} + +ErrCode AnsNotification::SubscribeNotification( + const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Failed to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr sptrInfo = new (std::nothrow) NotificationSubscribeInfo(subscribeInfo); + if (sptrInfo == nullptr) { + ANS_LOGE("Failed to create NotificationSubscribeInfo ptr."); + return ERR_ANS_NO_MEMORY; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + subscriberSptr->subscriber_.SetDeviceType(subscribeInfo.GetDeviceType()); + return proxy->Subscribe(subscriberSptr, sptrInfo); +} + +ErrCode AnsNotification::UnSubscribeNotification(NotificationSubscriber &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to unsubscribe with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + return proxy->Unsubscribe(subscriberSptr, nullptr); +} + +ErrCode AnsNotification::UnSubscribeNotification( + NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr sptrInfo = new (std::nothrow) NotificationSubscribeInfo(subscribeInfo); + if (sptrInfo == nullptr) { + ANS_LOGE("Failed to create NotificationSubscribeInfo ptr."); + return ERR_ANS_NO_MEMORY; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to unsubscribe with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + return proxy->Unsubscribe(subscriberSptr, sptrInfo); +} + +ErrCode AnsNotification::SubscribeNotification(const std::shared_ptr &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + return SubscribeNotification(subscriber, nullptr); +} + +ErrCode AnsNotification::SubscribeNotificationSelf(const std::shared_ptr &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (subscriber == nullptr) { + ANS_LOGE("Subscriber is nullptr."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr listener = nullptr; + CreateSubscribeListener(subscriber, listener); + if (listener == nullptr) { + ANS_LOGE("Failed to subscribe due to create subscriber listener failed."); + return ERR_ANS_NO_MEMORY; + } + DelayedSingleton::GetInstance()->SubscribeSAManager(); + return proxy->SubscribeSelf(listener); +} + +ErrCode AnsNotification::SubscribeNotification(const std::shared_ptr &subscriber, + const sptr &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (subscriber == nullptr) { + ANS_LOGE("Subscriber is nullptr."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Failed to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr listener = nullptr; + CreateSubscribeListener(subscriber, listener); + if (listener == nullptr) { + ANS_LOGE("Failed to subscribe due to create subscriber listener failed."); + return ERR_ANS_NO_MEMORY; + } + if (subscribeInfo != nullptr) { + subscriber->SetDeviceType(subscribeInfo->GetDeviceType()); + } + DelayedSingleton::GetInstance()->SubscribeSAManager(); + return proxy->Subscribe(listener, subscribeInfo); +} + +ErrCode AnsNotification::UnSubscribeNotification(const std::shared_ptr &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + return UnSubscribeNotification(subscriber, nullptr); +} + +ErrCode AnsNotification::UnSubscribeNotification(const std::shared_ptr &subscriber, + const sptr &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (subscriber == nullptr) { + ANS_LOGE("Subscriber is nullptr."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + std::lock_guard lock(subscriberMutex_); + auto item = subscribers_.find(subscriber); + if (item != subscribers_.end()) { + sptr listener = item->second; + int32_t ret = proxy->Unsubscribe(listener, subscribeInfo); + if (ret == ERR_OK) { + subscribers_.erase(item); + } + return ret; + } + ANS_LOGE("Failed to unsubscribe due to subscriber not found."); + return ERR_ANS_INVALID_PARAM; +} + +ErrCode AnsNotification::TriggerLocalLiveView(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const NotificationButtonOption &buttonOption) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + + if (buttonOption.GetButtonName().empty()) { + ANS_LOGE("Invalid button name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + sptr button(new (std::nothrow) NotificationButtonOption(buttonOption)); + return proxy->TriggerLocalLiveView(bo, notificationId, button); +} + +ErrCode AnsNotification::RemoveNotification(const std::string &key, int32_t removeReason) +{ + ANS_LOGI("enter RemoveNotification,key:%{public}s,removeReason:%{public}d", + key.c_str(), removeReason); + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (key.empty()) { + ANS_LOGW("Input key is empty."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->Delete(key, removeReason); +} + +ErrCode AnsNotification::RemoveNotification(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const std::string &label, int32_t removeReason) +{ + ANS_LOGI("enter RemoveNotification,bundle:%{public}s,Id:%{public}d,reason:%{public}d", + bundleOption.GetBundleName().c_str(), notificationId, removeReason); + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->RemoveNotification(bo, notificationId, label, removeReason); +} + +ErrCode AnsNotification::RemoveAllNotifications(const NotificationBundleOption &bundleOption) +{ + ANS_LOGI("enter RemoveAllNotifications,bundleName:%{public}s", bundleOption.GetBundleName().c_str()); + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy defeat."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->RemoveAllNotifications(bo); +} + +ErrCode AnsNotification::RemoveNotifications(const std::vector hashcodes, int32_t removeReason) +{ + ANS_LOGI("enter RemoveNotifications,removeReason:%{public}d", removeReason); + if (hashcodes.empty()) { + ANS_LOGE("Hashcodes is empty"); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->RemoveNotifications(hashcodes, removeReason); +} + +ErrCode AnsNotification::RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption) +{ + ANS_LOGI("enter RemoveNotificationsByBundle,bundleName:%{public}s", bundleOption.GetBundleName().c_str()); + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Defeated to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->DeleteByBundle(bo); +} + +ErrCode AnsNotification::RemoveNotifications() +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->DeleteAll(); +} + +ErrCode AnsNotification::GetNotificationSlotsForBundle( + const NotificationBundleOption &bundleOption, std::vector> &slots) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Input bundleName is empty."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->GetSlotsByBundle(bo, slots); +} + +ErrCode AnsNotification::GetNotificationSlotForBundle( + const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Input bundleName is empty."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->GetSlotByBundle(bo, slotType, slot); +} + +ErrCode AnsNotification::UpdateNotificationSlots( + const NotificationBundleOption &bundleOption, const std::vector> &slots) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy flop."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->UpdateSlots(bo, slots); +} + +ErrCode AnsNotification::GetAllActiveNotifications(std::vector> ¬ification) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetAllActiveNotifications(notification); +} + +ErrCode AnsNotification::GetAllActiveNotifications( + const std::vector key, std::vector> ¬ification) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetSpecialActiveNotifications(key, notification); +} + +ErrCode AnsNotification::GetActiveNotificationByFilter(const LiveViewFilter &filter, + sptr &request) +{ + if (filter.bundle.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + ANS_LOGD("Bundle name %{public}s, uid %{public}d, notification id %{public}d, label %{public}s.", + filter.bundle.GetBundleName().c_str(), filter.bundle.GetUid(), filter.notificationKey.id, + filter.notificationKey.label.c_str()); + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(filter.bundle)); + return proxy->GetActiveNotificationByFilter(bo, filter.notificationKey.id, filter.notificationKey.label, + filter.extraInfoKeys, request); +} + +ErrCode AnsNotification::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Input bundle is empty."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->IsSpecialBundleAllowedNotify(bo, allowed); +} + +ErrCode AnsNotification::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->SetNotificationsEnabledForAllBundles(deviceId, enabled); +} + +ErrCode AnsNotification::SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->SetNotificationsEnabledForBundle(deviceId, enabled); +} + +ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( + const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->SetNotificationsEnabledForSpecialBundle(deviceId, bo, enabled); +} + +ErrCode AnsNotification::SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalidated bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->SetShowBadgeEnabledForBundle(bo, enabled); +} + +ErrCode AnsNotification::GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->GetShowBadgeEnabledForBundle(bo, enabled); +} + +ErrCode AnsNotification::GetShowBadgeEnabled(bool &enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->GetShowBadgeEnabled(enabled); +} + +ErrCode AnsNotification::CancelGroup(const std::string &groupName) +{ + ANS_LOGI("enter CancelGroup,groupName:%{public}s", groupName.c_str()); + if (groupName.empty()) { + ANS_LOGE("Invalid group name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return proxy->CancelGroup(groupName, instanceKey); +} + +ErrCode AnsNotification::RemoveGroupByBundle( + const NotificationBundleOption &bundleOption, const std::string &groupName) +{ + ANS_LOGI("enter RemoveGroupByBundle,bundleName:%{public}s", bundleOption.GetBundleName().c_str()); + if (bundleOption.GetBundleName().empty() || groupName.empty()) { + ANS_LOGE("Invalid parameter."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->RemoveGroupByBundle(bo, groupName); +} + +ErrCode AnsNotification::SetDoNotDisturbDate(const NotificationDoNotDisturbDate &doNotDisturbDate) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + auto dndDatePtr = new (std::nothrow) NotificationDoNotDisturbDate(doNotDisturbDate); + if (dndDatePtr == nullptr) { + ANS_LOGE("Create notificationDoNotDisturbDate failed."); + return ERR_ANS_NO_MEMORY; + } + + sptr dndDate(dndDatePtr); + return proxy->SetDoNotDisturbDate(dndDate); +} + +ErrCode AnsNotification::GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr dndDate = nullptr; + auto ret = proxy->GetDoNotDisturbDate(dndDate); + if (ret != ERR_OK) { + ANS_LOGE("GetDoNotDisturbDate failed."); + return ret; + } + + if (!dndDate) { + ANS_LOGE("Invalid DoNotDisturbDate."); + return ERR_ANS_NO_MEMORY; + } + + doNotDisturbDate = *dndDate; + return ret; +} + +ErrCode AnsNotification::AddDoNotDisturbProfiles(const std::vector> &profiles) +{ + if (profiles.empty()) { + ANS_LOGW("The profiles is empty."); + return ERR_ANS_INVALID_PARAM; + } + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGW("Get ans manager proxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->AddDoNotDisturbProfiles(profiles); +} + +ErrCode AnsNotification::RemoveDoNotDisturbProfiles(const std::vector> &profiles) +{ + if (profiles.empty()) { + ANS_LOGW("The profiles is empty."); + return ERR_ANS_INVALID_PARAM; + } + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGW("Get ans manager proxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RemoveDoNotDisturbProfiles(profiles); +} + +ErrCode AnsNotification::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->DoesSupportDoNotDisturbMode(doesSupport); +} + +ErrCode AnsNotification::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); +} + +ErrCode AnsNotification::PublishContinuousTaskNotification(const NotificationRequest &request) +{ + if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) { + ANS_LOGE("Refuse to publish the notification without valid content"); + return ERR_ANS_INVALID_PARAM; + } + + if (!CanPublishMediaContent(request)) { + ANS_LOGE("Refuse to publish the notification because the sequence numbers actions not match those assigned to " + "added action buttons."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + + if (!CanPublishLiveViewContent(request)) { + ANS_LOGE("Refuse to publish the notification without valid live view content."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + auto pReq = new (std::nothrow) NotificationRequest(request); + if (pReq == nullptr) { + ANS_LOGE("Failed to create NotificationRequest ptr."); + return ERR_ANS_NO_MEMORY; + } + + sptr sptrReq(pReq); + if (IsNonDistributedNotificationType(sptrReq->GetNotificationType())) { + sptrReq->SetDistributed(false); + } + return proxy->PublishContinuousTaskNotification(sptrReq); +} + +ErrCode AnsNotification::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGI("enter CancelContinuousTaskNotification,notificationId:%{public}d", notificationId); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->CancelContinuousTaskNotification(label, notificationId); +} + +ErrCode AnsNotification::IsDistributedEnabled(bool &enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->IsDistributedEnabled(enabled); +} + +ErrCode AnsNotification::EnableDistributed(const bool enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->EnableDistributed(enabled); +} + +ErrCode AnsNotification::EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->EnableDistributedByBundle(bo, enabled); +} + +ErrCode AnsNotification::EnableDistributedSelf(const bool enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->EnableDistributedSelf(enabled); +} + +ErrCode AnsNotification::IsDistributedEnableByBundle(const NotificationBundleOption &bundleOption, bool &enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->IsDistributedEnableByBundle(bo, enabled); +} + +ErrCode AnsNotification::GetDeviceRemindType(NotificationConstant::RemindType &remindType) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->GetDeviceRemindType(remindType); +} + +void AnsNotification::ResetAnsManagerProxy() +{} + +void AnsNotification::Reconnect() +{ + ANS_LOGD("enter"); + for (int32_t i = 0; i < MAX_RETRY_TIME; i++) { + // try to connect ans + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + // Sleep 1000 milliseconds before reconnect. + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); + ANS_LOGE("get ans proxy fail, try again."); + continue; + } + + ANS_LOGD("get ans proxy success."); + return; + } +} + +ErrCode AnsNotification::PublishReminder(ReminderRequest &reminder) +{ + sptr tarReminder = nullptr; + switch (reminder.GetReminderType()) { + case (ReminderRequest::ReminderType::TIMER): { + ANSR_LOGI("Publish timer"); + ReminderRequestTimer &timer = (ReminderRequestTimer &)reminder; + tarReminder = new (std::nothrow) ReminderRequestTimer(timer); + break; + } + case (ReminderRequest::ReminderType::ALARM): { + ANSR_LOGI("Publish alarm"); + ReminderRequestAlarm &alarm = (ReminderRequestAlarm &)reminder; + tarReminder = new (std::nothrow) ReminderRequestAlarm(alarm); + break; + } + case (ReminderRequest::ReminderType::CALENDAR): { + ANSR_LOGI("Publish calendar"); + ReminderRequestCalendar &calendar = (ReminderRequestCalendar &)reminder; + tarReminder = new (std::nothrow) ReminderRequestCalendar(calendar); + break; + } + default: { + ANSR_LOGW("PublishReminder fail."); + return ERR_ANS_INVALID_PARAM; + } + } + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + ErrCode code = proxy->PublishReminder(tarReminder); + reminder.SetReminderId(tarReminder->GetReminderId()); + return code; +} + +ErrCode AnsNotification::CancelReminder(const int32_t reminderId) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CancelReminder(reminderId); +} + +ErrCode AnsNotification::CancelAllReminders() +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CancelAllReminders(); +} + +ErrCode AnsNotification::GetValidReminders(std::vector> &validReminders) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetValidReminders(validReminders); +} + +ErrCode AnsNotification::AddExcludeDate(const int32_t reminderId, const uint64_t date) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->AddExcludeDate(reminderId, date); +} + +ErrCode AnsNotification::DelExcludeDates(const int32_t reminderId) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->DelExcludeDates(reminderId); +} + +ErrCode AnsNotification::GetExcludeDates(const int32_t reminderId, std::vector& dates) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetExcludeDates(reminderId, dates); +} + +sptr AnsNotification::GetAnsManagerProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + ANS_LOGE("Failed to get system ability mgr."); + return nullptr; + } + + sptr remoteObject = + systemAbilityManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID); + if (!remoteObject) { + ANS_LOGE("Failed to get notification Manager."); + return nullptr; + } + + sptr proxy = iface_cast(remoteObject); + if ((!proxy) || (!proxy->AsObject())) { + ANS_LOGE("Failed to get notification Manager's proxy"); + return nullptr; + } + return proxy; +} + +bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) const +{ + if (NotificationContent::Type::MEDIA != request.GetNotificationType()) { + return true; + } + + if (request.GetContent() == nullptr) { + ANS_LOGE("Failed to publish notification with null content."); + return false; + } + + auto media = std::static_pointer_cast(request.GetContent()->GetNotificationContent()); + if (media == nullptr) { + ANS_LOGE("Failed to get media content."); + return false; + } + + auto showActions = media->GetShownActions(); + size_t size = request.GetActionButtons().size(); + for (auto it = showActions.begin(); it != showActions.end(); ++it) { + if (*it > size) { + ANS_LOGE("The sequence numbers actions is: %{public}d, the assigned to added action buttons size is: " + "%{public}zu.", *it, size); + return false; + } + } + + return true; +} + +bool AnsNotification::CanPublishLiveViewContent(const NotificationRequest &request) const +{ + if (!request.IsCommonLiveView()) { + return true; + } + + if (request.GetContent() == nullptr) { + ANS_LOGE("Failed to publish notification with null content."); + return false; + } + + auto content = request.GetContent()->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + if (liveView == nullptr) { + ANS_LOGE("Failed to get live view content."); + return false; + } + + auto status = liveView->GetLiveViewStatus(); + if (status >= NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_BUTT) { + ANS_LOGE("Invalid status %{public}u.", status); + return false; + } + + return true; +} + +ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) +{ + auto littleIcon = request.GetLittleIcon(); + if (NotificationRequest::CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of little icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto overlayIcon = request.GetOverlayIcon(); + if (overlayIcon && NotificationRequest::CheckImageOverSizeForPixelMap(overlayIcon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of overlay icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + ErrCode err = request.CheckImageSizeForContent(); + if (err != ERR_OK) { + return err; + } + + auto buttons = request.GetActionButtons(); + for (auto &btn : buttons) { + if (!btn) { + continue; + } + auto icon = btn->GetIcon(); + if (NotificationRequest::CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of icon in ActionButton exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + + auto users = request.GetMessageUsers(); + for (auto &user : users) { + if (!user) { + continue; + } + auto icon = user->GetPixelMap(); + if (NotificationRequest::CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in MessageUser exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + + auto bigIcon = request.GetBigIcon(); + if (NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { + request.ResetBigIcon(); + ANS_LOGI("The size of big icon exceeds limit"); + } + + return ERR_OK; +} + +ErrCode AnsNotification::IsSupportTemplate(const std::string &templateName, bool &support) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->IsSupportTemplate(templateName, support); +} + +bool AnsNotification::IsNonDistributedNotificationType(const NotificationContent::Type &type) +{ + return ((type == NotificationContent::Type::CONVERSATION) || + (type == NotificationContent::Type::PICTURE) || + (type == NotificationContent::Type::LIVE_VIEW)); +} + +ErrCode AnsNotification::IsAllowedNotify(const int32_t &userId, bool &allowed) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->IsSpecialUserAllowedNotify(userId, allowed); +} + +ErrCode AnsNotification::SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->SetNotificationsEnabledByUser(userId, enabled); +} + +ErrCode AnsNotification::RemoveNotifications(const int32_t &userId) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->DeleteAllByUser(userId); +} + +ErrCode AnsNotification::SetDoNotDisturbDate(const int32_t &userId, + const NotificationDoNotDisturbDate &doNotDisturbDate) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + auto dndDatePtr = new (std::nothrow) NotificationDoNotDisturbDate(doNotDisturbDate); + if (dndDatePtr == nullptr) { + ANS_LOGE("create DoNotDisturbDate failed."); + return ERR_ANS_NO_MEMORY; + } + + sptr dndDate(dndDatePtr); + return proxy->SetDoNotDisturbDate(dndDate); +} + +ErrCode AnsNotification::GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr dndDate = nullptr; + auto ret = proxy->GetDoNotDisturbDate(dndDate); + if (ret != ERR_OK) { + ANS_LOGE("Get DoNotDisturbDate failed."); + return ret; + } + + if (!dndDate) { + ANS_LOGE("Invalid DoNotDisturbDate."); + return ERR_ANS_NO_MEMORY; + } + + doNotDisturbDate = *dndDate; + return ret; +} + +ErrCode AnsNotification::SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("SetEnabledForBundleSlot fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->SetEnabledForBundleSlot(bo, slotType, enabled, isForceControl); +} + +ErrCode AnsNotification::GetEnabledForBundleSlot( + const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetEnabledForBundleSlot fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->GetEnabledForBundleSlot(bo, slotType, enabled); +} + +ErrCode AnsNotification::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetEnabledForBundleSlotSelf fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->GetEnabledForBundleSlotSelf(slotType, enabled); +} + +ErrCode AnsNotification::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, + int32_t recvUserId, std::vector &dumpInfo) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->ShellDump(cmd, bundle, userId, recvUserId, dumpInfo); +} + +ErrCode AnsNotification::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->SetSyncNotificationEnabledWithoutApp(userId, enabled); +} + +ErrCode AnsNotification::GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) +{ + if (userId <= SUBSCRIBE_USER_INIT) { + ANS_LOGE("Input userId is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->GetSyncNotificationEnabledWithoutApp(userId, enabled); +} + +ErrCode AnsNotification::SetBadgeNumber(int32_t badgeNumber) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("SetBadgeNumber fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return proxy->SetBadgeNumber(badgeNumber, instanceKey); +} + +ErrCode AnsNotification::SetBadgeNumberByBundle(const NotificationBundleOption &bundleOption, int32_t badgeNumber) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Unable to connect to ANS service."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bundleInfo(new (std::nothrow) NotificationBundleOption(bundleOption)); + if (bundleInfo == nullptr) { + ANS_LOGE("Unable to create new bundle info."); + return ERR_ANS_NO_MEMORY; + } + return proxy->SetBadgeNumberByBundle(bundleInfo, badgeNumber); +} + +ErrCode AnsNotification::GetAllNotificationEnabledBundles(std::vector &bundleOption) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetAllNotificationEnabledBundles(bundleOption); +} + +ErrCode AnsNotification::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("RegisterPushCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->RegisterPushCallback(pushCallback, notificationCheckRequest); +} + +ErrCode AnsNotification::UnregisterPushCallback() +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("UnregisterPushCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->UnregisterPushCallback(); +} + +ErrCode AnsNotification::SetAdditionConfig(const std::string &key, const std::string &value) +{ + if (key.empty()) { + ANS_LOGE("Set package config fail: key is empty."); + return ERR_ANS_INVALID_PARAM; + } + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Get ans manager proxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->SetAdditionConfig(key, value); +} + +ErrCode AnsNotification::SetDistributedEnabledByBundle(const NotificationBundleOption &bundleOption, + const std::string &deviceType, const bool enabled) +{ + ANS_LOGD("enter"); + if (bundleOption.GetBundleName().empty() || deviceType.empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("SetDistributedEnabledByBundleCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->SetDistributedEnabledByBundle(bo, deviceType, enabled); +} + +ErrCode AnsNotification::IsDistributedEnabledByBundle(const NotificationBundleOption &bundleOption, + const std::string &deviceType, bool &enabled) +{ + ANS_LOGD("enter"); + if (bundleOption.GetBundleName().empty() || deviceType.empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("IsDistributedEnabledByBundleCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->IsDistributedEnabledByBundle(bo, deviceType, enabled); +} + +ErrCode AnsNotification::SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("UnregisterPushCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->SetSmartReminderEnabled(deviceType, enabled); +} + +ErrCode AnsNotification::CancelAsBundleWithAgent(const NotificationBundleOption &bundleOption, const int32_t id) +{ + ANS_LOGI("enter CancelAsBundleWithAgent,bundleName:%{public}s,id:%{public}d", + bundleOption.GetBundleName().c_str(), id); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bundle(new (std::nothrow) NotificationBundleOption(bundleOption)); + return proxy->CancelAsBundleWithAgent(bundle, id); +} + +ErrCode AnsNotification::IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("UnregisterPushCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->IsSmartReminderEnabled(deviceType, enabled); +} + +ErrCode AnsNotification::SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("UnregisterPushCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->SetTargetDeviceStatus(deviceType, status); +} + + +bool AnsNotification::IsValidTemplate(const NotificationRequest &request) const +{ + if (request.GetTemplate() == nullptr) { + return true; + } + + std::string name = request.GetTemplate()->GetTemplateName(); + if (strcmp(name.c_str(), DOWNLOAD_TEMPLATE_NAME.c_str()) == 0) { + std::shared_ptr data = request.GetTemplate()->GetTemplateData(); + if (data ==nullptr || !data->HasParam(DOWNLOAD_FILENAME) || !data->HasParam(DOWNLOAD_TITLE)) { + ANS_LOGE("No required parameters."); + return false; + } + } + + return true; +} + +bool AnsNotification::IsValidDelayTime(const NotificationRequest &request) const +{ + return request.GetPublishDelayTime() <= MAX_PUBLISH_DELAY_TIME; +} + +ErrCode AnsNotification::GetDoNotDisturbProfile(int32_t id, sptr &profile) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetDoNotDisturbProfile(id, profile); +} + +void AnsNotification::CreateSubscribeListener(const std::shared_ptr &subscriber, + sptr &listener) +{ + std::lock_guard lock(subscriberMutex_); + auto item = subscribers_.find(subscriber); + if (item != subscribers_.end()) { + listener = item->second; + ANS_LOGD("subscriber has listener"); + return; + } + listener = new (std::nothrow) SubscriberListener(subscriber); + if (listener != nullptr) { + subscribers_[subscriber] = listener; + ANS_LOGD("CreateSubscribeListener success"); + } +} + +void AnsNotification::OnServiceDied() +{ + std::lock_guard lock(subscriberMutex_); + for (auto item : subscribers_) { + item.first->OnDied(); + } +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +ErrCode AnsNotification::RegisterSwingCallback(const std::function swingCbFunc) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("RegisterSwingCallback fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + swingCallBackStub_ = new(std::nothrow) SwingCallBackStub(swingCbFunc); + if (swingCallBackStub_ == nullptr) { + ANS_LOGE("RegisterSwingCallback swingCallBackStub_ == null"); + return ERR_ANS_INVALID_PARAM; + } + return proxy->RegisterSwingCallback(swingCallBackStub_->AsObject()); +} +#endif +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/reminder/src/ans_notification_branch_test.cpp b/frameworks/reminder/src/ans_notification_branch_test.cpp new file mode 100644 index 000000000..bdb62e491 --- /dev/null +++ b/frameworks/reminder/src/ans_notification_branch_test.cpp @@ -0,0 +1,882 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ans_notification.h" +#include "ans_subscriber_proxy.h" +#include "ans_manager_interface.h" +#include "ans_manager_proxy.h" +#undef private +#undef protected +#include "ans_dialog_callback_interface.h" +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "notification.h" +#include "notification_request.h" +#include "singleton.h" +#include "notification_subscriber.h" + +extern void MockGetAnsManagerProxy(OHOS::sptr mockRet); + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +namespace OHOS { +namespace Notification { +class MockAnsManagerInterface : public AnsManagerInterface { +public: + MockAnsManagerInterface() = default; + virtual ~MockAnsManagerInterface() + {}; + sptr AsObject() override + { + return nullptr; + } + + ErrCode Publish(const std::string &label, const sptr ¬ification) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishNotificationForIndirectProxy(const sptr ¬ification) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Cancel(int notificationId, const std::string &label, int32_t instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAll(int32_t instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundle( + int32_t notificationId, const std::string &representativeBundle, int32_t userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundle( + const sptr &bundleOption, int32_t notificationId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundle( + const sptr &bundleOption, int32_t notificationId, int32_t userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddSlots(const std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveAllSlots() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlots(std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotNumAsBundle(const sptr &bundleOption, uint64_t &num) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetActiveNotifications(std::vector> ¬ifications, int32_t instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetActiveNotificationNums(uint64_t &num) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetAllActiveNotifications(std::vector> ¬ifications) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSpecialActiveNotifications( + const std::vector &key, std::vector> ¬ifications) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishAsBundle( + const sptr notification, const std::string &representativeBundle) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationBadgeNum(int num) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetBundleImportance(int &importance) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode HasNotificationPolicyAccessPermission(bool &granted) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Delete(const std::string &key, int32_t removeReason) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveNotification(const sptr &bundleOption, int notificationId, + const std::string &label, int32_t removeReason) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveAllNotifications(const sptr &bundleOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveNotifications(const std::vector &hashcodes, int32_t removeReason) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DeleteByBundle(const sptr &bundleOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DeleteAll() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotsByBundle( + const sptr &bundleOption, std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotByBundle( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode UpdateSlots( + const sptr &bundleOption, const std::vector> &slots) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RequestEnableNotification(const std::string &deviceId, + const sptr &callback, + const sptr &callerToken) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledForSpecialBundle( + const std::string &deviceId, const sptr &bundleOption, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetShowBadgeEnabledForBundle(const sptr &bundleOption, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetShowBadgeEnabledForBundle(const sptr &bundleOption, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetShowBadgeEnabled(bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Subscribe(const sptr &subscriber, + const sptr &info) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SubscribeSelf(const sptr &subscriber) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetAllNotificationEnabledBundles(std::vector &bundleOption)override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SubscribeLocalLiveView(const sptr &subscriber, + const sptr &info, const bool isNatives) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode Unsubscribe( + const sptr &subscriber, const sptr &info) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsAllowedNotify(bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsAllowedNotifySelf(bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CanPopEnableNotificationDialog(const sptr &callback, + bool &canPop, std::string &bundleName) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveEnableNotificationDialog() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDoNotDisturbDate(const sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDoNotDisturbDate(sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddDoNotDisturbProfiles(const std::vector> &profiles) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveDoNotDisturbProfiles(const std::vector> &profiles) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnabled(bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode EnableDistributed(bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode EnableDistributedByBundle(const sptr &bundleOption, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode EnableDistributedSelf(bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnableByBundle(const sptr &bundleOption, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishContinuousTaskNotification(const sptr &request) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode PublishReminder(sptr &reminder) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelReminder(const int32_t reminderId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetValidReminders(std::vector> &reminders) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAllReminders() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DelExcludeDates(const int32_t reminderId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode DeleteAllByUser(const int32_t &userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, + std::vector &dumpInfo) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetBadgeNumberByBundle(const sptr& bundleOption, int32_t badgeNumber) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode UnregisterPushCallback() override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetActiveNotificationByFilter(const sptr &bundleOption, + const int32_t notificationId, const std::string &label, std::vector extraInfoKeys, + sptr &request) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode TriggerLocalLiveView(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode CancelAsBundleWithAgent(const sptr &bundleOption, const int32_t id) + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile) + { + return ERR_ANS_INVALID_PARAM; + } + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + ErrCode RegisterSwingCallback(const sptr &swingCallback) override + { + return ERR_ANS_INVALID_PARAM; + } +#endif +}; + +class AnsNotificationBranchTest : public testing::Test { +public: + AnsNotificationBranchTest() {} + + virtual ~AnsNotificationBranchTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); +}; + +void AnsNotificationBranchTest::SetUpTestCase() +{ + MockGetAnsManagerProxy(nullptr); +} + +void AnsNotificationBranchTest::TearDownTestCase() {} + +void AnsNotificationBranchTest::SetUp() {} + +/* + * @tc.name: RemoveNotifications_0100 + * @tc.desc: Test RemoveNotifications and hashcodes is empty + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0100, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + std::vector hashcodes; + int32_t removeReason = 1; + ErrCode ret = ansNotification->RemoveNotifications(hashcodes, removeReason); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: RemoveNotifications_0200 + * @tc.desc: 1.Test RemoveNotifications and hashcodes is not empty + * 2.GetAnsManagerProxy is false + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0200, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + std::string hashcode = "aa"; + std::vector hashcodes; + hashcodes.emplace_back(hashcode); + int32_t removeReason = 1; + ErrCode ret = ansNotification->RemoveNotifications(hashcodes, removeReason); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RemoveNotifications_0300 + * @tc.desc: 1.Test RemoveNotifications and hashcodes is not empty + * 2.GetAnsManagerProxy is true + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RemoveNotifications_0300, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + std::string hashcode = "aa"; + std::vector hashcodes; + hashcodes.emplace_back(hashcode); + int32_t removeReason = 1; + ansNotification->RemoveNotifications(hashcodes, removeReason); +} + +/* + * @tc.name: RegisterPushCallback_0100 + * @tc.desc: 1.Test RegisterPushCallback + * 2.GetAnsManagerProxy is false + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0100, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + sptr pushCallback = nullptr; + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ErrCode ret = ansNotification->RegisterPushCallback(pushCallback, checkRequest); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RegisterPushCallback_0200 + * @tc.desc: 1.Test RegisterPushCallback + * 2.GetAnsManagerProxy is true + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0200, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + sptr pushCallback = nullptr; + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ansNotification->RegisterPushCallback(pushCallback, checkRequest); +} + +/* + * @tc.name: UnregisterPushCallback_0100 + * @tc.desc: 1.Test UnregisterPushCallback + * 2.GetAnsManagerProxy is false + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, UnregisterPushCallback_0100, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + ErrCode ret = ansNotification->UnregisterPushCallback(); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnregisterPushCallback_0200 + * @tc.desc: 1.Test UnregisterPushCallback + * 2.GetAnsManagerProxy is true + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationBranchTest, UnregisterPushCallback_0200, Function | MediumTest | Level1) +{ + auto ansNotification = std::make_shared(); + EXPECT_NE(ansNotification, nullptr); + ansNotification->UnregisterPushCallback(); +} + +/* + * @tc.name: CanPublishLiveViewContent_0100 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0100, Function | MediumTest | Level1) +{ + NotificationRequest request; + auto notification = std::make_shared(); + EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0110 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0110, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_BUTT); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0120 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0120, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0130 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0130, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_TRUE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0140 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0140, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + auto content = std::make_shared(liveViewContent); + request.SetContent(content); + request.notificationContent_ = nullptr; + + auto notification = std::make_shared(); + EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: CanPublishLiveViewContent_0150 + * @tc.desc: CanPublishLiveViewContent + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, CanPublishLiveViewContent_0150, Function | MediumTest | Level1) +{ + NotificationRequest request; + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + auto liveViewContent = std::make_shared(); + auto content = std::make_shared(liveViewContent); + content->content_ = nullptr; + request.SetContent(content); + + auto notification = std::make_shared(); + EXPECT_FALSE(notification->CanPublishLiveViewContent(request)); +} + +/* + * @tc.name: SetNotificationSlotFlagsAsBundle_0001 + * @tc.desc: SetNotificationSlotFlagsAsBundle + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, SetNotificationSlotFlagsAsBundle_0001, Function | MediumTest | Level1) +{ + NotificationBundleOption bundle; + uint32_t slotFlags = 1; + auto notification = std::make_shared(); + ErrCode ret = notification->SetNotificationSlotFlagsAsBundle(bundle, slotFlags); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + ret = notification->GetNotificationSlotFlagsAsBundle(bundle, slotFlags); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: PublishNotification_0001 + * @tc.desc: PublishNotification + * @tc.type: FUNC + * @tc.require: issule + */ +HWTEST_F(AnsNotificationBranchTest, PublishNotification_0001, Function | MediumTest | Level1) +{ + auto notification = std::make_shared(); + MockGetAnsManagerProxy(new (std::nothrow) MockAnsManagerInterface()); + NotificationRequest req; + std::shared_ptr mediaContent = std::make_shared(); + auto content = std::make_shared(mediaContent); + content->content_ = nullptr; + req.SetContent(content); + + auto ret = notification->PublishNotification("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + ret = notification->PublishNotificationAsBundle("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + + auto liveViewContent = std::make_shared(); + auto content1 = std::make_shared(liveViewContent); + content1->content_ = nullptr; + req.SetContent(content1); + req.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + ret = notification->PublishNotification("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); + ret = notification->PublishNotificationAsBundle("label", req); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/reminder/src/reminder_helper.cpp similarity index 100% rename from frameworks/ans/src/reminder_helper.cpp rename to frameworks/reminder/src/reminder_helper.cpp diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/reminder/src/reminder_request.cpp similarity index 100% rename from frameworks/ans/src/reminder_request.cpp rename to frameworks/reminder/src/reminder_request.cpp diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/reminder/src/reminder_request_alarm.cpp similarity index 100% rename from frameworks/ans/src/reminder_request_alarm.cpp rename to frameworks/reminder/src/reminder_request_alarm.cpp diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/reminder/src/reminder_request_calendar.cpp similarity index 100% rename from frameworks/ans/src/reminder_request_calendar.cpp rename to frameworks/reminder/src/reminder_request_calendar.cpp diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/reminder/src/reminder_request_timer.cpp similarity index 100% rename from frameworks/ans/src/reminder_request_timer.cpp rename to frameworks/reminder/src/reminder_request_timer.cpp diff --git a/frameworks/reminder/test/ans_manager_proxy_unit_test.cpp b/frameworks/reminder/test/ans_manager_proxy_unit_test.cpp new file mode 100644 index 000000000..7fc87e8fe --- /dev/null +++ b/frameworks/reminder/test/ans_manager_proxy_unit_test.cpp @@ -0,0 +1,7981 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "ans_manager_proxy.h" +#include "notification_subscriber.h" +#undef private +#undef protected +#include "ans_const_define.h" +#include "ans_dialog_host_client.h" +#include "ans_manager_interface.h" +#include "ans_inner_errors.h" +#include "ans_subscriber_listener.h" +#include "message_parcel.h" +#include "mock_i_remote_object.h" +#include "notification.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; +using namespace std::placeholders; +using namespace OHOS::Media; + +extern void MockWriteInterfaceToken(bool mockRet); + +namespace OHOS { +namespace Notification { +class AnsManagerProxyUnitTest : public testing::Test { +public: + AnsManagerProxyUnitTest() {} + + virtual ~AnsManagerProxyUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); + std::shared_ptr MakeNewPixelMap(int32_t width, int32_t height); +}; + +void AnsManagerProxyUnitTest::SetUpTestCase() +{ + MockWriteInterfaceToken(true); +} + +void AnsManagerProxyUnitTest::TearDownTestCase() {} + +void AnsManagerProxyUnitTest::SetUp() {} + +void AnsManagerProxyUnitTest::TearDown() {} + +int SendRequestReplace(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, bool retBool, bool setRetBool) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetBool) { + reply.WriteBool(retBool); + } + return 0; +} + +int SendRequestReplaceNum(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, uint64_t retNum, bool setRetNum) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetNum) { + reply.WriteUint64(retNum); + } + return 0; +} + +int SendRequestReplaceString(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, std::string retStr, bool setRetStr) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetStr) { + reply.WriteString(retStr); + } + return 0; +} + +int SendRequestGetAllEnableNotifications(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option, int32_t error, int32_t retnum, bool setError, int32_t notificationNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (retnum) { + reply.WriteInt32(retnum); + } + + if (notificationNum > 0) { + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + for (int32_t i = 0; i < notificationNum; i++) { + reply.WriteParcelable(bundleOption); + } + } + + return 0; +} + +class TestSubscriber : public NotificationSubscriber { +public: + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnConnected() override + {} + void OnEnabledNotificationChanged( + const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnBadgeChanged(const std::shared_ptr &badgeData) override + {} + void OnBadgeEnabledChanged(const sptr &callbackData) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + + void OnBatchCanceled(const std::vector> + &requestList, const std::shared_ptr &sortingMap, int32_t deleteReason) override + {} +}; + +/* + * @tc.name: InnerTransactTest_0100 + * @tc.desc: test if AnsManagerProxy's InnerTransact function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); + EXPECT_EQ(ERR_OK, res); +} + +/* + * @tc.name: InnerTransactTest_0200 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: InnerTransactTest_0300 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(-1))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, res); +} + +/* + * @tc.name: InnerTransactTest_0400 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0400, TestSize.Level1"; + std::shared_ptr proxy = std::make_shared(nullptr); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(static_cast(code), flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: PublishTest_0100 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + sptr notification = nullptr; + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishTest_0200 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishTest_0300 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = ""; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishTest_0400 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: PublishTest_0500 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishTest_0600 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +std::shared_ptr AnsManagerProxyUnitTest::MakeNewPixelMap(int32_t width, int32_t height) +{ + const int32_t PIXEL_BYTES = 4; + std::shared_ptr pixelMap = std::make_shared(); + if (pixelMap == nullptr) { + return nullptr; + } + ImageInfo info; + info.size.width = width; + info.size.height = height; + info.pixelFormat = PixelFormat::ARGB_8888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + int32_t rowDataSize = width * PIXEL_BYTES; + uint32_t bufferSize = rowDataSize * height; + void *buffer = malloc(bufferSize); + if (buffer != nullptr) { + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + } + return pixelMap; +} + +/* + * @tc.name: PublishTest_0700 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + NotificationRequest request(1); + request.SetSlotType(slotType); + request.SetNotificationId(1); + + int pictureWidth = 1024; + int pictureLength = 1024 * 2 + 1; + auto basicContent = std::make_shared(); + basicContent->SetLockScreenPicture(MakeNewPixelMap(pictureWidth, pictureLength)); + auto result = request.CheckLockScreenPictureSizeForLiveView(basicContent); + EXPECT_EQ(ERR_ANS_PICTURE_OVER_SIZE, result); + + auto liveContent = std::make_shared(); + liveContent->SetLockScreenPicture(MakeNewPixelMap(1, 1)); + auto content = std::make_shared(liveContent); + request.SetContent(content); + + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: CancelTest_0100 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0200 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = ""; + int32_t result = proxy->Cancel(notificationId, label, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0300 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label, 0); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelTest_0400 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label, 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelTest_0500 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0100 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0200 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(0); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelAllTest_0300 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0400 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0100 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0200 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = ""; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0300 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelAsBundleTest_0400 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0500 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0600 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->CancelAsBundle(bundleOption, notificationId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0700 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0700, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(bundleOption, notificationId, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0100 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0200 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: AddSlotByTypeTest_0300 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0400 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0100 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AddSlotsTest_0200 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0300 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + slots.resize(MAX_SLOT_NUM + 1); // set MAX_SLOT_NUM + 1 slots + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AddSlotsTest_0400 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0400, TestSize.Level1"; + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + EXPECT_CALL(*iremoteObjects, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: AddSlotsTest_0500 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0600 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0600, TestSize.Level1"; + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + EXPECT_CALL(*iremoteObjects, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0100 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + sptr callerToken = nullptr; + sptr client = nullptr; + AnsDialogHostClient::CreateIfNullptr(client); + client = AnsDialogHostClient::GetInstance(); + int32_t result = proxy->RequestEnableNotification(deviceId, client, callerToken); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0200 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = ""; + sptr callerToken = nullptr; + sptr client = nullptr; + AnsDialogHostClient::CreateIfNullptr(client); + client = AnsDialogHostClient::GetInstance(); + int32_t result = proxy->RequestEnableNotification(deviceId, client, callerToken); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0300 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + sptr callerToken = nullptr; + sptr client = nullptr; + AnsDialogHostClient::CreateIfNullptr(client); + client = AnsDialogHostClient::GetInstance(); + int32_t result = proxy->RequestEnableNotification(deviceId, client, callerToken); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0400 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + sptr callerToken = nullptr; + sptr client = nullptr; + AnsDialogHostClient::CreateIfNullptr(client); + client = AnsDialogHostClient::GetInstance(); + int32_t result = proxy->RequestEnableNotification(deviceId, client, callerToken); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0100 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0200 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveSlotByTypeTest_0300 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0400 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0100 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0200 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveAllSlotsTest_0300 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0400 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceSlot(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t slotNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (slotNum == 1) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteParcelable(slot); + } + if (slotNum > 1) { + reply.WriteInt32(slotNum); + for (int32_t i = 0; i < slotNum; i++) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteStrongParcelable(slot); + } + } + return 0; +} + +/* + * @tc.name: GetSlotByTypeTest_0100 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0200 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_OK, result); + EXPECT_NE(nullptr, slot); +} +/* + * @tc.name: GetSlotByTypeTest_0300 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0400 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: GetSlotsTest_0100 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0200 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsTest_0300 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0400 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0100 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0200 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0300 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0400 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0500 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0600 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceNotifications(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t notificationNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (notificationNum > 0) { + reply.WriteInt32(notificationNum); + for (int32_t i = 0; i < notificationNum; i++) { + sptr request = new (std::nothrow) NotificationRequest(0); + reply.WriteStrongParcelable(request); + } + } + + return 0; +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0100 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0200 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint32_t soltFlags = 0; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_NE(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0300 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint32_t soltFlags = 0; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_NE(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0400 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_OK, result); + EXPECT_NE(ERR_OK, soltFlags); +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0500 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0600 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + uint32_t res = 1; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(res, result); +} + +/* + * @tc.name: GetSlotFlagsAsBundleTest_0700 + * @tc.desc: test GetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->GetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_NE(ERR_OK, result); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0100 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0200 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint32_t soltFlags = 0; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_NE(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0300 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint32_t soltFlags = 0; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_NE(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0400 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(ERR_OK, soltFlags); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0500 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0600 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotFlagsAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + uint32_t res = 1; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(res, result); +} + +/* + * @tc.name: SetSlotFlagsAsBundleTest_0700 + * @tc.desc: test SetSlotFlagsAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSlotFlagsAsBundleTest_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint32_t soltFlags = 0; + int32_t result = proxy->SetSlotFlagsAsBundle(bundleOption, soltFlags); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0100 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0200 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); + EXPECT_EQ(0, notifications.size()); +} +/* + * @tc.name: GetActiveNotificationsTest_0300 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications, 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0400 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0500 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0100 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0200 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0300 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0400 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0500 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0100 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0200 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); + EXPECT_EQ(0, notifications.size()); +} +/* + * @tc.name: GetAllActiveNotificationsTest_0300 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0400 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0500 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0100 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0200 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0300 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); + EXPECT_EQ(0, notifications.size()); +} +/* + * @tc.name: GetSpecialActiveNotificationsTest_0400 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0500 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0600 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0100 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0200 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = ""; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0300 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, canPublish); +} + +/* + * @tc.name: CanPublishAsBundleTest_0400 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0500 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0600 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0100 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0200 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = nullptr; + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishAsBundleTest_0300 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = ""; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishAsBundleTest_0400 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: PublishAsBundleTest_0500 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0600 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0100 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0200 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationBadgeNumTest_0300 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0400 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0100 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0200 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetBundleImportanceTest_0300 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0400 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0500 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0100 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0200 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, granted); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0300 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0400 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0500 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0100 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0200 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: RemoveNotificationTest_0300 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RemoveNotificationTest_0400 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0500 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0100 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0200 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0300 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0400 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0500 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0100 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0200 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("", 0); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: DeleteTest_0300 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: DeleteTest_0400 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0500 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0100 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0200 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: DeleteByBundleTest_0300 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: DeleteByBundleTest_0400 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0500 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0100 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0200 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllTest_0300 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0400 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0100 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0200 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0300 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsByBundleTest_0400 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0500 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0600 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0100 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0200 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0300 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0400 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0400, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + slots.resize(MAX_SLOT_NUM + 1); // set MAX_SLOT_NUM + 1 slots + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0500 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: UpdateSlotsTest_0600 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0700 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0100 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0200 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0300 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0400 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0100 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0200 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0300 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0400 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0100 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0200 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0300 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0400 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0500 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0100 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0200 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0300 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0400 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0500 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0100 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0200 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + EXPECT_CALL(*iremoteObjects, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0300 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0400 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0500 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0600 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0100 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0200 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0300 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0400 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0500 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0100 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0200 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + EXPECT_CALL(*iremoteObjects, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: SubscribeTest_0300 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0400 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0500 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(nullptr, subInfo); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UnsubscribeTest_0100 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0200 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: UnsubscribeTest_0300 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0400 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0500 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(nullptr, subInfo); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0100 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0200 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsAllowedNotifyTest_0300 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0400 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0500 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0100 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0200 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0300 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0400 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0500 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0600 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: CancelGroupTest_0100 + * @tc.desc: test CancelGroup function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelGroupTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelGroup("GroupName", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelGroupTest_0200 + * @tc.desc: test CancelGroup function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelGroupTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelGroup("GroupName", 0); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelGroupTest_0300 + * @tc.desc: test CancelGroup function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelGroupTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelGroup("GroupName", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelGroupTest_0400 + * @tc.desc: test CancelGroup function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelGroupTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelGroup("GroupName", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveGroupByBundleTest_0100 + * @tc.desc: test RemoveGroupByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveGroupByBundle(bundleOption, "GroupName"); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveGroupByBundleTest_0200 + * @tc.desc: test RemoveGroupByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveGroupByBundle(bundleOption, "GroupName"); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveGroupByBundleTest_0300 + * @tc.desc: test RemoveGroupByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveGroupByBundle(bundleOption, "GroupName"); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveGroupByBundleTest_0400 + * @tc.desc: test RemoveGroupByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveGroupByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveGroupByBundle(bundleOption, "GroupName"); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_0100 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t result = proxy->SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_0200 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t result = proxy->SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_0300 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t result = proxy->SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetDoNotDisturbDateTest_0400 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t result = proxy->SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_0500 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t result = proxy->SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetDoNotDisturbDateTest_0100 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t result = proxy->GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetDoNotDisturbDateTest_0200 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t result = proxy->GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} +/* + * @tc.name: GetDoNotDisturbDateTest_0300 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t result = proxy->GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetDoNotDisturbDateTest_0400 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t result = proxy->GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DoesSupportDoNotDisturbModeTest_0100 + * @tc.desc: test DoesSupportDoNotDisturbMode function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool doesSupport = false; + int32_t result = proxy->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DoesSupportDoNotDisturbModeTest_0200 + * @tc.desc: test DoesSupportDoNotDisturbMode function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool doesSupport = false; + int32_t result = proxy->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, doesSupport); +} + +/* + * @tc.name: DoesSupportDoNotDisturbModeTest_0300 + * @tc.desc: test DoesSupportDoNotDisturbMode function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool doesSupport = false; + int32_t result = proxy->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DoesSupportDoNotDisturbModeTest_0400 + * @tc.desc: test DoesSupportDoNotDisturbMode function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool doesSupport = false; + int32_t result = proxy->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DoesSupportDoNotDisturbModeTest_0500 + * @tc.desc: test DoesSupportDoNotDisturbMode function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DoesSupportDoNotDisturbModeTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool doesSupport = false; + int32_t result = proxy->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnabledTest_0100 + * @tc.desc: test IsDistributedEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnabledTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnabledTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->IsDistributedEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnabledTest_0200 + * @tc.desc: test IsDistributedEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnabledTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnabledTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->IsDistributedEnabled(enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: IsDistributedEnabledTest_0300 + * @tc.desc: test IsDistributedEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnabledTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnabledTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->IsDistributedEnabled(enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnabledTest_0400 + * @tc.desc: test IsDistributedEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnabledTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnabledTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->IsDistributedEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnabledTest_0500 + * @tc.desc: test IsDistributedEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnabledTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnabledTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->IsDistributedEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: EnableDistributedTest_0100 + * @tc.desc: test EnableDistributed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributed(true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: EnableDistributedTest_0200 + * @tc.desc: test EnableDistributed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributed(true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: EnableDistributedTest_0300 + * @tc.desc: test EnableDistributed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributed(true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: EnableDistributedTest_0400 + * @tc.desc: test EnableDistributed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributed(true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: EnableDistributedByBundleTest_0100 + * @tc.desc: test EnableDistributedByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->EnableDistributedByBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: EnableDistributedByBundleTest_0200 + * @tc.desc: test EnableDistributedByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->EnableDistributedByBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: EnableDistributedByBundleTest_0300 + * @tc.desc: test EnableDistributedByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->EnableDistributedByBundle(bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: EnableDistributedByBundleTest_0400 + * @tc.desc: test EnableDistributedByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->EnableDistributedByBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: EnableDistributedByBundleTest_0500 + * @tc.desc: test EnableDistributedByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->EnableDistributedByBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: EnableDistributedSelfTest_0100 + * @tc.desc: test EnableDistributedSelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedSelfTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedSelfTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributedSelf(true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: EnableDistributedSelfTest_0200 + * @tc.desc: test EnableDistributedSelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedSelfTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedSelfTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributedSelf(true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: EnableDistributedSelfTest_0300 + * @tc.desc: test EnableDistributedSelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedSelfTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedSelfTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributedSelf(true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: EnableDistributedSelfTest_0400 + * @tc.desc: test EnableDistributedSelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, EnableDistributedSelfTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, EnableDistributedSelfTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->EnableDistributedSelf(true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnableByBundleTest_0100 + * @tc.desc: test IsDistributedEnableByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + bool enabled = false; + int32_t result = proxy->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnableByBundleTest_0200 + * @tc.desc: test IsDistributedEnableByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + bool enabled = false; + int32_t result = proxy->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: IsDistributedEnableByBundleTest_0300 + * @tc.desc: test IsDistributedEnableByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + bool enabled = false; + int32_t result = proxy->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: IsDistributedEnableByBundleTest_0400 + * @tc.desc: test IsDistributedEnableByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + bool enabled = false; + int32_t result = proxy->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnableByBundleTest_0500 + * @tc.desc: test IsDistributedEnableByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + bool enabled = false; + int32_t result = proxy->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsDistributedEnableByBundleTest_0600 + * @tc.desc: test IsDistributedEnableByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsDistributedEnableByBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + bool enabled = false; + int32_t result = proxy->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishContinuousTaskNotificationTest_0100 + * @tc.desc: test PublishContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = nullptr; + int32_t result = proxy->PublishContinuousTaskNotification(notification); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishContinuousTaskNotificationTest_0200 + * @tc.desc: test PublishContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr ansManagerProxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, ansManagerProxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = ansManagerProxy->PublishContinuousTaskNotification(notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishContinuousTaskNotificationTest_0300 + * @tc.desc: test PublishContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->PublishContinuousTaskNotification(notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishContinuousTaskNotificationTest_0400 + * @tc.desc: test PublishContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->PublishContinuousTaskNotification(notification); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: PublishContinuousTaskNotificationTest_0500 + * @tc.desc: test PublishContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishContinuousTaskNotificationTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->PublishContinuousTaskNotification(notification); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelContinuousTaskNotificationTest_0100 + * @tc.desc: test CancelContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelContinuousTaskNotification("label", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelContinuousTaskNotificationTest_0200 + * @tc.desc: test CancelContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelContinuousTaskNotification("label", 0); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelContinuousTaskNotificationTest_0300 + * @tc.desc: test CancelContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelContinuousTaskNotification("label", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelContinuousTaskNotificationTest_0400 + * @tc.desc: test CancelContinuousTaskNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelContinuousTaskNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelContinuousTaskNotification("label", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0100 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0200 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0300 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, support); +} + +/* + * @tc.name: IsSupportTemplateTest_0400 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0500 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0600 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0100 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0200 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledByUserTest_0300 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0400 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0100 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0200 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllByUserTest_0300 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0400 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_2_0100 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t userId = 100; // 100 default user + int32_t result = proxy->SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_2_0200 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t userId = 100; // 100 default user + int32_t result = proxy->SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_2_0300 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t userId = 100; // 100 default user + int32_t result = proxy->SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetDoNotDisturbDateTest_2_0400 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t userId = 100; // 100 default user + int32_t result = proxy->SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetDoNotDisturbDateTest_2_0500 + * @tc.desc: test SetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetDoNotDisturbDateTest_2_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = new (std::nothrow) NotificationDoNotDisturbDate(); + int32_t userId = 100; // 100 default user + int32_t result = proxy->SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetDoNotDisturbDateTest_2_0100 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t userId = 0; + int32_t result = proxy->GetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetDoNotDisturbDateTest_2_0200 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t userId = 0; + int32_t result = proxy->GetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} +/* + * @tc.name: GetDoNotDisturbDateTest_2_0300 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t userId = 0; + int32_t result = proxy->GetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetDoNotDisturbDateTest_2_0400 + * @tc.desc: test GetDoNotDisturbDate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetDoNotDisturbDateTest_2_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr doNotDisturbDate = nullptr; + int32_t userId = 0; + int32_t result = proxy->GetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetEnabledForBundleSlotTest_0100 + * @tc.desc: test SetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetEnabledForBundleSlotTest_0200 + * @tc.desc: test SetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetEnabledForBundleSlotTest_0300 + * @tc.desc: test SetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: SetEnabledForBundleSlotTest_0400 + * @tc.desc: test SetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetEnabledForBundleSlotTest_0500 + * @tc.desc: test SetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetEnabledForBundleSlotTest_0100 + * @tc.desc: test GetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetEnabledForBundleSlotTest_0200 + * @tc.desc: test GetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr ansManagerProxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, ansManagerProxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + bool enabled = false; + int32_t result = ansManagerProxy->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetEnabledForBundleSlotTest_0300 + * @tc.desc: test GetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetEnabledForBundleSlotTest_0400 + * @tc.desc: test GetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetEnabledForBundleSlotTest_0500 + * @tc.desc: test GetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetEnabledForBundleSlotTest_0600 + * @tc.desc: test GetEnabledForBundleSlot function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetEnabledForBundleSlotTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetSyncNotificationEnabledWithoutAppTest_0100 + * @tc.desc: test SetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetSyncNotificationEnabledWithoutApp(0, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetSyncNotificationEnabledWithoutAppTest_0200 + * @tc.desc: test SetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetSyncNotificationEnabledWithoutApp(0, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetSyncNotificationEnabledWithoutAppTest_0300 + * @tc.desc: test SetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetSyncNotificationEnabledWithoutApp(0, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetSyncNotificationEnabledWithoutAppTest_0400 + * @tc.desc: test SetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetSyncNotificationEnabledWithoutAppTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetSyncNotificationEnabledWithoutApp(0, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSyncNotificationEnabledWithoutAppTest_0100 + * @tc.desc: test GetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetSyncNotificationEnabledWithoutApp(0, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSyncNotificationEnabledWithoutAppTest_0200 + * @tc.desc: test GetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetSyncNotificationEnabledWithoutApp(0, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetSyncNotificationEnabledWithoutAppTest_0300 + * @tc.desc: test GetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetSyncNotificationEnabledWithoutApp(0, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSyncNotificationEnabledWithoutAppTest_0400 + * @tc.desc: test GetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetSyncNotificationEnabledWithoutApp(0, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSyncNotificationEnabledWithoutAppTest_0500 + * @tc.desc: test GetSyncNotificationEnabledWithoutApp function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSyncNotificationEnabledWithoutAppTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetSyncNotificationEnabledWithoutApp(0, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceDumpInfo(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t num) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (num > 0) { + std::vector vecDump; + for (int32_t i = 0; i < num; i++) { + std::string info = std::to_string(i); + vecDump.push_back(info); + } + reply.WriteStringVector(vecDump); + } + + return 0; +} +/* + * @tc.name: ShellDumpTest_0100 + * @tc.desc: test ShellDump function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, ShellDumpTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, ShellDumpTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector dumpInfo; + int32_t result = proxy->ShellDump("anm dump -A", "BundleName", 0, 0, dumpInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: ShellDumpTest_0200 + * @tc.desc: test ShellDump function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, ShellDumpTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, ShellDumpTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceDumpInfo, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector dumpInfo; + int32_t result = proxy->ShellDump("anm dump -A", "BundleName", 0, 0, dumpInfo); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, dumpInfo.size()); +} + +/* + * @tc.name: ShellDumpTest_0300 + * @tc.desc: test ShellDump function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, ShellDumpTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, ShellDumpTest_0300, TestSize.Level1"; + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + EXPECT_CALL(*iremoteObjects, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceDumpInfo, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr ansManagerProxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, ansManagerProxy); + std::vector dumpInfo; + int32_t result = ansManagerProxy->ShellDump("anm dump -A", "BundleName", 0, 0, dumpInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: ShellDumpTest_0400 + * @tc.desc: test ShellDump function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, ShellDumpTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, ShellDumpTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector dumpInfo; + int32_t result = proxy->ShellDump("anm dump -A", "BundleName", 0, 0, dumpInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: ShellDumpTest_0500 + * @tc.desc: test ShellDump function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, ShellDumpTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, ShellDumpTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceDumpInfo, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector dumpInfo; + int32_t result = proxy->ShellDump("anm dump -A", "BundleName", 0, 0, dumpInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishReminder_0100 + * @tc.desc: test AnsManagerProxy's PublishReminder function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishReminder_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishReminder_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + sptr reminder = new ReminderRequest(); + ErrCode res = proxy->PublishReminder(reminder); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); +} + +/* + * @tc.name: PublishReminder_0200 + * @tc.desc: test AnsManagerProxy's PublishReminder function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishReminder_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishReminder_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + sptr reminder = nullptr; + ErrCode res = proxy->PublishReminder(reminder); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, res); +} + +/* + * @tc.name: PublishReminder_0300 + * @tc.desc: test AnsManagerProxy's PublishReminder function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishReminder_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishReminder_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + sptr reminder = new ReminderRequest(); + ErrCode res = proxy->PublishReminder(reminder); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); +} + +/* + * @tc.name: ReadReminders_0100 + * @tc.desc: test AnsManagerProxy's ReadReminders function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, ReadReminders_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, ReadReminders_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + uint8_t count = 10; + MessageParcel reply; + std::vector> reminders; + ErrCode res = proxy->ReadReminders(count, reply, reminders); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); +} + +/* + * @tc.name: SetBadgeNumberTest_0100 + * @tc.desc: test SetBadgeNumber function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetBadgeNumberTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->SetBadgeNumber(userId, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetBadgeNumberTest_0200 + * @tc.desc: test SetBadgeNumber function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetBadgeNumberTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t badgeNumber = 0; + int32_t result = proxy->SetBadgeNumber(badgeNumber, 0); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetBadgeNumberTest_0300 + * @tc.desc: test SetBadgeNumber function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetBadgeNumberTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t badgeNumber = 0; + int32_t result = proxy->SetBadgeNumber(badgeNumber, 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetBadgeNumberTest_0400 + * @tc.desc: test SetBadgeNumber function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetBadgeNumberTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t badgeNumber = 0; + int32_t result = proxy->SetBadgeNumber(badgeNumber, 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/** + * @tc.name: SetBadgeNumberByBundleTest_0100 + * @tc.desc: test SetBadgeNumberByBundle with null bundleOption, expect ErrCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberByBundleTest_0100, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t badgeNumber = 0; + int32_t result = proxy->SetBadgeNumberByBundle(nullptr, badgeNumber); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/** + * @tc.name: SetBadgeNumberByBundleTest_0200 + * @tc.desc: test SetBadgeNumberByBundle with invalid proxy object, expect ErrCode ERR_ANS_PARCELABLE_FAILED. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberByBundleTest_0200, TestSize.Level1) +{ + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + ASSERT_NE(nullptr, bundleOption); + std::string bundleName = "bundleName"; + bundleOption->SetBundleName(bundleName); + int32_t badgeNumber = 0; + int32_t result = proxy->SetBadgeNumberByBundle(bundleOption, badgeNumber); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/** + * @tc.name: SetBadgeNumberByBundleTest_0300 + * @tc.desc: test SetBadgeNumberByBundle with empty bundleOption, expect ErrCode ERR_ANS_PARCELABLE_FAILED. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberByBundleTest_0300, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + ASSERT_NE(nullptr, bundleOption); + std::string bundleName = "bundleName"; + bundleOption->SetBundleName(bundleName); + int32_t badgeNumber = 0; + int32_t result = proxy->SetBadgeNumberByBundle(bundleOption, badgeNumber); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: GetAllNotificationEnabledBundles_0100 + * @tc.desc: test GetAllNotificationEnabledBundles function + * @tc.type: FUNC + * @tc.require: #I92VGR + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector bundleOption; + int32_t result = proxy->GetAllNotificationEnabledBundles(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllNotificationEnabledBundles_0200 + * @tc.desc: test GetAllNotificationEnabledBundles function + * @tc.type: FUNC + * @tc.require: #I92VGR + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestGetAllEnableNotifications, _1, _2, _3, _4, + ERR_OK, true, 1, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector bundleOption; + int32_t result = proxy->GetAllNotificationEnabledBundles(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: GetAllNotificationEnabledBundles_0300 + * @tc.desc: test SetBadgeNumber function + * @tc.type: FUNC + * @tc.require: #I92VGR + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector bundleOption; + int32_t result = proxy->GetAllNotificationEnabledBundles(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetAllNotificationEnabledBundles_0400 + * @tc.desc: test GetAllNotificationEnabledBundles function + * @tc.type: FUNC + * @tc.require: #I92VGR + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllNotificationEnabledBundles_0400, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector bundleOption; + int32_t result = proxy->GetAllNotificationEnabledBundles(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationByFilterTest_0100 + * @tc.desc: test GetActiveNotificationByFilter function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationByFilterTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationByFilterTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t notificationId = 0; + std::string label = "label"; + std::vector extraInfoKeys; + + NotificationRequest request(1); + sptr liveViewRequest = new (std::nothrow) NotificationRequest(request); + + int32_t result = proxy->GetActiveNotificationByFilter(bundleOption, notificationId, label, + extraInfoKeys, liveViewRequest); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationByFilterTest_0200 + * @tc.desc: test GetActiveNotificationByFilter function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationByFilterTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationByFilterTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + sptr bundleOption = nullptr; + int32_t notificationId = 0; + std::string label = "label"; + std::vector extraInfoKeys; + + NotificationRequest request(1); + sptr liveViewRequest = new (std::nothrow) NotificationRequest(request); + + int32_t result = proxy->GetActiveNotificationByFilter(bundleOption, notificationId, label, + extraInfoKeys, liveViewRequest); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/** + * @tc.name: AddDoNotDisturbProfiles_0100 + * @tc.desc: test AddDoNotDisturbProfiles when profiles is empty. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, AddDoNotDisturbProfiles_0100, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> profiles; + profiles.clear(); + auto res = proxy->AddDoNotDisturbProfiles(profiles); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, res); +} + +/** + * @tc.name: AddDoNotDisturbProfiles_0200 + * @tc.desc: test AddDoNotDisturbProfiles when WriteInterfaceToken return false. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, AddDoNotDisturbProfiles_0200, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + MockWriteInterfaceToken(false); + auto res = proxy->AddDoNotDisturbProfiles(profiles); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); +} + +/** + * @tc.name: AddDoNotDisturbProfiles_0300 + * @tc.desc: test AddDoNotDisturbProfiles run success and return result. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, AddDoNotDisturbProfiles_0300, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + MockWriteInterfaceToken(true); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1) + .WillRepeatedly( + DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + auto res = proxy->AddDoNotDisturbProfiles(profiles); + EXPECT_NE(ERR_OK, res); + EXPECT_NE(ERR_ANS_PARCELABLE_FAILED, res); +} + +/** + * @tc.name: RemoveDoNotDisturbProfiles_0100 + * @tc.desc: test RemoveDoNotDisturbProfiles when profiles is empty. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveDoNotDisturbProfiles_0100, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> profiles; + profiles.clear(); + auto res = proxy->RemoveDoNotDisturbProfiles(profiles); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, res); +} + +/** + * @tc.name: RemoveDoNotDisturbProfiles_0200 + * @tc.desc: test RemoveDoNotDisturbProfiles when WriteInterfaceToken return false. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveDoNotDisturbProfiles_0200, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + MockWriteInterfaceToken(false); + auto res = proxy->RemoveDoNotDisturbProfiles(profiles); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); +} + +/** + * @tc.name: RemoveDoNotDisturbProfiles_0300 + * @tc.desc: test RemoveDoNotDisturbProfiles run success and return result. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveDoNotDisturbProfiles_0300, TestSize.Level1) +{ + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + MockWriteInterfaceToken(true); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1) + .WillRepeatedly( + DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + auto res = proxy->RemoveDoNotDisturbProfiles(profiles); + EXPECT_NE(ERR_OK, res); + EXPECT_NE(ERR_ANS_PARCELABLE_FAILED, res); +} + +/* + * @tc.name: IsNeedSilentInDoNotDisturbModeTest_0100 + * @tc.desc: test IsNeedSilentInDoNotDisturbMode function + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + int32_t result = proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsNeedSilentInDoNotDisturbModeTest_0200 + * @tc.desc: test IsNeedSilentInDoNotDisturbMode function + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + int32_t result = proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: IsNeedSilentInDoNotDisturbModeTest_0300 + * @tc.desc: test IsNeedSilentInDoNotDisturbMode function + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + int32_t result = proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsNeedSilentInDoNotDisturbModeTest_0400 + * @tc.desc: test IsNeedSilentInDoNotDisturbMode function + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + int32_t result = proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsNeedSilentInDoNotDisturbModeTest_0500 + * @tc.desc: test IsNeedSilentInDoNotDisturbMode function + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsNeedSilentInDoNotDisturbModeTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + int32_t result = proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(ERR_OK, result); +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/reminder/test/ans_manager_stub_test.cpp b/frameworks/reminder/test/ans_manager_stub_test.cpp new file mode 100644 index 000000000..8623c8d42 --- /dev/null +++ b/frameworks/reminder/test/ans_manager_stub_test.cpp @@ -0,0 +1,5417 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "errors.h" +#include "ipc_types.h" +#include "iremote_object.h" +#include "notification_button_option.h" +#include "notification_check_request.h" +#include "notification_subscribe_info.h" +#include + +#define private public +#define protected public +#include "ans_manager_stub.h" +#include "ans_subscriber_stub.h" +#include "reminder_request_alarm.h" +#include "reminder_request_timer.h" +#include "reminder_request_calendar.h" +#include "ans_dialog_host_client.h" +#include "notification_subscriber.h" +#undef private +#undef protected + +#include "ans_inner_errors.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class AnsManagerStubTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() + { + ansManagerStub_ = new AnsManagerStub(); + } + void TearDown() {} + sptr ansManagerStub_; +}; + +/** + * @tc.name: OnRemoteRequest01 + * @tc.desc: Test if get the wrong descriptor. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, OnRemoteRequest0001, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(u"error.GetDescriptor"); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)OBJECT_NULL); +} + +/** + * @tc.name: OnRemoteRequest02 + * @tc.desc: Test if get the wrong code. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, OnRemoteRequest0002, Function | SmallTest | Level1) +{ + uint32_t code = 267; + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)IPC_STUB_UNKNOW_TRANS_ERR); +} + +/** + * @tc.name: HandlePublish01 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + sptr notification = new NotificationRequest(); + notification->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + std::shared_ptr longTextContent = + std::make_shared("longtext"); + std::shared_ptr content2 = std::make_shared(longTextContent); + notification->SetContent(content2); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublish02 + * @tc.desc: Test if the label is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublish03 + * @tc.desc: Test if the notification is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancel01 + * @tc.desc: Test HandleCancel succeeds + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + int32_t instanceKey = 0; + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(instanceKey); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancel02 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancel03 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAll01 + * @tc.desc: Test HandleCancelAll succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAll01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t instanceKey = 0; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(instanceKey); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle01 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle02 + * @tc.desc: Test if the notificationId in data is null.. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle03 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle04 + * @tc.desc: Test if the userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle05 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle05, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_OPTION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle06 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle06, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_OPTION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle07 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle07, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_OPTION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle08 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle08, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_AND_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 3; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundleWithAgent01 + * @tc.desc: Test HandleCancelAsBundleWithAgent. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundleWithAgent01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_WITH_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr bundleOption = new NotificationBundleOption(); + int32_t id = 1; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(id); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleCancelAsBundleWithAgent02 + * @tc.desc: Test HandleCancelAsBundleWithAgent. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundleWithAgent02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_WITH_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundleWithAgent03 + * @tc.desc: Test HandleCancelAsBundleWithAgent. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundleWithAgent03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_WITH_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetTargetDeviceStatus01 + * @tc.desc: Test HandleSetTargetDeviceStatus. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetTargetDeviceStatus01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_TARGET_DEVICE_STATUS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + int32_t status = 1; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString("device"); + data.WriteInt32(status); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetTargetDeviceStatus02 + * @tc.desc: Test HandleSetTargetDeviceStatus. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetTargetDeviceStatus02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_TARGET_DEVICE_STATUS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString("device"); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetTargetDeviceStatus03 + * @tc.desc: Test HandleSetTargetDeviceStatus. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetTargetDeviceStatus03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_TARGET_DEVICE_STATUS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleAddSlotByType01 + * @tc.desc: Test HandleAddSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleAddSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ADD_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveSlotByType01 + * @tc.desc: Test HandleRemoveSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveAllSlots01 + * @tc.desc: Test HandleRemoveAllSlots succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_ALL_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotByType01 + * @tc.desc: Test HandleGetSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotNumAsBundle01 + * @tc.desc: Test HandleGetSlotNumAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotNumAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOT_NUM_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotNumAsBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotNumAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOT_NUM_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetActiveNotifications01 + * @tc.desc: Test HandleGetActiveNotifications succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t instanceKey = 0; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(instanceKey); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetActiveNotificationNums01 + * @tc.desc: Test HandleGetActiveNotificationNums succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotificationNums01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_NUMS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetAllActiveNotifications01 + * @tc.desc: Test HandleGetAllActiveNotifications succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetAllActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ALL_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetActiveNotificationByFilter01 + * @tc.desc: Test HandleGetActiveNotificationByFilter succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotificationByFilter01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetActiveNotificationByFilter02 + * @tc.desc: Test HandleGetActiveNotificationByFilter succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotificationByFilter02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleGetActiveNotificationByFilter03 + * @tc.desc: Test HandleGetActiveNotificationByFilter succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotificationByFilter03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleTriggerLocalLiveView01 + * @tc.desc: Test HandleTriggerLocalLiveView succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleTriggerLocalLiveView01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleTriggerLocalLiveView02 + * @tc.desc: Test HandleTriggerLocalLiveView succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleTriggerLocalLiveView02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + sptr buttonOption = new NotificationButtonOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteStrongParcelable(buttonOption); + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleTriggerLocalLiveView03 + * @tc.desc: Test HandleTriggerLocalLiveView succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleTriggerLocalLiveView03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleTriggerLocalLiveView04 + * @tc.desc: Test HandleTriggerLocalLiveView succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleTriggerLocalLiveView04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCanPublishAsBundle01 + * @tc.desc: Test HandleCanPublishAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CAN_PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCanPublishAsBundle02 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CAN_PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishAsBundle01 + * @tc.desc: Test HandlePublishAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + notification->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + std::shared_ptr longTextContent = + std::make_shared("longtext"); + std::shared_ptr content2 = std::make_shared(longTextContent); + notification->SetContent(content2); + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishAsBundle02 + * @tc.desc: Test if the notification in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishAsBundle03 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationBadgeNum01 + * @tc.desc: Test HandleSetNotificationBadgeNum succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationBadgeNum01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_BADGE_NUM); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t num = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(num); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationBadgeNum02 + * @tc.desc: Test if the num in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationBadgeNum02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_BADGE_NUM); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetBundleImportance01 + * @tc.desc: Test HandleGetBundleImportance succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetBundleImportance01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_BUNDLE_IMPORTANCE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetDoNotDisturbDate01 + * @tc.desc: Test HandleSetDoNotDisturbDate succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr date = new NotificationDoNotDisturbDate(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(date); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetDoNotDisturbDate02 + * @tc.desc: Test if the date in data is null.. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDate02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetDoNotDisturbDate01 + * @tc.desc: Test HandleGetDoNotDisturbDate succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDoesSupportDoNotDisturbMode01 + * @tc.desc: Test HandleDoesSupportDoNotDisturbMode01 succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDoesSupportDoNotDisturbMode01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DOES_SUPPORT_DO_NOT_DISTURB_MODE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishContinuousTaskNotification01 + * @tc.desc: Test HandlePublishContinuousTaskNotification succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishContinuousTaskNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr request = new NotificationRequest(); + request->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + std::shared_ptr longTextContent = + std::make_shared("longtext"); + std::shared_ptr content2 = std::make_shared(longTextContent); + request->SetContent(content2); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(request); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishContinuousTaskNotification02 + * @tc.desc: Test if the request in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishContinuousTaskNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification01 + * @tc.desc: Test HandleCancelContinuousTaskNotification succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a label"; + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification02 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification03 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsNotificationPolicyAccessGranted01 + * @tc.desc: Test HandleIsNotificationPolicyAccessGranted succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleIsNotificationPolicyAccessGranted01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_NOTIFICATION_POLICY_ACCESS_GRANTED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveNotification01 + * @tc.desc: Test HandleRemoveNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveNotification02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 1; + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification03 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification04 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification05 + * @tc.desc: Test if the removeReason in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification05, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveAllNotifications01 + * @tc.desc: Test HandleRemoveAllNotifications succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveAllNotifications02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllNotifications02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelete01 + * @tc.desc: Test HandleDelete succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string key = "this is a key"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(key); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDelete02 + * @tc.desc: Test if the key in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelete03 + * @tc.desc: Test if the removeReason in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string key = "this is a key"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(key); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteByBundle01 + * @tc.desc: Test HandleDeleteByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDeleteByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteAll01 + * @tc.desc: Test HandleDeleteAll succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteAll01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotsByBundle01 + * @tc.desc: Test HandleGetSlotsByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotsByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotsByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotsByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUpdateSlots01 + * @tc.desc: Test HandleUpdateSlots succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t infoSize = 3; + sptr slot1 = new NotificationSlot(); + sptr slot2 = new NotificationSlot(); + sptr slot3 = new NotificationSlot(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(infoSize); + data.WriteStrongParcelable(slot1); + data.WriteStrongParcelable(slot2); + data.WriteStrongParcelable(slot3); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleUpdateSlots02 + * @tc.desc: Test if the StrongParcelable:info in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t infoSize = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(infoSize); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUpdateSlots03 + * @tc.desc: Test if the StrongParcelable:info in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRequestEnableNotification01 + * @tc.desc: Test HandleRequestEnableNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + std::string deviceId = "this is a deviceId"; + sptr callback = new AnsDialogHostClient(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteRemoteObject(callback->AsObject()); + data.WriteBool(false); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleRequestEnableNotification03 + * @tc.desc: Test HandleRequestEnableNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + std::string deviceId = "this is a deviceId"; + const sptr callback = new AnsDialogHostClient(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteRemoteObject(callback->AsObject()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRequestEnableNotification04 + * @tc.desc: Test HandleRequestEnableNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRequestEnableNotification02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSubscribeSelf01 + * @tc.desc: Test SubscribeSelf. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribeSelf01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION_SELF); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSubscribeLocalLiveView01 + * @tc.desc: Test HandleSubscribeLocalLiveView. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribeLocalLiveView01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr info = new NotificationSubscribeInfo(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(true); + data.WriteStrongParcelable(info); + data.WriteBool(true); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSubscribeLocalLiveView02 + * @tc.desc: Test HandleSubscribeLocalLiveView. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribeLocalLiveView02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr info = nullptr; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(true); + data.WriteStrongParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle01 + * @tc.desc: Test HandleSetNotificationsEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles01 + * @tc.desc: Test HandleSetNotificationsEnabledForAllBundles succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle01 + * @tc.desc: Test HandleSetNotificationsEnabledForSpecialBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle03 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle04 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle01 + * @tc.desc: Test HandleSetShowBadgeEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleAddSlots01 + * @tc.desc: Test if the slots in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleAddSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ADD_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleAddSlots02 + * @tc.desc: Test if the result in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleAddSlots02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ADD_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::vector> slots; + sptr slot = new NotificationSlot(); + slots.emplace_back(slot); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + ErrCode result = ansManagerStub_->AddSlots(slots); + ansManagerStub_->WriteParcelableVector(slots, reply, result); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetSlots01 + * @tc.desc: Test HandleGetSlots succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleGetSpecialActiveNotifications01 + * @tc.desc: Test HandleGetSpecialActiveNotifications succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetSpecialActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SPECIAL_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::vector key; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStringVector(key); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleGetShowBadgeEnabledForBundle01 + * @tc.desc: Test HandleGetShowBadgeEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetShowBadgeEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleGetShowBadgeEnabledForBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetShowBadgeEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetShowBadgeEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetShowBadgeEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetShowBadgeEnabled01 + * @tc.desc: Test HandleGetShowBadgeEnabled succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetShowBadgeEnabled01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSubscribe01 + * @tc.desc: Test HandleSubscribe succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribe01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION); + MessageParcel parcels; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr subscriber; + bool subcribeInfo = true; + sptr info = new NotificationSubscribeInfo(); + + parcels.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + parcels.WriteParcelable(subscriber); + parcels.WriteBool(subcribeInfo); + parcels.WriteParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, parcels, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSubscribe02 + * @tc.desc: Test if the subcribeInfo in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribe02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION); + MessageParcel parcels; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr subscriber; + sptr info = new NotificationSubscribeInfo(); + + parcels.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + parcels.WriteRemoteObject(subscriber); + parcels.WriteParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, parcels, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSubscribe03 + * @tc.desc: Test if the info in parcels is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribe03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION); + MessageParcel parcels; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr subscriber; + bool subcribeInfo = true; + + parcels.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + parcels.WriteParcelable(subscriber); + parcels.WriteBool(subcribeInfo); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, parcels, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSubscribe04 + * @tc.desc: Test if the subscriber in parcel is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSubscribe04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION); + MessageParcel parcels; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool subcribeInfo = true; + sptr info = new NotificationSubscribeInfo(); + + parcels.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + parcels.WriteBool(subcribeInfo); + parcels.WriteParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, parcels, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUnsubscribe01 + * @tc.desc: Test HandleUnsubscribe succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleUnsubscribe01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + bool subcribeInfo = true; + sptr info = new NotificationSubscribeInfo(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(info); + data.WriteBool(subcribeInfo); + data.WriteParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUnsubscribe02 + * @tc.desc: Test if the subcribeInfo in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleUnsubscribe02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr subscriber; + sptr info = new NotificationSubscribeInfo(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteRemoteObject(subscriber); + data.WriteParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUnsubscribe03 + * @tc.desc: Test if the info in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleUnsubscribe03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr subscriber; + bool subcribeInfo = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(subscriber); + data.WriteBool(subcribeInfo); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUnsubscribe04 + * @tc.desc: Test if the subscriber in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleUnsubscribe04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool subcribeInfo = true; + sptr info = new NotificationSubscribeInfo(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(subcribeInfo); + data.WriteParcelable(info); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCanPopEnableNotificationDialog01 + * @tc.desc: Test HandleCanPopEnableNotificationDialog. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCanPopEnableNotificationDialog01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CAN_POP_ENABLE_NOTIFICATION_DIALOG); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(nullptr); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCanPopEnableNotificationDialog2 + * @tc.desc: Test HandleCanPopEnableNotificationDialog. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCanPopEnableNotificationDialog02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CAN_POP_ENABLE_NOTIFICATION_DIALOG); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr callback = new AnsDialogHostClient(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(callback->AsObject()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsAllowedNotify01 + * @tc.desc: Test HandleIsAllowedNotify succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsAllowedNotify01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_ALLOWED_NOTIFY); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleIsAllowedNotifySelf01 + * @tc.desc: Test HandleIsAllowedNotifySelf succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsAllowedNotifySelf01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_ALLOWED_NOTIFY_SELF); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleIsSpecialBundleAllowedNotify01 + * @tc.desc: Test HandleIsSpecialBundleAllowedNotify succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsSpecialBundleAllowedNotify01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleIsSpecialBundleAllowedNotify02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsSpecialBundleAllowedNotify02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelGroup01 + * @tc.desc: Test HandleCancelGroup succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCancelGroup01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_GROUP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string groupName = "this is groupName"; + int32_t instanceKey = 0; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(groupName); + data.WriteInt32(instanceKey); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleCancelGroup02 + * @tc.desc: Test if the groupName in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCancelGroup02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_GROUP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveGroupByBundle01 + * @tc.desc: Test HandleRemoveGroupByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveGroupByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + std::string groupName = "this is groupName"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteString(groupName); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleRemoveGroupByBundle02 + * @tc.desc: Test if the groupName in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveGroupByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveGroupByBundle03 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveGroupByBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string groupName = "this is groupName"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(groupName); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsDistributedEnabled01 + * @tc.desc: Test HandleIsDistributedEnabled succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsDistributedEnabled01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleEnableDistributed01 + * @tc.desc: Test HandleEnableDistributed succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributed01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleEnableDistributed02 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributed02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleEnableDistributedByBundle01 + * @tc.desc: Test HandleEnableDistributedByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributedByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleEnableDistributedByBundle02 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributedByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleEnableDistributedByBundle03 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributedByBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleEnableDistributedSelf01 + * @tc.desc: Test HandleEnableDistributedSelf succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributedSelf01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_SELF); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleEnableDistributedSelf02 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleEnableDistributedSelf02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_SELF); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsDistributedEnableByBundle01 + * @tc.desc: Test HandleIsDistributedEnableByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsDistributedEnableByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleIsDistributedEnableByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsDistributedEnableByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetDeviceRemindType01 + * @tc.desc: Test HandleGetDeviceRemindType succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetDeviceRemindType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_DEVICE_REMIND_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleShellDump01 + * @tc.desc: Test HandleShellDump succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleShellDump01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SHELL_DUMP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string cmd = "this is cmd"; + std::string bundle = "this is bundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(cmd); + data.WriteString(bundle); + data.WriteInt32(userId); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleShellDump02 + * @tc.desc: Test if the userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleShellDump02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SHELL_DUMP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string cmd = "this is cmd"; + std::string bundle = "this is bundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(cmd); + data.WriteString(bundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} +/** + * @tc.name: HandleShellDump03 + * @tc.desc: Test if the cmd in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleShellDump03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SHELL_DUMP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string bundle = "this is bundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(bundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} +/** + * @tc.name: HandleShellDump04 + * @tc.desc: Test if the bundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleShellDump04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SHELL_DUMP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string cmd = "this is cmd"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(cmd); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishReminder01 + * @tc.desc: Test Reminder type ALARM. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandlePublishReminder01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::ALARM); + sptr reminder = new ReminderRequest(); + sptr reminderRequestAlarm = new ReminderRequestAlarm(); + + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteUint8(typeInfo); + data.WriteStrongParcelable(reminder); + data.WriteParcelable(reminderRequestAlarm); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandlePublishReminder02 + * @tc.desc: Test Reminder type invalid. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandlePublishReminder02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); + sptr reminder = new ReminderRequest(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteUint8(typeInfo); + data.WriteParcelable(reminder); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: HandlePublishReminder03 + * @tc.desc: Test reminder in date is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandlePublishReminder03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishReminder04 + * @tc.desc: Test Reminder type TIMER. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandlePublishReminder04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::TIMER); + sptr reminder = new ReminderRequest(); + sptr reminderRequestTimer = new ReminderRequestTimer(); + + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteUint8(typeInfo); + data.WriteStrongParcelable(reminder); + data.WriteParcelable(reminderRequestTimer); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandlePublishReminder05 + * @tc.desc: Test Reminder type CALENDAR. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandlePublishReminder05, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::CALENDAR); + sptr reminder = new ReminderRequest(); + sptr reminderRequestCalendar = new ReminderRequestCalendar(); + + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteUint8(typeInfo); + data.WriteStrongParcelable(reminder); + data.WriteParcelable(reminderRequestCalendar); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandlePublishReminder06 + * @tc.desc: Test typeInfo in date is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandlePublishReminder06, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr reminder = new ReminderRequest(); + sptr reminderRequestCalendar = new ReminderRequestCalendar(); + + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(reminder); + data.WriteParcelable(reminderRequestCalendar); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelReminder01 + * @tc.desc: Test HandleCancelReminder ERR_INVALID_OPERATION. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCancelReminder01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t reminderId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(reminderId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleCancelReminder02 + * @tc.desc: Test reminderId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCancelReminder02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAllReminders01 + * @tc.desc: Test HandleCancelAllReminders result ERR_INVALID_OPERATION. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAllReminders01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleGetValidReminders01 + * @tc.desc: Test HandleGetValidReminders result ERR_INVALID_OPERATION. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetValidReminders01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleAddExcludeDate01 + * @tc.desc: Test HandleAddExcludeDate result ERR_INVALID_OPERATION. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleAddExcludeDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelExcludeDates01 + * @tc.desc: Test HandleDelExcludeDates result ERR_INVALID_OPERATION. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDelExcludeDates01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetExcludeDates01 + * @tc.desc: Test HandleGetExcludeDates result ERR_INVALID_OPERATION. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetExcludeDates01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: ReadParcelableVector01 + * @tc.desc: Test ReadParcelableVector result. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, ReadParcelableVector01, Function | SmallTest | Level1) +{ + std::vector> slots; + sptr slot = new NotificationSlot(); + slots.emplace_back(slot); + MessageParcel data; + bool ret = ansManagerStub_->ReadParcelableVector(slots, data); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: ReadParcelableVector02 + * @tc.desc: Test ReadParcelableVector result. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, ReadParcelableVector02, Function | SmallTest | Level1) +{ + std::vector> slots; + sptr slot = new NotificationSlot(); + slots.emplace_back(slot); + MessageParcel data; + + int32_t infoSize = 4; + data.WriteInt32(infoSize); + data.WriteStrongParcelable(slot); + bool ret = ansManagerStub_->ReadParcelableVector(slots, data); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: HandleIsSupportTemplate01 + * @tc.desc: Test HandleIsSupportTemplate succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsSupportTemplate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string templateName = "this is templateName"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(templateName); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleIsSupportTemplate02 + * @tc.desc: Test templateName in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsSupportTemplate02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsSpecialUserAllowedNotifyByUser01 + * @tc.desc: Test HandleIsSpecialUserAllowedNotifyByUser succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsSpecialUserAllowedNotifyByUser01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_SPECIAL_USER_ALLOWED_NOTIFY); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleIsSpecialUserAllowedNotifyByUser02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleIsSpecialUserAllowedNotifyByUser02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_SPECIAL_USER_ALLOWED_NOTIFY); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledByUser01 + * @tc.desc: Test HandleSetNotificationsEnabledByUser succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledByUser01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER); + MessageParcel parcels; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + bool enabled = true; + + parcels.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + parcels.WriteInt32(userId); + parcels.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, parcels, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetNotificationsEnabledByUser02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledByUser02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledByUser03 + * @tc.desc: Test enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledByUser03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteAllByUser01 + * @tc.desc: Test HandleDeleteAllByUser succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteAllByUser01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleDeleteAllByUser02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteAllByUser02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetDoNotDisturbDateByUser01 + * @tc.desc: Test HandleSetDoNotDisturbDateByUser succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDateByUser01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + sptr date = new NotificationDoNotDisturbDate(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + data.WriteStrongParcelable(date); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetDoNotDisturbDateByUser02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDateByUser02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr date = new NotificationDoNotDisturbDate(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(date); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetDoNotDisturbDateByUser03 + * @tc.desc: Test date in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDateByUser03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetDoNotDisturbDateByUser01 + * @tc.desc: Test HandleGetDoNotDisturbDateByUser succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetDoNotDisturbDateByUser01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + sptr date = new NotificationDoNotDisturbDate(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(date); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleGetDoNotDisturbDateByUser02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetDoNotDisturbDateByUser02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetEnabledForBundleSlot01 + * @tc.desc: Test HandleSetEnabledForBundleSlot succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetEnabledForBundleSlot01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t type = 4; + bool enabled = true; + bool isForceControl = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(type); + data.WriteBool(enabled); + data.WriteBool(isForceControl); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetEnabledForBundleSlot02 + * @tc.desc: Test bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetEnabledForBundleSlot02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t type = 4; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(type); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetEnabledForBundleSlot03 + * @tc.desc: Test type in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetEnabledForBundleSlot03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetEnabledForBundleSlot04 + * @tc.desc: Test enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetEnabledForBundleSlot04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t type = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(type); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetEnabledForBundleSlot01 + * @tc.desc: Test HandleGetEnabledForBundleSlot succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetEnabledForBundleSlot01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t type = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(type); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleGetEnabledForBundleSlot02 + * @tc.desc: Test bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetEnabledForBundleSlot02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t type = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(type); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetEnabledForBundleSlot03 + * @tc.desc: Test type in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetEnabledForBundleSlot03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetEnabledForBundleSlotSelf01 + * @tc.desc: Test type in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleGetEnabledForBundleSlotSelf01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT_SELF); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + int32_t type = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(type); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetBadgeNumber03 + * @tc.desc: HandleSetBadgeNumber. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleSetBadgeNumber03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_BADGE_NUMBER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + int32_t type = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(type); + data.WriteInt32(type); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleDistributedSetEnabledWithoutApp01 + * @tc.desc: Test HandleDistributedSetEnabledWithoutApp succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDistributedSetEnabledWithoutApp01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleDistributedSetEnabledWithoutApp02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDistributedSetEnabledWithoutApp02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDistributedSetEnabledWithoutApp03 + * @tc.desc: Test enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDistributedSetEnabledWithoutApp03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDistributedGetEnabledWithoutApp01 + * @tc.desc: Test HandleDistributedGetEnabledWithoutApp succeed. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDistributedGetEnabledWithoutApp01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleDistributedGetEnabledWithoutApp02 + * @tc.desc: Test userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HandleDistributedGetEnabledWithoutApp02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: GetSlots01 + * @tc.desc: Test GetSlots return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetSlots01, Function | SmallTest | Level1) +{ + std::vector> slots; + sptr slot = new NotificationSlot(); + slots.emplace_back(slot); + + ErrCode result = ansManagerStub_->GetSlots(slots); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetSpecialActiveNotifications01 + * @tc.desc: Test GetSpecialActiveNotifications return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetSpecialActiveNotifications01, Function | SmallTest | Level1) +{ + std::vector keys; + std::string key = "this is key"; + keys.emplace_back(key); + std::vector> notifications; + sptr notification = new Notification(); + notifications.emplace_back(notification); + + ErrCode result = ansManagerStub_->GetSpecialActiveNotifications(keys, notifications); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: PublishAsBundle01 + * @tc.desc: Test PublishAsBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, PublishAsBundle01, Function | SmallTest | Level1) +{ + sptr notification = new NotificationRequest(); + std::string representativeBundle = "this is representativeBundle"; + + ErrCode result = ansManagerStub_->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetNotificationBadgeNum01 + * @tc.desc: Test SetNotificationBadgeNum return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetNotificationBadgeNum01, Function | SmallTest | Level1) +{ + int num = 2; + ErrCode result = ansManagerStub_->SetNotificationBadgeNum(num); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetBundleImportance01 + * @tc.desc: Test GetBundleImportance return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetBundleImportance01, Function | SmallTest | Level1) +{ + int importance = 2; + ErrCode result = ansManagerStub_->GetBundleImportance(importance); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HasNotificationPolicyAccessPermission01 + * @tc.desc: Test HasNotificationPolicyAccessPermission return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, HasNotificationPolicyAccessPermission01, Function | SmallTest | Level1) +{ + bool granted = true; + ErrCode result = ansManagerStub_->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: RemoveNotification01 + * @tc.desc: Test RemoveNotification return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, RemoveNotification01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + int notificationId = 4; + std::string label = "this is label"; + int32_t removeReason = 2; + ErrCode result = ansManagerStub_->RemoveNotification(bundleOption, notificationId, label, removeReason); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: RemoveAllNotifications01 + * @tc.desc: Test RemoveAllNotifications return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, RemoveAllNotifications01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + ErrCode result = ansManagerStub_->RemoveAllNotifications(bundleOption); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: Delete01 + * @tc.desc: Test Delete return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, Delete01, Function | SmallTest | Level1) +{ + std::string key = "this is key"; + int32_t removeReason = 2; + ErrCode result = ansManagerStub_->Delete(key, removeReason); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: DeleteByBundle01 + * @tc.desc: Test DeleteByBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, DeleteByBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + ErrCode result = ansManagerStub_->DeleteByBundle(bundleOption); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: DeleteAll01 + * @tc.desc: Test DeleteAll return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, DeleteAll01, Function | SmallTest | Level1) +{ + ErrCode result = ansManagerStub_->DeleteAll(); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetSlotsByBundle01 + * @tc.desc: Test GetSlotsByBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetSlotsByBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + std::vector> slots; + sptr slot = new NotificationSlot(); + slots.emplace_back(slot); + + ErrCode result = ansManagerStub_->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: UpdateSlots01 + * @tc.desc: Test UpdateSlots return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, UpdateSlots01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + std::vector> slots; + sptr slot = new NotificationSlot(); + slots.emplace_back(slot); + + ErrCode result = ansManagerStub_->UpdateSlots(bundleOption, slots); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: RequestEnableNotification01 + * @tc.desc: Test RequestEnableNotification return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, RequestEnableNotification01, Function | SmallTest | Level1) +{ + std::string deviceId = "this is deviceId"; + sptr callback = nullptr; + sptr callerToken = nullptr; + ErrCode result = ansManagerStub_->RequestEnableNotification(deviceId, callback, callerToken); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetNotificationsEnabledForBundle01 + * @tc.desc: Test SetNotificationsEnabledForBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetNotificationsEnabledForBundle01, Function | SmallTest | Level1) +{ + std::string bundle = "this is bundle"; + bool enabled = true; + + ErrCode result = ansManagerStub_->SetNotificationsEnabledForBundle(bundle, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetNotificationsEnabledForAllBundles01 + * @tc.desc: Test SetNotificationsEnabledForAllBundles return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetNotificationsEnabledForAllBundles01, Function | SmallTest | Level1) +{ + std::string deviceId = "this is deviceId"; + bool enabled = true; + + ErrCode result = ansManagerStub_->SetNotificationsEnabledForAllBundles(deviceId, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetNotificationsEnabledForSpecialBundle01 + * @tc.desc: Test SetNotificationsEnabledForSpecialBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetNotificationsEnabledForSpecialBundle01, Function | SmallTest | Level1) +{ + std::string deviceId = "this is deviceId"; + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + ErrCode result = ansManagerStub_->SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetShowBadgeEnabledForBundle01 + * @tc.desc: Test SetShowBadgeEnabledForBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetShowBadgeEnabledForBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + ErrCode result = ansManagerStub_->SetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetShowBadgeEnabledForBundle01 + * @tc.desc: Test GetShowBadgeEnabledForBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetShowBadgeEnabledForBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + ErrCode result = ansManagerStub_->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetShowBadgeEnabled01 + * @tc.desc: Test GetShowBadgeEnabled return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetShowBadgeEnabled01, Function | SmallTest | Level1) +{ + bool enabled = true; + + ErrCode result = ansManagerStub_->GetShowBadgeEnabled(enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsAllowedNotify01 + * @tc.desc: Test IsAllowedNotify return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsAllowedNotify01, Function | SmallTest | Level1) +{ + bool allowed = true; + + ErrCode result = ansManagerStub_->IsAllowedNotify(allowed); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsAllowedNotifySelf01 + * @tc.desc: Test IsAllowedNotifySelf return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsAllowedNotifySelf01, Function | SmallTest | Level1) +{ + bool allowed = true; + + ErrCode result = ansManagerStub_->IsAllowedNotifySelf(allowed); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsSpecialBundleAllowedNotify01 + * @tc.desc: Test IsSpecialBundleAllowedNotify return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsSpecialBundleAllowedNotify01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bool allowed = true; + + ErrCode result = ansManagerStub_->IsSpecialBundleAllowedNotify(bundleOption, allowed); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: CancelGroup01 + * @tc.desc: Test CancelGroup return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, CancelGroup01, Function | SmallTest | Level1) +{ + std::string groupName = "this is groupName"; + + ErrCode result = ansManagerStub_->CancelGroup(groupName, 0); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: RemoveGroupByBundle01 + * @tc.desc: Test RemoveGroupByBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, RemoveGroupByBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + std::string groupName = "this is groupName"; + + ErrCode result = ansManagerStub_->RemoveGroupByBundle(bundleOption, groupName); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetDoNotDisturbDate01 + * @tc.desc: Test SetDoNotDisturbDate return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + sptr date = new NotificationDoNotDisturbDate(); + + ErrCode result = ansManagerStub_->SetDoNotDisturbDate(date); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetDoNotDisturbDate01 + * @tc.desc: Test GetDoNotDisturbDate return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + sptr date = new NotificationDoNotDisturbDate(); + + ErrCode result = ansManagerStub_->GetDoNotDisturbDate(date); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: DoesSupportDoNotDisturbMode01 + * @tc.desc: Test DoesSupportDoNotDisturbMode return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, DoesSupportDoNotDisturbMode01, Function | SmallTest | Level1) +{ + bool doesSupport = true; + + ErrCode result = ansManagerStub_->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsDistributedEnabled01 + * @tc.desc: Test IsDistributedEnabled return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsDistributedEnabled01, Function | SmallTest | Level1) +{ + bool enabled = true; + + ErrCode result = ansManagerStub_->IsDistributedEnabled(enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: EnableDistributed01 + * @tc.desc: Test EnableDistributed return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, EnableDistributed01, Function | SmallTest | Level1) +{ + bool enabled = true; + + ErrCode result = ansManagerStub_->EnableDistributed(enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: EnableDistributedByBundle01 + * @tc.desc: Test EnableDistributedByBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, EnableDistributedByBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + ErrCode result = ansManagerStub_->EnableDistributedByBundle(bundleOption, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: EnableDistributedSelf01 + * @tc.desc: Test EnableDistributedSelf return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, EnableDistributedSelf01, Function | SmallTest | Level1) +{ + bool enabled = true; + + ErrCode result = ansManagerStub_->EnableDistributedSelf(enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsDistributedEnableByBundle01 + * @tc.desc: Test IsDistributedEnableByBundle return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsDistributedEnableByBundle01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + ErrCode result = ansManagerStub_->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetDeviceRemindType01 + * @tc.desc: Test GetDeviceRemindType return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetDeviceRemindType01, Function | SmallTest | Level1) +{ + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::NONE; + + ErrCode result = ansManagerStub_->GetDeviceRemindType(remindType); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: PublishContinuousTaskNotification01 + * @tc.desc: Test PublishContinuousTaskNotification return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, PublishContinuousTaskNotification01, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(); + + ErrCode result = ansManagerStub_->PublishContinuousTaskNotification(request); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: CancelContinuousTaskNotification01 + * @tc.desc: Test CancelContinuousTaskNotification return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, CancelContinuousTaskNotification01, Function | SmallTest | Level1) +{ + std::string label = "this is label"; + int32_t notificationId = 4; + + ErrCode result = ansManagerStub_->CancelContinuousTaskNotification(label, notificationId); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: PublishReminder01 + * @tc.desc: Test PublishReminder return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, PublishReminder01, Function | SmallTest | Level1) +{ + sptr reminder = new ReminderRequest(); + + ErrCode result = ansManagerStub_->PublishReminder(reminder); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: CancelReminder01 + * @tc.desc: Test CancelReminder return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, CancelReminder01, Function | SmallTest | Level1) +{ + int32_t reminderId = 5; + + ErrCode result = ansManagerStub_->CancelReminder(reminderId); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetValidReminders01 + * @tc.desc: Test GetValidReminders return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetValidReminders01, Function | SmallTest | Level1) +{ + std::vector> reminders; + sptr reminder = new ReminderRequest(); + reminders.emplace_back(reminder); + + ErrCode result = ansManagerStub_->GetValidReminders(reminders); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: CancelAllReminders01 + * @tc.desc: Test CancelAllReminders return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, CancelAllReminders01, Function | SmallTest | Level1) +{ + ErrCode result = ansManagerStub_->CancelAllReminders(); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: AddExcludeDate01 + * @tc.desc: Test AddExcludeDate return. + * @tc.type: FUNC + * @tc.require: issue#I9F24R + */ +HWTEST_F(AnsManagerStubTest, AddExcludeDate01, Function | SmallTest | Level1) +{ + int32_t reminderId = 5; + uint64_t date = 1713196800000; + ErrCode result = ansManagerStub_->AddExcludeDate(reminderId, date); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: DelExcludeDates01 + * @tc.desc: Test DelExcludeDates return. + * @tc.type: FUNC + * @tc.require: issue#I9F24R + */ +HWTEST_F(AnsManagerStubTest, DelExcludeDates01, Function | SmallTest | Level1) +{ + int32_t reminderId = 5; + ErrCode result = ansManagerStub_->DelExcludeDates(reminderId); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetExcludeDates01 + * @tc.desc: Test GetExcludeDates return. + * @tc.type: FUNC + * @tc.require: issue#I9F24R + */ +HWTEST_F(AnsManagerStubTest, GetExcludeDates01, Function | SmallTest | Level1) +{ + int32_t reminderId = 5; + std::vector dates; + ErrCode result = ansManagerStub_->GetExcludeDates(reminderId, dates); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsSupportTemplate01 + * @tc.desc: Test IsSupportTemplate return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsSupportTemplate01, Function | SmallTest | Level1) +{ + std::string templateName = "this is templateName"; + bool support = true; + + ErrCode result = ansManagerStub_->IsSupportTemplate(templateName, support); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: IsSpecialUserAllowedNotify01 + * @tc.desc: Test IsSpecialUserAllowedNotify return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, IsSpecialUserAllowedNotify01, Function | SmallTest | Level1) +{ + int32_t userId = 2; + bool allowed = true; + + ErrCode result = ansManagerStub_->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetNotificationsEnabledByUser01 + * @tc.desc: Test SetNotificationsEnabledByUser return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetNotificationsEnabledByUser01, Function | SmallTest | Level1) +{ + int32_t deviceId = 2; + bool enabled = true; + + ErrCode result = ansManagerStub_->SetNotificationsEnabledByUser(deviceId, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: DeleteAllByUser01 + * @tc.desc: Test DeleteAllByUser return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, DeleteAllByUser01, Function | SmallTest | Level1) +{ + int32_t userId = 2; + + ErrCode result = ansManagerStub_->DeleteAllByUser(userId); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetDoNotDisturbDate02 + * @tc.desc: Test SetDoNotDisturbDate return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetDoNotDisturbDate02, Function | SmallTest | Level1) +{ + int32_t userId = 2; + sptr date = new NotificationDoNotDisturbDate(); + + ErrCode result = ansManagerStub_->SetDoNotDisturbDate(userId, date); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetDoNotDisturbDate02 + * @tc.desc: Test GetDoNotDisturbDate return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetDoNotDisturbDate02, Function | SmallTest | Level1) +{ + int32_t userId = 2; + sptr date = new NotificationDoNotDisturbDate(); + + ErrCode result = ansManagerStub_->GetDoNotDisturbDate(userId, date); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetEnabledForBundleSlot01 + * @tc.desc: Test SetEnabledForBundleSlot return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetEnabledForBundleSlot01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + bool enabled = true; + + ErrCode result = ansManagerStub_->SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetEnabledForBundleSlot01 + * @tc.desc: Test GetEnabledForBundleSlot return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetEnabledForBundleSlot01, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + bool enabled = true; + + ErrCode result = ansManagerStub_->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: ShellDump01 + * @tc.desc: Test ShellDump return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, ShellDump01, Function | SmallTest | Level1) +{ + std::string cmd = "this is cmd"; + std::string bundle = "this is bundle"; + int32_t userId = 5; + std::vector dumpInfo; + + ErrCode result = ansManagerStub_->ShellDump(cmd, bundle, userId, 0, dumpInfo); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: SetSyncNotificationEnabledWithoutApp01 + * @tc.desc: Test SetSyncNotificationEnabledWithoutApp return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, SetSyncNotificationEnabledWithoutApp01, Function | SmallTest | Level1) +{ + int32_t userId = 2; + bool enabled = true; + + ErrCode result = ansManagerStub_->SetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetSyncNotificationEnabledWithoutApp01 + * @tc.desc: Test GetSyncNotificationEnabledWithoutApp return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, GetSyncNotificationEnabledWithoutApp01, Function | SmallTest | Level1) +{ + int32_t userId = 2; + bool enabled = true; + + ErrCode result = ansManagerStub_->GetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: Subscribe01 + * @tc.desc: Test Subscribe return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, Subscribe01, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + + ErrCode result = ansManagerStub_->Subscribe(nullptr, info); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: Unsubscribe01 + * @tc.desc: Test Unsubscribe return. + * @tc.type: FUNC + * @tc.require: issueI620XB + */ +HWTEST_F(AnsManagerStubTest, Unsubscribe01, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + + ErrCode result = ansManagerStub_->Unsubscribe(nullptr, info); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleSetBadgeNumber01 + * @tc.desc: Test HandleSetBadgeNumber succeed. + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleSetBadgeNumber01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t badgeNumber = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(badgeNumber); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetBadgeNumber02 + * @tc.desc: Test badgeNumber in data is null. + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleSetBadgeNumber02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetAdditionConfig01 + * @tc.desc: Test HandleSetAdditionConfig. + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleSetAdditionConfig01, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteString("key"); + data.WriteString("value"); + + ErrCode ret = ansManagerStub_->HandleSetAdditionConfig(data, reply); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleSetAdditionConfig02 + * @tc.desc: Test HandleSetAdditionConfig. + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleSetAdditionConfig02, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteString("key"); + + ErrCode ret = ansManagerStub_->HandleSetAdditionConfig(data, reply); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetAdditionConfig03 + * @tc.desc: Test HandleSetAdditionConfig. + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleSetAdditionConfig03, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode ret = ansManagerStub_->HandleSetAdditionConfig(data, reply); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotifications01 + * @tc.desc: Test HandleRemoveNotifications function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotifications01, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + ErrCode ret = ansManagerStub_->HandleRemoveNotifications(data, reply); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleUnregisterPushCallback01 + * @tc.desc: Test HandleUnregisterPushCallback function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleUnregisterPushCallback01, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + ErrCode ret = ansManagerStub_->HandleUnregisterPushCallback(data, reply); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleRegisterPushCallback01 + * @tc.desc: Test HandleRegisterPushCallback function + * @tc.type: FUNC + * @tc.require: #I6C2X9 + */ +HWTEST_F(AnsManagerStubTest, HandleRegisterPushCallback01, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + ErrCode ret = ansManagerStub_->HandleRegisterPushCallback(data, reply); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRegisterPushCallback02 + * @tc.desc: Test HandleRegisterPushCallback succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRegisterPushCallback02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REGISTER_PUSH_CALLBACK); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr callback = new AnsDialogHostClient(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(callback->AsObject()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_NE((int)ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleRegisterPushCallback03 + * @tc.desc: Test HandleRegisterPushCallback succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRegisterPushCallback03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::REGISTER_PUSH_CALLBACK); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + sptr callback = new AnsDialogHostClient(); + sptr checkRequest = nullptr; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(callback->AsObject()); + data.WriteParcelable(checkRequest); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetSlotFlagsAsBundle01 + * @tc.desc: Test HandleGetSlotFlagsAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotFlagsAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + uint32_t res = 305; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_NE((int)ret, (int)res); +} + +/** + * @tc.name: HandleGetSlotFlagsAsBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotFlagsAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + uint32_t res = 305; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_NE((int)ret, (int)res); +} + +/* + * @tc.name: SetSmartReminderEnabled_0100 + * @tc.desc: test SetSmartReminderEnabled with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, SetSmartReminderEnabled_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + bool enabled = true; + data.WriteString("testDeviceType"); + data.WriteBool(enabled); + + ErrCode res = ansManagerStub_->HandleSetSmartReminderEnabled(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.name: IsSmartReminderEnabled_0100 + * @tc.desc: test IsSmartReminderEnabled with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, IsSmartReminderEnabled_0100, TestSize.Level1) +{ + bool enable = true; + MessageParcel data; + MessageParcel reply; + data.WriteString("testDeviceType1111"); + data.WriteBool(enable); + ErrCode result = ansManagerStub_->HandleIsSmartReminderEnabled(data, reply); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name: HandleSetSlotFlagsAsBundle01 + * @tc.desc: Test HandleSetSlotFlagsAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetSlotFlagsAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + uint32_t res = 305; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_NE((int)ret, (int)res); +} + +/** + * @tc.name: HandleGetAllNotificationEnableStatus + * @tc.desc: Test HandleGetAllNotificationEnableStatus. + * @tc.type: FUNC + * @tc.require: issueI92VGR + */ +HWTEST_F(AnsManagerStubTest, HandleGetAllNotificationEnableStatus01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_ALL_NOTIFICATION_ENABLE_STATUS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleSetSlotFlagsAsBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetSlotFlagsAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + uint32_t res = 305; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_NE((int)ret, (int)res); +} + +/* + * @tc.name: SetDistributedEnabledByBundle_0100 + * @tc.desc: test SetDistributedEnabledByBundle with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, SetDistributedEnabledByBundle_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + sptr bundleOption = new NotificationBundleOption(); + bundleOption->SetBundleName("bundleName"); + bundleOption->SetUid(1); + std::string deviceType = "testDeviceType"; + bool enabled = true; + data.WriteParcelable(bundleOption); + data.WriteString(deviceType); + data.WriteBool(enabled); + + ErrCode res = ansManagerStub_->HandleSetDistributedEnabledByBundle(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/* + * @tc.name: SetDistributedEnabledByBundle_0200 + * @tc.desc: test SetDistributedEnabledByBundle + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, SetDistributedEnabledByBundle_0200, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + data.WriteParcelable(nullptr); + + ErrCode res = ansManagerStub_->HandleSetDistributedEnabledByBundle(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: IsDistributedEnabledByBundle_0100 + * @tc.desc: test IsDistributedEnabledByBundle with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, IsDistributedEnabledByBundle_0100, TestSize.Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bundleOption->SetBundleName("bundleName"); + bundleOption->SetUid(1); + std::string deviceType = "testDeviceType1111"; + bool enable = true; + + MessageParcel data; + MessageParcel reply; + data.WriteParcelable(bundleOption); + data.WriteString(deviceType); + data.WriteBool(enable); + ErrCode result = ansManagerStub_->HandleIsDistributedEnabledByBundle(data, reply); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name: IsDistributedEnabledByBundle_0200 + * @tc.desc: test IsDistributedEnabledByBundle with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, IsDistributedEnabledByBundle_0200, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteParcelable(nullptr); + + ErrCode result = ansManagerStub_->HandleIsDistributedEnabledByBundle(data, reply); + EXPECT_EQ(result, ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetBadgeNumberByBundle01 + * @tc.desc: Test HandleSetBadgeNumberByBundle with invalid data, expect error code ERR_ANS_PARCELABLE_FAILED. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleSetBadgeNumberByBundle01, Function | SmallTest | Level1) +{ + ASSERT_NE(ansManagerStub_, nullptr); + MessageParcel data; + MessageParcel reply; + + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + EXPECT_NE(bundleOption, nullptr); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->HandleSetBadgeNumberByBundle(data, reply); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); + + int32_t badgeNumber = 4; + data.WriteInt32(badgeNumber); + ret = ansManagerStub_->HandleSetBadgeNumberByBundle(data, reply); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetBadgeNumberByBundle02 + * @tc.desc: Test HandleSetBadgeNumberByBundle with valid data, expect error code ERR_INVALID_OPERATION. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleSetBadgeNumberByBundle02, Function | SmallTest | Level1) +{ + ASSERT_NE(ansManagerStub_, nullptr); + MessageParcel data; + MessageParcel reply; + + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + EXPECT_NE(bundleOption, nullptr); + std::string bundleName = "bundleName"; + bundleOption->SetBundleName(bundleName); + data.WriteParcelable(bundleOption); + int32_t badgeNumber = 4; + data.WriteInt32(badgeNumber); + ErrCode ret = ansManagerStub_->HandleSetBadgeNumberByBundle(data, reply); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HandleAddDoNotDisturbProfiles_0100 + * @tc.desc: test HandleAddDoNotDisturbProfiles when ReadParcelableVector return false. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleAddDoNotDisturbProfiles_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + ErrCode ret = ansManagerStub_->HandleAddDoNotDisturbProfiles(data, reply); + EXPECT_EQ(ret, ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleAddDoNotDisturbProfiles_0200 + * @tc.desc: test HandleAddDoNotDisturbProfiles success. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleAddDoNotDisturbProfiles_0200, TestSize.Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + ErrCode result = ansManagerStub_->AddDoNotDisturbProfiles(profiles); + ansManagerStub_->WriteParcelableVector(profiles, reply, result); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleRemoveDoNotDisturbProfiles_0100 + * @tc.desc: test HandleRemoveDoNotDisturbProfiles when ReadParcelableVector return false. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveDoNotDisturbProfiles_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + ErrCode ret = ansManagerStub_->HandleRemoveDoNotDisturbProfiles(data, reply); + EXPECT_EQ(ret, ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveDoNotDisturbProfiles_0200 + * @tc.desc: test HandleRemoveDoNotDisturbProfiles success. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveDoNotDisturbProfiles, TestSize.Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::GET_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + ErrCode result = ansManagerStub_->AddDoNotDisturbProfiles(profiles); + ansManagerStub_->WriteParcelableVector(profiles, reply, result); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +/* + * @tc.name: RegisterSwingCallback_0100 + * @tc.desc: test RegisterSwingCallback with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, RegisterSwingCallback_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + sptr swingCallback = nullptr; + data.WriteRemoteObject(swingCallback); + ErrCode res = ansManagerStub_->HandleRegisterSwingCallback(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/* + * @tc.name: RegisterSwingCallback_0200 + * @tc.desc: test RegisterSwingCallback with parameters + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, RegisterSwingCallback_0200, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + sptr swingCallback = nullptr; + data.WriteRemoteObject(swingCallback); + ErrCode res = ansManagerStub_->HandleRegisterSwingCallback(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} +#endif + +/** + * @tc.name: HandleIsNeedSilentInDoNotDisturbMode01 + * @tc.desc: Test HandleIsNeedSilentInDoNotDisturbMode01 succeeds. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, HandleIsNeedSilentInDoNotDisturbMode01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(NotificationInterfaceCode::IS_NEED_SILENT_IN_DO_NOT_DISTURB_MODE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: IsNeedSilentInDoNotDisturbMode01 + * @tc.desc: Test IsNeedSilentInDoNotDisturbMode return. + * @tc.type: FUNC + */ +HWTEST_F(AnsManagerStubTest, IsNeedSilentInDoNotDisturbMode01, Function | SmallTest | Level1) +{ + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + + ErrCode result = ansManagerStub_->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); +} +} +} diff --git a/frameworks/reminder/test/ans_notification_unit_test.cpp b/frameworks/reminder/test/ans_notification_unit_test.cpp new file mode 100644 index 000000000..c74f161ec --- /dev/null +++ b/frameworks/reminder/test/ans_notification_unit_test.cpp @@ -0,0 +1,1615 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_dialog_callback_stub.h" +#include "errors.h" +#include "notification_slot.h" +#include "refbase.h" +#include +#include +#include +#include + +#define private public +#define protected public +#include "ans_notification.h" +#include "ans_subscriber_proxy.h" +#include "ans_manager_proxy.h" +#undef private +#undef protected +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "mock_i_remote_object.h" +#include "notification.h" +#include "singleton.h" +#include "notification_subscriber.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +extern void MockWriteInterfaceToken(bool mockRet); + +namespace OHOS { +namespace Notification { +class AnsNotificationUnitTest : public testing::Test { +public: + AnsNotificationUnitTest() {} + + virtual ~AnsNotificationUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); + std::shared_ptr ans_; + sptr ansManagerProxy_{nullptr}; +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + void UpdateStatuts(bool isEnable, int status) {} +#endif +}; + +void AnsNotificationUnitTest::SetUpTestCase() +{ + MockWriteInterfaceToken(true); +} + +void AnsNotificationUnitTest::TearDownTestCase() {} + +void AnsNotificationUnitTest::SetUp() +{ + if (!ans_) { + ans_ = DelayedSingleton::GetInstance(); + } +} + +void AnsNotificationUnitTest::TearDown() {} + +class TestAnsSubscriber : public NotificationSubscriber { +public: + void OnConnected() override + {} + void OnDisconnected() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDied() override + {} + void OnEnabledNotificationChanged( + const std::shared_ptr &callbackData) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + void OnBadgeChanged(const std::shared_ptr &badgeData) override + {} + void OnBadgeEnabledChanged(const sptr &callbackData) override + {} + void OnBatchCanceled(const std::vector> + &requestList, const std::shared_ptr &sortingMap, int32_t deleteReason) override + {} +}; + +/* + * @tc.name: GetAnsManagerProxy_0100 + * @tc.desc: test GetAnsManagerProxy return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetAnsManagerProxy_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); +} + +/* + * @tc.name: AddSlotByType_0100 + * @tc.desc: test AddSlotByType ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, AddSlotByType_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::CUSTOM; + ErrCode ret1 = ans_->AddSlotByType(slotType); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret3 = ans_->RemoveNotificationSlot(slotType); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RemoveAllSlots_0100 + * @tc.desc: test RemoveAllSlots ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, RemoveAllSlots_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + ErrCode ret1 = ans_->RemoveAllSlots(); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlot_0100 + * @tc.desc: test GetNotificationSlot ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlot_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::CUSTOM; + sptr slot = new NotificationSlot(); + ErrCode ret1 = ans_->GetNotificationSlot(slotType, slot); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + std::vector> slots; + slots.emplace_back(slot); + ErrCode ret2 = ans_->GetNotificationSlots(slots); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + std::vector nslots; + NotificationSlot notificationSlot; + nslots.emplace_back(notificationSlot); + ErrCode ret3 = ans_->AddNotificationSlots(nslots); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlotNumAsBundle_0100 + * @tc.desc: test GetNotificationSlotNumAsBundle ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotNumAsBundle_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + std::string bundleName = "bundleName"; + bundleOptions.SetBundleName(bundleName); + uint64_t num = 10; + ErrCode ret1 = ans_->GetNotificationSlotNumAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlotFlagsAsBundle_0100 + * @tc.desc: test GetNotificationSlotFlagsAsBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotFlagsAsBundle_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + std::string bundleName = "bundleName"; + bundleOptions.SetBundleName(bundleName); + uint32_t num = 10; + ErrCode ret1 = ans_->GetNotificationSlotFlagsAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlotFlagsAsBundle_0200 + * @tc.desc: test GetNotificationSlotFlagsAsBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotFlagsAsBundle_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + bundleOptions.SetBundleName(""); + uint32_t num = 10; + ErrCode ret1 = ans_->GetNotificationSlotFlagsAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: SetNotificationSlotFlagsAsBundle_0200 + * @tc.desc: test GetNotificationSlotFlagsAsBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetNotificationSlotFlagsAsBundle_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + bundleOptions.SetBundleName(""); + uint64_t num = 10; + ErrCode ret1 = ans_->SetNotificationSlotFlagsAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: CanPopEnableNotificationDialog_0100 + * @tc.desc: test CanPopEnableNotificationDialog. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, CanPopEnableNotificationDialog_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + sptr client = nullptr; + bool enable = true; + std::string bundleName = ""; + ErrCode ret1 = ans_->CanPopEnableNotificationDialog(client, enable, bundleName); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RemoveNotifications_0100 + * @tc.desc: test RemoveNotifications. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, RemoveNotifications_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::vector hashCodes = {"data1", "data2"}; + ErrCode ret1 = ans_->RemoveNotifications(hashCodes, 1); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlotForBundle_0100 + * @tc.desc: test GetNotificationSlotForBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotForBundle_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + bundleOptions.SetBundleName("name"); + sptr slot = new NotificationSlot(); + ErrCode ret1 = ans_->GetNotificationSlotForBundle(bundleOptions, + NotificationConstant::SlotType::CONTENT_INFORMATION, slot); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlotForBundle_0200 + * @tc.desc: test GetNotificationSlotForBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotForBundle_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + bundleOptions.SetBundleName(""); + sptr slot = new NotificationSlot(); + ErrCode ret1 = ans_->GetNotificationSlotForBundle(bundleOptions, + NotificationConstant::SlotType::CONTENT_INFORMATION, slot); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: GetEnabledForBundleSlotSelf_0100 + * @tc.desc: test GetEnabledForBundleSlotSelf. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetEnabledForBundleSlotSelf_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + bool enable = true; + ErrCode ret1 = ans_->GetEnabledForBundleSlotSelf( + NotificationConstant::SlotType::CONTENT_INFORMATION, enable); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RegisterPushCallback_0100 + * @tc.desc: test RegisterPushCallback. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, RegisterPushCallback_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + sptr callback = new AnsDialogHostClient(); + sptr checkRequest = nullptr; + ErrCode ret1 = ans_->RegisterPushCallback(callback->AsObject(), checkRequest); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnregisterPushCallback_0100 + * @tc.desc: test UnregisterPushCallback. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, UnregisterPushCallback_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + ErrCode ret1 = ans_->UnregisterPushCallback(); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetAdditionConfig_0100 + * @tc.desc: test SetAdditionConfig. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetAdditionConfig_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string key = "key"; + std::string value = "value"; + ErrCode ret1 = ans_->SetAdditionConfig(key, value); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetAdditionConfig_0200 + * @tc.desc: test SetAdditionConfig. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetAdditionConfig_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string key = ""; + std::string value = "value"; + ErrCode ret1 = ans_->SetAdditionConfig(key, value); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: CancelAsBundleWithAgent_0100 + * @tc.desc: test CancelAsBundleWithAgent. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, CancelAsBundleWithAgent_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + int32_t id = 1; + NotificationBundleOption bundleOption = NotificationBundleOption(); + ErrCode ret1 = ans_->CancelAsBundleWithAgent(bundleOption, id); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetTargetDeviceStatus_0100 + * @tc.desc: test SetAdditionConfig. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetTargetDeviceStatus_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string deviceType = "device"; + const uint32_t status = 1; + ErrCode ret1 = ans_->SetTargetDeviceStatus(deviceType, status); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: PublishNotification_0100 + * @tc.desc: test PublishNotification ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, PublishNotification_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string label = "this is label"; + NotificationRequest request; + std::shared_ptr normalContent = std::make_shared(); + std::shared_ptr content = std::make_shared(normalContent); + request.SetContent(content); + ErrCode ret1 = ans_->PublishNotification(label, request); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + int32_t notificationId = 10; + ErrCode ret3 = ans_->CancelNotification(label, notificationId); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret4 = ans_->CancelAllNotifications(); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); + std::string representativeBundle = "this is representativeBundle"; + int32_t userId = 5; + ErrCode ret5 = ans_->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetActiveNotificationNums_0100 + * @tc.desc: test GetActiveNotificationNums ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetActiveNotificationNums_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + uint64_t num = 4; + ErrCode ret1 = ans_->GetActiveNotificationNums(num); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + std::vector> request; + ErrCode ret2 = ans_->GetActiveNotifications(request); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: CanPublishNotificationAsBundle_0100 + * @tc.desc: test CanPublishNotificationAsBundle ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, CanPublishNotificationAsBundle_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string representativeBundle = "this is representativeBundle"; + bool canPublish = true; + ErrCode ret1 = ans_->CanPublishNotificationAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + std::string representativeBundle0 = ""; + ErrCode ret2 = ans_->CanPublishNotificationAsBundle(representativeBundle0, canPublish); + EXPECT_EQ(ret2, ERR_ANS_INVALID_PARAM); + NotificationRequest request; + ErrCode ret3 = ans_->PublishNotificationAsBundle(representativeBundle0, request); + EXPECT_EQ(ret3, ERR_ANS_INVALID_PARAM); + std::shared_ptr normalContent = std::make_shared(); + std::shared_ptr content = std::make_shared(normalContent); + request.SetContent(content); + ErrCode ret5 = ans_->PublishNotificationAsBundle(representativeBundle, request); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetNotificationBadgeNum_0100 + * @tc.desc: test SetNotificationBadgeNum ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetNotificationBadgeNum_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + ErrCode ret1 = ans_->SetNotificationBadgeNum(); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + int32_t num = 3; + ErrCode ret2 = ans_->SetNotificationBadgeNum(num); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: IsAllowedNotify_0100 + * @tc.desc: test IsAllowedNotify ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, IsAllowedNotify_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + bool allowed = true; + ErrCode ret1 = ans_->IsAllowedNotify(allowed); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret2 = ans_->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + NotificationBundleOption bundleOption; + std::string bundleName = "this is bundleName"; + bundleOption.SetBundleName(bundleName); + ErrCode ret3 = ans_->IsAllowedNotify(bundleOption, allowed); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RequestEnableNotification_0100 + * @tc.desc: test RequestEnableNotification ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, RequestEnableNotification_0100, Function | MediumTest | Level1) +{ + ans_->GetAnsManagerProxy(); + std::string deviceId = "this is deviceId"; + sptr callerToken = nullptr; + sptr client = nullptr; + AnsDialogHostClient::CreateIfNullptr(client); + client = AnsDialogHostClient::GetInstance(); + ErrCode ret1 = ans_->RequestEnableNotification(deviceId, client, callerToken); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + bool hasPermission = true; + ErrCode ret3 = ans_->HasNotificationPolicyAccessPermission(hasPermission); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetBundleImportance_0100 + * @tc.desc: test GetBundleImportance ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetBundleImportance_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationSlot::NotificationLevel importance = NotificationSlot::NotificationLevel::LEVEL_NONE; + ErrCode ret1 = ans_->GetBundleImportance(importance); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RemoveNotification_0100 + * @tc.desc: test RemoveNotification ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, RemoveNotification_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string key = ""; + int32_t removeReason = 10; + ErrCode ret1 = ans_->RemoveNotification(key, removeReason); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); + std::string key1 = "this is key1"; + ErrCode ret2 = ans_->RemoveNotification(key1, removeReason); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + NotificationBundleOption bundleOption; + std::string bundleName = "this is bundleName"; + bundleOption.SetBundleName(bundleName); + int32_t notificationId = 2; + std::string label = "this is label"; + ErrCode ret3 = ans_->RemoveNotification(bundleOption, notificationId, label, removeReason); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret4 = ans_->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret5 = ans_->RemoveNotificationsByBundle(bundleOption); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret6 = ans_->RemoveNotifications(); + EXPECT_EQ(ret6, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetNotificationSlotsForBundle_0100 + * @tc.desc: test GetNotificationSlotsForBundle ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotsForBundle_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOption; + std::string bundleName = "this is bundleName"; + bundleOption.SetBundleName(bundleName); + sptr slot = new NotificationSlot(); + std::vector> slots; + slots.emplace_back(slot); + ErrCode ret1 = ans_->GetNotificationSlotsForBundle(bundleOption, slots); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret2 = ans_->UpdateNotificationSlots(bundleOption, slots); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundles_0100 + * @tc.desc: test SetNotificationsEnabledForAllBundles ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetNotificationsEnabledForAllBundles_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string deviceId = "this is deviceId"; + bool enabled = true; + ErrCode ret1 = ans_->SetNotificationsEnabledForAllBundles(deviceId, enabled); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret2 = ans_->SetNotificationsEnabledForDefaultBundle(deviceId, enabled); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + NotificationBundleOption bundleOption; + std::string bundleName = "this is bundleName"; + bundleOption.SetBundleName(bundleName); + ErrCode ret3 = ans_->SetNotificationsEnabledForSpecifiedBundle(bundleOption, deviceId, enabled); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret4 = ans_->SetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret5 = ans_->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret6 = ans_->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ret6, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: CancelGroup_0100 + * @tc.desc: test CancelGroup ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, CancelGroup_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string groupName = "this is groupName"; + ErrCode ret1 = ans_->CancelGroup(groupName); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + NotificationBundleOption bundleOption; + std::string bundleName = "this is bundleName"; + bundleOption.SetBundleName(bundleName); + ErrCode ret2 = ans_->RemoveGroupByBundle(bundleOption, groupName); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetDoNotDisturbDate_0100 + * @tc.desc: test SetDoNotDisturbDate ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetDoNotDisturbDate_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationDoNotDisturbDate doNotDisturbDate; + ErrCode ret1 = ans_->SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret2 = ans_->GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + bool doesSupport = true; + ErrCode ret3 = ans_->DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: PublishContinuousTaskNotification_0100 + * @tc.desc: test PublishContinuousTaskNotification ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, PublishContinuousTaskNotification_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationRequest request; + std::shared_ptr normalContent = std::make_shared(); + std::shared_ptr content = std::make_shared(normalContent); + request.SetContent(content); + ErrCode ret1 = ans_->PublishContinuousTaskNotification(request); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + std::string label = "this is label"; + int32_t notificationId = 3; + ErrCode ret2 = ans_->CancelContinuousTaskNotification(label, notificationId); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: IsDistributedEnabled_0100 + * @tc.desc: test IsDistributedEnabled ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, IsDistributedEnabled_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + bool enabled = true; + ErrCode ret1 = ans_->IsDistributedEnabled(enabled); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret2 = ans_->EnableDistributed(enabled); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + NotificationBundleOption bundleOption; + ErrCode ret3 = ans_->EnableDistributedByBundle(bundleOption, enabled); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret4 = ans_->EnableDistributedSelf(enabled); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret5 = ans_->IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetDeviceRemindType_0100 + * @tc.desc: test GetDeviceRemindType ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetDeviceRemindType_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::NONE; + ErrCode ret1 = ans_->GetDeviceRemindType(remindType); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ReminderRequest reminder; + ErrCode ret2 = ans_->PublishReminder(reminder); + EXPECT_EQ(ret2, ERR_ANS_INVALID_PARAM); + int32_t reminderId = 1; + ErrCode ret3 = ans_->CancelReminder(reminderId); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret4 = ans_->CancelAllReminders(); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); + std::vector> validReminders; + ErrCode ret5 = ans_->GetValidReminders(validReminders); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: IsSupportTemplate_0100 + * @tc.desc: test IsSupportTemplate ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, IsSupportTemplate_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string templateName = "this is templateName"; + bool support = true; + ErrCode ret1 = ans_->IsSupportTemplate(templateName, support); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + int32_t userId = -1; + bool allowed = true; + ErrCode ret2 = ans_->IsAllowedNotify(userId, allowed); + EXPECT_EQ(ret2, ERR_ANS_INVALID_PARAM); + int32_t userId1 = 2; + ErrCode ret3 = ans_->IsAllowedNotify(userId1, allowed); + EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); + bool enabled = true; + ErrCode ret4 = ans_->SetNotificationsEnabledForAllBundles(userId, enabled); + EXPECT_EQ(ret4, ERR_ANS_INVALID_PARAM); + ErrCode ret5 = ans_->SetNotificationsEnabledForAllBundles(userId1, enabled); + EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret6 = ans_->RemoveNotifications(userId); + EXPECT_EQ(ret6, ERR_ANS_INVALID_PARAM); + ErrCode ret7 = ans_->RemoveNotifications(userId1); + EXPECT_EQ(ret7, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetDoNotDisturbDate_0200 + * @tc.desc: test SetDoNotDisturbDate ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetDoNotDisturbDate_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + int32_t userId = -1; + NotificationDoNotDisturbDate doNotDisturbDate; + ErrCode ret1 = ans_->SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); + int32_t userId1 = 2; + ErrCode ret2 = ans_->SetDoNotDisturbDate(userId1, doNotDisturbDate); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret3 = ans_->GetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ret3, ERR_ANS_INVALID_PARAM); + ErrCode ret4 = ans_->GetDoNotDisturbDate(userId1, doNotDisturbDate); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetEnabledForBundleSlot_0100 + * @tc.desc: test SetEnabledForBundleSlot ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetEnabledForBundleSlot_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject_ = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject_); + std::shared_ptr proxy = std::make_shared(iremoteObject_); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOption; + std::string bundleName = "bundleName"; + bundleOption.SetBundleName(bundleName); + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::CUSTOM; + bool enabled = true; + bool isForceControl = false; + ErrCode ret1 = ans_->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret2 = ans_->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: ShellDump_0100 + * @tc.desc: test ShellDump ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, ShellDump_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string cmd = "this is cmd"; + std::string bundle = "this is bundle"; + int32_t userId = 1; + std::vector dumpInfo; + ErrCode ret1 = ans_->ShellDump(cmd, bundle, userId, 0, dumpInfo); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetSyncNotificationEnabledWithoutApp_0100 + * @tc.desc: test SetSyncNotificationEnabledWithoutApp ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetSyncNotificationEnabledWithoutApp_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + int32_t userId = -1; + bool enabled = true; + ErrCode ret1 = ans_->SetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); + int32_t userId1 = 2; + ErrCode ret2 = ans_->SetSyncNotificationEnabledWithoutApp(userId1, enabled); + EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); + ErrCode ret3 = ans_->GetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(ret3, ERR_ANS_INVALID_PARAM); + ErrCode ret4 = ans_->GetSyncNotificationEnabledWithoutApp(userId1, enabled); + EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SubscribeNotification_0100 + * @tc.desc: test SubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SubscribeNotification_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject_ = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject_); + std::shared_ptr proxy = std::make_shared(iremoteObject_); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = TestAnsSubscriber(); + NotificationSubscribeInfo info; + ErrCode ret1 = ans_->SubscribeNotification(subscriber, info); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SubscribeNotification_0200 + * @tc.desc: test SubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SubscribeNotification_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = TestAnsSubscriber(); + ErrCode ret1 = ans_->SubscribeNotification(subscriber); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SubscribeNotification_0300 + * @tc.desc: test SubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SubscribeNotification_0300, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject_ = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject_); + std::shared_ptr proxy = std::make_shared(iremoteObject_); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = std::make_shared(); + sptr info = new (std::nothrow) NotificationSubscribeInfo(); + ErrCode ret1 = ans_->SubscribeNotification(subscriber, info); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SubscribeNotification_0400 + * @tc.desc: test SubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SubscribeNotification_0400, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + ErrCode ret1 = ans_->SubscribeNotification(nullptr); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: GetAllActiveNotifications_0100 + * @tc.desc: test GetAllActiveNotifications return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetAllActiveNotifications_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + std::vector> notification; + ErrCode ret1 = ans_->GetAllActiveNotifications(notification); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: GetAllActiveNotifications_0200 + * @tc.desc: test GetAllActiveNotifications return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetAllActiveNotifications_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + std::vector key; + std::vector> notification; + ErrCode ret1 = ans_->GetAllActiveNotifications(key, notification); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnSubscribeNotification_0100 + * @tc.desc: test UnSubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, UnSubscribeNotification_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = TestAnsSubscriber(); + ErrCode ret1 = ans_->UnSubscribeNotification(subscriber); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnSubscribeNotification_0200 + * @tc.desc: test UnSubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, UnSubscribeNotification_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = TestAnsSubscriber(); + NotificationSubscribeInfo info; + ErrCode ret1 = ans_->UnSubscribeNotification(subscriber, info); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnSubscribeNotification_0300 + * @tc.desc: test UnSubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, UnSubscribeNotification_0300, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = std::make_shared(); + ErrCode ret1 = ans_->UnSubscribeNotification(subscriber); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: UnSubscribeNotification_0400 + * @tc.desc: test UnSubscribeNotification return false. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, UnSubscribeNotification_0400, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + auto subscriber = std::make_shared(); + sptr info = new (std::nothrow) NotificationSubscribeInfo(); + ErrCode ret1 = ans_->UnSubscribeNotification(subscriber, info); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecifiedBundle_0100 + * @tc.desc: test SetNotificationsEnabledForSpecifiedBundle ErrCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetNotificationsEnabledForSpecifiedBundle_0100, Function | MediumTest | Level1) +{ + std::string deviceId = "this is deviceId"; + bool enabled = true; + NotificationBundleOption bundleOption; + std::string bundleName = ""; + bundleOption.SetBundleName(bundleName); + ErrCode ret3 = ans_->SetNotificationsEnabledForSpecifiedBundle(bundleOption, deviceId, enabled); + EXPECT_EQ(ret3, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: GetAllNotificationEnabledBundles_0100 + * @tc.desc: test GetAllNotificationEnabledBundles ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + * @tc.require: #I92VGR + */ +HWTEST_F(AnsNotificationUnitTest, GetAllNotificationEnabledBundles_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::vector bundleOption; + ErrCode ret = ans_->GetAllNotificationEnabledBundles(bundleOption); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: CancelGroup_0200 + * @tc.desc: test CancelGroup ErrCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, CancelGroup_0200, Function | MediumTest | Level1) +{ + std::string groupName = ""; + ErrCode ret1 = ans_->CancelGroup(groupName); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: SetSmartReminderEnabled_0100 + * @tc.desc: test SetSmartReminderEnabled with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, SetSmartReminderEnabled_0100, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool ret = ans_->GetAnsManagerProxy(); + EXPECT_EQ(ret, false); + ErrCode res = ans_->SetSmartReminderEnabled("testDeviceType", true); + EXPECT_EQ(res, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/** + * @tc.name: IsSmartReminderEnabled_0100 + * @tc.desc: test IsSmartReminderEnabled with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, IsSmartReminderEnabled_0100, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool ret = ans_->GetAnsManagerProxy(); + EXPECT_EQ(ret, false); + bool enable = true; + ErrCode result = ans_->IsSmartReminderEnabled("testDeviceType1111", enable); + EXPECT_EQ(result, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetBadgeNumberByBundle_0100 + * @tc.desc: test SetBadgeNumberByBundle with empty bundleOption, expect ErrCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, SetBadgeNumberByBundle_0100, TestSize.Level1) +{ + NotificationBundleOption bundleOption; + int32_t badgeNumber = 0; + ErrCode res = ans_->SetBadgeNumberByBundle(bundleOption, badgeNumber); + EXPECT_EQ(res, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: SetBadgeNumberByBundle_0200 + * @tc.desc: test SetBadgeNumberByBundle with invalid AnsManagerProxy, expect ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, SetBadgeNumberByBundle_0200, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool ret = ans_->GetAnsManagerProxy(); + EXPECT_EQ(ret, false); + + NotificationBundleOption bundleOption; + std::string bundleName = "bundleName"; + bundleOption.SetBundleName(bundleName); + int32_t badgeNumber = 0; + ErrCode res = ans_->SetBadgeNumberByBundle(bundleOption, badgeNumber); + EXPECT_EQ(res, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: SetDistributedEnabledByBundle_0100 + * @tc.desc: test SetDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, SetDistributedEnabledByBundle_0100, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool ret = ans_->GetAnsManagerProxy(); + EXPECT_EQ(ret, false); + + NotificationBundleOption bundleOption; + std::string bundleName = "bundleName"; + bundleOption.SetBundleName(bundleName); + bundleOption.SetUid(1); + std::string deviceType = "testDeviceType"; + + ErrCode res = ans_->SetDistributedEnabledByBundle(bundleOption, deviceType, true); + EXPECT_EQ(res, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/** + * @tc.name: SetDistributedEnabledByBundle_0200 + * @tc.desc: test SetDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, SetDistributedEnabledByBundle_0200, TestSize.Level1) +{ + NotificationBundleOption bundleOption; + std::string deviceType = "testDeviceType"; + ErrCode ret = ans_->SetDistributedEnabledByBundle(bundleOption, deviceType, true); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetDistributedEnabledByBundle_0300 + * @tc.desc: test SetDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, SetDistributedEnabledByBundle_0300, TestSize.Level1) +{ + NotificationBundleOption bundleOption; + bundleOption.SetBundleName(""); + bundleOption.SetUid(1); + std::string deviceType = "testDeviceType"; + ErrCode ret = ans_->SetDistributedEnabledByBundle(bundleOption, deviceType, true); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} + + +/** + * @tc.name: IsDistributedEnabledByBundle_0100 + * @tc.desc: test IsDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, IsDistributedEnabledByBundle_0100, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool ret = ans_->GetAnsManagerProxy(); + EXPECT_EQ(ret, false); + + NotificationBundleOption bundleOption; + std::string bundleName = "bundleName"; + bundleOption.SetBundleName(bundleName); + bundleOption.SetUid(1); + std::string deviceType = "testDeviceType1111"; + bool enable = true; + ErrCode result = ans_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable); + EXPECT_EQ(result, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/** + * @tc.name: IsDistributedEnabledByBundle_0200 + * @tc.desc: test IsDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, IsDistributedEnabledByBundle_0200, TestSize.Level1) +{ + MockWriteInterfaceToken(true); + NotificationBundleOption bundleOption; + std::string deviceType = "testDeviceType"; + + bool enable = true; + ErrCode ret = ans_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: IsDistributedEnabledByBundle_0300 + * @tc.desc: test IsDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, IsDistributedEnabledByBundle_0300, TestSize.Level1) +{ + MockWriteInterfaceToken(true); + NotificationBundleOption bundleOption; + bundleOption.SetBundleName(""); + bundleOption.SetUid(1); + std::string deviceType = "testDeviceType"; + + bool enable = true; + ErrCode ret = ans_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable); + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: AddDoNotDisturbProfiles_0100 + * @tc.desc: test AddDoNotDisturbProfiles ErrCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, AddDoNotDisturbProfiles_0100, TestSize.Level1) +{ + std::vector> profiles; + profiles.clear(); + ErrCode ret1 = ans_->AddDoNotDisturbProfiles(profiles); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: AddDoNotDisturbProfiles_0200 + * @tc.desc: test AddDoNotDisturbProfiles ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, AddDoNotDisturbProfiles_0200, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + ErrCode ret1 = ans_->AddDoNotDisturbProfiles(profiles); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: RemoveDoNotDisturbProfiles_0100 + * @tc.desc: test RemoveDoNotDisturbProfiles ErrCode ERR_ANS_INVALID_PARAM. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, RemoveDoNotDisturbProfiles_0100, TestSize.Level1) +{ + vector> profiles; + profiles.clear(); + ErrCode ret1 = ans_->RemoveDoNotDisturbProfiles(profiles); + EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); +} + +/* + * @tc.name: RemoveDoNotDisturbProfiles_0200 + * @tc.desc: test RemoveDoNotDisturbProfiles ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, RemoveDoNotDisturbProfiles_0200, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool res = ans_->GetAnsManagerProxy(); + EXPECT_EQ(res, false); + + int32_t id = 1; + std::string name = "Name"; + std::vector trustlist; + std::vector> profiles; + sptr disturbProfile = + new (std::nothrow) NotificationDoNotDisturbProfile(id, name, trustlist); + profiles.emplace_back(disturbProfile); + + ErrCode ret1 = ans_->RemoveDoNotDisturbProfiles(profiles); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +/* + * @tc.name: RegisterSwingCallback_0100 + * @tc.desc: test RegisterSwingCallback with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, RegisterSwingCallback_0100, TestSize.Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool ret = ans_->GetAnsManagerProxy(); + EXPECT_EQ(ret, false); + std::function swingCbFunc = + std::bind(&AnsNotificationUnitTest::UpdateStatuts, this, std::placeholders::_1, std::placeholders::_2); + ErrCode res = ans_->RegisterSwingCallback(swingCbFunc); + EXPECT_EQ(res, ERR_ANS_SERVICE_NOT_CONNECTED); +} +#endif + +/* + * @tc.name: IsNeedSilentInDoNotDisturbMode_0100 + * @tc.desc: test IsNeedSilentInDoNotDisturbMode. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, IsNeedSilentInDoNotDisturbMode_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::string phoneNumber = "11111111111"; + int32_t callerType = 0; + ErrCode ret = ans_->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/test/unittest/reminder_helper_test.cpp b/frameworks/reminder/test/reminder_helper_test.cpp similarity index 96% rename from frameworks/ans/test/unittest/reminder_helper_test.cpp rename to frameworks/reminder/test/reminder_helper_test.cpp index a97c0ed63..02f8be502 100644 --- a/frameworks/ans/test/unittest/reminder_helper_test.cpp +++ b/frameworks/reminder/test/reminder_helper_test.cpp @@ -1,165 +1,165 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#define private public -#define protected public -#include "reminder_request.h" -#undef private -#undef protected - -#include "ans_inner_errors.h" -#include "reminder_helper.h" - -using namespace testing::ext; -namespace OHOS { -namespace Notification { -class ReminderHelperTest : public testing::Test { -public: - static void SetUpTestCase() {} - static void TearDownTestCase() {} - void SetUp() {} - void TearDown() {} -}; - -/** - * @tc.name: PublishReminder_00001 - * @tc.desc: Test PublishReminder parameters. - * @tc.type: FUNC - * @tc.require: issueI5WRQ2 - */ -HWTEST_F(ReminderHelperTest, PublishReminder_00001, Function | SmallTest | Level1) -{ - ReminderRequest reminder; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.PublishReminder(reminder); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); -} - -/** - * @tc.name: CancelReminder_00001 - * @tc.desc: Test CancelReminder parameters. - * @tc.type: FUNC - * @tc.require: issueI5WRQ2 - */ -HWTEST_F(ReminderHelperTest, CancelReminder_00001, Function | SmallTest | Level1) -{ - int32_t reminderId = 10; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.CancelReminder(reminderId); - EXPECT_NE(ret, (int)ERR_OK); -} - -/** - * @tc.name: CancelAllReminders_00001 - * @tc.desc: Test CancelAllReminders parameters. - * @tc.type: FUNC - * @tc.require: issueI5WRQ2 - */ -HWTEST_F(ReminderHelperTest, CancelAllReminders_00001, Function | SmallTest | Level1) -{ - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.CancelAllReminders(); - EXPECT_NE(ret, (int)ERR_OK); -} - -/** - * @tc.name: GetValidReminders_00001 - * @tc.desc: Test GetValidReminders parameters. - * @tc.type: FUNC - * @tc.require: issueI5WRQ2 - */ -HWTEST_F(ReminderHelperTest, GetValidReminders_00001, Function | SmallTest | Level1) -{ - std::vector> validReminders; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.GetValidReminders(validReminders); - EXPECT_NE(ret, (int)ERR_OK); -} - -/** - * @tc.name: AddNotificationSlot_00001 - * @tc.desc: Test AddNotificationSlot parameters. - * @tc.type: FUNC - * @tc.require: issueI5WRQ2 - */ -HWTEST_F(ReminderHelperTest, AddNotificationSlot_00001, Function | SmallTest | Level1) -{ - NotificationSlot slot; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.AddNotificationSlot(slot); - EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); -} - -/** - * @tc.name: RemoveNotificationSlot_00001 - * @tc.desc: Test RemoveNotificationSlot parameters. - * @tc.type: FUNC - * @tc.require: issueI5WRQ2 - */ -HWTEST_F(ReminderHelperTest, RemoveNotificationSlot_00001, Function | SmallTest | Level1) -{ - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.RemoveNotificationSlot(slotType); - EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); -} - -/** - * @tc.name: AddExcludeDate_00001 - * @tc.desc: Test AddExcludeDate parameters. - * @tc.type: FUNC - * @tc.require: issue#I9F24R - */ -HWTEST_F(ReminderHelperTest, AddExcludeDate_00001, Function | SmallTest | Level1) -{ - int32_t reminderId = 1; - uint64_t date = 1713196800000; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.AddExcludeDate(reminderId, date); - EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); -} - -/** - * @tc.name: DelExcludeDates_00001 - * @tc.desc: Test DelExcludeDates parameters. - * @tc.type: FUNC - * @tc.require: issue#I9F24R - */ -HWTEST_F(ReminderHelperTest, DelExcludeDates_00001, Function | SmallTest | Level1) -{ - int32_t reminderId = 1; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.DelExcludeDates(reminderId); - EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); -} - -/** - * @tc.name: GetExcludeDates_00001 - * @tc.desc: Test GetExcludeDates parameters. - * @tc.type: FUNC - * @tc.require: issue#I9F24R - */ -HWTEST_F(ReminderHelperTest, GetExcludeDates_00001, Function | SmallTest | Level1) -{ - int32_t reminderId = 1; - std::vector dates; - ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.GetExcludeDates(reminderId, dates); - EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); -} -} -} +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "reminder_request.h" +#undef private +#undef protected + +#include "ans_inner_errors.h" +#include "reminder_helper.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class ReminderHelperTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: PublishReminder_00001 + * @tc.desc: Test PublishReminder parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, PublishReminder_00001, Function | SmallTest | Level1) +{ + ReminderRequest reminder; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.PublishReminder(reminder); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: CancelReminder_00001 + * @tc.desc: Test CancelReminder parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, CancelReminder_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 10; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.CancelReminder(reminderId); + EXPECT_NE(ret, (int)ERR_OK); +} + +/** + * @tc.name: CancelAllReminders_00001 + * @tc.desc: Test CancelAllReminders parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, CancelAllReminders_00001, Function | SmallTest | Level1) +{ + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.CancelAllReminders(); + EXPECT_NE(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetValidReminders_00001 + * @tc.desc: Test GetValidReminders parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, GetValidReminders_00001, Function | SmallTest | Level1) +{ + std::vector> validReminders; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.GetValidReminders(validReminders); + EXPECT_NE(ret, (int)ERR_OK); +} + +/** + * @tc.name: AddNotificationSlot_00001 + * @tc.desc: Test AddNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, AddNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationSlot slot; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.AddNotificationSlot(slot); + EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveNotificationSlot_00001 + * @tc.desc: Test RemoveNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, RemoveNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.RemoveNotificationSlot(slotType); + EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: AddExcludeDate_00001 + * @tc.desc: Test AddExcludeDate parameters. + * @tc.type: FUNC + * @tc.require: issue#I9F24R + */ +HWTEST_F(ReminderHelperTest, AddExcludeDate_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 1; + uint64_t date = 1713196800000; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.AddExcludeDate(reminderId, date); + EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: DelExcludeDates_00001 + * @tc.desc: Test DelExcludeDates parameters. + * @tc.type: FUNC + * @tc.require: issue#I9F24R + */ +HWTEST_F(ReminderHelperTest, DelExcludeDates_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 1; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.DelExcludeDates(reminderId); + EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetExcludeDates_00001 + * @tc.desc: Test GetExcludeDates parameters. + * @tc.type: FUNC + * @tc.require: issue#I9F24R + */ +HWTEST_F(ReminderHelperTest, GetExcludeDates_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 1; + std::vector dates; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.GetExcludeDates(reminderId, dates); + EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); +} +} +} diff --git a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp b/frameworks/reminder/test/reminder_request_alarm_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_alarm_test.cpp rename to frameworks/reminder/test/reminder_request_alarm_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp b/frameworks/reminder/test/reminder_request_branch_test/mock_reminder_request.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp rename to frameworks/reminder/test/reminder_request_branch_test/mock_reminder_request.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp b/frameworks/reminder/test/reminder_request_branch_test/reminder_request_branch_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp rename to frameworks/reminder/test/reminder_request_branch_test/reminder_request_branch_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/reminder/test/reminder_request_calendar_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_calendar_test.cpp rename to frameworks/reminder/test/reminder_request_calendar_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/reminder/test/reminder_request_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_test.cpp rename to frameworks/reminder/test/reminder_request_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_timer_test.cpp b/frameworks/reminder/test/reminder_request_timer_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_timer_test.cpp rename to frameworks/reminder/test/reminder_request_timer_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_store_test.cpp b/frameworks/reminder/test/reminder_store_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_store_test.cpp rename to frameworks/reminder/test/reminder_store_test.cpp -- Gitee From 108f5705996c9abb8c622bea9a0ecfaf290fdc59 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 7 Nov 2024 09:39:58 +0800 Subject: [PATCH 5/5] update Signed-off-by: gaojiaqi --- .../include/reminder_config_change_observer.h | 0 .../include/reminder_data_manager.h | 0 .../include/reminder_event_manager.h | 0 .../include/reminder_store.h | 0 .../include/reminder_table.h | 0 .../include/reminder_table_old.h | 0 .../include/reminder_timer_info.h | 0 .../src/reminder_config_change_observer.cpp | 0 .../src/reminder_data_manager.cpp | 0 .../src/reminder_data_manager_inner.cpp | 0 .../src/reminder_event_manager.cpp | 0 .../{ans => reminder}/src/reminder_store.cpp | 0 .../src/reminder_store_strategy.cpp | 0 .../{ans => reminder}/src/reminder_table.cpp | 0 .../src/reminder_table_old.cpp | 0 .../src/reminder_timer_info.cpp | 0 .../test}/reminder_data_manager_test.cpp | 1788 ++++++++--------- 17 files changed, 894 insertions(+), 894 deletions(-) rename services/{ans => reminder}/include/reminder_config_change_observer.h (100%) rename services/{ans => reminder}/include/reminder_data_manager.h (100%) rename services/{ans => reminder}/include/reminder_event_manager.h (100%) rename services/{ans => reminder}/include/reminder_store.h (100%) rename services/{ans => reminder}/include/reminder_table.h (100%) rename services/{ans => reminder}/include/reminder_table_old.h (100%) rename services/{ans => reminder}/include/reminder_timer_info.h (100%) rename services/{ans => reminder}/src/reminder_config_change_observer.cpp (100%) rename services/{ans => reminder}/src/reminder_data_manager.cpp (100%) rename services/{ans => reminder}/src/reminder_data_manager_inner.cpp (100%) rename services/{ans => reminder}/src/reminder_event_manager.cpp (100%) rename services/{ans => reminder}/src/reminder_store.cpp (100%) rename services/{ans => reminder}/src/reminder_store_strategy.cpp (100%) rename services/{ans => reminder}/src/reminder_table.cpp (100%) rename services/{ans => reminder}/src/reminder_table_old.cpp (100%) rename services/{ans => reminder}/src/reminder_timer_info.cpp (100%) rename services/{ans/test/unittest => reminder/test}/reminder_data_manager_test.cpp (97%) diff --git a/services/ans/include/reminder_config_change_observer.h b/services/reminder/include/reminder_config_change_observer.h similarity index 100% rename from services/ans/include/reminder_config_change_observer.h rename to services/reminder/include/reminder_config_change_observer.h diff --git a/services/ans/include/reminder_data_manager.h b/services/reminder/include/reminder_data_manager.h similarity index 100% rename from services/ans/include/reminder_data_manager.h rename to services/reminder/include/reminder_data_manager.h diff --git a/services/ans/include/reminder_event_manager.h b/services/reminder/include/reminder_event_manager.h similarity index 100% rename from services/ans/include/reminder_event_manager.h rename to services/reminder/include/reminder_event_manager.h diff --git a/services/ans/include/reminder_store.h b/services/reminder/include/reminder_store.h similarity index 100% rename from services/ans/include/reminder_store.h rename to services/reminder/include/reminder_store.h diff --git a/services/ans/include/reminder_table.h b/services/reminder/include/reminder_table.h similarity index 100% rename from services/ans/include/reminder_table.h rename to services/reminder/include/reminder_table.h diff --git a/services/ans/include/reminder_table_old.h b/services/reminder/include/reminder_table_old.h similarity index 100% rename from services/ans/include/reminder_table_old.h rename to services/reminder/include/reminder_table_old.h diff --git a/services/ans/include/reminder_timer_info.h b/services/reminder/include/reminder_timer_info.h similarity index 100% rename from services/ans/include/reminder_timer_info.h rename to services/reminder/include/reminder_timer_info.h diff --git a/services/ans/src/reminder_config_change_observer.cpp b/services/reminder/src/reminder_config_change_observer.cpp similarity index 100% rename from services/ans/src/reminder_config_change_observer.cpp rename to services/reminder/src/reminder_config_change_observer.cpp diff --git a/services/ans/src/reminder_data_manager.cpp b/services/reminder/src/reminder_data_manager.cpp similarity index 100% rename from services/ans/src/reminder_data_manager.cpp rename to services/reminder/src/reminder_data_manager.cpp diff --git a/services/ans/src/reminder_data_manager_inner.cpp b/services/reminder/src/reminder_data_manager_inner.cpp similarity index 100% rename from services/ans/src/reminder_data_manager_inner.cpp rename to services/reminder/src/reminder_data_manager_inner.cpp diff --git a/services/ans/src/reminder_event_manager.cpp b/services/reminder/src/reminder_event_manager.cpp similarity index 100% rename from services/ans/src/reminder_event_manager.cpp rename to services/reminder/src/reminder_event_manager.cpp diff --git a/services/ans/src/reminder_store.cpp b/services/reminder/src/reminder_store.cpp similarity index 100% rename from services/ans/src/reminder_store.cpp rename to services/reminder/src/reminder_store.cpp diff --git a/services/ans/src/reminder_store_strategy.cpp b/services/reminder/src/reminder_store_strategy.cpp similarity index 100% rename from services/ans/src/reminder_store_strategy.cpp rename to services/reminder/src/reminder_store_strategy.cpp diff --git a/services/ans/src/reminder_table.cpp b/services/reminder/src/reminder_table.cpp similarity index 100% rename from services/ans/src/reminder_table.cpp rename to services/reminder/src/reminder_table.cpp diff --git a/services/ans/src/reminder_table_old.cpp b/services/reminder/src/reminder_table_old.cpp similarity index 100% rename from services/ans/src/reminder_table_old.cpp rename to services/reminder/src/reminder_table_old.cpp diff --git a/services/ans/src/reminder_timer_info.cpp b/services/reminder/src/reminder_timer_info.cpp similarity index 100% rename from services/ans/src/reminder_timer_info.cpp rename to services/reminder/src/reminder_timer_info.cpp diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/reminder/test/reminder_data_manager_test.cpp similarity index 97% rename from services/ans/test/unittest/reminder_data_manager_test.cpp rename to services/reminder/test/reminder_data_manager_test.cpp index 852875a4f..5e065f698 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/reminder/test/reminder_data_manager_test.cpp @@ -1,894 +1,894 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#define private public -#define protected public -#include "common_event_data.h" -#include "common_event_manager.h" -#include "common_event_support.h" -#include "matching_skills.h" -#include "reminder_data_manager.h" -#include "reminder_event_manager.h" -#include "reminder_request_timer.h" -#include "reminder_request_alarm.h" -#include "reminder_request.h" -#include "reminder_request_calendar.h" -#include "ability_manager_client.h" -#include "mock_ipc_skeleton.h" -#undef private -#undef protected - -using namespace testing::ext; -using namespace OHOS::EventFwk; -namespace OHOS { -namespace Notification { -class ReminderDataManagerTest : public testing::Test { -public: - static void SetUpTestCase() - { - ReminderDataManager::InitInstance(nullptr); - manager = ReminderDataManager::GetInstance(); - manager->Init(false); - } - static void TearDownTestCase() - { - manager = nullptr; - } - void SetUp() {}; - void TearDown() {}; - -public: - static std::shared_ptr manager; -}; - -std::shared_ptr ReminderDataManagerTest::manager = nullptr; - -/** - * @tc.name: ReminderDataManagerTest_001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_001, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - sptr option = new NotificationBundleOption(); - manager->PublishReminder(reminder, option); - manager->CancelReminder(-1, option); - manager->CancelAllReminders("", -1, -1); - manager->CancelAllReminders(-1); - manager->IsMatched(reminder, "", -1, -1); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_002 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_002, Level1) -{ - sptr option = new NotificationBundleOption(); - std::vector> vec; - manager->GetValidReminders(option, vec); - sptr reminder = new ReminderRequestTimer(10); - manager->CheckReminderLimitExceededLocked(option, reminder); - manager->CancelNotification(reminder); - reminder->SetReminderId(10); - manager->AddToShowedReminders(reminder); - manager->AddToShowedReminders(reminder); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_003 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_003, Level1) -{ - manager->isReminderAgentReady_ = false; - manager->alertingReminderId_ = -1; - manager->OnUserSwitch(0); - manager->OnUserRemove(0); - manager->alertingReminderId_ = 1; - manager->OnUserSwitch(0); - manager->isReminderAgentReady_ = true; - manager->OnUserSwitch(0); - manager->alertingReminderId_ = -1; - manager->OnUserSwitch(0); - manager->OnUserRemove(0); - manager->OnBundleMgrServiceStart(); - manager->OnAbilityMgrServiceStart(); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_004 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_004, Level1) -{ - sptr option = new NotificationBundleOption(); - manager->OnProcessDiedLocked(option); - sptr reminder = new ReminderRequestTimer(10); - manager->CreateTimerInfo(ReminderDataManager::TimerType::TRIGGER_TIMER, reminder); - manager->CreateTimerInfo(ReminderDataManager::TimerType::ALERTING_TIMER, reminder); - manager->FindReminderRequestLocked(0, ""); - reminder->SetReminderId(10); - manager->reminderVector_.push_back(reminder); - manager->FindReminderRequestLocked(10, ""); - option->SetBundleName("test"); - manager->FindReminderRequestLocked(10, ""); - manager->FindReminderRequestLocked(10, "test"); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_005 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_005, Level1) -{ - EventFwk::Want want; - manager->CloseReminder(want, true); - sptr reminder = new ReminderRequestTimer(10); - reminder->SetReminderId(1); - manager->activeReminderId_ = 1; - manager->activeReminder_ = reminder; - manager->CloseReminder(reminder, true); - reminder->SetReminderId(2); - manager->alertingReminderId_ = 2; - manager->CloseReminder(reminder, true); - reminder->SetReminderId(3); - manager->CloseReminder(reminder, true); - manager->CloseReminder(reminder, false); - reminder->SetReminderId(4); - reminder->SetGroupId(""); - manager->CloseReminder(reminder, true); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_006 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_006, Level1) -{ - manager->RefreshRemindersDueToSysTimeChange(0); - manager->RefreshRemindersDueToSysTimeChange(1); - manager->activeReminderId_ = 1; - sptr reminder = new ReminderRequestTimer(10); - manager->activeReminder_ = reminder; - manager->RefreshRemindersDueToSysTimeChange(1); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_007 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_007, Level1) -{ - EventFwk::Want want; - want.SetParam(ReminderRequest::PARAM_REMINDER_ID, 10); - manager->ShowActiveReminder(want); - manager->CloseReminder(want, true); - sptr reminder = new ReminderRequestTimer(10); - reminder->SetReminderId(10); - manager->reminderVector_.push_back(reminder); - manager->ShowActiveReminder(want); - manager->activeReminderId_ = 10; - manager->activeReminder_ = reminder; - manager->ShowActiveReminder(want); - manager->CloseReminder(want, true); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_008 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_008, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - manager->TerminateAlerting(0, reminder); - manager->TerminateAlerting(nullptr, ""); - manager->TerminateAlerting(reminder, ""); - reminder->state_ = 2; - manager->TerminateAlerting(reminder, ""); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_009 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_009, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - sptr option = new NotificationBundleOption(); - manager->UpdateAndSaveReminderLocked(reminder, option); - sptr service(new AdvancedNotificationService); - manager->SetService(service); - manager->ShouldAlert(nullptr); - manager->currentUserId_ = 0; - option->SetUid(1); - manager->ShouldAlert(reminder); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_010 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_010, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - manager->HandleSysTimeChange(reminder); - manager->SetActiveReminder(nullptr); - manager->SetActiveReminder(reminder); - manager->SetAlertingReminder(nullptr); - manager->SetAlertingReminder(reminder); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_011 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_011, Level1) -{ - sptr reminder(new ReminderRequestTimer(10)); - reminder->SetReminderId(0); - sptr option(new NotificationBundleOption()); - manager->ShowReminder(reminder, true, true, true, true); - reminder->SetNotificationBundleOption(option); - reminder->SetReminderId(10); - manager->ShowReminder(reminder, true, true, true, true); - manager->ShowReminder(reminder, true, true, true, true); - manager->alertingReminderId_ = 1; - manager->ShowReminder(reminder, true, true, true, true); - manager->alertingReminderId_ = -1; - manager->ShowReminder(reminder, true, true, true, true); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_012 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_012, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - manager->activeReminderId_ = 10; - manager->activeReminder_ = reminder; - reminder->SetReminderId(10); - manager->activeReminderId_ = 1; - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_013 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_013, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - manager->activeReminderId_ = 10; - manager->activeReminder_ = reminder; - reminder->SetReminderId(10); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_014 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_014, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - reminder->SetReminderId(0); - manager->StartRecentReminder(); - manager->StopAlertingReminder(nullptr); - manager->alertingReminderId_ = -1; - manager->StopAlertingReminder(reminder); - manager->alertingReminderId_ = 1; - manager->StopAlertingReminder(reminder); - reminder->SetReminderId(1); - manager->StopAlertingReminder(reminder); - manager->Dump(); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_015 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_015, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - std::vector> vec; - vec.push_back(reminder); - manager->HandleImmediatelyShow(vec, true); - manager->HandleRefreshReminder(0, reminder); - manager->HandleSameNotificationIdShowing(reminder); - manager->Init(true); - manager->InitUserId(); - manager->GetImmediatelyShowRemindersLocked(vec); - manager->IsAllowedNotify(reminder); - manager->IsAllowedNotify(nullptr); - manager->IsReminderAgentReady(); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderDataManagerTest_016 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issuesI8CAQB - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_016, Level1) -{ - // not SystemApp - std::vector daysOfWeek; - sptr reminder = new ReminderRequestAlarm(0, 1, daysOfWeek); - std::shared_ptr buttonWantAgent = - std::make_shared(); - std::shared_ptr buttonDataShareUpdate = - std::make_shared(); - reminder->SetSystemApp(false); - reminder->SetActionButton("不再提醒", ReminderRequest::ActionButtonType::CLOSE, - "", buttonWantAgent, buttonDataShareUpdate); - manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::CLOSE); - - // INVALID ActionButtonType - reminder->SetSystemApp(true); - reminder->SetActionButton("无效的", ReminderRequest::ActionButtonType::INVALID, - "", buttonWantAgent, buttonDataShareUpdate); - manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::INVALID); - - // actionButtonType does not exist - std::map actionButtonMap; - manager->CheckUpdateConditions(reminder, ReminderRequest::ActionButtonType::CLOSE, actionButtonMap); - - // null ButtonDataShareUpdate - reminder->SetActionButton("稍后提醒", ReminderRequest::ActionButtonType::SNOOZE, "", buttonWantAgent); - manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::SNOOZE); - - // not have uri - manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::CLOSE); - - // update datashare - sptr reminder1 = new ReminderRequestAlarm(2, 3, daysOfWeek); - std::shared_ptr buttonWantAgent1 = - std::make_shared(); - std::shared_ptr buttonDataShareUpdate1 = - std::make_shared(); - reminder1->SetSystemApp(true); - reminder1->SetUserId(100); - buttonDataShareUpdate1->uri = "datashareTest://com.acts.dataShareTest"; - buttonDataShareUpdate1->equalTo = "namestringli" - "iddouble3.0statusbooltrue"; - buttonDataShareUpdate1->valuesBucket = "namestringwang" - "iddouble4.0statusbooltrueactionIdnullnull"; - reminder1->SetActionButton("不再提醒", ReminderRequest::ActionButtonType::CLOSE, "", - buttonWantAgent1, buttonDataShareUpdate1); - manager->UpdateAppDatabase(reminder1, ReminderRequest::ActionButtonType::CLOSE); - EXPECT_TRUE(reminder1->actionButtonMap_.size() > 0); -} - -/** - * @tc.name: ReminderDataManagerTest_017 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI8CDH3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_017, Level1) -{ - IPCSkeleton::SetCallingTokenID(1); - sptr reminder1 = new ReminderRequestTimer(10); - sptr reminder2 = new ReminderRequestTimer(10); - sptr reminder3 = new ReminderRequestTimer(10); - int32_t oldReminderId = 1; - reminder1->SetReminderId(1); - reminder2->SetReminderId(2); - reminder3->SetReminderId(3); - reminder1->SetGroupId("123"); - reminder2->SetGroupId("123"); - reminder3->SetGroupId("124"); - sptr option1 = new NotificationBundleOption(); - sptr option2 = new NotificationBundleOption(); - sptr option3 = new NotificationBundleOption(); - option1->SetBundleName("test"); - option2->SetBundleName("test"); - manager->PublishReminder(reminder1, option1); - manager->PublishReminder(reminder2, option2); - manager->PublishReminder(reminder3, option3); - manager->CloseRemindersByGroupId(oldReminderId, "test", "123"); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(reminder2->isExpired_); -} - -/** - * @tc.name: ReminderDataManagerTest_018 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI8E7Z1 - */ -HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_018, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - std::string ringUri = "123"; - reminder->SetCustomRingUri(ringUri); - std::string getRingUri = manager->GetCustomRingUri(reminder); - ASSERT_EQ(ringUri, getRingUri); -} - -/** - * @tc.name: ReminderEventManagerTest_001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_001, Level1) -{ - MatchingSkills matchingSkills; - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIME_CHANGED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); - CommonEventSubscribeInfo subscriberInfo(matchingSkills); - auto subscriber = std::make_shared(subscriberInfo, manager); - EventFwk::CommonEventData data; - Want want; - want.SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_TIME_CHANGED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - want.SetAction(CommonEventSupport::COMMON_EVENT_USER_REMOVED); - data.SetWant(want); - subscriber->OnReceiveEvent(data); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderEventManagerTest_002 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_002, Level1) -{ - auto statusChangeListener - = std::make_shared(manager); - statusChangeListener->OnAddSystemAbility(0, ""); - statusChangeListener->OnRemoveSystemAbility(0, ""); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderEventManagerTest_003 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_003, Level1) -{ - auto timeInfo = std::make_shared(); - timeInfo->SetType(0); - timeInfo->SetRepeat(false); - timeInfo->SetInterval(0); - timeInfo->SetWantAgent(nullptr); - timeInfo->action_ = ReminderRequest::REMINDER_EVENT_ALARM_ALERT; - timeInfo->OnTrigger(); - timeInfo->action_ = ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT; - timeInfo->OnTrigger(); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: ReminderEventManagerTest_004 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI5YTF3 - */ -HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_004, Level1) -{ - EventFwk::Want want; - manager->HandleCustomButtonClick(want); - sptr reminder = new ReminderRequestTimer(10); - manager->reminderVector_.push_back(reminder); - want.SetParam(ReminderRequest::PARAM_REMINDER_ID, 10); - manager->HandleCustomButtonClick(want); - system("rm -rf /data/service/el1/public/notification/"); - EXPECT_TRUE(manager != nullptr); -} - -/** - * @tc.name: StartExtensionAbilityTest_001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issueI92G9T - */ -HWTEST_F(ReminderDataManagerTest, StartExtensionAbilityTest_001, Level1) -{ - auto reminder1 = new ReminderRequestCalendar(10); - bool ret1 = manager->StartExtensionAbility(reminder1); - EXPECT_TRUE(ret1); - - auto reminder2 = new ReminderRequestCalendar(10); - auto wantInfo = std::make_shared(); - reminder2->SetRRuleWantAgentInfo(wantInfo); - bool ret2 = manager->StartExtensionAbility(reminder2); - EXPECT_TRUE(ret2); -} - -/** - * @tc.name: IsBelongToSameAppTest_001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I97Q9Q - */ -HWTEST_F(ReminderDataManagerTest, IsBelongToSameAppTest_001, Level1) -{ - sptr option1 = new NotificationBundleOption("test", 100); - sptr option2 = new NotificationBundleOption("test", 100); - EXPECT_TRUE(manager->IsBelongToSameApp(option1, option2)); - - option2->SetUid(101); - EXPECT_FALSE(manager->IsBelongToSameApp(option1, option2)); - - option2->SetUid(100); - option2->SetBundleName("test1"); - EXPECT_FALSE(manager->IsBelongToSameApp(option1, option2)); -} - -/** - * @tc.name: CheckIsSameAppTest_001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I97Q9Q - */ -HWTEST_F(ReminderDataManagerTest, CheckIsSameAppTest_001, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - reminder->SetCreatorBundleName("test"); - reminder->SetUserId(-1); - sptr option = new NotificationBundleOption("test", -1); - EXPECT_TRUE(manager->CheckIsSameApp(reminder, option)); - - reminder->SetCreatorBundleName("test1"); - EXPECT_FALSE(manager->CheckIsSameApp(reminder, option)); -} - -/** - * @tc.name: CheckPulishReminder - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I97Q9Q - */ -HWTEST_F(ReminderDataManagerTest, CheckPulishReminder_0001, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - sptr option = new NotificationBundleOption(); - IPCSkeleton::SetCallingTokenID(0); - ErrCode ret = manager->PublishReminder(reminder, option); - ASSERT_EQ(ret, ERR_REMINDER_CALLER_TOKEN_INVALID); - - IPCSkeleton::SetCallingTokenID(1); - ret = manager->PublishReminder(reminder, option); - EXPECT_NE(ret, ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED); -} - -/** - * @tc.name: OnLanguageChanged - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I97Q9Q - */ -HWTEST_F(ReminderDataManagerTest, OnLanguageChanged_0001, Level1) -{ - sptr reminder = new ReminderRequestTimer(10); - reminder->SetReminderId(10); - std::string title = "this is title"; - std::string resource = "close"; - ReminderRequest::ActionButtonType type = ReminderRequest::ActionButtonType::CLOSE; - reminder->SetActionButton(title, type, resource); - - manager->reminderVector_.push_back(reminder); - manager->showedReminderVector_.push_back(reminder); - - manager->OnLanguageChanged(); - EXPECT_TRUE(reminder->actionButtonMap_[type].title == "this is title"); -} - -/** - * @tc.name: ExcludeDate - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I97Q9Q - */ -HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) -{ - std::vector dates; - auto result = manager->CheckExcludeDateParam(9999, nullptr); - EXPECT_TRUE(result == nullptr); - - auto ret = manager->AddExcludeDate(9999, 100, nullptr); - EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); - - ret = manager->DelExcludeDates(9999, nullptr); - EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); - - ret = manager->GetExcludeDates(9999, nullptr, dates); - EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); - - sptr reminder = new ReminderRequestCalendar(10); - reminder->SetCreatorBundleName("test1"); - reminder->SetUserId(-1); - reminder->reminderId_ = 100; - manager->reminderVector_.push_back(reminder); - sptr option = new NotificationBundleOption("test", -1); - result = manager->CheckExcludeDateParam(100, option); - EXPECT_TRUE(result == nullptr); - - reminder->SetCreatorBundleName("test"); - reminder->reminderType_ = ReminderRequest::ReminderType::TIMER; - result = manager->CheckExcludeDateParam(100, option); - EXPECT_TRUE(result == nullptr); - - reminder->reminderType_ = ReminderRequest::ReminderType::CALENDAR; - result = manager->CheckExcludeDateParam(100, option); - EXPECT_TRUE(result == nullptr); - - reminder->repeatDaysOfWeek_ = 1; - result = manager->CheckExcludeDateParam(100, option); - EXPECT_TRUE(result != nullptr); - - ret = manager->AddExcludeDate(100, 100, option); - EXPECT_TRUE(ret == ERR_OK); - - ret = manager->DelExcludeDates(100, option); - EXPECT_TRUE(ret == ERR_OK); - - ret = manager->GetExcludeDates(100, option, dates); - EXPECT_TRUE(ret == ERR_OK); -} - -/** - * @tc.name: InitStartExtensionAbility - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I9IIDE - */ -HWTEST_F(ReminderDataManagerTest, InitStartExtensionAbility_0001, Level1) -{ - sptr reminder = new ReminderRequestCalendar(10); - reminder->reminderType_ = ReminderRequest::ReminderType::CALENDAR; - ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - uint64_t now = calendar->GetNowInstantMilli(); - calendar->SetDateTime(now-50000); - calendar->SetEndDateTime(now+50000); - manager->reminderVector_.push_back(calendar); - manager->Init(true); - EXPECT_TRUE(!manager->reminderVector_.empty()); -} - -/** - * @tc.name: ReminderNotificationSubscriber_00001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I9IIDE - */ -HWTEST_F(ReminderDataManagerTest, ReminderNotificationSubscriber_00001, Level1) -{ - ReminderEventManager::ReminderNotificationSubscriber test(manager); - sptr notificationReq = new NotificationRequest(); - std::shared_ptr notification = std::make_shared(notificationReq); - test.OnCanceled(notification, nullptr, NotificationConstant::CANCEL_REASON_DELETE); - SUCCEED(); - - test.OnCanceled(nullptr, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel(""); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("TEST_1"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("TEST_NOTIFICATION_1"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("REMINDER_NOTIFICATION_1"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("REMINDER_AGENT_INFO"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("REMINDER_AGENT_0"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); -} - -/** - * @tc.name: CancelAllReminders_00001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I9IIDE - */ -HWTEST_F(ReminderDataManagerTest, CancelAllReminders_00001, Level1) -{ - int32_t ret = manager->CancelAllReminders("", -1, -1); - EXPECT_TRUE(ret == ERR_OK); - - ret = manager->CancelAllReminders("com.example.simple", 100, 20020152); - EXPECT_TRUE(ret == ERR_OK); -} - -/** - * @tc.name: GetVaildReminders_00001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I9IIDE - */ -HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) -{ - sptr reminder1 = new ReminderRequestTimer(static_cast(50)); - reminder1->SetCreatorBundleName("test_getvalid"); - reminder1->SetCreatorUid(98765); - reminder1->SetBundleName("test_getvalid"); - reminder1->SetUid(98765); - sptr option1 = new NotificationBundleOption("test_getvalid", 98765); - manager->PublishReminder(reminder1, option1); - reminder1->SetExpired(false); - - sptr reminder2 = new ReminderRequestTimer(51); - reminder2->SetCreatorBundleName("test_getvalid"); - reminder2->SetCreatorUid(98765); - reminder2->SetBundleName("test_getvalid"); - reminder2->SetUid(98765); - reminder2->SetExpired(true); - sptr option2 = new NotificationBundleOption("test_getvalid", 98765); - manager->PublishReminder(reminder2, option2); - - std::vector> reminders; - manager->GetValidReminders(option2, reminders); - EXPECT_TRUE(reminders.size() == 1); -} - -/** - * @tc.name: IsMatched_00001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I9IIDE - */ -HWTEST_F(ReminderDataManagerTest, IsMatched_00001, Level1) -{ - sptr reminder = new ReminderRequestTimer(50); - reminder->SetCreatorBundleName("test_IsMatched"); - reminder->SetCreatorUid(98765); - reminder->SetBundleName("test_IsMatched"); - reminder->SetUid(98765); - reminder->SetUserId(100); - bool ret = manager->IsMatched(reminder, "test_IsMatched", 101, 98765); - EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "allPackages", 100, 98765); - EXPECT_EQ(ret, true); - ret = manager->IsMatched(reminder, "test_IsMatched2", 100, 98765); - EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "test_IsMatched", 100, -1); - EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "test_IsMatched", 100, 98766); - EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "test_IsMatched", 100, 98765); - EXPECT_EQ(ret, true); -} -} // namespace Notification -} // namespace OHOS +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#define private public +#define protected public +#include "common_event_data.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "matching_skills.h" +#include "reminder_data_manager.h" +#include "reminder_event_manager.h" +#include "reminder_request_timer.h" +#include "reminder_request_alarm.h" +#include "reminder_request.h" +#include "reminder_request_calendar.h" +#include "ability_manager_client.h" +#include "mock_ipc_skeleton.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS::EventFwk; +namespace OHOS { +namespace Notification { +class ReminderDataManagerTest : public testing::Test { +public: + static void SetUpTestCase() + { + ReminderDataManager::InitInstance(nullptr); + manager = ReminderDataManager::GetInstance(); + manager->Init(false); + } + static void TearDownTestCase() + { + manager = nullptr; + } + void SetUp() {}; + void TearDown() {}; + +public: + static std::shared_ptr manager; +}; + +std::shared_ptr ReminderDataManagerTest::manager = nullptr; + +/** + * @tc.name: ReminderDataManagerTest_001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_001, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + sptr option = new NotificationBundleOption(); + manager->PublishReminder(reminder, option); + manager->CancelReminder(-1, option); + manager->CancelAllReminders("", -1, -1); + manager->CancelAllReminders(-1); + manager->IsMatched(reminder, "", -1, -1); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_002 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_002, Level1) +{ + sptr option = new NotificationBundleOption(); + std::vector> vec; + manager->GetValidReminders(option, vec); + sptr reminder = new ReminderRequestTimer(10); + manager->CheckReminderLimitExceededLocked(option, reminder); + manager->CancelNotification(reminder); + reminder->SetReminderId(10); + manager->AddToShowedReminders(reminder); + manager->AddToShowedReminders(reminder); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_003 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_003, Level1) +{ + manager->isReminderAgentReady_ = false; + manager->alertingReminderId_ = -1; + manager->OnUserSwitch(0); + manager->OnUserRemove(0); + manager->alertingReminderId_ = 1; + manager->OnUserSwitch(0); + manager->isReminderAgentReady_ = true; + manager->OnUserSwitch(0); + manager->alertingReminderId_ = -1; + manager->OnUserSwitch(0); + manager->OnUserRemove(0); + manager->OnBundleMgrServiceStart(); + manager->OnAbilityMgrServiceStart(); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_004 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_004, Level1) +{ + sptr option = new NotificationBundleOption(); + manager->OnProcessDiedLocked(option); + sptr reminder = new ReminderRequestTimer(10); + manager->CreateTimerInfo(ReminderDataManager::TimerType::TRIGGER_TIMER, reminder); + manager->CreateTimerInfo(ReminderDataManager::TimerType::ALERTING_TIMER, reminder); + manager->FindReminderRequestLocked(0, ""); + reminder->SetReminderId(10); + manager->reminderVector_.push_back(reminder); + manager->FindReminderRequestLocked(10, ""); + option->SetBundleName("test"); + manager->FindReminderRequestLocked(10, ""); + manager->FindReminderRequestLocked(10, "test"); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_005 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_005, Level1) +{ + EventFwk::Want want; + manager->CloseReminder(want, true); + sptr reminder = new ReminderRequestTimer(10); + reminder->SetReminderId(1); + manager->activeReminderId_ = 1; + manager->activeReminder_ = reminder; + manager->CloseReminder(reminder, true); + reminder->SetReminderId(2); + manager->alertingReminderId_ = 2; + manager->CloseReminder(reminder, true); + reminder->SetReminderId(3); + manager->CloseReminder(reminder, true); + manager->CloseReminder(reminder, false); + reminder->SetReminderId(4); + reminder->SetGroupId(""); + manager->CloseReminder(reminder, true); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_006 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_006, Level1) +{ + manager->RefreshRemindersDueToSysTimeChange(0); + manager->RefreshRemindersDueToSysTimeChange(1); + manager->activeReminderId_ = 1; + sptr reminder = new ReminderRequestTimer(10); + manager->activeReminder_ = reminder; + manager->RefreshRemindersDueToSysTimeChange(1); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_007 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_007, Level1) +{ + EventFwk::Want want; + want.SetParam(ReminderRequest::PARAM_REMINDER_ID, 10); + manager->ShowActiveReminder(want); + manager->CloseReminder(want, true); + sptr reminder = new ReminderRequestTimer(10); + reminder->SetReminderId(10); + manager->reminderVector_.push_back(reminder); + manager->ShowActiveReminder(want); + manager->activeReminderId_ = 10; + manager->activeReminder_ = reminder; + manager->ShowActiveReminder(want); + manager->CloseReminder(want, true); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_008 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_008, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + manager->TerminateAlerting(0, reminder); + manager->TerminateAlerting(nullptr, ""); + manager->TerminateAlerting(reminder, ""); + reminder->state_ = 2; + manager->TerminateAlerting(reminder, ""); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_009 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_009, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + sptr option = new NotificationBundleOption(); + manager->UpdateAndSaveReminderLocked(reminder, option); + sptr service(new AdvancedNotificationService); + manager->SetService(service); + manager->ShouldAlert(nullptr); + manager->currentUserId_ = 0; + option->SetUid(1); + manager->ShouldAlert(reminder); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_010 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_010, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + manager->HandleSysTimeChange(reminder); + manager->SetActiveReminder(nullptr); + manager->SetActiveReminder(reminder); + manager->SetAlertingReminder(nullptr); + manager->SetAlertingReminder(reminder); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_011 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_011, Level1) +{ + sptr reminder(new ReminderRequestTimer(10)); + reminder->SetReminderId(0); + sptr option(new NotificationBundleOption()); + manager->ShowReminder(reminder, true, true, true, true); + reminder->SetNotificationBundleOption(option); + reminder->SetReminderId(10); + manager->ShowReminder(reminder, true, true, true, true); + manager->ShowReminder(reminder, true, true, true, true); + manager->alertingReminderId_ = 1; + manager->ShowReminder(reminder, true, true, true, true); + manager->alertingReminderId_ = -1; + manager->ShowReminder(reminder, true, true, true, true); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_012 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_012, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + manager->activeReminderId_ = 10; + manager->activeReminder_ = reminder; + reminder->SetReminderId(10); + manager->activeReminderId_ = 1; + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_013 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_013, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + manager->activeReminderId_ = 10; + manager->activeReminder_ = reminder; + reminder->SetReminderId(10); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_014 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_014, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + reminder->SetReminderId(0); + manager->StartRecentReminder(); + manager->StopAlertingReminder(nullptr); + manager->alertingReminderId_ = -1; + manager->StopAlertingReminder(reminder); + manager->alertingReminderId_ = 1; + manager->StopAlertingReminder(reminder); + reminder->SetReminderId(1); + manager->StopAlertingReminder(reminder); + manager->Dump(); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_015 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_015, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + std::vector> vec; + vec.push_back(reminder); + manager->HandleImmediatelyShow(vec, true); + manager->HandleRefreshReminder(0, reminder); + manager->HandleSameNotificationIdShowing(reminder); + manager->Init(true); + manager->InitUserId(); + manager->GetImmediatelyShowRemindersLocked(vec); + manager->IsAllowedNotify(reminder); + manager->IsAllowedNotify(nullptr); + manager->IsReminderAgentReady(); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderDataManagerTest_016 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issuesI8CAQB + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_016, Level1) +{ + // not SystemApp + std::vector daysOfWeek; + sptr reminder = new ReminderRequestAlarm(0, 1, daysOfWeek); + std::shared_ptr buttonWantAgent = + std::make_shared(); + std::shared_ptr buttonDataShareUpdate = + std::make_shared(); + reminder->SetSystemApp(false); + reminder->SetActionButton("不再提醒", ReminderRequest::ActionButtonType::CLOSE, + "", buttonWantAgent, buttonDataShareUpdate); + manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::CLOSE); + + // INVALID ActionButtonType + reminder->SetSystemApp(true); + reminder->SetActionButton("无效的", ReminderRequest::ActionButtonType::INVALID, + "", buttonWantAgent, buttonDataShareUpdate); + manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::INVALID); + + // actionButtonType does not exist + std::map actionButtonMap; + manager->CheckUpdateConditions(reminder, ReminderRequest::ActionButtonType::CLOSE, actionButtonMap); + + // null ButtonDataShareUpdate + reminder->SetActionButton("稍后提醒", ReminderRequest::ActionButtonType::SNOOZE, "", buttonWantAgent); + manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::SNOOZE); + + // not have uri + manager->UpdateAppDatabase(reminder, ReminderRequest::ActionButtonType::CLOSE); + + // update datashare + sptr reminder1 = new ReminderRequestAlarm(2, 3, daysOfWeek); + std::shared_ptr buttonWantAgent1 = + std::make_shared(); + std::shared_ptr buttonDataShareUpdate1 = + std::make_shared(); + reminder1->SetSystemApp(true); + reminder1->SetUserId(100); + buttonDataShareUpdate1->uri = "datashareTest://com.acts.dataShareTest"; + buttonDataShareUpdate1->equalTo = "namestringli" + "iddouble3.0statusbooltrue"; + buttonDataShareUpdate1->valuesBucket = "namestringwang" + "iddouble4.0statusbooltrueactionIdnullnull"; + reminder1->SetActionButton("不再提醒", ReminderRequest::ActionButtonType::CLOSE, "", + buttonWantAgent1, buttonDataShareUpdate1); + manager->UpdateAppDatabase(reminder1, ReminderRequest::ActionButtonType::CLOSE); + EXPECT_TRUE(reminder1->actionButtonMap_.size() > 0); +} + +/** + * @tc.name: ReminderDataManagerTest_017 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI8CDH3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_017, Level1) +{ + IPCSkeleton::SetCallingTokenID(1); + sptr reminder1 = new ReminderRequestTimer(10); + sptr reminder2 = new ReminderRequestTimer(10); + sptr reminder3 = new ReminderRequestTimer(10); + int32_t oldReminderId = 1; + reminder1->SetReminderId(1); + reminder2->SetReminderId(2); + reminder3->SetReminderId(3); + reminder1->SetGroupId("123"); + reminder2->SetGroupId("123"); + reminder3->SetGroupId("124"); + sptr option1 = new NotificationBundleOption(); + sptr option2 = new NotificationBundleOption(); + sptr option3 = new NotificationBundleOption(); + option1->SetBundleName("test"); + option2->SetBundleName("test"); + manager->PublishReminder(reminder1, option1); + manager->PublishReminder(reminder2, option2); + manager->PublishReminder(reminder3, option3); + manager->CloseRemindersByGroupId(oldReminderId, "test", "123"); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(reminder2->isExpired_); +} + +/** + * @tc.name: ReminderDataManagerTest_018 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI8E7Z1 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_018, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + std::string ringUri = "123"; + reminder->SetCustomRingUri(ringUri); + std::string getRingUri = manager->GetCustomRingUri(reminder); + ASSERT_EQ(ringUri, getRingUri); +} + +/** + * @tc.name: ReminderEventManagerTest_001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_001, Level1) +{ + MatchingSkills matchingSkills; + matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); + matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); + matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIME_CHANGED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); + CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto subscriber = std::make_shared(subscriberInfo, manager); + EventFwk::CommonEventData data; + Want want; + want.SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_TIME_CHANGED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + want.SetAction(CommonEventSupport::COMMON_EVENT_USER_REMOVED); + data.SetWant(want); + subscriber->OnReceiveEvent(data); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_002 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_002, Level1) +{ + auto statusChangeListener + = std::make_shared(manager); + statusChangeListener->OnAddSystemAbility(0, ""); + statusChangeListener->OnRemoveSystemAbility(0, ""); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_003 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_003, Level1) +{ + auto timeInfo = std::make_shared(); + timeInfo->SetType(0); + timeInfo->SetRepeat(false); + timeInfo->SetInterval(0); + timeInfo->SetWantAgent(nullptr); + timeInfo->action_ = ReminderRequest::REMINDER_EVENT_ALARM_ALERT; + timeInfo->OnTrigger(); + timeInfo->action_ = ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT; + timeInfo->OnTrigger(); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: ReminderEventManagerTest_004 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI5YTF3 + */ +HWTEST_F(ReminderDataManagerTest, ReminderEventManagerTest_004, Level1) +{ + EventFwk::Want want; + manager->HandleCustomButtonClick(want); + sptr reminder = new ReminderRequestTimer(10); + manager->reminderVector_.push_back(reminder); + want.SetParam(ReminderRequest::PARAM_REMINDER_ID, 10); + manager->HandleCustomButtonClick(want); + system("rm -rf /data/service/el1/public/notification/"); + EXPECT_TRUE(manager != nullptr); +} + +/** + * @tc.name: StartExtensionAbilityTest_001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI92G9T + */ +HWTEST_F(ReminderDataManagerTest, StartExtensionAbilityTest_001, Level1) +{ + auto reminder1 = new ReminderRequestCalendar(10); + bool ret1 = manager->StartExtensionAbility(reminder1); + EXPECT_TRUE(ret1); + + auto reminder2 = new ReminderRequestCalendar(10); + auto wantInfo = std::make_shared(); + reminder2->SetRRuleWantAgentInfo(wantInfo); + bool ret2 = manager->StartExtensionAbility(reminder2); + EXPECT_TRUE(ret2); +} + +/** + * @tc.name: IsBelongToSameAppTest_001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I97Q9Q + */ +HWTEST_F(ReminderDataManagerTest, IsBelongToSameAppTest_001, Level1) +{ + sptr option1 = new NotificationBundleOption("test", 100); + sptr option2 = new NotificationBundleOption("test", 100); + EXPECT_TRUE(manager->IsBelongToSameApp(option1, option2)); + + option2->SetUid(101); + EXPECT_FALSE(manager->IsBelongToSameApp(option1, option2)); + + option2->SetUid(100); + option2->SetBundleName("test1"); + EXPECT_FALSE(manager->IsBelongToSameApp(option1, option2)); +} + +/** + * @tc.name: CheckIsSameAppTest_001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I97Q9Q + */ +HWTEST_F(ReminderDataManagerTest, CheckIsSameAppTest_001, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + reminder->SetCreatorBundleName("test"); + reminder->SetUserId(-1); + sptr option = new NotificationBundleOption("test", -1); + EXPECT_TRUE(manager->CheckIsSameApp(reminder, option)); + + reminder->SetCreatorBundleName("test1"); + EXPECT_FALSE(manager->CheckIsSameApp(reminder, option)); +} + +/** + * @tc.name: CheckPulishReminder + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I97Q9Q + */ +HWTEST_F(ReminderDataManagerTest, CheckPulishReminder_0001, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + sptr option = new NotificationBundleOption(); + IPCSkeleton::SetCallingTokenID(0); + ErrCode ret = manager->PublishReminder(reminder, option); + ASSERT_EQ(ret, ERR_REMINDER_CALLER_TOKEN_INVALID); + + IPCSkeleton::SetCallingTokenID(1); + ret = manager->PublishReminder(reminder, option); + EXPECT_NE(ret, ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED); +} + +/** + * @tc.name: OnLanguageChanged + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I97Q9Q + */ +HWTEST_F(ReminderDataManagerTest, OnLanguageChanged_0001, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + reminder->SetReminderId(10); + std::string title = "this is title"; + std::string resource = "close"; + ReminderRequest::ActionButtonType type = ReminderRequest::ActionButtonType::CLOSE; + reminder->SetActionButton(title, type, resource); + + manager->reminderVector_.push_back(reminder); + manager->showedReminderVector_.push_back(reminder); + + manager->OnLanguageChanged(); + EXPECT_TRUE(reminder->actionButtonMap_[type].title == "this is title"); +} + +/** + * @tc.name: ExcludeDate + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I97Q9Q + */ +HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) +{ + std::vector dates; + auto result = manager->CheckExcludeDateParam(9999, nullptr); + EXPECT_TRUE(result == nullptr); + + auto ret = manager->AddExcludeDate(9999, 100, nullptr); + EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); + + ret = manager->DelExcludeDates(9999, nullptr); + EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); + + ret = manager->GetExcludeDates(9999, nullptr, dates); + EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); + + sptr reminder = new ReminderRequestCalendar(10); + reminder->SetCreatorBundleName("test1"); + reminder->SetUserId(-1); + reminder->reminderId_ = 100; + manager->reminderVector_.push_back(reminder); + sptr option = new NotificationBundleOption("test", -1); + result = manager->CheckExcludeDateParam(100, option); + EXPECT_TRUE(result == nullptr); + + reminder->SetCreatorBundleName("test"); + reminder->reminderType_ = ReminderRequest::ReminderType::TIMER; + result = manager->CheckExcludeDateParam(100, option); + EXPECT_TRUE(result == nullptr); + + reminder->reminderType_ = ReminderRequest::ReminderType::CALENDAR; + result = manager->CheckExcludeDateParam(100, option); + EXPECT_TRUE(result == nullptr); + + reminder->repeatDaysOfWeek_ = 1; + result = manager->CheckExcludeDateParam(100, option); + EXPECT_TRUE(result != nullptr); + + ret = manager->AddExcludeDate(100, 100, option); + EXPECT_TRUE(ret == ERR_OK); + + ret = manager->DelExcludeDates(100, option); + EXPECT_TRUE(ret == ERR_OK); + + ret = manager->GetExcludeDates(100, option, dates); + EXPECT_TRUE(ret == ERR_OK); +} + +/** + * @tc.name: InitStartExtensionAbility + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I9IIDE + */ +HWTEST_F(ReminderDataManagerTest, InitStartExtensionAbility_0001, Level1) +{ + sptr reminder = new ReminderRequestCalendar(10); + reminder->reminderType_ = ReminderRequest::ReminderType::CALENDAR; + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + uint64_t now = calendar->GetNowInstantMilli(); + calendar->SetDateTime(now-50000); + calendar->SetEndDateTime(now+50000); + manager->reminderVector_.push_back(calendar); + manager->Init(true); + EXPECT_TRUE(!manager->reminderVector_.empty()); +} + +/** + * @tc.name: ReminderNotificationSubscriber_00001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I9IIDE + */ +HWTEST_F(ReminderDataManagerTest, ReminderNotificationSubscriber_00001, Level1) +{ + ReminderEventManager::ReminderNotificationSubscriber test(manager); + sptr notificationReq = new NotificationRequest(); + std::shared_ptr notification = std::make_shared(notificationReq); + test.OnCanceled(notification, nullptr, NotificationConstant::CANCEL_REASON_DELETE); + SUCCEED(); + + test.OnCanceled(nullptr, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); + + notificationReq->SetLabel(""); + test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); + + notificationReq->SetLabel("TEST_1"); + test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); + + notificationReq->SetLabel("TEST_NOTIFICATION_1"); + test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); + + notificationReq->SetLabel("REMINDER_NOTIFICATION_1"); + test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); + + notificationReq->SetLabel("REMINDER_AGENT_INFO"); + test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); + + notificationReq->SetLabel("REMINDER_AGENT_0"); + test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); + SUCCEED(); +} + +/** + * @tc.name: CancelAllReminders_00001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I9IIDE + */ +HWTEST_F(ReminderDataManagerTest, CancelAllReminders_00001, Level1) +{ + int32_t ret = manager->CancelAllReminders("", -1, -1); + EXPECT_TRUE(ret == ERR_OK); + + ret = manager->CancelAllReminders("com.example.simple", 100, 20020152); + EXPECT_TRUE(ret == ERR_OK); +} + +/** + * @tc.name: GetVaildReminders_00001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I9IIDE + */ +HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) +{ + sptr reminder1 = new ReminderRequestTimer(static_cast(50)); + reminder1->SetCreatorBundleName("test_getvalid"); + reminder1->SetCreatorUid(98765); + reminder1->SetBundleName("test_getvalid"); + reminder1->SetUid(98765); + sptr option1 = new NotificationBundleOption("test_getvalid", 98765); + manager->PublishReminder(reminder1, option1); + reminder1->SetExpired(false); + + sptr reminder2 = new ReminderRequestTimer(51); + reminder2->SetCreatorBundleName("test_getvalid"); + reminder2->SetCreatorUid(98765); + reminder2->SetBundleName("test_getvalid"); + reminder2->SetUid(98765); + reminder2->SetExpired(true); + sptr option2 = new NotificationBundleOption("test_getvalid", 98765); + manager->PublishReminder(reminder2, option2); + + std::vector> reminders; + manager->GetValidReminders(option2, reminders); + EXPECT_TRUE(reminders.size() == 1); +} + +/** + * @tc.name: IsMatched_00001 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issue#I9IIDE + */ +HWTEST_F(ReminderDataManagerTest, IsMatched_00001, Level1) +{ + sptr reminder = new ReminderRequestTimer(50); + reminder->SetCreatorBundleName("test_IsMatched"); + reminder->SetCreatorUid(98765); + reminder->SetBundleName("test_IsMatched"); + reminder->SetUid(98765); + reminder->SetUserId(100); + bool ret = manager->IsMatched(reminder, "test_IsMatched", 101, 98765); + EXPECT_EQ(ret, false); + ret = manager->IsMatched(reminder, "allPackages", 100, 98765); + EXPECT_EQ(ret, true); + ret = manager->IsMatched(reminder, "test_IsMatched2", 100, 98765); + EXPECT_EQ(ret, false); + ret = manager->IsMatched(reminder, "test_IsMatched", 100, -1); + EXPECT_EQ(ret, false); + ret = manager->IsMatched(reminder, "test_IsMatched", 100, 98766); + EXPECT_EQ(ret, false); + ret = manager->IsMatched(reminder, "test_IsMatched", 100, 98765); + EXPECT_EQ(ret, true); +} +} // namespace Notification +} // namespace OHOS -- Gitee