1 /*
2 * Copyright (c) 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 "parcel.h"
26 #include "ans_manager_proxy.h"
27
28 namespace OHOS {
29 namespace Notification {
SetNotificationBadgeNum(int32_t num)30 ErrCode AnsManagerProxy::SetNotificationBadgeNum(int32_t num)
31 {
32 MessageParcel data;
33 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
34 ANS_LOGE("[SetNotificationBadgeNum] fail: write interface token failed.");
35 return ERR_ANS_PARCELABLE_FAILED;
36 }
37
38 if (!data.WriteInt32(num)) {
39 ANS_LOGE("[SetNotificationBadgeNum] fail: write num failed.");
40 return ERR_ANS_PARCELABLE_FAILED;
41 }
42
43 MessageParcel reply;
44 MessageOption option = {MessageOption::TF_SYNC};
45 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_BADGE_NUM, option, data, reply);
46 if (result != ERR_OK) {
47 ANS_LOGE("[SetNotificationBadgeNum] fail: transact ErrCode=%{public}d", result);
48 return ERR_ANS_TRANSACT_FAILED;
49 }
50
51 if (!reply.ReadInt32(result)) {
52 ANS_LOGE("[SetNotificationBadgeNum] fail: read result failed.");
53 return ERR_ANS_PARCELABLE_FAILED;
54 }
55
56 return result;
57 }
58
GetBundleImportance(int32_t & importance)59 ErrCode AnsManagerProxy::GetBundleImportance(int32_t &importance)
60 {
61 MessageParcel data;
62 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
63 ANS_LOGE("[GetBundleImportance] fail: write interface token failed.");
64 return ERR_ANS_PARCELABLE_FAILED;
65 }
66
67 MessageParcel reply;
68 MessageOption option = {MessageOption::TF_SYNC};
69 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_BUNDLE_IMPORTANCE, option, data, reply);
70 if (result != ERR_OK) {
71 ANS_LOGE("[GetBundleImportance] fail: transact ErrCode=%{public}d", result);
72 return ERR_ANS_TRANSACT_FAILED;
73 }
74
75 if (!reply.ReadInt32(result)) {
76 ANS_LOGE("[GetBundleImportance] fail: read result failed.");
77 return ERR_ANS_PARCELABLE_FAILED;
78 }
79
80 if (!reply.ReadInt32(importance)) {
81 ANS_LOGE("[GetBundleImportance] fail: read importance failed.");
82 return ERR_ANS_PARCELABLE_FAILED;
83 }
84
85 return result;
86 }
87
HasNotificationPolicyAccessPermission(bool & granted)88 ErrCode AnsManagerProxy::HasNotificationPolicyAccessPermission(bool &granted)
89 {
90 MessageParcel data;
91 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
92 ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: write interface token failed.");
93 return ERR_ANS_PARCELABLE_FAILED;
94 }
95
96 MessageParcel reply;
97 MessageOption option = {MessageOption::TF_SYNC};
98 ErrCode result = InnerTransact(NotificationInterfaceCode::IS_NOTIFICATION_POLICY_ACCESS_GRANTED,
99 option, data, reply);
100 if (result != ERR_OK) {
101 ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: transact ErrCode=%{public}d", result);
102 return ERR_ANS_TRANSACT_FAILED;
103 }
104
105 if (!reply.ReadInt32(result)) {
106 ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: read result failed.");
107 return ERR_ANS_PARCELABLE_FAILED;
108 }
109
110 if (!reply.ReadBool(granted)) {
111 ANS_LOGE("[HasNotificationPolicyAccessPermission] fail: read granted failed.");
112 return ERR_ANS_PARCELABLE_FAILED;
113 }
114
115 return result;
116 }
117
RequestEnableNotification(const std::string & deviceId,const sptr<AnsDialogCallback> & callback,const sptr<IRemoteObject> & callerToken)118 ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId,
119 const sptr<AnsDialogCallback> &callback,
120 const sptr<IRemoteObject> &callerToken)
121 {
122 ANS_LOGD("enter");
123 MessageParcel data;
124 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
125 ANS_LOGE("[RequestEnableNotification] fail: write interface token failed.");
126 return ERR_ANS_PARCELABLE_FAILED;
127 }
128
129 if (!data.WriteString(deviceId)) {
130 ANS_LOGE("[RequestEnableNotification] fail: write deviceId failed");
131 return ERR_ANS_PARCELABLE_FAILED;
132 }
133
134 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
135 ANS_LOGE("[RequestEnableNotification] fail: write callback failed");
136 return ERR_ANS_PARCELABLE_FAILED;
137 }
138
139 if (!data.WriteBool(callerToken != nullptr)) {
140 ANS_LOGE("fail: write callerToken failed");
141 return ERR_ANS_PARCELABLE_FAILED;
142 }
143 if (callerToken != nullptr) {
144 if (!data.WriteRemoteObject(callerToken)) {
145 ANS_LOGE("fail: write callerToken failed");
146 return ERR_ANS_PARCELABLE_FAILED;
147 }
148 }
149
150 MessageParcel reply;
151 MessageOption option = {MessageOption::TF_SYNC};
152 ErrCode result = InnerTransact(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION, option, data, reply);
153 if (result != ERR_OK) {
154 ANS_LOGE("[RequestEnableNotification] fail: transact ErrCode=%{public}d", result);
155 return ERR_ANS_TRANSACT_FAILED;
156 }
157
158 if (!reply.ReadInt32(result)) {
159 ANS_LOGE("[RequestEnableNotification] fail: read result failed.");
160 return ERR_ANS_PARCELABLE_FAILED;
161 }
162 return result;
163 }
164
RequestEnableNotification(const std::string bundleName,const int32_t uid)165 ErrCode AnsManagerProxy::RequestEnableNotification(const std::string bundleName, const int32_t uid)
166 {
167 ANS_LOGD("enter");
168 MessageParcel data;
169 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
170 ANS_LOGE("[RequestEnableNotification] fail: write interface token failed.");
171 return ERR_ANS_PARCELABLE_FAILED;
172 }
173
174 if (!data.WriteString(bundleName)) {
175 ANS_LOGE("[RequestEnableNotification] fail: write bundleName failed");
176 return ERR_ANS_PARCELABLE_FAILED;
177 }
178
179 if (!data.WriteInt32(uid)) {
180 ANS_LOGE("[RequestEnableNotification] fail: write uid failed");
181 return ERR_ANS_PARCELABLE_FAILED;
182 }
183
184 MessageParcel reply;
185 MessageOption option = {MessageOption::TF_SYNC};
186 ErrCode result = InnerTransact(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION_BY_BUNDLE,
187 option, data, reply);
188 if (result != ERR_OK) {
189 ANS_LOGE("[RequestEnableNotification] fail: transact ErrCode=%{public}d", result);
190 return ERR_ANS_TRANSACT_FAILED;
191 }
192
193 if (!reply.ReadInt32(result)) {
194 ANS_LOGE("[RequestEnableNotification] fail: read result failed.");
195 return ERR_ANS_PARCELABLE_FAILED;
196 }
197 return result;
198 }
199
SetNotificationsEnabledForBundle(const std::string & deviceId,bool enabled)200 ErrCode AnsManagerProxy::SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled)
201 {
202 MessageParcel data;
203 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
204 ANS_LOGE("[SetNotificationsEnabledForBundle] fail: write interface token failed.");
205 return ERR_ANS_PARCELABLE_FAILED;
206 }
207
208 if (!data.WriteString(deviceId)) {
209 ANS_LOGE("[SetNotificationsEnabledForBundle] fail: write deviceId failed");
210 return ERR_ANS_PARCELABLE_FAILED;
211 }
212
213 if (!data.WriteBool(enabled)) {
214 ANS_LOGE("[SetNotificationsEnabledForBundle] fail: write enabled failed");
215 return ERR_ANS_PARCELABLE_FAILED;
216 }
217
218 MessageParcel reply;
219 MessageOption option = {MessageOption::TF_SYNC};
220 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE, option, data, reply);
221 if (result != ERR_OK) {
222 ANS_LOGE("[SetNotificationsEnabledForBundle] fail: transact ErrCode=%{public}d", result);
223 return ERR_ANS_TRANSACT_FAILED;
224 }
225
226 if (!reply.ReadInt32(result)) {
227 ANS_LOGE("[SetNotificationsEnabledForBundle] fail: read result failed.");
228 return ERR_ANS_PARCELABLE_FAILED;
229 }
230
231 return result;
232 }
233
SetNotificationsEnabledForAllBundles(const std::string & deviceId,bool enabled)234 ErrCode AnsManagerProxy::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled)
235 {
236 MessageParcel data;
237 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
238 ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: write interface token failed.");
239 return ERR_ANS_PARCELABLE_FAILED;
240 }
241
242 if (!data.WriteString(deviceId)) {
243 ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: write deviceId failed");
244 return ERR_ANS_PARCELABLE_FAILED;
245 }
246
247 if (!data.WriteBool(enabled)) {
248 ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: write enabled failed");
249 return ERR_ANS_PARCELABLE_FAILED;
250 }
251
252 MessageParcel reply;
253 MessageOption option = {MessageOption::TF_SYNC};
254 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE,
255 option, data, reply);
256 if (result != ERR_OK) {
257 ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: transact ErrCode=%{public}d", result);
258 return ERR_ANS_TRANSACT_FAILED;
259 }
260
261 if (!reply.ReadInt32(result)) {
262 ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: read result failed.");
263 return ERR_ANS_PARCELABLE_FAILED;
264 }
265
266 return result;
267 }
268
SetNotificationsEnabledForSpecialBundle(const std::string & deviceId,const sptr<NotificationBundleOption> & bundleOption,bool enabled)269 ErrCode AnsManagerProxy::SetNotificationsEnabledForSpecialBundle(
270 const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled)
271 {
272 if (bundleOption == nullptr) {
273 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: bundleOption is empty.");
274 return ERR_ANS_INVALID_PARAM;
275 }
276
277 MessageParcel data;
278 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
279 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write interface token failed.");
280 return ERR_ANS_PARCELABLE_FAILED;
281 }
282
283 if (!data.WriteString(deviceId)) {
284 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write deviceId failed");
285 return ERR_ANS_PARCELABLE_FAILED;
286 }
287
288 if (!data.WriteParcelable(bundleOption)) {
289 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write bundleOption failed");
290 return ERR_ANS_PARCELABLE_FAILED;
291 }
292
293 if (!data.WriteBool(enabled)) {
294 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: write enabled failed");
295 return ERR_ANS_PARCELABLE_FAILED;
296 }
297
298 MessageParcel reply;
299 MessageOption option = {MessageOption::TF_SYNC};
300 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE,
301 option, data, reply);
302 if (result != ERR_OK) {
303 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: transact ErrCode=%{public}d", result);
304 return ERR_ANS_TRANSACT_FAILED;
305 }
306
307 if (!reply.ReadInt32(result)) {
308 ANS_LOGE("[SetNotificationsEnabledForSpecialBundle] fail: read result failed.");
309 return ERR_ANS_PARCELABLE_FAILED;
310 }
311
312 return result;
313 }
314
SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> & bundleOption,bool enabled)315 ErrCode AnsManagerProxy::SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled)
316 {
317 if (bundleOption == nullptr) {
318 ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: bundle is empty.");
319 return ERR_ANS_INVALID_PARAM;
320 }
321
322 MessageParcel data;
323 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
324 ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: write interface token failed.");
325 return ERR_ANS_PARCELABLE_FAILED;
326 }
327
328 if (!data.WriteParcelable(bundleOption)) {
329 ANS_LOGE("[SetShowBadgeEnabledForBundle] fail:: write bundle failed");
330 return ERR_ANS_PARCELABLE_FAILED;
331 }
332
333 if (!data.WriteBool(enabled)) {
334 ANS_LOGE("[SetShowBadgeEnabledForBundle] fail:: write enabled failed");
335 return ERR_ANS_PARCELABLE_FAILED;
336 }
337
338 MessageParcel reply;
339 MessageOption option = {MessageOption::TF_SYNC};
340 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE, option, data, reply);
341 if (result != ERR_OK) {
342 ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: transact ErrCode=%{public}d", result);
343 return ERR_ANS_TRANSACT_FAILED;
344 }
345
346 if (!reply.ReadInt32(result)) {
347 ANS_LOGE("[SetShowBadgeEnabledForBundle] fail: read result failed.");
348 return ERR_ANS_PARCELABLE_FAILED;
349 }
350
351 return result;
352 }
353
GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> & bundleOption,bool & enabled)354 ErrCode AnsManagerProxy::GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled)
355 {
356 if (bundleOption == nullptr) {
357 ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: bundle is empty.");
358 return ERR_ANS_INVALID_PARAM;
359 }
360
361 MessageParcel data;
362 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
363 ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: write interface token failed.");
364 return ERR_ANS_PARCELABLE_FAILED;
365 }
366
367 if (!data.WriteParcelable(bundleOption)) {
368 ANS_LOGE("[GetShowBadgeEnabledForBundle] fail:: write bundle failed");
369 return ERR_ANS_PARCELABLE_FAILED;
370 }
371
372 MessageParcel reply;
373 MessageOption option = {MessageOption::TF_SYNC};
374 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE, option, data, reply);
375 if (result != ERR_OK) {
376 ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: transact ErrCode=%{public}d", result);
377 return ERR_ANS_TRANSACT_FAILED;
378 }
379
380 if (!reply.ReadInt32(result)) {
381 ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read result failed.");
382 return ERR_ANS_PARCELABLE_FAILED;
383 }
384
385 if (!reply.ReadBool(enabled)) {
386 ANS_LOGE("[GetShowBadgeEnabledForBundle] fail: read enabled failed.");
387 return ERR_ANS_PARCELABLE_FAILED;
388 }
389
390 return result;
391 }
392
GetShowBadgeEnabled(bool & enabled)393 ErrCode AnsManagerProxy::GetShowBadgeEnabled(bool &enabled)
394 {
395 MessageParcel data;
396 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
397 ANS_LOGE("[GetShowBadgeEnabled] fail: write interface token failed.");
398 return ERR_ANS_PARCELABLE_FAILED;
399 }
400
401 MessageParcel reply;
402 MessageOption option = {MessageOption::TF_SYNC};
403 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED, option, data, reply);
404 if (result != ERR_OK) {
405 ANS_LOGE("[GetShowBadgeEnabled] fail: transact ErrCode=%{public}d", result);
406 return ERR_ANS_TRANSACT_FAILED;
407 }
408
409 if (!reply.ReadInt32(result)) {
410 ANS_LOGE("[GetShowBadgeEnabled] fail: read result failed.");
411 return ERR_ANS_PARCELABLE_FAILED;
412 }
413
414 if (!reply.ReadBool(enabled)) {
415 ANS_LOGE("[GetShowBadgeEnabled] fail: read enabled failed.");
416 return ERR_ANS_PARCELABLE_FAILED;
417 }
418
419 return result;
420 }
421
IsAllowedNotify(bool & allowed)422 ErrCode AnsManagerProxy::IsAllowedNotify(bool &allowed)
423 {
424 MessageParcel data;
425 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
426 ANS_LOGE("[IsAllowedNotify] fail: write interface token failed.");
427 return ERR_ANS_PARCELABLE_FAILED;
428 }
429
430 MessageParcel reply;
431 MessageOption option = {MessageOption::TF_SYNC};
432 ErrCode result = InnerTransact(NotificationInterfaceCode::IS_ALLOWED_NOTIFY, option, data, reply);
433 if (result != ERR_OK) {
434 ANS_LOGE("[IsAllowedNotify] fail: transact ErrCode=%{public}d", result);
435 return ERR_ANS_TRANSACT_FAILED;
436 }
437
438 if (!reply.ReadInt32(result)) {
439 ANS_LOGE("[IsAllowedNotify] fail: read result failed.");
440 return ERR_ANS_PARCELABLE_FAILED;
441 }
442
443 if (!reply.ReadBool(allowed)) {
444 ANS_LOGE("[IsAllowedNotify] fail: read allowed failed.");
445 return ERR_ANS_PARCELABLE_FAILED;
446 }
447
448 return result;
449 }
450
IsAllowedNotifySelf(bool & allowed)451 ErrCode AnsManagerProxy::IsAllowedNotifySelf(bool &allowed)
452 {
453 MessageParcel data;
454 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
455 ANS_LOGE("[IsAllowedNotifySelf] fail: write interface token failed.");
456 return ERR_ANS_PARCELABLE_FAILED;
457 }
458
459 MessageParcel reply;
460 MessageOption option = {MessageOption::TF_SYNC};
461 ErrCode result = InnerTransact(NotificationInterfaceCode::IS_ALLOWED_NOTIFY_SELF, option, data, reply);
462 if (result != ERR_OK) {
463 ANS_LOGE("[IsAllowedNotifySelf] fail: transact ErrCode=%{public}d", result);
464 return ERR_ANS_TRANSACT_FAILED;
465 }
466
467 if (!reply.ReadInt32(result)) {
468 ANS_LOGE("[IsAllowedNotifySelf] fail: read result failed.");
469 return ERR_ANS_PARCELABLE_FAILED;
470 }
471
472 if (!reply.ReadBool(allowed)) {
473 ANS_LOGE("[IsAllowedNotifySelf] fail: read allowed failed.");
474 return ERR_ANS_PARCELABLE_FAILED;
475 }
476
477 return result;
478 }
479
CanPopEnableNotificationDialog(const sptr<AnsDialogCallback> & callback,bool & canPop,std::string & bundleName)480 ErrCode AnsManagerProxy::CanPopEnableNotificationDialog(const sptr<AnsDialogCallback> &callback,
481 bool &canPop, std::string &bundleName)
482 {
483 MessageParcel data;
484 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
485 ANS_LOGE("[CanPopEnableNotificationDialog] fail: write interface token failed.");
486 return ERR_ANS_PARCELABLE_FAILED;
487 }
488
489 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
490 ANS_LOGE("[CanPopEnableNotificationDialog] fail: write callback failed");
491 return ERR_ANS_PARCELABLE_FAILED;
492 }
493
494 MessageParcel reply;
495 MessageOption option = {MessageOption::TF_SYNC};
496 ErrCode result = InnerTransact(NotificationInterfaceCode::CAN_POP_ENABLE_NOTIFICATION_DIALOG,
497 option, data, reply);
498 if (result != ERR_OK) {
499 ANS_LOGE("[CanPopEnableNotificationDialog] fail: transact ErrCode=%{public}d", result);
500 return ERR_ANS_TRANSACT_FAILED;
501 }
502
503 if (!reply.ReadInt32(result)) {
504 ANS_LOGE("[CanPopEnableNotificationDialog] fail: read result failed.");
505 return ERR_ANS_PARCELABLE_FAILED;
506 }
507
508 if (!reply.ReadBool(canPop)) {
509 ANS_LOGE("[CanPopEnableNotificationDialog] fail: read canPop failed.");
510 return ERR_ANS_PARCELABLE_FAILED;
511 }
512 if (!reply.ReadString(bundleName)) {
513 ANS_LOGE("[CanPopEnableNotificationDialog] fail: read bundleName failed.");
514 return ERR_ANS_PARCELABLE_FAILED;
515 }
516
517 return result;
518 }
519
RemoveEnableNotificationDialog()520 ErrCode AnsManagerProxy::RemoveEnableNotificationDialog()
521 {
522 MessageParcel data;
523 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
524 ANS_LOGE("[CanPopEnableNotificationDialog] fail: write interface token failed.");
525 return ERR_ANS_PARCELABLE_FAILED;
526 }
527 MessageParcel reply;
528 MessageOption option = {MessageOption::TF_SYNC};
529 ErrCode result = InnerTransact(NotificationInterfaceCode::REMOVE_ENABLE_NOTIFICATION_DIALOG,
530 option, data, reply);
531 if (result != ERR_OK) {
532 ANS_LOGE("[RemoveEnableNotificationDialog] fail: transact ErrCode=%{public}d", result);
533 return ERR_ANS_TRANSACT_FAILED;
534 }
535 if (!reply.ReadInt32(result)) {
536 ANS_LOGE("[CanPopEnableNotificationDialog] fail: read result failed.");
537 return ERR_ANS_PARCELABLE_FAILED;
538 }
539 return result;
540 }
541
IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> & bundleOption,bool & allowed)542 ErrCode AnsManagerProxy::IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed)
543 {
544 if (bundleOption == nullptr) {
545 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: bundle is empty.");
546 return ERR_ANS_INVALID_PARAM;
547 }
548
549 MessageParcel data;
550 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
551 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write interface token failed.");
552 return ERR_ANS_PARCELABLE_FAILED;
553 }
554
555 if (!data.WriteParcelable(bundleOption)) {
556 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write bundle failed");
557 return ERR_ANS_PARCELABLE_FAILED;
558 }
559
560 MessageParcel reply;
561 MessageOption option = {MessageOption::TF_SYNC};
562 ErrCode result = InnerTransact(NotificationInterfaceCode::IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY, option, data, reply);
563 if (result != ERR_OK) {
564 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: transact ErrCode=%{public}d", result);
565 return ERR_ANS_TRANSACT_FAILED;
566 }
567
568 if (!reply.ReadInt32(result)) {
569 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read result failed.");
570 return ERR_ANS_PARCELABLE_FAILED;
571 }
572
573 if (!reply.ReadBool(allowed)) {
574 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read allowed error.");
575 return ERR_ANS_PARCELABLE_FAILED;
576 }
577
578 return result;
579 }
580
IsSpecialUserAllowedNotify(const int32_t & userId,bool & allowed)581 ErrCode AnsManagerProxy::IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed)
582 {
583 MessageParcel data;
584 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
585 ANS_LOGE("[IsSpecialUserAllowedNotify] fail: write interface token failed.");
586 return ERR_ANS_PARCELABLE_FAILED;
587 }
588
589 if (!data.WriteInt32(userId)) {
590 ANS_LOGE("[IsSpecialUserAllowedNotify] fail: write userId failed");
591 return ERR_ANS_PARCELABLE_FAILED;
592 }
593
594 MessageParcel reply;
595 MessageOption option = {MessageOption::TF_SYNC};
596 ErrCode result = InnerTransact(NotificationInterfaceCode::IS_SPECIAL_USER_ALLOWED_NOTIFY, option, data, reply);
597 if (result != ERR_OK) {
598 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: transact ErrCode=%{public}d", result);
599 return ERR_ANS_TRANSACT_FAILED;
600 }
601
602 if (!reply.ReadInt32(result)) {
603 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read result failed.");
604 return ERR_ANS_PARCELABLE_FAILED;
605 }
606
607 if (!reply.ReadBool(allowed)) {
608 ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read allowed failed.");
609 return ERR_ANS_PARCELABLE_FAILED;
610 }
611
612 return result;
613 }
614
SetNotificationsEnabledByUser(const int32_t & userId,bool enabled)615 ErrCode AnsManagerProxy::SetNotificationsEnabledByUser(const int32_t &userId, bool enabled)
616 {
617 MessageParcel data;
618 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
619 ANS_LOGE("[SetNotificationsEnabledByUser] fail: write interface token failed.");
620 return ERR_ANS_PARCELABLE_FAILED;
621 }
622
623 if (!data.WriteInt32(userId)) {
624 ANS_LOGE("[SetNotificationsEnabledByUser] fail: write userId failed");
625 return ERR_ANS_PARCELABLE_FAILED;
626 }
627
628 if (!data.WriteBool(enabled)) {
629 ANS_LOGE("[SetNotificationsEnabledByUser] fail: write enabled failed");
630 return ERR_ANS_PARCELABLE_FAILED;
631 }
632
633 MessageParcel reply;
634 MessageOption option = {MessageOption::TF_SYNC};
635 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER, option, data, reply);
636 if (result != ERR_OK) {
637 ANS_LOGE("[SetNotificationsEnabledByUser] fail: transact ErrCode=%{public}d", result);
638 return ERR_ANS_TRANSACT_FAILED;
639 }
640
641 if (!reply.ReadInt32(result)) {
642 ANS_LOGE("[SetNotificationsEnabledByUser] fail: read result failed.");
643 return ERR_ANS_PARCELABLE_FAILED;
644 }
645
646 return result;
647 }
648
SetSyncNotificationEnabledWithoutApp(const int32_t userId,const bool enabled)649 ErrCode AnsManagerProxy::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled)
650 {
651 MessageParcel data;
652 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
653 ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: write interface token failed.");
654 return ERR_ANS_PARCELABLE_FAILED;
655 }
656
657 if (!data.WriteInt32(userId)) {
658 ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail:: write userId failed.");
659 return ERR_ANS_PARCELABLE_FAILED;
660 }
661
662 if (!data.WriteBool(enabled)) {
663 ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: write enabled failed");
664 return ERR_ANS_PARCELABLE_FAILED;
665 }
666
667 MessageParcel reply;
668 MessageOption option = {MessageOption::TF_SYNC};
669 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP,
670 option, data, reply);
671 if (result != ERR_OK) {
672 ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: transact ErrCode=%{public}d", result);
673 return ERR_ANS_TRANSACT_FAILED;
674 }
675
676 if (!reply.ReadInt32(result)) {
677 ANS_LOGE("[SetSyncNotificationEnabledWithoutApp] fail: read result failed.");
678 return ERR_ANS_PARCELABLE_FAILED;
679 }
680
681 return result;
682 }
683
GetSyncNotificationEnabledWithoutApp(const int32_t userId,bool & enabled)684 ErrCode AnsManagerProxy::GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled)
685 {
686 MessageParcel data;
687 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
688 ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: write interface token failed.");
689 return ERR_ANS_PARCELABLE_FAILED;
690 }
691
692 if (!data.WriteInt32(userId)) {
693 ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail:: write userId failed.");
694 return ERR_ANS_PARCELABLE_FAILED;
695 }
696
697 MessageParcel reply;
698 MessageOption option = {MessageOption::TF_SYNC};
699 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP,
700 option, data, reply);
701 if (result != ERR_OK) {
702 ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: transact ErrCode=%{public}d", result);
703 return ERR_ANS_TRANSACT_FAILED;
704 }
705
706 if (!reply.ReadInt32(result)) {
707 ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: read result failed.");
708 return ERR_ANS_PARCELABLE_FAILED;
709 }
710
711 if (!reply.ReadBool(enabled)) {
712 ANS_LOGE("[GetSyncNotificationEnabledWithoutApp] fail: read enable failed.");
713 return ERR_ANS_PARCELABLE_FAILED;
714 }
715
716 return result;
717 }
718
SetBadgeNumber(int32_t badgeNumber,const std::string & instanceKey)719 ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey)
720 {
721 MessageParcel data;
722 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
723 ANS_LOGE("[SetBadgeNumber] fail: write interface token failed.");
724 return ERR_ANS_PARCELABLE_FAILED;
725 }
726
727 if (!data.WriteInt32(badgeNumber)) {
728 ANS_LOGE("[SetBadgeNumber] fail:: write badgeNumber failed.");
729 return ERR_ANS_PARCELABLE_FAILED;
730 }
731
732 if (!data.WriteString(instanceKey)) {
733 ANS_LOGE("[SetBadgeNumber] fail:: write instancekey failed.");
734 return ERR_ANS_PARCELABLE_FAILED;
735 }
736
737 MessageParcel reply;
738 MessageOption option = {MessageOption::TF_SYNC};
739 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_BADGE_NUMBER, option, data, reply);
740 if (result != ERR_OK) {
741 ANS_LOGE("[SetBadgeNumber] fail: transact ErrCode=%{public}d", result);
742 return ERR_ANS_TRANSACT_FAILED;
743 }
744
745 if (!reply.ReadInt32(result)) {
746 ANS_LOGE("[SetBadgeNumber] fail: read result failed.");
747 return ERR_ANS_PARCELABLE_FAILED;
748 }
749
750 return result;
751 }
752
SetBadgeNumberByBundle(const sptr<NotificationBundleOption> & bundleOption,int32_t badgeNumber)753 ErrCode AnsManagerProxy::SetBadgeNumberByBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber)
754 {
755 if (bundleOption == nullptr) {
756 ANS_LOGE("Bundle is empty.");
757 return ERR_ANS_INVALID_PARAM;
758 }
759 MessageParcel data;
760 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
761 ANS_LOGE("Write interface token failed.");
762 return ERR_ANS_PARCELABLE_FAILED;
763 }
764 if (!data.WriteParcelable(bundleOption)) {
765 ANS_LOGE("Write bundle option failed.");
766 return ERR_ANS_PARCELABLE_FAILED;
767 }
768 if (!data.WriteInt32(badgeNumber)) {
769 ANS_LOGE("Write badge number failed.");
770 return ERR_ANS_PARCELABLE_FAILED;
771 }
772
773 MessageParcel reply;
774 MessageOption option = { MessageOption::TF_SYNC };
775 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_BADGE_NUMBER_BY_BUNDLE, option, data, reply);
776 if (result != ERR_OK) {
777 ANS_LOGE("Transact error code is: %{public}d", result);
778 return ERR_ANS_TRANSACT_FAILED;
779 }
780 if (!reply.ReadInt32(result)) {
781 ANS_LOGE("Read result failed.");
782 return ERR_ANS_PARCELABLE_FAILED;
783 }
784 return result;
785 }
786
SetBadgeNumberForDhByBundle(const sptr<NotificationBundleOption> & bundleOption,int32_t badgeNumber)787 ErrCode AnsManagerProxy::SetBadgeNumberForDhByBundle(
788 const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber)
789 {
790 if (bundleOption == nullptr) {
791 ANS_LOGE("Bundle is empty.");
792 return ERR_ANS_INVALID_PARAM;
793 }
794 MessageParcel data;
795 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
796 ANS_LOGE("Write interface token failed.");
797 return ERR_ANS_PARCELABLE_FAILED;
798 }
799 if (!data.WriteParcelable(bundleOption)) {
800 ANS_LOGE("Write bundle option failed.");
801 return ERR_ANS_PARCELABLE_FAILED;
802 }
803 if (!data.WriteInt32(badgeNumber)) {
804 ANS_LOGE("Write badge number failed.");
805 return ERR_ANS_PARCELABLE_FAILED;
806 }
807
808 MessageParcel reply;
809 MessageOption option = { MessageOption::TF_SYNC };
810 ErrCode result = InnerTransact(NotificationInterfaceCode::SET_BADGE_NUMBER_FOR_DH_BY_BUNDLE, option, data, reply);
811 if (result != ERR_OK) {
812 ANS_LOGE("Transact error code is: %{public}d", result);
813 return ERR_ANS_TRANSACT_FAILED;
814 }
815 if (!reply.ReadInt32(result)) {
816 ANS_LOGE("Read result failed.");
817 return ERR_ANS_PARCELABLE_FAILED;
818 }
819 return result;
820 }
821
GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> & bundleOption)822 ErrCode AnsManagerProxy::GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption)
823 {
824 ANS_LOGD("Called.");
825 MessageParcel data;
826 int32_t vectorSize = 0;
827 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
828 ANS_LOGE("Write interface token failed.");
829 return ERR_ANS_PARCELABLE_FAILED;
830 }
831
832 MessageParcel reply;
833 MessageOption option = { MessageOption::TF_SYNC };
834 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_NOTIFICATION_ENABLE_STATUS, option, data, reply);
835 if (result != ERR_OK) {
836 ANS_LOGE("Fail: transact ErrCode=%{public}d", result);
837 return ERR_ANS_TRANSACT_FAILED;
838 }
839
840 if (!reply.ReadInt32(result)) {
841 ANS_LOGE("Fail: read result failed.");
842 return ERR_ANS_PARCELABLE_FAILED;
843 }
844
845 if (!reply.ReadInt32(vectorSize)) {
846 ANS_LOGE("Fail: read vectorSize failed.");
847 return ERR_ANS_PARCELABLE_FAILED;
848 }
849
850 if (vectorSize > MAX_STATUS_VECTOR_NUM) {
851 ANS_LOGE("Bundle status vector is over size");
852 return ERR_ANS_PARCELABLE_FAILED;
853 }
854
855 for (auto i = 0; i < vectorSize; i++) {
856 sptr<NotificationBundleOption> obj = reply.ReadParcelable<NotificationBundleOption>();
857 if (obj == nullptr) {
858 ANS_LOGE("The obj of Bundle status vector is nullptr.");
859 return ERR_ANS_PARCELABLE_FAILED;
860 }
861 bundleOption.emplace_back(*obj);
862 }
863
864 return result;
865 }
866
GetAllLiveViewEnabledBundles(std::vector<NotificationBundleOption> & bundleOption)867 ErrCode AnsManagerProxy::GetAllLiveViewEnabledBundles(std::vector<NotificationBundleOption> &bundleOption)
868 {
869 ANS_LOGD("Called.");
870 MessageParcel data;
871 int32_t vectorSize = 0;
872 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
873 ANS_LOGE("Write interface token failed.");
874 return ERR_ANS_PARCELABLE_FAILED;
875 }
876
877 MessageParcel reply;
878 MessageOption option = { MessageOption::TF_SYNC };
879 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_LIVEVIEW_ENABLE_STATUS, option, data, reply);
880 if (result != ERR_OK) {
881 ANS_LOGE("Fail: transact ErrCode=%{public}d", result);
882 return ERR_ANS_TRANSACT_FAILED;
883 }
884
885 if (!reply.ReadInt32(result)) {
886 ANS_LOGE("Fail: read result failed.");
887 return ERR_ANS_PARCELABLE_FAILED;
888 }
889
890 if (!reply.ReadInt32(vectorSize)) {
891 ANS_LOGE("Fail: read vectorSize failed.");
892 return ERR_ANS_PARCELABLE_FAILED;
893 }
894
895 if (vectorSize > MAX_STATUS_VECTOR_NUM) {
896 ANS_LOGE("Bundle status vector is over size");
897 return ERR_ANS_PARCELABLE_FAILED;
898 }
899
900 for (auto i = 0; i < vectorSize; i++) {
901 sptr<NotificationBundleOption> obj = reply.ReadParcelable<NotificationBundleOption>();
902 if (obj == nullptr) {
903 ANS_LOGE("The obj of Bundle status vector is nullptr.");
904 return ERR_ANS_PARCELABLE_FAILED;
905 }
906 bundleOption.emplace_back(*obj);
907 }
908
909 return result;
910 }
911
GetAllDistribuedEnabledBundles(const std::string & deviceType,std::vector<NotificationBundleOption> & bundleOption)912 ErrCode AnsManagerProxy::GetAllDistribuedEnabledBundles(const std::string& deviceType,
913 std::vector<NotificationBundleOption> &bundleOption)
914 {
915 ANS_LOGD("Called.");
916 MessageParcel data;
917 int32_t vectorSize = 0;
918 if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) {
919 ANS_LOGE("Write interface token failed.");
920 return ERR_ANS_PARCELABLE_FAILED;
921 }
922
923 if (!data.WriteString(deviceType)) {
924 ANS_LOGE("[GetAllDistribuedEnabledBundles] fail: write deviceType failed");
925 return ERR_ANS_PARCELABLE_FAILED;
926 }
927
928 MessageParcel reply;
929 MessageOption option = { MessageOption::TF_SYNC };
930 ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_DISTRIBUTED_ENABLE_STATUS, option, data, reply);
931 if (result != ERR_OK) {
932 ANS_LOGE("Fail: transact ErrCode=%{public}d", result);
933 return ERR_ANS_TRANSACT_FAILED;
934 }
935
936 if (!reply.ReadInt32(result)) {
937 ANS_LOGE("Fail: read result failed.");
938 return ERR_ANS_PARCELABLE_FAILED;
939 }
940
941 if (!reply.ReadInt32(vectorSize)) {
942 ANS_LOGE("Fail: read vectorSize failed.");
943 return ERR_ANS_PARCELABLE_FAILED;
944 }
945
946 if (vectorSize > MAX_STATUS_VECTOR_NUM) {
947 ANS_LOGE("Bundle status vector is over size");
948 return ERR_ANS_PARCELABLE_FAILED;
949 }
950
951 for (auto i = 0; i < vectorSize; i++) {
952 sptr<NotificationBundleOption> obj = reply.ReadParcelable<NotificationBundleOption>();
953 if (obj == nullptr) {
954 ANS_LOGE("The obj of Bundle status vector is nullptr.");
955 return ERR_ANS_PARCELABLE_FAILED;
956 }
957 bundleOption.emplace_back(*obj);
958 }
959
960 return result;
961 }
962 } // namespace Notification
963 } // namespace OHOS
964