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_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H 17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H 18 19 #include "ans_manager_interface.h" 20 #include "distributed_notification_service_ipc_interface_code.h" 21 #include "iremote_proxy.h" 22 #include "want_params.h" 23 24 namespace OHOS { 25 namespace Notification { 26 class AnsManagerProxy : public IRemoteProxy<AnsManagerInterface> { 27 public: 28 AnsManagerProxy() = delete; 29 explicit AnsManagerProxy(const sptr<IRemoteObject> &impl); 30 ~AnsManagerProxy() override; 31 DISALLOW_COPY_AND_MOVE(AnsManagerProxy); 32 33 /** 34 * @brief Publishes a notification with a specified label. 35 * @note If a notification with the same ID has been published by the current application and has not been deleted, 36 * this method will update the notification. 37 * 38 * @param label Indicates the label of the notification to publish. 39 * @param notification Indicates the NotificationRequest object for setting the notification content. 40 * This parameter must be specified. 41 * @return Returns ERR_OK on success, others on failure. 42 */ 43 ErrCode Publish(const std::string &label, const sptr<NotificationRequest> ¬ification) override; 44 45 /** 46 * @brief Publishes a notification. 47 * @note If a notification with the same ID has been published by the current application and has not been deleted, 48 * this method will update the notification. 49 * 50 * @param notification Indicates the NotificationRequest object for setting the notification content. 51 * This parameter must be specified. 52 * @return Returns ERR_OK on success, others on failure. 53 */ 54 ErrCode PublishNotificationForIndirectProxy(const sptr<NotificationRequest> ¬ification) override; 55 56 /** 57 * @brief Cancels a published notification matching the specified label and notificationId. 58 * 59 * @param notificationId Indicates the ID of the notification to cancel. 60 * @param label Indicates the label of the notification to cancel. 61 * @param instanceKey Indicates the application instance key. 62 * @return Returns cancel notification result. 63 */ 64 ErrCode Cancel(int32_t notificationId, const std::string &label, int32_t instanceKey) override; 65 66 /** 67 * @brief Cancels all the published notifications. 68 * 69 * @param instanceKey Indicates the application instance key. 70 * @return Returns ERR_OK on success, others on failure. 71 */ 72 ErrCode CancelAll(int32_t instanceKey) 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 ErrCode CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId) override; 85 86 /** 87 * @brief Cancels a published agent notification. 88 * 89 * @param bundleOption Indicates the bundle of application your application is representing. 90 * @param notificationId Indicates the unique notification ID in the application. 91 * The value must be the ID of a published notification. 92 * Otherwise, this method does not take effect. 93 * @return Returns cancel notification result. 94 */ 95 ErrCode CancelAsBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId) override; 96 97 /** 98 * @brief Cancels a published agent notification. 99 * 100 * @param bundleOption Indicates the bundle of application bundle your application is representing. 101 * @param notificationId Indicates the unique notification ID in the application. 102 * The value must be the ID of a published notification. 103 * Otherwise, this method does not take effect. 104 * @param userId Indicates the specific user. 105 * @return Returns cancel notification result. 106 */ 107 ErrCode CancelAsBundle( 108 const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, int32_t userId) override; 109 110 /** 111 * @brief Adds a notification slot by type. 112 * 113 * @param slotType Indicates the notification slot type to be added. 114 * @return Returns ERR_OK on success, others on failure. 115 */ 116 ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override; 117 118 /** 119 * @brief Creates multiple notification slots. 120 * 121 * @param slots Indicates the notification slots to create. 122 * @return Returns ERR_OK on success, others on failure. 123 */ 124 ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override; 125 126 /** 127 * @brief Deletes a created notification slot based on the slot ID. 128 * 129 * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot 130 * This parameter must be specified. 131 * @return Returns ERR_OK on success, others on failure. 132 */ 133 ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override; 134 135 /** 136 * @brief Deletes all notification slots. 137 * 138 * @return Returns ERR_OK on success, others on failure. 139 */ 140 ErrCode RemoveAllSlots() override; 141 142 /** 143 * @brief Queries a created notification slot. 144 * 145 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This 146 * parameter must be specified. 147 * @param slot Indicates the created NotificationSlot. 148 * @return Returns ERR_OK on success, others on failure. 149 */ 150 ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot) override; 151 152 /** 153 * @brief Obtains all notification slots of this application. 154 * 155 * @param slots Indicates the created NotificationSlot. 156 * @return Returns ERR_OK on success, others on failure. 157 */ 158 ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override; 159 160 /** 161 * @brief Obtains the number of slot. 162 * 163 * @param bundleOption Indicates the bundle name and uid of the application. 164 * @param num Indicates the number of slot. 165 * @return Returns ERR_OK on success, others on failure. 166 */ 167 ErrCode GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num) override; 168 169 /** 170 * @brief Obtains active notifications of the current application in the system. 171 * 172 * @param notifications Indicates active NotificationRequest objects of the current application. 173 * @param instanceKey Indicates the application instance key. 174 * @return Returns ERR_OK on success, others on failure. 175 */ 176 ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications, int32_t instanceKey) override; 177 178 /** 179 * @brief Obtains the number of active notifications of the current application in the system. 180 * 181 * @param num Indicates the number of active notifications of the current application. 182 * @return Returns ERR_OK on success, others on failure. 183 */ 184 ErrCode GetActiveNotificationNums(uint64_t &num) override; 185 186 /** 187 * @brief Obtains all active notifications in the current system. The caller must have system permissions to 188 * call this method. 189 * 190 * @param notifications Indicates all active notifications of this application. 191 * @return Returns ERR_OK on success, others on failure. 192 */ 193 ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications) override; 194 195 /** 196 * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method 197 * to obtain particular active notifications, you must have received the notifications and obtained the key 198 * via {Notification::GetKey()}. 199 * 200 * @param key Indicates the key array for querying corresponding active notifications. 201 * If this parameter is null, this method returns all active notifications in the system. 202 * @param notification Indicates the set of active notifications corresponding to the specified key. 203 * @return Returns ERR_OK on success, others on failure. 204 */ 205 ErrCode GetSpecialActiveNotifications( 206 const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications) override; 207 208 /** 209 * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method 210 * to obtain particular live view notification extra info, you must have received the 211 * 212 * @param bundleOption Indicates the bundle name and uid of the application. 213 * @param notificationId Indicates the id of the notification to get the extra info by extra info keys. 214 * @param label 215 * @param extraInfoKeys 216 * @param extraInfo 217 * @return 218 */ 219 ErrCode GetActiveNotificationByFilter( 220 const sptr<NotificationBundleOption> &bundleOption, const int32_t notificationId, const std::string &label, 221 const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &request) override; 222 223 /** 224 * @brief Allows another application to act as an agent to publish notifications in the name of your application 225 * bundle. 226 * 227 * @param agent Indicates the name of the application bundle that can publish notifications for your application. 228 * @return Returns ERR_OK on success, others on failure. 229 */ 230 ErrCode SetNotificationAgent(const std::string &agent) override; 231 232 /** 233 * @brief Obtains the name of the application bundle that can publish notifications in the name of your application. 234 * 235 * @param agent Indicates the name of the application bundle that can publish notifications for your application if 236 * any; returns null otherwise. 237 * @return Returns ERR_OK on success, others on failure. 238 */ 239 ErrCode GetNotificationAgent(std::string &agent) override; 240 241 /** 242 * @brief Checks whether your application has permission to publish notifications by calling 243 * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the 244 * given representativeBundle. 245 * 246 * @param representativeBundle Indicates the name of application bundle your application is representing. 247 * @param canPublish Indicates whether your application has permission to publish notifications. 248 * @return Returns ERR_OK on success, others on failure. 249 */ 250 ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override; 251 252 /** 253 * @brief Publishes a notification in the name of a specified application bundle. 254 * @note If the notification to be published has the same ID as a published notification that has not been canceled, 255 * the existing notification will be replaced by the new one. 256 * 257 * @param notification Indicates the NotificationRequest object for setting the notification content. 258 * This parameter must be specified. 259 * @param representativeBundle Indicates the name of the application bundle that allows your application to publish 260 * notifications for it by calling setNotificationAgent. 261 * @return Returns ERR_OK on success, others on failure. 262 */ 263 ErrCode PublishAsBundle( 264 const sptr<NotificationRequest> notification, const std::string &representativeBundle) override; 265 266 /** 267 * @brief Sets the number of active notifications of the current application as the number to be displayed on the 268 * notification badge. 269 * 270 * @param num Indicates the badge number. 271 * @return Returns ERR_OK on success, others on failure. 272 */ 273 ErrCode SetNotificationBadgeNum(int32_t num) override; 274 275 /** 276 * @brief Obtains the importance level of this application. 277 * 278 * @param importance Indicates the importance level of this application, which can be LEVEL_NONE, 279 LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED. 280 * @return Returns ERR_OK on success, others on failure. 281 */ 282 ErrCode GetBundleImportance(int32_t &importance) override; 283 284 /** 285 * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. 286 * 287 * @param granted True if the application has permission; false for otherwise. 288 * @return Returns ERR_OK on success, others on failure. 289 */ 290 ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; 291 292 /** 293 * @brief Trigger the local live view after the button has been clicked. 294 * @note Your application must have platform signature to use this method. 295 * 296 * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. 297 * @param notificationId Indicates the id of the notification. 298 * @param buttonOption Indicates which button has been clicked. 299 * @return Returns trigger localLiveView result. 300 */ 301 ErrCode TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption, 302 const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption) override; 303 304 /** 305 * @brief Delete notification. 306 * 307 * @param bundleOption Indicates the NotificationBundleOption of the notification. 308 * @param notificationId Indicates the id of the notification. 309 * @param label Indicates the label of the notification. 310 * @param removeReason Indicates the reason of remove notification. 311 * @return Returns ERR_OK on success, others on failure. 312 */ 313 ErrCode RemoveNotification(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, 314 const std::string &label, int32_t removeReason) override; 315 316 /** 317 * @brief Delete all notifications. 318 * 319 * @param bundleOption Indicates the NotificationBundleOption of notifications. 320 * @return Returns ERR_OK on success, others on failure. 321 */ 322 ErrCode RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption) override; 323 324 ErrCode RemoveNotifications(const std::vector<std::string> &hashcodes, int32_t removeReason) override; 325 326 /** 327 * @brief Delete notification based on key. 328 * 329 * @param key Indicates the key to delete notification. 330 * @param removeReason Indicates the reason of remove notification. 331 * @return Returns ERR_OK on success, others on failure. 332 */ 333 ErrCode Delete(const std::string &key, int32_t removeReason) override; 334 335 /** 336 * @brief Remove notifications based on bundle. 337 * 338 * @param bundleOption Indicates the NotificationBundleOption of notifications. 339 * @return Returns ERR_OK on success, others on failure. 340 */ 341 ErrCode DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption) override; 342 343 /** 344 * @brief Remove all notifications. 345 * 346 * @return Returns ERR_OK on success, others on failure. 347 */ 348 ErrCode DeleteAll() override; 349 350 /** 351 * @brief Get all the slots corresponding to the bundle. 352 * 353 * @param bundleOption Indicates the NotificationBundleOption object. 354 * @param slots Indicates the notification slots. 355 * @return Returns ERR_OK on success, others on failure. 356 */ 357 ErrCode GetSlotsByBundle( 358 const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots) override; 359 360 /** 361 * @brief Get the specified slot corresponding to the bundle. 362 * 363 * @param bundleOption Indicates the NotificationBundleOption object. 364 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This 365 * parameter must be specified. 366 * @param slot Indicates the notification slot. 367 * @return Returns ERR_OK on success, others on failure. 368 */ 369 ErrCode GetSlotByBundle( 370 const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType, 371 sptr<NotificationSlot> &slot) override; 372 373 /** 374 * @brief Update slots according to bundle. 375 * 376 * @param bundleOption Indicates the NotificationBundleOption object. 377 * @param slots Indicates the notification slots to be updated. 378 * @return Returns ERR_OK on success, others on failure. 379 */ 380 ErrCode UpdateSlots( 381 const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots) override; 382 383 /** 384 * @brief Allow notifications to be sent based on the deviceId. 385 * 386 * @param deviceId Indicates the device Id. 387 * @return Returns ERR_OK on success, others on failure. 388 */ 389 ErrCode RequestEnableNotification(const std::string &deviceId, 390 const sptr<AnsDialogCallback> &callback, 391 const sptr<IRemoteObject> &callerToken) override; 392 393 /** 394 * @brief Set whether to allow the specified deviceId to send notifications for current bundle. 395 * 396 * @param deviceId Indicates the device Id. 397 * @param enabled Indicates the flag that allows notification to be pulished. 398 * @return Returns ERR_OK on success, others on failure. 399 */ 400 ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override; 401 402 /** 403 * @brief Set whether to allow the specified deviceId to send notifications for all bundles. 404 * 405 * @param deviceId Indicates the device Id. 406 * @param enabled Indicates the flag that allows notification to be pulished. 407 * @return Returns ERR_OK on success, others on failure. 408 */ 409 ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override; 410 411 /** 412 * @brief Set whether to allow the specified bundle to send notifications. 413 * 414 * @param bundleOption Indicates the NotificationBundleOption object. 415 * @param enabled Indicates the flag that allows notification to be pulished. 416 * @return Returns ERR_OK on success, others on failure. 417 */ 418 ErrCode SetNotificationsEnabledForSpecialBundle( 419 const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 420 421 /** 422 * @brief Sets whether the bundle allows the banner to display notification. 423 * 424 * @param bundleOption Indicates the NotificationBundleOption object. 425 * @param enabled Indicates the flag that allows badge to be shown. 426 * @return Returns ERR_OK on success, others on failure. 427 */ 428 ErrCode SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 429 430 /** 431 * @brief Gets whether the bundle allows the badge to display the status of notifications. 432 * 433 * @param bundleOption Indicates the NotificationBundleOption object. 434 * @param enabled Indicates the flag that allows badge to be shown. 435 * @return Returns ERR_OK on success, others on failure. 436 */ 437 ErrCode GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override; 438 439 /** 440 * @brief Gets whether allows the badge to display the status of notifications. 441 * 442 * @param enabled Indicates the flag that allows badge to be shown. 443 * @return Returns ERR_OK on success, others on failure. 444 */ 445 ErrCode GetShowBadgeEnabled(bool &enabled) override; 446 447 /** 448 * @brief Subscribes notifications. 449 * 450 * @param subscriber Indicates the subscriber. 451 * @param info Indicates the NotificationSubscribeInfo object. 452 * @return Returns ERR_OK on success, others on failure. 453 */ 454 ErrCode Subscribe(const sptr<AnsSubscriberInterface> &subscriber, 455 const sptr<NotificationSubscribeInfo> &info) override; 456 457 /** 458 * @brief Subscribes notifications self. 459 * 460 * @param subscriber Indicates the subscriber. 461 * @param info Indicates the NotificationSubscribeInfo object. 462 * @return Returns ERR_OK on success, others on failure. 463 */ 464 ErrCode SubscribeSelf(const sptr<AnsSubscriberInterface> &subscriber) override; 465 466 /** 467 * @brief Subscribes notifications. 468 * 469 * @param subscriber Indicates the subscriber. 470 * @param info Indicates the NotificationSubscribeInfo object. 471 * @return Returns ERR_OK on success, others on failure. 472 */ 473 ErrCode SubscribeLocalLiveView(const sptr<AnsSubscriberLocalLiveViewInterface> &subscriber, 474 const sptr<NotificationSubscribeInfo> &info, const bool isNative) override; 475 476 /** 477 * @brief Unsubscribes notifications. 478 * 479 * @param subscriber Indicates the subscriber. 480 * @param info Indicates the NotificationSubscribeInfo object. 481 * @return Returns ERR_OK on success, others on failure. 482 */ 483 ErrCode Unsubscribe(const sptr<AnsSubscriberInterface> &subscriber, 484 const sptr<NotificationSubscribeInfo> &info) override; 485 486 /** 487 * @brief Checks whether this device is allowed to publish notifications. 488 * 489 * @param allowed Indicates the flag that allows notification. 490 * @return Returns ERR_OK on success, others on failure. 491 */ 492 ErrCode IsAllowedNotify(bool &allowed) override; 493 494 /** 495 * @brief Checks whether this application is allowed to publish notifications. 496 * 497 * @param allowed Indicates the flag that allows notification. 498 * @return Returns ERR_OK on success, others on failure. 499 */ 500 ErrCode IsAllowedNotifySelf(bool &allowed) override; 501 502 /** 503 * @brief Checks whether this application can pop enable notification dialog. 504 * 505 * @param canPop True if can pop enable notification dialog 506 * @return Returns is canPop result. 507 */ 508 ErrCode CanPopEnableNotificationDialog(const sptr<AnsDialogCallback> &callback, 509 bool &canPop, std::string &bundleName) override; 510 511 /** 512 * @brief remove enable notification dialog. 513 * 514 * @return Returns remove dialog result. 515 */ 516 ErrCode RemoveEnableNotificationDialog() override; 517 518 /** 519 * @brief Checks whether notifications are allowed for a specific bundle. 520 * 521 * @param bundleOption Indicates the NotificationBundleOption object. 522 * @param allowed Indicates the flag that allows notification. 523 * @return Returns ERR_OK on success, others on failure. 524 */ 525 ErrCode IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed) override; 526 527 /** 528 * @brief Set do not disturb date. 529 * 530 * @param date Indicates the NotificationDoNotDisturbDate object. 531 * @return Returns ERR_OK on success, others on failure. 532 */ 533 ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date) override; 534 535 /** 536 * @brief Get do not disturb date. 537 * 538 * @param date Indicates the NotificationDoNotDisturbDate object. 539 * @return Returns ERR_OK on success, others on failure. 540 */ 541 ErrCode GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date) override; 542 543 /** 544 * @brief Add do not disturb Profiles. 545 * 546 * @param profiles Indicates the NotificationDoNotDisturbProfile objects. 547 * @return Returns ERR_OK on success, others on failure. 548 */ 549 ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override; 550 551 /** 552 * @brief Remove do not disturb Profiles. 553 * 554 * @param profiles Indicates the NotificationDoNotDisturbProfile objects. 555 * @return Returns ERR_OK on success, others on failure. 556 */ 557 ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override; 558 559 /** 560 * @brief Get whether Do Not Disturb mode is supported. 561 * 562 * @param doesSupport Indicates the flag that supports DND mode. 563 * @return Returns ERR_OK on success, others on failure. 564 */ 565 ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override; 566 567 /** 568 * @brief Is coming call need silent in do not disturb mode. 569 * 570 * @param phoneNumber the calling format number. 571 * @return Returns silent in do not disturb mode. 572 */ 573 ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override; 574 575 /** 576 * @brief Cancel notifications according to group. 577 * 578 * @param groupName Indicates the group name. 579 * @param instanceKey Indicates the application instance key. 580 * @return Returns ERR_OK on success, others on failure. 581 */ 582 ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) override; 583 584 /** 585 * @brief Delete notifications according to bundle and group. 586 * 587 * @param bundleOption Indicates the NotificationBundleOption object. 588 * @param groupName Indicates the group name. 589 * @return Returns ERR_OK on success, others on failure. 590 */ 591 ErrCode RemoveGroupByBundle( 592 const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName) override; 593 594 /** 595 * @brief Gets whether distributed notification is enabled. 596 * 597 * @param enabled Indicates the enabled flag. 598 * @return Returns ERR_OK on success, others on failure. 599 */ 600 ErrCode IsDistributedEnabled(bool &enabled) override; 601 602 /** 603 * @brief Sets distributed notification enabled or disabled. 604 * 605 * @param enabled Indicates the enabled flag. 606 * @return Returns ERR_OK on success, others on failure. 607 */ 608 ErrCode EnableDistributed(bool enabled) override; 609 610 /** 611 * @brief Sets distributed notification enabled or disabled for specific bundle. 612 * 613 * @param bundleOption Indicates the NotificationBundleOption object. 614 * @param enabled Indicates the enabled flag. 615 * @return Returns ERR_OK on success, others on failure. 616 */ 617 ErrCode EnableDistributedByBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override; 618 619 /** 620 * @brief Sets distributed notification enabled or disabled for current bundle. 621 * 622 * @param enabled Indicates the enabled flag. 623 * @return Returns ERR_OK on success, others on failure. 624 */ 625 ErrCode EnableDistributedSelf(bool enabled) override; 626 627 /** 628 * @brief Gets whether distributed notification is enabled for specific bundle. 629 * 630 * @param bundleOption Indicates the NotificationBundleOption object. 631 * @param enabled Indicates the enabled flag. 632 * @return Returns ERR_OK on success, others on failure. 633 */ 634 ErrCode IsDistributedEnableByBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override; 635 636 /** 637 * @brief Get the reminder type of the current device. 638 * 639 * @param remindType Reminder type for the device. 640 * @return Returns ERR_OK on success, others on failure. 641 */ 642 ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override; 643 644 /** 645 * @brief Publishes a continuous notification. 646 * 647 * @param request Notification requests that need to be posted. 648 * @return Returns ERR_OK on success, others on failure. 649 */ 650 ErrCode PublishContinuousTaskNotification(const sptr<NotificationRequest> &request) override; 651 652 /** 653 * @brief Cancels a continuous notification. 654 * 655 * @param label Identifies the label of the specified notification. 656 * @param notificationId Identifies the id of the specified notification. 657 * @return Returns ERR_OK on success, others on failure. 658 */ 659 ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; 660 661 /** 662 * @brief Checks whether this device is support template. 663 * 664 * @param templateName Identifies the template name for searching as a condition. 665 * @param support Identifies the support flag. 666 * @return Returns ERR_OK on success, others on failure. 667 */ 668 ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; 669 670 /** 671 * @brief Publishes a reminder notification. 672 * 673 * @param reminder Identifies the reminder notification request that needs to be published. 674 * @return Returns ERR_OK on success, others on failure. 675 */ 676 ErrCode PublishReminder(sptr<ReminderRequest> &reminder) override; 677 678 /** 679 * @brief Cancel a reminder notifications. 680 * 681 * @param reminderId Identifies the reminders id that needs to be canceled. 682 * @return Returns ERR_OK on success, others on failure. 683 */ 684 ErrCode CancelReminder(const int32_t reminderId) override; 685 686 /** 687 * @brief Get all valid reminder notifications. 688 * 689 * @param reminders Identifies the list of all valid notifications. 690 * @return Returns ERR_OK on success, others on failure. 691 */ 692 ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &reminders) override; 693 694 /** 695 * @brief Cancel all reminder notifications. 696 * 697 * @return Returns ERR_OK on success, others on failure. 698 */ 699 ErrCode CancelAllReminders() override; 700 701 /** 702 * @brief Add exclude date for reminder 703 * 704 * @param reminderId Identifies the reminders id. 705 * @param date exclude date 706 * @return Returns ERR_OK on success, others on failure. 707 */ 708 ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; 709 710 /** 711 * @brief Clear exclude date for reminder 712 * 713 * @param reminderId Identifies the reminders id. 714 * @return Returns ERR_OK on success, others on failure. 715 */ 716 ErrCode DelExcludeDates(const int32_t reminderId) override; 717 718 /** 719 * @brief Get exclude date for reminder 720 * 721 * @param reminderId Identifies the reminders id. 722 * @param dates exclude dates 723 * @return Returns ERR_OK on success, others on failure. 724 */ 725 ErrCode GetExcludeDates(const int32_t reminderId, std::vector<uint64_t>& dates) override; 726 727 /** 728 * @brief Checks Whether the specified users is allowed to publish notifications. 729 * 730 * @param userId Identifies the user's id. 731 * @param allowed Identifies the allowed flag. 732 * @return Returns ERR_OK on success, others on failure. 733 */ 734 ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override; 735 736 /** 737 * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must 738 * have system permissions to call this method. 739 * 740 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only 741 * be null or an empty string, indicating the current device. 742 * @param enabled Specifies whether to allow all applications to publish notifications. The value true 743 * indicates that notifications are allowed, and the value false indicates that notifications 744 * are not allowed. 745 * @return Returns ERR_OK on success, others on failure. 746 */ 747 ErrCode SetNotificationsEnabledByUser(const int32_t &userId, bool enabled) override; 748 749 /** 750 * @brief Delete all notifications by user. 751 * 752 * @param userId Indicates the user id. 753 * @return Returns ERR_OK on success, others on failure. 754 */ 755 ErrCode DeleteAllByUser(const int32_t &userId) override; 756 757 /** 758 * @brief Set do not disturb date by user. 759 * 760 * @param userId Indicates the user id. 761 * @param date Indicates NotificationDoNotDisturbDate object. 762 * @return Returns ERR_OK on success, others on failure. 763 */ 764 ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date) override; 765 766 /** 767 * @brief Get the do not disturb date by user. 768 * 769 * @param userId Indicates the user id. 770 * @param date Indicates the NotificationDoNotDisturbDate object. 771 * @return Returns ERR_OK on success, others on failure. 772 */ 773 ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date) override; 774 ErrCode SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption, 775 const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; 776 ErrCode GetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption, 777 const NotificationConstant::SlotType &slotType, bool &enabled) override; 778 ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; 779 780 /** 781 * @brief Obtains specific datas via specified dump option. 782 * 783 * @param cmd Indicates the specified dump command. 784 * @param bundle Indicates the specified bundle name. 785 * @param userId Indicates the specified userId. 786 * @param dumpInfo Indicates the container containing datas. 787 * @return Returns check result. 788 */ 789 ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, 790 std::vector<std::string> &dumpInfo) override; 791 792 /** 793 * @brief Set whether to sync notifications to devices that do not have the app installed. 794 * 795 * @param userId Indicates the specific user. 796 * @param enabled Allow or disallow sync notifications. 797 * @return Returns set enabled result. 798 */ 799 ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override; 800 801 /** 802 * @brief Obtains whether to sync notifications to devices that do not have the app installed. 803 * 804 * @param userId Indicates the specific user. 805 * @param enabled Allow or disallow sync notifications. 806 * @return Returns get enabled result. 807 */ 808 ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override; 809 810 /** 811 * @brief Set badge number. 812 * 813 * @param badgeNumber The badge number. 814 * @return Returns set badge number result. 815 */ 816 ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) override; 817 818 /** 819 * @brief Set badge number by bundle. 820 * 821 * @param bundleOption Indicates the bundle name and uid of the application. 822 * @param badgeNumber The badge number. 823 * @return Returns set badge number by bundle result. 824 */ 825 ErrCode SetBadgeNumberByBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override; 826 827 /** 828 * @brief Get the slotFlags of slot. 829 * 830 * @param bundleOption Indicates the bundle name and uid of the application. 831 * @param slot Indicates the specified slot object 832 * @param slotFlags Indicates the slogFlags of slot to get. 833 * @return Returns ERR_OK on success, others on failure. 834 */ 835 ErrCode GetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t &slotFlags) override; 836 837 /** 838 * @brief Set the slotFlags of slot. 839 * 840 * @param bundleOption Indicates the bundle name and uid of the application. 841 * @param slot Indicates the specified slot object 842 * @param slotFlags Indicates the slogFlags of slot to set. 843 * @return Returns ERR_OK on success, others on failure. 844 */ 845 ErrCode SetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t slotFlags) override; 846 847 /** 848 * @brief Obtains allow notification application list. 849 * 850 * @param bundleOption Indicates the bundle bundleOption. 851 * @return Returns ERR_OK on success, others on failure. 852 */ 853 ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override; 854 855 /** 856 * @brief Register Push Callback. 857 * 858 * @param pushCallback PushCallBack. 859 * @param notificationCheckRequest Filter conditions for push check. 860 * @return Returns register PushCallback result. 861 */ 862 ErrCode RegisterPushCallback(const sptr<IRemoteObject> &pushCallback, 863 const sptr<NotificationCheckRequest> ¬ificationCheckRequest) override; 864 865 /** 866 * @brief Unregister Push Callback. 867 * 868 * @return Returns unregister push Callback result. 869 */ 870 ErrCode UnregisterPushCallback() override; 871 872 /** 873 * @brief Set agent relationship. 874 * 875 * @param key Indicates storing agent relationship if the value is "PROXY_PKG". 876 * @param value Indicates key-value pair of agent relationship. 877 * @return Returns set result. 878 */ 879 ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override; 880 881 /** 882 * @brief Sets whether to allow a specified application to publish notifications cross 883 * device collaboration. The caller must have system permissions to call this method. 884 * 885 * @param bundleOption Indicates the bundle name and uid of the application. 886 * @param deviceType Indicates the type of the device running the application. 887 * @param enabled Specifies whether to allow the given application to publish notifications. The value 888 * true indicates that notifications are allowed, and the value false indicates that 889 * notifications are not allowed. 890 * @return Returns set notifications enabled for specified bundle result. 891 */ 892 ErrCode SetDistributedEnabledByBundle( 893 const sptr<NotificationBundleOption> &bundleOption, const std::string &deviceType, const bool enabled) override; 894 895 /** 896 * @brief get whether to allow a specified application to publish notifications cross 897 * device collaboration. The caller must have system permissions to call this method. 898 * 899 * @param bundleOption Indicates the bundle name and uid of the application. 900 * @param deviceType Indicates the type of the device running the application. 901 * @param enabled Specifies whether to allow the given application to publish notifications. The value 902 * true indicates that notifications are allowed, and the value false indicates that 903 * notifications are not allowed. 904 * @return Returns set notifications enabled for specified bundle result. 905 */ 906 ErrCode IsDistributedEnabledByBundle( 907 const sptr<NotificationBundleOption> &bundleOption, const std::string &deviceType, bool &enabled) override; 908 909 /** 910 * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders 911 * 912 * @param deviceType Indicates the type of the device running the application. 913 * @param enabled Specifies whether to allow the given device to publish notifications. 914 * The value true indicates that notifications are allowed, and the value 915 * false indicates that notifications are not allowed. 916 * @return Returns set notifications enabled for specified bundle result. 917 */ 918 ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override; 919 920 /** 921 * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders 922 * 923 * @param deviceType Indicates the type of the device running the application. 924 * @param enabled Specifies whether to allow the given device to publish notifications. 925 * The value true indicates that notifications are allowed, and the value 926 * false indicates that notifications are not allowed. 927 * @return Returns set notifications enabled for specified bundle result. 928 */ 929 ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override; 930 931 /** 932 * @brief Cancels a published agent notification. 933 * 934 * @param bundleOption Indicates the bundle name and uid of the application. 935 * @param id Indicates the unique notification ID in the application. 936 * @return Returns cancel result. 937 */ 938 ErrCode CancelAsBundleWithAgent(const sptr<NotificationBundleOption> &bundleOption, const int32_t id) override; 939 940 /** 941 * @brief Set the status of the target device. 942 * 943 * @param deviceType Type of the device whose status you want to set. 944 * @param status The status. 945 * @return Returns set result. 946 */ 947 ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) override; 948 949 /** 950 * @brief Get do not disturb profile by id. 951 * 952 * @param id Profile id. 953 * @param status Indicates the NotificationDoNotDisturbProfile objects. 954 * @return Returns ERR_OK on success, others on failure. 955 */ 956 ErrCode GetDoNotDisturbProfile(int32_t id, sptr<NotificationDoNotDisturbProfile> &profile) override; 957 958 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED 959 /** 960 * @brief Register Swing Callback. 961 * 962 * @param swingCallback SwingCallBack. 963 * @return Returns register SwingCallback result. 964 */ 965 ErrCode RegisterSwingCallback(const sptr<IRemoteObject> &swingCallback) override; 966 #endif 967 968 /** 969 * @brief Update Notification Timer by uid. 970 * 971 * @param uid uid. 972 * @return Returns Update result. 973 */ 974 ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override; 975 976 private: 977 ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, 978 MessageParcel &data, MessageParcel &reply); 979 980 template<typename T> WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & data)981 bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data) 982 { 983 if (!data.WriteInt32(parcelableVector.size())) { 984 ANS_LOGE("Failed to write ParcelableVector size."); 985 return false; 986 } 987 988 for (auto &parcelable : parcelableVector) { 989 if (!data.WriteStrongParcelable(parcelable)) { 990 ANS_LOGE("Failed to write ParcelableVector"); 991 return false; 992 } 993 } 994 return true; 995 } 996 997 template<typename T> ReadParcelableVector(std::vector<sptr<T>> & parcelableInfos,MessageParcel & reply,ErrCode & result)998 bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &reply, ErrCode &result) 999 { 1000 if (!reply.ReadInt32(result)) { 1001 ANS_LOGE("read result failed."); 1002 return false; 1003 } 1004 1005 int32_t infoSize = 0; 1006 if (!reply.ReadInt32(infoSize)) { 1007 ANS_LOGE("read Parcelable size failed."); 1008 return false; 1009 } 1010 1011 parcelableInfos.clear(); 1012 infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; 1013 for (int32_t index = 0; index < infoSize; index++) { 1014 sptr<T> info = reply.ReadStrongParcelable<T>(); 1015 if (info == nullptr) { 1016 ANS_LOGE("read Parcelable infos failed."); 1017 return false; 1018 } 1019 parcelableInfos.emplace_back(info); 1020 } 1021 1022 return true; 1023 } 1024 static inline BrokerDelegator<AnsManagerProxy> delegator_; 1025 1026 ErrCode ReadReminders(uint8_t &count, MessageParcel &reply, std::vector<sptr<ReminderRequest>> &reminders); 1027 }; 1028 } // namespace Notification 1029 } // namespace OHOS 1030 1031 #endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H 1032