1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "notification_helper.h"
17 #include "ans_notification.h"
18 #include "singleton.h"
19
20 namespace OHOS {
21 namespace {
22 int32_t g_publishContinuousTaskNotificationFlag = 0;
23 int32_t g_cancelContinuousTaskNotificationFlag = 0;
24 int32_t g_getAllActiveNotificationsFlag = 0;
25 }
26
SetPublishContinuousTaskNotificationFlag(int32_t flag)27 void SetPublishContinuousTaskNotificationFlag(int32_t flag)
28 {
29 g_publishContinuousTaskNotificationFlag = flag;
30 }
31
SetCancelContinuousTaskNotificationFlag(int32_t flag)32 void SetCancelContinuousTaskNotificationFlag(int32_t flag)
33 {
34 g_cancelContinuousTaskNotificationFlag = flag;
35 }
36
SetGetAllActiveNotificationsFlag(int32_t flag)37 void SetGetAllActiveNotificationsFlag(int32_t flag)
38 {
39 g_getAllActiveNotificationsFlag = flag;
40 }
41
42 namespace Notification {
43 namespace {
44 constexpr int32_t TEST_NUM_ONE = 1;
45 constexpr int32_t TEST_NUM_TWO = 2;
46 }
47
PublishContinuousTaskNotification(const NotificationRequest & request)48 ErrCode NotificationHelper::PublishContinuousTaskNotification(const NotificationRequest &request)
49 {
50 if (g_publishContinuousTaskNotificationFlag == 1) {
51 return -1;
52 }
53 return 0;
54 }
55
CancelContinuousTaskNotification(const std::string & label,int32_t notificationId)56 ErrCode NotificationHelper::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId)
57 {
58 if (g_cancelContinuousTaskNotificationFlag == 1) {
59 return -1;
60 }
61 return 0;
62 }
63
SubscribeNotification(const NotificationSubscriber & subscriber)64 ErrCode NotificationHelper::SubscribeNotification(const NotificationSubscriber &subscriber)
65 {
66 return 0;
67 }
68
SubscribeNotification(const NotificationSubscriber & subscriber,const NotificationSubscribeInfo & subscribeInfo)69 ErrCode NotificationHelper::SubscribeNotification(
70 const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo)
71 {
72 return 0;
73 }
74
UnSubscribeNotification(NotificationSubscriber & subscriber)75 ErrCode NotificationHelper::UnSubscribeNotification(NotificationSubscriber &subscriber)
76 {
77 return 0;
78 }
79
UnSubscribeNotification(NotificationSubscriber & subscriber,NotificationSubscribeInfo subscribeInfo)80 ErrCode NotificationHelper::UnSubscribeNotification(
81 NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo)
82 {
83 return 0;
84 }
85
GetAllActiveNotifications(std::vector<sptr<Notification>> & notification)86 ErrCode NotificationHelper::GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ification)
87 {
88 std::shared_ptr<NotificationNormalContent> normalContent
89 = std::make_shared<NotificationNormalContent>();
90 normalContent->SetTitle("appName1");
91 normalContent->SetText("prompt1");
92 if (g_getAllActiveNotificationsFlag == TEST_NUM_ONE) {
93 sptr<NotificationRequest> notificationRequest1 = sptr<NotificationRequest>(new NotificationRequest());
94 notificationRequest1->SetContent(std::make_shared<NotificationContent>(normalContent));
95 notificationRequest1->SetLabel("label1");
96 notificationRequest1->SetCreatorUid(0);
97 auto notification1 = sptr<Notification>(new Notification(notificationRequest1));
98 sptr<NotificationRequest> notificationRequest2 = sptr<NotificationRequest>(new NotificationRequest());
99 notificationRequest2->SetContent(std::make_shared<NotificationContent>(normalContent));
100 notificationRequest2->SetLabel("label");
101 notificationRequest2->SetCreatorUid(-1);
102 auto notification2 = sptr<Notification>(new Notification(notificationRequest1));
103 sptr<NotificationRequest> notificationRequest3 = sptr<NotificationRequest>(new NotificationRequest());
104 notificationRequest3->SetContent(std::make_shared<NotificationContent>(normalContent));
105 notificationRequest3->SetLabel("label1");
106 notificationRequest3->SetCreatorUid(-1);
107 auto notification3 = sptr<Notification>(new Notification(notificationRequest1));
108 sptr<NotificationRequest> notificationRequest4 = sptr<NotificationRequest>(new NotificationRequest());
109 notificationRequest4->SetContent(std::make_shared<NotificationContent>(normalContent));
110 notificationRequest4->SetLabel("label");
111 notificationRequest4->SetCreatorUid(0);
112 auto notification4 = sptr<Notification>(new Notification(notificationRequest1));
113 notification.emplace_back(notification1);
114 notification.emplace_back(notification2);
115 notification.emplace_back(notification3);
116 notification.emplace_back(notification4);
117 return 0;
118 }
119
120 if (g_getAllActiveNotificationsFlag == TEST_NUM_TWO) {
121 sptr<NotificationRequest> notificationRequest = sptr<NotificationRequest>(new NotificationRequest());
122 notificationRequest->SetContent(std::make_shared<NotificationContent>(normalContent));
123 notificationRequest->SetLabel("label");
124 notificationRequest->SetCreatorUid(0);
125 auto notification5 = sptr<Notification>(new Notification(notificationRequest));
126 notification.emplace_back(notification5);
127 return 0;
128 }
129 return 0;
130 }
131 } // namespace Notification
132 } // namespace OHOS
133