• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     ANS_LOGD("Publish instanceKey: %{public}s", notification->GetAppInstanceKey().c_str());
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     ANS_LOGD("PublishNotificationForIndirectProxy instanceKey: %{public}s", notification->GetAppInstanceKey().c_str());
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,const std::string & instanceKey)120 ErrCode AnsManagerProxy::Cancel(int32_t notificationId, const std::string &label, const std::string &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.WriteString(instanceKey)) {
139         ANS_LOGE("[Cancel] fail: write instanceKey failed");
140         return ERR_ANS_PARCELABLE_FAILED;
141     }
142     ANS_LOGD("Cancel instanceKey: %{public}s", instanceKey.c_str());
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(const std::string & instanceKey)159 ErrCode AnsManagerProxy::CancelAll(const std::string &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.WriteString(instanceKey)) {
168         ANS_LOGE("[CancelAll] fail: write instanceKey failed");
169         return ERR_ANS_PARCELABLE_FAILED;
170     }
171     ANS_LOGD("CancelAll instanceKey: %{public}s", instanceKey.c_str());
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,const std::string & instanceKey)302 ErrCode AnsManagerProxy::GetActiveNotifications(
303     std::vector<sptr<NotificationRequest>> &notifications, const std::string &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.WriteString(instanceKey)) {
312         ANS_LOGE("[GetActiveNotifications] fail: write instanceKey failed");
313         return ERR_ANS_PARCELABLE_FAILED;
314     }
315     ANS_LOGD("GetActiveNotifications instanceKey: %{public}s", instanceKey.c_str());
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     MessageOption option = {MessageOption::TF_SYNC};
371     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_ACTIVE_NOTIFICATIONS, option, data, reply);
372     if (result != ERR_OK) {
373         ANS_LOGE("[GetAllActiveNotifications] fail: transact ErrCode=%{public}d", result);
374         return ERR_ANS_TRANSACT_FAILED;
375     }
376 
377     if (!ReadParcelableVector(notifications, reply, result)) {
378         ANS_LOGE("[GetAllActiveNotifications] fail: read notifications failed.");
379         return ERR_ANS_PARCELABLE_FAILED;
380     }
381 
382     return result;
383 }
384 
GetSpecialActiveNotifications(const std::vector<std::string> & key,std::vector<sptr<Notification>> & notifications)385 ErrCode AnsManagerProxy::GetSpecialActiveNotifications(
386     const std::vector<std::string> &key, std::vector<sptr<Notification>> &notifications)
387 {
388     if (key.empty()) {
389         ANS_LOGE("[GetSpecialActiveNotifications] fail: key is empty.");
390         return ERR_ANS_INVALID_PARAM;
391     }
392 
393     MessageParcel data;
394     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
395         ANS_LOGE("[GetSpecialActiveNotifications] fail: write interface token failed.");
396         return ERR_ANS_PARCELABLE_FAILED;
397     }
398 
399     if (!data.WriteStringVector(key)) {
400         ANS_LOGE("[GetSpecialActiveNotifications] fail:: write key failed");
401         return ERR_ANS_PARCELABLE_FAILED;
402     }
403 
404     MessageParcel reply;
405     MessageOption option = {MessageOption::TF_SYNC};
406     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SPECIAL_ACTIVE_NOTIFICATIONS, option, data, reply);
407     if (result != ERR_OK) {
408         ANS_LOGE("[GetSpecialActiveNotifications] fail: transact ErrCode=%{public}d", result);
409         return ERR_ANS_TRANSACT_FAILED;
410     }
411 
412     if (!ReadParcelableVector(notifications, reply, result)) {
413         ANS_LOGE("[GetSpecialActiveNotifications] fail: read notifications failed.");
414         return ERR_ANS_PARCELABLE_FAILED;
415     }
416 
417     return result;
418 }
419 
GetActiveNotificationByFilter(const sptr<NotificationBundleOption> & bundleOption,const int32_t notificationId,const std::string & label,const std::vector<std::string> extraInfoKeys,sptr<NotificationRequest> & request)420 ErrCode AnsManagerProxy::GetActiveNotificationByFilter(
421     const sptr<NotificationBundleOption> &bundleOption, const int32_t notificationId, const std::string &label,
422     const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &request)
423 {
424     if (bundleOption == nullptr) {
425         ANS_LOGE("[GetActiveNotificationByFilter] fail: bundle is empty.");
426         return ERR_ANS_INVALID_PARAM;
427     }
428 
429     MessageParcel data;
430     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
431         ANS_LOGE("[GetActiveNotificationByFilter] fail: write interface token failed.");
432         return ERR_ANS_PARCELABLE_FAILED;
433     }
434 
435     if (!data.WriteParcelable(bundleOption)) {
436         ANS_LOGE("[GetActiveNotificationByFilter] fail: write bundleOption failed");
437         return ERR_ANS_PARCELABLE_FAILED;
438     }
439 
440     if (!data.WriteInt32(notificationId)) {
441         ANS_LOGE("[GetActiveNotificationByFilter] fail: write notificationId failed");
442         return ERR_ANS_PARCELABLE_FAILED;
443     }
444 
445     if (!data.WriteString(label)) {
446         ANS_LOGE("[GetActiveNotificationByFilter] fail: write label failed");
447         return ERR_ANS_PARCELABLE_FAILED;
448     }
449 
450     if (!data.WriteStringVector(extraInfoKeys)) {
451         ANS_LOGE("[GetActiveNotificationByFilter] fail:: write extraInfoKeys failed");
452         return ERR_ANS_PARCELABLE_FAILED;
453     }
454 
455     MessageParcel reply;
456     if (!reply.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) {
457         return ERR_ANS_PARCELABLE_FAILED;
458     }
459 
460     MessageOption option = {MessageOption::TF_SYNC};
461     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER, option, data, reply);
462     if (result != ERR_OK) {
463         ANS_LOGE("[GetActiveNotificationByFilter] fail: transact ErrCode=%{public}d", result);
464         return result;
465     }
466 
467     if (!reply.ReadInt32(result)) {
468         ANS_LOGE("[GetActiveNotificationByFilter] fail: read result failed.");
469         return ERR_ANS_PARCELABLE_FAILED;
470     }
471 
472     request = reply.ReadParcelable<NotificationRequest>();
473     if (request == nullptr) {
474         ANS_LOGE("[GetActiveNotificationByFilter] fail: read request is nullptr.");
475     }
476 
477     return result;
478 }
479 
GetAllNotificationsBySlotType(std::vector<sptr<Notification>> & notifications,const NotificationConstant::SlotType slotType)480 ErrCode AnsManagerProxy::GetAllNotificationsBySlotType(std::vector<sptr<Notification>> &notifications,
481     const NotificationConstant::SlotType slotType)
482 {
483     MessageParcel data;
484     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
485         ANS_LOGE("[GetAllNotificationsBySlotType] fail: write interface token failed.");
486         return ERR_ANS_PARCELABLE_FAILED;
487     }
488 
489     if (!data.WriteInt32(slotType)) {
490         ANS_LOGE("[GetAllNotificationsBySlotType] fail: write slotType failed");
491         return ERR_ANS_PARCELABLE_FAILED;
492     }
493 
494     MessageParcel reply;
495     MessageOption option = {MessageOption::TF_SYNC};
496     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_NOTIFICATIONS_BY_SLOTTYPE, option, data, reply);
497     if (result != ERR_OK) {
498         ANS_LOGE("[GetAllNotificationsBySlotType] fail: transact ErrCode=%{public}d", result);
499         return ERR_ANS_TRANSACT_FAILED;
500     }
501 
502     if (!ReadParcelableVector(notifications, reply, result)) {
503         ANS_LOGE("[GetAllNotificationsBySlotType] fail: read notifications failed.");
504         return ERR_ANS_PARCELABLE_FAILED;
505     }
506 
507     return result;
508 }
509 
CanPublishAsBundle(const std::string & representativeBundle,bool & canPublish)510 ErrCode AnsManagerProxy::CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish)
511 {
512     if (representativeBundle.empty()) {
513         ANS_LOGE("[CanPublishAsBundle] fail: representativeBundle is null.");
514         return ERR_ANS_INVALID_PARAM;
515     }
516 
517     MessageParcel data;
518     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
519         ANS_LOGE("[CanPublishAsBundle] fail: write interface token failed.");
520         return ERR_ANS_PARCELABLE_FAILED;
521     }
522 
523     if (!data.WriteString(representativeBundle)) {
524         ANS_LOGE("[CanPublishAsBundle] fail: write representativeBundle failed.");
525         return ERR_ANS_PARCELABLE_FAILED;
526     }
527 
528     MessageParcel reply;
529     MessageOption option = {MessageOption::TF_SYNC};
530     ErrCode result = InnerTransact(NotificationInterfaceCode::CAN_PUBLISH_AS_BUNDLE, option, data, reply);
531     if (result != ERR_OK) {
532         ANS_LOGE("[CanPublishAsBundle] fail: transact ErrCode=%{public}d", result);
533         return ERR_ANS_TRANSACT_FAILED;
534     }
535 
536     if (!reply.ReadInt32(result)) {
537         ANS_LOGE("[CanPublishAsBundle] fail: read result failed.");
538         return ERR_ANS_PARCELABLE_FAILED;
539     }
540 
541     if (!reply.ReadBool(canPublish)) {
542         ANS_LOGE("[CanPublishAsBundle] fail: read canPublish failed.");
543         return ERR_ANS_PARCELABLE_FAILED;
544     }
545 
546     return result;
547 }
548 
PublishAsBundle(const sptr<NotificationRequest> notification,const std::string & representativeBundle)549 ErrCode AnsManagerProxy::PublishAsBundle(
550     const sptr<NotificationRequest> notification, const std::string &representativeBundle)
551 {
552     if (notification == nullptr) {
553         ANS_LOGE("[PublishAsBundle] fail: notification is null ptr.");
554         return ERR_ANS_INVALID_PARAM;
555     }
556 
557     if (representativeBundle.empty()) {
558         ANS_LOGE("[PublishAsBundle] fail: representativeBundle is empty.");
559         return ERR_ANS_INVALID_PARAM;
560     }
561 
562     MessageParcel data;
563     if (notification->IsCommonLiveView()) {
564         if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) {
565             return ERR_ANS_PARCELABLE_FAILED;
566         }
567     }
568     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
569         ANS_LOGE("[PublishAsBundle] fail: write interface token failed.");
570         return ERR_ANS_PARCELABLE_FAILED;
571     }
572 
573     if (!data.WriteParcelable(notification)) {
574         ANS_LOGE("[PublishAsBundle] fail: write notification failed.");
575         return ERR_ANS_PARCELABLE_FAILED;
576     }
577 
578     if (!data.WriteString(representativeBundle)) {
579         ANS_LOGE("[PublishAsBundle] fail: write representativeBundle failed.");
580         return ERR_ANS_PARCELABLE_FAILED;
581     }
582 
583     MessageParcel reply;
584     MessageOption option = {MessageOption::TF_SYNC};
585     ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_AS_BUNDLE, option, data, reply);
586     if (result != ERR_OK) {
587         ANS_LOGE("[PublishAsBundle] fail: transact ErrCode=%{public}d", result);
588         return ERR_ANS_TRANSACT_FAILED;
589     }
590 
591     if (!reply.ReadInt32(result)) {
592         ANS_LOGE("[PublishAsBundle] fail: read result failed.");
593         return ERR_ANS_PARCELABLE_FAILED;
594     }
595 
596     return result;
597 }
598 
TriggerLocalLiveView(const sptr<NotificationBundleOption> & bundleOption,const int32_t notificationId,const sptr<NotificationButtonOption> & buttonOption)599 ErrCode AnsManagerProxy::TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption,
600     const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption)
601 {
602     if (bundleOption == nullptr) {
603         ANS_LOGE("[TriggerLocalLiveView] fail: bundle is empty.");
604         return ERR_ANS_INVALID_PARAM;
605     }
606 
607     MessageParcel data;
608     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
609         ANS_LOGE("[TriggerLocalLiveView] fail:, write interface token failed.");
610         return ERR_ANS_PARCELABLE_FAILED;
611     }
612 
613     if (!data.WriteStrongParcelable(bundleOption)) {
614         ANS_LOGE("[TriggerLocalLiveView] fail:: write bundle failed");
615         return ERR_ANS_PARCELABLE_FAILED;
616     }
617 
618     if (!data.WriteInt32(notificationId)) {
619         ANS_LOGE("[TriggerLocalLiveView] fail: write notificationId failed");
620         return ERR_ANS_PARCELABLE_FAILED;
621     }
622 
623     if (!data.WriteStrongParcelable(buttonOption)) {
624         ANS_LOGE("[TriggerLocalLiveView] fail: write label failed");
625         return ERR_ANS_PARCELABLE_FAILED;
626     }
627 
628     MessageParcel reply;
629     MessageOption option = {MessageOption::TF_SYNC};
630     ErrCode result = InnerTransact(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION,
631         option, data, reply);
632     if (result != ERR_OK) {
633         ANS_LOGE("[TriggerLocalLiveView] fail: transact ErrCode=%{public}d", result);
634         return ERR_ANS_TRANSACT_FAILED;
635     }
636 
637     if (!reply.ReadInt32(result)) {
638         ANS_LOGE("[TriggerLocalLiveView] fail: read result error.");
639         return ERR_ANS_PARCELABLE_FAILED;
640     }
641 
642     return result;
643 }
644 
Delete(const std::string & key,int32_t removeReason)645 ErrCode AnsManagerProxy::Delete(const std::string &key, int32_t removeReason)
646 {
647     if (key.empty()) {
648         ANS_LOGE("[Delete] fail: key is empty.");
649         return ERR_ANS_INVALID_PARAM;
650     }
651 
652     MessageParcel data;
653     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
654         ANS_LOGE("[Delete] fail:, write interface token failed.");
655         return ERR_ANS_PARCELABLE_FAILED;
656     }
657 
658     if (!data.WriteString(key)) {
659         ANS_LOGE("[Delete] fail:: write key failed");
660         return ERR_ANS_PARCELABLE_FAILED;
661     }
662 
663     if (!data.WriteInt32(removeReason)) {
664         ANS_LOGE("[Delete] fail: write removeReason failed");
665         return ERR_ANS_PARCELABLE_FAILED;
666     }
667 
668     MessageParcel reply;
669     MessageOption option = {MessageOption::TF_SYNC};
670     ErrCode result = InnerTransact(NotificationInterfaceCode::DELETE_NOTIFICATION, option, data, reply);
671     if (result != ERR_OK) {
672         ANS_LOGE("[Delete] fail: transact ErrCode=%{public}d", result);
673         return ERR_ANS_TRANSACT_FAILED;
674     }
675 
676     if (!reply.ReadInt32(result)) {
677         ANS_LOGE("[Delete] fail: read result failed.");
678         return ERR_ANS_PARCELABLE_FAILED;
679     }
680 
681     return result;
682 }
683 
DeleteByBundle(const sptr<NotificationBundleOption> & bundleOption)684 ErrCode AnsManagerProxy::DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption)
685 {
686     if (bundleOption == nullptr) {
687         ANS_LOGE("[DeleteByBundle] fail: bundle is empty.");
688         return ERR_ANS_INVALID_PARAM;
689     }
690 
691     MessageParcel data;
692     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
693         ANS_LOGE("[DeleteByBundle] fail: write interface token failed.");
694         return ERR_ANS_PARCELABLE_FAILED;
695     }
696 
697     if (!data.WriteStrongParcelable(bundleOption)) {
698         ANS_LOGE("[DeleteByBundle] fail: write bundle failed");
699         return ERR_ANS_PARCELABLE_FAILED;
700     }
701 
702     MessageParcel reply;
703     MessageOption option = {MessageOption::TF_SYNC};
704     ErrCode result = InnerTransact(NotificationInterfaceCode::DELETE_NOTIFICATION_BY_BUNDLE, option, data, reply);
705     if (result != ERR_OK) {
706         ANS_LOGE("[DeleteByBundle] fail: transact ErrCode=%{public}d", result);
707         return ERR_ANS_TRANSACT_FAILED;
708     }
709 
710     if (!reply.ReadInt32(result)) {
711         ANS_LOGE("[DeleteByBundle] fail: read result failed.");
712         return ERR_ANS_PARCELABLE_FAILED;
713     }
714 
715     return result;
716 }
717 
DeleteAll()718 ErrCode AnsManagerProxy::DeleteAll()
719 {
720     MessageParcel data;
721     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
722         ANS_LOGE("[DeleteAll] fail:, write interface token failed.");
723         return ERR_ANS_PARCELABLE_FAILED;
724     }
725 
726     MessageParcel reply;
727     MessageOption option = {MessageOption::TF_SYNC};
728     ErrCode result = InnerTransact(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS, option, data, reply);
729     if (result != ERR_OK) {
730         ANS_LOGE("[DeleteAll] fail: transact ErrCode=%{public}d", result);
731         return ERR_ANS_TRANSACT_FAILED;
732     }
733 
734     if (!reply.ReadInt32(result)) {
735         ANS_LOGE("[DeleteAll] fail: read result failed.");
736         return ERR_ANS_PARCELABLE_FAILED;
737     }
738 
739     return result;
740 }
741 
CancelGroup(const std::string & groupName,const std::string & instanceKey)742 ErrCode AnsManagerProxy::CancelGroup(const std::string &groupName, const std::string &instanceKey)
743 {
744     MessageParcel data;
745     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
746         ANS_LOGE("[CancelGroup] fail: write interface token failed.");
747         return ERR_ANS_PARCELABLE_FAILED;
748     }
749 
750     if (!data.WriteString(groupName)) {
751         ANS_LOGE("[CancelGroup] fail: write groupName failed.");
752         return ERR_ANS_PARCELABLE_FAILED;
753     }
754 
755     if (!data.WriteString(instanceKey)) {
756         ANS_LOGE("[CancelGroup] fail: write instanceKey failed.");
757         return ERR_ANS_PARCELABLE_FAILED;
758     }
759     ANS_LOGD("CancelGroup instanceKey: %{public}s", instanceKey.c_str());
760     MessageParcel reply;
761     MessageOption option = {MessageOption::TF_SYNC};
762     ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_GROUP, option, data, reply);
763     if (result != ERR_OK) {
764         ANS_LOGE("[CancelGroup] fail: transact ErrCode=%{public}d", result);
765         return ERR_ANS_TRANSACT_FAILED;
766     }
767 
768     if (!reply.ReadInt32(result)) {
769         ANS_LOGE("[CancelGroup] fail: read result failed.");
770         return ERR_ANS_PARCELABLE_FAILED;
771     }
772 
773     return result;
774 }
775 
RemoveGroupByBundle(const sptr<NotificationBundleOption> & bundleOption,const std::string & groupName)776 ErrCode AnsManagerProxy::RemoveGroupByBundle(
777     const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName)
778 {
779     MessageParcel data;
780     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
781         ANS_LOGE("[RemoveGroupByBundle] fail: write interface token failed.");
782         return ERR_ANS_PARCELABLE_FAILED;
783     }
784 
785     if (!data.WriteParcelable(bundleOption)) {
786         ANS_LOGE("[RemoveGroupByBundle] fail:: write bundleOption failed");
787         return ERR_ANS_PARCELABLE_FAILED;
788     }
789 
790     if (!data.WriteString(groupName)) {
791         ANS_LOGE("[RemoveGroupByBundle] fail: write groupName failed.");
792         return ERR_ANS_PARCELABLE_FAILED;
793     }
794 
795     MessageParcel reply;
796     MessageOption option = {MessageOption::TF_SYNC};
797     ErrCode result = InnerTransact(NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE, option, data, reply);
798     if (result != ERR_OK) {
799         ANS_LOGE("[RemoveGroupByBundle] fail: transact ErrCode=%{public}d", result);
800         return ERR_ANS_TRANSACT_FAILED;
801     }
802 
803     if (!reply.ReadInt32(result)) {
804         ANS_LOGE("[RemoveGroupByBundle] fail: read result failed.");
805         return ERR_ANS_PARCELABLE_FAILED;
806     }
807 
808     return result;
809 }
810 
PublishContinuousTaskNotification(const sptr<NotificationRequest> & request)811 ErrCode AnsManagerProxy::PublishContinuousTaskNotification(const sptr<NotificationRequest> &request)
812 {
813     if (request == nullptr) {
814         ANS_LOGE("[PublishContinuousTaskNotification] fail: notification request is null ptr.");
815         return ERR_ANS_INVALID_PARAM;
816     }
817 
818     MessageParcel data;
819     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
820         ANS_LOGE("[PublishContinuousTaskNotification] fail: write interface token failed.");
821         return ERR_ANS_PARCELABLE_FAILED;
822     }
823 
824     if (!data.WriteParcelable(request)) {
825         ANS_LOGE("[PublishContinuousTaskNotification] fail: write request failed.");
826         return ERR_ANS_PARCELABLE_FAILED;
827     }
828 
829     MessageParcel reply;
830     MessageOption option = {MessageOption::TF_SYNC};
831     ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_CONTINUOUS_TASK_NOTIFICATION,
832         option, data, reply);
833     if (result != ERR_OK) {
834         ANS_LOGE("[PublishContinuousTaskNotification] fail: transact ErrCode=%{public}d", result);
835         return ERR_ANS_TRANSACT_FAILED;
836     }
837 
838     if (!reply.ReadInt32(result)) {
839         ANS_LOGE("[PublishContinuousTaskNotification] fail: read result failed.");
840         return ERR_ANS_PARCELABLE_FAILED;
841     }
842 
843     return result;
844 }
845 
CancelContinuousTaskNotification(const std::string & label,int32_t notificationId)846 ErrCode AnsManagerProxy::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId)
847 {
848     MessageParcel data;
849     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
850         ANS_LOGE("[CancelContinuousTaskNotification] fail: write interface token failed.");
851         return ERR_ANS_PARCELABLE_FAILED;
852     }
853 
854     if (!data.WriteString(label)) {
855         ANS_LOGE("[CancelContinuousTaskNotification] fail: write label failed");
856         return ERR_ANS_PARCELABLE_FAILED;
857     }
858 
859     if (!data.WriteInt32(notificationId)) {
860         ANS_LOGE("[CancelContinuousTaskNotification] fail: write notificationId failed");
861         return ERR_ANS_PARCELABLE_FAILED;
862     }
863     MessageParcel reply;
864     MessageOption option = {MessageOption::TF_SYNC};
865     ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION, option, data, reply);
866     if (result != ERR_OK) {
867         ANS_LOGE("[CancelContinuousTaskNotification] fail: transact ErrCode=%{public}d", result);
868         return ERR_ANS_TRANSACT_FAILED;
869     }
870 
871     if (!reply.ReadInt32(result)) {
872         ANS_LOGE("[CancelContinuousTaskNotification] fail: read result failed.");
873         return ERR_ANS_PARCELABLE_FAILED;
874     }
875 
876     return result;
877 }
878 
IsSupportTemplate(const std::string & templateName,bool & support)879 ErrCode AnsManagerProxy::IsSupportTemplate(const std::string &templateName, bool &support)
880 {
881     MessageParcel data;
882     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
883         ANS_LOGE("[IsSupportTemplate] fail: write interface token failed.");
884         return ERR_ANS_PARCELABLE_FAILED;
885     }
886 
887     if (!data.WriteString(templateName)) {
888         ANS_LOGE("[IsSupportTemplate] fail: write template name failed");
889         return ERR_ANS_PARCELABLE_FAILED;
890     }
891 
892     MessageParcel reply;
893     MessageOption option = {MessageOption::TF_SYNC};
894     ErrCode result = InnerTransact(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE, option, data, reply);
895     if (result != ERR_OK) {
896         ANS_LOGE("[IsSupportTemplate] fail: transact ErrCode=%{public}d", result);
897         return ERR_ANS_TRANSACT_FAILED;
898     }
899 
900     if (!reply.ReadInt32(result)) {
901         ANS_LOGE("[IsSupportTemplate] fail: read result failed.");
902         return ERR_ANS_PARCELABLE_FAILED;
903     }
904 
905     if (!reply.ReadBool(support)) {
906         ANS_LOGE("[IsSupportTemplate] fail: read support failed.");
907         return ERR_ANS_PARCELABLE_FAILED;
908     }
909 
910     return result;
911 }
912 
DeleteAllByUser(const int32_t & userId)913 ErrCode AnsManagerProxy::DeleteAllByUser(const int32_t &userId)
914 {
915     MessageParcel data;
916     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
917         ANS_LOGE("[DeleteAllByUser] fail:, write interface token failed.");
918         return ERR_ANS_PARCELABLE_FAILED;
919     }
920 
921     if (!data.WriteInt32(userId)) {
922         ANS_LOGE("[DeleteAllByUser] fail: write userId failed");
923         return ERR_ANS_PARCELABLE_FAILED;
924     }
925 
926     MessageParcel reply;
927     MessageOption option = {MessageOption::TF_SYNC};
928     ErrCode result = InnerTransact(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER, option, data, reply);
929     if (result != ERR_OK) {
930         ANS_LOGE("[DeleteAllByUser] fail: transact ErrCode=%{public}d", result);
931         return ERR_ANS_TRANSACT_FAILED;
932     }
933 
934     if (!reply.ReadInt32(result)) {
935         ANS_LOGE("[DeleteAllByUser] fail: read result failed.");
936         return ERR_ANS_PARCELABLE_FAILED;
937     }
938 
939     return result;
940 }
941 
CancelAsBundleWithAgent(const sptr<NotificationBundleOption> & bundleOption,const int32_t id)942 ErrCode AnsManagerProxy::CancelAsBundleWithAgent(const sptr<NotificationBundleOption> &bundleOption, const int32_t id)
943 {
944     if (bundleOption == nullptr) {
945         ANS_LOGE("Bundle is empty.");
946         return ERR_ANS_INVALID_PARAM;
947     }
948 
949     MessageParcel data;
950     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
951         ANS_LOGE("Write interface token failed.");
952         return ERR_ANS_PARCELABLE_FAILED;
953     }
954 
955     if (!data.WriteStrongParcelable(bundleOption)) {
956         ANS_LOGE("Write bundle failed.");
957         return ERR_ANS_PARCELABLE_FAILED;
958     }
959 
960     if (!data.WriteInt32(id)) {
961         ANS_LOGE("Write notification id failed.");
962         return ERR_ANS_PARCELABLE_FAILED;
963     }
964 
965     MessageParcel reply;
966     MessageOption option = {MessageOption::TF_SYNC};
967     ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_AS_BUNDLE_WITH_AGENT, option, data, reply);
968     if (result != ERR_OK) {
969         ANS_LOGE("Transact fail: ErrCode=%{public}d", result);
970         return ERR_ANS_TRANSACT_FAILED;
971     }
972 
973     if (!reply.ReadInt32(result)) {
974         ANS_LOGE("Read result error.");
975         return ERR_ANS_PARCELABLE_FAILED;
976     }
977 
978     return result;
979 }
980 
UpdateNotificationTimerByUid(const int32_t uid,const bool isPaused)981 ErrCode AnsManagerProxy::UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused)
982 {
983     MessageParcel data;
984     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
985         ANS_LOGE("write interface token failed.");
986         return ERR_ANS_PARCELABLE_FAILED;
987     }
988 
989     if (!data.WriteInt32(uid)) {
990         ANS_LOGE("write uid failed.");
991         return ERR_ANS_PARCELABLE_FAILED;
992     }
993 
994     if (!data.WriteBool(isPaused)) {
995         ANS_LOGE("write isPaused failed.");
996         return ERR_ANS_PARCELABLE_FAILED;
997     }
998 
999     MessageParcel reply;
1000     MessageOption option = { MessageOption::TF_SYNC };
1001     ErrCode result = InnerTransact(NotificationInterfaceCode::UPDATE_NOTIFICATION_TIMER, option, data, reply);
1002     if (result != ERR_OK) {
1003         ANS_LOGE("transact ErrCode=%{public}d", result);
1004         return ERR_ANS_TRANSACT_FAILED;
1005     }
1006 
1007     if (!reply.ReadInt32(result)) {
1008         ANS_LOGE("fail: read result failed.");
1009         return ERR_ANS_PARCELABLE_FAILED;
1010     }
1011 
1012     return result;
1013 }
1014 
DisableNotificationFeature(const sptr<NotificationDisable> & notificationDisable)1015 ErrCode AnsManagerProxy::DisableNotificationFeature(const sptr<NotificationDisable> &notificationDisable)
1016 {
1017     MessageParcel data;
1018     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1019         ANS_LOGE("write interface token failed.");
1020         return ERR_ANS_PARCELABLE_FAILED;
1021     }
1022 
1023     if (!data.WriteParcelable(notificationDisable)) {
1024         ANS_LOGE("write notificationDisable failed");
1025         return ERR_ANS_PARCELABLE_FAILED;
1026     }
1027 
1028     MessageParcel reply;
1029     MessageOption option = { MessageOption::TF_SYNC };
1030     ErrCode result = InnerTransact(NotificationInterfaceCode::DISABLE_NOTIFICATION_FEATURE, option, data, reply);
1031     if (result != ERR_OK) {
1032         ANS_LOGE("transact ErrCode=%{public}d", result);
1033         return ERR_ANS_TRANSACT_FAILED;
1034     }
1035 
1036     if (!reply.ReadInt32(result)) {
1037         ANS_LOGE("fail: read result failed.");
1038         return ERR_ANS_PARCELABLE_FAILED;
1039     }
1040 
1041     return result;
1042 }
1043 
DistributeOperation(sptr<NotificationOperationInfo> & operationInfo,const sptr<OperationCallbackInterface> & callback)1044 ErrCode AnsManagerProxy::DistributeOperation(sptr<NotificationOperationInfo>& operationInfo,
1045     const sptr<OperationCallbackInterface> &callback)
1046 {
1047     MessageParcel data;
1048     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1049         ANS_LOGE("write interface token failed.");
1050         return ERR_ANS_PARCELABLE_FAILED;
1051     }
1052 
1053     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
1054         ANS_LOGE("write parcel failed.");
1055         return ERR_ANS_PARCELABLE_FAILED;
1056     }
1057 
1058     if (!data.WriteParcelable(operationInfo)) {
1059         ANS_LOGE("[Subscribe] fail: write operationInfo failed");
1060         return ERR_ANS_PARCELABLE_FAILED;
1061     }
1062 
1063     MessageParcel reply;
1064     MessageOption option = { MessageOption::TF_SYNC };
1065     ErrCode result = InnerTransact(NotificationInterfaceCode::DISTRIBUTE_OPERATION, option, data, reply);
1066     if (result != ERR_OK) {
1067         ANS_LOGE("transact ErrCode=%{public}d", result);
1068         return ERR_ANS_TRANSACT_FAILED;
1069     }
1070 
1071     if (!reply.ReadInt32(result)) {
1072         ANS_LOGE("read result failed.");
1073         return ERR_ANS_PARCELABLE_FAILED;
1074     }
1075 
1076     return result;
1077 }
1078 
ReplyDistributeOperation(const std::string & hashCode,const int32_t result)1079 ErrCode AnsManagerProxy::ReplyDistributeOperation(const std::string& hashCode, const int32_t result)
1080 {
1081     MessageParcel data;
1082     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1083         ANS_LOGE("write interface token failed.");
1084         return ERR_ANS_PARCELABLE_FAILED;
1085     }
1086 
1087     if (!data.WriteString(hashCode)) {
1088         ANS_LOGE("write hashCode failed");
1089         return ERR_ANS_PARCELABLE_FAILED;
1090     }
1091 
1092     if (!data.WriteInt32(result)) {
1093         ANS_LOGE("write result failed");
1094         return ERR_ANS_PARCELABLE_FAILED;
1095     }
1096 
1097     MessageParcel reply;
1098     MessageOption option = { MessageOption::TF_SYNC };
1099     ErrCode ret =
1100         InnerTransact(NotificationInterfaceCode::REPLY_DISTRIBUTE_OPERATION, option, data, reply);
1101     if (ret != ERR_OK) {
1102         ANS_LOGE("transact ErrCode=%{public}d", ret);
1103         return ret;
1104     }
1105 
1106     if (!reply.ReadInt32(ret)) {
1107         ANS_LOGE("read result failed.");
1108         return ERR_ANS_PARCELABLE_FAILED;
1109     }
1110 
1111     return ret;
1112 }
1113 
GetNotificationRequestByHashCode(const std::string & hashCode,sptr<NotificationRequest> & notificationRequest)1114 ErrCode AnsManagerProxy::GetNotificationRequestByHashCode(
1115     const std::string& hashCode, sptr<NotificationRequest>& notificationRequest)
1116 {
1117     MessageParcel data;
1118     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1119         ANS_LOGE("write interface token failed.");
1120         return ERR_ANS_PARCELABLE_FAILED;
1121     }
1122 
1123     if (!data.WriteString(hashCode)) {
1124         ANS_LOGE("write hashCode failed");
1125         return ERR_ANS_PARCELABLE_FAILED;
1126     }
1127 
1128     MessageParcel reply;
1129     MessageOption option = { MessageOption::TF_SYNC };
1130     ErrCode result =
1131         InnerTransact(NotificationInterfaceCode::GET_NOTIFICATION_REQUEST_BY_HASHCODE, option, data, reply);
1132     if (result != ERR_OK) {
1133         ANS_LOGE("transact ErrCode=%{public}d", result);
1134         return result;
1135     }
1136 
1137     if (!reply.ReadInt32(result)) {
1138         ANS_LOGE("read result failed.");
1139         return ERR_ANS_PARCELABLE_FAILED;
1140     }
1141 
1142     notificationRequest = reply.ReadParcelable<NotificationRequest>();
1143     if (notificationRequest == nullptr) {
1144         ANS_LOGE("read request is nullptr.");
1145     }
1146     return result;
1147 }
1148 
SetHashCodeRule(const uint32_t type)1149 ErrCode AnsManagerProxy::SetHashCodeRule(const uint32_t type)
1150 {
1151     MessageParcel data;
1152     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
1153         ANS_LOGE("write interface token failed.");
1154         return ERR_ANS_PARCELABLE_FAILED;
1155     }
1156 
1157     if (!data.WriteInt32(type)) {
1158         ANS_LOGE("write type failed");
1159         return ERR_ANS_PARCELABLE_FAILED;
1160     }
1161 
1162     MessageParcel reply;
1163     MessageOption option = { MessageOption::TF_SYNC };
1164     ErrCode result =
1165         InnerTransact(NotificationInterfaceCode::Set_HASH_CODE_RULE, option, data, reply);
1166     if (result != ERR_OK) {
1167         ANS_LOGE("transact ErrCode=%{public}d", result);
1168         return result;
1169     }
1170 
1171     if (!reply.ReadInt32(result)) {
1172         ANS_LOGE("read result failed.");
1173         return ERR_ANS_PARCELABLE_FAILED;
1174     }
1175 
1176     return result;
1177 }
1178 }  // namespace Notification
1179 }  // namespace OHOS
1180