• 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 AppExecFwk::ExtensionAbilityInfo &abilityInfo, const EntInfo &entInfo,
32         AdminType role, const std::vector<std::string> &permissions);
33     bool UpdateAdmin(int32_t userId, const AppExecFwk::ExtensionAbilityInfo &abilityInfo, const EntInfo &entInfo,
34         AdminType role, const std::vector<std::string> &permissions);
35     bool DeleteAdmin(int32_t userId, const std::string &packageName);
36     bool UpdateAdmin(int32_t userId, const std::string &packageName, const std::string &className,
37         const std::vector<std::string> &permissions);
38     bool UpdateEntInfo(int32_t userId, const std::string &packageName, const EntInfo &entInfo);
39     bool UpdateManagedEvents(int32_t userId, const std::string &packageName,
40         const std::vector<ManagedEvent> &managedEvents);
41     std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> QueryAllAdmin();
42     bool InsertAuthorizedAdmin(const std::string &bundleName, const std::vector<std::string> &permissions,
43         const std::string &parentName);
44     bool UpdateAuthorizedAdmin(const std::string &bundleName, const std::vector<std::string> &permissions,
45         const std::string &parentName);
46 
47 private:
48     NativeRdb::ValuesBucket CreateValuesBucket(int32_t userId, const AppExecFwk::ExtensionAbilityInfo &abilityInfo,
49         const EntInfo &entInfo, AdminType role, const std::vector<std::string> &permissions);
50     void SetAdminItems(std::shared_ptr<NativeRdb::ResultSet> resultSet, std::shared_ptr<Admin> item);
51     void ConvertStrToJson(const std::string &str, Json::Value &json);
52     static std::shared_ptr<AdminPoliciesStorageRdb> instance_;
53     static std::mutex mutexLock_;
54 };
55 } // namespace EDM
56 } // namespace OHOS
57 
58 #endif // SERVICES_EDM_INCLUDE_ADMIN_POLICIES_STORAGE_RDB_H