• 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 #include "json/json.h"
27 
28 namespace OHOS {
29 namespace EDM {
30 class AdminManager : public std::enable_shared_from_this<AdminManager> {
31 public:
32     static std::shared_ptr<AdminManager> GetInstance();
33     bool GetAdminByUserId(int32_t userId, std::vector<std::shared_ptr<Admin>> &userAdmin);
34     void GetAdminBySubscribeEvent(ManagedEvent event,
35         std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> &subscribeAdmins);
36     std::shared_ptr<Admin> GetAdminByPkgName(const std::string &packageName, int32_t userId);
37     ErrCode DeleteAdmin(const std::string &packageName, int32_t userId);
38     ErrCode UpdateAdmin(std::shared_ptr<Admin> getAdmin, int32_t userId, const Admin &adminItem);
39     bool IsSuperAdminExist();
40     bool IsByodAdminExist();
41     bool IsSuperAdmin(const std::string &bundleName);
42     bool IsAdminExist();
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, 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     ~AdminManager();
63     void Dump();
64 
65 private:
66     AdminManager();
67 
68     std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> admins_;
69     static std::mutex mutexLock_;
70     static std::shared_ptr<AdminManager> instance_;
71 };
72 } // namespace EDM
73 } // namespace OHOS
74 
75 #endif // SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H
76