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