• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <memory>
17 
18 #include "notification_config_parse.h"
19 
20 #include "ans_log_wrapper.h"
21 #ifdef ENABLE_ANS_ADDITIONAL_CONTROL
22 #include "notification_extension_wrapper.h"
23 #endif
24 #include "notification_slot.h"
25 #include "file_utils.h"
26 #include "mock_device_manager_impl.h"
27 
28 namespace OHOS {
29 namespace Notification {
30 static int32_t g_configScene = -1;
31 constexpr int32_t CONFIG_SCENE_0 = 0;
32 constexpr int32_t CONFIG_SCENE_1 = 1;
33 constexpr int32_t CONFIG_SCENE_2 = 2;
34 constexpr int32_t CONFIG_SCENE_3 = 3;
35 constexpr int32_t CONFIG_SCENE_4 = 4;
36 constexpr int32_t DEFAULT_TITLE_LENGTH = 200;
37 constexpr int32_t DEFAULT_CONTENT_LENGTH = 400;
38 constexpr int32_t MOCK_DEFAULT_REPLY_TIMEOUT = 3;
39 
MockConfigScene(int32_t scene)40 void DeviceTrigger::MockConfigScene(int32_t scene)
41 {
42     g_configScene = scene;
43 }
44 
NotificationConfigParse()45 NotificationConfigParse::NotificationConfigParse()
46 {
47 }
48 
GetAppPrivileges(const std::string & bundleName) const49 std::shared_ptr<NotificationAppPrivileges> NotificationConfigParse::GetAppPrivileges(
50     const std::string &bundleName) const
51 {
52     return nullptr;
53 }
54 
GetConfigJson(const std::string & keyCheck,nlohmann::json & configJson) const55 bool NotificationConfigParse::GetConfigJson(const std::string &keyCheck, nlohmann::json &configJson) const
56 {
57     if (g_configScene == CONFIG_SCENE_0) {
58         return false;
59     }
60     if (g_configScene == CONFIG_SCENE_1) {
61         return true;
62     }
63     if (g_configScene == CONFIG_SCENE_2) {
64         nlohmann::json distribuedConfig;
65         nlohmann::json notificationService;
66         notificationService["distribuedConfig"] = distribuedConfig;
67         configJson["notificationService"] = notificationService;
68         return true;
69     }
70     if (g_configScene == CONFIG_SCENE_3) {
71         nlohmann::json distribuedConfig;
72         distribuedConfig["maxContentLength"] = std::string();
73         nlohmann::json notificationService;
74         notificationService["distribuedConfig"] = distribuedConfig;
75         configJson["notificationService"] = notificationService;
76         return true;
77     }
78     if (g_configScene == CONFIG_SCENE_4) {
79         nlohmann::json distribuedConfig;
80         nlohmann::json supportPeerDevice = nlohmann::json::array();
81         supportPeerDevice.emplace_back("Watch");
82         distribuedConfig["supportPeerDevice"] = supportPeerDevice;
83         nlohmann::json notificationService;
84         notificationService["distribuedConfig"] = distribuedConfig;
85         configJson["notificationService"] = notificationService;
86         return true;
87     }
88     nlohmann::json distribuedConfig;
89     nlohmann::json supportPeerDevice = nlohmann::json::array();
90     supportPeerDevice.emplace_back("Watch");
91     distribuedConfig["localType"] = "Phone";
92     distribuedConfig["supportPeerDevice"] = supportPeerDevice;
93     distribuedConfig["maxTitleLength"] = DEFAULT_TITLE_LENGTH;
94     distribuedConfig["maxContentLength"] = DEFAULT_CONTENT_LENGTH;
95     nlohmann::json notificationService;
96     notificationService["distribuedConfig"] = distribuedConfig;
97     configJson["notificationService"] = notificationService;
98     return true;
99 }
100 
GetCurrentSlotReminder(std::map<NotificationConstant::SlotType,std::shared_ptr<NotificationFlags>> & currentSlotReminder) const101 bool NotificationConfigParse::GetCurrentSlotReminder(
102     std::map<NotificationConstant::SlotType, std::shared_ptr<NotificationFlags>> &currentSlotReminder) const
103 {
104     return true;
105 }
106 
GetConfigSlotReminderModeByType(NotificationConstant::SlotType slotType)107 uint32_t NotificationConfigParse::GetConfigSlotReminderModeByType(NotificationConstant::SlotType slotType)
108 {
109     return 0;
110 }
111 
IsLiveViewEnabled(const std::string bundleName) const112 bool NotificationConfigParse::IsLiveViewEnabled(const std::string bundleName) const
113 {
114     return true;
115 }
116 
IsReminderEnabled(const std::string & bundleName) const117 bool NotificationConfigParse::IsReminderEnabled(const std::string& bundleName) const
118 {
119     return true;
120 }
121 
IsDistributedReplyEnabled(const std::string & bundleName) const122 bool NotificationConfigParse::IsDistributedReplyEnabled(const std::string& bundleName) const
123 {
124     return true;
125 }
126 
IsBannerEnabled(const std::string bundleName) const127 bool NotificationConfigParse::IsBannerEnabled(const std::string bundleName) const
128 {
129     return false;
130 }
131 
GetFlowCtrlConfigFromCCM(FlowControlThreshold & threshold)132 void NotificationConfigParse::GetFlowCtrlConfigFromCCM(FlowControlThreshold &threshold)
133 {
134 }
135 
GetSmartReminderEnableList(std::vector<std::string> & deviceTypes)136 bool NotificationConfigParse::GetSmartReminderEnableList(std::vector<std::string>& deviceTypes)
137 {
138     return true;
139 }
140 
GetMirrorNotificationEnabledStatus(std::vector<std::string> & deviceTypes)141 bool NotificationConfigParse::GetMirrorNotificationEnabledStatus(std::vector<std::string>& deviceTypes)
142 {
143     return true;
144 }
145 
GetAppAndDeviceRelationMap(std::map<std::string,std::string> & relationMap)146 bool NotificationConfigParse::GetAppAndDeviceRelationMap(std::map<std::string, std::string>& relationMap)
147 {
148     return true;
149 }
150 
GetCollaborativeDeleteType() const151 std::unordered_set<std::string> NotificationConfigParse::GetCollaborativeDeleteType() const
152 {
153     std::unordered_set<std::string> collaborativeDeleteTypeSet;
154     collaborativeDeleteTypeSet.insert("LIVE_VIEW");
155     collaborativeDeleteTypeSet.insert("SOCIAL_COMMUNICATION");
156     return collaborativeDeleteTypeSet;
157 }
158 
GetFilterUidAndBundleName(const std::string & key)159 bool NotificationConfigParse::GetFilterUidAndBundleName(const std::string &key)
160 {
161     return false;
162 }
163 
GetCollaborationFilter()164 void NotificationConfigParse::GetCollaborationFilter()
165 {
166 }
167 
IsInCollaborationFilter(const std::string & bundleName,int32_t uid) const168 bool NotificationConfigParse::IsInCollaborationFilter(const std::string& bundleName, int32_t uid) const
169 {
170     return false;
171 }
172 
GetStartAbilityTimeout()173 uint32_t NotificationConfigParse::GetStartAbilityTimeout()
174 {
175     return MOCK_DEFAULT_REPLY_TIMEOUT;
176 }
177 
GetReportTrustListConfig()178 void NotificationConfigParse::GetReportTrustListConfig()
179 {
180     return;
181 }
182 
IsReportTrustList(const std::string & bundleName) const183 bool NotificationConfigParse::IsReportTrustList(const std::string& bundleName) const
184 {
185     return true;
186 }
187 
GetCollaborativeDeleteTypeByDevice(std::map<std::string,std::map<std::string,std::unordered_set<std::string>>> & resultMap) const188 bool NotificationConfigParse::GetCollaborativeDeleteTypeByDevice(std::map<std::string,
189     std::map<std::string, std::unordered_set<std::string>>>& resultMap) const
190 {
191     return true;
192 }
193 } // namespace Notification
194 } // namespace OHOS
195 
196