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 <set> 21 22 #include "block_data.h" 23 #include "sys_cfg_parser.h" 24 25 namespace OHOS { 26 namespace MiscServices { 27 struct ImeIdentification { 28 std::string bundleName; 29 std::string subName; 30 bool operator==(const ImeIdentification &ime) const 31 { 32 return (bundleName == ime.bundleName && subName == ime.subName); 33 } 34 bool operator<(const ImeIdentification &ime) const 35 { 36 return bundleName == ime.bundleName ? (subName < ime.subName) : (bundleName < ime.bundleName); 37 } 38 }; 39 40 class InputTypeManager { 41 public: 42 static InputTypeManager &GetInstance(); 43 bool IsSupported(InputType type); 44 bool IsInputType(const ImeIdentification &ime); 45 bool IsStarted(); 46 bool IsSecurityImeStarted(); 47 bool IsCameraImeStarted(); 48 bool IsVoiceImeStarted(); 49 bool IsVoiceKbImeStarted(); 50 bool IsInputTypeImeStarted(InputType type); 51 InputType GetCurrentInputType(); 52 void Set(bool isStarted, const ImeIdentification ¤tIme = {}); 53 ImeIdentification GetCurrentIme(); 54 int32_t GetImeByInputType(InputType type, ImeIdentification &ime); 55 56 private: 57 bool Init(); 58 std::mutex stateLock_; 59 bool isStarted_{ false }; 60 ImeIdentification currentTypeIme_; 61 62 std::mutex typesLock_; 63 std::map<InputType, ImeIdentification> inputTypes_; 64 std::mutex listLock_; 65 std::set<ImeIdentification> inputTypeImeList_; 66 67 std::atomic_bool isTypeCfgReady_{ false }; 68 std::atomic_bool isInitInProgress_{ false }; 69 BlockData<bool> isInitSuccess_{ false }; 70 }; 71 } // namespace MiscServices 72 } // namespace OHOS 73 74 #endif //INPUTMETHOD_IMF_INPUT_TYPE_MANAGER_H 75