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 InputType GetCurrentInputType(); 51 void Set(bool isStarted, const ImeIdentification ¤tIme = {}); 52 ImeIdentification GetCurrentIme(); 53 int32_t GetImeByInputType(InputType type, ImeIdentification &ime); 54 55 private: 56 bool Init(); 57 std::mutex stateLock_; 58 bool isStarted_{ false }; 59 ImeIdentification currentTypeIme_; 60 61 std::mutex typesLock_; 62 std::map<InputType, ImeIdentification> inputTypes_; 63 std::mutex listLock_; 64 std::set<ImeIdentification> inputTypeImeList_; 65 66 std::atomic_bool isTypeCfgReady_{ false }; 67 std::atomic_bool isInitInProgress_{ false }; 68 BlockData<bool> isInitSuccess_{ false }; 69 }; 70 } // namespace MiscServices 71 } // namespace OHOS 72 73 #endif //INPUTMETHOD_IMF_INPUT_TYPE_MANAGER_H 74