• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_MANAGER_H
17 #define SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H
18 
19 #include <map>
20 #include <memory>
21 #include <unordered_map>
22 
23 #include "admin.h"
24 #include "admin_policies_storage_rdb.h"
25 #include "ent_info.h"
26 
27 namespace OHOS {
28 namespace EDM {
29 class AdminManager : public std::enable_shared_from_this<AdminManager> {
30 public:
31     static std::shared_ptr<AdminManager> GetInstance();
32     bool GetAdminByUserId(int32_t userId, std::vector<std::shared_ptr<Admin>> &userAdmin);
33     void GetAdminBySubscribeEvent(ManagedEvent event,
34         std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> &subscribeAdmins);
35     std::shared_ptr<Admin> GetAdminByPkgName(const std::string &packageName, int32_t userId);
36     ErrCode DeleteAdmin(const std::string &packageName, int32_t userId);
37     ErrCode UpdateAdmin(std::shared_ptr<Admin> getAdmin, int32_t userId, const Admin &adminItem);
38     bool IsSuperAdminExist();
39     bool IsByodAdminExist();
40     bool IsSuperAdmin(const std::string &bundleName);
41     bool IsAdminExist();
42     bool IsByodAdmin(const std::string &bundleName, int32_t userId);
43     bool IsSuperOrSubSuperAdmin(const std::string &bundleName);
44     bool HasPermissionToHandlePolicy(std::shared_ptr<Admin> admin, const std::string &policyName);
45     void GetEnabledAdmin(AdminType role, std::vector<std::string> &packageNameList, int32_t userId);
46     std::shared_ptr<Admin> GetSuperAdmin();
47     void Init();
48     ErrCode SetAdminValue(int32_t userId, const Admin &adminItem);
49     ErrCode GetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId);
50     ErrCode SetEntInfo(const std::string &packageName, const EntInfo &entInfo, int32_t userId);
51     ErrCode SaveSubscribeEvents(const std::vector<uint32_t> &events, const std::string &bundleName, int32_t userId);
52     ErrCode RemoveSubscribeEvents(const std::vector<uint32_t> &events, const std::string &bundleName, int32_t userId);
53     ErrCode GetPoliciesByVirtualAdmin(const std::string &bundleName, const std::string &parentName,
54         std::vector<std::string> &policies);
55     void GetVirtualAdminsByPolicy(const std::string &policyName, const std::string &parentName,
56         std::vector<std::string> &bundleNames);
57     ErrCode GetSubOrSuperOrByodAdminByPkgName(const std::string &subAdminName,
58         std::shared_ptr<Admin> &subOrSuperOrByodAdmin);
59     void GetAdmins(std::vector<std::shared_ptr<Admin>> &admins, int32_t currentUserId);
60     bool GetAdminsByTypeAndUserId(AdminType type, std::vector<std::shared_ptr<Admin>> &admins, int32_t userId);
61     ErrCode GetSubSuperAdminsByParentName(const std::string &parentName, std::vector<std::string> &subAdmins);
62     ErrCode ReplaceSuperAdminByPackageName(const std::string &packageName, const Admin &newAdmin);
63     ~AdminManager();
64     void Dump();
65     void ClearAdmins();
66     void InsertAdmins(int32_t userId, std::vector<std::shared_ptr<Admin>> admins);
67 
68 private:
69     AdminManager();
70 
71     static std::once_flag flag_;
72     static std::shared_ptr<AdminManager> instance_;
73 };
74 } // namespace EDM
75 } // namespace OHOS
76 
77 #endif // SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H
78