/* * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H #define SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H #include #include #include #include "admin.h" #include "admin_policies_storage_rdb.h" #include "ent_info.h" #include "json/json.h" namespace OHOS { namespace EDM { class AdminManager : public std::enable_shared_from_this { public: static std::shared_ptr GetInstance(); bool GetAdminByUserId(int32_t userId, std::vector> &userAdmin); void GetAdminBySubscribeEvent(ManagedEvent event, std::unordered_map>> &subscribeAdmins); std::shared_ptr GetAdminByPkgName(const std::string &packageName, int32_t userId); ErrCode DeleteAdmin(const std::string &packageName, int32_t userId); ErrCode UpdateAdmin(std::shared_ptr getAdmin, int32_t userId, const Admin &adminItem); bool IsSuperAdminExist(); bool IsSuperAdmin(const std::string &bundleName); bool IsAdminExist(); bool IsSuperOrSubSuperAdmin(const std::string &bundleName); bool HasPermissionToHandlePolicy(std::shared_ptr admin, const std::string &policyName); void GetEnabledAdmin(AdminType role, std::vector &packageNameList, int32_t userId); std::shared_ptr GetSuperAdmin(); void Init(); ErrCode SetAdminValue(int32_t userId, const Admin &adminItem); ErrCode GetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId); ErrCode SetEntInfo(const std::string &packageName, EntInfo &entInfo, int32_t userId); ErrCode SaveSubscribeEvents(const std::vector &events, const std::string &bundleName, int32_t userId); ErrCode RemoveSubscribeEvents(const std::vector &events, const std::string &bundleName, int32_t userId); ErrCode GetPoliciesByVirtualAdmin(const std::string &bundleName, const std::string &parentName, std::vector &policies); void GetVirtualAdminsByPolicy(const std::string &policyName, const std::string &parentName, std::vector &bundleNames); ErrCode GetSubOrSuperAdminByPkgName(const std::string &subAdminName, std::shared_ptr &subOrSuperAdmin); ErrCode GetSubSuperAdminsByParentName(const std::string &parentName, std::vector &subAdmins); ~AdminManager(); void Dump(); private: AdminManager(); std::unordered_map>> admins_; static std::mutex mutexLock_; static std::shared_ptr instance_; }; } // namespace EDM } // namespace OHOS #endif // SERVICES_EDM_INCLUDE_ADMIN_MANAGER_H