122736c2fSopenharmony_ci/* 222736c2fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 422736c2fSopenharmony_ci * you may not use this file except in compliance with the License. 522736c2fSopenharmony_ci * You may obtain a copy of the License at 622736c2fSopenharmony_ci * 722736c2fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 822736c2fSopenharmony_ci * 922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and 1322736c2fSopenharmony_ci * limitations under the License. 1422736c2fSopenharmony_ci */ 1522736c2fSopenharmony_ci 1622736c2fSopenharmony_ci#ifndef SERVICES_INCLUDE_IME_INFO_ENQUIRER_H 1722736c2fSopenharmony_ci#define SERVICES_INCLUDE_IME_INFO_ENQUIRER_H 1822736c2fSopenharmony_ci 1922736c2fSopenharmony_ci#include <application_info.h> 2022736c2fSopenharmony_ci#include <memory> 2122736c2fSopenharmony_ci#include <mutex> 2222736c2fSopenharmony_ci#include <string> 2322736c2fSopenharmony_ci#include <vector> 2422736c2fSopenharmony_ci#include "bundle_mgr_proxy.h" 2522736c2fSopenharmony_ci#include "element_name.h" 2622736c2fSopenharmony_ci#include "enable_ime_data_parser.h" 2722736c2fSopenharmony_ci#include "ime_cfg_manager.h" 2822736c2fSopenharmony_ci#include "input_method_info.h" 2922736c2fSopenharmony_ci#include "input_method_property.h" 3022736c2fSopenharmony_ci#include "input_method_status.h" 3122736c2fSopenharmony_ci#include "refbase.h" 3222736c2fSopenharmony_ci#include "resource_manager.h" 3322736c2fSopenharmony_ci#include "sys_cfg_parser.h" 3422736c2fSopenharmony_cinamespace OHOS { 3522736c2fSopenharmony_cinamespace MiscServices { 3622736c2fSopenharmony_cienum class Condition { 3722736c2fSopenharmony_ci UPPER = 0, 3822736c2fSopenharmony_ci LOWER, 3922736c2fSopenharmony_ci ENGLISH, 4022736c2fSopenharmony_ci CHINESE, 4122736c2fSopenharmony_ci}; 4222736c2fSopenharmony_ci 4322736c2fSopenharmony_cienum class ImeTargetString { 4422736c2fSopenharmony_ci LABEL = 0, 4522736c2fSopenharmony_ci DESCRIPTION, 4622736c2fSopenharmony_ci}; 4722736c2fSopenharmony_ci 4822736c2fSopenharmony_cistruct Subtype : public Serializable { 4922736c2fSopenharmony_ci std::string label; 5022736c2fSopenharmony_ci std::string id; 5122736c2fSopenharmony_ci std::string icon; 5222736c2fSopenharmony_ci std::string mode; 5322736c2fSopenharmony_ci std::string locale; 5422736c2fSopenharmony_ci bool Unmarshal(cJSON *node) override 5522736c2fSopenharmony_ci { 5622736c2fSopenharmony_ci GetValue(node, GET_NAME(label), label); 5722736c2fSopenharmony_ci auto ret = GetValue(node, GET_NAME(id), id); 5822736c2fSopenharmony_ci GetValue(node, GET_NAME(icon), icon); 5922736c2fSopenharmony_ci GetValue(node, GET_NAME(mode), mode); 6022736c2fSopenharmony_ci GetValue(node, GET_NAME(locale), locale); 6122736c2fSopenharmony_ci return ret; 6222736c2fSopenharmony_ci } 6322736c2fSopenharmony_ci}; 6422736c2fSopenharmony_cistruct SubtypeCfg : public Serializable { 6522736c2fSopenharmony_ci static constexpr uint32_t MAX_SUBTYPE_NUM = 256; 6622736c2fSopenharmony_ci std::vector<Subtype> subtypes; 6722736c2fSopenharmony_ci bool Unmarshal(cJSON *node) override 6822736c2fSopenharmony_ci { 6922736c2fSopenharmony_ci return GetValue(node, GET_NAME(subtypes), subtypes, MAX_SUBTYPE_NUM); 7022736c2fSopenharmony_ci } 7122736c2fSopenharmony_ci}; 7222736c2fSopenharmony_ci 7322736c2fSopenharmony_ciclass ImeInfoInquirer { 7422736c2fSopenharmony_cipublic: 7522736c2fSopenharmony_ci using CompareHandler = std::function<bool(const SubProperty &)>; 7622736c2fSopenharmony_ci static ImeInfoInquirer &GetInstance(); 7722736c2fSopenharmony_ci std::string GetDumpInfo(int32_t userId); 7822736c2fSopenharmony_ci std::shared_ptr<ImeNativeCfg> GetImeToStart(int32_t userId); 7922736c2fSopenharmony_ci std::shared_ptr<Property> GetImeProperty( 8022736c2fSopenharmony_ci int32_t userId, const std::string &bundleName, const std::string &extName = ""); 8122736c2fSopenharmony_ci std::shared_ptr<Property> GetCurrentInputMethod(int32_t userId); 8222736c2fSopenharmony_ci std::shared_ptr<SubProperty> GetCurrentSubtype(int32_t userId); 8322736c2fSopenharmony_ci std::shared_ptr<ImeInfo> GetImeInfo(int32_t userId, const std::string &bundleName, const std::string &subName); 8422736c2fSopenharmony_ci std::shared_ptr<ImeInfo> GetDefaultImeInfo(int32_t userId); 8522736c2fSopenharmony_ci std::shared_ptr<Property> GetDefaultImeCfgProp(); 8622736c2fSopenharmony_ci std::shared_ptr<SubProperty> FindTargetSubtypeByCondition(const std::vector<SubProperty> &subProps, 8722736c2fSopenharmony_ci const Condition &condition); 8822736c2fSopenharmony_ci bool GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId); 8922736c2fSopenharmony_ci bool GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode); 9022736c2fSopenharmony_ci int32_t GetDefaultInputMethod(const int32_t userId, std::shared_ptr<Property> &prop, bool isBrief = false); 9122736c2fSopenharmony_ci int32_t GetInputMethodConfig(const int32_t userId, AppExecFwk::ElementName &inputMethodConfig); 9222736c2fSopenharmony_ci int32_t ListInputMethod(int32_t userId, InputMethodStatus status, std::vector<Property> &props, bool enableOn); 9322736c2fSopenharmony_ci int32_t ListInputMethodSubtype(int32_t userId, const std::string &bundleName, std::vector<SubProperty> &subProps); 9422736c2fSopenharmony_ci int32_t ListCurrentInputMethodSubtype(int32_t userId, std::vector<SubProperty> &subProps); 9522736c2fSopenharmony_ci int32_t GetSwitchInfoBySwitchCount(SwitchInfo &switchInfo, int32_t userId, bool enableOn, uint32_t cacheCount); 9622736c2fSopenharmony_ci bool IsEnableInputMethod(); 9722736c2fSopenharmony_ci bool IsEnableSecurityMode(); 9822736c2fSopenharmony_ci void InitSystemConfig(); 9922736c2fSopenharmony_ci ImeNativeCfg GetDefaultIme(); 10022736c2fSopenharmony_ci int32_t QueryFullImeInfo(std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &imeInfos); 10122736c2fSopenharmony_ci int32_t QueryFullImeInfo(int32_t userId, std::vector<FullImeInfo> &imeInfos); 10222736c2fSopenharmony_ci int32_t GetFullImeInfo(int32_t userId, const std::string &bundleName, FullImeInfo &imeInfo); 10322736c2fSopenharmony_ci bool IsInputMethod(int32_t userId, const std::string &bundleName); 10422736c2fSopenharmony_ci bool IsRunningIme(int32_t userId, const std::string &bundleName); 10522736c2fSopenharmony_ci std::vector<std::string> GetRunningIme(int32_t userId); 10622736c2fSopenharmony_ci bool IsDefaultImeSet(int32_t userId); 10722736c2fSopenharmony_ci 10822736c2fSopenharmony_ciprivate: 10922736c2fSopenharmony_ci ImeInfoInquirer() = default; 11022736c2fSopenharmony_ci ~ImeInfoInquirer() = default; 11122736c2fSopenharmony_ci OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 11222736c2fSopenharmony_ci SubProperty GetExtends(const std::vector<OHOS::AppExecFwk::Metadata> &metaData); 11322736c2fSopenharmony_ci std::string GetTargetString( 11422736c2fSopenharmony_ci const AppExecFwk::ExtensionAbilityInfo &extension, ImeTargetString target, int32_t userId); 11522736c2fSopenharmony_ci int32_t GetAppLabelFromRes(const AppExecFwk::ExtensionAbilityInfo &extension, std::string &label); 11622736c2fSopenharmony_ci std::string GetStringById(const std::string &bundleName, const std::string &moduleName, const uint32_t labelId, 11722736c2fSopenharmony_ci const int32_t userId); 11822736c2fSopenharmony_ci bool GetBundleInfoByBundleName(int32_t userId, const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo); 11922736c2fSopenharmony_ci std::shared_ptr<ImeInfo> GetImeInfoFromCache(const int32_t userId, const std::string &bundleName, 12022736c2fSopenharmony_ci const std::string &subName); 12122736c2fSopenharmony_ci std::shared_ptr<ImeInfo> GetImeInfoFromBundleMgr( 12222736c2fSopenharmony_ci const int32_t userId, const std::string &bundleName, const std::string &subName); 12322736c2fSopenharmony_ci int32_t GetExtInfosByBundleName(const int32_t userId, const std::string &bundleName, 12422736c2fSopenharmony_ci std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos); 12522736c2fSopenharmony_ci bool IsNewExtInfos(const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos); 12622736c2fSopenharmony_ci bool IsImeInstalled(const int32_t userId, const std::string &bundleName, const std::string &extName); 12722736c2fSopenharmony_ci std::vector<InputMethodInfo> ListInputMethodInfo(const int32_t userId); 12822736c2fSopenharmony_ci int32_t ListInputMethod(const int32_t userId, std::vector<Property> &props); 12922736c2fSopenharmony_ci int32_t ListEnabledInputMethod(const int32_t userId, std::vector<Property> &props, bool enableOn); 13022736c2fSopenharmony_ci int32_t ListDisabledInputMethod(const int32_t userId, std::vector<Property> &props, bool enableOn); 13122736c2fSopenharmony_ci int32_t ListInputMethodSubtype(const int32_t userId, 13222736c2fSopenharmony_ci const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, std::vector<SubProperty> &subProps); 13322736c2fSopenharmony_ci int32_t ListInputMethodSubtype(const int32_t userId, const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, 13422736c2fSopenharmony_ci std::vector<SubProperty> &subProps); 13522736c2fSopenharmony_ci int32_t GetSubProperty(int32_t userId, const std::string &subName, 13622736c2fSopenharmony_ci const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, SubProperty &subProp); 13722736c2fSopenharmony_ci int32_t GetSubProperty(int32_t userId, const std::string &subName, 13822736c2fSopenharmony_ci const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, SubProperty &subProp); 13922736c2fSopenharmony_ci int32_t ParseSubtype(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, std::vector<Subtype> &subtypes); 14022736c2fSopenharmony_ci bool ParseSubtypeProfile(const std::vector<std::string> &profiles, SubtypeCfg &subtypeCfg); 14122736c2fSopenharmony_ci void CovertToLanguage(const std::string &locale, std::string &language); 14222736c2fSopenharmony_ci bool QueryImeExtInfos(const int32_t userId, std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &infos); 14322736c2fSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> GetResMgr(const std::string &resourcePath); 14422736c2fSopenharmony_ci int32_t GetFullImeInfo( 14522736c2fSopenharmony_ci int32_t userId, const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> &extInfos, FullImeInfo &imeInfo); 14622736c2fSopenharmony_ci 14722736c2fSopenharmony_ci SystemConfig systemConfig_; 14822736c2fSopenharmony_ci bool IsTempInputMethod(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo); 14922736c2fSopenharmony_ci}; 15022736c2fSopenharmony_ci} // namespace MiscServices 15122736c2fSopenharmony_ci} // namespace OHOS 15222736c2fSopenharmony_ci#endif // SERVICES_INCLUDE_IME_INFO_ENQUIRER_H 153