• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_IME_INFO_ENQUIRER_H
17 #define SERVICES_INCLUDE_IME_INFO_ENQUIRER_H
18 
19 #include <application_info.h>
20 
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <vector>
25 #include "bundle_mgr_proxy.h"
26 #include "element_name.h"
27 #include "enable_ime_data_parser.h"
28 #include "ime_cfg_manager.h"
29 #include "input_method_info.h"
30 #include "input_method_property.h"
31 #include "input_method_status.h"
32 #include "refbase.h"
33 #include "resource_manager.h"
34 #include "sys_cfg_parser.h"
35 namespace OHOS {
36 namespace MiscServices {
37 enum class Condition {
38     UPPER = 0,
39     LOWER,
40     ENGLISH,
41     CHINESE,
42 };
43 
44 enum class ImeTargetString {
45     LABEL = 0,
46     DESCRIPTION,
47 };
48 
49 struct Subtype : public Serializable {
50     std::string label;
51     std::string id;
52     std::string icon;
53     std::string mode;
54     std::string locale;
UnmarshalSubtype55     bool Unmarshal(cJSON *node) override
56     {
57         GetValue(node, GET_NAME(label), label);
58         auto ret = GetValue(node, GET_NAME(id), id);
59         GetValue(node, GET_NAME(icon), icon);
60         GetValue(node, GET_NAME(mode), mode);
61         GetValue(node, GET_NAME(locale), locale);
62         return ret;
63     }
64 };
65 struct SubtypeCfg : public Serializable {
66     static constexpr uint32_t MAX_SUBTYPE_NUM = 256;
67     std::vector<Subtype> subtypes;
UnmarshalSubtypeCfg68     bool Unmarshal(cJSON *node) override
69     {
70         return GetValue(node, GET_NAME(subtypes), subtypes, MAX_SUBTYPE_NUM);
71     }
72 };
73 
74 class ImeInfoInquirer {
75 public:
76     using CompareHandler = std::function<bool(const SubProperty &)>;
77     static ImeInfoInquirer &GetInstance();
78     std::string GetDumpInfo(int32_t userId);
79     std::shared_ptr<ImeNativeCfg> GetImeToStart(int32_t userId);
80     std::shared_ptr<Property> GetImeProperty(
81         int32_t userId, const std::string &bundleName, const std::string &extName = "");
82     std::shared_ptr<Property> GetCurrentInputMethod(int32_t userId);
83     std::shared_ptr<SubProperty> GetCurrentSubtype(int32_t userId);
84     std::shared_ptr<ImeInfo> GetImeInfo(int32_t userId, const std::string &bundleName, const std::string &subName);
85     std::shared_ptr<ImeInfo> GetDefaultImeInfo(int32_t userId);
86     std::shared_ptr<Property> GetDefaultImeCfgProp();
87     std::shared_ptr<SubProperty> FindTargetSubtypeByCondition(const std::vector<SubProperty> &subProps,
88         const Condition &condition);
89     bool GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId);
90     bool GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode);
91     int32_t GetDefaultInputMethod(const int32_t userId, std::shared_ptr<Property> &prop, bool isBrief = false);
92     int32_t GetInputMethodConfig(const int32_t userId, AppExecFwk::ElementName &inputMethodConfig);
93     int32_t ListInputMethod(int32_t userId, InputMethodStatus status, std::vector<Property> &props, bool enableOn);
94     int32_t ListInputMethodSubtype(int32_t userId, const std::string &bundleName, std::vector<SubProperty> &subProps);
95     int32_t ListCurrentInputMethodSubtype(int32_t userId, std::vector<SubProperty> &subProps);
96     int32_t GetSwitchInfoBySwitchCount(SwitchInfo &switchInfo, int32_t userId, bool enableOn, uint32_t cacheCount);
97     bool IsEnableInputMethod();
98     bool IsEnableSecurityMode();
99     void InitSystemConfig();
100     ImeNativeCfg GetDefaultIme();
101     int32_t QueryFullImeInfo(std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &imeInfos);
102     int32_t QueryFullImeInfo(int32_t userId, std::vector<FullImeInfo> &imeInfos);
103     int32_t GetFullImeInfo(int32_t userId, const std::string &bundleName, FullImeInfo &imeInfo);
104     bool IsInputMethod(int32_t userId, const std::string &bundleName);
105     bool IsRunningIme(int32_t userId, const std::string &bundleName);
106     std::vector<std::string> GetRunningIme(int32_t userId);
107 
108 private:
109     ImeInfoInquirer() = default;
110     ~ImeInfoInquirer() = default;
111     OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr();
112     SubProperty GetExtends(const std::vector<OHOS::AppExecFwk::Metadata> &metaData);
113     std::string GetTargetString(
114         const AppExecFwk::ExtensionAbilityInfo &extension, ImeTargetString target, int32_t userId);
115     std::string GetStringById(const std::string &bundleName, const std::string &moduleName, const uint32_t labelId,
116         const int32_t userId);
117     bool GetBundleInfoByBundleName(int32_t userId, const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo);
118     std::shared_ptr<ImeInfo> GetImeInfoFromCache(const int32_t userId, const std::string &bundleName,
119         const std::string &subName);
120     std::shared_ptr<ImeInfo> GetImeInfoFromBundleMgr(
121         const int32_t userId, const std::string &bundleName, const std::string &subName);
122     int32_t GetExtInfosByBundleName(const int32_t userId, const std::string &bundleName,
123         std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos);
124     bool IsNewExtInfos(const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos);
125     bool IsImeInstalled(const int32_t userId, const std::string &bundleName, const std::string &extName);
126     std::vector<InputMethodInfo> ListInputMethodInfo(const int32_t userId);
127     int32_t ListInputMethod(const int32_t userId, std::vector<Property> &props);
128     int32_t ListEnabledInputMethod(const int32_t userId, std::vector<Property> &props, bool enableOn);
129     int32_t ListDisabledInputMethod(const int32_t userId, std::vector<Property> &props, bool enableOn);
130     int32_t ListInputMethodSubtype(const int32_t userId,
131         const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, std::vector<SubProperty> &subProps);
132     int32_t ListInputMethodSubtype(const int32_t userId, const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo,
133         std::vector<SubProperty> &subProps);
134     int32_t GetSubProperty(int32_t userId, const std::string &subName,
135         const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, SubProperty &subProp);
136     int32_t GetSubProperty(int32_t userId, const std::string &subName,
137         const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, SubProperty &subProp);
138     int32_t ParseSubtype(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, std::vector<Subtype> &subtypes);
139     bool ParseSubtypeProfile(const std::vector<std::string> &profiles, SubtypeCfg &subtypeCfg);
140     void CovertToLanguage(const std::string &locale, std::string &language);
141     bool QueryImeExtInfos(const int32_t userId, std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &infos);
142     std::shared_ptr<Global::Resource::ResourceManager> GetResMgr(const std::string &resourcePath);
143     int32_t GetFullImeInfo(
144         int32_t userId, const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, FullImeInfo &imeInfo);
145 
146     SystemConfig systemConfig_;
147     bool IsTempInputMethod(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo);
148 };
149 } // namespace MiscServices
150 } // namespace OHOS
151 #endif // SERVICES_INCLUDE_IME_INFO_ENQUIRER_H
152