1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_ADVANCED_NOTIFICATION_SERVICE_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_ADVANCED_NOTIFICATION_SERVICE_H 18 19 #include <ctime> 20 #include <list> 21 #include <memory> 22 #include <mutex> 23 #include <set> 24 25 #include "event_handler.h" 26 #include "event_runner.h" 27 #include "ffrt.h" 28 #include "refbase.h" 29 30 #include "ans_const_define.h" 31 #include "ans_manager_stub.h" 32 #include "common_notification_publish_process.h" 33 #include "distributed_kv_data_manager.h" 34 #include "distributed_kvstore_death_recipient.h" 35 #include "live_publish_process.h" 36 #include "notification.h" 37 #include "notification_bundle_option.h" 38 #include "notification_dialog_manager.h" 39 #include "notification_do_not_disturb_profile.h" 40 #include "notification_record.h" 41 #include "notification_slot_filter.h" 42 #include "notification_sorting_map.h" 43 #include "permission_filter.h" 44 #include "push_callback_interface.h" 45 #include "system_event_observer.h" 46 #include "notification_subscriber_manager.h" 47 #include "distributed_device_status.h" 48 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED 49 #include "reminder_swing_decision_center.h" 50 #endif 51 #include "notification_clone_bundle_info.h" 52 53 namespace OHOS { 54 namespace Notification { 55 56 static const uint32_t DEFAULT_SLOT_FLAGS = 59; // 0b111011 57 class AdvancedNotificationService final : public AnsManagerStub { 58 public: 59 struct NotificationRequestDb { 60 sptr<NotificationRequest> request {nullptr}; 61 sptr<NotificationBundleOption> bundleOption {nullptr}; 62 }; 63 64 struct RecentNotification { 65 sptr<Notification> notification = nullptr; 66 bool isActive = false; 67 int32_t deleteReason = 0; 68 int64_t deleteTime = 0; 69 }; 70 71 ~AdvancedNotificationService() override; 72 73 DISALLOW_COPY_AND_MOVE(AdvancedNotificationService); 74 75 /** 76 * @brief Get the instance of service. 77 * 78 * @return Returns the instance. 79 */ 80 static sptr<AdvancedNotificationService> GetInstance(); 81 82 static std::map<std::string, uint32_t>& GetDefaultSlotConfig(); 83 84 void SelfClean(); 85 86 /** 87 * @brief Get notification_svr_queue of service. 88 * 89 * @return Returns the queue. 90 */ 91 std::shared_ptr<ffrt::queue> GetNotificationSvrQueue(); 92 93 // AnsManagerStub 94 95 /** 96 * @brief Publishes a notification with a specified label. 97 * @note If a notification with the same ID has been published by the current application and has not been deleted, 98 * this method will update the notification. 99 * 100 * @param label Indicates the label of the notification to publish. 101 * @param notification Indicates the NotificationRequest object for setting the notification content. 102 * This parameter must be specified. 103 * @return Returns ERR_OK on success, others on failure. 104 */ 105 ErrCode Publish(const std::string &label, const sptr<NotificationRequest> &request) override; 106 107 /** 108 * @brief Publishes a notification. 109 * @note If a notification with the same ID has been published by the current application and has not been deleted, 110 * this method will update the notification. 111 * 112 * @param notification Indicates the NotificationRequest object for setting the notification content. 113 * This parameter must be specified. 114 * @return Returns ERR_OK on success, others on failure. 115 */ 116 ErrCode PublishNotificationForIndirectProxy(const sptr<NotificationRequest> &request) override; 117 118 /** 119 * @brief Cancels a published notification matching the specified label and notificationId. 120 * 121 * @param notificationId Indicates the ID of the notification to cancel. 122 * @param label Indicates the label of the notification to cancel. 123 * @param instanceKey Indicates the application instance key. 124 * @return Returns cancel notification result. 125 */ 126 ErrCode Cancel(int32_t notificationId, const std::string &label, const std::string &instanceKey) override; 127 128 /** 129 * @brief Cancels all the published notifications. 130 * 131 * @param instanceKey Indicates the application instance key. 132 * @return Returns ERR_OK on success, others on failure. 133 */ 134 ErrCode CancelAll(const std::string &instanceKey) override; 135 136 /** 137 * @brief Cancels a published agent notification. 138 * 139 * @param notificationId Indicates the unique notification ID in the application. 140 * The value must be the ID of a published notification. 141 * Otherwise, this method does not take effect. 142 * @param representativeBundle Indicates the name of application bundle your application is representing. 143 * @param userId Indicates the specific user. 144 * @return Returns cancel notification result. 145 */ 146 ErrCode CancelAsBundle( 147 int32_t notificationId, const std::string &representativeBundle, int32_t userId) override; 148 149 /** 150 * @brief Cancels a published agent notification. 151 * 152 * @param bundleOption Indicates the bundle of application bundle your application is representing. 153 * @param notificationId Indicates the unique notification ID in the application. 154 * The value must be the ID of a published notification. 155 * Otherwise, this method does not take effect. 156 * @return Returns cancel notification result. 157 */ 158 ErrCode CancelAsBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId) override; 159 160 /** 161 * @brief Cancels a published agent notification. 162 * 163 * @param bundleOption Indicates the bundle of application bundle your application is representing. 164 * @param notificationId Indicates the unique notification ID in the application. 165 * The value must be the ID of a published notification. 166 * Otherwise, this method does not take effect. 167 * @param userId Indicates the specific user. 168 * @return Returns cancel notification result. 169 */ 170 ErrCode CancelAsBundle( 171 const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, int32_t userId) override; 172 173 /** 174 * @brief Adds a notification slot by type. 175 * 176 * @param slotType Indicates the notification slot type to be added. 177 * @return Returns ERR_OK on success, others on failure. 178 */ 179 ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override; 180 181 /** 182 * @brief Creates multiple notification slots. 183 * 184 * @param slots Indicates the notification slots to create. 185 * @return Returns ERR_OK on success, others on failure. 186 */ 187 ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override; 188 189 /** 190 * @brief Deletes a created notification slot based on the slot ID. 191 * 192 * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot 193 * This parameter must be specified. 194 * @return Returns ERR_OK on success, others on failure. 195 */ 196 ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override; 197 198 /** 199 * @brief Deletes all notification slots. 200 * 201 * @return Returns ERR_OK on success, others on failure. 202 */ 203 ErrCode RemoveAllSlots() override; 204 205 /** 206 * @brief Queries a created notification slot. 207 * 208 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This 209 * parameter must be specified. 210 * @param slot Indicates the created NotificationSlot. 211 * @return Returns ERR_OK on success, others on failure. 212 */ 213 ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot) override; 214 215 /** 216 * @brief Obtains all notification slots of this application. 217 * 218 * @param slots Indicates the created NotificationSlot. 219 * @return Returns ERR_OK on success, others on failure. 220 */ 221 ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override; 222 223 /** 224 * @brief Obtains the number of slot. 225 * 226 * @param bundleOption Indicates the bundle name and uid of the application. 227 * @param num Indicates the number of slot. 228 * @return Returns ERR_OK on success, others on failure. 229 */ 230 ErrCode GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num) override; 231 232 /** 233 * @brief Obtains active notifications of the current application in the system. 234 * 235 * @param notifications Indicates active NotificationRequest objects of the current application. 236 * @param instanceKey Indicates the application instance key. 237 * @return Returns ERR_OK on success, others on failure. 238 */ 239 ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications, 240 const std::string &instanceKey) override; 241 242 /** 243 * @brief Obtains the number of active notifications of the current application in the system. 244 * 245 * @param num Indicates the number of active notifications of the current application. 246 * @return Returns ERR_OK on success, others on failure. 247 */ 248 ErrCode GetActiveNotificationNums(uint64_t &num) override; 249 250 /** 251 * @brief Obtains all active notifications in the current system. The caller must have system permissions to 252 * call this method. 253 * 254 * @param notifications Indicates all active notifications of this application. 255 * @return Returns ERR_OK on success, others on failure. 256 */ 257 ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications) override; 258 259 /** 260 * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method 261 * to obtain particular active notifications, you must have received the notifications and obtained the key 262 * via {Notification::GetKey()}. 263 * 264 * @param key Indicates the key array for querying corresponding active notifications. 265 * If this parameter is null, this method returns all active notifications in the system. 266 * @param notification Indicates the set of active notifications corresponding to the specified key. 267 * @return Returns ERR_OK on success, others on failure. 268 */ 269 ErrCode GetSpecialActiveNotifications( 270 const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications) override; 271 272 ErrCode GetActiveNotificationByFilter( 273 const sptr<NotificationBundleOption> &bundleOption, const int32_t notificationId, const std::string &label, 274 const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &request) override; 275 276 /** 277 * @brief Allows another application to act as an agent to publish notifications in the name of your application 278 * bundle. 279 * 280 * @param agent Indicates the name of the application bundle that can publish notifications for your application. 281 * @return Returns ERR_OK on success, others on failure. 282 */ 283 ErrCode SetNotificationAgent(const std::string &agent) override; 284 285 /** 286 * @brief Obtains the name of the application bundle that can publish notifications in the name of your application. 287 * 288 * @param agent Indicates the name of the application bundle that can publish notifications for your application if 289 * any; returns null otherwise. 290 * @return Returns ERR_OK on success, others on failure. 291 */ 292 ErrCode GetNotificationAgent(std::string &agent) override; 293 294 /** 295 * @brief Checks whether your application has permission to publish notifications by calling 296 * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the 297 * given representativeBundle. 298 * 299 * @param representativeBundle Indicates the name of application bundle your application is representing. 300 * @param canPublish Indicates whether your application has permission to publish notifications. 301 * @return Returns ERR_OK on success, others on failure. 302 */ 303 ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override; 304 305 /** 306 * @brief Publishes a notification in the name of a specified application bundle. 307 * @note If the notification to be published has the same ID as a published notification that has not been canceled, 308 * the existing notification will be replaced by the new one. 309 * 310 * @param notification Indicates the NotificationRequest object for setting the notification content. 311 * This parameter must be specified. 312 * @param representativeBundle Indicates the name of the application bundle that allows your application to publish 313 * notifications for it by calling setNotificationAgent. 314 * @return Returns ERR_OK on success, others on failure. 315 */ 316 ErrCode PublishAsBundle( 317 const sptr<NotificationRequest> notification, const std::string &representativeBundle) override; 318 319 /** 320 * @brief Sets the number of active notifications of the current application as the number to be displayed on the 321 * notification badge. 322 * 323 * @param num Indicates the badge number. 324 * @return Returns ERR_OK on success, others on failure. 325 */ 326 ErrCode SetNotificationBadgeNum(int32_t num) override; 327 328 /** 329 * @brief Obtains the importance level of this application. 330 * 331 * @param importance Indicates the importance level of this application, which can be LEVEL_NONE, 332 LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED. 333 * @return Returns ERR_OK on success, others on failure. 334 */ 335 ErrCode GetBundleImportance(int32_t &importance) override; 336 337 /** 338 * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. 339 * 340 * @param granted True if the application has permission; false for otherwise. 341 * @return Returns ERR_OK on success, others on failure. 342 */ 343 ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; 344 345 /** 346 * @brief Trigger the local live view after the button has been clicked. 347 * @note Your application must have platform signature to use this method. 348 * 349 * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. 350 * @param notificationId Indicates the id of the notification. 351 * @param buttonOption Indicates which button has been clicked. 352 * @return Returns trigger localLiveView result. 353 */ 354 ErrCode TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption, 355 const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption) override; 356 357 /** 358 * @brief Delete notification. 359 * 360 * @param bundleOption Indicates the NotificationBundleOption of the notification. 361 * @param notificationId Indicates the id of the notification. 362 * @param label Indicates the label of the notification. 363 * @param removeReason Indicates the reason of remove notification. 364 * @return Returns ERR_OK on success, others on failure. 365 */ 366 ErrCode RemoveNotification(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, 367 const std::string &label, int32_t removeReason) override; 368 369 /** 370 * @brief Delete all notifications. 371 * 372 * @param bundleOption Indicates the NotificationBundleOption of notifications. 373 * @return Returns ERR_OK on success, others on failure. 374 */ 375 ErrCode RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption) override; 376 377 ErrCode RemoveAllNotificationsForDisable(const sptr<NotificationBundleOption> &bundleOption); 378 379 ErrCode RemoveNotifications(const std::vector<std::string> &keys, int32_t removeReason) override; 380 381 ErrCode GetUnifiedGroupInfoFromDb(std::string &enable); 382 383 /** 384 * @brief Delete notification based on key. 385 * 386 * @param key Indicates the key to delete notification. 387 * @param removeReason Indicates the reason of remove notification. 388 * @return Returns ERR_OK on success, others on failure. 389 */ 390 ErrCode Delete(const std::string &key, int32_t removeReason) override; 391 392 /** 393 * @brief Remove notifications based on bundle. 394 * 395 * @param bundleOption Indicates the NotificationBundleOption of notifications. 396 * @return Returns ERR_OK on success, others on failure. 397 */ 398 ErrCode DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption) override; 399 400 /** 401 * @brief Remove all notifications. 402 * 403 * @return Returns ERR_OK on success, others on failure. 404 */ 405 ErrCode DeleteAll() override; 406 407 /** 408 * @brief Get all the slots corresponding to the bundle. 409 * 410 * @param bundleOption Indicates the NotificationBundleOption object. 411 * @param slots Indicates the notification slots. 412 * @return Returns ERR_OK on success, others on failure. 413 */ 414 ErrCode GetSlotsByBundle( 415 const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots) override; 416 417 /** 418 * @brief Get the specified slot corresponding to the bundle. 419 * 420 * @param bundleOption Indicates the NotificationBundleOption object. 421 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This 422 * parameter must be specified. 423 * @param slot Indicates the notification slot. 424 * @return Returns ERR_OK on success, others on failure. 425 */ 426 ErrCode GetSlotByBundle( 427 const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType, 428 sptr<NotificationSlot> &slot) override; 429 430 /** 431 * @brief Update slots according to bundle. 432 * 433 * @param bundleOption Indicates the NotificationBundleOption object. 434 * @param slots Indicates the notification slots to be updated. 435 * @return Returns ERR_OK on success, others on failure. 436 */ 437 ErrCode UpdateSlots( 438 const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots) override; 439 440 /** 441 * @brief Allow notifications to be sent based on the deviceId. 442 * 443 * @param deviceId Indicates the device Id. 444 * @return Returns ERR_OK on success, others on failure. 445 */ 446 ErrCode RequestEnableNotification(const std::string &deviceId, 447 const sptr<AnsDialogCallback> &callback, 448 const sptr<IRemoteObject> &callerToken) override; 449 450 /** 451 * @brief Set whether to allow the specified deviceId to send notifications for current bundle. 452 * 453 * @param deviceId Indicates the device Id. 454 * @param enabled Indicates the flag that allows notification to be pulished. 455 * @return Returns ERR_OK on success, others on failure. 456 */ 457 ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override; 458 459 /** 460 * @brief Set whether to allow the specified deviceId to send notifications for all bundles. 461 * 462 * @param deviceId Indicates the device Id. 463 * @param enabled Indicates the flag that allows notification to be pulished. 464 * @return Returns ERR_OK on success, others on failure. 465 */ 466 ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override; 467 468 /** 469 * @brief Set whether to allow the specified bundle to send notifications. 470 * 471 * @param bundleOption Indicates the NotificationBundleOption object. 472 * @param enabled Indicates the flag that allows notification to be pulished. 473 * @return Returns ERR_OK on success, others on failure. 474 */ 475 ErrCode SetNotificationsEnabledForSpecialBundle( 476 const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 477 478 /** 479 * @brief Sets whether the bundle allows the banner to display notification. 480 * 481 * @param bundleOption Indicates the NotificationBundleOption object. 482 * @param enabled Indicates the flag that allows badge to be shown. 483 * @return Returns ERR_OK on success, others on failure. 484 */ 485 ErrCode SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 486 487 /** 488 * @brief Gets whether the bundle allows the badge to display the status of notifications. 489 * 490 * @param bundleOption Indicates the NotificationBundleOption object. 491 * @param enabled Indicates the flag that allows badge to be shown. 492 * @return Returns ERR_OK on success, others on failure. 493 */ 494 ErrCode GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override; 495 496 /** 497 * @brief Gets whether allows the badge to display the status of notifications. 498 * 499 * @param enabled Indicates the flag that allows badge to be shown. 500 * @return Returns ERR_OK on success, others on failure. 501 */ 502 ErrCode GetShowBadgeEnabled(bool &enabled) override; 503 504 /** 505 * @brief Subscribes notifications. 506 * 507 * @param subscriber Indicates the subscriber. 508 * @param info Indicates the NotificationSubscribeInfo object. 509 * @return Returns ERR_OK on success, others on failure. 510 */ 511 ErrCode Subscribe(const sptr<AnsSubscriberInterface> &subscriber, 512 const sptr<NotificationSubscribeInfo> &info) override; 513 514 /** 515 * @brief Subscribes notifications self. 516 * 517 * @param subscriber Indicates the subscriber. 518 * @return Returns ERR_OK on success, others on failure. 519 */ 520 ErrCode SubscribeSelf(const sptr<AnsSubscriberInterface> &subscriber) override; 521 522 /** 523 * @brief Subscribes notifications. 524 * 525 * @param subscriber Indicates the subscriber. 526 * @param info Indicates the NotificationSubscribeInfo object. 527 * @return Returns ERR_OK on success, others on failure. 528 */ 529 ErrCode SubscribeLocalLiveView(const sptr<AnsSubscriberLocalLiveViewInterface> &subscriber, 530 const sptr<NotificationSubscribeInfo> &info, const bool isNative) override; 531 532 /** 533 * @brief Unsubscribes notifications. 534 * 535 * @param subscriber Indicates the subscriber. 536 * @param info Indicates the NotificationSubscribeInfo object. 537 * @return Returns ERR_OK on success, others on failure. 538 */ 539 ErrCode Unsubscribe(const sptr<AnsSubscriberInterface> &subscriber, 540 const sptr<NotificationSubscribeInfo> &info) override; 541 542 /** 543 * @brief Checks whether this device is allowed to publish notifications. 544 * 545 * @param allowed Indicates the flag that allows notification. 546 * @return Returns ERR_OK on success, others on failure. 547 */ 548 ErrCode IsAllowedNotify(bool &allowed) override; 549 550 /** 551 * @brief Checks whether this application is allowed to publish notifications. 552 * 553 * @param allowed Indicates the flag that allows notification. 554 * @return Returns ERR_OK on success, others on failure. 555 */ 556 ErrCode IsAllowedNotifySelf(bool &allowed) override; 557 558 /** 559 * @brief Checks whether this application can pop enable notification dialog. 560 * 561 * @param canPop True if can pop enable notification dialog 562 * @return Returns is canPop result. 563 */ 564 ErrCode CanPopEnableNotificationDialog(const sptr<AnsDialogCallback> &callback, 565 bool &canPop, std::string &bundleName) override; 566 567 /** 568 * @brief remove enable notification dialog. 569 * 570 * @return Returns remove dialog result. 571 */ 572 ErrCode RemoveEnableNotificationDialog() override; 573 574 ErrCode RemoveEnableNotificationDialog(const sptr<NotificationBundleOption> &bundleOption); 575 576 /** 577 * @brief Checks whether notifications are allowed for a specific bundle. 578 * 579 * @param bundleOption Indicates the NotificationBundleOption object. 580 * @param allowed Indicates the flag that allows notification. 581 * @return Returns ERR_OK on success, others on failure. 582 */ 583 ErrCode IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed) override; 584 585 /** 586 * @brief Set do not disturb date. 587 * 588 * @param date Indicates the NotificationDoNotDisturbDate object. 589 * @return Returns ERR_OK on success, others on failure. 590 */ 591 ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date) override; 592 593 /** 594 * @brief Get do not disturb date. 595 * 596 * @param date Indicates the NotificationDoNotDisturbDate object. 597 * @return Returns ERR_OK on success, others on failure. 598 */ 599 ErrCode GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date) override; 600 601 /** 602 * @brief Add Do Not Disturb profiles. 603 * 604 * @param profiles Indicates the list of NotificationDoNotDisturbProfile objects to add. 605 * @return Returns ERR_OK on success, others on failure. 606 */ 607 ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override; 608 609 /** 610 * @brief Remove Do Not Disturb profiles. 611 * 612 * @param profiles Indicates the list of NotificationDoNotDisturbProfile objects to remove. 613 * @return Returns ERR_OK on success, others on failure. 614 */ 615 ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override; 616 617 /** 618 * @brief Get whether Do Not Disturb mode is supported. 619 * 620 * @param doesSupport Indicates the flag that supports DND mode. 621 * @return Returns ERR_OK on success, others on failure. 622 */ 623 ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override; 624 625 /** 626 * @brief Is coming call need silent in do not disturb mode. 627 * 628 * @param phoneNumber the calling format number. 629 * @return Returns silent in do not disturb mode. 630 */ 631 ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override; 632 633 /** 634 * @brief Cancel notifications according to group. 635 * 636 * @param groupName Indicates the group name. 637 * @param instanceKey Indicates the application instance key. 638 * @return Returns ERR_OK on success, others on failure. 639 */ 640 ErrCode CancelGroup(const std::string &groupName, const std::string &instanceKey) override; 641 642 /** 643 * @brief Delete notifications according to bundle and group. 644 * 645 * @param bundleOption Indicates the NotificationBundleOption object. 646 * @param groupName Indicates the group name. 647 * @return Returns ERR_OK on success, others on failure. 648 */ 649 ErrCode RemoveGroupByBundle( 650 const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName) override; 651 652 /** 653 * @brief Gets whether distributed notification is enabled. 654 * 655 * @param enabled Indicates the enabled flag. 656 * @return Returns ERR_OK on success, others on failure. 657 */ 658 ErrCode IsDistributedEnabled(bool &enabled) override; 659 660 /** 661 * @brief Sets distributed notification enabled or disabled. 662 * 663 * @param enabled Indicates the enabled flag. 664 * @return Returns ERR_OK on success, others on failure. 665 */ 666 ErrCode EnableDistributed(bool enabled) override; 667 668 /** 669 * @brief Sets distributed notification enabled or disabled for specific bundle. 670 * 671 * @param bundleOption Indicates the NotificationBundleOption object. 672 * @param enabled Indicates the enabled flag. 673 * @return Returns ERR_OK on success, others on failure. 674 */ 675 ErrCode EnableDistributedByBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 676 677 /** 678 * @brief Sets distributed notification enabled or disabled for current bundle. 679 * 680 * @param enabled Indicates the enabled flag. 681 * @return Returns ERR_OK on success, others on failure. 682 */ 683 ErrCode EnableDistributedSelf(bool enabled) override; 684 685 /** 686 * @brief Gets whether distributed notification is enabled for specific bundle. 687 * 688 * @param bundleOption Indicates the NotificationBundleOption object. 689 * @param enabled Indicates the enabled flag. 690 * @return Returns ERR_OK on success, others on failure. 691 */ 692 ErrCode IsDistributedEnableByBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override; 693 694 /** 695 * @brief Get the reminder type of the current device. 696 * 697 * @param remindType Reminder type for the device. 698 * @return Returns ERR_OK on success, others on failure. 699 */ 700 ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override; 701 702 /** 703 * @brief Publishes a continuous notification. 704 * 705 * @param request Notification requests that need to be posted. 706 * @return Returns ERR_OK on success, others on failure. 707 */ 708 ErrCode PublishContinuousTaskNotification(const sptr<NotificationRequest> &request) override; 709 710 /** 711 * @brief Cancels a continuous notification. 712 * 713 * @param label Identifies the label of the specified notification. 714 * @param notificationId Identifies the id of the specified notification. 715 * @return Returns ERR_OK on success, others on failure. 716 */ 717 ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; 718 719 /** 720 * @brief Check reminder permission 721 */ 722 bool CheckReminderPermission(); 723 724 /** 725 * @brief Publishes a reminder notification. 726 * 727 * @param reminder Identifies the reminder notification request that needs to be published. 728 * @return Returns ERR_OK on success, others on failure. 729 */ 730 ErrCode PublishReminder(sptr<ReminderRequest> &reminder) override; 731 732 /** 733 * @brief Cancel a reminder notifications. 734 * 735 * @param reminderId Identifies the reminders id that needs to be canceled. 736 * @return Returns ERR_OK on success, others on failure. 737 */ 738 ErrCode CancelReminder(const int32_t reminderId) override; 739 740 /** 741 * @brief Get all valid reminder notifications. 742 * 743 * @param reminders Identifies the list of all valid notifications. 744 * @return Returns ERR_OK on success, others on failure. 745 */ 746 ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &reminders) override; 747 748 /** 749 * @brief Cancel all reminder notifications. 750 * 751 * @return Returns ERR_OK on success, others on failure. 752 */ 753 ErrCode CancelAllReminders() override; 754 755 /** 756 * @brief Add exclude date for reminder 757 * 758 * @param reminderId Identifies the reminders id. 759 * @param date exclude date 760 * @return Returns ERR_OK on success, others on failure. 761 */ 762 ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; 763 764 /** 765 * @brief Clear exclude date for reminder 766 * 767 * @param reminderId Identifies the reminders id. 768 * @return Returns ERR_OK on success, others on failure. 769 */ 770 ErrCode DelExcludeDates(const int32_t reminderId) override; 771 772 /** 773 * @brief Get exclude date for reminder 774 * 775 * @param reminderId Identifies the reminders id. 776 * @param dates exclude dates 777 * @return Returns ERR_OK on success, others on failure. 778 */ 779 ErrCode GetExcludeDates(const int32_t reminderId, std::vector<uint64_t>& dates) override; 780 781 /** 782 * @brief Checks whether this device is support template. 783 * 784 * @param templateName Identifies the template name for searching as a condition. 785 * @param support Identifies the support flag. 786 * @return Returns ERR_OK on success, others on failure. 787 */ 788 ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; 789 790 /** 791 * @brief Checks Whether the specified users is allowed to publish notifications. 792 * 793 * @param userId Identifies the user's id. 794 * @param allowed Identifies the allowed flag. 795 * @return Returns ERR_OK on success, others on failure. 796 */ 797 ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override; 798 799 /** 800 * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must 801 * have system permissions to call this method. 802 * 803 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only 804 * be null or an empty string, indicating the current device. 805 * @param enabled Specifies whether to allow all applications to publish notifications. The value true 806 * indicates that notifications are allowed, and the value false indicates that notifications 807 * are not allowed. 808 * @return Returns ERR_OK on success, others on failure. 809 */ 810 ErrCode SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) override; 811 812 /** 813 * @brief Delete all notifications by user. 814 * 815 * @param userId Indicates the user id. 816 * @return Returns ERR_OK on success, others on failure. 817 */ 818 ErrCode DeleteAllByUser(const int32_t &userId) override; 819 820 /** 821 * @brief Set do not disturb date by user. 822 * 823 * @param userId Indicates the user id. 824 * @param date Indicates NotificationDoNotDisturbDate object. 825 * @return Returns ERR_OK on success, others on failure. 826 */ 827 ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date) override; 828 829 /** 830 * @brief Get the do not disturb date by user. 831 * 832 * @param userId Indicates the user id. 833 * @param date Indicates the NotificationDoNotDisturbDate object. 834 * @return Returns ERR_OK on success, others on failure. 835 */ 836 ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date) override; 837 ErrCode SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption, 838 const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; 839 ErrCode GetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption, 840 const NotificationConstant::SlotType &slotType, bool &enabled) override; 841 ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; 842 843 // SystemEvent 844 845 /** 846 * @brief Obtains the event of bundle removed. 847 * 848 * @param bundleOption Indicates the bundle info. 849 */ 850 void OnBundleRemoved(const sptr<NotificationBundleOption> &bundleOption); 851 852 /** 853 * @brief Obtains the event of bundle batch removed. 854 * 855 * @param notifications Notification vector. 856 */ 857 void ExecBatchCancel(std::vector<sptr<Notification>> ¬ifications, int32_t &reason); 858 859 /** 860 * @brief Obtains the event of user removed. 861 * 862 * @param userId Indicates the user. 863 */ 864 void OnUserRemoved(const int32_t &userId); 865 866 /** 867 * @brief Set whether to sync notifications to devices that do not have the app installed. 868 * 869 * @param userId Indicates the specific user. 870 * @param enabled Allow or disallow sync notifications. 871 * @return Returns set enabled result. 872 */ 873 ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override; 874 875 /** 876 * @brief Obtains whether to sync notifications to devices that do not have the app installed. 877 * 878 * @param userId Indicates the specific user. 879 * @param enabled Allow or disallow sync notifications. 880 * @return Returns get enabled result. 881 */ 882 ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override; 883 884 /** 885 * @brief Obtains the number of slotFlags. 886 * 887 * @param bundleOption Indicates the bundle name and uid of the application. 888 * @param slot Indicates the specified slot object 889 * @param slotFlags Indicates the slogFlags of slot. 890 * @return Returns ERR_OK on success, others on failure. 891 */ 892 virtual ErrCode GetSlotFlagsAsBundle(const sptr<NotificationBundleOption>& bundleOption, 893 uint32_t &slotFlags) override; 894 895 /** 896 * @brief Set the slotFlags of slot. 897 * 898 * @param bundleOption Indicates the bundle name and uid of the application. 899 * @param slot Indicates the specified slot object 900 * @param slotFlags Indicates the slogFlags of slot to set. 901 * @return Returns ERR_OK on success, others on failure. 902 */ 903 virtual ErrCode SetSlotFlagsAsBundle(const sptr<NotificationBundleOption>& bundleOption, 904 uint32_t slotFlags) override; 905 906 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED 907 /** 908 * @brief Obtains the event of turn on screen. 909 */ 910 void OnScreenOn(); 911 912 /** 913 * @brief Obtains the event of turn off screen. 914 */ 915 void OnScreenOff(); 916 #endif 917 void OnResourceRemove(int32_t userId); 918 void OnBundleDataCleared(const sptr<NotificationBundleOption> &bundleOption); 919 920 /** 921 * @brief Obtains the event of bundle install. 922 * 923 * @param bundleOption Indicates the bundle info. 924 */ 925 void OnBundleDataAdd(const sptr<NotificationBundleOption> &bundleOption); 926 927 /** 928 * @brief Obtains the event of bundle update. 929 * 930 * @param bundleOption Indicates the bundle info. 931 */ 932 void OnBundleDataUpdate(const sptr<NotificationBundleOption> &bundleOption); 933 934 /** 935 * @brief Boot system completed event callback. 936 */ 937 void OnBootSystemCompleted(); 938 939 // Distributed KvStore 940 941 /** 942 * @brief Obtains the death event of the Distributed KvStore service. 943 */ 944 void OnDistributedKvStoreDeathRecipient(); 945 946 ErrCode CancelPreparedNotification(int32_t notificationId, const std::string &label, 947 const sptr<NotificationBundleOption> &bundleOption, const int32_t reason); 948 949 ErrCode PrepareNotificationInfo( 950 const sptr<NotificationRequest> &request, sptr<NotificationBundleOption> &bundleOption); 951 ErrCode PublishPreparedNotification(const sptr<NotificationRequest> &request, 952 const sptr<NotificationBundleOption> &bundleOption, bool isUpdateByOwner = false); 953 954 /** 955 * @brief Dump current running status for debuging. 956 * 957 * @param cmd Indicates the specified dump command. 958 * @param bundle Indicates the specified bundle name. 959 * @param userId Indicates the specified userId. 960 * @param dumpInfo Indicates the container containing datas. 961 * @return Returns ERR_OK on success, others on failure. 962 */ 963 ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, 964 std::vector<std::string> &dumpInfo) override; 965 966 /** 967 * @brief Set badge number. 968 * 969 * @param badgeNumber The badge number. 970 * @param instanceKey The application instance key. 971 * @return Returns set badge number result. 972 */ 973 ErrCode SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) override; 974 975 /** 976 * @brief Set badge number by bundle. 977 * 978 * @param bundleOption Indicates the bundle name and uid of the application. 979 * @param badgeNumber The badge number. 980 * @return Returns set badge number by bundle result. 981 */ 982 ErrCode SetBadgeNumberByBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override; 983 984 /** 985 * @brief Obtains allow notification application list. 986 * 987 * @param bundleOption Indicates the bundle bundleOption. 988 * @return Returns ERR_OK on success, others on failure. 989 */ 990 ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override; 991 992 /** 993 * @brief Register Push Callback. 994 * 995 * @param pushCallback PushCallBack. 996 * @param notificationCheckRequest Filter conditions for push check 997 * @return Returns register push Callback result. 998 */ 999 ErrCode RegisterPushCallback(const sptr<IRemoteObject>& pushCallback, 1000 const sptr<NotificationCheckRequest> ¬ificationCheckRequest) override; 1001 1002 /** 1003 * @brief Unregister Push Callback. 1004 * 1005 * @return Returns unregister push Callback result. 1006 */ 1007 ErrCode UnregisterPushCallback() override; 1008 1009 /** 1010 * @brief Sets whether to allow a specified application to publish notifications cross 1011 * device collaboration. The caller must have system permissions to call this method. 1012 * 1013 * @param bundleOption Indicates the bundle name and uid of the application. 1014 * @param deviceType Indicates the type of the device running the application. 1015 * @param enabled Specifies whether to allow the given application to publish notifications. The value 1016 * true indicates that notifications are allowed, and the value false indicates that 1017 * notifications are not allowed. 1018 * @return Returns set notifications enabled for specified bundle result. 1019 */ 1020 ErrCode SetDistributedEnabledByBundle(const sptr<NotificationBundleOption> &bundleOption, 1021 const std::string &deviceType, const bool enabled) override; 1022 1023 /* 1024 * @brief Get whether to allow a specified application to publish notifications cross 1025 * device collaboration. The caller must have system permissions to call this method. 1026 * 1027 * @param bundleOption Indicates the bundle name and uid of the application. 1028 * @param deviceType Indicates the type of the device running the application. 1029 * @param enabled Specifies whether to allow the given application to publish notifications. The value 1030 * true indicates that notifications are allowed, and the value false indicates that 1031 * notifications are not allowed. 1032 * @return Returns set notifications enabled for specified bundle result. 1033 */ 1034 ErrCode IsDistributedEnabledByBundle(const sptr<NotificationBundleOption> &bundleOption, 1035 const std::string &deviceType, bool &enabled) override; 1036 1037 /** 1038 * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders 1039 * 1040 * @param deviceType Indicates the type of the device running the application. 1041 * @param enabled Specifies whether to allow the given device to publish notifications. 1042 * The value true indicates that notifications are allowed, and the value 1043 * false indicates that notifications are not allowed. 1044 * @return Returns set notifications enabled for specified bundle result. 1045 */ 1046 ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override; 1047 1048 /** 1049 * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders 1050 * 1051 * @param deviceType Indicates the type of the device running the application. 1052 * @param enabled Specifies whether to allow the given device to publish notifications. 1053 * The value true indicates that notifications are allowed, and the value 1054 * false indicates that notifications are not allowed. 1055 * @return Returns set notifications enabled for specified bundle result. 1056 */ 1057 ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override; 1058 1059 /** 1060 * @brief Set the status of the target device. 1061 * 1062 * @param deviceType Type of the device whose status you want to set. 1063 * @param status The status. 1064 * @return Returns set result. 1065 */ 1066 ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) override; 1067 1068 /** 1069 * @brief clear notification when aggregate local switch close. 1070 */ 1071 void ClearAllNotificationGroupInfo(std::string localSwitch); 1072 1073 /** 1074 * @brief Reset pushcallback proxy 1075 */ 1076 void ResetPushCallbackProxy(); 1077 1078 /** 1079 * @brief Set the notification SlotFlags whitelist. 1080 */ 1081 void SetSlotFlagsTrustlistsAsBundle(const sptr<NotificationBundleOption> &bundleOption); 1082 1083 /** 1084 * @brief Init The Default Installation Package Notification Enabled. 1085 */ 1086 void InitNotificationEnableList(); 1087 /** 1088 * @brief Remove Local Live Notifications 1089 */ 1090 ErrCode RemoveSystemLiveViewNotifications(const std::string& bundleName, const int32_t uid); 1091 1092 /** 1093 * @brief Remove Local Live Notifications created by sa. 1094 */ 1095 ErrCode RemoveSystemLiveViewNotificationsOfSa(int32_t uid); 1096 1097 /** 1098 * @brief Set the notification flags by soltType. 1099 */ 1100 void SetRequestBySlotType(const sptr<NotificationRequest> &request, 1101 const sptr<NotificationBundleOption> &bundleOption); 1102 1103 // Might fail if ces subscribe failed, if failed, dialogManager_ will be set nullptr 1104 bool CreateDialogManager(); 1105 1106 /** 1107 * @brief Set agent relationship. 1108 * 1109 * @param key Indicates storing agent relationship if the value is "PROXY_PKG". 1110 * @param value Indicates key-value pair of agent relationship. 1111 * @return Returns set result. 1112 */ 1113 ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override; 1114 1115 /** 1116 * @brief Cancels a published agent notification. 1117 * 1118 * @param bundleOption Indicates the bundle name and uid of the application. 1119 * @param id Indicates the unique notification ID in the application. 1120 * @return Returns cancel result. 1121 */ 1122 ErrCode CancelAsBundleWithAgent(const sptr<NotificationBundleOption> &bundleOption, const int32_t id) override; 1123 1124 /** 1125 * @brief Init publish process. 1126 */ 1127 bool InitPublishProcess(); 1128 1129 /** 1130 * @brief Recover LiveView from DB. 1131 */ 1132 void RecoverLiveViewFromDb(int32_t userId = -1); 1133 1134 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED 1135 /** 1136 * @brief Register Swing Callback. 1137 * 1138 * @param swingCallback SwingCallBack. 1139 * @return Returns register swing Callback result. 1140 */ 1141 ErrCode RegisterSwingCallback(const sptr<IRemoteObject>& swingCallback) override; 1142 #endif 1143 1144 /** 1145 * @brief update unified group info. 1146 */ 1147 void UpdateUnifiedGroupInfo(const std::string &key, std::shared_ptr<NotificationUnifiedGroupInfo> &groupInfo); 1148 1149 /** 1150 * @brief Whether reminders are allowed. 1151 */ 1152 bool AllowUseReminder(const std::string& bundleName); 1153 1154 /** 1155 * @brief Get do not disturb profile by id. 1156 * 1157 * @param id Profile id. 1158 * @param status Indicates the NotificationDoNotDisturbProfile object. 1159 * @return Returns ERR_OK on success, others on failure. 1160 */ 1161 ErrCode GetDoNotDisturbProfile(int32_t id, sptr<NotificationDoNotDisturbProfile> &profile) override; 1162 1163 int32_t OnBackup(MessageParcel& data, MessageParcel& reply); 1164 1165 int32_t OnRestore(MessageParcel& data, MessageParcel& reply); 1166 1167 void ResetDistributedEnabled(); 1168 1169 void UpdateCloneBundleInfo(const NotificationCloneBundleInfo cloneBundleInfo); 1170 1171 /** 1172 * @brief Update notification timer by uid 1173 * 1174 * @param uid uid. 1175 * @param isPaused if paused 1176 * @return Returns ERR_OK on success, others on failure. 1177 */ 1178 ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override; 1179 1180 /** 1181 * @brief set rule of generate hashCode. 1182 * 1183 * @param type generate hashCode. 1184 * @return Returns ERR_OK on success, others on failure. 1185 */ 1186 ErrCode SetHashCodeRule(const uint32_t type) override; 1187 1188 protected: 1189 /** 1190 * @brief Query whether there is a agent relationship between the two apps. 1191 * 1192 * @param agentBundleName The bundleName of the agent app. 1193 * @param sourceBundleName The bundleName of the source app. 1194 * @return Returns true if There is an agent relationship; returns false otherwise. 1195 */ 1196 bool IsAgentRelationship(const std::string &agentBundleName, const std::string &sourceBundleName); 1197 1198 private: 1199 struct RecentInfo { 1200 std::list<std::shared_ptr<RecentNotification>> list; 1201 size_t recentCount = 16; 1202 }; 1203 1204 enum UploadStatus { 1205 CREATE, 1206 FIRST_UPDATE_TIME_OUT, 1207 CONTINUOUS_UPDATE_TIME_OUT, 1208 END, 1209 FINISH 1210 }; 1211 1212 struct SoundPermissionInfo { 1213 std::set<std::string> bundleName_; 1214 std::atomic<bool> needUpdateCache_ = true; 1215 bool allPackage_ = false; 1216 std::mutex dbMutex_; 1217 }; 1218 1219 enum ContactPolicy { 1220 FORBID_EVERYONE = 1, 1221 ALLOW_EVERYONE = 2, 1222 ALLOW_EXISTING_CONTACTS = 3, 1223 ALLOW_FAVORITE_CONTACTS = 4, 1224 ALLOW_SPECIFIED_CONTACTS = 5, 1225 }; 1226 1227 AdvancedNotificationService(); 1228 1229 void StartFilters(); 1230 void StopFilters(); 1231 ErrCode Filter(const std::shared_ptr<NotificationRecord> &record, bool isRecover = false); 1232 void ChangeNotificationByControlFlags(const std::shared_ptr<NotificationRecord> &record, 1233 const bool isAgentController); 1234 ErrCode CheckPublishPreparedNotification(const std::shared_ptr<NotificationRecord> &record, bool isSystemApp); 1235 void AddToNotificationList(const std::shared_ptr<NotificationRecord> &record); 1236 void AddToDelayNotificationList(const std::shared_ptr<NotificationRecord> &record); 1237 ErrCode UpdateInNotificationList(const std::shared_ptr<NotificationRecord> &record); 1238 void UpdateInDelayNotificationList(const std::shared_ptr<NotificationRecord> &record); 1239 ErrCode AssignToNotificationList(const std::shared_ptr<NotificationRecord> &record); 1240 ErrCode RemoveFromNotificationList(const sptr<NotificationBundleOption> &bundleOption, const std::string &label, 1241 int32_t notificationId, sptr<Notification> ¬ification, bool isCancel = false); 1242 ErrCode RemoveFromNotificationList(const std::string &key, sptr<Notification> ¬ification, 1243 bool isCancel, int32_t removeReason); 1244 ErrCode RemoveFromNotificationListForDeleteAll(const std::string &key, 1245 const int32_t &userId, sptr<Notification> ¬ification); 1246 bool RemoveFromDelayedNotificationList(const std::string &key); 1247 std::shared_ptr<NotificationRecord> GetFromNotificationList(const std::string &key); 1248 std::shared_ptr<NotificationRecord> GetFromNotificationList(const int32_t ownerUid, const int32_t notificationId); 1249 std::shared_ptr<NotificationRecord> GetFromDelayedNotificationList( 1250 const int32_t ownerUid, const int32_t notificationId); 1251 std::vector<std::string> GetNotificationKeys(const sptr<NotificationBundleOption> &bundleOption); 1252 std::vector<std::string> GetNotificationKeysByBundle(const sptr<NotificationBundleOption> &bundleOption); 1253 bool IsNotificationExists(const std::string &key); 1254 void SortNotificationList(); 1255 static bool NotificationCompare( 1256 const std::shared_ptr<NotificationRecord> &first, const std::shared_ptr<NotificationRecord> &second); 1257 ErrCode PublishInNotificationList(const std::shared_ptr<NotificationRecord> &record); 1258 ErrCode RemoveNotificationBySlot(const sptr<NotificationBundleOption> &bundleOption, 1259 const sptr<NotificationSlot> &slot, const int reason); 1260 1261 sptr<NotificationSortingMap> GenerateSortingMap(); 1262 static sptr<NotificationBundleOption> GenerateBundleOption(); 1263 static sptr<NotificationBundleOption> GenerateValidBundleOption(const sptr<NotificationBundleOption> &bundleOption); 1264 1265 std::string TimeToString(int64_t time); 1266 int64_t GetNowSysTime(); 1267 ErrCode ActiveNotificationDump(const std::string& bundle, int32_t userId, int32_t recvUserId, 1268 std::vector<std::string> &dumpInfo); 1269 ErrCode RecentNotificationDump(const std::string& bundle, int32_t userId, int32_t recvUserId, 1270 std::vector<std::string> &dumpInfo); 1271 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED 1272 ErrCode DistributedNotificationDump(const std::string& bundle, int32_t userId, int32_t recvUserId, 1273 std::vector<std::string> &dumpInfo); 1274 #endif 1275 ErrCode SetRecentNotificationCount(const std::string arg); 1276 void UpdateRecentNotification(sptr<Notification> ¬ification, bool isDelete, int32_t reason); 1277 1278 void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate); 1279 ErrCode PrepareNotificationRequest(const sptr<NotificationRequest> &request); 1280 ErrCode PrepareContinuousTaskNotificationRequest(const sptr<NotificationRequest> &request, const int32_t &uid); 1281 1282 void TriggerRemoveWantAgent(const sptr<NotificationRequest> &request); 1283 bool CheckApiCompatibility(const sptr<NotificationBundleOption> &bundleOption); 1284 ErrCode IsAllowedNotifySelf(const sptr<NotificationBundleOption> &bundleOption, bool &allowed); 1285 1286 ErrCode SetNotificationRemindType(sptr<Notification> notification, bool isLocal); 1287 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED 1288 std::vector<std::string> GetLocalNotificationKeys(const sptr<NotificationBundleOption> &bundleOption); 1289 NotificationConstant::RemindType GetRemindType(); 1290 ErrCode DoDistributedPublish( 1291 const sptr<NotificationBundleOption> bundleOption, const std::shared_ptr<NotificationRecord> record); 1292 ErrCode DoDistributedDelete( 1293 const std::string deviceId, const std::string bundleName, const sptr<Notification> notification); 1294 void GetDistributedInfo(const std::string &key, std::string &deviceId, std::string &bundleName); 1295 bool CheckDistributedNotificationType(const sptr<NotificationRequest> &request); 1296 void OnDistributedPublish( 1297 const std::string &deviceId, const std::string &bundleName, sptr<NotificationRequest> &request); 1298 void OnDistributedUpdate( 1299 const std::string &deviceId, const std::string &bundleName, sptr<NotificationRequest> &request); 1300 void OnDistributedDelete( 1301 const std::string &deviceId, const std::string &bundleName, const std::string &label, int32_t id); 1302 static ErrCode GetDistributedEnableInApplicationInfo( 1303 const sptr<NotificationBundleOption> bundleOption, bool &enable); 1304 bool CheckPublishWithoutApp(const int32_t userId, const sptr<NotificationRequest> &request); 1305 void InitDistributeCallBack(); 1306 #endif 1307 1308 ErrCode SetDoNotDisturbDateByUser(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date); 1309 ErrCode GetDoNotDisturbDateByUser(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date); 1310 ErrCode GetHasPoppedDialog(const sptr<NotificationBundleOption> bundleOption, bool &hasPopped); 1311 static ErrCode GetAppTargetBundle(const sptr<NotificationBundleOption> &bundleOption, 1312 sptr<NotificationBundleOption> &targetBundle); 1313 bool PublishSlotChangeCommonEvent(const sptr<NotificationBundleOption> &bundleOption); 1314 void ReportInfoToResourceSchedule(const int32_t userId, const std::string &bundleName); 1315 int Dump(int fd, const std::vector<std::u16string> &args) override; 1316 void GetDumpInfo(const std::vector<std::u16string> &args, std::string &result); 1317 1318 static void SendSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr<NotificationSubscribeInfo> &info, 1319 ErrCode errCode); 1320 static void SendUnSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr<NotificationSubscribeInfo> &info); 1321 void SendPublishHiSysEvent(const sptr<NotificationRequest> &request, ErrCode errCode); 1322 void SendCancelHiSysEvent(int32_t notificationId, const std::string &label, 1323 const sptr<NotificationBundleOption> &bundleOption, ErrCode errCode); 1324 void SendRemoveHiSysEvent(int32_t notificationId, const std::string &label, 1325 const sptr<NotificationBundleOption> &bundleOption, ErrCode errCode); 1326 void SendEnableNotificationHiSysEvent(const sptr<NotificationBundleOption> &bundleOption, bool enabled, 1327 ErrCode errCode); 1328 void SendEnableNotificationSlotHiSysEvent(const sptr<NotificationBundleOption> &bundleOption, 1329 const NotificationConstant::SlotType &slotType, bool enabled, ErrCode errCode); 1330 void SendFlowControlOccurHiSysEvent(const std::shared_ptr<NotificationRecord> &record); 1331 void SendLiveViewUploadHiSysEvent(const std::shared_ptr<NotificationRecord> &record, int32_t uploadStatus); 1332 1333 ErrCode SetRequestBundleInfo(const sptr<NotificationRequest> &request, int32_t uid, std::string &bundle); 1334 ErrCode PrePublishNotificationBySa(const sptr<NotificationRequest> &request, int32_t uid, std::string &bundle); 1335 ErrCode PrePublishRequest(const sptr<NotificationRequest> &request); 1336 ErrCode PublishNotificationBySa(const sptr<NotificationRequest> &request); 1337 bool IsNeedPushCheck(const sptr<NotificationRequest> &request); 1338 void FillExtraInfoToJson(const sptr<NotificationRequest> &request, 1339 sptr<NotificationCheckRequest> &checkRequest, nlohmann::json &jsonObject); 1340 ErrCode PushCheck(const sptr<NotificationRequest> &request); 1341 uint64_t StartAutoDelete(const std::shared_ptr<NotificationRecord> &record, 1342 int64_t deleteTimePoint, int32_t reason); 1343 void TriggerAutoDelete(const std::string &hashCode, int32_t reason); 1344 void SendNotificationsOnCanceled(std::vector<sptr<Notification>> ¬ifications, 1345 const sptr<NotificationSortingMap> ¬ificationMap, int32_t deleteReason); 1346 void SetAgentNotification(sptr<NotificationRequest>& notificationRequest, std::string& bundleName); 1347 ErrCode SetDefaultNotificationEnabled( 1348 const sptr<NotificationBundleOption> &bundleOption, bool enabled); 1349 ErrCode IsAllowedNotifyForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &allowed); 1350 void AddLiveViewSubscriber(); 1351 void EraseLiveViewSubsciber(const std::string &bundleName); 1352 bool GetLiveViewSubscribeState(const std::string &bundleName); 1353 bool CheckLocalLiveViewSubscribed(const sptr<NotificationRequest> &request); 1354 bool CheckLocalLiveViewAllowed(const sptr<NotificationRequest> &request); 1355 static bool GetBundleInfoByNotificationBundleOption( 1356 const sptr<NotificationBundleOption> &bundleOption, AppExecFwk::BundleInfo &bundleInfo); 1357 1358 ErrCode GetTargetRecordList(const int32_t uid, NotificationConstant::SlotType slotType, 1359 NotificationContent::Type contentType, std::vector<std::shared_ptr<NotificationRecord>>& recordList); 1360 ErrCode GetCommonTargetRecordList(const int32_t uid, NotificationConstant::SlotType slotType, 1361 NotificationContent::Type contentType, std::vector<std::shared_ptr<NotificationRecord>>& recordList); 1362 ErrCode RemoveNotificationFromRecordList(const std::vector<std::shared_ptr<NotificationRecord>>& recordList); 1363 void OnSubscriberAdd(const std::shared_ptr<NotificationSubscriberManager::SubscriberRecord> &record); 1364 void OnSubscriberAddInffrt(const std::shared_ptr<NotificationSubscriberManager::SubscriberRecord> &record); 1365 bool IsLiveViewCanRecover(const sptr<NotificationRequest> request); 1366 ErrCode FillNotificationRecord(const NotificationRequestDb &requestdbObj, 1367 std::shared_ptr<NotificationRecord> record); 1368 static int32_t SetNotificationRequestToDb(const NotificationRequestDb &requestDb); 1369 static int32_t GetNotificationRequestFromDb(const std::string &key, NotificationRequestDb &requestDb); 1370 static int32_t GetBatchNotificationRequestsFromDb(std::vector<NotificationRequestDb> &requests, 1371 int32_t userId = -1); 1372 static int32_t DoubleDeleteNotificationFromDb(const std::string &key, 1373 const std::string &secureKey, const int32_t userId); 1374 static int32_t DeleteNotificationRequestFromDb(const std::string &key, const int32_t userId); 1375 void CancelTimer(uint64_t timerId); 1376 void BatchCancelTimer(std::vector<uint64_t> timerIds); 1377 ErrCode UpdateNotificationTimerInfo(const std::shared_ptr<NotificationRecord> &record); 1378 ErrCode SetFinishTimer(const std::shared_ptr<NotificationRecord> &record); 1379 ErrCode StartFinishTimer(const std::shared_ptr<NotificationRecord> &record, 1380 int64_t expireTimePoint, const int32_t reason); 1381 void CancelFinishTimer(const std::shared_ptr<NotificationRecord> &record); 1382 ErrCode SetUpdateTimer(const std::shared_ptr<NotificationRecord> &record); 1383 ErrCode StartUpdateTimer(const std::shared_ptr<NotificationRecord> &record, 1384 int64_t expireTimePoint, const int32_t reason); 1385 void CancelUpdateTimer(const std::shared_ptr<NotificationRecord> &record); 1386 void StartArchiveTimer(const std::shared_ptr<NotificationRecord> &record); 1387 void CancelArchiveTimer(const std::shared_ptr<NotificationRecord> &record); 1388 ErrCode StartAutoDeletedTimer(const std::shared_ptr<NotificationRecord> &record); 1389 void ProcForDeleteLiveView(const std::shared_ptr<NotificationRecord> &record); 1390 ErrCode IsAllowedGetNotificationByFilter(const std::shared_ptr<NotificationRecord> &record); 1391 void QueryDoNotDisturbProfile(const int32_t &userId, std::string &enable, std::string &profileId); 1392 void CheckDoNotDisturbProfile(const std::shared_ptr<NotificationRecord> &record); 1393 void ReportDoNotDisturbModeChanged(const int32_t &userId, std::string &enable); 1394 void DoNotDisturbUpdataReminderFlags(const std::shared_ptr<NotificationRecord> &record); 1395 ErrCode CheckCommonParams(); 1396 std::shared_ptr<NotificationRecord> GetRecordFromNotificationList( 1397 int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName); 1398 std::shared_ptr<NotificationRecord> MakeNotificationRecord( 1399 const sptr<NotificationRequest> &request, const sptr<NotificationBundleOption> &bundleOption); 1400 void FillActionButtons(const sptr<NotificationRequest> &request); 1401 ErrCode IsAllowedGetNotificationByFilter(const std::shared_ptr<NotificationRecord> &record, 1402 const sptr<NotificationBundleOption> &bundleOption); 1403 ErrCode FillRequestByKeys(const sptr<NotificationRequest> &oldRequest, 1404 const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &newRequest); 1405 ErrCode IsAllowedRemoveSlot(const sptr<NotificationBundleOption> &bundleOption, 1406 const NotificationConstant::SlotType &slotType); 1407 void HandleBadgeEnabledChanged(const sptr<NotificationBundleOption> &bundleOption, bool enabled); 1408 ErrCode CheckBundleOptionValid(sptr<NotificationBundleOption> &bundleOption); 1409 bool IsNeedNotifyConsumed(const sptr<NotificationRequest> &request); 1410 ErrCode AddRecordToMemory(const std::shared_ptr<NotificationRecord> &record, 1411 bool isSystemApp, bool isUpdateByOwner, const bool isAgentController); 1412 ErrCode DuplicateMsgControl(const sptr<NotificationRequest> &request); 1413 void RemoveExpiredUniqueKey(); 1414 bool IsDuplicateMsg(const std::string &uniqueKey); 1415 void DeleteDuplicateMsgs(const sptr<NotificationBundleOption> &bundleOption); 1416 ErrCode PublishRemoveDuplicateEvent(const std::shared_ptr<NotificationRecord> &record); 1417 std::vector<AppExecFwk::BundleInfo> GetBundlesOfActiveUser(); 1418 ErrCode UpdateSlotAuthInfo(const std::shared_ptr<NotificationRecord> &record); 1419 void FillLockScreenPicture(const sptr<NotificationRequest> &newRequest, 1420 const sptr<NotificationRequest> &oldRequest); 1421 ErrCode CancelAsBundleWithAgent( 1422 const sptr<NotificationBundleOption> &bundleOption, const int32_t id, const std::string &label, int32_t userId); 1423 static ErrCode SetLockScreenPictureToDb(const sptr<NotificationRequest> &request); 1424 static ErrCode GetLockScreenPictureFromDb(NotificationRequest *request); 1425 void RemoveDoNotDisturbProfileTrustList(const sptr<NotificationBundleOption> &bundleOption); 1426 ErrCode AssignValidNotificationSlot(const std::shared_ptr<NotificationRecord> &record, 1427 const sptr<NotificationBundleOption> &bundleOption); 1428 ErrCode UpdateSlotReminderModeBySlotFlags(const sptr<NotificationBundleOption> &bundle, uint32_t slotFlags); 1429 ErrCode CheckSoundPermission(const sptr<NotificationRequest> &request, std::string bundleName); 1430 void GenerateSlotReminderMode(const sptr<NotificationSlot> &slot, const sptr<NotificationBundleOption> &bundle, 1431 bool isSpecifiedSlot = false, uint32_t defaultSlotFlags = DEFAULT_SLOT_FLAGS); 1432 static void CloseAlert(const std::shared_ptr<NotificationRecord> &record); 1433 bool IsUpdateSystemLiveviewByOwner(const sptr<NotificationRequest> &request); 1434 bool IsSaCreateSystemLiveViewAsBundle(const std::shared_ptr<NotificationRecord> &record, int32_t ipcUid); 1435 ErrCode SaPublishSystemLiveViewAsBundle(const std::shared_ptr<NotificationRecord> &record); 1436 bool IsNotificationExistsInDelayList(const std::string &key); 1437 uint64_t StartDelayPublishTimer(const int32_t ownerUid, const int32_t notificationId, const uint32_t delayTime); 1438 ErrCode StartPublishDelayedNotification(const std::shared_ptr<NotificationRecord> &record); 1439 void StartPublishDelayedNotificationTimeOut(const int32_t ownerUid, const int32_t notificationId); 1440 void UpdateRecordByOwner(const std::shared_ptr<NotificationRecord> &record, bool isSystemApp); 1441 ErrCode DeleteAllByUserInner(const int32_t &userId, int32_t reason, bool isAsync = false); 1442 ErrCode RemoveAllNotificationsInner(const sptr<NotificationBundleOption> &bundleOption, int32_t reason); 1443 void RemoveNotificationList(const std::shared_ptr<NotificationRecord> &record); 1444 void StartFinishTimerForUpdate(const std::shared_ptr<NotificationRecord> &record, uint64_t process); 1445 ErrCode CheckLongTermLiveView(const sptr<NotificationRequest> &request, const std::string &key); 1446 void ExcuteCancelGroupCancel(const sptr<NotificationBundleOption>& bundleOption, 1447 const std::string &groupName, const int32_t reason); 1448 ErrCode ExcuteCancelAll(const sptr<NotificationBundleOption>& bundleOption, const int32_t reason); 1449 ErrCode ExcuteDelete(const std::string &key, const int32_t removeReason); 1450 ErrCode CheckNeedSilent(const std::string &phoneNumber, int32_t callerType, int32_t userId); 1451 uint32_t GetDefaultSlotFlags(const sptr<NotificationRequest> &request); 1452 bool IsSystemUser(int32_t userId); 1453 1454 ErrCode OnRecoverLiveView(const std::vector<std::string> &keys); 1455 void HandleUpdateLiveViewNotificationTimer(const int32_t uid, const bool isPaused); 1456 void CancelWantAgent(const sptr<Notification> ¬ification); 1457 void CancelOnceWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent); 1458 void SetClassificationWithVoip(const sptr<NotificationRequest> &request); 1459 1460 ErrCode SetEnabledForBundleSlotInner(const sptr<NotificationBundleOption> &bundleOption, 1461 const sptr<NotificationBundleOption> &bundle, 1462 const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); 1463 ErrCode AddSlotThenPublishEvent( 1464 const sptr<NotificationSlot> &slot, 1465 const sptr<NotificationBundleOption> &bundle, 1466 bool enabled, bool isForceControl); 1467 private: 1468 static sptr<AdvancedNotificationService> instance_; 1469 static std::mutex instanceMutex_; 1470 static std::mutex pushMutex_; 1471 static std::map<NotificationConstant::SlotType, sptr<IPushCallBack>> pushCallBacks_; 1472 static std::map<NotificationConstant::SlotType, sptr<NotificationCheckRequest>> checkRequests_; 1473 bool aggregateLocalSwitch_ = false; 1474 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_ = nullptr; 1475 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ = nullptr; 1476 std::list<std::shared_ptr<NotificationRecord>> notificationList_; 1477 std::shared_ptr<RecentInfo> recentInfo_ = nullptr; 1478 std::shared_ptr<DistributedKvStoreDeathRecipient> distributedKvStoreDeathRecipient_ = nullptr; 1479 std::shared_ptr<SystemEventObserver> systemEventObserver_ = nullptr; 1480 DistributedKv::DistributedKvDataManager dataManager_; 1481 sptr<IRemoteObject::DeathRecipient> pushRecipient_ = nullptr; 1482 std::shared_ptr<ffrt::queue> notificationSvrQueue_ = nullptr; 1483 std::map<NotificationConstant::SlotType, std::shared_ptr<BasePublishProcess>> publishProcess_; 1484 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED 1485 NotificationConstant::DistributedReminderPolicy distributedReminderPolicy_ = DEFAULT_DISTRIBUTED_REMINDER_POLICY; 1486 bool localScreenOn_ = true; 1487 #endif 1488 std::shared_ptr<SoundPermissionInfo> soundPermissionInfo_ = nullptr; 1489 std::shared_ptr<PermissionFilter> permissonFilter_ = nullptr; 1490 std::shared_ptr<NotificationSlotFilter> notificationSlotFilter_ = nullptr; 1491 std::shared_ptr<NotificationDialogManager> dialogManager_ = nullptr; 1492 std::list<std::pair<std::chrono::steady_clock::time_point, std::string>> uniqueKeyList_; 1493 std::list<std::pair<std::shared_ptr<NotificationRecord>, uint64_t>> delayNotificationList_; 1494 std::mutex delayNotificationMutext_; 1495 static std::mutex doNotDisturbMutex_; 1496 std::map<int32_t, std::string> doNotDisturbEnableRecord_; 1497 }; 1498 1499 /** 1500 * @class PushCallbackRecipient 1501 * PushCallbackRecipient notices IRemoteBroker died. 1502 */ 1503 class PushCallbackRecipient : public IRemoteObject::DeathRecipient { 1504 public: 1505 PushCallbackRecipient(); 1506 virtual ~PushCallbackRecipient(); 1507 void OnRemoteDied(const wptr<IRemoteObject> &remote); 1508 }; 1509 } // namespace Notification 1510 } // namespace OHOS 1511 1512 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_ADVANCED_NOTIFICATION_SERVICE_H 1513