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_NOTIFICATION_CONFIG_FILE_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_NOTIFICATION_CONFIG_FILE_H 18 19 #include <map> 20 #include <string> 21 #include <set> 22 #include <vector> 23 #include <singleton.h> 24 #include <unordered_set> 25 #include <mutex> 26 27 #ifdef CONFIG_POLICY_ENABLE 28 #include "config_policy_utils.h" 29 #endif 30 #include "nlohmann/json.hpp" 31 #include "notification_app_privileges.h" 32 #include "notification_bundle_option.h" 33 #include "notification_constant.h" 34 #include "notification_flags.h" 35 #include "advanced_notification_flow_control_service.h" 36 37 namespace OHOS { 38 namespace Notification { 39 class NotificationConfigParse : public DelayedSingleton<NotificationConfigParse> { 40 public: 41 NotificationConfigParse(); 42 ~NotificationConfigParse() = default; 43 44 bool GetConfigJson(const std::string &keyCheck, nlohmann::json &configJson) const; 45 bool GetCurrentSlotReminder( 46 std::map<NotificationConstant::SlotType, std::shared_ptr<NotificationFlags>> ¤tSlotReminder) const; 47 void GetReportTrustListConfig(); 48 bool IsReportTrustList(const std::string& bundleName) const; 49 uint32_t GetConfigSlotReminderModeByType(NotificationConstant::SlotType slotType); 50 std::shared_ptr<NotificationAppPrivileges> GetAppPrivileges(const std::string &bundleName) const; 51 bool IsLiveViewEnabled(const std::string bundleName) const; 52 bool IsBannerEnabled(const std::string bundleName) const; 53 bool IsReminderEnabled(const std::string& bundleName) const; 54 bool IsDistributedReplyEnabled(const std::string& bundleName) const; 55 void GetFlowCtrlConfigFromCCM(FlowControlThreshold &threshold); 56 bool GetSmartReminderEnableList(std::vector<std::string>& deviceTypes); 57 bool GetMirrorNotificationEnabledStatus(std::vector<std::string>& deviceTypes); 58 bool GetAppAndDeviceRelationMap(std::map<std::string, std::string>& relationMap); 59 std::unordered_set<std::string> GetCollaborativeDeleteType() const; 60 bool GetCollaborativeDeleteTypeByDevice(std::map<std::string, std::map<std::string, 61 std::unordered_set<std::string>>>& map) const; 62 bool GetFilterUidAndBundleName(const std::string &key); 63 void GetCollaborationFilter(); 64 bool IsInCollaborationFilter(const std::string &bundleName, int32_t uid) const; 65 uint32_t GetStartAbilityTimeout(); 66 67 private: 68 bool ParseCollaborativeDeleteTypesDevices(std::map<std::string, std::map<std::string, 69 std::unordered_set<std::string>>>& map, nlohmann::json& collaborativeDeleteTypes) const; 70 bool ParseDeviceSlotType(const nlohmann::json& device, 71 std::map<std::string, std::unordered_set<std::string>>& peerDeviceTypeMap) const; 72 std::map<NotificationConstant::SlotType, uint32_t> defaultCurrentSlotReminder_; 73 std::vector<nlohmann::json> notificationConfigJsons_; 74 ffrt::mutex mutex_; 75 ffrt::mutex slotReminderMutex_; 76 std::vector<int32_t> uidList_; 77 std::vector<std::string> bundleNameList_; 78 std::set<std::string> reporteTrustSet_ {}; 79 80 public: 81 constexpr static const char* CFG_KEY_NOTIFICATION_SERVICE = "notificationService"; 82 constexpr static const char* CFG_KEY_SLOT_TYPE_REMINDER = "slotTypeReminder"; 83 constexpr static const char* CFG_KEY_NAME = "name"; 84 constexpr static const char* CFG_KEY_REMINDER_FLAGS = "reminderFlags"; 85 constexpr static const char* APP_PRIVILEGES = "appPrivileges"; 86 constexpr static const char* COLLABORATION_FILTER = "collaborationFilter"; 87 constexpr static const char* COLLABORATION_FILTER_KEY_NAME = "bundleName"; 88 constexpr static const char* COLLABORATION_FILTER_KEY_UID = "uid"; 89 constexpr static const char* CFG_KEY_MAX_CREATE_NUM_PERSECOND = "MaxCreateNumPerSecond"; 90 constexpr static const char* CFG_KEY_MAX_UPDATE_NUM_PERSECOND = "MaxUpdateNumPerSecond"; 91 constexpr static const char* CFG_KEY_MAX_CREATE_NUM_PERSECOND_PERAPP = "MaxCreateNumPerSecondPerApp"; 92 constexpr static const char* CFG_KEY_MAX_UPDATE_NUM_PERSECOND_PERAPP = "MaxUpdateNumPerSecondPerApp"; 93 constexpr static const char* CFG_KEY_SMART_REMINDER_ENABLE_LIST = "smartReminderEnableList"; 94 constexpr static const char* CFG_KEY_MIRROR_NOTIFICAITON_ENABLED_STATUS = "mirrorNotificationEnabledStatus"; 95 constexpr static const char* CFG_KEY_APP_AND_DEVICE_RELATION_MAP = "appAndDeviceRelationMap"; 96 constexpr static const char* CFG_KEY_DFX_NORMAL_EVENT = "dfxNormalEvent"; 97 #ifdef CONFIG_POLICY_ENABLE 98 constexpr static const char* NOTIFICAITON_CONFIG_FILE = "etc/notification/notification_config.json"; 99 # else 100 constexpr static const char* NOTIFICAITON_CONFIG_FILE = "system/etc/notification/notification_config.json"; 101 #endif 102 constexpr static const char* CFG_KEY_COLLABORATIVE_DELETE_TYPES = "collaborativeDeleteTypes"; 103 constexpr static const char* CFG_KEY_START_ABILITY_TIMEOUT = "startAbilityTimeout"; 104 constexpr static const char* CFG_KEY_COLLABORATIVE_DELETE_TYPES_DEVICES = "collaborativeDeleteTypesDevices"; 105 constexpr static const char* LOCAL_DEVICE_TYPE = "localDeviceType"; 106 constexpr static const char* PEER_DELETE_FILTER_DEVICE = "peerDeleteFilterDevice"; 107 constexpr static const char* PEER_DEVICE_TYPE = "peerDeviceType"; 108 constexpr static const char* DELETE_SLOT_TYPE = "deleteSlotTypes"; 109 }; 110 } // namespace Notification 111 } // namespace OHOS 112 113 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_NOTIFICATION_CONFIG_FILE_H 114