• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <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 "parcel.h"
26 #include "ans_manager_proxy.h"
27 
28 namespace OHOS {
29 namespace Notification {
30 const static int MAX_SLOT_FLAGS = 0b111111;
AddSlotByType(NotificationConstant::SlotType slotType)31 ErrCode AnsManagerProxy::AddSlotByType(NotificationConstant::SlotType slotType)
32 {
33     MessageParcel data;
34     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
35         ANS_LOGE("[AddSlotByType] fail: write interface token failed.");
36         return ERR_ANS_PARCELABLE_FAILED;
37     }
38 
39     if (!data.WriteInt32(slotType)) {
40         ANS_LOGE("[AddSlotByType] fail:: write slotIds failed.");
41         return ERR_ANS_PARCELABLE_FAILED;
42     }
43 
44     MessageParcel reply;
45     MessageOption option = {MessageOption::TF_SYNC};
46     ErrCode result = InnerTransact(NotificationInterfaceCode::ADD_SLOT_BY_TYPE, option, data, reply);
47     if (result != ERR_OK) {
48         ANS_LOGE("[AddSlotByType] fail: transact ErrCode=%{public}d", result);
49         return ERR_ANS_TRANSACT_FAILED;
50     }
51 
52     if (!reply.ReadInt32(result)) {
53         ANS_LOGE("[AddSlotByType] fail: read result failed.");
54         return ERR_ANS_PARCELABLE_FAILED;
55     }
56 
57     return result;
58 }
59 
AddSlots(const std::vector<sptr<NotificationSlot>> & slots)60 ErrCode AnsManagerProxy::AddSlots(const std::vector<sptr<NotificationSlot>> &slots)
61 {
62     if (slots.empty()) {
63         ANS_LOGE("[AddSlots] fail: slots is empty.");
64         return ERR_ANS_INVALID_PARAM;
65     }
66 
67     size_t slotsSize = slots.size();
68     if (slotsSize > MAX_SLOT_NUM) {
69         ANS_LOGE("[AddSlots] fail: slotsSize over max size.");
70         return ERR_ANS_INVALID_PARAM;
71     }
72 
73     MessageParcel data;
74     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
75         ANS_LOGE("[AddSlots] fail: write interface token failed.");
76         return ERR_ANS_PARCELABLE_FAILED;
77     }
78 
79     if (!WriteParcelableVector(slots, data)) {
80         ANS_LOGE("[AddSlots] fail: write slots failed");
81         return ERR_ANS_PARCELABLE_FAILED;
82     }
83 
84     MessageParcel reply;
85     MessageOption option = {MessageOption::TF_SYNC};
86     ErrCode result = InnerTransact(NotificationInterfaceCode::ADD_SLOTS, option, data, reply);
87     if (result != ERR_OK) {
88         ANS_LOGE("[AddSlots] fail: transact ErrCode=%{public}d", result);
89         return ERR_ANS_TRANSACT_FAILED;
90     }
91 
92     if (!reply.ReadInt32(result)) {
93         ANS_LOGE("[AddSlots] fail: read result failed.");
94         return ERR_ANS_PARCELABLE_FAILED;
95     }
96 
97     return result;
98 }
99 
RemoveSlotByType(const NotificationConstant::SlotType & slotType)100 ErrCode AnsManagerProxy::RemoveSlotByType(const NotificationConstant::SlotType &slotType)
101 {
102     MessageParcel data;
103     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
104         ANS_LOGE("[RemoveSlotByType] fail: write interface token failed.");
105         return ERR_ANS_PARCELABLE_FAILED;
106     }
107 
108     if (!data.WriteInt32(slotType)) {
109         ANS_LOGE("[RemoveSlotByType] fail:: write slotIds failed.");
110         return ERR_ANS_PARCELABLE_FAILED;
111     }
112 
113     MessageParcel reply;
114     MessageOption option = {MessageOption::TF_SYNC};
115     ErrCode result = InnerTransact(NotificationInterfaceCode::REMOVE_SLOT_BY_TYPE, option, data, reply);
116     if (result != ERR_OK) {
117         ANS_LOGE("[RemoveSlotByType] fail: transact ErrCode=%{public}d", result);
118         return ERR_ANS_TRANSACT_FAILED;
119     }
120 
121     if (!reply.ReadInt32(result)) {
122         ANS_LOGE("[RemoveSlotByType] fail: read result failed.");
123         return ERR_ANS_PARCELABLE_FAILED;
124     }
125 
126     return result;
127 }
128 
RemoveAllSlots()129 ErrCode AnsManagerProxy::RemoveAllSlots()
130 {
131     MessageParcel data;
132     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
133         ANS_LOGE("[RemoveAllSlots] fail: write interface token failed.");
134         return ERR_ANS_PARCELABLE_FAILED;
135     }
136 
137     MessageParcel reply;
138     MessageOption option = {MessageOption::TF_SYNC};
139     ErrCode result = InnerTransact(NotificationInterfaceCode::REMOVE_ALL_SLOTS, option, data, reply);
140     if (result != ERR_OK) {
141         ANS_LOGE("[RemoveAllSlots] fail: transact ErrCode=%{public}d", result);
142         return ERR_ANS_TRANSACT_FAILED;
143     }
144 
145     if (!reply.ReadInt32(result)) {
146         ANS_LOGE("[RemoveAllSlots] fail: read result failed.");
147         return ERR_ANS_PARCELABLE_FAILED;
148     }
149 
150     return result;
151 }
152 
GetSlotByType(const NotificationConstant::SlotType & slotType,sptr<NotificationSlot> & slot)153 ErrCode AnsManagerProxy::GetSlotByType(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot)
154 {
155     MessageParcel data;
156     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
157         ANS_LOGE("[GetSlotByType] fail: write interface token failed.");
158         return ERR_ANS_PARCELABLE_FAILED;
159     }
160 
161     if (!data.WriteInt32(slotType)) {
162         ANS_LOGE("[GetSlotByType] fail:: write slotId failed");
163         return ERR_ANS_PARCELABLE_FAILED;
164     }
165 
166     MessageParcel reply;
167     MessageOption option = {MessageOption::TF_SYNC};
168     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOT_BY_TYPE, option, data, reply);
169     if (result != ERR_OK) {
170         ANS_LOGE("[GetSlotByType] fail: transact ErrCode=%{public}d", result);
171         return ERR_ANS_TRANSACT_FAILED;
172     }
173 
174     if (!reply.ReadInt32(result)) {
175         ANS_LOGE("[GetSlotByType] fail: read result failed.");
176         return ERR_ANS_PARCELABLE_FAILED;
177     }
178 
179     if (result == ERR_OK) {
180         slot = reply.ReadParcelable<NotificationSlot>();
181         if (slot == nullptr) {
182             ANS_LOGE("[GetSlotByType] slot is null");
183         }
184     }
185 
186     return result;
187 }
188 
GetSlots(std::vector<sptr<NotificationSlot>> & slots)189 ErrCode AnsManagerProxy::GetSlots(std::vector<sptr<NotificationSlot>> &slots)
190 {
191     MessageParcel data;
192     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
193         ANS_LOGE("[GetSlots] fail: write interface token failed.");
194         return ERR_ANS_PARCELABLE_FAILED;
195     }
196 
197     MessageParcel reply;
198     MessageOption option = {MessageOption::TF_SYNC};
199     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOTS, option, data, reply);
200     if (result != ERR_OK) {
201         ANS_LOGE("[GetSlots] fail: transact ErrCode=%{public}d", result);
202         return ERR_ANS_TRANSACT_FAILED;
203     }
204 
205     if (!ReadParcelableVector(slots, reply, result)) {
206         ANS_LOGE("[GetSlots] fail: read slots failed.");
207         return ERR_ANS_PARCELABLE_FAILED;
208     }
209 
210     return result;
211 }
212 
GetSlotNumAsBundle(const sptr<NotificationBundleOption> & bundleOption,uint64_t & num)213 ErrCode AnsManagerProxy::GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num)
214 {
215     if (bundleOption == nullptr) {
216         ANS_LOGE("[GetSlotNumAsBundle] fail: bundle is empty.");
217         return ERR_ANS_INVALID_PARAM;
218     }
219 
220     MessageParcel data;
221     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
222         ANS_LOGE("[GetSlotNumAsBundle] fail: write interface token failed.");
223         return ERR_ANS_PARCELABLE_FAILED;
224     }
225 
226     if (!data.WriteStrongParcelable(bundleOption)) {
227         ANS_LOGE("[GetSlotNumAsBundle] fail:: write bundle failed");
228         return ERR_ANS_PARCELABLE_FAILED;
229     }
230 
231     MessageParcel reply;
232     MessageOption option = {MessageOption::TF_SYNC};
233     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOT_NUM_AS_BUNDLE, option, data, reply);
234     if (result != ERR_OK) {
235         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: transact ErrCode=%{public}d", result);
236         return ERR_ANS_TRANSACT_FAILED;
237     }
238 
239     if (!reply.ReadInt32(result)) {
240         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read result failed.");
241         return ERR_ANS_PARCELABLE_FAILED;
242     }
243 
244     if (!reply.ReadUint64(num)) {
245         ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read enabled failed.");
246         return ERR_ANS_PARCELABLE_FAILED;
247     }
248 
249     return result;
250 }
251 
GetSlotsByBundle(const sptr<NotificationBundleOption> & bundleOption,std::vector<sptr<NotificationSlot>> & slots)252 ErrCode AnsManagerProxy::GetSlotsByBundle(
253     const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots)
254 {
255     if (bundleOption == nullptr) {
256         ANS_LOGE("[GetSlotsByBundle] fail: bundleOption is empty.");
257         return ERR_ANS_INVALID_PARAM;
258     }
259 
260     MessageParcel data;
261     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
262         ANS_LOGE("[GetSlotsByBundle] fail: write interface token failed.");
263         return ERR_ANS_PARCELABLE_FAILED;
264     }
265 
266     if (!data.WriteParcelable(bundleOption)) {
267         ANS_LOGE("[GetSlotsByBundle] fail:: write bundle failed");
268         return ERR_ANS_PARCELABLE_FAILED;
269     }
270 
271     MessageParcel reply;
272     MessageOption option = {MessageOption::TF_SYNC};
273     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOTS_BY_BUNDLE, option, data, reply);
274     if (result != ERR_OK) {
275         ANS_LOGE("[GetSlotsByBundle] fail: transact ErrCode=%{public}d", result);
276         return ERR_ANS_TRANSACT_FAILED;
277     }
278 
279     if (!ReadParcelableVector(slots, reply, result)) {
280         ANS_LOGE("[GetSlotsByBundle] fail: read slots failed.");
281         return ERR_ANS_PARCELABLE_FAILED;
282     }
283 
284     return result;
285 }
286 
GetSlotByBundle(const sptr<NotificationBundleOption> & bundleOption,const NotificationConstant::SlotType & slotType,sptr<NotificationSlot> & slot)287 ErrCode AnsManagerProxy::GetSlotByBundle(
288     const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType,
289     sptr<NotificationSlot> &slot)
290 {
291     if (bundleOption == nullptr) {
292         ANS_LOGE("[GetSlotByBundle] fail: bundleOption is empty.");
293         return ERR_ANS_INVALID_PARAM;
294     }
295 
296     MessageParcel data;
297     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
298         ANS_LOGE("[GetSlotByBundle] fail: write interface token failed.");
299         return ERR_ANS_PARCELABLE_FAILED;
300     }
301 
302     if (!data.WriteParcelable(bundleOption)) {
303         ANS_LOGE("[GetSlotByBundle] fail:: write bundle failed");
304         return ERR_ANS_PARCELABLE_FAILED;
305     }
306 
307     if (!data.WriteInt32(slotType)) {
308         ANS_LOGE("[GetSlotByBundle] fail:: write slotId failed");
309         return ERR_ANS_PARCELABLE_FAILED;
310     }
311 
312     MessageParcel reply;
313     MessageOption option = {MessageOption::TF_SYNC};
314     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOT_BY_BUNDLE, option, data, reply);
315     if (result != ERR_OK) {
316         ANS_LOGE("[GetSlotByBundle] fail: transact ErrCode=%{public}d", result);
317         return ERR_ANS_TRANSACT_FAILED;
318     }
319 
320     if (!reply.ReadInt32(result)) {
321         ANS_LOGE("[GetSlotByBundle] fail: read result failed.");
322         return ERR_ANS_PARCELABLE_FAILED;
323     }
324 
325     if (result == ERR_OK) {
326         slot = reply.ReadParcelable<NotificationSlot>();
327         if (slot == nullptr) {
328             ANS_LOGE("[GetSlotByBundle] slot is null");
329         }
330     }
331 
332     return result;
333 }
334 
UpdateSlots(const sptr<NotificationBundleOption> & bundleOption,const std::vector<sptr<NotificationSlot>> & slots)335 ErrCode AnsManagerProxy::UpdateSlots(
336     const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots)
337 {
338     if (bundleOption == nullptr) {
339         ANS_LOGE("[UpdateSlots] fail: bundleOption is empty.");
340         return ERR_ANS_INVALID_PARAM;
341     }
342 
343     if (slots.empty()) {
344         ANS_LOGE("[UpdateSlots] fail: slots is empty.");
345         return ERR_ANS_INVALID_PARAM;
346     }
347 
348     size_t slotSize = slots.size();
349     if (slotSize > MAX_SLOT_NUM) {
350         ANS_LOGE("[UpdateSlots] fail: slotSize over max size.");
351         return ERR_ANS_INVALID_PARAM;
352     }
353 
354     MessageParcel data;
355     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
356         ANS_LOGE("[UpdateSlots] fail: write interface token failed.");
357         return ERR_ANS_PARCELABLE_FAILED;
358     }
359 
360     if (!data.WriteParcelable(bundleOption)) {
361         ANS_LOGE("[UpdateSlots] fail:: write bundleoption failed");
362         return ERR_ANS_PARCELABLE_FAILED;
363     }
364 
365     if (!WriteParcelableVector(slots, data)) {
366         ANS_LOGE("[UpdateSlots] fail: write slots failed");
367         return ERR_ANS_PARCELABLE_FAILED;
368     }
369 
370     MessageParcel reply;
371     MessageOption option = {MessageOption::TF_SYNC};
372     ErrCode result = InnerTransact(NotificationInterfaceCode::UPDATE_SLOTS, option, data, reply);
373     if (result != ERR_OK) {
374         ANS_LOGE("[UpdateSlots] fail: transact ErrCode=%{public}d", result);
375         return ERR_ANS_TRANSACT_FAILED;
376     }
377 
378     if (!reply.ReadInt32(result)) {
379         ANS_LOGE("[UpdateSlots] fail: read result failed.");
380         return ERR_ANS_PARCELABLE_FAILED;
381     }
382 
383     return result;
384 }
385 
SetEnabledForBundleSlot(const sptr<NotificationBundleOption> & bundleOption,const NotificationConstant::SlotType & slotType,bool enabled,bool isForceControl)386 ErrCode AnsManagerProxy::SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
387     const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl)
388 {
389     if (bundleOption == nullptr) {
390         ANS_LOGE("[SetEnabledForBundleSlot] fail: bundle is empty.");
391         return ERR_ANS_INVALID_PARAM;
392     }
393 
394     MessageParcel data;
395     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
396         ANS_LOGE("[SetEnabledForBundleSlot] fail: write interface token failed.");
397         return ERR_ANS_PARCELABLE_FAILED;
398     }
399 
400     if (!data.WriteStrongParcelable(bundleOption)) {
401         ANS_LOGE("[SetEnabledForBundleSlot] fail:: write bundle failed");
402         return ERR_ANS_PARCELABLE_FAILED;
403     }
404 
405     if (!data.WriteInt32(slotType)) {
406         ANS_LOGE("[SetEnabledForBundleSlot] fail:: write slotType failed.");
407         return ERR_ANS_PARCELABLE_FAILED;
408     }
409 
410     if (!data.WriteBool(enabled)) {
411         ANS_LOGE("[SetEnabledForBundleSlot] fail: write enabled failed");
412         return ERR_ANS_PARCELABLE_FAILED;
413     }
414 
415     if (!data.WriteBool(isForceControl)) {
416         ANS_LOGE("[SetEnabledForBundleSlot] fail: write isForceControl failed");
417         return ERR_ANS_PARCELABLE_FAILED;
418     }
419 
420     MessageParcel reply;
421     MessageOption option = {MessageOption::TF_SYNC};
422     ErrCode result = InnerTransact(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT, option, data, reply);
423     if (result != ERR_OK) {
424         ANS_LOGE("[SetEnabledForBundleSlot] fail: transact ErrCode=%{public}d", result);
425         return ERR_ANS_TRANSACT_FAILED;
426     }
427 
428     if (!reply.ReadInt32(result)) {
429         ANS_LOGE("[SetEnabledForBundleSlot] fail: read result failed.");
430         return ERR_ANS_PARCELABLE_FAILED;
431     }
432 
433     return result;
434 }
435 
GetEnabledForBundleSlot(const sptr<NotificationBundleOption> & bundleOption,const NotificationConstant::SlotType & slotType,bool & enabled)436 ErrCode AnsManagerProxy::GetEnabledForBundleSlot(
437     const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled)
438 {
439     if (bundleOption == nullptr) {
440         ANS_LOGE("[GetEnabledForBundleSlot] fail: bundle is empty.");
441         return ERR_ANS_INVALID_PARAM;
442     }
443 
444     MessageParcel data;
445     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
446         ANS_LOGE("[GetEnabledForBundleSlot] fail: write interface token failed.");
447         return ERR_ANS_PARCELABLE_FAILED;
448     }
449 
450     if (!data.WriteStrongParcelable(bundleOption)) {
451         ANS_LOGE("[GetEnabledForBundleSlot] fail:: write bundle failed");
452         return ERR_ANS_PARCELABLE_FAILED;
453     }
454 
455     if (!data.WriteInt32(slotType)) {
456         ANS_LOGE("[GetEnabledForBundleSlot] fail:: write slotType failed.");
457         return ERR_ANS_PARCELABLE_FAILED;
458     }
459 
460     MessageParcel reply;
461     MessageOption option = {MessageOption::TF_SYNC};
462     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT, option, data, reply);
463     if (result != ERR_OK) {
464         ANS_LOGE("[GetEnabledForBundleSlot] fail: transact ErrCode=%{public}d", result);
465         return ERR_ANS_TRANSACT_FAILED;
466     }
467 
468     if (!reply.ReadInt32(result)) {
469         ANS_LOGE("[GetEnabledForBundleSlot] fail: read result failed.");
470         return ERR_ANS_PARCELABLE_FAILED;
471     }
472 
473     if (!reply.ReadBool(enabled)) {
474         ANS_LOGE("[GetEnabledForBundleSlot] fail: read enable failed.");
475         return ERR_ANS_PARCELABLE_FAILED;
476     }
477 
478     return result;
479 }
480 
GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType & slotType,bool & enabled)481 ErrCode AnsManagerProxy::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled)
482 {
483     MessageParcel data;
484     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
485         ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: write interface token failed.");
486         return ERR_ANS_PARCELABLE_FAILED;
487     }
488 
489     if (!data.WriteInt32(slotType)) {
490         ANS_LOGE("[GetEnabledForBundleSlotSelf] 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_ENABLED_FOR_BUNDLE_SLOT_SELF, option, data, reply);
497     if (result != ERR_OK) {
498         ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: transact ErrCode=%{public}d", result);
499         return ERR_ANS_TRANSACT_FAILED;
500     }
501 
502     if (!reply.ReadInt32(result)) {
503         ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: read result failed.");
504         return ERR_ANS_PARCELABLE_FAILED;
505     }
506 
507     if (!reply.ReadBool(enabled)) {
508         ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: read enable failed.");
509         return ERR_ANS_PARCELABLE_FAILED;
510     }
511 
512     return result;
513 }
514 
GetSlotFlagsAsBundle(const sptr<NotificationBundleOption> & bundleOption,uint32_t & slotFlags)515 ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption,  uint32_t& slotFlags)
516 {
517     if (bundleOption == nullptr) {
518         ANS_LOGE("[GetSlotFlagsAsBundle] fail: bundle is empty.");
519         return ERR_ANS_INVALID_PARAM;
520     }
521 
522     MessageParcel data;
523     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
524         ANS_LOGE("[GetSlotFlagsAsBundle] fail: write interface token failed.");
525         return ERR_ANS_PARCELABLE_FAILED;
526     }
527 
528     if (!data.WriteStrongParcelable(bundleOption)) {
529         ANS_LOGE("[GetSlotFlagsAsBundle] fail:: write bundle failed");
530         return ERR_ANS_PARCELABLE_FAILED;
531     }
532 
533     if (!data.WriteInt32(slotFlags)) {
534         ANS_LOGE("[GetSlotFlagsAsBundle] fail: write slots failed");
535         return ERR_ANS_PARCELABLE_FAILED;
536     }
537 
538     MessageParcel reply;
539     MessageOption option = {MessageOption::TF_SYNC};
540     ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE, option, data, reply);
541     if (result != ERR_OK) {
542         ANS_LOGE("fail: transact ErrCode=%{public}d", result);
543         return ERR_ANS_TRANSACT_FAILED;
544     }
545 
546     if (!reply.ReadInt32(result)) {
547         ANS_LOGE("fail: read result failed.");
548         return ERR_ANS_PARCELABLE_FAILED;
549     }
550 
551     if (!reply.ReadUint32(slotFlags)) {
552         ANS_LOGE("[GetSlotFlagsAsBundle] fail: read enabled failed.");
553         return ERR_ANS_PARCELABLE_FAILED;
554     }
555 
556     return result;
557 }
558 
SetSlotFlagsAsBundle(const sptr<NotificationBundleOption> & bundleOption,uint32_t slotFlags)559 ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption,  uint32_t slotFlags)
560 {
561     if (bundleOption == nullptr) {
562         ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundleOption is empty.");
563         return ERR_ANS_INVALID_PARAM;
564     }
565 
566     if (slotFlags > MAX_SLOT_FLAGS) {
567         ANS_LOGE("[SetSlotFlagsAsBundle] fail: Invalid slotFlags.");
568         return ERR_ANS_INVALID_PARAM;
569     }
570 
571     MessageParcel data;
572     if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
573         ANS_LOGE("[SetSlotFlagsAsBundle] fail: write interface token failed.");
574         return ERR_ANS_PARCELABLE_FAILED;
575     }
576 
577     if (!data.WriteParcelable(bundleOption)) {
578         ANS_LOGE("[SetSlotFlagsAsBundle] fail:: write bundleoption failed");
579         return ERR_ANS_PARCELABLE_FAILED;
580     }
581 
582     // got the LSB 6 bits as slotflags;
583     uint32_t validSlotFlag = MAX_SLOT_FLAGS & slotFlags;
584     if (!data.WriteInt32(validSlotFlag)) {
585         ANS_LOGE("[SetSlotFlagsAsBundle] fail: write slots failed");
586         return ERR_ANS_PARCELABLE_FAILED;
587     }
588 
589     MessageParcel reply;
590     MessageOption option = { MessageOption::TF_SYNC };
591     ErrCode result = InnerTransact(NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE, option, data, reply);
592     if (result != ERR_OK) {
593         ANS_LOGE("transact ErrCode=%{public}d", result);
594         return ERR_ANS_TRANSACT_FAILED;
595     }
596 
597     if (!reply.ReadInt32(result)) {
598         ANS_LOGE("fail: read result failed.");
599         return ERR_ANS_PARCELABLE_FAILED;
600     }
601 
602     return result;
603 }
604 }  // namespace Notification
605 }  // namespace OHOS
606