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 SECURITY_MODE_PARSER_H 17 #define SECURITY_MODE_PARSER_H 18 19 #include <map> 20 #include <mutex> 21 #include <string> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "datashare_helper.h" 26 #include "global.h" 27 #include "input_method_utils.h" 28 #include "serializable.h" 29 #include "settings_data_observer.h" 30 #include "settings_data_utils.h" 31 32 namespace OHOS { 33 namespace MiscServices { 34 struct SecModeCfg : public Serializable { 35 UserImeConfig userImeCfg; UnmarshalSecModeCfg36 bool Unmarshal(cJSON *node) override 37 { 38 GetValue(node, GET_NAME(fullExperienceList), userImeCfg); 39 return true; 40 } 41 }; 42 class SecurityModeParser : public RefBase { 43 public: 44 static sptr<SecurityModeParser> GetInstance(); 45 int32_t Initialize(const int32_t userId); 46 SecurityMode GetSecurityMode(const std::string &bundleName, int32_t userId); 47 int32_t UpdateFullModeList(int32_t userId); 48 bool IsDefaultFullMode(const std::string &bundleName, int32_t userId); 49 static constexpr const char *SECURITY_MODE = "settings.inputmethod.full_experience"; 50 51 private: 52 SecurityModeParser() = default; 53 ~SecurityModeParser(); 54 55 bool ParseSecurityMode(const std::string &valueStr, const int32_t userId); 56 bool IsFullMode(const std::string bundleName); 57 bool IsExpired(const std::string &expirationTime); 58 static std::mutex instanceMutex_; 59 static sptr<SecurityModeParser> instance_; 60 std::mutex listMutex_; 61 std::vector<std::string> fullModeList_; 62 std::mutex initLock_; 63 bool initialized_{ false }; 64 }; 65 } // namespace MiscServices 66 } // namespace OHOS 67 68 #endif // SECURITY_MODE_PARSER_H