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 #ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_STUB_H 17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_STUB_H 18 19 #include <functional> 20 #include <map> 21 22 #include "ans_manager_interface.h" 23 #include "ans_subscriber_local_live_view_interface.h" 24 #include "distributed_notification_service_ipc_interface_code.h" 25 #include "iremote_stub.h" 26 27 namespace OHOS { 28 namespace Notification { 29 class AnsManagerStub : public IRemoteStub<AnsManagerInterface> { 30 public: 31 AnsManagerStub(); 32 ~AnsManagerStub() override; 33 DISALLOW_COPY_AND_MOVE(AnsManagerStub); 34 35 /** 36 * @brief Handle remote request. 37 * 38 * @param data Indicates the input parcel. 39 * @param reply Indicates the output parcel. 40 * @param option Indicates the message option. 41 * @return Returns ERR_OK on success, others on failure. 42 */ 43 virtual int OnRemoteRequest( 44 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 45 46 /** 47 * @brief Publishes a notification with a specified label. 48 * @note If a notification with the same ID has been published by the current application and has not been deleted, 49 * this method will update the notification. 50 * 51 * @param label Indicates the label of the notification to publish. 52 * @param notification Indicates the NotificationRequest object for setting the notification content. 53 * This parameter must be specified. 54 * @return Returns ERR_OK on success, others on failure. 55 */ 56 virtual ErrCode Publish(const std::string &label, const sptr<NotificationRequest> ¬ification) override; 57 58 /** 59 * @brief Cancels a published notification matching the specified label and notificationId. 60 * 61 * @param notificationId Indicates the ID of the notification to cancel. 62 * @param label Indicates the label of the notification to cancel. 63 * @return Returns cancel notification result. 64 */ 65 virtual ErrCode Cancel(int32_t notificationId, const std::string &label) override; 66 67 /** 68 * @brief Cancels all the published notifications. 69 * 70 * @return Returns ERR_OK on success, others on failure. 71 */ 72 virtual ErrCode CancelAll() override; 73 74 /** 75 * @brief Cancels a published agent notification. 76 * 77 * @param notificationId Indicates the unique notification ID in the application. 78 * The value must be the ID of a published notification. 79 * Otherwise, this method does not take effect. 80 * @param representativeBundle Indicates the name of application bundle your application is representing. 81 * @param userId Indicates the specific user. 82 * @return Returns cancel notification result. 83 */ 84 virtual ErrCode CancelAsBundle( 85 int32_t notificationId, const std::string &representativeBundle, int32_t userId) override; 86 87 /** 88 * @brief Adds a notification slot by type. 89 * 90 * @param slotType Indicates the notification slot type to be added. 91 * @return Returns ERR_OK on success, others on failure. 92 */ 93 virtual ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override; 94 95 /** 96 * @brief Creates multiple notification slots. 97 * 98 * @param slots Indicates the notification slots to create. 99 * @return Returns ERR_OK on success, others on failure. 100 */ 101 virtual ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override; 102 103 /** 104 * @brief Deletes a created notification slot based on the slot ID. 105 * 106 * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot 107 * This parameter must be specified. 108 * @return Returns ERR_OK on success, others on failure. 109 */ 110 virtual ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override; 111 112 /** 113 * @brief Deletes all notification slots. 114 * 115 * @return Returns ERR_OK on success, others on failure. 116 */ 117 virtual ErrCode RemoveAllSlots() override; 118 119 /** 120 * @brief Queries a created notification slot. 121 * 122 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This 123 * parameter must be specified. 124 * @param slot Indicates the created NotificationSlot. 125 * @return Returns ERR_OK on success, others on failure. 126 */ 127 virtual ErrCode GetSlotByType( 128 const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot) override; 129 130 /** 131 * @brief Obtains all notification slots of this application. 132 * 133 * @param slots Indicates the created NotificationSlot. 134 * @return Returns ERR_OK on success, others on failure. 135 */ 136 virtual ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override; 137 138 /** 139 * @brief Obtains the number of slot. 140 * 141 * @param bundleOption Indicates the bundle name and uid of the application. 142 * @param num Indicates the number of slot. 143 * @return Returns ERR_OK on success, others on failure. 144 */ 145 virtual ErrCode GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num) override; 146 147 /** 148 * @brief Obtains active notifications of the current application in the system. 149 * 150 * @param notifications Indicates active NotificationRequest objects of the current application. 151 * @return Returns ERR_OK on success, others on failure. 152 */ 153 virtual ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications) override; 154 155 /** 156 * @brief Obtains the number of active notifications of the current application in the system. 157 * 158 * @param num Indicates the number of active notifications of the current application. 159 * @return Returns ERR_OK on success, others on failure. 160 */ 161 virtual ErrCode GetActiveNotificationNums(uint64_t &num) override; 162 163 /** 164 * @brief Obtains all active notifications in the current system. The caller must have system permissions to 165 * call this method. 166 * 167 * @param notifications Indicates all active notifications of this application. 168 * @return Returns ERR_OK on success, others on failure. 169 */ 170 virtual ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications) override; 171 172 /** 173 * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method 174 * to obtain particular active notifications, you must have received the notifications and obtained the key 175 * via {Notification::GetKey()}. 176 * 177 * @param key Indicates the key array for querying corresponding active notifications. 178 * If this parameter is null, this method returns all active notifications in the system. 179 * @param notification Indicates the set of active notifications corresponding to the specified key. 180 * @return Returns ERR_OK on success, others on failure. 181 */ 182 virtual ErrCode GetSpecialActiveNotifications( 183 const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications) override; 184 185 virtual ErrCode GetActiveNotificationByFilter( 186 const sptr<NotificationBundleOption> &bundleOption, const int32_t notificationId, const std::string &label, 187 std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &request) override; 188 189 /** 190 * @brief Allows another application to act as an agent to publish notifications in the name of your application 191 * bundle. 192 * 193 * @param agent Indicates the name of the application bundle that can publish notifications for your application. 194 * @return Returns ERR_OK on success, others on failure. 195 */ 196 virtual ErrCode SetNotificationAgent(const std::string &agent) override; 197 198 /** 199 * @brief Obtains the name of the application bundle that can publish notifications in the name of your application. 200 * 201 * @param agent Indicates the name of the application bundle that can publish notifications for your application if 202 * any; returns null otherwise. 203 * @return Returns ERR_OK on success, others on failure. 204 */ 205 virtual ErrCode GetNotificationAgent(std::string &agent) override; 206 207 /** 208 * @brief Checks whether your application has permission to publish notifications by calling 209 * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the 210 * given representativeBundle. 211 * 212 * @param representativeBundle Indicates the name of application bundle your application is representing. 213 * @param canPublish Indicates whether your application has permission to publish notifications. 214 * @return Returns ERR_OK on success, others on failure. 215 */ 216 virtual ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override; 217 218 /** 219 * @brief Publishes a notification in the name of a specified application bundle. 220 * @note If the notification to be published has the same ID as a published notification that has not been canceled, 221 * the existing notification will be replaced by the new one. 222 * 223 * @param notification Indicates the NotificationRequest object for setting the notification content. 224 * This parameter must be specified. 225 * @param representativeBundle Indicates the name of the application bundle that allows your application to publish 226 * notifications for it by calling setNotificationAgent. 227 * @return Returns ERR_OK on success, others on failure. 228 */ 229 virtual ErrCode PublishAsBundle( 230 const sptr<NotificationRequest> notification, const std::string &representativeBundle) override; 231 232 /** 233 * @brief Sets the number of active notifications of the current application as the number to be displayed on the 234 * notification badge. 235 * 236 * @param num Indicates the badge number. 237 * @return Returns ERR_OK on success, others on failure. 238 */ 239 virtual ErrCode SetNotificationBadgeNum(int32_t num) override; 240 241 /** 242 * @brief Obtains the importance level of this application. 243 * 244 * @param importance Indicates the importance level of this application, which can be LEVEL_NONE, 245 LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED. 246 * @return Returns ERR_OK on success, others on failure. 247 */ 248 virtual ErrCode GetBundleImportance(int32_t &importance) override; 249 250 /** 251 * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. 252 * 253 * @param granted True if the application has permission; false for otherwise. 254 * @return Returns ERR_OK on success, others on failure. 255 */ 256 virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; 257 258 /** 259 * @brief Trigger the local live view after the button has been clicked. 260 * @note Your application must have platform signature to use this method. 261 * 262 * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. 263 * @param notificationId Indicates the id of the notification. 264 * @param buttonOption Indicates which button has been clicked. 265 * @return Returns trigger localLiveView result. 266 */ 267 virtual ErrCode TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption, 268 const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption) override; 269 270 /** 271 * @brief Delete notification. 272 * 273 * @param bundleOption Indicates the NotificationBundleOption of the notification. 274 * @param notificationId Indicates the id of the notification. 275 * @param label Indicates the label of the notification. 276 * @param removeReason Indicates the reason of remove notification. 277 * @return Returns ERR_OK on success, others on failure. 278 */ 279 virtual ErrCode RemoveNotification(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, 280 const std::string &label, int32_t removeReason) override; 281 282 /** 283 * @brief Delete all notifications. 284 * 285 * @param bundleOption Indicates the NotificationBundleOption of notifications. 286 * @return Returns ERR_OK on success, others on failure. 287 */ 288 virtual ErrCode RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption) override; 289 290 ErrCode RemoveNotifications(const std::vector<std::string> &keys, int32_t removeReason) override; 291 292 /** 293 * @brief Delete notification based on key. 294 * 295 * @param key Indicates the key to delete notification. 296 * @param removeReason Indicates the reason of remove notification. 297 * @return Returns ERR_OK on success, others on failure. 298 */ 299 virtual ErrCode Delete(const std::string &key, int32_t removeReason) override; 300 301 /** 302 * @brief Remove notifications based on bundle. 303 * 304 * @param bundleOption Indicates the NotificationBundleOption of notifications. 305 * @return Returns ERR_OK on success, others on failure. 306 */ 307 virtual ErrCode DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption) override; 308 309 /** 310 * @brief Remove all notifications. 311 * 312 * @return Returns ERR_OK on success, others on failure. 313 */ 314 virtual ErrCode DeleteAll() override; 315 316 /** 317 * @brief Get all the slots corresponding to the bundle. 318 * 319 * @param bundleOption Indicates the NotificationBundleOption object. 320 * @param slots Indicates the notification slots. 321 * @return Returns ERR_OK on success, others on failure. 322 */ 323 virtual ErrCode GetSlotsByBundle( 324 const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots) override; 325 326 /** 327 * @brief Update slots according to bundle. 328 * 329 * @param bundleOption Indicates the NotificationBundleOption object. 330 * @param slots Indicates the notification slots to be updated. 331 * @return Returns ERR_OK on success, others on failure. 332 */ 333 virtual ErrCode UpdateSlots( 334 const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots) override; 335 336 /** 337 * @brief Allow notifications to be sent based on the deviceId. 338 * 339 * @param deviceId Indicates the device Id. 340 * @return Returns ERR_OK on success, others on failure. 341 */ 342 ErrCode RequestEnableNotification(const std::string &deviceId, 343 const sptr<AnsDialogCallback> &callback, 344 const sptr<IRemoteObject> &callerToken) override; 345 346 /** 347 * @brief Set whether to allow the specified deviceId to send notifications for current bundle. 348 * 349 * @param deviceId Indicates the device Id. 350 * @param enabled Indicates the flag that allows notification to be pulished. 351 * @return Returns ERR_OK on success, others on failure. 352 */ 353 virtual ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override; 354 355 /** 356 * @brief Set whether to allow the specified deviceId to send notifications for all bundles. 357 * 358 * @param deviceId Indicates the device Id. 359 * @param enabled Indicates the flag that allows notification to be pulished. 360 * @return Returns ERR_OK on success, others on failure. 361 */ 362 virtual ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override; 363 364 /** 365 * @brief Set whether to allow the specified bundle to send notifications. 366 * 367 * @param bundleOption Indicates the NotificationBundleOption object. 368 * @param enabled Indicates the flag that allows notification to be pulished. 369 * @return Returns ERR_OK on success, others on failure. 370 */ 371 virtual ErrCode SetNotificationsEnabledForSpecialBundle( 372 const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 373 374 /** 375 * @brief Sets whether the bundle allows the banner to display notification. 376 * 377 * @param bundleOption Indicates the NotificationBundleOption object. 378 * @param enabled Indicates the flag that allows badge to be shown. 379 * @return Returns ERR_OK on success, others on failure. 380 */ 381 virtual ErrCode SetShowBadgeEnabledForBundle( 382 const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 383 384 /** 385 * @brief Gets whether the bundle allows the badge to display the status of notifications. 386 * 387 * @param bundleOption Indicates the NotificationBundleOption object. 388 * @param enabled Indicates the flag that allows badge to be shown. 389 * @return Returns ERR_OK on success, others on failure. 390 */ 391 virtual ErrCode GetShowBadgeEnabledForBundle( 392 const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override; 393 394 /** 395 * @brief Gets whether allows the badge to display the status of notifications. 396 * 397 * @param enabled Indicates the flag that allows badge to be shown. 398 * @return Returns ERR_OK on success, others on failure. 399 */ 400 virtual ErrCode GetShowBadgeEnabled(bool &enabled) override; 401 402 /** 403 * @brief Subscribes notifications. 404 * 405 * @param subscriber Indicates the subscriber. 406 * @param info Indicates the NotificationSubscribeInfo object. 407 * @return Returns ERR_OK on success, others on failure. 408 */ 409 virtual ErrCode Subscribe( 410 const sptr<AnsSubscriberInterface> &subscriber, const sptr<NotificationSubscribeInfo> &info) override; 411 412 /** 413 * @brief Subscribes notifications self. 414 * 415 * @param subscriber Indicates the subscriber. 416 * @return Returns ERR_OK on success, others on failure. 417 */ 418 virtual ErrCode SubscribeSelf(const sptr<AnsSubscriberInterface> &subscriber) override; 419 420 virtual ErrCode SubscribeLocalLiveView( 421 const sptr<AnsSubscriberLocalLiveViewInterface> &subscriber, 422 const sptr<NotificationSubscribeInfo> &info) override; 423 424 /** 425 * @brief Unsubscribes notifications. 426 * 427 * @param subscriber Indicates the subscriber. 428 * @param info Indicates the NotificationSubscribeInfo object. 429 * @return Returns ERR_OK on success, others on failure. 430 */ 431 virtual ErrCode Unsubscribe( 432 const sptr<AnsSubscriberInterface> &subscriber, const sptr<NotificationSubscribeInfo> &info) override; 433 434 /** 435 * @brief Checks whether this device is allowed to publish notifications. 436 * 437 * @param allowed Indicates the flag that allows notification. 438 * @return Returns ERR_OK on success, others on failure. 439 */ 440 virtual ErrCode IsAllowedNotify(bool &allowed) override; 441 442 /** 443 * @brief Checks whether this application is allowed to publish notifications. 444 * 445 * @param allowed Indicates the flag that allows notification. 446 * @return Returns ERR_OK on success, others on failure. 447 */ 448 virtual ErrCode IsAllowedNotifySelf(bool &allowed) override; 449 450 /** 451 * @brief Checks whether notifications are allowed for a specific bundle. 452 * 453 * @param bundleOption Indicates the NotificationBundleOption object. 454 * @param allowed Indicates the flag that allows notification. 455 * @return Returns ERR_OK on success, others on failure. 456 */ 457 virtual ErrCode IsSpecialBundleAllowedNotify( 458 const sptr<NotificationBundleOption> &bundleOption, bool &allowed) override; 459 460 /** 461 * @brief Set do not disturb date. 462 * 463 * @param date Indicates the NotificationDoNotDisturbDate object. 464 * @return Returns ERR_OK on success, others on failure. 465 */ 466 virtual ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date) override; 467 468 /** 469 * @brief Get do not disturb date. 470 * 471 * @param date Indicates the NotificationDoNotDisturbDate object. 472 * @return Returns ERR_OK on success, others on failure. 473 */ 474 virtual ErrCode GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date) override; 475 476 /** 477 * @brief Get whether Do Not Disturb mode is supported. 478 * 479 * @param doesSupport Indicates the flag that supports DND mode. 480 * @return Returns ERR_OK on success, others on failure. 481 */ 482 virtual ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override; 483 484 /** 485 * @brief Cancel notifications according to group. 486 * 487 * @param groupName Indicates the group name. 488 * @return Returns ERR_OK on success, others on failure. 489 */ 490 virtual ErrCode CancelGroup(const std::string &groupName) override; 491 492 /** 493 * @brief Delete notifications according to bundle and group. 494 * 495 * @param bundleOption Indicates the NotificationBundleOption object. 496 * @param groupName Indicates the group name. 497 * @return Returns ERR_OK on success, others on failure. 498 */ 499 virtual ErrCode RemoveGroupByBundle( 500 const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName) override; 501 502 /** 503 * @brief Gets whether distributed notification is enabled. 504 * 505 * @param enabled Indicates the enabled flag. 506 * @return Returns ERR_OK on success, others on failure. 507 */ 508 virtual ErrCode IsDistributedEnabled(bool &enabled) override; 509 510 /** 511 * @brief Sets distributed notification enabled or disabled. 512 * 513 * @param enabled Indicates the enabled flag. 514 * @return Returns ERR_OK on success, others on failure. 515 */ 516 virtual ErrCode EnableDistributed(bool enabled) override; 517 518 /** 519 * @brief Sets distributed notification enabled or disabled for specific bundle. 520 * 521 * @param bundleOption Indicates the NotificationBundleOption object. 522 * @param enabled Indicates the enabled flag. 523 * @return Returns ERR_OK on success, others on failure. 524 */ 525 virtual ErrCode EnableDistributedByBundle( 526 const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 527 528 /** 529 * @brief Sets distributed notification enabled or disabled for current bundle. 530 * 531 * @param enabled Indicates the enabled flag. 532 * @return Returns ERR_OK on success, others on failure. 533 */ 534 virtual ErrCode EnableDistributedSelf(bool enabled) override; 535 536 /** 537 * @brief Gets whether distributed notification is enabled for specific bundle. 538 * 539 * @param bundleOption Indicates the NotificationBundleOption object. 540 * @param enabled Indicates the enabled flag. 541 * @return Returns ERR_OK on success, others on failure. 542 */ 543 virtual ErrCode IsDistributedEnableByBundle( 544 const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override; 545 546 /** 547 * @brief Get the reminder type of the current device. 548 * 549 * @param remindType Reminder type for the device. 550 * @return Returns ERR_OK on success, others on failure. 551 */ 552 virtual ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override; 553 554 /** 555 * @brief Publishes a continuous notification. 556 * 557 * @param request Notification requests that need to be posted. 558 * @return Returns ERR_OK on success, others on failure. 559 */ 560 virtual ErrCode PublishContinuousTaskNotification(const sptr<NotificationRequest> &request) override; 561 562 /** 563 * @brief Cancels a continuous notification. 564 * 565 * @param label Identifies the label of the specified notification. 566 * @param notificationId Identifies the id of the specified notification. 567 * @return Returns ERR_OK on success, others on failure. 568 */ 569 virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; 570 571 /** 572 * @brief Publishes a reminder notification. 573 * 574 * @param reminder Identifies the reminder notification request that needs to be published. 575 * @return Returns ERR_OK on success, others on failure. 576 */ 577 virtual ErrCode PublishReminder(sptr<ReminderRequest> &reminder) override; 578 579 /** 580 * @brief Cancel a reminder notifications. 581 * 582 * @param reminderId Identifies the reminders id that needs to be canceled. 583 * @return Returns ERR_OK on success, others on failure. 584 */ 585 virtual ErrCode CancelReminder(const int32_t reminderId) override; 586 587 /** 588 * @brief Get all valid reminder notifications. 589 * 590 * @param reminders Identifies the list of all valid notifications. 591 * @return Returns ERR_OK on success, others on failure. 592 */ 593 virtual ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &reminders) override; 594 595 /** 596 * @brief Cancel all reminder notifications. 597 * 598 * @return Returns ERR_OK on success, others on failure. 599 */ 600 virtual ErrCode CancelAllReminders() override; 601 602 /** 603 * @brief Checks whether this device is support template. 604 * 605 * @param templateName Identifies the template name for searching as a condition. 606 * @param support Identifies the support flag. 607 * @return Returns ERR_OK on success, others on failure. 608 */ 609 virtual ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; 610 611 /** 612 * @brief Checks Whether the specified users is allowed to publish notifications. 613 * 614 * @param userId Identifies the user's id. 615 * @param allowed Identifies the allowed flag. 616 * @return Returns ERR_OK on success, others on failure. 617 */ 618 virtual ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override; 619 620 /** 621 * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must 622 * have system permissions to call this method. 623 * 624 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only 625 * be null or an empty string, indicating the current device. 626 * @param enabled Specifies whether to allow all applications to publish notifications. The value true 627 * indicates that notifications are allowed, and the value false indicates that notifications 628 * are not allowed. 629 * @return Returns ERR_OK on success, others on failure. 630 */ 631 virtual ErrCode SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) override; 632 633 /** 634 * @brief Delete all notifications by user. 635 * 636 * @param userId Indicates the user id. 637 * @return Returns ERR_OK on success, others on failure. 638 */ 639 virtual ErrCode DeleteAllByUser(const int32_t &userId) override; 640 641 /** 642 * @brief Set do not disturb date by user. 643 * 644 * @param userId Indicates the user id. 645 * @param date Indicates NotificationDoNotDisturbDate object. 646 * @return Returns ERR_OK on success, others on failure. 647 */ 648 virtual ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date) override; 649 650 /** 651 * @brief Get the do not disturb date by user. 652 * 653 * @param userId Indicates the user id. 654 * @param date Indicates the NotificationDoNotDisturbDate object. 655 * @return Returns ERR_OK on success, others on failure. 656 */ 657 virtual ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date) override; 658 virtual ErrCode SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption, 659 const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; 660 virtual ErrCode GetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption, 661 const NotificationConstant::SlotType &slotType, bool &enabled) override; 662 virtual ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; 663 664 /** 665 * @brief Obtains specific datas via specified dump option. 666 * 667 * @param cmd Indicates the specified dump command. 668 * @param bundle Indicates the specified bundle name. 669 * @param userId Indicates the specified userId. 670 * @param dumpInfo Indicates the container containing datas. 671 * @return Returns check result. 672 */ 673 virtual ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, 674 std::vector<std::string> &dumpInfo) override; 675 676 /** 677 * @brief Set whether to sync notifications to devices that do not have the app installed. 678 * 679 * @param userId Indicates the specific user. 680 * @param enabled Allow or disallow sync notifications. 681 * @return Returns set enabled result. 682 */ 683 virtual ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override; 684 685 /** 686 * @brief Obtains whether to sync notifications to devices that do not have the app installed. 687 * 688 * @param userId Indicates the specific user. 689 * @param enabled Allow or disallow sync notifications. 690 * @return Returns get enabled result. 691 */ 692 virtual ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override; 693 694 /** 695 * @brief Set badge number. 696 * 697 * @param badgeNumber The badge number. 698 * @return Returns set badge number result. 699 */ 700 virtual ErrCode SetBadgeNumber(int32_t badgeNumber) override; 701 702 /** 703 * @brief Get slotFlags. 704 * 705 * @param badgeNumber The slotFlags. 706 * @return Returns get slotFlags result. 707 */ 708 virtual ErrCode GetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, 709 uint32_t &slotFlags) override; 710 711 /** 712 * @brief Set slotFlags. 713 * 714 * @param badgeNumber The slotFlags. 715 * @return Returns set slotFlags result. 716 */ 717 virtual ErrCode SetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, 718 uint32_t slotFlags) override; 719 720 /** 721 * @brief Register Push Callback. 722 * 723 * @param pushCallback PushCallBack. 724 * @param notificationCheckRequest Filter conditions for push check 725 * @return Returns register PushCallback result. 726 */ 727 ErrCode RegisterPushCallback(const sptr<IRemoteObject>& pushCallback, 728 const sptr<NotificationCheckRequest>& notificationCheckRequest) override; 729 730 /** 731 * @brief Unregister Push Callback. 732 * 733 * @return Returns unregister push Callback result. 734 */ 735 ErrCode UnregisterPushCallback() override; 736 737 private: 738 static const std::map<NotificationInterfaceCode, std::function<ErrCode(AnsManagerStub *, MessageParcel &, MessageParcel &)>> 739 interfaces_; 740 741 ErrCode HandlePublish(MessageParcel &data, MessageParcel &reply); 742 ErrCode HandleCancel(MessageParcel &data, MessageParcel &reply); 743 ErrCode HandleCancelAll(MessageParcel &data, MessageParcel &reply); 744 ErrCode HandleCancelAsBundle(MessageParcel &data, MessageParcel &reply); 745 ErrCode HandleAddSlotByType(MessageParcel &data, MessageParcel &reply); 746 ErrCode HandleAddSlots(MessageParcel &data, MessageParcel &reply); 747 ErrCode HandleRemoveSlotByType(MessageParcel &data, MessageParcel &reply); 748 ErrCode HandleRemoveAllSlots(MessageParcel &data, MessageParcel &reply); 749 ErrCode HandleGetSlots(MessageParcel &data, MessageParcel &reply); 750 ErrCode HandleGetSlotByType(MessageParcel &data, MessageParcel &reply); 751 ErrCode HandleGetSlotNumAsBundle(MessageParcel &data, MessageParcel &reply); 752 ErrCode HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply); 753 ErrCode HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply); 754 ErrCode HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply); 755 ErrCode HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply); 756 ErrCode HandleGetActiveNotificationByFilter(MessageParcel &data, MessageParcel &reply); 757 ErrCode HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply); 758 ErrCode HandleGetNotificationAgent(MessageParcel &data, MessageParcel &reply); 759 ErrCode HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply); 760 ErrCode HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply); 761 ErrCode HandleSetNotificationBadgeNum(MessageParcel &data, MessageParcel &reply); 762 ErrCode HandleGetBundleImportance(MessageParcel &data, MessageParcel &reply); 763 ErrCode HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply); 764 ErrCode HandleRemoveNotification(MessageParcel &data, MessageParcel &reply); 765 ErrCode HandleRemoveAllNotifications(MessageParcel &data, MessageParcel &reply); 766 ErrCode HandleRemoveNotifications(MessageParcel &data, MessageParcel &reply); 767 ErrCode HandleDelete(MessageParcel &data, MessageParcel &reply); 768 ErrCode HandleDeleteByBundle(MessageParcel &data, MessageParcel &reply); 769 ErrCode HandleDeleteAll(MessageParcel &data, MessageParcel &reply); 770 ErrCode HandleGetSlotsByBundle(MessageParcel &data, MessageParcel &reply); 771 ErrCode HandleUpdateSlots(MessageParcel &data, MessageParcel &reply); 772 ErrCode HandleRequestEnableNotification(MessageParcel &data, MessageParcel &reply); 773 ErrCode HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply); 774 ErrCode HandleSetNotificationsEnabledForAllBundles(MessageParcel &data, MessageParcel &reply); 775 ErrCode HandleSetNotificationsEnabledForSpecialBundle(MessageParcel &data, MessageParcel &reply); 776 ErrCode HandleSetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply); 777 ErrCode HandleGetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply); 778 ErrCode HandleGetShowBadgeEnabled(MessageParcel &data, MessageParcel &reply); 779 ErrCode HandleSubscribe(MessageParcel &data, MessageParcel &reply); 780 ErrCode HandleUnsubscribe(MessageParcel &data, MessageParcel &reply); 781 ErrCode HandleIsAllowedNotify(MessageParcel &data, MessageParcel &reply); 782 ErrCode HandleIsAllowedNotifySelf(MessageParcel &data, MessageParcel &reply); 783 ErrCode HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply); 784 ErrCode HandleIsDistributedEnabled(MessageParcel &data, MessageParcel &reply); 785 ErrCode HandleEnableDistributed(MessageParcel &data, MessageParcel &reply); 786 ErrCode HandleEnableDistributedByBundle(MessageParcel &data, MessageParcel &reply); 787 ErrCode HandleEnableDistributedSelf(MessageParcel &data, MessageParcel &reply); 788 ErrCode HandleIsDistributedEnableByBundle(MessageParcel &data, MessageParcel &reply); 789 ErrCode HandleShellDump(MessageParcel &data, MessageParcel &reply); 790 ErrCode HandleCancelGroup(MessageParcel &data, MessageParcel &reply); 791 ErrCode HandleRemoveGroupByBundle(MessageParcel &data, MessageParcel &reply); 792 ErrCode HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); 793 ErrCode HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); 794 ErrCode HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply); 795 ErrCode HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply); 796 ErrCode HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); 797 ErrCode HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); 798 ErrCode HandlePublishReminder(MessageParcel &data, MessageParcel &reply); 799 ErrCode HandleCancelReminder(MessageParcel &data, MessageParcel &reply); 800 ErrCode HandleGetValidReminders(MessageParcel &data, MessageParcel &reply); 801 ErrCode HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply); 802 ErrCode HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply); 803 ErrCode HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply); 804 ErrCode HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply); 805 ErrCode HandleDeleteAllByUser(MessageParcel &data, MessageParcel &reply); 806 ErrCode HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply); 807 ErrCode HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply); 808 ErrCode HandleSetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); 809 ErrCode HandleGetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); 810 ErrCode HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply); 811 ErrCode HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply); 812 ErrCode HandleDistributedGetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply); 813 ErrCode HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply); 814 ErrCode HandleRegisterPushCallback(MessageParcel &data, MessageParcel &reply); 815 ErrCode HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply); 816 ErrCode HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply); 817 ErrCode HandleTriggerLocalLiveView(MessageParcel &data, MessageParcel &reply); 818 ErrCode HandleSubscribeSelf(MessageParcel &data, MessageParcel &reply); 819 ErrCode HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply); 820 ErrCode HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply); 821 template<typename T> WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & reply,ErrCode & result)822 bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &reply, ErrCode &result) 823 { 824 if (!reply.WriteInt32(result)) { 825 ANS_LOGE("write result failed, ErrCode=%{public}d", result); 826 return false; 827 } 828 829 if (!reply.WriteInt32(parcelableVector.size())) { 830 ANS_LOGE("write ParcelableVector size failed"); 831 return false; 832 } 833 834 for (auto &parcelable : parcelableVector) { 835 if (!reply.WriteStrongParcelable(parcelable)) { 836 ANS_LOGE("write ParcelableVector failed"); 837 return false; 838 } 839 } 840 return true; 841 } 842 843 template<typename T> ReadParcelableVector(std::vector<sptr<T>> & parcelableInfos,MessageParcel & data)844 bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &data) 845 { 846 int32_t infoSize = 0; 847 if (!data.ReadInt32(infoSize)) { 848 ANS_LOGE("Failed to read Parcelable size."); 849 return false; 850 } 851 852 parcelableInfos.clear(); 853 infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; 854 for (int32_t index = 0; index < infoSize; index++) { 855 sptr<T> info = data.ReadStrongParcelable<T>(); 856 if (info == nullptr) { 857 ANS_LOGE("Failed to read Parcelable infos."); 858 return false; 859 } 860 parcelableInfos.emplace_back(info); 861 } 862 863 return true; 864 } 865 }; 866 } // namespace Notification 867 } // namespace OHOS 868 869 #endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_STUB_H 870