• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <unistd.h>
17 
18 #include "ans_const_define.h"
19 #include "ans_inner_errors.h"
20 #include "ans_log_wrapper.h"
21 #include "message_option.h"
22 #include "message_parcel.h"
23 #include "parcel.h"
24 #include "reminder_request_alarm.h"
25 #include "reminder_request_calendar.h"
26 #include "reminder_request_timer.h"
27 #include "ans_manager_proxy.h"
28 
29 namespace OHOS {
30 namespace Notification {
AnsManagerProxy(const sptr<IRemoteObject> & impl)31 AnsManagerProxy::AnsManagerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<AnsManagerInterface>(impl)
32 {}
33 
~AnsManagerProxy()34 AnsManagerProxy::~AnsManagerProxy()
35 {}
36 
Publish(const std::string & label,const sptr<NotificationRequest> & notification)37 ErrCode AnsManagerProxy::Publish(const std::string &label, const sptr<NotificationRequest> &notification)
38 {
39     if (notification == nullptr) {
40         ANS_LOGE("[Publish] fail: notification is null ptr.");
41         return ERR_ANS_INVALID_PARAM;
42     }
43 
44     MessageParcel data;
45     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
46         ANS_LOGE("[Publish] fail: write interface token failed.");
47         return ERR_ANS_PARCELABLE_FAILED;
48     }
49 
50     if (!data.WriteString(label)) {
51         ANS_LOGE("[Publish] fail: write label failed.");
52         return ERR_ANS_PARCELABLE_FAILED;
53     }
54 
55     if (!data.WriteParcelable(notification)) {
56         ANS_LOGE("[Publish] fail: write notification parcelable failed");
57         return ERR_ANS_PARCELABLE_FAILED;
58     }
59 
60     MessageParcel reply;
61     MessageOption option = {MessageOption::TF_SYNC};
62     ErrCode result = InnerTransact(PUBLISH_NOTIFICATION, option, data, reply);
63     if (result != ERR_OK) {
64         ANS_LOGE("[Publish] fail: transact ErrCode=%{public}d", result);
65         return ERR_ANS_TRANSACT_FAILED;
66     }
67 
68     if (!reply.ReadInt32(result)) {
69         ANS_LOGE("[Publish] fail: read result failed.");
70         return ERR_ANS_PARCELABLE_FAILED;
71     }
72 
73     return result;
74 }
75 
PublishToDevice(const sptr<NotificationRequest> & notification,const std::string & deviceId)76 ErrCode AnsManagerProxy::PublishToDevice(const sptr<NotificationRequest> &notification, const std::string &deviceId)
77 {
78     if (notification == nullptr) {
79         ANS_LOGE("[PublishToDevice] fail: notification is null ptr.");
80         return ERR_ANS_INVALID_PARAM;
81     }
82 
83     MessageParcel data;
84     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
85         ANS_LOGE("[PublishToDevice] fail: write interface token failed.");
86         return ERR_ANS_PARCELABLE_FAILED;
87     }
88 
89     if (!data.WriteParcelable(notification)) {
90         ANS_LOGE("[PublishToDevice] fail: write notification parcelable failed.");
91         return ERR_ANS_PARCELABLE_FAILED;
92     }
93 
94     if (!data.WriteString(deviceId)) {
95         ANS_LOGE("[PublishToDevice] fail: write deviceId failed");
96         return ERR_ANS_PARCELABLE_FAILED;
97     }
98 
99     MessageParcel reply;
100     MessageOption option = {MessageOption::TF_SYNC};
101     ErrCode result = InnerTransact(PUBLISH_NOTIFICATION_TO_DEVICE, option, data, reply);
102     if (result != ERR_OK) {
103         ANS_LOGE("[PublishToDevice] fail: transact ErrCode=%{public}d", result);
104         return ERR_ANS_TRANSACT_FAILED;
105     }
106 
107     if (!reply.ReadInt32(result)) {
108         ANS_LOGE("[PublishToDevice] fail: read result failed.");
109         return ERR_ANS_PARCELABLE_FAILED;
110     }
111 
112     return result;
113 }
114 
Cancel(int32_t notificationId,const std::string & label)115 ErrCode AnsManagerProxy::Cancel(int32_t notificationId, const std::string &label)
116 {
117     MessageParcel data;
118     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
119         ANS_LOGE("[Cancel] fail: write interface token failed.");
120         return ERR_ANS_PARCELABLE_FAILED;
121     }
122 
123     if (!data.WriteInt32(notificationId)) {
124         ANS_LOGE("[Cancel] fail: write notificationId failed");
125         return ERR_ANS_PARCELABLE_FAILED;
126     }
127 
128     if (!data.WriteString(label)) {
129         ANS_LOGE("[Cancel] fail: write label failed");
130         return ERR_ANS_PARCELABLE_FAILED;
131     }
132 
133     MessageParcel reply;
134     MessageOption option = {MessageOption::TF_SYNC};
135     ErrCode result = InnerTransact(CANCEL_NOTIFICATION, option, data, reply);
136     if (result != ERR_OK) {
137         ANS_LOGE("[Cancel] fail: transact ErrCode=%{public}d", result);
138         return ERR_ANS_TRANSACT_FAILED;
139     }
140 
141     if (!reply.ReadInt32(result)) {
142         ANS_LOGE("[Cancel] fail: read result failed.");
143         return ERR_ANS_PARCELABLE_FAILED;
144     }
145 
146     return result;
147 }
148 
CancelAll()149 ErrCode AnsManagerProxy::CancelAll()
150 {
151     MessageParcel data;
152     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
153         ANS_LOGE("[CancelAll] fail: write interface token failed.");
154         return ERR_ANS_PARCELABLE_FAILED;
155     }
156 
157     MessageParcel reply;
158     MessageOption option = {MessageOption::TF_SYNC};
159     ErrCode result = InnerTransact(CANCEL_ALL_NOTIFICATIONS, option, data, reply);
160     if (result != ERR_OK) {
161         ANS_LOGE("[CancelAll] fail: transact ErrCode=%{public}d", result);
162         return ERR_ANS_TRANSACT_FAILED;
163     }
164 
165     if (!reply.ReadInt32(result)) {
166         ANS_LOGE("[CancelAll] fail: read result failed.");
167         return ERR_ANS_PARCELABLE_FAILED;
168     }
169 
170     return result;
171 }
172 
CancelAsBundle(int32_t notificationId,const std::string & representativeBundle,int32_t userId)173 ErrCode AnsManagerProxy::CancelAsBundle(
174     int32_t notificationId, const std::string &representativeBundle, int32_t userId)
175 {
176     MessageParcel data;
177     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
178         ANS_LOGE("[CancelAsBundle] fail: write interface token failed.");
179         return ERR_ANS_PARCELABLE_FAILED;
180     }
181 
182     if (!data.WriteInt32(notificationId)) {
183         ANS_LOGE("[CancelAsBundle] fail: write notificationId failed");
184         return ERR_ANS_PARCELABLE_FAILED;
185     }
186 
187     if (!data.WriteString(representativeBundle)) {
188         ANS_LOGE("[CancelAsBundle] fail: write representativeBundle failed");
189         return ERR_ANS_PARCELABLE_FAILED;
190     }
191 
192     if (!data.WriteInt32(userId)) {
193         ANS_LOGE("[CancelAsBundle] fail: write userId failed");
194         return ERR_ANS_PARCELABLE_FAILED;
195     }
196 
197     MessageParcel reply;
198     MessageOption option = {MessageOption::TF_SYNC};
199     ErrCode result = InnerTransact(CANCEL_AS_BUNDLE, option, data, reply);
200     if (result != ERR_OK) {
201         ANS_LOGE("[CancelAsBundle] fail: transact ErrCode=%{public}d", result);
202         return ERR_ANS_TRANSACT_FAILED;
203     }
204 
205     if (!reply.ReadInt32(result)) {
206         ANS_LOGE("[CancelAsBundle] fail: read result failed.");
207         return ERR_ANS_PARCELABLE_FAILED;
208     }
209 
210     return result;
211 }
212 
AddSlotByType(NotificationConstant::SlotType slotType)213 ErrCode AnsManagerProxy::AddSlotByType(NotificationConstant::SlotType slotType)
214 {
215     MessageParcel data;
216     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
217         ANS_LOGE("[AddSlotByType] fail: write interface token failed.");
218         return ERR_ANS_PARCELABLE_FAILED;
219     }
220 
221     if (!data.WriteInt32(slotType)) {
222         ANS_LOGE("[AddSlotByType] fail:: write slotIds failed.");
223         return ERR_ANS_PARCELABLE_FAILED;
224     }
225 
226     MessageParcel reply;
227     MessageOption option = {MessageOption::TF_SYNC};
228     ErrCode result = InnerTransact(ADD_SLOT_BY_TYPE, option, data, reply);
229     if (result != ERR_OK) {
230         ANS_LOGE("[AddSlotByType] fail: transact ErrCode=%{public}d", result);
231         return ERR_ANS_TRANSACT_FAILED;
232     }
233 
234     if (!reply.ReadInt32(result)) {
235         ANS_LOGE("[AddSlotByType] fail: read result failed.");
236         return ERR_ANS_PARCELABLE_FAILED;
237     }
238 
239     return result;
240 }
241 
AddSlots(const std::vector<sptr<NotificationSlot>> & slots)242 ErrCode AnsManagerProxy::AddSlots(const std::vector<sptr<NotificationSlot>> &slots)
243 {
244     if (slots.empty()) {
245         ANS_LOGE("[AddSlots] fail: slots is empty.");
246         return ERR_ANS_INVALID_PARAM;
247     }
248 
249     size_t slotsSize = slots.size();
250     if (slotsSize > MAX_SLOT_NUM) {
251         ANS_LOGE("[AddSlots] fail: slotsSize over max size.");
252         return ERR_ANS_INVALID_PARAM;
253     }
254 
255     MessageParcel data;
256     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
257         ANS_LOGE("[AddSlots] fail: write interface token failed.");
258         return ERR_ANS_PARCELABLE_FAILED;
259     }
260 
261     if (!WriteParcelableVector(slots, data)) {
262         ANS_LOGE("[AddSlots] fail: write slots failed");
263         return ERR_ANS_PARCELABLE_FAILED;
264     }
265 
266     MessageParcel reply;
267     MessageOption option = {MessageOption::TF_SYNC};
268     ErrCode result = InnerTransact(ADD_SLOTS, option, data, reply);
269     if (result != ERR_OK) {
270         ANS_LOGE("[AddSlots] fail: transact ErrCode=%{public}d", result);
271         return ERR_ANS_TRANSACT_FAILED;
272     }
273 
274     if (!reply.ReadInt32(result)) {
275         ANS_LOGE("[AddSlots] fail: read result failed.");
276         return ERR_ANS_PARCELABLE_FAILED;
277     }
278 
279     return result;
280 }
281 
RemoveSlotByType(const NotificationConstant::SlotType & slotType)282 ErrCode AnsManagerProxy::RemoveSlotByType(const NotificationConstant::SlotType &slotType)
283 {
284     MessageParcel data;
285     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
286         ANS_LOGE("[RemoveSlotByType] fail: write interface token failed.");
287         return ERR_ANS_PARCELABLE_FAILED;
288     }
289 
290     if (!data.WriteInt32(slotType)) {
291         ANS_LOGE("[RemoveSlotByType] fail:: write slotIds failed.");
292         return ERR_ANS_PARCELABLE_FAILED;
293     }
294 
295     MessageParcel reply;
296     MessageOption option = {MessageOption::TF_SYNC};
297     ErrCode result = InnerTransact(REMOVE_SLOT_BY_TYPE, option, data, reply);
298     if (result != ERR_OK) {
299         ANS_LOGE("[RemoveSlotByType] fail: transact ErrCode=%{public}d", result);
300         return ERR_ANS_TRANSACT_FAILED;
301     }
302 
303     if (!reply.ReadInt32(result)) {
304         ANS_LOGE("[RemoveSlotByType] fail: read result failed.");
305         return ERR_ANS_PARCELABLE_FAILED;
306     }
307 
308     return result;
309 }
310 
RemoveAllSlots()311 ErrCode AnsManagerProxy::RemoveAllSlots()
312 {
313     MessageParcel data;
314     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
315         ANS_LOGE("[RemoveAllSlots] fail: write interface token failed.");
316         return ERR_ANS_PARCELABLE_FAILED;
317     }
318 
319     MessageParcel reply;
320     MessageOption option = {MessageOption::TF_SYNC};
321     ErrCode result = InnerTransact(REMOVE_ALL_SLOTS, option, data, reply);
322     if (result != ERR_OK) {
323         ANS_LOGE("[RemoveAllSlots] fail: transact ErrCode=%{public}d", result);
324         return ERR_ANS_TRANSACT_FAILED;
325     }
326 
327     if (!reply.ReadInt32(result)) {
328         ANS_LOGE("[RemoveAllSlots] fail: read result failed.");
329         return ERR_ANS_PARCELABLE_FAILED;
330     }
331 
332     return result;
333 }
334 
GetSlotByType(const NotificationConstant::SlotType & slotType,sptr<NotificationSlot> & slot)335 ErrCode AnsManagerProxy::GetSlotByType(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot)
336 {
337     MessageParcel data;
338     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
339         ANS_LOGE("[GetSlotByType] fail: write interface token failed.");
340         return ERR_ANS_PARCELABLE_FAILED;
341     }
342 
343     if (!data.WriteInt32(slotType)) {
344         ANS_LOGE("[GetSlotByType] fail:: write slotId failed");
345         return ERR_ANS_PARCELABLE_FAILED;
346     }
347 
348     MessageParcel reply;
349     MessageOption option = {MessageOption::TF_SYNC};
350     ErrCode result = InnerTransact(GET_SLOT_BY_TYPE, option, data, reply);
351     if (result != ERR_OK) {
352         ANS_LOGE("[GetSlotByType] fail: transact ErrCode=%{public}d", result);
353         return ERR_ANS_TRANSACT_FAILED;
354     }
355 
356     if (!reply.ReadInt32(result)) {
357         ANS_LOGE("[GetSlotByType] fail: read result failed.");
358         return ERR_ANS_PARCELABLE_FAILED;
359     }
360 
361     if (result == ERR_OK) {
362         slot = reply.ReadParcelable<NotificationSlot>();
363         if (slot == nullptr) {
364             ANS_LOGE("[GetSlotByType] slot is null");
365         }
366     }
367 
368     return result;
369 }
370 
GetSlots(std::vector<sptr<NotificationSlot>> & slots)371 ErrCode AnsManagerProxy::GetSlots(std::vector<sptr<NotificationSlot>> &slots)
372 {
373     MessageParcel data;
374     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
375         ANS_LOGE("[GetSlots] fail: write interface token failed.");
376         return ERR_ANS_PARCELABLE_FAILED;
377     }
378 
379     MessageParcel reply;
380     MessageOption option = {MessageOption::TF_SYNC};
381     ErrCode result = InnerTransact(GET_SLOTS, option, data, reply);
382     if (result != ERR_OK) {
383         ANS_LOGE("[GetSlots] fail: transact ErrCode=%{public}d", result);
384         return ERR_ANS_TRANSACT_FAILED;
385     }
386 
387     if (!ReadParcelableVector(slots, reply, result)) {
388         ANS_LOGE("[GetSlots] fail: read slots failed.");
389         return ERR_ANS_PARCELABLE_FAILED;
390     }
391 
392     return result;
393 }
394 
GetSlotNumAsBundle(const sptr<NotificationBundleOption> & bundleOption,uint64_t & num)395 ErrCode AnsManagerProxy::GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num)
396 {
397     if (bundleOption == nullptr) {
398         ANS_LOGE("[GetSlotNumAsBundle] fail: bundle is empty.");
399         return ERR_ANS_INVALID_PARAM;
400     }
401 
402     MessageParcel data;
403     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
404         ANS_LOGE("[GetSlotNumAsBundle] fail: write interface token failed.");
405         return ERR_ANS_PARCELABLE_FAILED;
406     }
407 
408     if (!data.WriteStrongParcelable(bundleOption)) {
409         ANS_LOGE("[GetSlotNumAsBundle] fail:: write bundle failed");
410         return ERR_ANS_PARCELABLE_FAILED;
411     }
412 
413     MessageParcel reply;
414     MessageOption option = {MessageOption::TF_SYNC};
415     ErrCode result = InnerTransact(GET_SLOT_NUM_AS_BUNDLE, option, data, reply);
416     if (result != ERR_OK) {
417         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: transact ErrCode=%{public}d", result);
418         return ERR_ANS_TRANSACT_FAILED;
419     }
420 
421     if (!reply.ReadInt32(result)) {
422         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read result failed.");
423         return ERR_ANS_PARCELABLE_FAILED;
424     }
425 
426     if (!reply.ReadUint64(num)) {
427         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read enabled failed.");
428         return ERR_ANS_PARCELABLE_FAILED;
429     }
430 
431     return result;
432 }
433 
GetActiveNotifications(std::vector<sptr<NotificationRequest>> & notifications)434 ErrCode AnsManagerProxy::GetActiveNotifications(std::vector<sptr<NotificationRequest>> &notifications)
435 {
436     MessageParcel data;
437     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
438         ANS_LOGE("[GetActiveNotifications] fail: write interface token failed.");
439         return ERR_ANS_PARCELABLE_FAILED;
440     }
441 
442     MessageParcel reply;
443     MessageOption option = {MessageOption::TF_SYNC};
444     ErrCode result = InnerTransact(GET_ACTIVE_NOTIFICATIONS, option, data, reply);
445     if (result != ERR_OK) {
446         ANS_LOGE("[GetActiveNotifications] fail: transact ErrCode=%{public}d", result);
447         return ERR_ANS_TRANSACT_FAILED;
448     }
449 
450     if (!ReadParcelableVector(notifications, reply, result)) {
451         ANS_LOGE("[GetActiveNotifications] fail: read notifications failed.");
452         return ERR_ANS_PARCELABLE_FAILED;
453     }
454 
455     return result;
456 }
457 
GetActiveNotificationNums(uint64_t & num)458 ErrCode AnsManagerProxy::GetActiveNotificationNums(uint64_t &num)
459 {
460     MessageParcel data;
461     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
462         ANS_LOGE("[GetActiveNotificationNums] fail: write interface token failed.");
463         return ERR_ANS_PARCELABLE_FAILED;
464     }
465 
466     MessageParcel reply;
467     MessageOption option = {MessageOption::TF_SYNC};
468     ErrCode result = InnerTransact(GET_ACTIVE_NOTIFICATION_NUMS, option, data, reply);
469     if (result != ERR_OK) {
470         ANS_LOGE("[GetActiveNotificationNums] fail: transact ErrCode=%{public}d", result);
471         return ERR_ANS_TRANSACT_FAILED;
472     }
473 
474     if (!reply.ReadInt32(result)) {
475         ANS_LOGE("[GetActiveNotificationNums] fail: read result failed.");
476         return ERR_ANS_PARCELABLE_FAILED;
477     }
478 
479     if (!reply.ReadUint64(num)) {
480         ANS_LOGE("[GetActiveNotificationNums] fail: read notification num failed.");
481         return ERR_ANS_PARCELABLE_FAILED;
482     }
483 
484     return result;
485 }
486 
GetAllActiveNotifications(std::vector<sptr<Notification>> & notifications)487 ErrCode AnsManagerProxy::GetAllActiveNotifications(std::vector<sptr<Notification>> &notifications)
488 {
489     MessageParcel data;
490     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
491         ANS_LOGE("[GetAllActiveNotifications] fail: write interface token failed.");
492         return ERR_ANS_PARCELABLE_FAILED;
493     }
494 
495     MessageParcel reply;
496     MessageOption option = {MessageOption::TF_SYNC};
497     ErrCode result = InnerTransact(GET_ALL_ACTIVE_NOTIFICATIONS, option, data, reply);
498     if (result != ERR_OK) {
499         ANS_LOGE("[GetAllActiveNotifications] fail: transact ErrCode=%{public}d", result);
500         return ERR_ANS_TRANSACT_FAILED;
501     }
502 
503     if (!ReadParcelableVector(notifications, reply, result)) {
504         ANS_LOGE("[GetAllActiveNotifications] fail: read notifications failed.");
505         return ERR_ANS_PARCELABLE_FAILED;
506     }
507 
508     return result;
509 }
510 
GetSpecialActiveNotifications(const std::vector<std::string> & key,std::vector<sptr<Notification>> & notifications)511 ErrCode AnsManagerProxy::GetSpecialActiveNotifications(
512     const std::vector<std::string> &key, std::vector<sptr<Notification>> &notifications)
513 {
514     if (key.empty()) {
515         ANS_LOGE("[GetSpecialActiveNotifications] fail: key is empty.");
516         return ERR_ANS_INVALID_PARAM;
517     }
518 
519     MessageParcel data;
520     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
521         ANS_LOGE("[GetSpecialActiveNotifications] fail: write interface token failed.");
522         return ERR_ANS_PARCELABLE_FAILED;
523     }
524 
525     if (!data.WriteStringVector(key)) {
526         ANS_LOGE("[GetSpecialActiveNotifications] fail:: write key failed");
527         return ERR_ANS_PARCELABLE_FAILED;
528     }
529 
530     MessageParcel reply;
531     MessageOption option = {MessageOption::TF_SYNC};
532     ErrCode result = InnerTransact(GET_SPECIAL_ACTIVE_NOTIFICATIONS, option, data, reply);
533     if (result != ERR_OK) {
534         ANS_LOGE("[GetSpecialActiveNotifications] fail: transact ErrCode=%{public}d", result);
535         return ERR_ANS_TRANSACT_FAILED;
536     }
537 
538     if (!ReadParcelableVector(notifications, reply, result)) {
539         ANS_LOGE("[GetSpecialActiveNotifications] fail: read notifications failed.");
540         return ERR_ANS_PARCELABLE_FAILED;
541     }
542 
543     return result;
544 }
545 
SetNotificationAgent(const std::string & agent)546 ErrCode AnsManagerProxy::SetNotificationAgent(const std::string &agent)
547 {
548     if (agent.empty()) {
549         ANS_LOGE("[SetNotificationAgent] fail: agent is null.");
550         return ERR_ANS_INVALID_PARAM;
551     }
552 
553     MessageParcel data;
554     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
555         ANS_LOGE("[SetNotificationAgent] fail: write interface token failed.");
556         return ERR_ANS_PARCELABLE_FAILED;
557     }
558 
559     if (!data.WriteString(agent)) {
560         ANS_LOGE("[SetNotificationAgent] fail:: write agent failed.");
561         return ERR_ANS_PARCELABLE_FAILED;
562     }
563 
564     MessageParcel reply;
565     MessageOption option = {MessageOption::TF_SYNC};
566     ErrCode result = InnerTransact(SET_NOTIFICATION_AGENT, option, data, reply);
567     if (result != ERR_OK) {
568         ANS_LOGE("[SetNotificationAgent] fail: transact ErrCode=%{public}d", result);
569         return ERR_ANS_TRANSACT_FAILED;
570     }
571 
572     if (!reply.ReadInt32(result)) {
573         ANS_LOGE("[SetNotificationAgent] fail: read result failed.");
574         return ERR_ANS_PARCELABLE_FAILED;
575     }
576 
577     return result;
578 }
579 
GetNotificationAgent(std::string & agent)580 ErrCode AnsManagerProxy::GetNotificationAgent(std::string &agent)
581 {
582     MessageParcel data;
583     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
584         ANS_LOGE("[GetNotificationAgent] fail: write interface token failed.");
585         return ERR_ANS_PARCELABLE_FAILED;
586     }
587 
588     MessageParcel reply;
589     MessageOption option = {MessageOption::TF_SYNC};
590     ErrCode result = InnerTransact(GET_NOTIFICATION_AGENT, option, data, reply);
591     if (result != ERR_OK) {
592         ANS_LOGE("[GetNotificationAgent] fail: transact ErrCode=%{public}d", result);
593         return ERR_ANS_TRANSACT_FAILED;
594     }
595 
596     if (!reply.ReadInt32(result)) {
597         ANS_LOGE("[GetNotificationAgent] fail: read result failed.");
598         return ERR_ANS_PARCELABLE_FAILED;
599     }
600 
601     if (!reply.ReadString(agent)) {
602         ANS_LOGE("[GetNotificationAgent] fail: read agent failed.");
603         return ERR_ANS_PARCELABLE_FAILED;
604     }
605 
606     return result;
607 }
608 
CanPublishAsBundle(const std::string & representativeBundle,bool & canPublish)609 ErrCode AnsManagerProxy::CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish)
610 {
611     if (representativeBundle.empty()) {
612         ANS_LOGE("[CanPublishAsBundle] fail: representativeBundle is null.");
613         return ERR_ANS_INVALID_PARAM;
614     }
615 
616     MessageParcel data;
617     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
618         ANS_LOGE("[CanPublishAsBundle] fail: write interface token failed.");
619         return ERR_ANS_PARCELABLE_FAILED;
620     }
621 
622     if (!data.WriteString(representativeBundle)) {
623         ANS_LOGE("[CanPublishAsBundle] fail: write representativeBundle failed.");
624         return ERR_ANS_PARCELABLE_FAILED;
625     }
626 
627     MessageParcel reply;
628     MessageOption option = {MessageOption::TF_SYNC};
629     ErrCode result = InnerTransact(CAN_PUBLISH_AS_BUNDLE, option, data, reply);
630     if (result != ERR_OK) {
631         ANS_LOGE("[CanPublishAsBundle] fail: transact ErrCode=%{public}d", result);
632         return ERR_ANS_TRANSACT_FAILED;
633     }
634 
635     if (!reply.ReadInt32(result)) {
636         ANS_LOGE("[CanPublishAsBundle] fail: read result failed.");
637         return ERR_ANS_PARCELABLE_FAILED;
638     }
639 
640     if (!reply.ReadBool(canPublish)) {
641         ANS_LOGE("[CanPublishAsBundle] fail: read canPublish failed.");
642         return ERR_ANS_PARCELABLE_FAILED;
643     }
644 
645     return result;
646 }
647 
PublishAsBundle(const sptr<NotificationRequest> notification,const std::string & representativeBundle)648 ErrCode AnsManagerProxy::PublishAsBundle(
649     const sptr<NotificationRequest> notification, const std::string &representativeBundle)
650 {
651     if (notification == nullptr) {
652         ANS_LOGE("[PublishAsBundle] fail: notification is null ptr.");
653         return ERR_ANS_INVALID_PARAM;
654     }
655 
656     if (representativeBundle.empty()) {
657         ANS_LOGE("[PublishAsBundle] fail: representativeBundle is empty.");
658         return ERR_ANS_INVALID_PARAM;
659     }
660 
661     MessageParcel data;
662     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
663         ANS_LOGE("[PublishAsBundle] fail: write interface token failed.");
664         return ERR_ANS_PARCELABLE_FAILED;
665     }
666 
667     if (!data.WriteParcelable(notification)) {
668         ANS_LOGE("[PublishAsBundle] fail: write notification failed.");
669         return ERR_ANS_PARCELABLE_FAILED;
670     }
671 
672     if (!data.WriteString(representativeBundle)) {
673         ANS_LOGE("[PublishAsBundle] fail: write representativeBundle failed.");
674         return ERR_ANS_PARCELABLE_FAILED;
675     }
676 
677     MessageParcel reply;
678     MessageOption option = {MessageOption::TF_SYNC};
679     ErrCode result = InnerTransact(PUBLISH_AS_BUNDLE, option, data, reply);
680     if (result != ERR_OK) {
681         ANS_LOGE("[PublishAsBundle] fail: transact ErrCode=%{public}d", result);
682         return ERR_ANS_TRANSACT_FAILED;
683     }
684 
685     if (!reply.ReadInt32(result)) {
686         ANS_LOGE("[PublishAsBundle] fail: read result failed.");
687         return ERR_ANS_PARCELABLE_FAILED;
688     }
689 
690     return result;
691 }
692 
SetNotificationBadgeNum(int32_t num)693 ErrCode AnsManagerProxy::SetNotificationBadgeNum(int32_t num)
694 {
695     MessageParcel data;
696     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
697         ANS_LOGE("[SetNotificationBadgeNum] fail: write interface token failed.");
698         return ERR_ANS_PARCELABLE_FAILED;
699     }
700 
701     if (!data.WriteInt32(num)) {
702         ANS_LOGE("[SetNotificationBadgeNum] fail: write num failed.");
703         return ERR_ANS_PARCELABLE_FAILED;
704     }
705 
706     MessageParcel reply;
707     MessageOption option = {MessageOption::TF_SYNC};
708     ErrCode result = InnerTransact(SET_NOTIFICATION_BADGE_NUM, option, data, reply);
709     if (result != ERR_OK) {
710         ANS_LOGE("[SetNotificationBadgeNum] fail: transact ErrCode=%{public}d", result);
711         return ERR_ANS_TRANSACT_FAILED;
712     }
713 
714     if (!reply.ReadInt32(result)) {
715         ANS_LOGE("[SetNotificationBadgeNum] fail: read result failed.");
716         return ERR_ANS_PARCELABLE_FAILED;
717     }
718 
719     return result;
720 }
721 
GetBundleImportance(int32_t & importance)722 ErrCode AnsManagerProxy::GetBundleImportance(int32_t &importance)
723 {
724     MessageParcel data;
725     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
726         ANS_LOGE("[GetBundleImportance] fail: write interface token failed.");
727         return ERR_ANS_PARCELABLE_FAILED;
728     }
729 
730     MessageParcel reply;
731     MessageOption option = {MessageOption::TF_SYNC};
732     ErrCode result = InnerTransact(GET_BUNDLE_IMPORTANCE, option, data, reply);
733     if (result != ERR_OK) {
734         ANS_LOGE("[GetBundleImportance] fail: transact ErrCode=%{public}d", result);
735         return ERR_ANS_TRANSACT_FAILED;
736     }
737 
738     if (!reply.ReadInt32(result)) {
739         ANS_LOGE("[GetBundleImportance] fail: read result failed.");
740         return ERR_ANS_PARCELABLE_FAILED;
741     }
742 
743     if (!reply.ReadInt32(importance)) {
744         ANS_LOGE("[GetBundleImportance] fail: read importance failed.");
745         return ERR_ANS_PARCELABLE_FAILED;
746     }
747 
748     return result;
749 }
750 
HasNotificationPolicyAccessPermission(bool & granted)751 ErrCode AnsManagerProxy::HasNotificationPolicyAccessPermission(bool &granted)
752 {
753     MessageParcel data;
754     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
755         ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: write interface token failed.");
756         return ERR_ANS_PARCELABLE_FAILED;
757     }
758 
759     MessageParcel reply;
760     MessageOption option = {MessageOption::TF_SYNC};
761     ErrCode result = InnerTransact(IS_NOTIFICATION_POLICY_ACCESS_GRANTED, option, data, reply);
762     if (result != ERR_OK) {
763         ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: transact ErrCode=%{public}d", result);
764         return ERR_ANS_TRANSACT_FAILED;
765     }
766 
767     if (!reply.ReadInt32(result)) {
768         ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: read result failed.");
769         return ERR_ANS_PARCELABLE_FAILED;
770     }
771 
772     if (!reply.ReadBool(granted)) {
773         ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: read granted failed.");
774         return ERR_ANS_PARCELABLE_FAILED;
775     }
776 
777     return result;
778 }
779 
SetPrivateNotificationsAllowed(bool allow)780 ErrCode AnsManagerProxy::SetPrivateNotificationsAllowed(bool allow)
781 {
782     MessageParcel data;
783     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
784         ANS_LOGE("[SetPrivateNotificationsAllowed] fail: write interface token failed.");
785         return ERR_ANS_PARCELABLE_FAILED;
786     }
787 
788     if (!data.WriteBool(allow)) {
789         ANS_LOGE("[SetPrivateNotificationsAllowed] fail: write allow failed");
790         return ERR_ANS_PARCELABLE_FAILED;
791     }
792 
793     MessageParcel reply;
794     MessageOption option = {MessageOption::TF_SYNC};
795     ErrCode result = InnerTransact(SET_PRIVATIVE_NOTIFICATIONS_ALLOWED, option, data, reply);
796     if (result != ERR_OK) {
797         ANS_LOGE("[SetPrivateNotificationsAllowed] fail: transact ErrCode=%{public}d", result);
798         return ERR_ANS_TRANSACT_FAILED;
799     }
800 
801     if (!reply.ReadInt32(result)) {
802         ANS_LOGE("[SetPrivateNotificationsAllowed] fail: read result failed.");
803         return ERR_ANS_PARCELABLE_FAILED;
804     }
805 
806     return result;
807 }
808 
GetPrivateNotificationsAllowed(bool & allow)809 ErrCode AnsManagerProxy::GetPrivateNotificationsAllowed(bool &allow)
810 {
811     MessageParcel data;
812     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
813         ANS_LOGE("[GetPrivateNotificationsAllowed] fail: write interface token failed.");
814         return ERR_ANS_PARCELABLE_FAILED;
815     }
816 
817     MessageParcel reply;
818     MessageOption option = {MessageOption::TF_SYNC};
819     ErrCode result = InnerTransact(GET_PRIVATIVE_NOTIFICATIONS_ALLOWED, option, data, reply);
820     if (result != ERR_OK) {
821         ANS_LOGE("[GetPrivateNotificationsAllowed] fail: transact ErrCode=%{public}d", result);
822         return ERR_ANS_TRANSACT_FAILED;
823     }
824 
825     if (!reply.ReadInt32(result)) {
826         ANS_LOGE("[GetPrivateNotificationsAllowed] fail: read result failed.");
827         return ERR_ANS_PARCELABLE_FAILED;
828     }
829 
830     if (!reply.ReadBool(allow)) {
831         ANS_LOGE("[GetPrivateNotificationsAllowed] fail: read allow failed.");
832         return ERR_ANS_PARCELABLE_FAILED;
833     }
834 
835     return result;
836 }
837 
RemoveNotification(const sptr<NotificationBundleOption> & bundleOption,int32_t notificationId,const std::string & label,int32_t removeReason)838 ErrCode AnsManagerProxy::RemoveNotification(const sptr<NotificationBundleOption> &bundleOption,
839     int32_t notificationId, const std::string &label, int32_t removeReason)
840 {
841     if (bundleOption == nullptr) {
842         ANS_LOGE("[RemoveNotification] fail: bundle is empty.");
843         return ERR_ANS_INVALID_PARAM;
844     }
845 
846     MessageParcel data;
847     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
848         ANS_LOGE("[RemoveNotification] fail:, write interface token failed.");
849         return ERR_ANS_PARCELABLE_FAILED;
850     }
851 
852     if (!data.WriteStrongParcelable(bundleOption)) {
853         ANS_LOGE("[RemoveNotification] fail:: write bundle failed");
854         return ERR_ANS_PARCELABLE_FAILED;
855     }
856 
857     if (!data.WriteInt32(notificationId)) {
858         ANS_LOGE("[RemoveNotification] fail: write notificationId failed");
859         return ERR_ANS_PARCELABLE_FAILED;
860     }
861 
862     if (!data.WriteString(label)) {
863         ANS_LOGE("[RemoveNotification] fail: write label failed");
864         return ERR_ANS_PARCELABLE_FAILED;
865     }
866 
867     if (!data.WriteInt32(removeReason)) {
868         ANS_LOGE("[RemoveNotification] fail: write removeReason failed");
869         return ERR_ANS_PARCELABLE_FAILED;
870     }
871 
872     MessageParcel reply;
873     MessageOption option = {MessageOption::TF_SYNC};
874     ErrCode result = InnerTransact(REMOVE_NOTIFICATION, option, data, reply);
875     if (result != ERR_OK) {
876         ANS_LOGE("[RemoveNotification] fail: transact ErrCode=%{public}d", result);
877         return ERR_ANS_TRANSACT_FAILED;
878     }
879 
880     if (!reply.ReadInt32(result)) {
881         ANS_LOGE("[RemoveNotification] fail: read result failed.");
882         return ERR_ANS_PARCELABLE_FAILED;
883     }
884 
885     return result;
886 }
887 
RemoveAllNotifications(const sptr<NotificationBundleOption> & bundleOption)888 ErrCode AnsManagerProxy::RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption)
889 {
890     if (bundleOption == nullptr) {
891         ANS_LOGE("[RemoveAllNotifications] fail: bundle is empty.");
892         return ERR_ANS_INVALID_PARAM;
893     }
894 
895     MessageParcel data;
896     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
897         ANS_LOGE("[RemoveAllNotifications] fail:, write interface token failed.");
898         return ERR_ANS_PARCELABLE_FAILED;
899     }
900 
901     if (!data.WriteStrongParcelable(bundleOption)) {
902         ANS_LOGE("[RemoveAllNotifications] fail:: write bundle failed");
903         return ERR_ANS_PARCELABLE_FAILED;
904     }
905 
906     MessageParcel reply;
907     MessageOption option = {MessageOption::TF_SYNC};
908     ErrCode result = InnerTransact(REMOVE_ALL_NOTIFICATIONS, option, data, reply);
909     if (result != ERR_OK) {
910         ANS_LOGE("[RemoveNotification] fail: transact ErrCode=%{public}d", result);
911         return ERR_ANS_TRANSACT_FAILED;
912     }
913 
914     if (!reply.ReadInt32(result)) {
915         ANS_LOGE("[RemoveNotification] fail: read result failed.");
916         return ERR_ANS_PARCELABLE_FAILED;
917     }
918 
919     return result;
920 }
921 
Delete(const std::string & key,int32_t removeReason)922 ErrCode AnsManagerProxy::Delete(const std::string &key, int32_t removeReason)
923 {
924     if (key.empty()) {
925         ANS_LOGE("[Delete] fail: key is empty.");
926         return ERR_ANS_INVALID_PARAM;
927     }
928 
929     MessageParcel data;
930     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
931         ANS_LOGE("[Delete] fail:, write interface token failed.");
932         return ERR_ANS_PARCELABLE_FAILED;
933     }
934 
935     if (!data.WriteString(key)) {
936         ANS_LOGE("[Delete] fail:: write key failed");
937         return ERR_ANS_PARCELABLE_FAILED;
938     }
939 
940     if (!data.WriteInt32(removeReason)) {
941         ANS_LOGE("[Delete] fail: write removeReason failed");
942         return ERR_ANS_PARCELABLE_FAILED;
943     }
944 
945     MessageParcel reply;
946     MessageOption option = {MessageOption::TF_SYNC};
947     ErrCode result = InnerTransact(DELETE_NOTIFICATION, option, data, reply);
948     if (result != ERR_OK) {
949         ANS_LOGE("[Delete] fail: transact ErrCode=%{public}d", result);
950         return ERR_ANS_TRANSACT_FAILED;
951     }
952 
953     if (!reply.ReadInt32(result)) {
954         ANS_LOGE("[Delete] fail: read result failed.");
955         return ERR_ANS_PARCELABLE_FAILED;
956     }
957 
958     return result;
959 }
960 
DeleteByBundle(const sptr<NotificationBundleOption> & bundleOption)961 ErrCode AnsManagerProxy::DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption)
962 {
963     if (bundleOption == nullptr) {
964         ANS_LOGE("[DeleteByBundle] fail: bundle is empty.");
965         return ERR_ANS_INVALID_PARAM;
966     }
967 
968     MessageParcel data;
969     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
970         ANS_LOGE("[DeleteByBundle] fail: write interface token failed.");
971         return ERR_ANS_PARCELABLE_FAILED;
972     }
973 
974     if (!data.WriteStrongParcelable(bundleOption)) {
975         ANS_LOGE("[DeleteByBundle] fail: write bundle failed");
976         return ERR_ANS_PARCELABLE_FAILED;
977     }
978 
979     MessageParcel reply;
980     MessageOption option = {MessageOption::TF_SYNC};
981     ErrCode result = InnerTransact(DELETE_NOTIFICATION_BY_BUNDLE, option, data, reply);
982     if (result != ERR_OK) {
983         ANS_LOGE("[DeleteByBundle] fail: transact ErrCode=%{public}d", result);
984         return ERR_ANS_TRANSACT_FAILED;
985     }
986 
987     if (!reply.ReadInt32(result)) {
988         ANS_LOGE("[DeleteByBundle] fail: read result failed.");
989         return ERR_ANS_PARCELABLE_FAILED;
990     }
991 
992     return result;
993 }
994 
DeleteAll()995 ErrCode AnsManagerProxy::DeleteAll()
996 {
997     MessageParcel data;
998     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
999         ANS_LOGE("[DeleteAll] fail:, write interface token failed.");
1000         return ERR_ANS_PARCELABLE_FAILED;
1001     }
1002 
1003     MessageParcel reply;
1004     MessageOption option = {MessageOption::TF_SYNC};
1005     ErrCode result = InnerTransact(DELETE_ALL_NOTIFICATIONS, option, data, reply);
1006     if (result != ERR_OK) {
1007         ANS_LOGE("[DeleteAll] fail: transact ErrCode=%{public}d", result);
1008         return ERR_ANS_TRANSACT_FAILED;
1009     }
1010 
1011     if (!reply.ReadInt32(result)) {
1012         ANS_LOGE("[DeleteAll] fail: read result failed.");
1013         return ERR_ANS_PARCELABLE_FAILED;
1014     }
1015 
1016     return result;
1017 }
1018 
GetSlotsByBundle(const sptr<NotificationBundleOption> & bundleOption,std::vector<sptr<NotificationSlot>> & slots)1019 ErrCode AnsManagerProxy::GetSlotsByBundle(
1020     const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots)
1021 {
1022     if (bundleOption == nullptr) {
1023         ANS_LOGE("[GetSlotsByBundle] fail: bundleOption is empty.");
1024         return ERR_ANS_INVALID_PARAM;
1025     }
1026 
1027     MessageParcel data;
1028     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1029         ANS_LOGE("[GetSlotsByBundle] fail: write interface token failed.");
1030         return ERR_ANS_PARCELABLE_FAILED;
1031     }
1032 
1033     if (!data.WriteParcelable(bundleOption)) {
1034         ANS_LOGE("[GetSlotsByBundle] fail:: write bundle failed");
1035         return ERR_ANS_PARCELABLE_FAILED;
1036     }
1037 
1038     MessageParcel reply;
1039     MessageOption option = {MessageOption::TF_SYNC};
1040     ErrCode result = InnerTransact(GET_SLOTS_BY_BUNDLE, option, data, reply);
1041     if (result != ERR_OK) {
1042         ANS_LOGE("[GetSlotsByBundle] fail: transact ErrCode=%{public}d", result);
1043         return ERR_ANS_TRANSACT_FAILED;
1044     }
1045 
1046     if (!ReadParcelableVector(slots, reply, result)) {
1047         ANS_LOGE("[GetSlotsByBundle] fail: read slots failed.");
1048         return ERR_ANS_PARCELABLE_FAILED;
1049     }
1050 
1051     return result;
1052 }
1053 
UpdateSlots(const sptr<NotificationBundleOption> & bundleOption,const std::vector<sptr<NotificationSlot>> & slots)1054 ErrCode AnsManagerProxy::UpdateSlots(
1055     const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots)
1056 {
1057     if (bundleOption == nullptr) {
1058         ANS_LOGE("[UpdateSlots] fail: bundleOption is empty.");
1059         return ERR_ANS_INVALID_PARAM;
1060     }
1061 
1062     if (slots.empty()) {
1063         ANS_LOGE("[UpdateSlots] fail: slots is empty.");
1064         return ERR_ANS_INVALID_PARAM;
1065     }
1066 
1067     size_t slotSize = slots.size();
1068     if (slotSize > MAX_SLOT_NUM) {
1069         ANS_LOGE("[UpdateSlots] fail: slotSize over max size.");
1070         return ERR_ANS_INVALID_PARAM;
1071     }
1072 
1073     MessageParcel data;
1074     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1075         ANS_LOGE("[UpdateSlots] fail: write interface token failed.");
1076         return ERR_ANS_PARCELABLE_FAILED;
1077     }
1078 
1079     if (!data.WriteParcelable(bundleOption)) {
1080         ANS_LOGE("[UpdateSlots] fail:: write bundleoption failed");
1081         return ERR_ANS_PARCELABLE_FAILED;
1082     }
1083 
1084     if (!WriteParcelableVector(slots, data)) {
1085         ANS_LOGE("[UpdateSlots] fail: write slots failed");
1086         return ERR_ANS_PARCELABLE_FAILED;
1087     }
1088 
1089     MessageParcel reply;
1090     MessageOption option = {MessageOption::TF_SYNC};
1091     ErrCode result = InnerTransact(UPDATE_SLOTS, option, data, reply);
1092     if (result != ERR_OK) {
1093         ANS_LOGE("[UpdateSlots] fail: transact ErrCode=%{public}d", result);
1094         return ERR_ANS_TRANSACT_FAILED;
1095     }
1096 
1097     if (!reply.ReadInt32(result)) {
1098         ANS_LOGE("[UpdateSlots] fail: read result failed.");
1099         return ERR_ANS_PARCELABLE_FAILED;
1100     }
1101 
1102     return result;
1103 }
1104 
RequestEnableNotification(const std::string & deviceId)1105 ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId)
1106 {
1107     ANS_LOGI("enter");
1108     MessageParcel data;
1109     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1110         ANS_LOGE("[RequestEnableNotification] fail: write interface token failed.");
1111         return ERR_ANS_PARCELABLE_FAILED;
1112     }
1113 
1114     if (!data.WriteString(deviceId)) {
1115         ANS_LOGE("[RequestEnableNotification] fail: write deviceId failed");
1116         return ERR_ANS_PARCELABLE_FAILED;
1117     }
1118 
1119     MessageParcel reply;
1120     MessageOption option = {MessageOption::TF_SYNC};
1121     ErrCode result = InnerTransact(REQUEST_ENABLE_NOTIFICATION, option, data, reply);
1122     if (result != ERR_OK) {
1123         ANS_LOGE("[RequestEnableNotification] fail: transact ErrCode=%{public}d", result);
1124         return ERR_ANS_TRANSACT_FAILED;
1125     }
1126 
1127     if (!reply.ReadInt32(result)) {
1128         ANS_LOGE("[RequestEnableNotification] fail: read result failed.");
1129         return ERR_ANS_PARCELABLE_FAILED;
1130     }
1131     return result;
1132 }
1133 
SetNotificationsEnabledForBundle(const std::string & deviceId,bool enabled)1134 ErrCode AnsManagerProxy::SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled)
1135 {
1136     MessageParcel data;
1137     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1138         ANS_LOGE("[SetNotificationsEnabledForBundle] fail: write interface token failed.");
1139         return ERR_ANS_PARCELABLE_FAILED;
1140     }
1141 
1142     if (!data.WriteString(deviceId)) {
1143         ANS_LOGE("[SetNotificationsEnabledForBundle] fail: write deviceId failed");
1144         return ERR_ANS_PARCELABLE_FAILED;
1145     }
1146 
1147     if (!data.WriteBool(enabled)) {
1148         ANS_LOGE("[SetNotificationsEnabledForBundle] fail: write enabled failed");
1149         return ERR_ANS_PARCELABLE_FAILED;
1150     }
1151 
1152     MessageParcel reply;
1153     MessageOption option = {MessageOption::TF_SYNC};
1154     ErrCode result = InnerTransact(SET_NOTIFICATION_ENABLED_FOR_BUNDLE, option, data, reply);
1155     if (result != ERR_OK) {
1156         ANS_LOGE("[SetNotificationsEnabledForBundle] fail: transact ErrCode=%{public}d", result);
1157         return ERR_ANS_TRANSACT_FAILED;
1158     }
1159 
1160     if (!reply.ReadInt32(result)) {
1161         ANS_LOGE("[SetNotificationsEnabledForBundle] fail: read result failed.");
1162         return ERR_ANS_PARCELABLE_FAILED;
1163     }
1164 
1165     return result;
1166 }
1167 
SetNotificationsEnabledForAllBundles(const std::string & deviceId,bool enabled)1168 ErrCode AnsManagerProxy::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled)
1169 {
1170     MessageParcel data;
1171     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1172         ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: write interface token failed.");
1173         return ERR_ANS_PARCELABLE_FAILED;
1174     }
1175 
1176     if (!data.WriteString(deviceId)) {
1177         ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: write deviceId failed");
1178         return ERR_ANS_PARCELABLE_FAILED;
1179     }
1180 
1181     if (!data.WriteBool(enabled)) {
1182         ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: write enabled failed");
1183         return ERR_ANS_PARCELABLE_FAILED;
1184     }
1185 
1186     MessageParcel reply;
1187     MessageOption option = {MessageOption::TF_SYNC};
1188     ErrCode result = InnerTransact(SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE, option, data, reply);
1189     if (result != ERR_OK) {
1190         ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: transact ErrCode=%{public}d", result);
1191         return ERR_ANS_TRANSACT_FAILED;
1192     }
1193 
1194     if (!reply.ReadInt32(result)) {
1195         ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: read result failed.");
1196         return ERR_ANS_PARCELABLE_FAILED;
1197     }
1198 
1199     return result;
1200 }
1201 
SetNotificationsEnabledForSpecialBundle(const std::string & deviceId,const sptr<NotificationBundleOption> & bundleOption,bool enabled)1202 ErrCode AnsManagerProxy::SetNotificationsEnabledForSpecialBundle(
1203     const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled)
1204 {
1205     if (bundleOption == nullptr) {
1206         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: bundleOption is empty.");
1207         return ERR_ANS_INVALID_PARAM;
1208     }
1209 
1210     MessageParcel data;
1211     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1212         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write interface token failed.");
1213         return ERR_ANS_PARCELABLE_FAILED;
1214     }
1215 
1216     if (!data.WriteString(deviceId)) {
1217         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write deviceId failed");
1218         return ERR_ANS_PARCELABLE_FAILED;
1219     }
1220 
1221     if (!data.WriteParcelable(bundleOption)) {
1222         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write bundleOption failed");
1223         return ERR_ANS_PARCELABLE_FAILED;
1224     }
1225 
1226     if (!data.WriteBool(enabled)) {
1227         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write enabled failed");
1228         return ERR_ANS_PARCELABLE_FAILED;
1229     }
1230 
1231     MessageParcel reply;
1232     MessageOption option = {MessageOption::TF_SYNC};
1233     ErrCode result = InnerTransact(SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE, option, data, reply);
1234     if (result != ERR_OK) {
1235         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: transact ErrCode=%{public}d", result);
1236         return ERR_ANS_TRANSACT_FAILED;
1237     }
1238 
1239     if (!reply.ReadInt32(result)) {
1240         ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: read result failed.");
1241         return ERR_ANS_PARCELABLE_FAILED;
1242     }
1243 
1244     return result;
1245 }
1246 
SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> & bundleOption,bool enabled)1247 ErrCode AnsManagerProxy::SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled)
1248 {
1249     if (bundleOption == nullptr) {
1250         ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: bundle is empty.");
1251         return ERR_ANS_INVALID_PARAM;
1252     }
1253 
1254     MessageParcel data;
1255     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1256         ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: write interface token failed.");
1257         return ERR_ANS_PARCELABLE_FAILED;
1258     }
1259 
1260     if (!data.WriteParcelable(bundleOption)) {
1261         ANS_LOGE("[SetShowBadgeEnabledForBundle] fail:: write bundle failed");
1262         return ERR_ANS_PARCELABLE_FAILED;
1263     }
1264 
1265     if (!data.WriteBool(enabled)) {
1266         ANS_LOGE("[SetShowBadgeEnabledForBundle] fail:: write enabled failed");
1267         return ERR_ANS_PARCELABLE_FAILED;
1268     }
1269 
1270     MessageParcel reply;
1271     MessageOption option = {MessageOption::TF_SYNC};
1272     ErrCode result = InnerTransact(SET_SHOW_BADGE_ENABLED_FOR_BUNDLE, option, data, reply);
1273     if (result != ERR_OK) {
1274         ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: transact ErrCode=%{public}d", result);
1275         return ERR_ANS_TRANSACT_FAILED;
1276     }
1277 
1278     if (!reply.ReadInt32(result)) {
1279         ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: read result failed.");
1280         return ERR_ANS_PARCELABLE_FAILED;
1281     }
1282 
1283     return result;
1284 }
1285 
GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> & bundleOption,bool & enabled)1286 ErrCode AnsManagerProxy::GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled)
1287 {
1288     if (bundleOption == nullptr) {
1289         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: bundle is empty.");
1290         return ERR_ANS_INVALID_PARAM;
1291     }
1292 
1293     MessageParcel data;
1294     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1295         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: write interface token failed.");
1296         return ERR_ANS_PARCELABLE_FAILED;
1297     }
1298 
1299     if (!data.WriteParcelable(bundleOption)) {
1300         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail:: write bundle failed");
1301         return ERR_ANS_PARCELABLE_FAILED;
1302     }
1303 
1304     MessageParcel reply;
1305     MessageOption option = {MessageOption::TF_SYNC};
1306     ErrCode result = InnerTransact(GET_SHOW_BADGE_ENABLED_FOR_BUNDLE, option, data, reply);
1307     if (result != ERR_OK) {
1308         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: transact ErrCode=%{public}d", result);
1309         return ERR_ANS_TRANSACT_FAILED;
1310     }
1311 
1312     if (!reply.ReadInt32(result)) {
1313         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read result failed.");
1314         return ERR_ANS_PARCELABLE_FAILED;
1315     }
1316 
1317     if (!reply.ReadBool(enabled)) {
1318         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read enabled failed.");
1319         return ERR_ANS_PARCELABLE_FAILED;
1320     }
1321 
1322     return result;
1323 }
1324 
GetShowBadgeEnabled(bool & enabled)1325 ErrCode AnsManagerProxy::GetShowBadgeEnabled(bool &enabled)
1326 {
1327     MessageParcel data;
1328     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1329         ANS_LOGE("[GetShowBadgeEnabled] fail: write interface token failed.");
1330         return ERR_ANS_PARCELABLE_FAILED;
1331     }
1332 
1333     MessageParcel reply;
1334     MessageOption option = {MessageOption::TF_SYNC};
1335     ErrCode result = InnerTransact(GET_SHOW_BADGE_ENABLED, option, data, reply);
1336     if (result != ERR_OK) {
1337         ANS_LOGE("[GetShowBadgeEnabled] fail: transact ErrCode=%{public}d", result);
1338         return ERR_ANS_TRANSACT_FAILED;
1339     }
1340 
1341     if (!reply.ReadInt32(result)) {
1342         ANS_LOGE("[GetShowBadgeEnabled] fail: read result failed.");
1343         return ERR_ANS_PARCELABLE_FAILED;
1344     }
1345 
1346     if (!reply.ReadBool(enabled)) {
1347         ANS_LOGE("[GetShowBadgeEnabled] fail: read enabled failed.");
1348         return ERR_ANS_PARCELABLE_FAILED;
1349     }
1350 
1351     return result;
1352 }
1353 
Subscribe(const sptr<AnsSubscriberInterface> & subscriber,const sptr<NotificationSubscribeInfo> & info)1354 ErrCode AnsManagerProxy::Subscribe(const sptr<AnsSubscriberInterface> &subscriber,
1355     const sptr<NotificationSubscribeInfo> &info)
1356 {
1357     if (subscriber == nullptr) {
1358         ANS_LOGE("[Subscribe] fail: subscriber is empty.");
1359         return ERR_ANS_INVALID_PARAM;
1360     }
1361 
1362     MessageParcel data;
1363     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1364         ANS_LOGE("[Subscribe] fail: write interface token failed.");
1365         return ERR_ANS_PARCELABLE_FAILED;
1366     }
1367 
1368     bool ret = data.WriteRemoteObject(subscriber->AsObject());
1369     if (!ret) {
1370         ANS_LOGE("[Subscribe] fail: write subscriber failed.");
1371         return ERR_ANS_PARCELABLE_FAILED;
1372     }
1373 
1374     if (!data.WriteBool(info != nullptr)) {
1375         ANS_LOGE("[Subscribe] fail: write isSubcribeInfo failed");
1376         return ERR_ANS_PARCELABLE_FAILED;
1377     }
1378 
1379     if (info != nullptr) {
1380         if (!data.WriteParcelable(info)) {
1381             ANS_LOGE("[Subscribe] fail: write subcribeInfo failed");
1382             return ERR_ANS_PARCELABLE_FAILED;
1383         }
1384     }
1385 
1386     MessageParcel reply;
1387     MessageOption option = {MessageOption::TF_SYNC};
1388     ErrCode result = InnerTransact(SUBSCRIBE_NOTIFICATION, option, data, reply);
1389     if (result != ERR_OK) {
1390         ANS_LOGE("[Subscribe] fail: transact ErrCode=%{public}d", result);
1391         return ERR_ANS_TRANSACT_FAILED;
1392     }
1393 
1394     if (!reply.ReadInt32(result)) {
1395         ANS_LOGE("[Subscribe] fail: read result failed.");
1396         return ERR_ANS_PARCELABLE_FAILED;
1397     }
1398 
1399     return result;
1400 }
1401 
Unsubscribe(const sptr<AnsSubscriberInterface> & subscriber,const sptr<NotificationSubscribeInfo> & info)1402 ErrCode AnsManagerProxy::Unsubscribe(
1403     const sptr<AnsSubscriberInterface> &subscriber, const sptr<NotificationSubscribeInfo> &info)
1404 {
1405     if (subscriber == nullptr) {
1406         ANS_LOGE("[Unsubscribe] fail: subscriber is empty.");
1407         return ERR_ANS_INVALID_PARAM;
1408     }
1409 
1410     MessageParcel data;
1411     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1412         ANS_LOGE("[Unsubscribe] fail: write interface token failed.");
1413         return ERR_ANS_PARCELABLE_FAILED;
1414     }
1415 
1416     bool ret = data.WriteRemoteObject(subscriber->AsObject());
1417     if (!ret) {
1418         ANS_LOGE("[Unsubscribe] fail: write subscriber failed.");
1419         return ERR_ANS_PARCELABLE_FAILED;
1420     }
1421 
1422     if (!data.WriteBool(info != nullptr)) {
1423         ANS_LOGE("[Unsubscribe] fail: write isSubcribeInfo failed");
1424         return ERR_ANS_PARCELABLE_FAILED;
1425     }
1426 
1427     if (info != nullptr) {
1428         if (!data.WriteParcelable(info)) {
1429             ANS_LOGE("[Unsubscribe] fail: write subcribeInfo failed");
1430             return ERR_ANS_PARCELABLE_FAILED;
1431         }
1432     }
1433 
1434     MessageParcel reply;
1435     MessageOption option = {MessageOption::TF_SYNC};
1436     ErrCode result = InnerTransact(UNSUBSCRIBE_NOTIFICATION, option, data, reply);
1437     if (result != ERR_OK) {
1438         ANS_LOGE("[Unsubscribe] fail: transact ErrCode=%{public}d", result);
1439         return ERR_ANS_TRANSACT_FAILED;
1440     }
1441 
1442     if (!reply.ReadInt32(result)) {
1443         ANS_LOGE("[Unsubscribe] fail: read result failed.");
1444         return ERR_ANS_PARCELABLE_FAILED;
1445     }
1446 
1447     return result;
1448 }
1449 
AreNotificationsSuspended(bool & suspended)1450 ErrCode AnsManagerProxy::AreNotificationsSuspended(bool &suspended)
1451 {
1452     MessageParcel data;
1453     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1454         ANS_LOGE("[AreNotificationsSuspended] fail: write interface token failed.");
1455         return ERR_ANS_PARCELABLE_FAILED;
1456     }
1457 
1458     MessageParcel reply;
1459     MessageOption option = {MessageOption::TF_SYNC};
1460     ErrCode result = InnerTransact(ARE_NOTIFICATION_SUSPENDED, option, data, reply);
1461     if (result != ERR_OK) {
1462         ANS_LOGE("[AreNotificationsSuspended] fail: transact ErrCode=%{public}d", result);
1463         return ERR_ANS_TRANSACT_FAILED;
1464     }
1465 
1466     if (!reply.ReadInt32(result)) {
1467         ANS_LOGE("[AreNotificationsSuspended] fail: read result failed.");
1468         return ERR_ANS_PARCELABLE_FAILED;
1469     }
1470 
1471     if (!reply.ReadBool(suspended)) {
1472         ANS_LOGE("[AreNotificationsSuspended] fail: read suspended failed.");
1473         return ERR_ANS_PARCELABLE_FAILED;
1474     }
1475 
1476     return result;
1477 }
1478 
GetCurrentAppSorting(sptr<NotificationSortingMap> & sortingMap)1479 ErrCode AnsManagerProxy::GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap)
1480 {
1481     MessageParcel data;
1482     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1483         ANS_LOGE("[GetCurrentAppSorting] fail: write interface token failed.");
1484         return ERR_ANS_PARCELABLE_FAILED;
1485     }
1486 
1487     MessageParcel reply;
1488     MessageOption option = {MessageOption::TF_SYNC};
1489     ErrCode result = InnerTransact(GET_CURRENT_APP_SORTING, option, data, reply);
1490     if (result != ERR_OK) {
1491         ANS_LOGE("[GetCurrentAppSorting] fail: transact ErrCode=%{public}d", result);
1492         return ERR_ANS_TRANSACT_FAILED;
1493     }
1494 
1495     if (!reply.ReadInt32(result)) {
1496         ANS_LOGE("[GetCurrentAppSorting] fail: read result failed.");
1497         return ERR_ANS_PARCELABLE_FAILED;
1498     }
1499 
1500     sortingMap = reply.ReadParcelable<NotificationSortingMap>();
1501     if (sortingMap == nullptr) {
1502         ANS_LOGE("[GetCurrentAppSorting] fail: read sortingMap failed.");
1503         return ERR_ANS_PARCELABLE_FAILED;
1504     }
1505 
1506     return result;
1507 }
1508 
IsAllowedNotify(bool & allowed)1509 ErrCode AnsManagerProxy::IsAllowedNotify(bool &allowed)
1510 {
1511     MessageParcel data;
1512     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1513         ANS_LOGE("[IsAllowedNotify] fail: write interface token failed.");
1514         return ERR_ANS_PARCELABLE_FAILED;
1515     }
1516 
1517     MessageParcel reply;
1518     MessageOption option = {MessageOption::TF_SYNC};
1519     ErrCode result = InnerTransact(IS_ALLOWED_NOTIFY, option, data, reply);
1520     if (result != ERR_OK) {
1521         ANS_LOGE("[IsAllowedNotify] fail: transact ErrCode=%{public}d", result);
1522         return ERR_ANS_TRANSACT_FAILED;
1523     }
1524 
1525     if (!reply.ReadInt32(result)) {
1526         ANS_LOGE("[IsAllowedNotify] fail: read result failed.");
1527         return ERR_ANS_PARCELABLE_FAILED;
1528     }
1529 
1530     if (!reply.ReadBool(allowed)) {
1531         ANS_LOGE("[IsAllowedNotify] fail: read allowed failed.");
1532         return ERR_ANS_PARCELABLE_FAILED;
1533     }
1534 
1535     return result;
1536 }
1537 
IsAllowedNotifySelf(bool & allowed)1538 ErrCode AnsManagerProxy::IsAllowedNotifySelf(bool &allowed)
1539 {
1540     MessageParcel data;
1541     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1542         ANS_LOGE("[IsAllowedNotifySelf] fail: write interface token failed.");
1543         return ERR_ANS_PARCELABLE_FAILED;
1544     }
1545 
1546     MessageParcel reply;
1547     MessageOption option = {MessageOption::TF_SYNC};
1548     ErrCode result = InnerTransact(IS_ALLOWED_NOTIFY_SELF, option, data, reply);
1549     if (result != ERR_OK) {
1550         ANS_LOGE("[IsAllowedNotifySelf] fail: transact ErrCode=%{public}d", result);
1551         return ERR_ANS_TRANSACT_FAILED;
1552     }
1553 
1554     if (!reply.ReadInt32(result)) {
1555         ANS_LOGE("[IsAllowedNotifySelf] fail: read result failed.");
1556         return ERR_ANS_PARCELABLE_FAILED;
1557     }
1558 
1559     if (!reply.ReadBool(allowed)) {
1560         ANS_LOGE("[IsAllowedNotifySelf] fail: read allowed failed.");
1561         return ERR_ANS_PARCELABLE_FAILED;
1562     }
1563 
1564     return result;
1565 }
1566 
IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> & bundleOption,bool & allowed)1567 ErrCode AnsManagerProxy::IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed)
1568 {
1569     if (bundleOption == nullptr) {
1570         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: bundle is empty.");
1571         return ERR_ANS_INVALID_PARAM;
1572     }
1573 
1574     MessageParcel data;
1575     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1576         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write interface token failed.");
1577         return ERR_ANS_PARCELABLE_FAILED;
1578     }
1579 
1580     if (!data.WriteParcelable(bundleOption)) {
1581         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write bundle failed");
1582         return ERR_ANS_PARCELABLE_FAILED;
1583     }
1584 
1585     MessageParcel reply;
1586     MessageOption option = {MessageOption::TF_SYNC};
1587     ErrCode result = InnerTransact(IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY, option, data, reply);
1588     if (result != ERR_OK) {
1589         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: transact ErrCode=%{public}d", result);
1590         return ERR_ANS_TRANSACT_FAILED;
1591     }
1592 
1593     if (!reply.ReadInt32(result)) {
1594         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read result failed.");
1595         return ERR_ANS_PARCELABLE_FAILED;
1596     }
1597 
1598     if (!reply.ReadBool(allowed)) {
1599         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read allowed failed.");
1600         return ERR_ANS_PARCELABLE_FAILED;
1601     }
1602 
1603     return result;
1604 }
1605 
CancelGroup(const std::string & groupName)1606 ErrCode AnsManagerProxy::CancelGroup(const std::string &groupName)
1607 {
1608     MessageParcel data;
1609     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1610         ANS_LOGE("[CancelGroup] fail: write interface token failed.");
1611         return ERR_ANS_PARCELABLE_FAILED;
1612     }
1613 
1614     if (!data.WriteString(groupName)) {
1615         ANS_LOGE("[CancelGroup] fail: write groupName failed.");
1616         return ERR_ANS_PARCELABLE_FAILED;
1617     }
1618 
1619     MessageParcel reply;
1620     MessageOption option = {MessageOption::TF_SYNC};
1621     ErrCode result = InnerTransact(CANCEL_GROUP, option, data, reply);
1622     if (result != ERR_OK) {
1623         ANS_LOGE("[CancelGroup] fail: transact ErrCode=%{public}d", result);
1624         return ERR_ANS_TRANSACT_FAILED;
1625     }
1626 
1627     if (!reply.ReadInt32(result)) {
1628         ANS_LOGE("[CancelGroup] fail: read result failed.");
1629         return ERR_ANS_PARCELABLE_FAILED;
1630     }
1631 
1632     return result;
1633 }
1634 
RemoveGroupByBundle(const sptr<NotificationBundleOption> & bundleOption,const std::string & groupName)1635 ErrCode AnsManagerProxy::RemoveGroupByBundle(
1636     const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName)
1637 {
1638     MessageParcel data;
1639     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1640         ANS_LOGE("[RemoveGroupByBundle] fail: write interface token failed.");
1641         return ERR_ANS_PARCELABLE_FAILED;
1642     }
1643 
1644     if (!data.WriteParcelable(bundleOption)) {
1645         ANS_LOGE("[RemoveGroupByBundle] fail:: write bundleOption failed");
1646         return ERR_ANS_PARCELABLE_FAILED;
1647     }
1648 
1649     if (!data.WriteString(groupName)) {
1650         ANS_LOGE("[RemoveGroupByBundle] fail: write groupName failed.");
1651         return ERR_ANS_PARCELABLE_FAILED;
1652     }
1653 
1654     MessageParcel reply;
1655     MessageOption option = {MessageOption::TF_SYNC};
1656     ErrCode result = InnerTransact(REMOVE_GROUP_BY_BUNDLE, option, data, reply);
1657     if (result != ERR_OK) {
1658         ANS_LOGE("[RemoveGroupByBundle] fail: transact ErrCode=%{public}d", result);
1659         return ERR_ANS_TRANSACT_FAILED;
1660     }
1661 
1662     if (!reply.ReadInt32(result)) {
1663         ANS_LOGE("[RemoveGroupByBundle] fail: read result failed.");
1664         return ERR_ANS_PARCELABLE_FAILED;
1665     }
1666 
1667     return result;
1668 }
1669 
SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> & date)1670 ErrCode AnsManagerProxy::SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date)
1671 {
1672     if (date == nullptr) {
1673         ANS_LOGE("[SetDoNotDisturbDate] fail: date is empty.");
1674         return ERR_ANS_INVALID_PARAM;
1675     }
1676 
1677     MessageParcel data;
1678     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1679         ANS_LOGE("[SetDoNotDisturbDate] fail: write interface token failed.");
1680         return ERR_ANS_PARCELABLE_FAILED;
1681     }
1682 
1683     if (!data.WriteParcelable(date)) {
1684         ANS_LOGE("[SetDoNotDisturbDate] fail: write date failed");
1685         return ERR_ANS_PARCELABLE_FAILED;
1686     }
1687 
1688     MessageParcel reply;
1689     MessageOption option = {MessageOption::TF_SYNC};
1690     ErrCode result = InnerTransact(SET_DO_NOT_DISTURB_DATE, option, data, reply);
1691     if (result != ERR_OK) {
1692         ANS_LOGE("[SetDoNotDisturbDate] fail: transact ErrCode=%{public}d", result);
1693         return ERR_ANS_TRANSACT_FAILED;
1694     }
1695 
1696     if (!reply.ReadInt32(result)) {
1697         ANS_LOGE("[SetDoNotDisturbDate] fail: read result failed.");
1698         return ERR_ANS_PARCELABLE_FAILED;
1699     }
1700 
1701     return result;
1702 }
1703 
GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> & date)1704 ErrCode AnsManagerProxy::GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date)
1705 {
1706     MessageParcel data;
1707     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1708         ANS_LOGE("[GetDoNotDisturbDate] fail: write interface token failed.");
1709         return ERR_ANS_PARCELABLE_FAILED;
1710     }
1711 
1712     MessageParcel reply;
1713     MessageOption option = {MessageOption::TF_SYNC};
1714     ErrCode result = InnerTransact(GET_DO_NOT_DISTURB_DATE, option, data, reply);
1715     if (result != ERR_OK) {
1716         ANS_LOGE("[GetDoNotDisturbDate] fail: transact ErrCode=%{public}d", result);
1717         return ERR_ANS_TRANSACT_FAILED;
1718     }
1719 
1720     if (!reply.ReadInt32(result)) {
1721         ANS_LOGE("[GetDoNotDisturbDate] fail: read result failed.");
1722         return ERR_ANS_PARCELABLE_FAILED;
1723     }
1724 
1725     if (result == ERR_OK) {
1726         date = reply.ReadParcelable<NotificationDoNotDisturbDate>();
1727         if (date == nullptr) {
1728             ANS_LOGE("[GetDoNotDisturbDate] fail: read date failed.");
1729             return ERR_ANS_PARCELABLE_FAILED;
1730         }
1731     }
1732 
1733     return result;
1734 }
1735 
DoesSupportDoNotDisturbMode(bool & doesSupport)1736 ErrCode AnsManagerProxy::DoesSupportDoNotDisturbMode(bool &doesSupport)
1737 {
1738     MessageParcel data;
1739     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1740         ANS_LOGE("[DoesSupportDoNotDisturbMode] fail: write interface token failed.");
1741         return ERR_ANS_PARCELABLE_FAILED;
1742     }
1743 
1744     MessageParcel reply;
1745     MessageOption option = {MessageOption::TF_SYNC};
1746     ErrCode result = InnerTransact(DOES_SUPPORT_DO_NOT_DISTURB_MODE, option, data, reply);
1747     if (result != ERR_OK) {
1748         ANS_LOGE("[DoesSupportDoNotDisturbMode] fail: transact ErrCode=%{public}d", result);
1749         return ERR_ANS_TRANSACT_FAILED;
1750     }
1751 
1752     if (!reply.ReadInt32(result)) {
1753         ANS_LOGE("[DoesSupportDoNotDisturbMode] fail: read result failed.");
1754         return ERR_ANS_PARCELABLE_FAILED;
1755     }
1756 
1757     if (!reply.ReadBool(doesSupport)) {
1758         ANS_LOGE("[DoesSupportDoNotDisturbMode] fail: read doesSupport failed.");
1759         return ERR_ANS_PARCELABLE_FAILED;
1760     }
1761 
1762     return result;
1763 }
1764 
IsDistributedEnabled(bool & enabled)1765 ErrCode AnsManagerProxy::IsDistributedEnabled(bool &enabled)
1766 {
1767     MessageParcel data;
1768     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1769         ANS_LOGE("[IsDistributedEnabled] fail: write interface token failed.");
1770         return ERR_ANS_PARCELABLE_FAILED;
1771     }
1772 
1773     MessageParcel reply;
1774     MessageOption option = {MessageOption::TF_SYNC};
1775     ErrCode result = InnerTransact(IS_DISTRIBUTED_ENABLED, option, data, reply);
1776     if (result != ERR_OK) {
1777         ANS_LOGE("[IsDistributedEnabled] fail: transact ErrCode=%{public}d", result);
1778         return ERR_ANS_TRANSACT_FAILED;
1779     }
1780 
1781     if (!reply.ReadInt32(result)) {
1782         ANS_LOGE("[IsDistributedEnabled] fail: read result failed.");
1783         return ERR_ANS_PARCELABLE_FAILED;
1784     }
1785 
1786     if (!reply.ReadBool(enabled)) {
1787         ANS_LOGE("[IsDistributedEnabled] fail: read enabled failed.");
1788         return ERR_ANS_PARCELABLE_FAILED;
1789     }
1790 
1791     return result;
1792 }
1793 
EnableDistributed(bool enabled)1794 ErrCode AnsManagerProxy::EnableDistributed(bool enabled)
1795 {
1796     MessageParcel data;
1797     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1798         ANS_LOGE("[EnableDistributed] fail: write interface token failed.");
1799         return ERR_ANS_PARCELABLE_FAILED;
1800     }
1801 
1802     if (!data.WriteBool(enabled)) {
1803         ANS_LOGE("[EnableDistributed] fail: write enabled failed");
1804         return ERR_ANS_PARCELABLE_FAILED;
1805     }
1806 
1807     MessageParcel reply;
1808     MessageOption option = {MessageOption::TF_SYNC};
1809     ErrCode result = InnerTransact(ENABLE_DISTRIBUTED, option, data, reply);
1810     if (result != ERR_OK) {
1811         ANS_LOGE("[EnableDistributed] fail: transact ErrCode=%{public}d", result);
1812         return ERR_ANS_TRANSACT_FAILED;
1813     }
1814 
1815     if (!reply.ReadInt32(result)) {
1816         ANS_LOGE("[EnableDistributed] fail: read result failed.");
1817         return ERR_ANS_PARCELABLE_FAILED;
1818     }
1819 
1820     return result;
1821 }
1822 
EnableDistributedByBundle(const sptr<NotificationBundleOption> & bundleOption,bool enabled)1823 ErrCode AnsManagerProxy::EnableDistributedByBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled)
1824 {
1825     if (bundleOption == nullptr) {
1826         ANS_LOGE("[EnableDistributedByBundle] fail: bundle is empty.");
1827         return ERR_ANS_INVALID_PARAM;
1828     }
1829 
1830     MessageParcel data;
1831     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1832         ANS_LOGE("[EnableDistributedByBundle] fail: write interface token failed.");
1833         return ERR_ANS_PARCELABLE_FAILED;
1834     }
1835 
1836     if (!data.WriteParcelable(bundleOption)) {
1837         ANS_LOGE("[EnableDistributedByBundle] fail:: write bundle failed");
1838         return ERR_ANS_PARCELABLE_FAILED;
1839     }
1840 
1841     if (!data.WriteBool(enabled)) {
1842         ANS_LOGE("[EnableDistributedByBundle] fail:: write enabled failed");
1843         return ERR_ANS_PARCELABLE_FAILED;
1844     }
1845 
1846     MessageParcel reply;
1847     MessageOption option = {MessageOption::TF_SYNC};
1848     ErrCode result = InnerTransact(ENABLE_DISTRIBUTED_BY_BUNDLE, option, data, reply);
1849     if (result != ERR_OK) {
1850         ANS_LOGE("[EnableDistributedByBundle] fail: transact ErrCode=%{public}d", result);
1851         return ERR_ANS_TRANSACT_FAILED;
1852     }
1853 
1854     if (!reply.ReadInt32(result)) {
1855         ANS_LOGE("[EnableDistributedByBundle] fail: read result failed.");
1856         return ERR_ANS_PARCELABLE_FAILED;
1857     }
1858 
1859     return result;
1860 }
1861 
EnableDistributedSelf(bool enabled)1862 ErrCode AnsManagerProxy::EnableDistributedSelf(bool enabled)
1863 {
1864     MessageParcel data;
1865     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1866         ANS_LOGE("[EnableDistributedSelf] fail: write interface token failed.");
1867         return ERR_ANS_PARCELABLE_FAILED;
1868     }
1869 
1870     if (!data.WriteBool(enabled)) {
1871         ANS_LOGE("[EnableDistributedSelf] fail: write enabled failed");
1872         return ERR_ANS_PARCELABLE_FAILED;
1873     }
1874 
1875     MessageParcel reply;
1876     MessageOption option = {MessageOption::TF_SYNC};
1877     ErrCode result = InnerTransact(ENABLE_DISTRIBUTED_SELF, option, data, reply);
1878     if (result != ERR_OK) {
1879         ANS_LOGE("[EnableDistributedSelf] fail: transact ErrCode=%{public}d", result);
1880         return ERR_ANS_TRANSACT_FAILED;
1881     }
1882 
1883     if (!reply.ReadInt32(result)) {
1884         ANS_LOGE("[EnableDistributedSelf] fail: read result failed.");
1885         return ERR_ANS_PARCELABLE_FAILED;
1886     }
1887 
1888     return result;
1889 }
1890 
IsDistributedEnableByBundle(const sptr<NotificationBundleOption> & bundleOption,bool & enabled)1891 ErrCode AnsManagerProxy::IsDistributedEnableByBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled)
1892 {
1893     if (bundleOption == nullptr) {
1894         ANS_LOGE("[IsDistributedEnableByBundle] fail: bundle is empty.");
1895         return ERR_ANS_INVALID_PARAM;
1896     }
1897 
1898     MessageParcel data;
1899     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1900         ANS_LOGE("[IsDistributedEnableByBundle] fail: write interface token failed.");
1901         return ERR_ANS_PARCELABLE_FAILED;
1902     }
1903 
1904     if (!data.WriteParcelable(bundleOption)) {
1905         ANS_LOGE("[IsDistributedEnableByBundle] fail: write bundle failed");
1906         return ERR_ANS_PARCELABLE_FAILED;
1907     }
1908 
1909     MessageParcel reply;
1910     MessageOption option = {MessageOption::TF_SYNC};
1911     ErrCode result = InnerTransact(IS_DISTRIBUTED_ENABLED_BY_BUNDLE, option, data, reply);
1912     if (result != ERR_OK) {
1913         ANS_LOGE("[IsDistributedEnableByBundle] fail: transact ErrCode=%{public}d", result);
1914         return ERR_ANS_TRANSACT_FAILED;
1915     }
1916 
1917     if (!reply.ReadInt32(result)) {
1918         ANS_LOGE("[IsDistributedEnableByBundle] fail: read result failed.");
1919         return ERR_ANS_PARCELABLE_FAILED;
1920     }
1921 
1922     if (!reply.ReadBool(enabled)) {
1923         ANS_LOGE("[IsDistributedEnableByBundle] fail: read enabled failed.");
1924         return ERR_ANS_PARCELABLE_FAILED;
1925     }
1926 
1927     return result;
1928 }
1929 
GetDeviceRemindType(NotificationConstant::RemindType & remindType)1930 ErrCode AnsManagerProxy::GetDeviceRemindType(NotificationConstant::RemindType &remindType)
1931 {
1932     MessageParcel data;
1933     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1934         ANS_LOGE("[GetDeviceRemindType] fail: write interface token failed.");
1935         return ERR_ANS_PARCELABLE_FAILED;
1936     }
1937 
1938     MessageParcel reply;
1939     MessageOption option = {MessageOption::TF_SYNC};
1940     ErrCode result = InnerTransact(GET_DEVICE_REMIND_TYPE, option, data, reply);
1941     if (result != ERR_OK) {
1942         ANS_LOGE("[GetDeviceRemindType] fail: transact ErrCode=%{public}d", result);
1943         return ERR_ANS_TRANSACT_FAILED;
1944     }
1945 
1946     if (!reply.ReadInt32(result)) {
1947         ANS_LOGE("[GetDeviceRemindType] fail: read result failed.");
1948         return ERR_ANS_PARCELABLE_FAILED;
1949     }
1950 
1951     if (result == ERR_OK) {
1952         int32_t rType {-1};
1953         if (!reply.ReadInt32(rType)) {
1954             ANS_LOGE("[GetDeviceRemindType] fail: read remind type failed.");
1955             return ERR_ANS_PARCELABLE_FAILED;
1956         }
1957 
1958         remindType = static_cast<NotificationConstant::RemindType>(rType);
1959     }
1960 
1961     return result;
1962 }
1963 
PublishContinuousTaskNotification(const sptr<NotificationRequest> & request)1964 ErrCode AnsManagerProxy::PublishContinuousTaskNotification(const sptr<NotificationRequest> &request)
1965 {
1966     if (request == nullptr) {
1967         ANS_LOGE("[PublishContinuousTaskNotification] fail: notification request is null ptr.");
1968         return ERR_ANS_INVALID_PARAM;
1969     }
1970 
1971     MessageParcel data;
1972     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1973         ANS_LOGE("[PublishContinuousTaskNotification] fail: write interface token failed.");
1974         return ERR_ANS_PARCELABLE_FAILED;
1975     }
1976 
1977     if (!data.WriteParcelable(request)) {
1978         ANS_LOGE("[PublishContinuousTaskNotification] fail: write request failed.");
1979         return ERR_ANS_PARCELABLE_FAILED;
1980     }
1981 
1982     MessageParcel reply;
1983     MessageOption option = {MessageOption::TF_SYNC};
1984     ErrCode result = InnerTransact(PUBLISH_CONTINUOUS_TASK_NOTIFICATION, option, data, reply);
1985     if (result != ERR_OK) {
1986         ANS_LOGE("[PublishContinuousTaskNotification] fail: transact ErrCode=%{public}d", result);
1987         return ERR_ANS_TRANSACT_FAILED;
1988     }
1989 
1990     if (!reply.ReadInt32(result)) {
1991         ANS_LOGE("[PublishContinuousTaskNotification] fail: read result failed.");
1992         return ERR_ANS_PARCELABLE_FAILED;
1993     }
1994 
1995     return result;
1996 }
1997 
CancelContinuousTaskNotification(const std::string & label,int32_t notificationId)1998 ErrCode AnsManagerProxy::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId)
1999 {
2000     MessageParcel data;
2001     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2002         ANS_LOGE("[CancelContinuousTaskNotification] fail: write interface token failed.");
2003         return ERR_ANS_PARCELABLE_FAILED;
2004     }
2005 
2006     if (!data.WriteString(label)) {
2007         ANS_LOGE("[CancelContinuousTaskNotification] fail: write label failed");
2008         return ERR_ANS_PARCELABLE_FAILED;
2009     }
2010 
2011     if (!data.WriteInt32(notificationId)) {
2012         ANS_LOGE("[CancelContinuousTaskNotification] fail: write notificationId failed");
2013         return ERR_ANS_PARCELABLE_FAILED;
2014     }
2015     MessageParcel reply;
2016     MessageOption option = {MessageOption::TF_SYNC};
2017     ErrCode result = InnerTransact(CANCEL_CONTINUOUS_TASK_NOTIFICATION, option, data, reply);
2018     if (result != ERR_OK) {
2019         ANS_LOGE("[CancelContinuousTaskNotification] fail: transact ErrCode=%{public}d", result);
2020         return ERR_ANS_TRANSACT_FAILED;
2021     }
2022 
2023     if (!reply.ReadInt32(result)) {
2024         ANS_LOGE("[CancelContinuousTaskNotification] fail: read result failed.");
2025         return ERR_ANS_PARCELABLE_FAILED;
2026     }
2027 
2028     return result;
2029 }
2030 
PublishReminder(sptr<ReminderRequest> & reminder)2031 ErrCode AnsManagerProxy::PublishReminder(sptr<ReminderRequest> &reminder)
2032 {
2033     ANSR_LOGI("PublishReminder");
2034     MessageParcel data;
2035     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2036         ANSR_LOGE("[PublishReminder] fail: write interface token failed.");
2037         return ERR_ANS_PARCELABLE_FAILED;
2038     }
2039     if (reminder == nullptr) {
2040         ANSR_LOGW("[PublishReminder] fail: reminder is null ptr.");
2041         return ERR_ANS_INVALID_PARAM;
2042     }
2043     if (!data.WriteUint8(static_cast<uint8_t>(reminder->GetReminderType()))) {
2044         ANSR_LOGE("[PublishReminder] fail: write reminder type failed");
2045         return ERR_ANS_PARCELABLE_FAILED;
2046     }
2047     if (!data.WriteParcelable(reminder)) {
2048         ANSR_LOGE("[Publish] fail: write reminder parcelable failed");
2049         return ERR_ANS_PARCELABLE_FAILED;
2050     }
2051 
2052     MessageParcel reply;
2053     MessageOption option = {MessageOption::TF_SYNC};
2054     ErrCode result = InnerTransact(PUBLISH_REMINDER, option, data, reply);
2055     if (result != ERR_OK) {
2056         ANSR_LOGE("[PublishReminder] fail: transact ErrCode=%{public}d", result);
2057         return ERR_ANS_TRANSACT_FAILED;
2058     }
2059     int32_t reminderId = -1;
2060     if (!reply.ReadInt32(reminderId)) {
2061         ANSR_LOGE("[PublishReminder] fail: read reminder id failed.");
2062         return ERR_ANS_PARCELABLE_FAILED;
2063     }
2064     reminder->SetReminderId(reminderId);
2065     ANSR_LOGD("ReminderId=%{public}d", reminder->GetReminderId());
2066     if (!reply.ReadInt32(result)) {
2067         ANSR_LOGE("[PublishReminder] fail: read result failed.");
2068         return ERR_ANS_PARCELABLE_FAILED;
2069     }
2070     return result;
2071 }
2072 
CancelReminder(const int32_t reminderId)2073 ErrCode AnsManagerProxy::CancelReminder(const int32_t reminderId)
2074 {
2075     ANSR_LOGI("[CancelReminder]");
2076     MessageParcel data;
2077     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2078         ANSR_LOGE("[CancelReminder] fail: write interface token failed.");
2079         return ERR_ANS_PARCELABLE_FAILED;
2080     }
2081     if (!data.WriteInt32(reminderId)) {
2082         ANSR_LOGE("[CancelReminder] fail: write reminder id failed");
2083         return ERR_ANS_PARCELABLE_FAILED;
2084     }
2085 
2086     MessageParcel reply;
2087     MessageOption option = {MessageOption::TF_SYNC};
2088     ErrCode result = InnerTransact(CANCEL_REMINDER, option, data, reply);
2089     if (result != ERR_OK) {
2090         ANSR_LOGE("[CancelReminder] fail: transact ErrCode=%{public}d", result);
2091         return ERR_ANS_TRANSACT_FAILED;
2092     }
2093     if (!reply.ReadInt32(result)) {
2094         ANSR_LOGE("[PublishReminder] fail: read result failed.");
2095         return ERR_ANS_PARCELABLE_FAILED;
2096     }
2097     return result;
2098 }
2099 
CancelAllReminders()2100 ErrCode AnsManagerProxy::CancelAllReminders()
2101 {
2102     ANSR_LOGI("[CancelAllReminders]");
2103     MessageParcel data;
2104     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2105         ANSR_LOGE("[CancelAllReminders] fail: write interface token failed.");
2106         return ERR_ANS_PARCELABLE_FAILED;
2107     }
2108 
2109     MessageParcel reply;
2110     MessageOption option = {MessageOption::TF_SYNC};
2111     ErrCode result = InnerTransact(CANCEL_ALL_REMINDERS, option, data, reply);
2112     if (result != ERR_OK) {
2113         ANSR_LOGE("[CancelAllReminders] fail: transact ErrCode=%{public}d", result);
2114         return ERR_ANS_TRANSACT_FAILED;
2115     }
2116     if (!reply.ReadInt32(result)) {
2117         ANSR_LOGE("[PublishReminder] fail: read result failed.");
2118         return ERR_ANS_PARCELABLE_FAILED;
2119     }
2120     return result;
2121 }
2122 
GetValidReminders(std::vector<sptr<ReminderRequest>> & reminders)2123 ErrCode AnsManagerProxy::GetValidReminders(std::vector<sptr<ReminderRequest>> &reminders)
2124 {
2125     ANSR_LOGI("[GetValidReminders]");
2126     MessageParcel data;
2127     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2128         ANSR_LOGE("[GetValidReminders] fail: write interface token failed.");
2129         return ERR_ANS_PARCELABLE_FAILED;
2130     }
2131 
2132     MessageParcel reply;
2133     MessageOption option = {MessageOption::TF_SYNC};
2134     ErrCode result = InnerTransact(GET_ALL_VALID_REMINDERS, option, data, reply);
2135     if (result != ERR_OK) {
2136         ANSR_LOGE("[GetValidReminders] fail: transact ErrCode=%{public}d", result);
2137         return ERR_ANS_TRANSACT_FAILED;
2138     }
2139     uint8_t count = 0;
2140     if (!reply.ReadUint8(count)) {
2141         ANSR_LOGE("[GetValidReminders] fail: read reminder count failed.");
2142         return ERR_ANS_PARCELABLE_FAILED;
2143     }
2144     ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count);
2145     reminders.clear();
2146     result = ReadReminders(count, reply, reminders);
2147     if (result != ERR_OK) {
2148         ANSR_LOGE("[GetValidReminders] fail: ReadReminders ErrCode=%{public}d", result);
2149         return result;
2150     } else {
2151         ANSR_LOGD("[GetValidReminders], size=%{public}zu", reminders.size());
2152     }
2153     if (!reply.ReadInt32(result)) {
2154         ANSR_LOGE("[PublishReminder] fail: read result failed.");
2155         return ERR_ANS_PARCELABLE_FAILED;
2156     }
2157     return result;
2158 }
2159 
ReadReminders(uint8_t & count,MessageParcel & reply,std::vector<sptr<ReminderRequest>> & reminders)2160 ErrCode AnsManagerProxy::ReadReminders(
2161     uint8_t &count, MessageParcel &reply, std::vector<sptr<ReminderRequest>> &reminders)
2162 {
2163     for (uint8_t i = 0; i < count; i++) {
2164         uint8_t typeInfo = static_cast<uint8_t>(ReminderRequest::ReminderType::INVALID);
2165         if (!reply.ReadUint8(typeInfo)) {
2166             ANSR_LOGE("Failed to read reminder type");
2167             return ERR_ANS_PARCELABLE_FAILED;
2168         }
2169         auto reminderType = static_cast<ReminderRequest::ReminderType>(typeInfo);
2170         sptr<ReminderRequest> reminder;
2171         if (ReminderRequest::ReminderType::ALARM == reminderType) {
2172             ANSR_LOGD("[GetValidReminders] alarm");
2173             reminder = reply.ReadParcelable<ReminderRequestAlarm>();
2174         } else if (ReminderRequest::ReminderType::TIMER == reminderType) {
2175             ANSR_LOGD("[GetValidReminders] timer");
2176             reminder = reply.ReadParcelable<ReminderRequestTimer>();
2177         } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) {
2178             ANSR_LOGD("[GetValidReminders] calendar");
2179             reminder = reply.ReadParcelable<ReminderRequestCalendar>();
2180         } else {
2181             ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo);
2182             return ERR_ANS_INVALID_PARAM;
2183         }
2184         if (!reminder) {
2185             ANSR_LOGE("[GetValidReminders] fail: Reminder ReadParcelable failed");
2186             return ERR_ANS_PARCELABLE_FAILED;
2187         }
2188         reminders.push_back(reminder);
2189     }
2190     return ERR_OK;
2191 }
2192 
InnerTransact(uint32_t code,MessageOption & flags,MessageParcel & data,MessageParcel & reply)2193 ErrCode AnsManagerProxy::InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply)
2194 {
2195     auto remote = Remote();
2196     if (remote == nullptr) {
2197         ANS_LOGE("[InnerTransact] fail: get Remote fail code %{public}u", code);
2198         return ERR_DEAD_OBJECT;
2199     }
2200     int32_t err = remote->SendRequest(code, data, reply, flags);
2201     switch (err) {
2202         case NO_ERROR: {
2203             return ERR_OK;
2204         }
2205         case DEAD_OBJECT: {
2206             ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
2207             return ERR_DEAD_OBJECT;
2208         }
2209         default: {
2210             ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
2211             return ERR_ANS_TRANSACT_FAILED;
2212         }
2213     }
2214 }
2215 
2216 template<typename T>
WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & data)2217 bool AnsManagerProxy::WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data)
2218 {
2219     if (!data.WriteInt32(parcelableVector.size())) {
2220         ANS_LOGE("write ParcelableVector size failed");
2221         return false;
2222     }
2223 
2224     for (auto &parcelable : parcelableVector) {
2225         if (!data.WriteStrongParcelable(parcelable)) {
2226             ANS_LOGE("write ParcelableVector failed");
2227             return false;
2228         }
2229     }
2230     return true;
2231 }
2232 
2233 template<typename T>
ReadParcelableVector(std::vector<sptr<T>> & parcelableInfos,MessageParcel & reply,ErrCode & result)2234 bool AnsManagerProxy::ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &reply, ErrCode &result)
2235 {
2236     if (!reply.ReadInt32(result)) {
2237         ANS_LOGE("read result failed.");
2238         return false;
2239     }
2240 
2241     int32_t infoSize = 0;
2242     if (!reply.ReadInt32(infoSize)) {
2243         ANS_LOGE("read Parcelable size failed.");
2244         return false;
2245     }
2246 
2247     parcelableInfos.clear();
2248     for (int32_t index = 0; index < infoSize; index++) {
2249         sptr<T> info = reply.ReadStrongParcelable<T>();
2250         if (info == nullptr) {
2251             ANS_LOGE("read Parcelable infos failed.");
2252             return false;
2253         }
2254         parcelableInfos.emplace_back(info);
2255     }
2256 
2257     return true;
2258 }
2259 
IsSupportTemplate(const std::string & templateName,bool & support)2260 ErrCode AnsManagerProxy::IsSupportTemplate(const std::string &templateName, bool &support)
2261 {
2262     MessageParcel data;
2263     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2264         ANS_LOGE("[IsSupportTemplate] fail: write interface token failed.");
2265         return ERR_ANS_PARCELABLE_FAILED;
2266     }
2267 
2268     if (!data.WriteString(templateName)) {
2269         ANS_LOGE("[IsSupportTemplate] fail: write template name failed");
2270         return ERR_ANS_PARCELABLE_FAILED;
2271     }
2272 
2273     MessageParcel reply;
2274     MessageOption option = {MessageOption::TF_SYNC};
2275     ErrCode result = InnerTransact(IS_SUPPORT_TEMPLATE, option, data, reply);
2276     if (result != ERR_OK) {
2277         ANS_LOGE("[IsSupportTemplate] fail: transact ErrCode=%{public}d", result);
2278         return ERR_ANS_TRANSACT_FAILED;
2279     }
2280 
2281     if (!reply.ReadInt32(result)) {
2282         ANS_LOGE("[IsSupportTemplate] fail: read result failed.");
2283         return ERR_ANS_PARCELABLE_FAILED;
2284     }
2285 
2286     if (!reply.ReadBool(support)) {
2287         ANS_LOGE("[IsSupportTemplate] fail: read support failed.");
2288         return ERR_ANS_PARCELABLE_FAILED;
2289     }
2290 
2291     return result;
2292 }
2293 
IsSpecialUserAllowedNotify(const int32_t & userId,bool & allowed)2294 ErrCode AnsManagerProxy::IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed)
2295 {
2296     MessageParcel data;
2297     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2298         ANS_LOGE("[IsSpecialUserAllowedNotify] fail: write interface token failed.");
2299         return ERR_ANS_PARCELABLE_FAILED;
2300     }
2301 
2302     if (!data.WriteInt32(userId)) {
2303         ANS_LOGE("[IsSpecialUserAllowedNotify] fail: write userId failed");
2304         return ERR_ANS_PARCELABLE_FAILED;
2305     }
2306 
2307     MessageParcel reply;
2308     MessageOption option = {MessageOption::TF_SYNC};
2309     ErrCode result = InnerTransact(IS_SPECIAL_USER_ALLOWED_NOTIFY, option, data, reply);
2310     if (result != ERR_OK) {
2311         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: transact ErrCode=%{public}d", result);
2312         return ERR_ANS_TRANSACT_FAILED;
2313     }
2314 
2315     if (!reply.ReadInt32(result)) {
2316         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read result failed.");
2317         return ERR_ANS_PARCELABLE_FAILED;
2318     }
2319 
2320     if (!reply.ReadBool(allowed)) {
2321         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read allowed failed.");
2322         return ERR_ANS_PARCELABLE_FAILED;
2323     }
2324 
2325     return result;
2326 }
2327 
SetNotificationsEnabledByUser(const int32_t & userId,bool enabled)2328 ErrCode AnsManagerProxy::SetNotificationsEnabledByUser(const int32_t &userId, bool enabled)
2329 {
2330     MessageParcel data;
2331     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2332         ANS_LOGE("[SetNotificationsEnabledByUser] fail: write interface token failed.");
2333         return ERR_ANS_PARCELABLE_FAILED;
2334     }
2335 
2336     if (!data.WriteInt32(userId)) {
2337         ANS_LOGE("[SetNotificationsEnabledByUser] fail: write userId failed");
2338         return ERR_ANS_PARCELABLE_FAILED;
2339     }
2340 
2341     if (!data.WriteBool(enabled)) {
2342         ANS_LOGE("[SetNotificationsEnabledByUser] fail: write enabled failed");
2343         return ERR_ANS_PARCELABLE_FAILED;
2344     }
2345 
2346     MessageParcel reply;
2347     MessageOption option = {MessageOption::TF_SYNC};
2348     ErrCode result = InnerTransact(SET_NOTIFICATION_ENABLED_BY_USER, option, data, reply);
2349     if (result != ERR_OK) {
2350         ANS_LOGE("[SetNotificationsEnabledByUser] fail: transact ErrCode=%{public}d", result);
2351         return ERR_ANS_TRANSACT_FAILED;
2352     }
2353 
2354     if (!reply.ReadInt32(result)) {
2355         ANS_LOGE("[SetNotificationsEnabledByUser] fail: read result failed.");
2356         return ERR_ANS_PARCELABLE_FAILED;
2357     }
2358 
2359     return result;
2360 }
2361 
DeleteAllByUser(const int32_t & userId)2362 ErrCode AnsManagerProxy::DeleteAllByUser(const int32_t &userId)
2363 {
2364     MessageParcel data;
2365     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2366         ANS_LOGE("[DeleteAllByUser] fail:, write interface token failed.");
2367         return ERR_ANS_PARCELABLE_FAILED;
2368     }
2369 
2370     if (!data.WriteInt32(userId)) {
2371         ANS_LOGE("[DeleteAllByUser] fail: write userId failed");
2372         return ERR_ANS_PARCELABLE_FAILED;
2373     }
2374 
2375     MessageParcel reply;
2376     MessageOption option = {MessageOption::TF_SYNC};
2377     ErrCode result = InnerTransact(DELETE_ALL_NOTIFICATIONS_BY_USER, option, data, reply);
2378     if (result != ERR_OK) {
2379         ANS_LOGE("[DeleteAllByUser] fail: transact ErrCode=%{public}d", result);
2380         return ERR_ANS_TRANSACT_FAILED;
2381     }
2382 
2383     if (!reply.ReadInt32(result)) {
2384         ANS_LOGE("[DeleteAllByUser] fail: read result failed.");
2385         return ERR_ANS_PARCELABLE_FAILED;
2386     }
2387 
2388     return result;
2389 }
2390 
SetDoNotDisturbDate(const int32_t & userId,const sptr<NotificationDoNotDisturbDate> & date)2391 ErrCode AnsManagerProxy::SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date)
2392 {
2393     if (date == nullptr) {
2394         ANS_LOGE("[SetDoNotDisturbDate] fail: date is empty.");
2395         return ERR_ANS_INVALID_PARAM;
2396     }
2397 
2398     MessageParcel data;
2399     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2400         ANS_LOGE("[SetDoNotDisturbDate] fail: write interface token failed.");
2401         return ERR_ANS_PARCELABLE_FAILED;
2402     }
2403 
2404     if (!data.WriteInt32(userId)) {
2405         ANS_LOGE("[SetDoNotDisturbDate] fail: write userId failed");
2406         return ERR_ANS_PARCELABLE_FAILED;
2407     }
2408 
2409     if (!data.WriteParcelable(date)) {
2410         ANS_LOGE("[SetDoNotDisturbDate] fail: write date failed");
2411         return ERR_ANS_PARCELABLE_FAILED;
2412     }
2413 
2414     MessageParcel reply;
2415     MessageOption option = {MessageOption::TF_SYNC};
2416     ErrCode result = InnerTransact(SET_DO_NOT_DISTURB_DATE_BY_USER, option, data, reply);
2417     if (result != ERR_OK) {
2418         ANS_LOGE("[SetDoNotDisturbDate] fail: transact ErrCode=%{public}d", result);
2419         return ERR_ANS_TRANSACT_FAILED;
2420     }
2421 
2422     if (!reply.ReadInt32(result)) {
2423         ANS_LOGE("[SetDoNotDisturbDate] fail: read result failed.");
2424         return ERR_ANS_PARCELABLE_FAILED;
2425     }
2426 
2427     return result;
2428 }
2429 
GetDoNotDisturbDate(const int32_t & userId,sptr<NotificationDoNotDisturbDate> & date)2430 ErrCode AnsManagerProxy::GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date)
2431 {
2432     MessageParcel data;
2433     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2434         ANS_LOGE("[GetDoNotDisturbDate] fail: write interface token failed.");
2435         return ERR_ANS_PARCELABLE_FAILED;
2436     }
2437 
2438     if (!data.WriteInt32(userId)) {
2439         ANS_LOGE("[GetDoNotDisturbDate] fail: write userId failed");
2440         return ERR_ANS_PARCELABLE_FAILED;
2441     }
2442 
2443     MessageParcel reply;
2444     MessageOption option = {MessageOption::TF_SYNC};
2445     ErrCode result = InnerTransact(GET_DO_NOT_DISTURB_DATE_BY_USER, option, data, reply);
2446     if (result != ERR_OK) {
2447         ANS_LOGE("[GetDoNotDisturbDate] fail: transact ErrCode=%{public}d", result);
2448         return ERR_ANS_TRANSACT_FAILED;
2449     }
2450 
2451     if (!reply.ReadInt32(result)) {
2452         ANS_LOGE("[GetDoNotDisturbDate] fail: read result failed.");
2453         return ERR_ANS_PARCELABLE_FAILED;
2454     }
2455 
2456     if (result == ERR_OK) {
2457         date = reply.ReadParcelable<NotificationDoNotDisturbDate>();
2458         if (date == nullptr) {
2459             ANS_LOGE("[GetDoNotDisturbDate] fail: read date failed.");
2460             return ERR_ANS_PARCELABLE_FAILED;
2461         }
2462     }
2463 
2464     return result;
2465 }
2466 
SetEnabledForBundleSlot(const sptr<NotificationBundleOption> & bundleOption,const NotificationConstant::SlotType & slotType,bool enabled)2467 ErrCode AnsManagerProxy::SetEnabledForBundleSlot(
2468     const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled)
2469 {
2470     if (bundleOption == nullptr) {
2471         ANS_LOGE("[SetEnabledForBundleSlot] fail: bundle is empty.");
2472         return ERR_ANS_INVALID_PARAM;
2473     }
2474 
2475     MessageParcel data;
2476     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2477         ANS_LOGE("[SetEnabledForBundleSlot] fail: write interface token failed.");
2478         return ERR_ANS_PARCELABLE_FAILED;
2479     }
2480 
2481     if (!data.WriteStrongParcelable(bundleOption)) {
2482         ANS_LOGE("[SetEnabledForBundleSlot] fail:: write bundle failed");
2483         return ERR_ANS_PARCELABLE_FAILED;
2484     }
2485 
2486     if (!data.WriteInt32(slotType)) {
2487         ANS_LOGE("[SetEnabledForBundleSlot] fail:: write slotType failed.");
2488         return ERR_ANS_PARCELABLE_FAILED;
2489     }
2490 
2491     if (!data.WriteBool(enabled)) {
2492         ANS_LOGE("[SetEnabledForBundleSlot] fail: write enabled failed");
2493         return ERR_ANS_PARCELABLE_FAILED;
2494     }
2495 
2496     MessageParcel reply;
2497     MessageOption option = {MessageOption::TF_SYNC};
2498     ErrCode result = InnerTransact(SET_ENABLED_FOR_BUNDLE_SLOT, option, data, reply);
2499     if (result != ERR_OK) {
2500         ANS_LOGE("[SetEnabledForBundleSlot] fail: transact ErrCode=%{public}d", result);
2501         return ERR_ANS_TRANSACT_FAILED;
2502     }
2503 
2504     if (!reply.ReadInt32(result)) {
2505         ANS_LOGE("[SetEnabledForBundleSlot] fail: read result failed.");
2506         return ERR_ANS_PARCELABLE_FAILED;
2507     }
2508 
2509     return result;
2510 }
2511 
GetEnabledForBundleSlot(const sptr<NotificationBundleOption> & bundleOption,const NotificationConstant::SlotType & slotType,bool & enabled)2512 ErrCode AnsManagerProxy::GetEnabledForBundleSlot(
2513     const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled)
2514 {
2515     if (bundleOption == nullptr) {
2516         ANS_LOGE("[GetEnabledForBundleSlot] fail: bundle is empty.");
2517         return ERR_ANS_INVALID_PARAM;
2518     }
2519 
2520     MessageParcel data;
2521     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2522         ANS_LOGE("[GetEnabledForBundleSlot] fail: write interface token failed.");
2523         return ERR_ANS_PARCELABLE_FAILED;
2524     }
2525 
2526     if (!data.WriteStrongParcelable(bundleOption)) {
2527         ANS_LOGE("[GetEnabledForBundleSlot] fail:: write bundle failed");
2528         return ERR_ANS_PARCELABLE_FAILED;
2529     }
2530 
2531     if (!data.WriteInt32(slotType)) {
2532         ANS_LOGE("[GetEnabledForBundleSlot] fail:: write slotType failed.");
2533         return ERR_ANS_PARCELABLE_FAILED;
2534     }
2535 
2536     MessageParcel reply;
2537     MessageOption option = {MessageOption::TF_SYNC};
2538     ErrCode result = InnerTransact(GET_ENABLED_FOR_BUNDLE_SLOT, option, data, reply);
2539     if (result != ERR_OK) {
2540         ANS_LOGE("[GetEnabledForBundleSlot] fail: transact ErrCode=%{public}d", result);
2541         return ERR_ANS_TRANSACT_FAILED;
2542     }
2543 
2544     if (!reply.ReadInt32(result)) {
2545         ANS_LOGE("[GetEnabledForBundleSlot] fail: read result failed.");
2546         return ERR_ANS_PARCELABLE_FAILED;
2547     }
2548 
2549     if (!reply.ReadBool(enabled)) {
2550         ANS_LOGE("[GetEnabledForBundleSlot] fail: read enable failed.");
2551         return ERR_ANS_PARCELABLE_FAILED;
2552     }
2553 
2554     return result;
2555 }
2556 
SetSyncNotificationEnabledWithoutApp(const int32_t userId,const bool enabled)2557 ErrCode AnsManagerProxy::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled)
2558 {
2559     MessageParcel data;
2560     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2561         ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: write interface token failed.");
2562         return ERR_ANS_PARCELABLE_FAILED;
2563     }
2564 
2565     if (!data.WriteInt32(userId)) {
2566         ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail:: write userId failed.");
2567         return ERR_ANS_PARCELABLE_FAILED;
2568     }
2569 
2570     if (!data.WriteBool(enabled)) {
2571         ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: write enabled failed");
2572         return ERR_ANS_PARCELABLE_FAILED;
2573     }
2574 
2575     MessageParcel reply;
2576     MessageOption option = {MessageOption::TF_SYNC};
2577     ErrCode result = InnerTransact(SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP, option, data, reply);
2578     if (result != ERR_OK) {
2579         ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: transact ErrCode=%{public}d", result);
2580         return ERR_ANS_TRANSACT_FAILED;
2581     }
2582 
2583     if (!reply.ReadInt32(result)) {
2584         ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: read result failed.");
2585         return ERR_ANS_PARCELABLE_FAILED;
2586     }
2587 
2588     return result;
2589 }
2590 
GetSyncNotificationEnabledWithoutApp(const int32_t userId,bool & enabled)2591 ErrCode AnsManagerProxy::GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled)
2592 {
2593     MessageParcel data;
2594     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2595         ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: write interface token failed.");
2596         return ERR_ANS_PARCELABLE_FAILED;
2597     }
2598 
2599     if (!data.WriteInt32(userId)) {
2600         ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail:: write userId failed.");
2601         return ERR_ANS_PARCELABLE_FAILED;
2602     }
2603 
2604     MessageParcel reply;
2605     MessageOption option = {MessageOption::TF_SYNC};
2606     ErrCode result = InnerTransact(GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP, option, data, reply);
2607     if (result != ERR_OK) {
2608         ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: transact ErrCode=%{public}d", result);
2609         return ERR_ANS_TRANSACT_FAILED;
2610     }
2611 
2612     if (!reply.ReadInt32(result)) {
2613         ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: read result failed.");
2614         return ERR_ANS_PARCELABLE_FAILED;
2615     }
2616 
2617     if (!reply.ReadBool(enabled)) {
2618         ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: read enable failed.");
2619         return ERR_ANS_PARCELABLE_FAILED;
2620     }
2621 
2622     return result;
2623 }
2624 
ShellDump(const std::string & cmd,const std::string & bundle,int32_t userId,std::vector<std::string> & dumpInfo)2625 ErrCode AnsManagerProxy::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId,
2626     std::vector<std::string> &dumpInfo)
2627 {
2628     MessageParcel data;
2629     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
2630         ANS_LOGE("[ShellDump] fail: write interface token failed.");
2631         return ERR_ANS_PARCELABLE_FAILED;
2632     }
2633     if (!data.WriteString(cmd)) {
2634         ANS_LOGE("[ShellDump] fail: write dump cmd failed.");
2635         return ERR_ANS_PARCELABLE_FAILED;
2636     }
2637     if (!data.WriteString(bundle)) {
2638         ANS_LOGE("[ShellDump] fail: write dump bundle failed.");
2639         return ERR_ANS_PARCELABLE_FAILED;
2640     }
2641     if (!data.WriteInt32(userId)) {
2642         ANS_LOGE("[ShellDump] fail: write dump userId failed.");
2643         return ERR_ANS_PARCELABLE_FAILED;
2644     }
2645     MessageParcel reply;
2646     MessageOption option = {MessageOption::TF_SYNC};
2647     ErrCode result = InnerTransact(SHELL_DUMP, option, data, reply);
2648     if (result != ERR_OK) {
2649         ANS_LOGE("[ShellDump] fail: transact ErrCode=%{public}d", result);
2650         return ERR_ANS_TRANSACT_FAILED;
2651     }
2652     if (!reply.ReadInt32(result)) {
2653         ANS_LOGE("[ShellDump] fail: read result failed.");
2654         return ERR_ANS_PARCELABLE_FAILED;
2655     }
2656     if (!reply.ReadStringVector(&dumpInfo)) {
2657         ANS_LOGE("[ShellDump] fail: read dumpInfo failed.");
2658         return ERR_ANS_PARCELABLE_FAILED;
2659     }
2660     return result;
2661 }
2662 }  // namespace Notification
2663 }  // namespace OHOS
2664