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 "ime_cfg_manager.h" 21 #include "input_method_info.h" 22 #include "input_method_property.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); 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, uint32_t cacheCount); 88 bool IsEnableInputMethod(); 89 bool IsEnableSecurityMode(); 90 bool IsEnableAppAgent(); 91 bool IsEnableNumKey(); 92 bool IsProxyIme(int32_t callingUid); 93 bool IsSpecialSaUid(int32_t callingUid); 94 void InitSystemConfig(); 95 SystemConfig GetSystemConfig(); 96 ImeNativeCfg GetDefaultIme(); 97 std::string GetSystemSpecialIme(); 98 int32_t QueryFullImeInfo(std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &imeInfos); 99 int32_t QueryFullImeInfo(int32_t userId, std::vector<FullImeInfo> &imeInfos, bool needBrief = false); 100 int32_t GetFullImeInfo(int32_t userId, const std::string &bundleName, FullImeInfo &imeInfo); 101 bool IsInputMethod(int32_t userId, const std::string &bundleName); 102 bool IsRunningIme(int32_t userId, const std::string &bundleName); 103 std::vector<std::string> GetRunningIme(int32_t userId); 104 bool IsDefaultImeSet(int32_t userId); 105 bool IsImeInstalled(const int32_t userId, const std::string &bundleName, const std::string &extName); 106 bool IsInputMethodExtension(pid_t pid); 107 bool IsRestrictedDefaultImeByDisplay(uint64_t displayId); 108 bool IsDynamicStartIme(); 109 std::unordered_set<std::string> GetDisableNumKeyAppDeviceTypes(); 110 bool IsCapacitySupport(const std::string &capacityName); 111 bool GetCompatibleDeviceType(const std::string &bundleName, std::string &compatibleDeviceType); 112 113 private: 114 ImeInfoInquirer() = default; 115 ~ImeInfoInquirer() = default; 116 OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 117 SubProperty GetExtends(const std::vector<OHOS::AppExecFwk::Metadata> &metaData); 118 std::string GetTargetString( 119 const AppExecFwk::ExtensionAbilityInfo &extension, ImeTargetString target, int32_t userId); 120 std::string GetStringById(const std::string &bundleName, const std::string &moduleName, const uint32_t labelId, 121 const int32_t userId); 122 bool GetBundleInfoByBundleName(int32_t userId, const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo); 123 std::shared_ptr<ImeInfo> GetImeInfoFromCache(const int32_t userId, const std::string &bundleName, 124 const std::string &subName); 125 std::shared_ptr<ImeInfo> GetImeInfoFromBundleMgr( 126 const int32_t userId, const std::string &bundleName, const std::string &subName); 127 int32_t GetExtInfosByBundleName(const int32_t userId, const std::string &bundleName, 128 std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos); 129 bool IsNewExtInfos(const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos); 130 std::vector<InputMethodInfo> ListInputMethodInfo(const int32_t userId); 131 int32_t ListInputMethod(const int32_t userId, std::vector<Property> &props); 132 int32_t ListEnabledInputMethod(const int32_t userId, std::vector<Property> &props); 133 int32_t ListDisabledInputMethod(const int32_t userId, std::vector<Property> &props); 134 int32_t ListAllInputMethod(const int32_t userId, std::vector<Property> &props); 135 int32_t ListInputMethodSubtype(const int32_t userId, 136 const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, std::vector<SubProperty> &subProps); 137 int32_t ListInputMethodSubtype(const int32_t userId, const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, 138 std::vector<SubProperty> &subProps); 139 int32_t GetSubProperty(int32_t userId, const std::string &subName, 140 const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, SubProperty &subProp); 141 int32_t GetSubProperty(int32_t userId, const std::string &subName, 142 const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, SubProperty &subProp); 143 int32_t ParseSubtype(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, std::vector<Subtype> &subtypes); 144 bool ParseSubtypeProfile(const std::vector<std::string> &profiles, SubtypeCfg &subtypeCfg); 145 void CovertToLanguage(const std::string &locale, std::string &language); 146 bool QueryImeExtInfos(const int32_t userId, std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &infos); 147 std::shared_ptr<Global::Resource::ResourceManager> GetResMgr(const std::string &resourcePath); 148 int32_t GetFullImeInfo(int32_t userId, const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, 149 FullImeInfo &imeInfo, bool needBrief = false); 150 151 SystemConfig systemConfig_; 152 bool IsTempInputMethod(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo); 153 }; 154 } // namespace MiscServices 155 } // namespace OHOS 156 #endif // SERVICES_INCLUDE_IME_INFO_ENQUIRER_H 157