• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 SERVICES_INCLUDE_SYS_CFG_PARSE_H
17 #define SERVICES_INCLUDE_SYS_CFG_PARSE_H
18 
19 #include "input_method_status.h"
20 #include "input_method_utils.h"
21 #include "serializable.h"
22 namespace OHOS {
23 namespace MiscServices {
24 struct SystemConfig : public Serializable {
25     std::string systemInputMethodConfigAbility;
26     std::string defaultInputMethod;
27     std::string systemSpecialInputMethod;
28     bool enableInputMethodFeature = false;
29     bool enableFullExperienceFeature = false;
30     EnabledStatus initEnabledState{ EnabledStatus::DISABLED };
31     bool enableAppAgentFeature = false;
32     bool enableNumKeyFeature = false;
33     std::unordered_set<std::string> disableNumKeyAppDeviceTypes;
34     std::unordered_set<int32_t> proxyImeUidList;
35     std::unordered_set<int32_t> specialSaUidList;
36     std::unordered_set<std::string> defaultImeScreenList;
37     std::unordered_set<std::string> supportedCapacityList;
38     std::string dynamicStartImeSysParam;
39     std::string dynamicStartImeValue;
40 
UnmarshalSystemConfig41     bool Unmarshal(cJSON *node) override
42     {
43         GetValue(node, GET_NAME(systemInputMethodConfigAbility), systemInputMethodConfigAbility);
44         GetValue(node, GET_NAME(defaultInputMethod), defaultInputMethod);
45         GetValue(node, GET_NAME(systemSpecialInputMethod), systemSpecialInputMethod);
46         GetValue(node, GET_NAME(enableInputMethodFeature), enableInputMethodFeature);
47         GetValue(node, GET_NAME(enableFullExperienceFeature), enableFullExperienceFeature);
48         auto enableState = static_cast<int32_t>(EnabledStatus::DISABLED);
49         GetValue(node, GET_NAME(initEnabledState), enableState);
50         initEnabledState = static_cast<EnabledStatus>(enableState);
51         GetValue(node, GET_NAME(enableAppAgentFeature), enableAppAgentFeature);
52         GetValue(node, GET_NAME(enableNumKeyFeature), enableNumKeyFeature);
53         GetValue(node, GET_NAME(disableNumKeyAppDeviceTypes), disableNumKeyAppDeviceTypes);
54         GetValue(node, GET_NAME(proxyImeUidList), proxyImeUidList);
55         GetValue(node, GET_NAME(specialSaUidList), specialSaUidList);
56         GetValue(node, GET_NAME(defaultImeScreenList), defaultImeScreenList);
57         GetValue(node, GET_NAME(supportedCapacityList), supportedCapacityList);
58         GetValue(node, GET_NAME(dynamicStartImeSysParam), dynamicStartImeSysParam);
59         GetValue(node, GET_NAME(dynamicStartImeValue), dynamicStartImeValue);
60         return true;
61     }
62 };
63 struct ImeSystemConfig : public Serializable {
64     SystemConfig systemConfig;
UnmarshalImeSystemConfig65     bool Unmarshal(cJSON *node) override
66     {
67         return GetValue(node, GET_NAME(systemConfig), systemConfig);
68     }
69 };
70 
71 struct InputTypeInfo : public Serializable {
72     InputType type{ InputType::NONE };
73     std::string bundleName;
74     std::string subName;
UnmarshalInputTypeInfo75     bool Unmarshal(cJSON *node) override
76     {
77         int32_t typeTemp = -1;
78         auto ret = GetValue(node, GET_NAME(inputType), typeTemp);
79         if (typeTemp <= static_cast<int32_t>(InputType::NONE) || typeTemp >= static_cast<int32_t>(InputType::END)) {
80             return false;
81         }
82         type = static_cast<InputType>(typeTemp);
83         ret = GetValue(node, GET_NAME(bundleName), bundleName) && ret;
84         ret = GetValue(node, GET_NAME(subtypeId), subName) && ret;
85         return ret;
86     }
87 };
88 struct InputTypeCfg : public Serializable {
89     std::vector<InputTypeInfo> inputType;
UnmarshalInputTypeCfg90     bool Unmarshal(cJSON *node) override
91     {
92         return GetValue(node, GET_NAME(supportedInputTypeList), inputType);
93     }
94 };
95 
96 struct SysPanelAdjust : public Serializable {
97     std::vector<std::string> style;
98     int32_t top = 0;
99     int32_t left = 0;
100     int32_t right = 0;
101     int32_t bottom = 0;
UnmarshalSysPanelAdjust102     bool Unmarshal(cJSON *node) override
103     {
104         auto ret = GetValue(node, GET_NAME(style), style);
105         ret = GetValue(node, GET_NAME(top), top) && ret;
106         ret = GetValue(node, GET_NAME(left), left) && ret;
107         ret = GetValue(node, GET_NAME(right), right) && ret;
108         ret = GetValue(node, GET_NAME(bottom), bottom) && ret;
109         return ret;
110     }
111 };
112 
113 struct SysPanelAdjustCfg : public Serializable {
114     std::vector<SysPanelAdjust> panelAdjust;
UnmarshalSysPanelAdjustCfg115     bool Unmarshal(cJSON *node) override
116     {
117         return GetValue(node, GET_NAME(sysPanelAdjust), panelAdjust);
118     }
119 };
120 
121 struct DefaultFullImeInfo : public Serializable {
122     std::string appId;
123     std::string expirationTime;
124     uint32_t expirationVersionCode{ 0 };
UnmarshalDefaultFullImeInfo125     bool Unmarshal(cJSON *node) override
126     {
127         bool ret = GetValue(node, GET_NAME(appIdentifier), appId);
128         ret &= GetValue(node, GET_NAME(expirationTime), expirationTime);
129         GetValue(node, GET_NAME(expirationVersionCode), expirationVersionCode);
130         return ret;
131     }
132 };
133 
134 struct DefaultFullImeCfg : Serializable {
135     std::vector<DefaultFullImeInfo> defaultFullImeList;
UnmarshalDefaultFullImeCfg136     bool Unmarshal(cJSON *node) override
137     {
138         return GetValue(node, GET_NAME(defaultFullImeList), defaultFullImeList);
139     }
140 };
141 
142 struct IgnoreSysPanelAdjust : public Serializable {
143     std::vector<int32_t> inputType;
UnmarshalIgnoreSysPanelAdjust144     bool Unmarshal(cJSON *node) override
145     {
146         return GetValue(node, GET_NAME(inputType), inputType);
147     }
148 };
149 
150 struct IgnoreSysPanelAdjustCfg : public Serializable {
151     IgnoreSysPanelAdjust ignoreSysPanelAdjust;
UnmarshalIgnoreSysPanelAdjustCfg152     bool Unmarshal(cJSON *node) override
153     {
154         return GetValue(node, GET_NAME(ignoreSysPanelAdjust), ignoreSysPanelAdjust);
155     }
156 };
157 
158 class SysCfgParser {
159 public:
160     static bool ParseSystemConfig(SystemConfig &systemConfig);
161     static bool ParseInputType(std::vector<InputTypeInfo> &inputType);
162     static bool ParsePanelAdjust(std::vector<SysPanelAdjust> &sysPanelAdjust);
163     static bool ParseDefaultFullIme(std::vector<DefaultFullImeInfo> &defaultFullImeList);
164     static bool ParseIgnoreSysPanelAdjust(IgnoreSysPanelAdjust &ignoreSysPanelAdjust);
165 
166 private:
167     static std::string GetSysCfgContent(const std::string &key);
168 };
169 } // namespace MiscServices
170 } // namespace OHOS
171 #endif // SERVICES_INCLUDE_SYS_CFG_PARSE_H
172