• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_button_option.h"
24 #include "parcel.h"
25 #include "reminder_request_alarm.h"
26 #include "reminder_request_calendar.h"
27 #include "reminder_request_timer.h"
28 
29 namespace OHOS {
30 namespace Notification {
31 const std::map<NotificationInterfaceCode, std::function<ErrCode(AnsManagerStub *, MessageParcel &, MessageParcel &)>>
32     AnsManagerStub::interfaces_ = {
33         {NotificationInterfaceCode::PUBLISH_NOTIFICATION,
34             std::bind(
35                 &AnsManagerStub::HandlePublish, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
36         {NotificationInterfaceCode::CANCEL_NOTIFICATION,
37             std::bind(
38                 &AnsManagerStub::HandleCancel, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
39         {NotificationInterfaceCode::CANCEL_ALL_NOTIFICATIONS,
40             std::bind(
41                 &AnsManagerStub::HandleCancelAll, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
42         {NotificationInterfaceCode::CANCEL_AS_BUNDLE,
43             std::bind(&AnsManagerStub::HandleCancelAsBundle, std::placeholders::_1, std::placeholders::_2,
44                 std::placeholders::_3)},
45         {NotificationInterfaceCode::ADD_SLOT_BY_TYPE,
46             std::bind(&AnsManagerStub::HandleAddSlotByType, std::placeholders::_1, std::placeholders::_2,
47                 std::placeholders::_3)},
48         {NotificationInterfaceCode::ADD_SLOTS,
49             std::bind(
50                 &AnsManagerStub::HandleAddSlots, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
51         {NotificationInterfaceCode::REMOVE_SLOT_BY_TYPE,
52             std::bind(&AnsManagerStub::HandleRemoveSlotByType, std::placeholders::_1, std::placeholders::_2,
53                 std::placeholders::_3)},
54         {NotificationInterfaceCode::REMOVE_ALL_SLOTS,
55             std::bind(&AnsManagerStub::HandleRemoveAllSlots, std::placeholders::_1, std::placeholders::_2,
56                 std::placeholders::_3)},
57         {NotificationInterfaceCode::GET_SLOT_BY_TYPE,
58             std::bind(&AnsManagerStub::HandleGetSlotByType, std::placeholders::_1, std::placeholders::_2,
59                 std::placeholders::_3)},
60         {NotificationInterfaceCode::GET_SLOTS,
61             std::bind(
62                 &AnsManagerStub::HandleGetSlots, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
63         {NotificationInterfaceCode::GET_SLOT_NUM_AS_BUNDLE,
64             std::bind(&AnsManagerStub::HandleGetSlotNumAsBundle, std::placeholders::_1, std::placeholders::_2,
65                 std::placeholders::_3)},
66         {NotificationInterfaceCode::GET_ACTIVE_NOTIFICATIONS,
67             std::bind(&AnsManagerStub::HandleGetActiveNotifications, std::placeholders::_1, std::placeholders::_2,
68                 std::placeholders::_3)},
69         {NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_NUMS,
70             std::bind(&AnsManagerStub::HandleGetActiveNotificationNums, std::placeholders::_1, std::placeholders::_2,
71                 std::placeholders::_3)},
72         {NotificationInterfaceCode::GET_ALL_ACTIVE_NOTIFICATIONS,
73             std::bind(&AnsManagerStub::HandleGetAllActiveNotifications, std::placeholders::_1, std::placeholders::_2,
74                 std::placeholders::_3)},
75         {NotificationInterfaceCode::GET_SPECIAL_ACTIVE_NOTIFICATIONS,
76             std::bind(&AnsManagerStub::HandleGetSpecialActiveNotifications, std::placeholders::_1,
77                 std::placeholders::_2, std::placeholders::_3)},
78         {NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER,
79             std::bind(&AnsManagerStub::HandleGetActiveNotificationByFilter, std::placeholders::_1,
80                 std::placeholders::_2, std::placeholders::_3)},
81         {NotificationInterfaceCode::SET_NOTIFICATION_AGENT,
82             std::bind(&AnsManagerStub::HandleSetNotificationAgent, std::placeholders::_1, std::placeholders::_2,
83                 std::placeholders::_3)},
84         {NotificationInterfaceCode::GET_NOTIFICATION_AGENT,
85             std::bind(&AnsManagerStub::HandleGetNotificationAgent, std::placeholders::_1, std::placeholders::_2,
86                 std::placeholders::_3)},
87         {NotificationInterfaceCode::CAN_PUBLISH_AS_BUNDLE,
88             std::bind(&AnsManagerStub::HandleCanPublishAsBundle, std::placeholders::_1, std::placeholders::_2,
89                 std::placeholders::_3)},
90         {NotificationInterfaceCode::PUBLISH_AS_BUNDLE,
91             std::bind(&AnsManagerStub::HandlePublishAsBundle, std::placeholders::_1, std::placeholders::_2,
92                 std::placeholders::_3)},
93         {NotificationInterfaceCode::SET_NOTIFICATION_BADGE_NUM,
94             std::bind(&AnsManagerStub::HandleSetNotificationBadgeNum, std::placeholders::_1, std::placeholders::_2,
95                 std::placeholders::_3)},
96         {NotificationInterfaceCode::GET_BUNDLE_IMPORTANCE,
97             std::bind(&AnsManagerStub::HandleGetBundleImportance, std::placeholders::_1, std::placeholders::_2,
98                 std::placeholders::_3)},
99         {NotificationInterfaceCode::IS_NOTIFICATION_POLICY_ACCESS_GRANTED,
100             std::bind(&AnsManagerStub::HandleIsNotificationPolicyAccessGranted, std::placeholders::_1,
101                 std::placeholders::_2, std::placeholders::_3)},
102         {NotificationInterfaceCode::REMOVE_NOTIFICATION,
103             std::bind(&AnsManagerStub::HandleRemoveNotification, std::placeholders::_1, std::placeholders::_2,
104                 std::placeholders::_3)},
105         {NotificationInterfaceCode::REMOVE_ALL_NOTIFICATIONS,
106             std::bind(&AnsManagerStub::HandleRemoveAllNotifications, std::placeholders::_1, std::placeholders::_2,
107                 std::placeholders::_3)},
108         {NotificationInterfaceCode::REMOVE_NOTIFICATIONS_BY_KEYS,
109             std::bind(&AnsManagerStub::HandleRemoveNotifications, std::placeholders::_1, std::placeholders::_2,
110                 std::placeholders::_3)},
111         {NotificationInterfaceCode::DELETE_NOTIFICATION,
112             std::bind(
113                 &AnsManagerStub::HandleDelete, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
114         {NotificationInterfaceCode::DELETE_NOTIFICATION_BY_BUNDLE,
115             std::bind(&AnsManagerStub::HandleDeleteByBundle, std::placeholders::_1, std::placeholders::_2,
116                 std::placeholders::_3)},
117         {NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS,
118             std::bind(
119                 &AnsManagerStub::HandleDeleteAll, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
120         {NotificationInterfaceCode::GET_SLOTS_BY_BUNDLE,
121             std::bind(&AnsManagerStub::HandleGetSlotsByBundle, std::placeholders::_1, std::placeholders::_2,
122                 std::placeholders::_3)},
123         {NotificationInterfaceCode::UPDATE_SLOTS,
124             std::bind(&AnsManagerStub::HandleUpdateSlots, std::placeholders::_1, std::placeholders::_2,
125                 std::placeholders::_3)},
126         {NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION,
127             std::bind(&AnsManagerStub::HandleRequestEnableNotification, std::placeholders::_1, std::placeholders::_2,
128                 std::placeholders::_3)},
129         {NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE,
130             std::bind(&AnsManagerStub::HandleSetNotificationsEnabledForBundle, std::placeholders::_1,
131                 std::placeholders::_2, std::placeholders::_3)},
132         {NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE,
133             std::bind(&AnsManagerStub::HandleSetNotificationsEnabledForAllBundles, std::placeholders::_1,
134                 std::placeholders::_2, std::placeholders::_3)},
135         {NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE,
136             std::bind(&AnsManagerStub::HandleSetNotificationsEnabledForSpecialBundle, std::placeholders::_1,
137                 std::placeholders::_2, std::placeholders::_3)},
138         {NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE,
139             std::bind(&AnsManagerStub::HandleSetShowBadgeEnabledForBundle, std::placeholders::_1, std::placeholders::_2,
140                 std::placeholders::_3)},
141         {NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE,
142             std::bind(&AnsManagerStub::HandleGetShowBadgeEnabledForBundle, std::placeholders::_1, std::placeholders::_2,
143                 std::placeholders::_3)},
144         {NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED,
145             std::bind(&AnsManagerStub::HandleGetShowBadgeEnabled, std::placeholders::_1, std::placeholders::_2,
146                 std::placeholders::_3)},
147         {NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION,
148             std::bind(
149                 &AnsManagerStub::HandleSubscribe, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
150         {NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION,
151             std::bind(&AnsManagerStub::HandleUnsubscribe, std::placeholders::_1, std::placeholders::_2,
152                 std::placeholders::_3)},
153         {NotificationInterfaceCode::IS_ALLOWED_NOTIFY,
154             std::bind(&AnsManagerStub::HandleIsAllowedNotify, std::placeholders::_1, std::placeholders::_2,
155                 std::placeholders::_3)},
156         {NotificationInterfaceCode::IS_ALLOWED_NOTIFY_SELF,
157             std::bind(&AnsManagerStub::HandleIsAllowedNotifySelf, std::placeholders::_1, std::placeholders::_2,
158                 std::placeholders::_3)},
159         {NotificationInterfaceCode::IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY,
160             std::bind(&AnsManagerStub::HandleIsSpecialBundleAllowedNotify, std::placeholders::_1, std::placeholders::_2,
161                 std::placeholders::_3)},
162         {NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE,
163             std::bind(&AnsManagerStub::HandleSetDoNotDisturbDate, std::placeholders::_1, std::placeholders::_2,
164                 std::placeholders::_3)},
165         {NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE,
166             std::bind(&AnsManagerStub::HandleGetDoNotDisturbDate, std::placeholders::_1, std::placeholders::_2,
167                 std::placeholders::_3)},
168         {NotificationInterfaceCode::DOES_SUPPORT_DO_NOT_DISTURB_MODE,
169             std::bind(&AnsManagerStub::HandleDoesSupportDoNotDisturbMode, std::placeholders::_1, std::placeholders::_2,
170                 std::placeholders::_3)},
171         {NotificationInterfaceCode::CANCEL_GROUP,
172             std::bind(&AnsManagerStub::HandleCancelGroup, std::placeholders::_1, std::placeholders::_2,
173                 std::placeholders::_3)},
174         {NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE,
175             std::bind(&AnsManagerStub::HandleRemoveGroupByBundle, std::placeholders::_1, std::placeholders::_2,
176                 std::placeholders::_3)},
177         {NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED,
178             std::bind(&AnsManagerStub::HandleIsDistributedEnabled, std::placeholders::_1, std::placeholders::_2,
179                 std::placeholders::_3)},
180         {NotificationInterfaceCode::ENABLE_DISTRIBUTED,
181             std::bind(&AnsManagerStub::HandleEnableDistributed, std::placeholders::_1, std::placeholders::_2,
182                 std::placeholders::_3)},
183         {NotificationInterfaceCode::ENABLE_DISTRIBUTED_BY_BUNDLE,
184             std::bind(&AnsManagerStub::HandleEnableDistributedByBundle, std::placeholders::_1, std::placeholders::_2,
185                 std::placeholders::_3)},
186         {NotificationInterfaceCode::ENABLE_DISTRIBUTED_SELF,
187             std::bind(&AnsManagerStub::HandleEnableDistributedSelf, std::placeholders::_1, std::placeholders::_2,
188                 std::placeholders::_3)},
189         {NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED_BY_BUNDLE,
190             std::bind(&AnsManagerStub::HandleIsDistributedEnableByBundle, std::placeholders::_1, std::placeholders::_2,
191                 std::placeholders::_3)},
192         {NotificationInterfaceCode::GET_DEVICE_REMIND_TYPE,
193             std::bind(&AnsManagerStub::HandleGetDeviceRemindType, std::placeholders::_1, std::placeholders::_2,
194                 std::placeholders::_3)},
195         {NotificationInterfaceCode::SHELL_DUMP,
196             std::bind(
197                 &AnsManagerStub::HandleShellDump, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
198         {NotificationInterfaceCode::PUBLISH_CONTINUOUS_TASK_NOTIFICATION,
199             std::bind(
200                 &AnsManagerStub::HandlePublishContinuousTaskNotification, std::placeholders::_1, std::placeholders::_2,
201                 std::placeholders::_3)},
202         {NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION,
203             std::bind(
204                 &AnsManagerStub::HandleCancelContinuousTaskNotification, std::placeholders::_1, std::placeholders::_2,
205                 std::placeholders::_3)},
206         {NotificationInterfaceCode::PUBLISH_REMINDER,
207             std::bind(&AnsManagerStub::HandlePublishReminder, std::placeholders::_1, std::placeholders::_2,
208                 std::placeholders::_3)},
209         {NotificationInterfaceCode::CANCEL_REMINDER,
210             std::bind(&AnsManagerStub::HandleCancelReminder, std::placeholders::_1, std::placeholders::_2,
211                 std::placeholders::_3)},
212         {NotificationInterfaceCode::CANCEL_ALL_REMINDERS,
213             std::bind(
214                 &AnsManagerStub::HandleCancelAllReminders, std::placeholders::_1, std::placeholders::_2,
215                 std::placeholders::_3)},
216         {NotificationInterfaceCode::GET_ALL_VALID_REMINDERS,
217             std::bind(&AnsManagerStub::HandleGetValidReminders, std::placeholders::_1, std::placeholders::_2,
218                 std::placeholders::_3)},
219         {NotificationInterfaceCode::IS_SUPPORT_TEMPLATE,
220             std::bind(
221                 &AnsManagerStub::HandleIsSupportTemplate, std::placeholders::_1, std::placeholders::_2,
222                 std::placeholders::_3)},
223         {NotificationInterfaceCode::IS_SPECIAL_USER_ALLOWED_NOTIFY,
224             std::bind(&AnsManagerStub::HandleIsSpecialUserAllowedNotifyByUser, std::placeholders::_1,
225                 std::placeholders::_2, std::placeholders::_3)},
226         {NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER,
227             std::bind(&AnsManagerStub::HandleSetNotificationsEnabledByUser, std::placeholders::_1,
228                 std::placeholders::_2, std::placeholders::_3)},
229         {NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER,
230             std::bind(&AnsManagerStub::HandleDeleteAllByUser, std::placeholders::_1, std::placeholders::_2,
231                 std::placeholders::_3)},
232         {NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER,
233             std::bind(&AnsManagerStub::HandleSetDoNotDisturbDateByUser, std::placeholders::_1, std::placeholders::_2,
234                 std::placeholders::_3)},
235         {NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER,
236             std::bind(&AnsManagerStub::HandleGetDoNotDisturbDateByUser, std::placeholders::_1, std::placeholders::_2,
237                 std::placeholders::_3)},
238         {NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT,
239             std::bind(&AnsManagerStub::HandleSetEnabledForBundleSlot, std::placeholders::_1, std::placeholders::_2,
240                 std::placeholders::_3)},
241         {NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT,
242             std::bind(&AnsManagerStub::HandleGetEnabledForBundleSlot, std::placeholders::_1, std::placeholders::_2,
243                 std::placeholders::_3)},
244         {NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT_SELF,
245             std::bind(&AnsManagerStub::HandleGetEnabledForBundleSlotSelf, std::placeholders::_1, std::placeholders::_2,
246                 std::placeholders::_3)},
247         {NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP,
248             std::bind(&AnsManagerStub::HandleDistributedSetEnabledWithoutApp, std::placeholders::_1,
249                 std::placeholders::_2, std::placeholders::_3)},
250         {NotificationInterfaceCode::GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP,
251             std::bind(&AnsManagerStub::HandleDistributedGetEnabledWithoutApp, std::placeholders::_1,
252                 std::placeholders::_2, std::placeholders::_3)},
253         {NotificationInterfaceCode::SET_BADGE_NUMBER,
254             std::bind(&AnsManagerStub::HandleSetBadgeNumber, std::placeholders::_1,
255                 std::placeholders::_2, std::placeholders::_3)},
256         {NotificationInterfaceCode::REGISTER_PUSH_CALLBACK,
257             std::bind(&AnsManagerStub::HandleRegisterPushCallback, std::placeholders::_1,
258                 std::placeholders::_2, std::placeholders::_3)},
259         {NotificationInterfaceCode::UNREGISTER_PUSH_CALLBACK,
260             std::bind(&AnsManagerStub::HandleUnregisterPushCallback, std::placeholders::_1,
261                 std::placeholders::_2, std::placeholders::_3)},
262         {NotificationInterfaceCode::SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION,
263             std::bind(&AnsManagerStub::HandleSubscribeLocalLiveView, std::placeholders::_1,
264                 std::placeholders::_2, std::placeholders::_3)},
265         {NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION,
266             std::bind(&AnsManagerStub::HandleTriggerLocalLiveView, std::placeholders::_1,
267                 std::placeholders::_2, std::placeholders::_3)},
268         {NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION_SELF,
269             std::bind(&AnsManagerStub::HandleSubscribeSelf, std::placeholders::_1,
270                 std::placeholders::_2, std::placeholders::_3)},
271         {NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE,
272             std::bind(&AnsManagerStub::HandleSetSlotFlagsAsBundle, std::placeholders::_1,
273                 std::placeholders::_2, std::placeholders::_3)},
274         {NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE,
275             std::bind(&AnsManagerStub::HandleGetSlotFlagsAsBundle, std::placeholders::_1,
276                 std::placeholders::_2, std::placeholders::_3)},
277 };
278 
AnsManagerStub()279 AnsManagerStub::AnsManagerStub()
280 {}
281 
~AnsManagerStub()282 AnsManagerStub::~AnsManagerStub()
283 {}
284 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & flags)285 int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags)
286 {
287     std::u16string descriptor = AnsManagerStub::GetDescriptor();
288     std::u16string remoteDescriptor = data.ReadInterfaceToken();
289     if (descriptor != remoteDescriptor) {
290         ANS_LOGE("[OnRemoteRequest] fail: invalid interface token!");
291         return OBJECT_NULL;
292     }
293 
294     auto it = interfaces_.find(static_cast<NotificationInterfaceCode>(code));
295     if (it == interfaces_.end()) {
296         ANS_LOGE("[OnRemoteRequest] fail: unknown code!");
297         return IPCObjectStub::OnRemoteRequest(code, data, reply, flags);
298     }
299 
300     auto fun = it->second;
301     if (fun == nullptr) {
302         ANS_LOGE("[OnRemoteRequest] fail: not find function!");
303         return IPCObjectStub::OnRemoteRequest(code, data, reply, flags);
304     }
305 
306     ErrCode result = fun(this, data, reply);
307     if (SUCCEEDED(result)) {
308         return NO_ERROR;
309     }
310 
311     ANS_LOGE("[OnRemoteRequest] fail: Failed to call interface %{public}u, err:%{public}d", code, result);
312     return result;
313 }
314 
HandlePublish(MessageParcel & data,MessageParcel & reply)315 ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply)
316 {
317     std::string label;
318     if (!data.ReadString(label)) {
319         ANS_LOGE("[HandlePublish] fail: read label failed");
320         return ERR_ANS_PARCELABLE_FAILED;
321     }
322 
323     sptr<NotificationRequest> notification = data.ReadParcelable<NotificationRequest>();
324     if (!notification) {
325         ANS_LOGE("[HandlePublish] fail: notification ReadParcelable failed");
326         return ERR_ANS_PARCELABLE_FAILED;
327     }
328 
329     ErrCode result = Publish(label, notification);
330     if (!reply.WriteInt32(result)) {
331         ANS_LOGE("[HandlePublish] fail: write result failed, ErrCode=%{public}d", result);
332         return ERR_ANS_PARCELABLE_FAILED;
333     }
334     return ERR_OK;
335 }
336 
HandleCancel(MessageParcel & data,MessageParcel & reply)337 ErrCode AnsManagerStub::HandleCancel(MessageParcel &data, MessageParcel &reply)
338 {
339     int32_t notificationId = 0;
340     if (!data.ReadInt32(notificationId)) {
341         ANS_LOGE("[HandleCancel] fail: read notificationId failed");
342         return ERR_ANS_PARCELABLE_FAILED;
343     }
344 
345     std::string label;
346     if (!data.ReadString(label)) {
347         ANS_LOGE("[HandleCancel] fail: read label failed");
348         return ERR_ANS_PARCELABLE_FAILED;
349     }
350 
351     ErrCode result = Cancel(notificationId, label);
352     if (!reply.WriteInt32(result)) {
353         ANS_LOGE("[HandleCancel] fail: write result failed, ErrCode=%{public}d", result);
354         return ERR_ANS_PARCELABLE_FAILED;
355     }
356     return ERR_OK;
357 }
358 
HandleCancelAll(MessageParcel & data,MessageParcel & reply)359 ErrCode AnsManagerStub::HandleCancelAll(MessageParcel &data, MessageParcel &reply)
360 {
361     ErrCode result = CancelAll();
362     if (!reply.WriteInt32(result)) {
363         ANS_LOGE("[HandleCancelAll] fail: write result failed, ErrCode=%{public}d", result);
364         return ERR_ANS_PARCELABLE_FAILED;
365     }
366     return ERR_OK;
367 }
368 
HandleCancelAsBundle(MessageParcel & data,MessageParcel & reply)369 ErrCode AnsManagerStub::HandleCancelAsBundle(MessageParcel &data, MessageParcel &reply)
370 {
371     int32_t notificationId = 0;
372     if (!data.ReadInt32(notificationId)) {
373         ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed");
374         return ERR_ANS_PARCELABLE_FAILED;
375     }
376 
377     std::string representativeBundle;
378     if (!data.ReadString(representativeBundle)) {
379         ANS_LOGE("[HandleCancelAsBundle] fail: read representativeBundle failed");
380         return ERR_ANS_PARCELABLE_FAILED;
381     }
382 
383     int32_t userId = 0;
384     if (!data.ReadInt32(userId)) {
385         ANS_LOGE("[HandleCancelAsBundle] fail: read userId failed");
386         return ERR_ANS_PARCELABLE_FAILED;
387     }
388 
389     ErrCode result = CancelAsBundle(notificationId, representativeBundle, userId);
390     if (!reply.WriteInt32(result)) {
391         ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result);
392         return ERR_ANS_PARCELABLE_FAILED;
393     }
394     return ERR_OK;
395 }
396 
HandleAddSlotByType(MessageParcel & data,MessageParcel & reply)397 ErrCode AnsManagerStub::HandleAddSlotByType(MessageParcel &data, MessageParcel &reply)
398 {
399     NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(data.ReadInt32());
400     ErrCode result = AddSlotByType(slotType);
401     if (!reply.WriteInt32(result)) {
402         ANS_LOGE("[HandleAddSlotByType] fail: write result failed, ErrCode=%{public}d", result);
403         return ERR_ANS_PARCELABLE_FAILED;
404     }
405     return ERR_OK;
406 }
407 
HandleAddSlots(MessageParcel & data,MessageParcel & reply)408 ErrCode AnsManagerStub::HandleAddSlots(MessageParcel &data, MessageParcel &reply)
409 {
410     std::vector<sptr<NotificationSlot>> slots;
411     if (!ReadParcelableVector(slots, data)) {
412         ANS_LOGE("[HandleAddSlots] fail: read slotsSize failed");
413         return ERR_ANS_PARCELABLE_FAILED;
414     }
415     ErrCode result = AddSlots(slots);
416     if (!reply.WriteInt32(result)) {
417         ANS_LOGE("[HandleAddSlots] fail: write result failed, ErrCode=%{public}d", result);
418         return ERR_ANS_PARCELABLE_FAILED;
419     }
420     return ERR_OK;
421 }
422 
HandleRemoveSlotByType(MessageParcel & data,MessageParcel & reply)423 ErrCode AnsManagerStub::HandleRemoveSlotByType(MessageParcel &data, MessageParcel &reply)
424 {
425     NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(data.ReadInt32());
426 
427     ErrCode result = RemoveSlotByType(slotType);
428     if (!reply.WriteInt32(result)) {
429         ANS_LOGE("[HandleRemoveSlotByType] fail: write result failed, ErrCode=%{public}d", result);
430         return ERR_ANS_PARCELABLE_FAILED;
431     }
432     return ERR_OK;
433 }
434 
HandleRemoveAllSlots(MessageParcel & data,MessageParcel & reply)435 ErrCode AnsManagerStub::HandleRemoveAllSlots(MessageParcel &data, MessageParcel &reply)
436 {
437     ErrCode result = RemoveAllSlots();
438     if (!reply.WriteInt32(result)) {
439         ANS_LOGE("[HandleRemoveAllSlots] fail: write result failed, ErrCode=%{public}d", result);
440         return ERR_ANS_PARCELABLE_FAILED;
441     }
442     return ERR_OK;
443 }
444 
HandleGetSlots(MessageParcel & data,MessageParcel & reply)445 ErrCode AnsManagerStub::HandleGetSlots(MessageParcel &data, MessageParcel &reply)
446 {
447     std::vector<sptr<NotificationSlot>> slots;
448     ErrCode result = GetSlots(slots);
449     if (!WriteParcelableVector(slots, reply, result)) {
450         ANS_LOGE("[HandleGetSlots] fail: write slots failed");
451         return ERR_ANS_PARCELABLE_FAILED;
452     }
453 
454     return ERR_OK;
455 }
456 
HandleGetSlotByType(MessageParcel & data,MessageParcel & reply)457 ErrCode AnsManagerStub::HandleGetSlotByType(MessageParcel &data, MessageParcel &reply)
458 {
459     NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(data.ReadInt32());
460 
461     sptr<NotificationSlot> slot = nullptr;
462     ErrCode result = GetSlotByType(slotType, slot);
463     if (!reply.WriteInt32(result)) {
464         ANS_LOGE("[HandleGetSlotByType] fail: write result failed, ErrCode=%{public}d", result);
465         return ERR_ANS_PARCELABLE_FAILED;
466     }
467 
468     if (!reply.WriteParcelable(slot)) {
469         ANS_LOGE("[HandleGetSlotByType] fail: write slot failed.");
470         return ERR_ANS_PARCELABLE_FAILED;
471     }
472     return ERR_OK;
473 }
474 
HandleGetSlotNumAsBundle(MessageParcel & data,MessageParcel & reply)475 ErrCode AnsManagerStub::HandleGetSlotNumAsBundle(MessageParcel &data, MessageParcel &reply)
476 {
477     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
478     if (bundleOption == nullptr) {
479         ANS_LOGE("[HandleGetSlotNumAsBundle] fail: read bundle failed.");
480         return ERR_ANS_PARCELABLE_FAILED;
481     }
482 
483     uint64_t num = 0;
484     ErrCode result = GetSlotNumAsBundle(bundleOption, num);
485     if (!reply.WriteInt32(result)) {
486         ANS_LOGE("[HandleGetSlotNumAsBundle] fail: write result failed, ErrCode=%{public}d", result);
487         return ERR_ANS_PARCELABLE_FAILED;
488     }
489 
490     if (!reply.WriteUint64(num)) {
491         ANS_LOGE("[HandleGetSlotNumAsBundle] fail: write enabled failed, ErrCode=%{public}d", result);
492         return ERR_ANS_PARCELABLE_FAILED;
493     }
494     return ERR_OK;
495 }
496 
HandleSetSlotFlagsAsBundle(MessageParcel & data,MessageParcel & reply)497 ErrCode AnsManagerStub::HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply)
498 {
499     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
500     if (bundleOption == nullptr) {
501         ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read bundle failed.");
502         return ERR_ANS_PARCELABLE_FAILED;
503     }
504 
505     int32_t slotFlags = 0;
506     if (!data.ReadInt32(slotFlags)) {
507         ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read notification failed");
508         return ERR_ANS_PARCELABLE_FAILED;
509     }
510 
511     ErrCode result = SetSlotFlagsAsBundle(bundleOption, slotFlags);
512     if (!reply.WriteInt32(result)) {
513         ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result);
514         return ERR_ANS_PARCELABLE_FAILED;
515     }
516 
517     return ERR_OK;
518 }
519 
HandleGetSlotFlagsAsBundle(MessageParcel & data,MessageParcel & reply)520 ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply)
521 {
522     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
523     if (bundleOption == nullptr) {
524         ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: read bundle failed.");
525         return ERR_ANS_PARCELABLE_FAILED;
526     }
527 
528     uint32_t slotFlags = 0;
529     ErrCode result = GetSlotFlagsAsBundle(bundleOption, slotFlags);
530     if (!reply.WriteInt32(result)) {
531         ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result);
532         return ERR_ANS_PARCELABLE_FAILED;
533     }
534 
535     if (!reply.WriteUint32(slotFlags)) {
536         ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write enabled failed, ErrCode=%{public}d", result);
537         return ERR_ANS_PARCELABLE_FAILED;
538     }
539 
540     return ERR_OK;
541 }
542 
HandleGetActiveNotifications(MessageParcel & data,MessageParcel & reply)543 ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply)
544 {
545     std::vector<sptr<NotificationRequest>> notifications;
546     ErrCode result = GetActiveNotifications(notifications);
547     if (!WriteParcelableVector(notifications, reply, result)) {
548         ANS_LOGE("[HandleGetActiveNotifications] fail: write notifications failed");
549         return ERR_ANS_PARCELABLE_FAILED;
550     }
551     return ERR_OK;
552 }
553 
HandleGetActiveNotificationNums(MessageParcel & data,MessageParcel & reply)554 ErrCode AnsManagerStub::HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply)
555 {
556     uint64_t num = 0;
557     ErrCode result = GetActiveNotificationNums(num);
558     if (!reply.WriteInt32(result)) {
559         ANS_LOGE("[HandleGetActiveNotificationNums] fail: write result failed, ErrCode=%{public}d", result);
560         return ERR_ANS_PARCELABLE_FAILED;
561     }
562 
563     if (!reply.WriteUint64(num)) {
564         ANS_LOGE("[HandleGetActiveNotificationNums] fail: write num failed");
565         return ERR_ANS_PARCELABLE_FAILED;
566     }
567     return ERR_OK;
568 }
569 
HandleGetAllActiveNotifications(MessageParcel & data,MessageParcel & reply)570 ErrCode AnsManagerStub::HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply)
571 {
572     std::vector<sptr<Notification>> notifications;
573     ErrCode result = GetAllActiveNotifications(notifications);
574     if (!WriteParcelableVector(notifications, reply, result)) {
575         ANS_LOGE("[HandleGetAllActiveNotifications] fail: write notifications failed");
576         return ERR_ANS_PARCELABLE_FAILED;
577     }
578     return ERR_OK;
579 }
580 
HandleGetSpecialActiveNotifications(MessageParcel & data,MessageParcel & reply)581 ErrCode AnsManagerStub::HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply)
582 {
583     std::vector<std::string> key;
584     if (!data.ReadStringVector(&key)) {
585         ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: read key failed");
586         return ERR_ANS_PARCELABLE_FAILED;
587     }
588 
589     std::vector<sptr<Notification>> notifications;
590     ErrCode result = GetSpecialActiveNotifications(key, notifications);
591     if (!WriteParcelableVector(notifications, reply, result)) {
592         ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: write notifications failed");
593         return ERR_ANS_PARCELABLE_FAILED;
594     }
595     return ERR_OK;
596 }
597 
HandleGetActiveNotificationByFilter(MessageParcel & data,MessageParcel & reply)598 ErrCode AnsManagerStub::HandleGetActiveNotificationByFilter(MessageParcel &data, MessageParcel &reply)
599 {
600     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
601     if (bundleOption == nullptr) {
602         ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read bundleOption failed.");
603         return ERR_ANS_PARCELABLE_FAILED;
604     }
605 
606     int32_t notificationId = 0;
607     if (!data.ReadInt32(notificationId)) {
608         ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read notificationId failed");
609         return ERR_ANS_PARCELABLE_FAILED;
610     }
611 
612     std::string label;
613     if (!data.ReadString(label)) {
614         ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read label failed");
615         return ERR_ANS_PARCELABLE_FAILED;
616     }
617 
618     std::vector<std::string> extraInfoKeys;
619     if (!data.ReadStringVector(&extraInfoKeys)) {
620         ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read extraInfoKeys failed");
621         return ERR_ANS_PARCELABLE_FAILED;
622     }
623 
624     sptr<NotificationRequest> request;
625     ErrCode result = GetActiveNotificationByFilter(bundleOption, notificationId, label, extraInfoKeys, request);
626     if (!reply.WriteInt32(result)) {
627         ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: write result failed, ErrCode=%{public}d", result);
628         return ERR_ANS_PARCELABLE_FAILED;
629     }
630 
631     if (!reply.WriteParcelable(request)) {
632         ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed");
633         return ERR_ANS_PARCELABLE_FAILED;
634     }
635     return result;
636 }
637 
HandleSetNotificationAgent(MessageParcel & data,MessageParcel & reply)638 ErrCode AnsManagerStub::HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply)
639 {
640     std::string agent;
641     if (!data.ReadString(agent)) {
642         ANS_LOGE("[HandleSetNotificationAgent] fail: read agent failed");
643         return ERR_ANS_PARCELABLE_FAILED;
644     }
645 
646     ErrCode result = SetNotificationAgent(agent);
647     if (!reply.WriteInt32(result)) {
648         ANS_LOGE("[HandleSetNotificationAgent] fail: write result failed, ErrCode=%{public}d", result);
649         return ERR_ANS_PARCELABLE_FAILED;
650     }
651     return ERR_OK;
652 }
653 
HandleGetNotificationAgent(MessageParcel & data,MessageParcel & reply)654 ErrCode AnsManagerStub::HandleGetNotificationAgent(MessageParcel &data, MessageParcel &reply)
655 {
656     std::string agent;
657     ErrCode result = GetNotificationAgent(agent);
658     if (!reply.WriteInt32(result)) {
659         ANS_LOGE("[HandleGetNotificationAgent] fail: write result failed, ErrCode=%{public}d", result);
660         return ERR_ANS_PARCELABLE_FAILED;
661     }
662 
663     if (!reply.WriteString(agent)) {
664         ANS_LOGE("[HandleGetNotificationAgent] fail: write agent failed");
665         return ERR_ANS_PARCELABLE_FAILED;
666     }
667 
668     return ERR_OK;
669 }
670 
HandleCanPublishAsBundle(MessageParcel & data,MessageParcel & reply)671 ErrCode AnsManagerStub::HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply)
672 {
673     std::string representativeBundle;
674     if (!data.ReadString(representativeBundle)) {
675         ANS_LOGE("[HandleCanPublishAsBundle] fail: read representativeBundle failed");
676         return ERR_ANS_PARCELABLE_FAILED;
677     }
678 
679     bool canPublish = false;
680     ErrCode result = CanPublishAsBundle(representativeBundle, canPublish);
681     if (!reply.WriteInt32(result)) {
682         ANS_LOGE("[HandleCanPublishAsBundle] fail: write result failed, ErrCode=%{public}d", result);
683         return ERR_ANS_PARCELABLE_FAILED;
684     }
685 
686     if (!reply.WriteBool(canPublish)) {
687         ANS_LOGE("[HandleCanPublishAsBundle] fail: write canPublish failed");
688         return ERR_ANS_PARCELABLE_FAILED;
689     }
690 
691     return ERR_OK;
692 }
693 
HandlePublishAsBundle(MessageParcel & data,MessageParcel & reply)694 ErrCode AnsManagerStub::HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply)
695 {
696     sptr<NotificationRequest> notification = data.ReadParcelable<NotificationRequest>();
697     if (!notification) {
698         ANS_LOGE("[HandlePublishAsBundle] fail: read notification failed");
699         return ERR_ANS_PARCELABLE_FAILED;
700     }
701 
702     std::string representativeBundle;
703     if (!data.ReadString(representativeBundle)) {
704         ANS_LOGE("[HandlePublishAsBundle] fail: read representativeBundle failed.");
705         return ERR_ANS_PARCELABLE_FAILED;
706     }
707 
708     ErrCode result = PublishAsBundle(notification, representativeBundle);
709     if (!reply.WriteInt32(result)) {
710         ANS_LOGE("[HandlePublishAsBundle] fail: write result failed, ErrCode=%{public}d", result);
711         return ERR_ANS_PARCELABLE_FAILED;
712     }
713     return ERR_OK;
714 }
715 
HandleSetNotificationBadgeNum(MessageParcel & data,MessageParcel & reply)716 ErrCode AnsManagerStub::HandleSetNotificationBadgeNum(MessageParcel &data, MessageParcel &reply)
717 {
718     int32_t num = 0;
719     if (!data.ReadInt32(num)) {
720         ANS_LOGE("[HandleSetNotificationBadgeNum] fail: read notification failed");
721         return ERR_ANS_PARCELABLE_FAILED;
722     }
723 
724     ErrCode result = SetNotificationBadgeNum(num);
725     if (!reply.WriteInt32(result)) {
726         ANS_LOGE("[HandleSetNotificationBadgeNum] fail: write result failed, ErrCode=%{public}d", result);
727         return ERR_ANS_PARCELABLE_FAILED;
728     }
729     return ERR_OK;
730 }
731 
HandleGetBundleImportance(MessageParcel & data,MessageParcel & reply)732 ErrCode AnsManagerStub::HandleGetBundleImportance(MessageParcel &data, MessageParcel &reply)
733 {
734     int32_t importance = 0;
735     ErrCode result = GetBundleImportance(importance);
736     if (!reply.WriteInt32(result)) {
737         ANS_LOGE("[HandleGetBundleImportance] fail: write result failed, ErrCode=%{public}d", result);
738         return ERR_ANS_PARCELABLE_FAILED;
739     }
740 
741     if (!reply.WriteInt32(importance)) {
742         ANS_LOGE("[HandleGetBundleImportance] fail: write importance failed.");
743         return ERR_ANS_PARCELABLE_FAILED;
744     }
745     return ERR_OK;
746 }
747 
HandleSetDoNotDisturbDate(MessageParcel & data,MessageParcel & reply)748 ErrCode AnsManagerStub::HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply)
749 {
750     sptr<NotificationDoNotDisturbDate> date = data.ReadParcelable<NotificationDoNotDisturbDate>();
751     if (date == nullptr) {
752         ANS_LOGE("[HandleSetDoNotDisturbDate] fail: read date failed.");
753         return ERR_ANS_PARCELABLE_FAILED;
754     }
755 
756     ErrCode result = SetDoNotDisturbDate(date);
757     if (!reply.WriteInt32(result)) {
758         ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result);
759         return ERR_ANS_PARCELABLE_FAILED;
760     }
761 
762     return ERR_OK;
763 }
764 
HandleGetDoNotDisturbDate(MessageParcel & data,MessageParcel & reply)765 ErrCode AnsManagerStub::HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply)
766 {
767     sptr<NotificationDoNotDisturbDate> date = nullptr;
768 
769     ErrCode result = GetDoNotDisturbDate(date);
770     if (!reply.WriteInt32(result)) {
771         ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result);
772         return ERR_ANS_PARCELABLE_FAILED;
773     }
774 
775     if (result == ERR_OK) {
776         if (!reply.WriteParcelable(date)) {
777             ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write date failed.");
778             return ERR_ANS_PARCELABLE_FAILED;
779         }
780     }
781 
782     return ERR_OK;
783 }
784 
HandleDoesSupportDoNotDisturbMode(MessageParcel & data,MessageParcel & reply)785 ErrCode AnsManagerStub::HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply)
786 {
787     bool support = false;
788 
789     ErrCode result = DoesSupportDoNotDisturbMode(support);
790     if (!reply.WriteInt32(result)) {
791         ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result);
792         return ERR_ANS_PARCELABLE_FAILED;
793     }
794 
795     if (!reply.WriteBool(support)) {
796         ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write doesSupport failed.");
797         return ERR_ANS_PARCELABLE_FAILED;
798     }
799 
800     return ERR_OK;
801 }
802 
HandlePublishContinuousTaskNotification(MessageParcel & data,MessageParcel & reply)803 ErrCode AnsManagerStub::HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply)
804 {
805     sptr<NotificationRequest> request = data.ReadParcelable<NotificationRequest>();
806     if (!request) {
807         ANS_LOGE("[HandlePublishContinuousTaskNotification] fail: notification ReadParcelable failed");
808         return ERR_ANS_PARCELABLE_FAILED;
809     }
810 
811     ErrCode result = PublishContinuousTaskNotification(request);
812     if (!reply.WriteInt32(result)) {
813         ANS_LOGE("[HandlePublishContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result);
814         return ERR_ANS_PARCELABLE_FAILED;
815     }
816     return ERR_OK;
817 }
818 
HandleCancelContinuousTaskNotification(MessageParcel & data,MessageParcel & reply)819 ErrCode AnsManagerStub::HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply)
820 {
821     std::string label;
822     if (!data.ReadString(label)) {
823         ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: read label failed");
824         return ERR_ANS_PARCELABLE_FAILED;
825     }
826 
827     int32_t notificationId = 0;
828     if (!data.ReadInt32(notificationId)) {
829         ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: read notificationId failed");
830         return ERR_ANS_PARCELABLE_FAILED;
831     }
832 
833     ErrCode result = CancelContinuousTaskNotification(label, notificationId);
834     if (!reply.WriteInt32(result)) {
835         ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result);
836         return ERR_ANS_PARCELABLE_FAILED;
837     }
838     return ERR_OK;
839 }
840 
HandleIsNotificationPolicyAccessGranted(MessageParcel & data,MessageParcel & reply)841 ErrCode AnsManagerStub::HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply)
842 {
843     bool granted = false;
844     ErrCode result = HasNotificationPolicyAccessPermission(granted);
845     if (!reply.WriteInt32(result)) {
846         ANS_LOGE("[HandleIsNotificationPolicyAccessGranted] fail: write result failed, ErrCode=%{public}d", result);
847         return ERR_ANS_PARCELABLE_FAILED;
848     }
849 
850     if (!reply.WriteBool(granted)) {
851         ANS_LOGE("[HandleIsNotificationPolicyAccessGranted] fail: write granted failed.");
852         return ERR_ANS_PARCELABLE_FAILED;
853     }
854     return ERR_OK;
855 }
856 
HandleTriggerLocalLiveView(MessageParcel & data,MessageParcel & reply)857 ErrCode AnsManagerStub::HandleTriggerLocalLiveView(MessageParcel &data, MessageParcel &reply)
858 {
859     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
860     if (bundleOption == nullptr) {
861         ANS_LOGE("[HandleTriggerLocalLiveView] fail: read bundle failed.");
862         return ERR_ANS_PARCELABLE_FAILED;
863     }
864 
865     int32_t notificationId = 0;
866     if (!data.ReadInt32(notificationId)) {
867         ANS_LOGE("[HandleTriggerLocalLiveView] fail: read notificationId failed");
868         return ERR_ANS_PARCELABLE_FAILED;
869     }
870 
871     sptr<NotificationButtonOption> buttonOption = data.ReadStrongParcelable<NotificationButtonOption>();
872     if (buttonOption == nullptr) {
873         ANS_LOGE("[HandleTriggerLocalLiveView] fail: read button failed.");
874         return ERR_ANS_PARCELABLE_FAILED;
875     }
876 
877     ErrCode result = TriggerLocalLiveView(bundleOption, notificationId, buttonOption);
878     if (!reply.WriteInt32(result)) {
879         ANS_LOGE("[HandleTriggerLocalLiveView] fail: write result failed, ErrCode=%{public}d", result);
880         return ERR_ANS_PARCELABLE_FAILED;
881     }
882     return ERR_OK;
883 }
884 
HandleRemoveNotification(MessageParcel & data,MessageParcel & reply)885 ErrCode AnsManagerStub::HandleRemoveNotification(MessageParcel &data, MessageParcel &reply)
886 {
887     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
888     if (bundleOption == nullptr) {
889         ANS_LOGE("[HandleRemoveNotification] fail: read bundle failed.");
890         return ERR_ANS_PARCELABLE_FAILED;
891     }
892 
893     int32_t notificationId = 0;
894     if (!data.ReadInt32(notificationId)) {
895         ANS_LOGE("[HandleRemoveNotification] fail: read notificationId failed");
896         return ERR_ANS_PARCELABLE_FAILED;
897     }
898 
899     std::string label;
900     if (!data.ReadString(label)) {
901         ANS_LOGE("[HandleRemoveNotification] fail: read label failed");
902         return ERR_ANS_PARCELABLE_FAILED;
903     }
904 
905     int32_t removeReason = 0;
906     if (!data.ReadInt32(removeReason)) {
907         ANS_LOGE("[HandleRemoveNotification] fail: read removeReason failed");
908         return ERR_ANS_PARCELABLE_FAILED;
909     }
910 
911     ErrCode result = RemoveNotification(bundleOption, notificationId, label, removeReason);
912     if (!reply.WriteInt32(result)) {
913         ANS_LOGE("[HandleRemoveNotification] fail: write result failed, ErrCode=%{public}d", result);
914         return ERR_ANS_PARCELABLE_FAILED;
915     }
916     return ERR_OK;
917 }
918 
HandleRemoveAllNotifications(MessageParcel & data,MessageParcel & reply)919 ErrCode AnsManagerStub::HandleRemoveAllNotifications(MessageParcel &data, MessageParcel &reply)
920 {
921     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
922     if (bundleOption == nullptr) {
923         ANS_LOGE("[HandleRemoveAllNotifications] fail: read bundle failed.");
924         return ERR_ANS_PARCELABLE_FAILED;
925     }
926 
927     ErrCode result = RemoveAllNotifications(bundleOption);
928     if (!reply.WriteInt32(result)) {
929         ANS_LOGE("[HandleRemoveAllNotifications] fail: write result failed, ErrCode=%{public}d", result);
930         return ERR_ANS_PARCELABLE_FAILED;
931     }
932     return ERR_OK;
933 }
934 
HandleRemoveNotifications(MessageParcel & data,MessageParcel & reply)935 ErrCode AnsManagerStub::HandleRemoveNotifications(MessageParcel &data, MessageParcel &reply)
936 {
937     int32_t keysSize = 0;
938     if (!data.ReadInt32(keysSize)) {
939         ANS_LOGE("read keys size failed.");
940         return false;
941     }
942 
943     std::vector<std::string> keys;
944     if (!data.ReadStringVector(&keys)) {
945         ANS_LOGE("read keys failed");
946         return ERR_ANS_PARCELABLE_FAILED;
947     }
948 
949     int32_t removeReason = 0;
950     if (!data.ReadInt32(removeReason)) {
951         ANS_LOGE("read removeReason failed");
952         return ERR_ANS_PARCELABLE_FAILED;
953     }
954 
955     ErrCode result = RemoveNotifications(keys, removeReason);
956     if (!reply.WriteInt32(result)) {
957         ANS_LOGE("write result failed, ErrCode=%{public}d", result);
958         return ERR_ANS_PARCELABLE_FAILED;
959     }
960     return ERR_OK;
961 }
962 
963 
HandleDelete(MessageParcel & data,MessageParcel & reply)964 ErrCode AnsManagerStub::HandleDelete(MessageParcel &data, MessageParcel &reply)
965 {
966     std::string key;
967     if (!data.ReadString(key)) {
968         ANS_LOGE("[HandleDelete] fail: read key failed.");
969         return ERR_ANS_PARCELABLE_FAILED;
970     }
971 
972     int32_t removeReason = 0;
973     if (!data.ReadInt32(removeReason)) {
974         ANS_LOGE("[HandleDelete] fail: read removeReason failed");
975         return ERR_ANS_PARCELABLE_FAILED;
976     }
977 
978     ErrCode result = Delete(key, removeReason);
979     if (!reply.WriteInt32(result)) {
980         ANS_LOGE("[HandleDelete] fail: write result failed, ErrCode=%{public}d", result);
981         return ERR_ANS_PARCELABLE_FAILED;
982     }
983     return ERR_OK;
984 }
985 
HandleDeleteByBundle(MessageParcel & data,MessageParcel & reply)986 ErrCode AnsManagerStub::HandleDeleteByBundle(MessageParcel &data, MessageParcel &reply)
987 {
988     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
989     if (bundleOption == nullptr) {
990         ANS_LOGE("[HandleDeleteByBundle] fail: read bundle failed.");
991         return ERR_ANS_PARCELABLE_FAILED;
992     }
993 
994     ErrCode result = DeleteByBundle(bundleOption);
995     if (!reply.WriteInt32(result)) {
996         ANS_LOGE("[HandleDeleteByBundle] fail: write result failed, ErrCode=%{public}d", result);
997         return ERR_ANS_PARCELABLE_FAILED;
998     }
999     return ERR_OK;
1000 }
1001 
HandleDeleteAll(MessageParcel & data,MessageParcel & reply)1002 ErrCode AnsManagerStub::HandleDeleteAll(MessageParcel &data, MessageParcel &reply)
1003 {
1004     ErrCode result = DeleteAll();
1005     if (!reply.WriteInt32(result)) {
1006         ANS_LOGE("[HandleDeleteAll] fail: write result failed, ErrCode=%{public}d", result);
1007         return ERR_ANS_PARCELABLE_FAILED;
1008     }
1009     return ERR_OK;
1010 }
1011 
HandleGetSlotsByBundle(MessageParcel & data,MessageParcel & reply)1012 ErrCode AnsManagerStub::HandleGetSlotsByBundle(MessageParcel &data, MessageParcel &reply)
1013 {
1014     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1015     if (bundleOption == nullptr) {
1016         ANS_LOGE("[HandleGetSlotsByBundle] fail: read bundleOption failed.");
1017         return ERR_ANS_PARCELABLE_FAILED;
1018     }
1019 
1020     std::vector<sptr<NotificationSlot>> slots;
1021     ErrCode result = GetSlotsByBundle(bundleOption, slots);
1022     if (!WriteParcelableVector(slots, reply, result)) {
1023         ANS_LOGE("[HandleGetSlotsByBundle] fail: write slots failed.");
1024         return ERR_ANS_PARCELABLE_FAILED;
1025     }
1026     return ERR_OK;
1027 }
1028 
HandleUpdateSlots(MessageParcel & data,MessageParcel & reply)1029 ErrCode AnsManagerStub::HandleUpdateSlots(MessageParcel &data, MessageParcel &reply)
1030 {
1031     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1032     if (bundleOption == nullptr) {
1033         ANS_LOGE("[HandleUpdateSlots] fail: read bundleOption failed.");
1034         return ERR_ANS_PARCELABLE_FAILED;
1035     }
1036 
1037     std::vector<sptr<NotificationSlot>> slots;
1038     if (!ReadParcelableVector(slots, data)) {
1039         ANS_LOGE("[HandleUpdateSlots] fail: read slots failed");
1040         return ERR_ANS_PARCELABLE_FAILED;
1041     }
1042 
1043     ErrCode result = UpdateSlots(bundleOption, slots);
1044     if (!reply.WriteInt32(result)) {
1045         ANS_LOGE("[HandleUpdateSlots] fail: write result failed, ErrCode=%{public}d", result);
1046         return ERR_ANS_PARCELABLE_FAILED;
1047     }
1048     return ERR_OK;
1049 }
1050 
HandleRequestEnableNotification(MessageParcel & data,MessageParcel & reply)1051 ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, MessageParcel &reply)
1052 {
1053     ANS_LOGD("enter");
1054     std::string deviceId;
1055     if (!data.ReadString(deviceId)) {
1056         ANS_LOGE("[HandleRequestEnableNotification] fail: read deviceId failed.");
1057         return ERR_ANS_PARCELABLE_FAILED;
1058     }
1059 
1060     sptr<IRemoteObject> callback = data.ReadRemoteObject();
1061     if (callback == nullptr) {
1062         ANS_LOGE("[HandleRequestEnableNotification] fail: read callback failed");
1063         return ERR_ANS_PARCELABLE_FAILED;
1064     }
1065 
1066     bool hasCallerToken = false;
1067     if (!data.ReadBool(hasCallerToken)) {
1068         ANS_LOGE("fail: read hasCallerToken failed.");
1069         return ERR_ANS_PARCELABLE_FAILED;
1070     }
1071 
1072     sptr<IRemoteObject> callerToken = nullptr;
1073     if (hasCallerToken) {
1074         callerToken = data.ReadRemoteObject();
1075     }
1076 
1077     ErrCode result = RequestEnableNotification(deviceId,
1078         iface_cast<AnsDialogCallback>(callback), callerToken);
1079     if (!reply.WriteInt32(result)) {
1080         ANS_LOGE("[HandleRequestEnableNotification] fail: write result failed, ErrCode=%{public}d", result);
1081         return ERR_ANS_PARCELABLE_FAILED;
1082     }
1083     return ERR_OK;
1084 }
1085 
HandleSetNotificationsEnabledForBundle(MessageParcel & data,MessageParcel & reply)1086 ErrCode AnsManagerStub::HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply)
1087 {
1088     std::string deviceId;
1089     if (!data.ReadString(deviceId)) {
1090         ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: read deviceId failed.");
1091         return ERR_ANS_PARCELABLE_FAILED;
1092     }
1093 
1094     bool enabled = false;
1095     if (!data.ReadBool(enabled)) {
1096         ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: read enabled failed.");
1097         return ERR_ANS_PARCELABLE_FAILED;
1098     }
1099 
1100     ErrCode result = SetNotificationsEnabledForBundle(deviceId, enabled);
1101     if (!reply.WriteInt32(result)) {
1102         ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result);
1103         return ERR_ANS_PARCELABLE_FAILED;
1104     }
1105     return ERR_OK;
1106 }
1107 
HandleSetNotificationsEnabledForAllBundles(MessageParcel & data,MessageParcel & reply)1108 ErrCode AnsManagerStub::HandleSetNotificationsEnabledForAllBundles(MessageParcel &data, MessageParcel &reply)
1109 {
1110     std::string deviceId;
1111     if (!data.ReadString(deviceId)) {
1112         ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: read deviceId failed.");
1113         return ERR_ANS_PARCELABLE_FAILED;
1114     }
1115 
1116     bool enabled = false;
1117     if (!data.ReadBool(enabled)) {
1118         ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: read enabled failed.");
1119         return ERR_ANS_PARCELABLE_FAILED;
1120     }
1121 
1122     ErrCode result = SetNotificationsEnabledForAllBundles(deviceId, enabled);
1123     if (!reply.WriteInt32(result)) {
1124         ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: write result failed, ErrCode=%{public}d", result);
1125         return ERR_ANS_PARCELABLE_FAILED;
1126     }
1127     return ERR_OK;
1128 }
1129 
HandleSetNotificationsEnabledForSpecialBundle(MessageParcel & data,MessageParcel & reply)1130 ErrCode AnsManagerStub::HandleSetNotificationsEnabledForSpecialBundle(MessageParcel &data, MessageParcel &reply)
1131 {
1132     std::string deviceId;
1133     if (!data.ReadString(deviceId)) {
1134         ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read deviceId failed.");
1135         return ERR_ANS_PARCELABLE_FAILED;
1136     }
1137 
1138     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1139     if (bundleOption == nullptr) {
1140         ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read bundleOption failed.");
1141         return ERR_ANS_PARCELABLE_FAILED;
1142     }
1143 
1144     bool enabled = false;
1145     if (!data.ReadBool(enabled)) {
1146         ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read enabled failed.");
1147         return ERR_ANS_PARCELABLE_FAILED;
1148     }
1149 
1150     ErrCode result = SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled);
1151     if (!reply.WriteInt32(result)) {
1152         ANS_LOGE(
1153             "[HandleSetNotificationsEnabledForSpecialBundle] fail: write result failed, ErrCode=%{public}d", result);
1154         return ERR_ANS_PARCELABLE_FAILED;
1155     }
1156     return ERR_OK;
1157 }
1158 
HandleSetShowBadgeEnabledForBundle(MessageParcel & data,MessageParcel & reply)1159 ErrCode AnsManagerStub::HandleSetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply)
1160 {
1161     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1162     if (bundleOption == nullptr) {
1163         ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: read bundle failed.");
1164         return ERR_ANS_PARCELABLE_FAILED;
1165     }
1166 
1167     bool enabled = false;
1168     if (!data.ReadBool(enabled)) {
1169         ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: read enabled failed.");
1170         return ERR_ANS_PARCELABLE_FAILED;
1171     }
1172 
1173     ErrCode result = SetShowBadgeEnabledForBundle(bundleOption, enabled);
1174     if (!reply.WriteInt32(result)) {
1175         ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result);
1176         return ERR_ANS_PARCELABLE_FAILED;
1177     }
1178     return ERR_OK;
1179 }
1180 
HandleGetShowBadgeEnabledForBundle(MessageParcel & data,MessageParcel & reply)1181 ErrCode AnsManagerStub::HandleGetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply)
1182 {
1183     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1184     if (bundleOption == nullptr) {
1185         ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: read bundle failed.");
1186         return ERR_ANS_PARCELABLE_FAILED;
1187     }
1188 
1189     bool enabled = false;
1190     ErrCode result = GetShowBadgeEnabledForBundle(bundleOption, enabled);
1191     if (!reply.WriteInt32(result)) {
1192         ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result);
1193         return ERR_ANS_PARCELABLE_FAILED;
1194     }
1195 
1196     if (!reply.WriteBool(enabled)) {
1197         ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: write enabled failed, ErrCode=%{public}d", result);
1198         return ERR_ANS_PARCELABLE_FAILED;
1199     }
1200     return ERR_OK;
1201 }
1202 
HandleGetShowBadgeEnabled(MessageParcel & data,MessageParcel & reply)1203 ErrCode AnsManagerStub::HandleGetShowBadgeEnabled(MessageParcel &data, MessageParcel &reply)
1204 {
1205     bool enabled = false;
1206     ErrCode result = GetShowBadgeEnabled(enabled);
1207     if (!reply.WriteInt32(result)) {
1208         ANS_LOGE("[HandleGetShowBadgeEnabled] fail: write result failed, ErrCode=%{public}d", result);
1209         return ERR_ANS_PARCELABLE_FAILED;
1210     }
1211 
1212     if (!reply.WriteBool(enabled)) {
1213         ANS_LOGE("[HandleGetShowBadgeEnabled] fail: write enabled failed, ErrCode=%{public}d", result);
1214         return ERR_ANS_PARCELABLE_FAILED;
1215     }
1216     return ERR_OK;
1217 }
1218 
HandleSubscribe(MessageParcel & data,MessageParcel & reply)1219 ErrCode AnsManagerStub::HandleSubscribe(MessageParcel &data, MessageParcel &reply)
1220 {
1221     sptr<IRemoteObject> subscriber = data.ReadRemoteObject();
1222     if (subscriber == nullptr) {
1223         ANS_LOGE("[HandleSubscribe] fail: read subscriber failed");
1224         return ERR_ANS_PARCELABLE_FAILED;
1225     }
1226 
1227     bool subcribeInfo = false;
1228     if (!data.ReadBool(subcribeInfo)) {
1229         ANS_LOGE("[HandleSubscribe] fail: read isSubcribeInfo failed");
1230         return ERR_ANS_PARCELABLE_FAILED;
1231     }
1232 
1233     sptr<NotificationSubscribeInfo> info = nullptr;
1234     if (subcribeInfo) {
1235         info = data.ReadParcelable<NotificationSubscribeInfo>();
1236         if (info == nullptr) {
1237             ANS_LOGE("[HandleSubscribe] fail: read info failed");
1238             return ERR_ANS_PARCELABLE_FAILED;
1239         }
1240     }
1241 
1242     ErrCode result = Subscribe(iface_cast<AnsSubscriberInterface>(subscriber), info);
1243     if (!reply.WriteInt32(result)) {
1244         ANS_LOGE("[HandleSubscribe] fail: write result failed, ErrCode=%{public}d", result);
1245         return ERR_ANS_PARCELABLE_FAILED;
1246     }
1247     return ERR_OK;
1248 }
1249 
HandleSubscribeSelf(MessageParcel & data,MessageParcel & reply)1250 ErrCode AnsManagerStub::HandleSubscribeSelf(MessageParcel &data, MessageParcel &reply)
1251 {
1252     sptr<IRemoteObject> subscriber = data.ReadRemoteObject();
1253     if (subscriber == nullptr) {
1254         ANS_LOGE("[HandleSubscribeSelf] fail: read subscriber failed");
1255         return ERR_ANS_PARCELABLE_FAILED;
1256     }
1257 
1258     ErrCode result = SubscribeSelf(iface_cast<AnsSubscriberInterface>(subscriber));
1259     if (!reply.WriteInt32(result)) {
1260         ANS_LOGE("[HandleSubscribeSelf] fail: write result failed, ErrCode=%{public}d", result);
1261         return ERR_ANS_PARCELABLE_FAILED;
1262     }
1263     return ERR_OK;
1264 }
1265 
HandleSubscribeLocalLiveView(MessageParcel & data,MessageParcel & reply)1266 ErrCode AnsManagerStub::HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply)
1267 {
1268     sptr<IRemoteObject> subscriber = data.ReadRemoteObject();
1269     if (subscriber == nullptr) {
1270         ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read subscriber failed");
1271         return ERR_ANS_PARCELABLE_FAILED;
1272     }
1273 
1274     bool subcribeInfo = false;
1275     if (!data.ReadBool(subcribeInfo)) {
1276         ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read isSubcribeInfo failed");
1277         return ERR_ANS_PARCELABLE_FAILED;
1278     }
1279 
1280     sptr<NotificationSubscribeInfo> info = nullptr;
1281     if (subcribeInfo) {
1282         info = data.ReadParcelable<NotificationSubscribeInfo>();
1283         if (info == nullptr) {
1284             ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read info failed");
1285             return ERR_ANS_PARCELABLE_FAILED;
1286         }
1287     }
1288 
1289     ErrCode result = SubscribeLocalLiveView(iface_cast<AnsSubscriberLocalLiveViewInterface>(subscriber), info);
1290     if (!reply.WriteInt32(result)) {
1291         ANS_LOGE("[HandleSubscribeLocalLiveView] fail: write result failed, ErrCode=%{public}d", result);
1292         return ERR_ANS_PARCELABLE_FAILED;
1293     }
1294     return ERR_OK;
1295 }
1296 
HandleUnsubscribe(MessageParcel & data,MessageParcel & reply)1297 ErrCode AnsManagerStub::HandleUnsubscribe(MessageParcel &data, MessageParcel &reply)
1298 {
1299     sptr<IRemoteObject> subscriber = data.ReadRemoteObject();
1300     if (subscriber == nullptr) {
1301         ANS_LOGE("[HandleUnsubscribe] fail: read subscriber failed");
1302         return ERR_ANS_PARCELABLE_FAILED;
1303     }
1304 
1305     bool subcribeInfo = false;
1306     if (!data.ReadBool(subcribeInfo)) {
1307         ANS_LOGE("[HandleUnsubscribe] fail: read isSubcribeInfo failed");
1308         return ERR_ANS_PARCELABLE_FAILED;
1309     }
1310 
1311     sptr<NotificationSubscribeInfo> info = nullptr;
1312     if (subcribeInfo) {
1313         info = data.ReadParcelable<NotificationSubscribeInfo>();
1314         if (info == nullptr) {
1315             ANS_LOGE("[HandleUnsubscribe] fail: read info failed");
1316             return ERR_ANS_PARCELABLE_FAILED;
1317         }
1318     }
1319 
1320     ErrCode result = Unsubscribe(iface_cast<AnsSubscriberInterface>(subscriber), info);
1321     if (!reply.WriteInt32(result)) {
1322         ANS_LOGE("[HandleUnsubscribe] fail: write result failed, ErrCode=%{public}d", result);
1323         return ERR_ANS_PARCELABLE_FAILED;
1324     }
1325     return ERR_OK;
1326 }
1327 
HandleIsAllowedNotify(MessageParcel & data,MessageParcel & reply)1328 ErrCode AnsManagerStub::HandleIsAllowedNotify(MessageParcel &data, MessageParcel &reply)
1329 {
1330     bool allowed = false;
1331     ErrCode result = IsAllowedNotify(allowed);
1332     if (!reply.WriteInt32(result)) {
1333         ANS_LOGE("[HandleIsAllowedNotify] fail: write result failed, ErrCode=%{public}d", result);
1334         return ERR_ANS_PARCELABLE_FAILED;
1335     }
1336 
1337     if (!reply.WriteBool(allowed)) {
1338         ANS_LOGE("[HandleIsAllowedNotify] fail: write allowed failed.");
1339         return ERR_ANS_PARCELABLE_FAILED;
1340     }
1341     return ERR_OK;
1342 }
1343 
HandleIsAllowedNotifySelf(MessageParcel & data,MessageParcel & reply)1344 ErrCode AnsManagerStub::HandleIsAllowedNotifySelf(MessageParcel &data, MessageParcel &reply)
1345 {
1346     bool allowed = false;
1347     ErrCode result = IsAllowedNotifySelf(allowed);
1348     if (!reply.WriteInt32(result)) {
1349         ANS_LOGE("[HandleIsAllowedNotifySelf] fail: write result failed, ErrCode=%{public}d", result);
1350         return ERR_ANS_PARCELABLE_FAILED;
1351     }
1352 
1353     if (!reply.WriteBool(allowed)) {
1354         ANS_LOGE("[HandleIsAllowedNotifySelf] fail: write allowed failed.");
1355         return ERR_ANS_PARCELABLE_FAILED;
1356     }
1357     return ERR_OK;
1358 }
1359 
HandleIsSpecialBundleAllowedNotify(MessageParcel & data,MessageParcel & reply)1360 ErrCode AnsManagerStub::HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply)
1361 {
1362     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1363     if (bundleOption == nullptr) {
1364         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read bundle failed.");
1365         return ERR_ANS_PARCELABLE_FAILED;
1366     }
1367 
1368     bool allowed = false;
1369     ErrCode result = IsSpecialBundleAllowedNotify(bundleOption, allowed);
1370     if (!reply.WriteInt32(result)) {
1371         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write result failed, ErrCode=%{public}d", result);
1372         return ERR_ANS_PARCELABLE_FAILED;
1373     }
1374 
1375     if (!reply.WriteBool(allowed)) {
1376         ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write allowed failed.");
1377         return ERR_ANS_PARCELABLE_FAILED;
1378     }
1379     return ERR_OK;
1380 }
1381 
HandleCancelGroup(MessageParcel & data,MessageParcel & reply)1382 ErrCode AnsManagerStub::HandleCancelGroup(MessageParcel &data, MessageParcel &reply)
1383 {
1384     std::string groupName;
1385     if (!data.ReadString(groupName)) {
1386         ANS_LOGE("[HandleCancelGroup] fail: read groupName failed.");
1387         return ERR_ANS_PARCELABLE_FAILED;
1388     }
1389 
1390     ErrCode result = CancelGroup(groupName);
1391     if (!reply.WriteInt32(result)) {
1392         ANS_LOGE("[HandleCancelGroup] fail: write result failed, ErrCode=%{public}d", result);
1393         return ERR_ANS_PARCELABLE_FAILED;
1394     }
1395     return ERR_OK;
1396 }
1397 
HandleRemoveGroupByBundle(MessageParcel & data,MessageParcel & reply)1398 ErrCode AnsManagerStub::HandleRemoveGroupByBundle(MessageParcel &data, MessageParcel &reply)
1399 {
1400     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1401     if (bundleOption == nullptr) {
1402         ANS_LOGE("[HandleRemoveGroupByBundle] fail: read bundleOption failed.");
1403         return ERR_ANS_PARCELABLE_FAILED;
1404     }
1405 
1406     std::string groupName;
1407     if (!data.ReadString(groupName)) {
1408         ANS_LOGE("[HandleRemoveGroupByBundle] fail: read groupName failed.");
1409         return ERR_ANS_PARCELABLE_FAILED;
1410     }
1411 
1412     ErrCode result = RemoveGroupByBundle(bundleOption, groupName);
1413     if (!reply.WriteInt32(result)) {
1414         ANS_LOGE("[HandleRemoveGroupByBundle] fail: write result failed, ErrCode=%{public}d", result);
1415         return ERR_ANS_PARCELABLE_FAILED;
1416     }
1417     return ERR_OK;
1418 }
1419 
HandleIsDistributedEnabled(MessageParcel & data,MessageParcel & reply)1420 ErrCode AnsManagerStub::HandleIsDistributedEnabled(MessageParcel &data, MessageParcel &reply)
1421 {
1422     bool enabled = false;
1423     ErrCode result = IsDistributedEnabled(enabled);
1424     if (!reply.WriteInt32(result)) {
1425         ANS_LOGE("[HandleIsDistributedEnabled] fail: write result failed, ErrCode=%{public}d", result);
1426         return ERR_ANS_PARCELABLE_FAILED;
1427     }
1428 
1429     if (!reply.WriteBool(enabled)) {
1430         ANS_LOGE("[HandleIsDistributedEnabled] fail: write enabled failed.");
1431         return ERR_ANS_PARCELABLE_FAILED;
1432     }
1433 
1434     return ERR_OK;
1435 }
1436 
HandleEnableDistributed(MessageParcel & data,MessageParcel & reply)1437 ErrCode AnsManagerStub::HandleEnableDistributed(MessageParcel &data, MessageParcel &reply)
1438 {
1439     bool enabled = false;
1440     if (!data.ReadBool(enabled)) {
1441         ANS_LOGE("[HandleEnableDistributed] fail: read enabled failed.");
1442         return ERR_ANS_PARCELABLE_FAILED;
1443     }
1444 
1445     ErrCode result = EnableDistributed(enabled);
1446     if (!reply.WriteInt32(result)) {
1447         ANS_LOGE("[HandleEnableDistributed] fail: write result failed, ErrCode=%{public}d", result);
1448         return ERR_ANS_PARCELABLE_FAILED;
1449     }
1450 
1451     return ERR_OK;
1452 }
1453 
HandleEnableDistributedByBundle(MessageParcel & data,MessageParcel & reply)1454 ErrCode AnsManagerStub::HandleEnableDistributedByBundle(MessageParcel &data, MessageParcel &reply)
1455 {
1456     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1457     if (bundleOption == nullptr) {
1458         ANS_LOGE("[HandleEnableDistributedByBundle] fail: read bundle failed.");
1459         return ERR_ANS_PARCELABLE_FAILED;
1460     }
1461 
1462     bool enabled = false;
1463     if (!data.ReadBool(enabled)) {
1464         ANS_LOGE("[HandleEnableDistributedByBundle] fail: read enabled failed.");
1465         return ERR_ANS_PARCELABLE_FAILED;
1466     }
1467 
1468     ErrCode result = EnableDistributedByBundle(bundleOption, enabled);
1469     if (!reply.WriteInt32(result)) {
1470         ANS_LOGE("[HandleEnableDistributedByBundle] fail: write result failed, ErrCode=%{public}d", result);
1471         return ERR_ANS_PARCELABLE_FAILED;
1472     }
1473 
1474     return ERR_OK;
1475 }
1476 
HandleEnableDistributedSelf(MessageParcel & data,MessageParcel & reply)1477 ErrCode AnsManagerStub::HandleEnableDistributedSelf(MessageParcel &data, MessageParcel &reply)
1478 {
1479     bool enabled = false;
1480     if (!data.ReadBool(enabled)) {
1481         ANS_LOGE("[HandleEnableDistributedSelf] fail: read enabled failed.");
1482         return ERR_ANS_PARCELABLE_FAILED;
1483     }
1484 
1485     ErrCode result = EnableDistributedSelf(enabled);
1486     if (!reply.WriteInt32(result)) {
1487         ANS_LOGE("[HandleEnableDistributedSelf] fail: write result failed, ErrCode=%{public}d", result);
1488         return ERR_ANS_PARCELABLE_FAILED;
1489     }
1490 
1491     return ERR_OK;
1492 }
1493 
HandleIsDistributedEnableByBundle(MessageParcel & data,MessageParcel & reply)1494 ErrCode AnsManagerStub::HandleIsDistributedEnableByBundle(MessageParcel &data, MessageParcel &reply)
1495 {
1496     sptr<NotificationBundleOption> bundleOption = data.ReadParcelable<NotificationBundleOption>();
1497     if (bundleOption == nullptr) {
1498         ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: read bundle failed.");
1499         return ERR_ANS_PARCELABLE_FAILED;
1500     }
1501 
1502     bool enabled = false;
1503     ErrCode result = IsDistributedEnableByBundle(bundleOption, enabled);
1504     if (!reply.WriteInt32(result)) {
1505         ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: write result failed, ErrCode=%{public}d", result);
1506         return ERR_ANS_PARCELABLE_FAILED;
1507     }
1508 
1509     if (!reply.WriteBool(enabled)) {
1510         ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: write enabled failed.");
1511         return ERR_ANS_PARCELABLE_FAILED;
1512     }
1513 
1514     return ERR_OK;
1515 }
1516 
HandleGetDeviceRemindType(MessageParcel & data,MessageParcel & reply)1517 ErrCode AnsManagerStub::HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply)
1518 {
1519     auto rType {NotificationConstant::RemindType::NONE};
1520     ErrCode result = GetDeviceRemindType(rType);
1521     if (!reply.WriteInt32(result)) {
1522         ANS_LOGE("[HandleGetDeviceRemindType] fail: write result failed, ErrCode=%{public}d", result);
1523         return ERR_ANS_PARCELABLE_FAILED;
1524     }
1525 
1526     if (!reply.WriteInt32(static_cast<int32_t>(rType))) {
1527         ANS_LOGE("[HandleGetDeviceRemindType] fail: write remind type failed.");
1528         return ERR_ANS_PARCELABLE_FAILED;
1529     }
1530 
1531     return ERR_OK;
1532 }
1533 
HandleShellDump(MessageParcel & data,MessageParcel & reply)1534 ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &reply)
1535 {
1536     std::string cmd;
1537     if (!data.ReadString(cmd)) {
1538         ANS_LOGE("[HandleShellDump] fail: read cmd failed.");
1539         return ERR_ANS_PARCELABLE_FAILED;
1540     }
1541     std::string bundle;
1542     if (!data.ReadString(bundle)) {
1543         ANS_LOGE("[HandleShellDump] fail: read bundle failed.");
1544         return ERR_ANS_PARCELABLE_FAILED;
1545     }
1546     int32_t userId;
1547     if (!data.ReadInt32(userId)) {
1548         ANS_LOGE("[HandleShellDump] fail: read userId failed.");
1549         return ERR_ANS_PARCELABLE_FAILED;
1550     }
1551     std::vector<std::string> notificationsInfo;
1552     ErrCode result = ShellDump(cmd, bundle, userId, notificationsInfo);
1553     if (!reply.WriteInt32(result)) {
1554         ANS_LOGE("[HandleGetRecentNotificationsInfo] fail: write result failed, ErrCode=%{public}d", result);
1555         return ERR_ANS_PARCELABLE_FAILED;
1556     }
1557 
1558     if (!reply.WriteStringVector(notificationsInfo)) {
1559         ANS_LOGE("[HandleGetRecentNotificationsInfo] fail: write notificationsInfo failed.");
1560         return ERR_ANS_PARCELABLE_FAILED;
1561     }
1562     return ERR_OK;
1563 }
1564 
HandlePublishReminder(MessageParcel & data,MessageParcel & reply)1565 ErrCode AnsManagerStub::HandlePublishReminder(MessageParcel &data, MessageParcel &reply)
1566 {
1567     ANSR_LOGI("HandlePublishReminder");
1568     uint8_t typeInfo = static_cast<uint8_t>(ReminderRequest::ReminderType::INVALID);
1569     if (!data.ReadUint8(typeInfo)) {
1570         ANSR_LOGE("Failed to read reminder type");
1571         return ERR_ANS_PARCELABLE_FAILED;
1572     }
1573     ReminderRequest::ReminderType reminderType = static_cast<ReminderRequest::ReminderType>(typeInfo);
1574     sptr<ReminderRequest> reminder;
1575     if (ReminderRequest::ReminderType::ALARM == reminderType) {
1576         ANSR_LOGD("Publish alarm");
1577         reminder = data.ReadParcelable<ReminderRequestAlarm>();
1578     } else if (ReminderRequest::ReminderType::TIMER == reminderType) {
1579         ANSR_LOGD("Publish timer");
1580         reminder = data.ReadParcelable<ReminderRequestTimer>();
1581     } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) {
1582         ANSR_LOGD("Publish calendar");
1583         reminder = data.ReadParcelable<ReminderRequestCalendar>();
1584     } else {
1585         ANSR_LOGE("Reminder type invalid");
1586         return ERR_ANS_INVALID_PARAM;
1587     }
1588     if (!reminder) {
1589         ANSR_LOGE("Reminder ReadParcelable failed");
1590         return ERR_ANS_PARCELABLE_FAILED;
1591     }
1592 
1593     ErrCode result = PublishReminder(reminder);
1594 
1595     if (!reply.WriteInt32(reminder->GetReminderId())) {
1596         ANSR_LOGE("Write back reminderId failed");
1597         return ERR_ANS_PARCELABLE_FAILED;
1598     }
1599     if (!reply.WriteInt32(result)) {
1600         ANSR_LOGE("Write back result failed");
1601         return ERR_ANS_PARCELABLE_FAILED;
1602     }
1603     return result;
1604 }
1605 
HandleCancelReminder(MessageParcel & data,MessageParcel & reply)1606 ErrCode AnsManagerStub::HandleCancelReminder(MessageParcel &data, MessageParcel &reply)
1607 {
1608     ANSR_LOGI("HandleCancelReminder");
1609     int32_t reminderId = -1;
1610     if (!data.ReadInt32(reminderId)) {
1611         ANSR_LOGE("Read reminder id failed.");
1612         return ERR_ANS_PARCELABLE_FAILED;
1613     }
1614 
1615     ErrCode result = CancelReminder(reminderId);
1616     if (!reply.WriteInt32(result)) {
1617         ANSR_LOGE("Write back result failed");
1618         return ERR_ANS_PARCELABLE_FAILED;
1619     }
1620     return result;
1621 }
1622 
HandleCancelAllReminders(MessageParcel & data,MessageParcel & reply)1623 ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply)
1624 {
1625     ErrCode result = CancelAllReminders();
1626     if (!reply.WriteInt32(result)) {
1627         ANSR_LOGE("Write back result failed");
1628         return ERR_ANS_PARCELABLE_FAILED;
1629     }
1630     return result;
1631 }
1632 
HandleGetValidReminders(MessageParcel & data,MessageParcel & reply)1633 ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply)
1634 {
1635     ANSR_LOGI("HandleGetValidReminders");
1636     std::vector<sptr<ReminderRequest>> validReminders;
1637     ErrCode result = GetValidReminders(validReminders);
1638 
1639     ANSR_LOGD("Write back size=%{public}zu", validReminders.size());
1640     if (!reply.WriteUint8(static_cast<uint8_t>(validReminders.size()))) {
1641         ANSR_LOGE("Write back reminder count failed");
1642         return ERR_ANS_PARCELABLE_FAILED;
1643     }
1644 
1645     for (auto it = validReminders.begin(); it != validReminders.end(); ++it) {
1646         sptr<ReminderRequest> reminder = (*it);
1647         uint8_t reminderType = static_cast<uint8_t>(reminder->GetReminderType());
1648         ANSR_LOGD("ReminderType=%{public}d", reminderType);
1649         if (!reply.WriteUint8(reminderType)) {
1650             ANSR_LOGW("Write reminder type failed");
1651             return ERR_ANS_PARCELABLE_FAILED;
1652         }
1653         if (!reply.WriteParcelable(reminder)) {
1654             ANSR_LOGW("Write reminder parcelable failed");
1655             return ERR_ANS_PARCELABLE_FAILED;
1656         }
1657     }
1658     if (!reply.WriteInt32(result)) {
1659         ANSR_LOGE("Write back result failed");
1660         return ERR_ANS_PARCELABLE_FAILED;
1661     }
1662     return result;
1663 }
1664 
HandleIsSupportTemplate(MessageParcel & data,MessageParcel & reply)1665 ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply)
1666 {
1667     std::string templateName;
1668     if (!data.ReadString(templateName)) {
1669         ANS_LOGE("[HandleIsSupportTemplate] fail: read template name failed.");
1670         return ERR_ANS_PARCELABLE_FAILED;
1671     }
1672     bool support = false;
1673     ErrCode result = IsSupportTemplate(templateName, support);
1674     if (!reply.WriteInt32(result)) {
1675         ANS_LOGE("[HandleIsSupportTemplate] fail: write result failed, ErrCode=%{public}d", result);
1676         return ERR_ANS_PARCELABLE_FAILED;
1677     }
1678     if (!reply.WriteBool(support)) {
1679         ANS_LOGE("[HandleIsSupportTemplate] fail: write support failed.");
1680         return ERR_ANS_PARCELABLE_FAILED;
1681     }
1682     return ERR_OK;
1683 }
1684 
HandleIsSpecialUserAllowedNotifyByUser(MessageParcel & data,MessageParcel & reply)1685 ErrCode AnsManagerStub::HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply)
1686 {
1687     int32_t userId = SUBSCRIBE_USER_INIT;
1688     if (!data.ReadInt32(userId)) {
1689         ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: read userId failed.");
1690         return ERR_ANS_PARCELABLE_FAILED;
1691     }
1692 
1693     bool allowed = false;
1694     ErrCode result = IsSpecialUserAllowedNotify(userId, allowed);
1695     if (!reply.WriteInt32(result)) {
1696         ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: write result failed, ErrCode=%{public}d", result);
1697         return ERR_ANS_PARCELABLE_FAILED;
1698     }
1699 
1700     if (!reply.WriteBool(allowed)) {
1701         ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: write allowed failed.");
1702         return ERR_ANS_PARCELABLE_FAILED;
1703     }
1704     return ERR_OK;
1705 }
1706 
HandleSetNotificationsEnabledByUser(MessageParcel & data,MessageParcel & reply)1707 ErrCode AnsManagerStub::HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply)
1708 {
1709     int32_t userId = SUBSCRIBE_USER_INIT;
1710     if (!data.ReadInt32(userId)) {
1711         ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: read userId failed.");
1712         return ERR_ANS_PARCELABLE_FAILED;
1713     }
1714 
1715     bool enabled = false;
1716     if (!data.ReadBool(enabled)) {
1717         ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: read enabled failed.");
1718         return ERR_ANS_PARCELABLE_FAILED;
1719     }
1720 
1721     ErrCode result = SetNotificationsEnabledByUser(userId, enabled);
1722     if (!reply.WriteInt32(result)) {
1723         ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: write result failed, ErrCode=%{public}d", result);
1724         return ERR_ANS_PARCELABLE_FAILED;
1725     }
1726     return ERR_OK;
1727 }
1728 
HandleDeleteAllByUser(MessageParcel & data,MessageParcel & reply)1729 ErrCode AnsManagerStub::HandleDeleteAllByUser(MessageParcel &data, MessageParcel &reply)
1730 {
1731     int32_t userId = SUBSCRIBE_USER_INIT;
1732     if (!data.ReadInt32(userId)) {
1733         ANS_LOGE("[HandleDeleteAllByUser] fail: read userId failed.");
1734         return ERR_ANS_PARCELABLE_FAILED;
1735     }
1736 
1737     ErrCode result = DeleteAllByUser(userId);
1738     if (!reply.WriteInt32(result)) {
1739         ANS_LOGE("[HandleDeleteAllByUser] fail: write result failed, ErrCode=%{public}d", result);
1740         return ERR_ANS_PARCELABLE_FAILED;
1741     }
1742     return ERR_OK;
1743 }
1744 
HandleSetDoNotDisturbDateByUser(MessageParcel & data,MessageParcel & reply)1745 ErrCode AnsManagerStub::HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply)
1746 {
1747     int32_t userId = SUBSCRIBE_USER_INIT;
1748     if (!data.ReadInt32(userId)) {
1749         ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read userId failed.");
1750         return ERR_ANS_PARCELABLE_FAILED;
1751     }
1752 
1753     sptr<NotificationDoNotDisturbDate> date = data.ReadParcelable<NotificationDoNotDisturbDate>();
1754     if (date == nullptr) {
1755         ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read date failed.");
1756         return ERR_ANS_PARCELABLE_FAILED;
1757     }
1758 
1759     ErrCode result = SetDoNotDisturbDate(userId, date);
1760     if (!reply.WriteInt32(result)) {
1761         ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result);
1762         return ERR_ANS_PARCELABLE_FAILED;
1763     }
1764 
1765     return ERR_OK;
1766 }
1767 
HandleGetDoNotDisturbDateByUser(MessageParcel & data,MessageParcel & reply)1768 ErrCode AnsManagerStub::HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply)
1769 {
1770     int32_t userId = SUBSCRIBE_USER_INIT;
1771     if (!data.ReadInt32(userId)) {
1772         ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: read userId failed.");
1773         return ERR_ANS_PARCELABLE_FAILED;
1774     }
1775 
1776     sptr<NotificationDoNotDisturbDate> date = nullptr;
1777     ErrCode result = GetDoNotDisturbDate(userId, date);
1778     if (!reply.WriteInt32(result)) {
1779         ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result);
1780         return ERR_ANS_PARCELABLE_FAILED;
1781     }
1782 
1783     if (result == ERR_OK) {
1784         if (!reply.WriteParcelable(date)) {
1785             ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write date failed.");
1786             return ERR_ANS_PARCELABLE_FAILED;
1787         }
1788     }
1789 
1790     return ERR_OK;
1791 }
1792 
HandleSetEnabledForBundleSlot(MessageParcel & data,MessageParcel & reply)1793 ErrCode AnsManagerStub::HandleSetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply)
1794 {
1795     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
1796     if (bundleOption == nullptr) {
1797         ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read bundle failed.");
1798         return ERR_ANS_PARCELABLE_FAILED;
1799     }
1800 
1801     int32_t type = 0;
1802     if (!data.ReadInt32(type)) {
1803         ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read slot type failed.");
1804         return ERR_ANS_PARCELABLE_FAILED;
1805     }
1806     NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(type);
1807 
1808     bool enabled = false;
1809     if (!data.ReadBool(enabled)) {
1810         ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read enabled failed.");
1811         return ERR_ANS_PARCELABLE_FAILED;
1812     }
1813 
1814     bool isForceControl = false;
1815     if (!data.ReadBool(isForceControl)) {
1816         ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read isForceControl failed.");
1817         return ERR_ANS_PARCELABLE_FAILED;
1818     }
1819 
1820     ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl);
1821     if (!reply.WriteInt32(result)) {
1822         ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result);
1823         return ERR_ANS_PARCELABLE_FAILED;
1824     }
1825 
1826     return ERR_OK;
1827 }
1828 
HandleGetEnabledForBundleSlot(MessageParcel & data,MessageParcel & reply)1829 ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply)
1830 {
1831     sptr<NotificationBundleOption> bundleOption = data.ReadStrongParcelable<NotificationBundleOption>();
1832     if (bundleOption == nullptr) {
1833         ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: read bundle failed.");
1834         return ERR_ANS_PARCELABLE_FAILED;
1835     }
1836 
1837     int32_t type = 0;
1838     if (!data.ReadInt32(type)) {
1839         ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: read slot type failed.");
1840         return ERR_ANS_PARCELABLE_FAILED;
1841     }
1842     NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(type);
1843 
1844     bool enabled = false;
1845     ErrCode result = GetEnabledForBundleSlot(bundleOption, slotType, enabled);
1846     if (!reply.WriteInt32(result)) {
1847         ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result);
1848         return ERR_ANS_PARCELABLE_FAILED;
1849     }
1850 
1851     if (!reply.WriteBool(enabled)) {
1852         ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: write enabled failed, ErrCode=%{public}d", result);
1853         return ERR_ANS_PARCELABLE_FAILED;
1854     }
1855 
1856     return ERR_OK;
1857 }
1858 
HandleGetEnabledForBundleSlotSelf(MessageParcel & data,MessageParcel & reply)1859 ErrCode AnsManagerStub::HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply)
1860 {
1861     int32_t type = 0;
1862     if (!data.ReadInt32(type)) {
1863         ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: read slot type failed.");
1864         return ERR_ANS_PARCELABLE_FAILED;
1865     }
1866     NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(type);
1867 
1868     bool enabled = false;
1869     ErrCode result = GetEnabledForBundleSlotSelf(slotType, enabled);
1870     if (!reply.WriteInt32(result)) {
1871         ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write result failed, ErrCode=%{public}d", result);
1872         return ERR_ANS_PARCELABLE_FAILED;
1873     }
1874 
1875     if (!reply.WriteBool(enabled)) {
1876         ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write enabled failed, ErrCode=%{public}d", result);
1877         return ERR_ANS_PARCELABLE_FAILED;
1878     }
1879 
1880     return ERR_OK;
1881 }
1882 
HandleDistributedSetEnabledWithoutApp(MessageParcel & data,MessageParcel & reply)1883 ErrCode AnsManagerStub::HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply)
1884 {
1885     int32_t userId = SUBSCRIBE_USER_INIT;
1886     if (!data.ReadInt32(userId)) {
1887         ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: read userId failed.");
1888         return ERR_ANS_PARCELABLE_FAILED;
1889     }
1890 
1891     bool enabled = false;
1892     if (!data.ReadBool(enabled)) {
1893         ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: read enabled failed.");
1894         return ERR_ANS_PARCELABLE_FAILED;
1895     }
1896 
1897     ErrCode result = SetSyncNotificationEnabledWithoutApp(userId, enabled);
1898     if (!reply.WriteInt32(result)) {
1899         ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: write result failed, ErrCode=%{public}d",
1900             result);
1901         return ERR_ANS_PARCELABLE_FAILED;
1902     }
1903 
1904     return ERR_OK;
1905 }
1906 
HandleDistributedGetEnabledWithoutApp(MessageParcel & data,MessageParcel & reply)1907 ErrCode AnsManagerStub::HandleDistributedGetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply)
1908 {
1909     int32_t userId = SUBSCRIBE_USER_INIT;
1910     if (!data.ReadInt32(userId)) {
1911         ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: read userId failed.");
1912         return ERR_ANS_PARCELABLE_FAILED;
1913     }
1914 
1915     bool enabled = false;
1916     ErrCode result = GetSyncNotificationEnabledWithoutApp(userId, enabled);
1917     if (!reply.WriteInt32(result)) {
1918         ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: write result failed, ErrCode=%{public}d",
1919             result);
1920         return ERR_ANS_PARCELABLE_FAILED;
1921     }
1922 
1923     if (!reply.WriteBool(enabled)) {
1924         ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: write enabled failed.");
1925         return ERR_ANS_PARCELABLE_FAILED;
1926     }
1927 
1928     return ERR_OK;
1929 }
1930 
HandleSetBadgeNumber(MessageParcel & data,MessageParcel & reply)1931 ErrCode AnsManagerStub::HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply)
1932 {
1933     ANSR_LOGI("HandleSetBadgeNumber");
1934     int32_t badgeNumber = -1;
1935     if (!data.ReadInt32(badgeNumber)) {
1936         ANSR_LOGE("Read badge number failed.");
1937         return ERR_ANS_PARCELABLE_FAILED;
1938     }
1939 
1940     ErrCode result = SetBadgeNumber(badgeNumber);
1941     if (!reply.WriteInt32(result)) {
1942         ANSR_LOGE("Write badge number failed");
1943         return ERR_ANS_PARCELABLE_FAILED;
1944     }
1945     return result;
1946 }
1947 
HandleRegisterPushCallback(MessageParcel & data,MessageParcel & reply)1948 ErrCode AnsManagerStub::HandleRegisterPushCallback(MessageParcel &data, MessageParcel &reply)
1949 {
1950     sptr<IRemoteObject> pushCallBack = data.ReadRemoteObject();
1951     if (pushCallBack == nullptr) {
1952         ANS_LOGE("fail: read JSPushCallBack failed.");
1953         return ERR_ANS_PARCELABLE_FAILED;
1954     }
1955 
1956     sptr<NotificationCheckRequest> notificationCheckRequest = data.ReadParcelable<NotificationCheckRequest>();
1957     if (notificationCheckRequest == nullptr) {
1958         ANS_LOGE("fail: read notificationCheckRequest failed.");
1959         return ERR_ANS_PARCELABLE_FAILED;
1960     }
1961 
1962     ErrCode result = RegisterPushCallback(pushCallBack, notificationCheckRequest);
1963     if (!reply.WriteInt32(result)) {
1964         ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result);
1965         return ERR_ANS_PARCELABLE_FAILED;
1966     }
1967     return result;
1968 }
1969 
HandleUnregisterPushCallback(MessageParcel & data,MessageParcel & reply)1970 ErrCode AnsManagerStub::HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply)
1971 {
1972     ErrCode result = UnregisterPushCallback();
1973     if (!reply.WriteInt32(result)) {
1974         ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result);
1975         return ERR_ANS_PARCELABLE_FAILED;
1976     }
1977     return result;
1978 }
1979 }  // namespace Notification
1980 }  // namespace OHOS
1981