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 "json/json.h" 28 #include "ipolicy_manager.h" 29 #include "user_policy_manager.h" 30 31 namespace OHOS { 32 namespace EDM { 33 34 class PolicyManager final: public IPolicyManager { 35 public: 36 ErrCode GetAdminByPolicyName(const std::string &policyName, AdminValueItemsMap &adminValueItems, 37 int32_t userId = EdmConstants::DEFAULT_USER_ID) override; 38 39 ErrCode GetPolicy(const std::string &adminName, const std::string &policyName, std::string &policyValue, 40 int32_t userId = EdmConstants::DEFAULT_USER_ID) override; 41 42 void Init(std::vector<int32_t> userIds); 43 44 ErrCode SetPolicy(const std::string &adminName, const std::string &policyName, const std::string &adminPolicyValue, 45 const std::string &mergedPolicyValue, int32_t userId = EdmConstants::DEFAULT_USER_ID); 46 47 ErrCode GetAllPolicyByAdmin(const std::string &adminName, PolicyItemsMap &allAdminPolicy, 48 int32_t userId = EdmConstants::DEFAULT_USER_ID); 49 50 void GetPolicyUserIds(std::vector<int32_t> &userIds); 51 52 void Dump(); 53 54 private: 55 std::shared_ptr<UserPolicyManager> GetUserPolicyMgr(int32_t userId); 56 57 std::map<std::int32_t, std::shared_ptr<UserPolicyManager>> policyMgrMap_; 58 std::shared_ptr<UserPolicyManager> defaultPolicyMgr_; 59 }; 60 } // namespace EDM 61 } // namespace OHOS 62 63 #endif // SERVICES_EDM_INCLUDE_EDM_POLICY_MANAGER_H 64