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