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 SERVICES_EDM_INCLUDE_DEVICE_POLICIES_STORAGE_RDB_H 17 #define SERVICES_EDM_INCLUDE_DEVICE_POLICIES_STORAGE_RDB_H 18 19 #include <unordered_map> 20 #include "edm_rdb_data_manager.h" 21 22 namespace OHOS { 23 namespace EDM { 24 using PolicyItemsMap = std::unordered_map<std::string, std::string>; /* PolicyName and PolicyValue pair */ 25 using AdminValueItemsMap = std::unordered_map<std::string, std::string>; /* AdminName and PolicyValue pair */ 26 27 class DevicePoliciesStorageRdb { 28 public: 29 DevicePoliciesStorageRdb(); 30 ~DevicePoliciesStorageRdb() = default; 31 static std::shared_ptr<DevicePoliciesStorageRdb> GetInstance(); 32 bool InsertAdminPolicy(int32_t userId, const std::string &adminName, const std::string &policyName, 33 const std::string &policyValue); 34 bool UpdateAdminPolicy(int32_t userId, const std::string &adminName, const std::string &policyName, 35 const std::string &policyValue); 36 bool DeleteAdminPolicy(int32_t userId, const std::string &adminName, const std::string &policyName); 37 bool QueryAdminPolicy(int32_t userId, std::unordered_map<std::string, PolicyItemsMap> &adminPolicies, 38 std::unordered_map<std::string, AdminValueItemsMap> &policyAdmins); 39 bool InsertCombinedPolicy(int32_t userId, const std::string &policyName, const std::string &policyValue); 40 bool UpdateCombinedPolicy(int32_t userId, const std::string &policyName, const std::string &policyValue); 41 bool DeleteCombinedPolicy(int32_t userId, const std::string &policyName); 42 bool QueryCombinedPolicy(int32_t userId, PolicyItemsMap &itemsMap); 43 bool QueryAllUserId(std::vector<int32_t> &userIds); 44 private: 45 void CreateDeviceAdminPoliciesTable(); 46 void CreateDeviceCombinedPoliciesTable(); 47 void PraseAdminPolicies(const std::string &adminName, const std::string &policyName, const std::string &policyValue, 48 std::unordered_map<std::string, PolicyItemsMap> &adminPolicies); 49 void PrasePolicyAdmins(const std::string &adminName, const std::string &policyName, const std::string &policyValue, 50 std::unordered_map<std::string, AdminValueItemsMap> &policyAdmins); 51 static std::shared_ptr<DevicePoliciesStorageRdb> instance_; 52 static std::mutex mutexLock_; 53 }; 54 } // namespace EDM 55 } // namespace OHOS 56 57 #endif // SERVICES_EDM_INCLUDE_DEVICE_POLICIES_STORAGE_RDB_H