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 <memory>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "input_method_property.h"
25 #include "input_method_status.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 class ImeInfoInquirer {
30 public:
31     static ImeInfoInquirer &GetInstance();
32     std::shared_ptr<ImeInfo> GetDefaultImeInfo(int32_t userId);
33     std::shared_ptr<Property> GetCurrentInputMethod(int32_t userId);
34     std::shared_ptr<Property> GetDefaultImeCfgProp();
35     void SetFullImeInfo(bool isReturnOk, const FullImeInfo &imeInfo);
36     void SetFullImeInfo(bool isReturnOk, const std::vector<FullImeInfo> &imeInfos);
37     void SetFullImeInfo(bool isReturnOk, const std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &fullImeInfos);
38     int32_t QueryFullImeInfo(std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> &fullImeInfos) const;
39     int32_t QueryFullImeInfo(int32_t userId, std::vector<FullImeInfo> &imeInfos) const;
40     int32_t GetFullImeInfo(int32_t userId, const std::string &bundleName, FullImeInfo &imeInfo) const;
41     static bool GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId);
42     static bool GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode);
43 
44 private:
45     static std::shared_ptr<ImeInfo> defaultIme_;
46     static std::shared_ptr<Property> currentIme_;
47     static std::shared_ptr<Property> defaultImeProperty_;
48     bool isQueryAllFullImeInfosOk_{ false };
49     std::vector<std::pair<int32_t, std::vector<FullImeInfo>>> allFullImeInfos_;
50     bool isQueryFullImeInfosOk_{ false };
51     std::vector<FullImeInfo> fullImeInfos_;
52     bool isGetFullImeInfoOk_{ false };
53     FullImeInfo fullImeInfo_;
54 };
55 } // namespace MiscServices
56 } // namespace OHOS
57 #endif // SERVICES_INCLUDE_IME_INFO_ENQUIRER_H
58