• 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 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     bool IsSecurityMode(int32_t userId, const std::string &bundleName);
50     static constexpr const char *SECURITY_MODE = "settings.inputmethod.full_experience";
51 
52 private:
53     SecurityModeParser() = default;
54     ~SecurityModeParser();
55 
56     bool ParseSecurityMode(const std::string &valueStr, const int32_t userId);
57     bool IsFullMode(const std::string bundleName);
58     bool IsExpired(const std::string &expirationTime);
59     static std::mutex instanceMutex_;
60     static sptr<SecurityModeParser> instance_;
61     std::mutex listMutex_;
62     std::vector<std::string> fullModeList_;
63     std::mutex initLock_;
64     bool initialized_{ false };
65 };
66 } // namespace MiscServices
67 } // namespace OHOS
68 
69 #endif // SECURITY_MODE_PARSER_H