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 SetCurrentSlotReminder( 48 std::map<NotificationConstant::SlotType, std::shared_ptr<NotificationFlags>> ¤tSlotReminder, 49 NotificationConstant::SlotType &slotType, std::shared_ptr<NotificationFlags> &reminderFlags); 50 void GetReportTrustListConfig(); 51 bool IsReportTrustList(const std::string& bundleName) const; 52 uint32_t GetConfigSlotReminderModeByType(NotificationConstant::SlotType slotType) const; 53 std::shared_ptr<NotificationAppPrivileges> GetAppPrivileges(const std::string &bundleName) const; 54 bool IsLiveViewEnabled(const std::string bundleName) const; 55 bool IsBannerEnabled(const std::string bundleName) const; 56 bool IsReminderEnabled(const std::string& bundleName) const; 57 void GetFlowCtrlConfigFromCCM(FlowControlThreshold &threshold); 58 bool GetSmartReminderEnableList(std::vector<std::string>& deviceTypes); 59 bool GetMirrorNotificationEnabledStatus(std::vector<std::string>& deviceTypes); 60 bool GetAppAndDeviceRelationMap(std::map<std::string, std::string>& relationMap); 61 std::unordered_set<std::string> GetCollaborativeDeleteType() 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 std::map<NotificationConstant::SlotType, uint32_t> defaultCurrentSlotReminder_; 69 std::vector<nlohmann::json> notificationConfigJsons_; 70 std::mutex mutex_; 71 std::mutex slotReminderMutex_; 72 std::vector<int32_t> uidList_; 73 std::vector<std::string> bundleNameList_; 74 std::set<std::string> reporteTrustSet_ {}; 75 76 public: 77 constexpr static const char* CFG_KEY_NOTIFICATION_SERVICE = "notificationService"; 78 constexpr static const char* CFG_KEY_SLOT_TYPE_REMINDER = "slotTypeReminder"; 79 constexpr static const char* CFG_KEY_NAME = "name"; 80 constexpr static const char* CFG_KEY_REMINDER_FLAGS = "reminderFlags"; 81 constexpr static const char* APP_PRIVILEGES = "appPrivileges"; 82 constexpr static const char* COLLABORATION_FILTER = "collaborationFilter"; 83 constexpr static const char* COLLABORATION_FILTER_KEY_NAME = "bundleName"; 84 constexpr static const char* COLLABORATION_FILTER_KEY_UID = "uid"; 85 constexpr static const char* CFG_KEY_MAX_CREATE_NUM_PERSECOND = "MaxCreateNumPerSecond"; 86 constexpr static const char* CFG_KEY_MAX_UPDATE_NUM_PERSECOND = "MaxUpdateNumPerSecond"; 87 constexpr static const char* CFG_KEY_MAX_CREATE_NUM_PERSECOND_PERAPP = "MaxCreateNumPerSecondPerApp"; 88 constexpr static const char* CFG_KEY_MAX_UPDATE_NUM_PERSECOND_PERAPP = "MaxUpdateNumPerSecondPerApp"; 89 constexpr static const char* CFG_KEY_SMART_REMINDER_ENABLE_LIST = "smartReminderEnableList"; 90 constexpr static const char* CFG_KEY_MIRROR_NOTIFICAITON_ENABLED_STATUS = "mirrorNotificationEnabledStatus"; 91 constexpr static const char* CFG_KEY_APP_AND_DEVICE_RELATION_MAP = "appAndDeviceRelationMap"; 92 constexpr static const char* CFG_KEY_DFX_NORMAL_EVENT = "dfxNormalEvent"; 93 #ifdef CONFIG_POLICY_ENABLE 94 constexpr static const char* NOTIFICAITON_CONFIG_FILE = "etc/notification/notification_config.json"; 95 # else 96 constexpr static const char* NOTIFICAITON_CONFIG_FILE = "system/etc/notification/notification_config.json"; 97 #endif 98 constexpr static const char* CFG_KEY_COLLABORATIVE_DELETE_TYPES = "collaborativeDeleteTypes"; 99 constexpr static const char* CFG_KEY_START_ABILITY_TIMEOUT = "startAbilityTimeout"; 100 }; 101 } // namespace Notification 102 } // namespace OHOS 103 104 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_NOTIFICATION_CONFIG_FILE_H 105