From eece98558e939ec96f98bf7a766218abeda9f5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E5=BF=97=E9=9B=84?= Date: Wed, 7 Aug 2024 17:14:09 +0800 Subject: [PATCH 1/3] ans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 侯志雄 --- frameworks/ans/src/notification_helper.cpp | 4 +- .../core/include/ans_manager_interface.h | 2 +- frameworks/core/include/ans_manager_proxy.h | 2 +- frameworks/core/include/ans_manager_stub.h | 2 +- frameworks/core/include/ans_notification.h | 2 +- frameworks/core/src/ans_manager_proxy.cpp | 9 +- frameworks/core/src/ans_manager_stub.cpp | 8 +- .../core/src/ans_manager_stub_invalid.cpp | 2 +- frameworks/core/src/ans_notification.cpp | 4 +- .../ans_notification_branch_test.cpp | 1766 ++++++++--------- interfaces/inner_api/notification_helper.h | 2 +- .../ans/include/advanced_datashare_helper.h | 2 + .../include/advanced_notification_service.h | 3 +- .../ans/src/advanced_datashare_helper.cpp | 51 +- .../advanced_notification_publish_service.cpp | 29 +- 15 files changed, 979 insertions(+), 909 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 9e6680fc3..0cad2612f 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -370,9 +370,9 @@ ErrCode NotificationHelper::DoesSupportDoNotDisturbMode(bool &doesSupport) return DelayedSingleton::GetInstance()->DoesSupportDoNotDisturbMode(doesSupport); } -ErrCode NotificationHelper::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber) +ErrCode NotificationHelper::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) { - return DelayedSingleton::GetInstance()->IsNeedSilentInDoNotDisturbMode(phoneNumber); + return DelayedSingleton::GetInstance()->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); } ErrCode NotificationHelper::IsDistributedEnabled(bool &enabled) diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 26b74deec..790abe0ce 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -564,7 +564,7 @@ public: * @param phoneNumber the calling format number. * @return Returns silent in do not disturb mode. */ - virtual ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber) = 0; + virtual ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) = 0; /** * @brief Cancel notifications according to group. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 73580e190..59bf9a7eb 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -552,7 +552,7 @@ public: * @param phoneNumber the calling format number. * @return Returns silent in do not disturb mode. */ - ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber) override; + ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override; /** * @brief Cancel notifications according to group. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 96d170725..0ec670f8f 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -552,7 +552,7 @@ public: * @param phoneNumber the calling format number. * @return Returns silent in do not disturb mode. */ - virtual ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber) override; + virtual ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override; /** * @brief Cancel notifications according to group. diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 98af4ca6f..d1da72dfb 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -691,7 +691,7 @@ public: * @param phoneNumber the calling format number. * @return Returns silent in do not disturb mode. */ - ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber); + ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType); /** * @brief Checks if the device supports distributed notification. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 7474f02fd..a163f3121 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -1355,7 +1355,7 @@ ErrCode AnsManagerProxy::IsSpecialBundleAllowedNotify(const sptrDoesSupportDoNotDisturbMode(doesSupport); } -ErrCode AnsNotification::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber) +ErrCode AnsNotification::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) { sptr proxy = GetAnsManagerProxy(); if (!proxy) { @@ -1040,7 +1040,7 @@ ErrCode AnsNotification::IsNeedSilentInDoNotDisturbMode(const std::string &phone return ERR_ANS_SERVICE_NOT_CONNECTED; } - return proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber); + return proxy->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); } ErrCode AnsNotification::PublishContinuousTaskNotification(const NotificationRequest &request) diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index 87ae6c25e..a27ac928f 100644 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -1,883 +1,883 @@ -/* - * 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(bool 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 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 SetNotificationAgent(const std::string &agent) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetNotificationAgent(std::string &agent) 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 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) 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; - } - -#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() {} - -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; - MockGetAnsManagerProxy(false); - 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; - MockGetAnsManagerProxy(true); - ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); - 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; - MockGetAnsManagerProxy(false); - 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; - MockGetAnsManagerProxy(true); - ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); - 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); - MockGetAnsManagerProxy(false); - 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); - MockGetAnsManagerProxy(true); - ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); - 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(); - notification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); - NotificationRequest req; - std::shared_ptr mediaContent = std::make_shared(); - auto content = std::make_shared(mediaContent); - content->content_ = nullptr; - req.SetContent(content); - - auto ret = notification->PublishNotification("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = notification->PublishNotificationAsBundle("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - - auto liveViewContent = std::make_shared(); - auto content1 = std::make_shared(liveViewContent); - content1->content_ = nullptr; - req.SetContent(content1); - req.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); - ret = notification->PublishNotification("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = notification->PublishNotificationAsBundle("label", req); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); -} - -} // namespace Notification -} // namespace OHOS +/* + * Copyright (c) 2023-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(bool 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 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 SetNotificationAgent(const std::string &agent) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode GetNotificationAgent(std::string &agent) 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 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; + } + +#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() {} + +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; + MockGetAnsManagerProxy(false); + 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; + MockGetAnsManagerProxy(true); + ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); + 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; + MockGetAnsManagerProxy(false); + 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; + MockGetAnsManagerProxy(true); + ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); + 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); + MockGetAnsManagerProxy(false); + 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); + MockGetAnsManagerProxy(true); + ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); + 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(); + notification->ansManagerProxy_ = 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/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index b23763c40..cbb33dbd1 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -673,7 +673,7 @@ public: * @param phoneNumber the calling format number. * @return Returns silent in do not disturb mode. */ - static ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber); + static ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType); /** * @brief Check if the device supports distributed notification. diff --git a/services/ans/include/advanced_datashare_helper.h b/services/ans/include/advanced_datashare_helper.h index ccfaa186a..eb23f11df 100644 --- a/services/ans/include/advanced_datashare_helper.h +++ b/services/ans/include/advanced_datashare_helper.h @@ -28,6 +28,7 @@ namespace { constexpr const char *KEY_FOCUS_MODE_ENABLE = "focus_mode_enable"; constexpr const char *KEY_FOCUS_MODE_PROFILE = "focus_mode_profile"; constexpr const char *KEY_FOCUS_MODE_CALL_MESSAGE_POLICY = "focus_mode_call_message_policy"; +constexpr const char *KEY_FOCUS_MODE_REPEAT_CALLERS_ENABLE = "focus_mode_repeate_callers_enable"; } // namespace class AdvancedDatashareHelper : DelayedSingleton { @@ -36,6 +37,7 @@ public: ~AdvancedDatashareHelper() = default; bool Query(Uri &uri, const std::string &key, std::string &value); bool QueryContact(Uri &uri, const std::string &phoneNumber, const std::string &policy); + bool isRepeatCall(const std::string &phoneNumber); std::string GetFocusModeEnableUri(const int32_t &userId) const; std::string GetFocusModeProfileUri(const int32_t &userId) const; std::string GetFocusModeCallPolicyUri(const int32_t &userId) const; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 5cb91d2f8..481fe391e 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -607,7 +607,7 @@ public: * @param phoneNumber the calling format number. * @return Returns silent in do not disturb mode. */ - ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber) override; + ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override; /** * @brief Cancel notifications according to group. @@ -1371,6 +1371,7 @@ private: const std::string &groupName, const int32_t reason); ErrCode ExcuteCancelAll(const sptr& bundleOption, const int32_t reason); ErrCode ExcuteDelete(const std::string &key, const int32_t removeReason); + ErrCode CheckNeedSilent(const std::string &phoneNumber, int32_t callerType); private: static sptr instance_; diff --git a/services/ans/src/advanced_datashare_helper.cpp b/services/ans/src/advanced_datashare_helper.cpp index d5c5281ae..48ef99c60 100644 --- a/services/ans/src/advanced_datashare_helper.cpp +++ b/services/ans/src/advanced_datashare_helper.cpp @@ -44,6 +44,8 @@ constexpr const char *UNIFIED_GROUP_ENABLE_URI = "?Proxy=true&key=unified_group_ constexpr const char *CONTACT_URI = "datashare:///com.ohos.contactsdataability"; constexpr const char *RAW_CONTACT_URI = "datashare:///com.ohos.contactsdataability/contacts/raw_contact"; constexpr const char *CONTACT_DATA = "datashare:///com.ohos.contactsdataability/contacts/contact_data"; +constexpr const char *CALLLOG_URI = "datashare:///com.ohos.calllogability"; +constexpr const char *CALL_SUBSECTION = "datashare:///com.ohos.calllogability/calls/calllog"; constexpr const char *PHONE_NUMBER = "phone_number"; constexpr const char *IS_DELETED = "is_deleted"; constexpr const char *TYPE_ID = "type_id"; @@ -53,7 +55,10 @@ constexpr const char *FAVORITE = "favorite"; constexpr const char *FOCUS_MODE_LIST = "focus_mode_list"; constexpr const char *ADVANCED_DATA_COLUMN_KEYWORD = "KEYWORD"; constexpr const char *ADVANCED_DATA_COLUMN_VALUE = "VALUE"; +constexpr const char *CALL_DIRECTION = "call_direction"; +constexpr const char *CREATE_TIME = "create_time"; constexpr const unsigned int PHONE_NUMBER_LENGTH = 7; +constexpr const unsigned int MAX_TIME_INTERVAL = 15 * 60; constexpr const int TYPE_ID_FIVE = 5; std::vector QUERY_CONTACT_COLUMN_LIST = {FORMAT_PHONE_NUMBER, FAVORITE, FOCUS_MODE_LIST, DETAIL_INFO}; } // namespace @@ -148,10 +153,11 @@ bool AdvancedDatashareHelper::QueryContact(Uri &uri, const std::string &phoneNum helper->Release(); return false; } + bool isFound = false; int rowCount = 0; resultSet->GetRowCount(rowCount); if (rowCount <= 0) { - ANS_LOGE("Query failed failed"); + ANS_LOGI("Query success, but rowCount is 0."); } else { int resultId = -1; #ifdef OHOS_BUILD_ENABLE_TELEPHONY_CUST @@ -159,12 +165,12 @@ bool AdvancedDatashareHelper::QueryContact(Uri &uri, const std::string &phoneNum #endif if ((phoneNumber.size() >= PHONE_NUMBER_LENGTH && resultSet->GoToRow(resultId) == DataShare::E_OK) || (phoneNumber.size() < PHONE_NUMBER_LENGTH && resultSet->GoToFirstRow() == DataShare::E_OK)) { - return dealWithContactResult(helper, resultSet, policy); + isFound = dealWithContactResult(helper, resultSet, policy); } } resultSet->Close(); helper->Release(); - return false; + return isFound; } bool AdvancedDatashareHelper::dealWithContactResult(std::shared_ptr helper, @@ -198,9 +204,46 @@ bool AdvancedDatashareHelper::dealWithContactResult(std::shared_ptr helper = CreateContactDataShareHelper(CALLLOG_URI); + if (helper == nullptr) { + ANS_LOGE("The data share helper is nullptr."); + return false; + } + bool isRepeat = false; + DataShare::DataSharePredicates predicates; + std::vector columns; + Uri uri(CALL_SUBSECTION); + predicates.EqualTo(PHONE_NUMBER, phoneNumber); + predicates.EqualTo(CALL_DIRECTION, 0); + predicates.OrderByDesc(CREATE_TIME); + columns.push_back(CREATE_TIME); + auto resultSet = helper->Query(uri, predicates, columns); + IPCSkeleton::SetCallingIdentity(identity); + if (resultSet == nullptr) { + helper->Release(); + return false; + } + int rowCount = 0; + resultSet->GetRowCount(rowCount); + if (rowCount > 0) { + int32_t columnIndex; + int32_t callTime = 0; + if (resultSet->GoToFirstRow() == 0) { + resultSet->GetColumnIndex(CREATE_TIME, columnIndex); + resultSet->GetInt(columnIndex, callTime); + } + if (time(NULL) - callTime < MAX_TIME_INTERVAL) { + isRepeat = true; + } + } resultSet->Close(); helper->Release(); - return isNeedSilent; + return isRepeat; } std::string AdvancedDatashareHelper::GetFocusModeEnableUri(const int32_t &userId) const diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 5da921c37..5d4bee453 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -59,6 +59,7 @@ constexpr int32_t HOURS_IN_ONE_DAY = 24; const static std::string NOTIFICATION_EVENT_PUSH_AGENT = "notification.event.PUSH_AGENT"; constexpr int32_t RSS_PID = 3051; constexpr int32_t TYPE_CODE_DOWNLOAD = 8; +constexpr const char *FOCUS_MODE_REPEAT_CALLERS_ENABLE = "1"; static constexpr const char *CONTACT_DATA = "datashare:///com.ohos.contactsdataability/contacts/contact_data"; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( @@ -1634,7 +1635,7 @@ ErrCode AdvancedNotificationService::RemoveNotificationBySlot(const sptr::GetInstance(); if (datashareHelper == nullptr) { ANS_LOGE("The data share helper is nullptr."); @@ -1654,28 +1658,37 @@ ErrCode AdvancedNotificationService::IsNeedSilentInDoNotDisturbMode(const std::s ANS_LOGD("GetActiveUserId is false"); return ERR_ANS_GET_ACTIVE_USER_FAILED; } - ANS_LOGI("IsNeedSilentInDoNotDisturbMode: userId = %{public}d", userId); - std::string policy; + bool isNeedSilent = false; + std::string policy; Uri policyUri(datashareHelper->GetFocusModeCallPolicyUri(userId)); bool ret = datashareHelper->Query(policyUri, KEY_FOCUS_MODE_CALL_MESSAGE_POLICY, policy); - ANS_LOGI("get policy[%{public}s]: ", policy.c_str()); if (!ret) { ANS_LOGE("Query focus mode call message policy fail."); return -1; } + std::string repeat_call; + bool repeat_ret = datashareHelper->Query(policyUri, KEY_FOCUS_MODE_REPEAT_CALLERS_ENABLE, repeat_call); + if (!repeat_ret) { + ANS_LOGE("Query focus mode repeat callers enable fail."); + } + ANS_LOGI("focus_mode_call_policy is %{public}s, repeat_call is %{public}s", policy.c_str(), repeat_call.c_str()); + if (repeat_call == FOCUS_MODE_REPEAT_CALLERS_ENABLE && + callerType == 0 && atoi(policy.c_str()) != ContactPolicy::ALLOW_EVERYONE) { + if (datashareHelper->isRepeatCall(phoneNumber)) { + return 1; + } + } + switch (atoi(policy.c_str())) { case ContactPolicy::FORBID_EVERYONE: - ANS_LOGI("IsNeedSilentInDoNotDisturbMode: focus_mode_call_message_policy is 1"); break; case ContactPolicy::ALLOW_EVERYONE: - ANS_LOGI("IsNeedSilentInDoNotDisturbMode: focus_mode_call_message_policy is 2"); isNeedSilent = true; break; case ContactPolicy::ALLOW_EXISTING_CONTACTS: case ContactPolicy::ALLOW_FAVORITE_CONTACTS: - case ContactPolicy::ALLOW_SPECIFIED_CONTACTS: - ANS_LOGI("IsNeedSilentInDoNotDisturbMode: focus_mode_call_message_policy is %{public}s", policy.c_str()); + case ContactPolicy::ALLOW_SPECIFIED_CONTACTS: Uri uri(CONTACT_DATA); isNeedSilent = datashareHelper->QueryContact(uri, phoneNumber, policy); break; -- Gitee From 2b8e564515b1215e76034208a1376740b882481a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E5=BF=97=E9=9B=84?= Date: Wed, 7 Aug 2024 17:39:17 +0800 Subject: [PATCH 2/3] ans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 侯志雄 --- interfaces/inner_api/notification_helper.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index cbb33dbd1..9bdf7d776 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -947,6 +947,7 @@ public: static ErrCode IsDistributedEnabledByBundle( const NotificationBundleOption &bundleOption, const std::string &deviceType, bool &enabled); + /** * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders * -- Gitee From eecbc18befb8f706f3cfa99c5b25207bc2dee4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E5=BF=97=E9=9B=84?= Date: Wed, 7 Aug 2024 17:45:07 +0800 Subject: [PATCH 3/3] ans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 侯志雄 --- interfaces/inner_api/notification_helper.h | 2021 ++++++++++---------- 1 file changed, 1010 insertions(+), 1011 deletions(-) diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index 9bdf7d776..ed52c0b54 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -1,1011 +1,1010 @@ -/* - * 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H - -#include "ans_dialog_host_client.h" -#include "notification_bundle_option.h" -#include "notification_button_option.h" -#include "notification_do_not_disturb_date.h" -#include "notification_do_not_disturb_profile.h" -#include "enabled_notification_callback_data.h" -#include "notification_request.h" -#include "notification_slot.h" -#include "notification_sorting_map.h" -#include "notification_subscriber.h" -#include "notification_local_live_view_subscriber.h" -#include "want_params.h" - -namespace OHOS { -namespace Notification { -class NotificationHelper { -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. - */ - static 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. - */ - static 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. - */ - static ErrCode AddNotificationSlots(const std::vector &slots); - - /** - * @brief Deletes a created notification slot based on the slot ID. - * - * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot - * This parameter must be specified. - * @return Returns remove notification slot result. - */ - static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); - - /** - * @brief Deletes all notification slots. - * - * @return Returns remove all slots result. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static 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 get slotFlags by bundle result. - */ - static ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags); - - /** - * @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. - */ - static ErrCode PublishNotification(const NotificationRequest &request); - - /** - * @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. - */ - static ErrCode PublishNotification(const std::string &label, 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. - */ - static 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. - */ - static ErrCode CancelNotification(const std::string &label, int32_t notificationId); - - /** - * @brief Cancels all the published notifications. - * - * @note To cancel a specified notification, see CancelNotification(int_32). - * @return Returns cancel all notifications result. - */ - static 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. - */ - static 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 bundle 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. - */ - static ErrCode CancelAsBundle(const NotificationBundleOption &bundleOption, int32_t notificationId); - - /** - * @brief Obtains the number of active notifications of the current application in the system. - * - * @param nums Indicates the number of active notifications of the current application. - * @return Returns get active notification nums result. - */ - static 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. - */ - static ErrCode GetActiveNotifications(std::vector> &request); - - /** - * @brief Allows another application to act as an agent to publish notifications in the name of your application - * bundle. - * - * @param agent Indicates the name of the application bundle that can publish notifications for your application. - * @return Returns set notification agent result. - */ - static ErrCode SetNotificationAgent(const std::string &agent); - - /** - * @brief Obtains the name of the application bundle that can publish notifications in the name of your application. - * - * @param agent Indicates the name of the application bundle that can publish notifications for your application if - * any; returns null otherwise. - * @return Returns get notification agent result. - */ - static ErrCode GetNotificationAgent(std::string &agent); - - /** - * @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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static ErrCode CanPopEnableNotificationDialog(sptr &hostClient, - bool &canPop, std::string &bundleName); - - /** - * @brief Allow 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. - */ - static 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; false otherwise. - * @return Returns has notification policy access permission. - */ - static ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission); - - /** - * @brief Obtains the importance level of this application. - * - * @param importance Indicates 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 - */ - static 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. - * - * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. - * This parameter must be specified. - * @return Returns unsubscribe notification result. - */ - static ErrCode SubscribeNotification(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 unsubscribe notification result. - */ - static ErrCode SubscribeNotificationSelf(const NotificationSubscriber &subscriber); - - /** - * @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. - */ - static ErrCode SubscribeNotification( - const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo); - - /** - * @brief Subscribes the localLiveView button click. This method can be called only - * by applications with required system permissions. - * @note To subscribe to a button click, inherit the {NotificationLocalLiveViewSubscriber} class, override its - * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. - * After the button is clicked, subscribers that meet the filter criteria can receive the response - * - * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. - * For details, see {NotificationSubscriber}. - * @return Returns subscribe notification result. - */ - static ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber, - const bool isNative = true); - - /** - * @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. - */ - static ErrCode UnSubscribeNotification(NotificationSubscriber &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. - * - * @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. - */ - static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo 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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static ErrCode RemoveAllNotifications(const NotificationBundleOption &bundleOption); - - static 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. - */ - static 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. - */ - static 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. - */ - static ErrCode GetNotificationSlotsForBundle( - const NotificationBundleOption &bundleOption, std::vector> &slots); - - /** - * @brief Obtains all notification slots 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. - */ - static ErrCode GetNotificationSlotForBundle( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, - sptr &slot); - - /** - * @brief Update 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. - */ - static 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 - */ - static 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. - */ - static ErrCode GetAllActiveNotifications( - const std::vector key, std::vector> ¬ification); - - /** - * @brief Obtains the active notifications by filter. - * @param filter - * @param extraInfo - * @return - */ - static 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; false otherwise. - * @return Returns is allowed notify result. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static ErrCode SetNotificationsEnabledForSpecifiedBundle( - const NotificationBundleOption &bundleOption, std::string &deviceId, bool enabled); - - /** - * @brief Sets whether to allow a specified application 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. - */ - static ErrCode SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled); - - /** - * @brief Obtains the flag that whether to allow a specified application 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. - */ - static ErrCode GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled); - - /** - * @brief Obtains the flag that whether to allow the current application to show badge. - * - * @param enabled Specifies whether to allow the given application to show badge. - * @return Returns get result. - */ - static ErrCode GetShowBadgeEnabled(bool &enabled); - - /** - * @brief Cancel the notification of the specified group of this application. - * - * @param groupName Indicates the specified group name. - * @return Returns cancel group result. - */ - static ErrCode CancelGroup(const std::string &groupName); - - /** - * @brief Remove the notification of the specified group of the specified application. - * - * @param bundleOption Indicates the bundle name and uid of the specified application. - * @param groupName Indicates the specified group name. - * @return Returns remove group by bundle result. - */ - static 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. - */ - static 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. - */ - static ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate); - - /** - * @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. - */ - static 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. - */ - static ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType); - - /** - * @brief Check if the device supports distributed notification. - * - * @param enabled True if the device supports distributed notification; false otherwise. - * @return Returns is distributed enabled result. - */ - static ErrCode IsDistributedEnabled(bool &enabled); - - /** - * @brief Set 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. - */ - static ErrCode EnableDistributed(const bool enabled); - - /** - * @brief Set 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. - */ - static ErrCode EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled); - - /** - * @brief Set 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. - */ - static ErrCode EnableDistributedSelf(const bool enabled); - - /** - * @brief Check 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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId); - - /** - * @brief Obtains whether the template is supported by the system. - * - * @param support Indicates whether is it a system supported template. - * @return Returns check result. - */ - static ErrCode IsSupportTemplate(const std::string &templateName, bool &support); - - /** - * @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; false otherwise. - * @return Returns get allowed result. - */ - static ErrCode IsAllowedNotify(const int32_t &userId, bool &allowed); - - /** - * @brief Sets whether to allow all applications to publish notifications on a specified user. - * The caller must have system permissions to call this method. - * - * @param userId Indicates the ID of the user running the application. - * @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. - */ - static ErrCode SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled); - - /** - * @brief Removes notifications under specified user. - * @note Your application must have platform signature to use this method. - * - * @param userId Indicates the ID of user whose notifications are to be removed. - * @return Returns remove notification result. - */ - static ErrCode RemoveNotifications(const int32_t &userId); - - /** - * @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. - */ - static 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. - */ - static ErrCode GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate); - - /** - * @brief Obtains the do not disturb on a specified user. - * @note Your application must have system signature to call this method. - * - * @param profiles Indicates the do not disturb time to add. - * @return Returns set do not disturb time result. - */ - static ErrCode AddDoNotDisturbProfiles(const std::vector> &profiles); - - /** - * @brief Obtains the do not disturb on a specified user. - * @note Your application must have system signature to call this method. - * - * @param profiles Indicates the do not disturb time to remove. - * @return Returns set do not disturb time result. - */ - static ErrCode RemoveDoNotDisturbProfiles(const std::vector> &profiles); - - /** - * 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 enabled 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. - */ - static 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 enabled the type of slot enabled to get. - * @return Returns get slot number by bundle result. - */ - static 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 enabled the type of slot enabled to get. - * @return Returns get enabled result. - */ - static ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); - - /** - * @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. - */ - static 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. - */ - static ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled); - - /** - * @brief Set badge number. - * - * @param badgeNumber The badge number. - * @return Returns set badge number result. - */ - static 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. - */ - static 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. - */ - static ErrCode GetAllNotificationEnabledBundles(std::vector &bundleOption); - - /** - * @brief Register Push Callback. - * - * @param pushCallback push appliction's Callback. - * @param notificationCheckRequest Filter conditions for push check. - * @return Returns register push callback result. - */ - static ErrCode RegisterPushCallback( - const sptr& pushCallback, const sptr ¬ificationCheckRequest); - - /** - * @brief Unregister Push Callback. - * - * @return Returns unregister push Callback result. - */ - static ErrCode UnregisterPushCallback(); - - /** - * @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. - */ - static 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. - */ - static 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. - */ - static 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. - */ - static ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled); - - /** - * @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. - */ - static ErrCode SetAdditionConfig(const std::string &key, const std::string &value); - - /** - * @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. - */ - static 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. - */ - static ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status); - - /** - * @brief Register Swing Callback Function. - * - * @param swingCallback swing Callback Function. - * @return Returns register swing callback result. - */ - static ErrCode RegisterSwingCallback(const std::function swingCbFunc); -}; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H +/* + * 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H + +#include "ans_dialog_host_client.h" +#include "notification_bundle_option.h" +#include "notification_button_option.h" +#include "notification_do_not_disturb_date.h" +#include "notification_do_not_disturb_profile.h" +#include "enabled_notification_callback_data.h" +#include "notification_request.h" +#include "notification_slot.h" +#include "notification_sorting_map.h" +#include "notification_subscriber.h" +#include "notification_local_live_view_subscriber.h" +#include "want_params.h" + +namespace OHOS { +namespace Notification { +class NotificationHelper { +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. + */ + static 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. + */ + static 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. + */ + static ErrCode AddNotificationSlots(const std::vector &slots); + + /** + * @brief Deletes a created notification slot based on the slot ID. + * + * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot + * This parameter must be specified. + * @return Returns remove notification slot result. + */ + static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); + + /** + * @brief Deletes all notification slots. + * + * @return Returns remove all slots result. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static 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 get slotFlags by bundle result. + */ + static ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags); + + /** + * @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. + */ + static ErrCode PublishNotification(const NotificationRequest &request); + + /** + * @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. + */ + static ErrCode PublishNotification(const std::string &label, 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. + */ + static 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. + */ + static ErrCode CancelNotification(const std::string &label, int32_t notificationId); + + /** + * @brief Cancels all the published notifications. + * + * @note To cancel a specified notification, see CancelNotification(int_32). + * @return Returns cancel all notifications result. + */ + static 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. + */ + static 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 bundle 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. + */ + static ErrCode CancelAsBundle(const NotificationBundleOption &bundleOption, int32_t notificationId); + + /** + * @brief Obtains the number of active notifications of the current application in the system. + * + * @param nums Indicates the number of active notifications of the current application. + * @return Returns get active notification nums result. + */ + static 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. + */ + static ErrCode GetActiveNotifications(std::vector> &request); + + /** + * @brief Allows another application to act as an agent to publish notifications in the name of your application + * bundle. + * + * @param agent Indicates the name of the application bundle that can publish notifications for your application. + * @return Returns set notification agent result. + */ + static ErrCode SetNotificationAgent(const std::string &agent); + + /** + * @brief Obtains the name of the application bundle that can publish notifications in the name of your application. + * + * @param agent Indicates the name of the application bundle that can publish notifications for your application if + * any; returns null otherwise. + * @return Returns get notification agent result. + */ + static ErrCode GetNotificationAgent(std::string &agent); + + /** + * @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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static ErrCode CanPopEnableNotificationDialog(sptr &hostClient, + bool &canPop, std::string &bundleName); + + /** + * @brief Allow 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. + */ + static 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; false otherwise. + * @return Returns has notification policy access permission. + */ + static ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission); + + /** + * @brief Obtains the importance level of this application. + * + * @param importance Indicates 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 + */ + static 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. + * + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns unsubscribe notification result. + */ + static ErrCode SubscribeNotification(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 unsubscribe notification result. + */ + static ErrCode SubscribeNotificationSelf(const NotificationSubscriber &subscriber); + + /** + * @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. + */ + static ErrCode SubscribeNotification( + const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo); + + /** + * @brief Subscribes the localLiveView button click. This method can be called only + * by applications with required system permissions. + * @note To subscribe to a button click, inherit the {NotificationLocalLiveViewSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the button is clicked, subscribers that meet the filter criteria can receive the response + * + * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. + * For details, see {NotificationSubscriber}. + * @return Returns subscribe notification result. + */ + static ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber, + const bool isNative = true); + + /** + * @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. + */ + static ErrCode UnSubscribeNotification(NotificationSubscriber &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. + * + * @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. + */ + static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo 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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static ErrCode RemoveAllNotifications(const NotificationBundleOption &bundleOption); + + static 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. + */ + static 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. + */ + static 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. + */ + static ErrCode GetNotificationSlotsForBundle( + const NotificationBundleOption &bundleOption, std::vector> &slots); + + /** + * @brief Obtains all notification slots 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. + */ + static ErrCode GetNotificationSlotForBundle( + const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot); + + /** + * @brief Update 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. + */ + static 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 + */ + static 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. + */ + static ErrCode GetAllActiveNotifications( + const std::vector key, std::vector> ¬ification); + + /** + * @brief Obtains the active notifications by filter. + * @param filter + * @param extraInfo + * @return + */ + static 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; false otherwise. + * @return Returns is allowed notify result. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static ErrCode SetNotificationsEnabledForSpecifiedBundle( + const NotificationBundleOption &bundleOption, std::string &deviceId, bool enabled); + + /** + * @brief Sets whether to allow a specified application 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. + */ + static ErrCode SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled); + + /** + * @brief Obtains the flag that whether to allow a specified application 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. + */ + static ErrCode GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled); + + /** + * @brief Obtains the flag that whether to allow the current application to show badge. + * + * @param enabled Specifies whether to allow the given application to show badge. + * @return Returns get result. + */ + static ErrCode GetShowBadgeEnabled(bool &enabled); + + /** + * @brief Cancel the notification of the specified group of this application. + * + * @param groupName Indicates the specified group name. + * @return Returns cancel group result. + */ + static ErrCode CancelGroup(const std::string &groupName); + + /** + * @brief Remove the notification of the specified group of the specified application. + * + * @param bundleOption Indicates the bundle name and uid of the specified application. + * @param groupName Indicates the specified group name. + * @return Returns remove group by bundle result. + */ + static 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. + */ + static 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. + */ + static ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate); + + /** + * @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. + */ + static 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. + */ + static ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType); + + /** + * @brief Check if the device supports distributed notification. + * + * @param enabled True if the device supports distributed notification; false otherwise. + * @return Returns is distributed enabled result. + */ + static ErrCode IsDistributedEnabled(bool &enabled); + + /** + * @brief Set 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. + */ + static ErrCode EnableDistributed(const bool enabled); + + /** + * @brief Set 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. + */ + static ErrCode EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled); + + /** + * @brief Set 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. + */ + static ErrCode EnableDistributedSelf(const bool enabled); + + /** + * @brief Check 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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId); + + /** + * @brief Obtains whether the template is supported by the system. + * + * @param support Indicates whether is it a system supported template. + * @return Returns check result. + */ + static ErrCode IsSupportTemplate(const std::string &templateName, bool &support); + + /** + * @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; false otherwise. + * @return Returns get allowed result. + */ + static ErrCode IsAllowedNotify(const int32_t &userId, bool &allowed); + + /** + * @brief Sets whether to allow all applications to publish notifications on a specified user. + * The caller must have system permissions to call this method. + * + * @param userId Indicates the ID of the user running the application. + * @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. + */ + static ErrCode SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled); + + /** + * @brief Removes notifications under specified user. + * @note Your application must have platform signature to use this method. + * + * @param userId Indicates the ID of user whose notifications are to be removed. + * @return Returns remove notification result. + */ + static ErrCode RemoveNotifications(const int32_t &userId); + + /** + * @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. + */ + static 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. + */ + static ErrCode GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate); + + /** + * @brief Obtains the do not disturb on a specified user. + * @note Your application must have system signature to call this method. + * + * @param profiles Indicates the do not disturb time to add. + * @return Returns set do not disturb time result. + */ + static ErrCode AddDoNotDisturbProfiles(const std::vector> &profiles); + + /** + * @brief Obtains the do not disturb on a specified user. + * @note Your application must have system signature to call this method. + * + * @param profiles Indicates the do not disturb time to remove. + * @return Returns set do not disturb time result. + */ + static ErrCode RemoveDoNotDisturbProfiles(const std::vector> &profiles); + + /** + * 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 enabled 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. + */ + static 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 enabled the type of slot enabled to get. + * @return Returns get slot number by bundle result. + */ + static 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 enabled the type of slot enabled to get. + * @return Returns get enabled result. + */ + static ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); + + /** + * @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. + */ + static 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. + */ + static ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled); + + /** + * @brief Set badge number. + * + * @param badgeNumber The badge number. + * @return Returns set badge number result. + */ + static 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. + */ + static 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. + */ + static ErrCode GetAllNotificationEnabledBundles(std::vector &bundleOption); + + /** + * @brief Register Push Callback. + * + * @param pushCallback push appliction's Callback. + * @param notificationCheckRequest Filter conditions for push check. + * @return Returns register push callback result. + */ + static ErrCode RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest); + + /** + * @brief Unregister Push Callback. + * + * @return Returns unregister push Callback result. + */ + static ErrCode UnregisterPushCallback(); + + /** + * @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. + */ + static 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. + */ + static 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. + */ + static 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. + */ + static ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled); + + /** + * @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. + */ + static ErrCode SetAdditionConfig(const std::string &key, const std::string &value); + + /** + * @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. + */ + static 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. + */ + static ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status); + + /** + * @brief Register Swing Callback Function. + * + * @param swingCallback swing Callback Function. + * @return Returns register swing callback result. + */ + static ErrCode RegisterSwingCallback(const std::function swingCbFunc); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H -- Gitee