• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 ENABLE_UPGRADE_MANAGER_H
17 #define ENABLE_UPGRADE_MANAGER_H
18 #include <set>
19 
20 #include "event_handler.h"
21 #include "ime_enabled_info_manager.h"
22 #include "input_method_property.h"
23 #include "input_method_status.h"
24 #include "serializable.h"
25 #include "settings_data_utils.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 struct ImePersistInfo : public Serializable {
30     ImePersistInfo() = default;
ImePersistInfoImePersistInfo31     ImePersistInfo(int32_t userId, std::string currentIme, std::string currentSubName, bool isDefaultImeSet)
32         : userId(userId), currentIme(std::move(currentIme)), currentSubName(std::move(currentSubName)),
33           isDefaultImeSet(isDefaultImeSet){};
34     static constexpr int32_t INVALID_USERID = -1;
35     int32_t userId{ INVALID_USERID };
36     std::string currentIme;
37     std::string currentSubName;
38     std::string tempScreenLockIme;
39     bool isDefaultImeSet{ false };
40 
MarshalImePersistInfo41     bool Marshal(cJSON *node) const override
42     {
43         auto ret = SetValue(node, GET_NAME(userId), userId);
44         ret = SetValue(node, GET_NAME(currentIme), currentIme) && ret;
45         ret = SetValue(node, GET_NAME(currentSubName), currentSubName) && ret;
46         SetValue(node, GET_NAME(tempScreenLockIme), tempScreenLockIme);
47         ret = SetValue(node, GET_NAME(isDefaultImeSet), isDefaultImeSet) && ret;
48         return ret;
49     }
UnmarshalImePersistInfo50     bool Unmarshal(cJSON *node) override
51     {
52         auto ret = GetValue(node, GET_NAME(userId), userId);
53         ret = GetValue(node, GET_NAME(currentIme), currentIme) && ret;
54         ret = GetValue(node, GET_NAME(currentSubName), currentSubName) && ret;
55         GetValue(node, GET_NAME(tempScreenLockIme), tempScreenLockIme);
56         ret = GetValue(node, GET_NAME(isDefaultImeSet), isDefaultImeSet) && ret;
57         return ret;
58     }
59 };
60 
61 struct ImePersistCfg : public Serializable {
62     std::vector<ImePersistInfo> imePersistInfo;
MarshalImePersistCfg63     bool Marshal(cJSON *node) const override
64     {
65         return SetValue(node, GET_NAME(imeCfgList), imePersistInfo);
66     }
UnmarshalImePersistCfg67     bool Unmarshal(cJSON *node) override
68     {
69         return GetValue(node, GET_NAME(imeCfgList), imePersistInfo);
70     }
71 };
72 
73 struct UserImeConfig : public Serializable {
74     std::string userId;
75     std::vector<std::string> identities;
UnmarshalUserImeConfig76     bool Unmarshal(cJSON *node) override
77     {
78         return GetValue(node, userId, identities);
79     }
MarshalUserImeConfig80     bool Marshal(cJSON *node) const override
81     {
82         return SetValue(node, userId, identities);
83     }
84 };
85 struct EnabledImeCfg : public Serializable {
86     UserImeConfig userImeCfg;
UnmarshalEnabledImeCfg87     bool Unmarshal(cJSON *node) override
88     {
89         return GetValue(node, GET_NAME(enableImeList), userImeCfg);
90     }
MarshalEnabledImeCfg91     bool Marshal(cJSON *node) const override
92     {
93         return SetValue(node, GET_NAME(enableImeList), userImeCfg);
94     }
95 };
96 struct SecurityModeCfg : public Serializable {
97     UserImeConfig userImeCfg;
UnmarshalSecurityModeCfg98     bool Unmarshal(cJSON *node) override
99     {
100         return GetValue(node, GET_NAME(fullExperienceList), userImeCfg);
101     }
102 };
103 class EnableUpgradeManager {
104 public:
105     static EnableUpgradeManager &GetInstance();
106     int32_t Upgrade(int32_t userId, const std::vector<FullImeInfo> &imeInfos);
107     int32_t GetFullExperienceTable(int32_t userId, std::set<std::string> &bundleNames);
108     /* add for compatibility that sys ime listen global table change for smart menu in tablet */
109     void UpdateGlobalEnabledTable(int32_t userId, const ImeEnabledCfg &newEnabledCfg);
110 
111 private:
112     EnableUpgradeManager() = default;
113     ~EnableUpgradeManager() = default;
114     int32_t GetEnabledTable(int32_t userId, std::set<std::string> &bundleNames);
115     int32_t GetUserEnabledTable(int32_t userId, std::string &content);
116     int32_t GetUserEnabledTable(int32_t userId, std::set<std::string> &bundleNames);
117     int32_t GetGlobalEnabledTable(int32_t userId, std::set<std::string> &bundleNames);
118     int32_t GetGlobalEnabledTable(int32_t userId, std::string &content);
119     int32_t GetEnabledTable(int32_t userId, const std::string &uriProxy, std::set<std::string> &bundleNames);
120     int32_t GetEnabledTable(int32_t userId, const std::string &uriProxy, std::string &content);
121     int32_t ParseEnabledTable(int32_t userId, std::string &content, std::set<std::string> &bundleNames);
122     int32_t GetGlobalTableUserId(const std::string &valueStr);
123     std::string GenerateGlobalContent(int32_t userId, const std::vector<std::string> &bundleNames);
124     bool SetGlobalEnabledTable(const std::string &content);
125     bool SetUserEnabledTable(int32_t userId, const std::string &content);
126     bool SetEnabledTable(const std::string &uriProxy, const std::string &content);
127     int32_t MergeTwoTable(int32_t userId, std::vector<ImeEnabledInfo> &enabledInfos);
128     int32_t PaddedByBundleMgr(
129         int32_t userId, const std::vector<FullImeInfo> &imeInfos, std::vector<ImeEnabledInfo> &enabledInfos);
130     int32_t PaddedByImePersistCfg(int32_t userId, std::vector<ImeEnabledInfo> &enabledInfos);
131     EnabledStatus ComputeEnabledStatus(const std::string &bundleName, EnabledStatus initStatus);
132     int32_t GetImePersistCfg(int32_t userId, ImePersistInfo &persisInfo);
133     std::mutex upgradedLock_;
134     std::set<int32_t> upgradedUserId_;
135 };
136 } // namespace MiscServices
137 } // namespace OHOS
138 
139 #endif // ENABLE_UPGRADE_MANAGER_H