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