• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 Notification {
AddNotificationSlot(const NotificationSlot & slot)22 ErrCode NotificationHelper::AddNotificationSlot(const NotificationSlot &slot)
23 {
24     return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlot(slot);
25 }
26 
AddSlotByType(const NotificationConstant::SlotType & slotType)27 ErrCode NotificationHelper::AddSlotByType(const NotificationConstant::SlotType &slotType)
28 {
29     return DelayedSingleton<AnsNotification>::GetInstance()->AddSlotByType(slotType);
30 }
31 
AddNotificationSlots(const std::vector<NotificationSlot> & slots)32 ErrCode NotificationHelper::AddNotificationSlots(const std::vector<NotificationSlot> &slots)
33 {
34     return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlots(slots);
35 }
36 
RemoveNotificationSlot(const NotificationConstant::SlotType & slotType)37 ErrCode NotificationHelper::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType)
38 {
39     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotificationSlot(slotType);
40 }
41 
RemoveAllSlots()42 ErrCode NotificationHelper::RemoveAllSlots()
43 {
44     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveAllSlots();
45 }
46 
GetNotificationSlot(const NotificationConstant::SlotType & slotType,sptr<NotificationSlot> & slot)47 ErrCode NotificationHelper::GetNotificationSlot(
48     const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot)
49 {
50     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlot(slotType, slot);
51 }
52 
GetNotificationSlots(std::vector<sptr<NotificationSlot>> & slots)53 ErrCode NotificationHelper::GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots)
54 {
55     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlots(slots);
56 }
57 
AddNotificationSlotGroup(const NotificationSlotGroup & slotGroup)58 ErrCode NotificationHelper::AddNotificationSlotGroup(const NotificationSlotGroup &slotGroup)
59 {
60     return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlotGroup(slotGroup);
61 }
62 
AddNotificationSlotGroups(const std::vector<NotificationSlotGroup> & slotGroups)63 ErrCode NotificationHelper::AddNotificationSlotGroups(const std::vector<NotificationSlotGroup> &slotGroups)
64 {
65     return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlotGroups(slotGroups);
66 }
67 
RemoveNotificationSlotGroup(const std::string & slotGroupId)68 ErrCode NotificationHelper::RemoveNotificationSlotGroup(const std::string &slotGroupId)
69 {
70     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotificationSlotGroup(slotGroupId);
71 }
72 
GetNotificationSlotGroup(const std::string & groupId,sptr<NotificationSlotGroup> & group)73 ErrCode NotificationHelper::GetNotificationSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group)
74 {
75     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotGroup(groupId, group);
76 }
77 
GetNotificationSlotGroups(std::vector<sptr<NotificationSlotGroup>> & groups)78 ErrCode NotificationHelper::GetNotificationSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups)
79 {
80     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotGroups(groups);
81 }
82 
GetNotificationSlotNumAsBundle(const NotificationBundleOption & bundleOption,int & num)83 ErrCode NotificationHelper::GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, int &num)
84 {
85     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotNumAsBundle(bundleOption, num);
86 }
87 
PublishNotification(const NotificationRequest & request)88 ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request)
89 {
90     return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotification(request);
91 }
92 
PublishNotification(const std::string & label,const NotificationRequest & request)93 ErrCode NotificationHelper::PublishNotification(const std::string &label, const NotificationRequest &request)
94 {
95     return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotification(label, request);
96 }
97 
PublishNotification(const NotificationRequest & request,const std::string & deviceId)98 ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request, const std::string &deviceId)
99 {
100     return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotification(request, deviceId);
101 }
102 
CancelNotification(int32_t notificationId)103 ErrCode NotificationHelper::CancelNotification(int32_t notificationId)
104 {
105     return DelayedSingleton<AnsNotification>::GetInstance()->CancelNotification(notificationId);
106 }
107 
CancelNotification(const std::string & label,int32_t notificationId)108 ErrCode NotificationHelper::CancelNotification(const std::string &label, int32_t notificationId)
109 {
110     return DelayedSingleton<AnsNotification>::GetInstance()->CancelNotification(label, notificationId);
111 }
112 
CancelAllNotifications()113 ErrCode NotificationHelper::CancelAllNotifications()
114 {
115     return DelayedSingleton<AnsNotification>::GetInstance()->CancelAllNotifications();
116 }
117 
GetActiveNotificationNums(int32_t & num)118 ErrCode NotificationHelper::GetActiveNotificationNums(int32_t &num)
119 {
120     return DelayedSingleton<AnsNotification>::GetInstance()->GetActiveNotificationNums(num);
121 }
122 
GetActiveNotifications(std::vector<sptr<NotificationRequest>> & request)123 ErrCode NotificationHelper::GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request)
124 {
125     return DelayedSingleton<AnsNotification>::GetInstance()->GetActiveNotifications(request);
126 }
127 
GetCurrentAppSorting(sptr<NotificationSortingMap> & sortingMap)128 ErrCode NotificationHelper::GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap)
129 {
130     return DelayedSingleton<AnsNotification>::GetInstance()->GetCurrentAppSorting(sortingMap);
131 }
132 
SetNotificationAgent(const std::string & agent)133 ErrCode NotificationHelper::SetNotificationAgent(const std::string &agent)
134 {
135     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationAgent(agent);
136 }
137 
GetNotificationAgent(std::string & agent)138 ErrCode NotificationHelper::GetNotificationAgent(std::string &agent)
139 {
140     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationAgent(agent);
141 }
142 
CanPublishNotificationAsBundle(const std::string & representativeBundle,bool & canPublish)143 ErrCode NotificationHelper::CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish)
144 {
145     return DelayedSingleton<AnsNotification>::GetInstance()->CanPublishNotificationAsBundle(
146         representativeBundle, canPublish);
147 }
148 
PublishNotificationAsBundle(const std::string & representativeBundle,const NotificationRequest & request)149 ErrCode NotificationHelper::PublishNotificationAsBundle(
150     const std::string &representativeBundle, const NotificationRequest &request)
151 {
152     return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotificationAsBundle(representativeBundle, request);
153 }
154 
SetNotificationBadgeNum()155 ErrCode NotificationHelper::SetNotificationBadgeNum()
156 {
157     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationBadgeNum();
158 }
159 
SetNotificationBadgeNum(int32_t num)160 ErrCode NotificationHelper::SetNotificationBadgeNum(int32_t num)
161 {
162     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationBadgeNum(num);
163 }
164 
IsAllowedNotify(bool & allowed)165 ErrCode NotificationHelper::IsAllowedNotify(bool &allowed)
166 {
167     return DelayedSingleton<AnsNotification>::GetInstance()->IsAllowedNotify(allowed);
168 }
169 
IsAllowedNotifySelf(bool & allowed)170 ErrCode NotificationHelper::IsAllowedNotifySelf(bool &allowed)
171 {
172     return DelayedSingleton<AnsNotification>::GetInstance()->IsAllowedNotifySelf(allowed);
173 }
174 
RequestEnableNotification(std::string & deviceId)175 ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId)
176 {
177     return DelayedSingleton<AnsNotification>::GetInstance()->RequestEnableNotification(deviceId);
178 }
179 
AreNotificationsSuspended(bool & suspended)180 ErrCode NotificationHelper::AreNotificationsSuspended(bool &suspended)
181 {
182     return DelayedSingleton<AnsNotification>::GetInstance()->AreNotificationsSuspended(suspended);
183 }
184 
HasNotificationPolicyAccessPermission(bool & hasPermission)185 ErrCode NotificationHelper::HasNotificationPolicyAccessPermission(bool &hasPermission)
186 {
187     return DelayedSingleton<AnsNotification>::GetInstance()->HasNotificationPolicyAccessPermission(hasPermission);
188 }
189 
GetBundleImportance(NotificationSlot::NotificationLevel & importance)190 ErrCode NotificationHelper::GetBundleImportance(NotificationSlot::NotificationLevel &importance)
191 {
192     return DelayedSingleton<AnsNotification>::GetInstance()->GetBundleImportance(importance);
193 }
194 
SubscribeNotification(const NotificationSubscriber & subscriber)195 ErrCode NotificationHelper::SubscribeNotification(const NotificationSubscriber &subscriber)
196 {
197     return DelayedSingleton<AnsNotification>::GetInstance()->SubscribeNotification(subscriber);
198 }
199 
SubscribeNotification(const NotificationSubscriber & subscriber,const NotificationSubscribeInfo & subscribeInfo)200 ErrCode NotificationHelper::SubscribeNotification(
201     const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo)
202 {
203     return DelayedSingleton<AnsNotification>::GetInstance()->SubscribeNotification(subscriber, subscribeInfo);
204 }
205 
UnSubscribeNotification(NotificationSubscriber & subscriber)206 ErrCode NotificationHelper::UnSubscribeNotification(NotificationSubscriber &subscriber)
207 {
208     return DelayedSingleton<AnsNotification>::GetInstance()->UnSubscribeNotification(subscriber);
209 }
210 
UnSubscribeNotification(NotificationSubscriber & subscriber,NotificationSubscribeInfo subscribeInfo)211 ErrCode NotificationHelper::UnSubscribeNotification(
212     NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo)
213 {
214     return DelayedSingleton<AnsNotification>::GetInstance()->UnSubscribeNotification(subscriber, subscribeInfo);
215 }
216 
RemoveNotification(const std::string & key)217 ErrCode NotificationHelper::RemoveNotification(const std::string &key)
218 {
219     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotification(key);
220 }
221 
RemoveNotification(const NotificationBundleOption & bundleOption,const int32_t notificationId,const std::string & label)222 ErrCode NotificationHelper::RemoveNotification(
223     const NotificationBundleOption &bundleOption, const int32_t notificationId, const std::string &label)
224 {
225     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotification(bundleOption, notificationId, label);
226 }
227 
RemoveAllNotifications(const NotificationBundleOption & bundleOption)228 ErrCode NotificationHelper::RemoveAllNotifications(const NotificationBundleOption &bundleOption)
229 {
230     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveAllNotifications(bundleOption);
231 }
232 
RemoveNotificationsByBundle(const NotificationBundleOption & bundleOption)233 ErrCode NotificationHelper::RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption)
234 {
235     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotificationsByBundle(bundleOption);
236 }
237 
RemoveNotifications()238 ErrCode NotificationHelper::RemoveNotifications()
239 {
240     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotifications();
241 }
242 
GetNotificationSlotsForBundle(const NotificationBundleOption & bundleOption,std::vector<sptr<NotificationSlot>> & slots)243 ErrCode NotificationHelper::GetNotificationSlotsForBundle(
244     const NotificationBundleOption &bundleOption, std::vector<sptr<NotificationSlot>> &slots)
245 {
246     return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotsForBundle(bundleOption, slots);
247 }
248 
UpdateNotificationSlots(const NotificationBundleOption & bundleOption,const std::vector<sptr<NotificationSlot>> & slots)249 ErrCode NotificationHelper::UpdateNotificationSlots(
250     const NotificationBundleOption &bundleOption, const std::vector<sptr<NotificationSlot>> &slots)
251 {
252     return DelayedSingleton<AnsNotification>::GetInstance()->UpdateNotificationSlots(bundleOption, slots);
253 }
254 
UpdateNotificationSlotGroups(const NotificationBundleOption & bundleOption,const std::vector<sptr<NotificationSlotGroup>> & groups)255 ErrCode NotificationHelper::UpdateNotificationSlotGroups(
256     const NotificationBundleOption &bundleOption, const std::vector<sptr<NotificationSlotGroup>> &groups)
257 {
258     return DelayedSingleton<AnsNotification>::GetInstance()->UpdateNotificationSlotGroups(bundleOption, groups);
259 }
260 
GetAllActiveNotifications(std::vector<sptr<Notification>> & notification)261 ErrCode NotificationHelper::GetAllActiveNotifications(std::vector<sptr<Notification>> &notification)
262 {
263     return DelayedSingleton<AnsNotification>::GetInstance()->GetAllActiveNotifications(notification);
264 }
265 
GetAllActiveNotifications(const std::vector<std::string> key,std::vector<sptr<Notification>> & notification)266 ErrCode NotificationHelper::GetAllActiveNotifications(
267     const std::vector<std::string> key, std::vector<sptr<Notification>> &notification)
268 {
269     return DelayedSingleton<AnsNotification>::GetInstance()->GetAllActiveNotifications(key, notification);
270 }
271 
IsAllowedNotify(const NotificationBundleOption & bundleOption,bool & allowed)272 ErrCode NotificationHelper::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed)
273 {
274     return DelayedSingleton<AnsNotification>::GetInstance()->IsAllowedNotify(bundleOption, allowed);
275 }
276 
SetNotificationsEnabledForAllBundles(const std::string & deviceId,bool enabled)277 ErrCode NotificationHelper::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled)
278 {
279     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForAllBundles(deviceId, enabled);
280 }
281 
SetNotificationsEnabledForDefaultBundle(const std::string & deviceId,bool enabled)282 ErrCode NotificationHelper::SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled)
283 {
284     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForDefaultBundle(deviceId, enabled);
285 }
286 
SetNotificationsEnabledForSpecifiedBundle(const NotificationBundleOption & bundleOption,std::string & deviceId,bool enabled)287 ErrCode NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
288     const NotificationBundleOption &bundleOption, std::string &deviceId, bool enabled)
289 {
290     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForSpecifiedBundle(
291         bundleOption, deviceId, enabled);
292 }
293 
SetShowBadgeEnabledForBundle(const NotificationBundleOption & bundleOption,bool enabled)294 ErrCode NotificationHelper::SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled)
295 {
296     return DelayedSingleton<AnsNotification>::GetInstance()->SetShowBadgeEnabledForBundle(bundleOption, enabled);
297 }
298 
GetShowBadgeEnabledForBundle(const NotificationBundleOption & bundleOption,bool & enabled)299 ErrCode NotificationHelper::GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled)
300 {
301     return DelayedSingleton<AnsNotification>::GetInstance()->GetShowBadgeEnabledForBundle(bundleOption, enabled);
302 }
303 
GetShowBadgeEnabled(bool & enabled)304 ErrCode NotificationHelper::GetShowBadgeEnabled(bool &enabled)
305 {
306     return DelayedSingleton<AnsNotification>::GetInstance()->GetShowBadgeEnabled(enabled);
307 }
308 
CancelGroup(const std::string & groupName)309 ErrCode NotificationHelper::CancelGroup(const std::string &groupName)
310 {
311     return DelayedSingleton<AnsNotification>::GetInstance()->CancelGroup(groupName);
312 }
313 
RemoveGroupByBundle(const NotificationBundleOption & bundleOption,const std::string & groupName)314 ErrCode NotificationHelper::RemoveGroupByBundle(
315     const NotificationBundleOption &bundleOption, const std::string &groupName)
316 {
317     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveGroupByBundle(bundleOption, groupName);
318 }
319 
SetDoNotDisturbDate(const NotificationDoNotDisturbDate & doNotDisturbDate)320 ErrCode NotificationHelper::SetDoNotDisturbDate(const NotificationDoNotDisturbDate &doNotDisturbDate)
321 {
322     return DelayedSingleton<AnsNotification>::GetInstance()->SetDoNotDisturbDate(doNotDisturbDate);
323 }
324 
GetDoNotDisturbDate(NotificationDoNotDisturbDate & doNotDisturbDate)325 ErrCode NotificationHelper::GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate)
326 {
327     return DelayedSingleton<AnsNotification>::GetInstance()->GetDoNotDisturbDate(doNotDisturbDate);
328 }
329 
DoesSupportDoNotDisturbMode(bool & doesSupport)330 ErrCode NotificationHelper::DoesSupportDoNotDisturbMode(bool &doesSupport)
331 {
332     return DelayedSingleton<AnsNotification>::GetInstance()->DoesSupportDoNotDisturbMode(doesSupport);
333 }
334 
IsDistributedEnabled(bool & enabled)335 ErrCode NotificationHelper::IsDistributedEnabled(bool &enabled)
336 {
337     return DelayedSingleton<AnsNotification>::GetInstance()->IsDistributedEnabled(enabled);
338 }
339 
EnableDistributed(const bool enabled)340 ErrCode NotificationHelper::EnableDistributed(const bool enabled)
341 {
342     return DelayedSingleton<AnsNotification>::GetInstance()->EnableDistributed(enabled);
343 }
344 
EnableDistributedByBundle(const NotificationBundleOption & bundleOption,const bool enabled)345 ErrCode NotificationHelper::EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled)
346 {
347     return DelayedSingleton<AnsNotification>::GetInstance()->EnableDistributedByBundle(bundleOption, enabled);
348 }
349 
EnableDistributedSelf(const bool enabled)350 ErrCode NotificationHelper::EnableDistributedSelf(const bool enabled)
351 {
352     return DelayedSingleton<AnsNotification>::GetInstance()->EnableDistributedSelf(enabled);
353 }
354 
IsDistributedEnableByBundle(const NotificationBundleOption & bundleOption,bool & enabled)355 ErrCode NotificationHelper::IsDistributedEnableByBundle(const NotificationBundleOption &bundleOption, bool &enabled)
356 {
357     return DelayedSingleton<AnsNotification>::GetInstance()->IsDistributedEnableByBundle(bundleOption, enabled);
358 }
359 
GetDeviceRemindType(NotificationConstant::RemindType & remindType)360 ErrCode NotificationHelper::GetDeviceRemindType(NotificationConstant::RemindType &remindType)
361 {
362     return DelayedSingleton<AnsNotification>::GetInstance()->GetDeviceRemindType(remindType);
363 }
364 
PublishContinuousTaskNotification(const NotificationRequest & request)365 ErrCode NotificationHelper::PublishContinuousTaskNotification(const NotificationRequest &request)
366 {
367     return DelayedSingleton<AnsNotification>::GetInstance()->PublishContinuousTaskNotification(request);
368 }
369 
CancelContinuousTaskNotification(const std::string & label,int32_t notificationId)370 ErrCode NotificationHelper::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId)
371 {
372     return DelayedSingleton<AnsNotification>::GetInstance()->CancelContinuousTaskNotification(label, notificationId);
373 }
374 
IsSupportTemplate(const std::string & templateName,bool & support)375 ErrCode NotificationHelper::IsSupportTemplate(const std::string &templateName, bool &support)
376 {
377     return DelayedSingleton<AnsNotification>::GetInstance()->IsSupportTemplate(templateName, support);
378 }
379 
IsAllowedNotify(const int32_t & userId,bool & allowed)380 ErrCode NotificationHelper::IsAllowedNotify(const int32_t &userId, bool &allowed)
381 {
382     return DelayedSingleton<AnsNotification>::GetInstance()->IsAllowedNotify(userId, allowed);
383 }
384 
SetNotificationsEnabledForAllBundles(const int32_t & userId,bool enabled)385 ErrCode NotificationHelper::SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled)
386 {
387     return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForAllBundles(
388         userId, enabled);
389 }
390 
RemoveNotifications(const int32_t & userId)391 ErrCode NotificationHelper::RemoveNotifications(const int32_t &userId)
392 {
393     return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotifications(userId);
394 }
395 
SetDoNotDisturbDate(const int32_t & userId,const NotificationDoNotDisturbDate & doNotDisturbDate)396 ErrCode NotificationHelper::SetDoNotDisturbDate(const int32_t &userId,
397     const NotificationDoNotDisturbDate &doNotDisturbDate)
398 {
399     return DelayedSingleton<AnsNotification>::GetInstance()->SetDoNotDisturbDate(userId, doNotDisturbDate);
400 }
401 
GetDoNotDisturbDate(const int32_t & userId,NotificationDoNotDisturbDate & doNotDisturbDate)402 ErrCode NotificationHelper::GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate)
403 {
404     return DelayedSingleton<AnsNotification>::GetInstance()->GetDoNotDisturbDate(userId, doNotDisturbDate);
405 }
406 }  // namespace Notification
407 }  // namespace OHOS