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