• 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 SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H
17 #define SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H
18 
19 #include <unordered_map>
20 
21 #include "admin.h"
22 #include "edm_rdb_data_manager.h"
23 #include "json/json.h"
24 
25 namespace OHOS {
26 namespace EDM {
27 class AdminPoliciesStorageRdb {
28 public:
29     AdminPoliciesStorageRdb();
30     static std::shared_ptr<AdminPoliciesStorageRdb> GetInstance();
31     bool InsertAdmin(int32_t userId, const Admin &admin);
32     bool UpdateAdmin(int32_t userId, const Admin &admin);
33     bool DeleteAdmin(int32_t userId, const std::string &packageName);
34     bool UpdateEntInfo(int32_t userId, const std::string &packageName, const EntInfo &entInfo);
35     bool UpdateManagedEvents(int32_t userId, const std::string &packageName,
36         const std::vector<ManagedEvent> &managedEvents);
37     std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> QueryAllAdmin();
38     bool ReplaceAdmin(const std::string packageName, int32_t userId, const Admin &newAdmin);
39     bool UpdateParentName(const std::string packageName, const std::string currentParentName,
40         const std::string targetParentName);
41 
42 private:
43     NativeRdb::ValuesBucket CreateInsertValuesBucket(int32_t userId, const Admin &admin);
44     void CreateUpdateValuesBucket(int32_t userId, const Admin &admin, NativeRdb::ValuesBucket &valuesBucket);
45     void SetAdminItems(std::shared_ptr<NativeRdb::ResultSet> resultSet, std::shared_ptr<Admin> item);
46     void SetManagedEventStr(std::shared_ptr<NativeRdb::ResultSet> resultSet, std::shared_ptr<Admin> item);
47     void ConvertStrToJson(const std::string &str, Json::Value &json);
48     void SetAdminStringInfo(const std::string &stringInfo, std::vector<std::string> &info);
49     static bool CreateAdminPoliciesTable();
50     static std::shared_ptr<AdminPoliciesStorageRdb> instance_;
51     static std::once_flag flag_;
52     static bool isAdminPoliciesTableInit_;
53 };
54 } // namespace EDM
55 } // namespace OHOS
56 
57 #endif // SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H