/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SERVICES_INCLUDE_IME_INFO_ENQUIRER_H #define SERVICES_INCLUDE_IME_INFO_ENQUIRER_H #include #include #include #include #include #include "bundle_mgr_proxy.h" #include "input_method_info.h" #include "input_method_property.h" #include "input_method_status.h" #include "nlohmann/json.hpp" #include "refbase.h" namespace OHOS { namespace MiscServices { struct ImeInfo { Property prop; SubProperty subProp; std::vector subProps; bool isNewIme{ false }; }; enum class Condition { UPPER = 0, LOWER, ENGLISH, CHINESE, }; class ImeInfoInquirer { public: using CompareHandler = std::function; static ImeInfoInquirer &GetInstance(); std::shared_ptr GetImeSubProp(const std::vector &subProps, const Condition &condition); std::string GetInputMethodParam(const int32_t userId); std::shared_ptr GetCurrentInputMethod(const int32_t userId); std::shared_ptr GetCurrentInputMethodSubtype(const int32_t userId); std::string GetStartedIme(const int32_t userId); std::shared_ptr GetDefaultImeInfo(const int32_t userId); int32_t GetImeInfo( const int32_t userId, const std::string &bundleName, const std::string &subName, ImeInfo &info); void SetCurrentImeInfo(const ImeInfo &info); void SetCurrentImeInfo(const int32_t userId); void ResetCurrentImeInfo(); int32_t ListInputMethod(const int32_t userId, const InputMethodStatus status, std::vector &props); int32_t ListInputMethodSubtype( const int32_t userId, const std::string &bundleName, std::vector &subProps); int32_t ListCurrentInputMethodSubtype(const int32_t userId, std::vector &subProps); private: ImeInfoInquirer() = default; ~ImeInfoInquirer() = default; OHOS::sptr GetBundleMgr(); SubProperty GetExtends(const std::vector &metaData); std::string GetDefaultIme(); std::string GetStringById( const std::string &bundleName, const std::string &moduleName, const int32_t labelId, const int32_t userId); int32_t GetImeInfoFromNative(const int32_t userId, const std::string &subName, ImeInfo &info); int32_t GetImeInfoFromBundleMgr( const int32_t userId, const std::string &bundleName, const std::string &subName, ImeInfo &info); int32_t GetExtInfosByBundleName(const int32_t userId, const std::string &bundleName, std::vector &extInfos); bool IsNewExtInfos(const std::vector &extInfos); bool IsImeInstalled(const int32_t userId, const std::string &bundleName, const std::string &extName); std::vector ListInputMethodInfo(const int32_t userId); int32_t ListInputMethod(const int32_t userId, std::vector &props); int32_t ListEnabledInputMethod(const int32_t userId, std::vector &props); int32_t ListDisabledInputMethod(const int32_t userId, std::vector &props); int32_t ListInputMethodSubtype(const int32_t userId, const std::vector &extInfos, std::vector &subProps); int32_t ListInputMethodSubtype(const int32_t userId, const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, std::vector &subProps); bool ParseSubProp(const std::vector &profiles, std::vector &subProps); void ParseSubProp(const nlohmann::json &jsonSubProps, std::vector &subProps); void ParseSubProp(const nlohmann::json &jsonSubProp, SubProperty &subProp); void ParseLanguage(const std::string &locale, std::string &language); bool QueryImeExtInfos(const int32_t userId, std::vector &infos); std::recursive_mutex currentImeInfoLock_; std::shared_ptr currentImeInfo_{ nullptr }; std::mutex defaultImeInfoLock_; std::shared_ptr defaultImeInfo_{ nullptr }; }; } // namespace MiscServices } // namespace OHOS #endif // SERVICES_INCLUDE_IME_INFO_ENQUIRER_H