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