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