• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 INPUTMETHOD_IMF_INPUT_TYPE_MANAGER_H
17 #define INPUTMETHOD_IMF_INPUT_TYPE_MANAGER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <set>
22 #include <string>
23 
24 #include "block_data.h"
25 #include "input_method_utils.h"
26 #include "nlohmann/json.hpp"
27 
28 namespace OHOS {
29 namespace MiscServices {
30 struct ImeIdentification {
31     std::string bundleName;
32     std::string subName;
33     bool operator==(const ImeIdentification &ime) const
34     {
35         return (bundleName == ime.bundleName && subName == ime.subName);
36     }
37     bool operator<(const ImeIdentification &ime) const
38     {
39         return bundleName == ime.bundleName ? (subName < ime.subName) : (bundleName < ime.bundleName);
40     }
41 };
42 
43 struct InputTypeCfg {
44     InputType type{};
45     ImeIdentification ime;
46 };
47 
48 class InputTypeManager {
49 public:
50     static InputTypeManager &GetInstance();
51     bool IsSupported(InputType type);
52     bool IsInputType(const ImeIdentification &ime);
53     bool IsStarted();
54     bool IsCameraImeStarted();
55     void Set(bool isStarted, const ImeIdentification &currentIme = {});
56     ImeIdentification GetCurrentIme();
57     int32_t GetImeByInputType(InputType type, ImeIdentification &ime);
58 
59 private:
60     bool Init();
61     bool ParseFromCustomSystem();
62     bool GetCfgsFromFile(const std::string &cfgPath);
63     std::string ReadFile(const std::string &path);
64     std::mutex stateLock_;
65     bool isStarted_{ false };
66     ImeIdentification currentTypeIme_;
67 
68     std::mutex typesLock_;
69     std::map<InputType, ImeIdentification> inputTypes_;
70     std::mutex listLock_;
71     std::set<ImeIdentification> inputTypeImeList_;
72 
73     std::atomic_bool isTypeCfgReady_{ false };
74     std::atomic_bool isInitInProgress_{ false };
75     BlockData<bool> isInitSuccess_{ false };
76 };
77 } // namespace MiscServices
78 } // namespace OHOS
79 
80 #endif //INPUTMETHOD_IMF_INPUT_TYPE_MANAGER_H
81