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 "edm_permission.h" 26 #include "ent_info.h" 27 #include "json/json.h" 28 #include "permission_manager.h" 29 30 namespace OHOS { 31 namespace EDM { 32 class AdminManager : public std::enable_shared_from_this<AdminManager> { 33 public: 34 static std::shared_ptr<AdminManager> GetInstance(); 35 ErrCode GetReqPermission(const std::vector<std::string> &permissions, std::vector<EdmPermission> &edmPermissions); 36 bool GetAdminByUserId(int32_t userId, std::vector<std::shared_ptr<Admin>> &userAdmin); 37 void GetAdminBySubscribeEvent(ManagedEvent event, 38 std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> &subscribeAdmins); 39 std::shared_ptr<Admin> GetAdminByPkgName(const std::string &packageName, int32_t userId); 40 ErrCode DeleteAdmin(const std::string &packageName, int32_t userId); 41 ErrCode UpdateAdmin(AppExecFwk::ExtensionAbilityInfo &abilityInfo, const std::vector<std::string> &permissions, 42 int32_t userId); 43 ErrCode GetGrantedPermission(std::vector<std::string> &permissions, AdminType type); 44 bool IsSuperAdminExist(); 45 bool IsAdminExist(); 46 bool IsSuperOrSubSuperAdmin(const std::string &bundleName); 47 void GetEnabledAdmin(AdminType role, std::vector<std::string> &packageNameList, int32_t userId); 48 void Init(); 49 ErrCode SetAdminValue(AppExecFwk::ExtensionAbilityInfo &abilityInfo, EntInfo &entInfo, AdminType role, 50 std::vector<std::string> &permissions, int32_t userId); 51 ErrCode GetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId); 52 ErrCode SetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId); 53 ErrCode SaveSubscribeEvents(const std::vector<uint32_t> &events, const std::string &bundleName, int32_t userId); 54 ErrCode RemoveSubscribeEvents(const std::vector<uint32_t> &events, const std::string &bundleName, int32_t userId); 55 ErrCode SaveAuthorizedAdmin(const std::string &bundleName, const std::vector<std::string> &permissions, 56 const std::string &parentName); 57 ErrCode GetSubOrSuperAdminByPkgName(const std::string &subAdminName, std::shared_ptr<Admin> &subOrSuperAdmin); 58 ErrCode GetSubSuperAdminsByParentName(const std::string &parentName, std::vector<std::string> &subAdmins); 59 ~AdminManager(); 60 61 private: 62 AdminManager(); 63 64 std::unordered_map<int32_t, std::vector<std::shared_ptr<Admin>>> admins_; 65 static std::mutex mutexLock_; 66 static std::shared_ptr<AdminManager> instance_; 67 }; 68 } // namespace EDM 69 } // namespace OHOS 70 71 #endif // SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H 72