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