• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 SERVICES_EDM_INCLUDE_EDM_POLICY_MANAGER_H
17 #define SERVICES_EDM_INCLUDE_EDM_POLICY_MANAGER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 #include "device_policies_storage_rdb.h"
25 #include "edm_constants.h"
26 #include "edm_errors.h"
27 #include "ipolicy_manager.h"
28 #include "user_policy_manager.h"
29 
30 namespace OHOS {
31 namespace EDM {
32 
33 class PolicyManager final: public IPolicyManager {
34 public:
35     ErrCode GetAdminByPolicyName(const std::string &policyName, AdminValueItemsMap &adminValueItems,
36         int32_t userId = EdmConstants::DEFAULT_USER_ID) override;
37 
38     ErrCode GetPolicy(const std::string &adminName, const std::string &policyName, std::string &policyValue,
39         int32_t userId = EdmConstants::DEFAULT_USER_ID) override;
40 
41     void Init(std::vector<int32_t> userIds);
42 
43     ErrCode SetPolicy(const std::string &adminName, const std::string &policyName, const std::string &adminPolicyValue,
44         const std::string &mergedPolicyValue, int32_t userId = EdmConstants::DEFAULT_USER_ID);
45 
46     ErrCode GetAllPolicyByAdmin(const std::string &adminName, PolicyItemsMap &allAdminPolicy,
47         int32_t userId = EdmConstants::DEFAULT_USER_ID);
48 
49     void GetPolicyUserIds(std::vector<int32_t> &userIds) override;
50 
51     ErrCode ReplaceAllPolicy(int32_t userId, const std::string &adminName, const std::string &newAdminName);
52 
53     void Dump();
54 
55 private:
56     std::shared_ptr<UserPolicyManager> GetUserPolicyMgr(int32_t userId);
57 
58     std::map<std::int32_t, std::shared_ptr<UserPolicyManager>> policyMgrMap_;
59     std::shared_ptr<UserPolicyManager> defaultPolicyMgr_;
60 };
61 } // namespace EDM
62 } // namespace OHOS
63 
64 #endif // SERVICES_EDM_INCLUDE_EDM_POLICY_MANAGER_H
65