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