1 /* 2 * Copyright (c) 2022 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 EDM_ADMIN_MANAGER_H 17 #define EDM_ADMIN_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include "admin.h" 22 #include "ent_info.h" 23 #include "edm_permission.h" 24 #include "json/json.h" 25 #include "permission_manager.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 ErrCode GetReqPermission(const std::vector<std::string> &permissions, std::vector<EdmPermission> &edmPermissions); 33 void GetAllAdmin(std::vector<std::shared_ptr<Admin>> &allAdmin); 34 std::shared_ptr<Admin> GetAdminByPkgName(const std::string &packageName); 35 ErrCode DeleteAdmin(const std::string &packageName); 36 ErrCode UpdateAdmin(AppExecFwk::AbilityInfo &abilityInfo, const std::vector<std::string> &permissions); 37 ErrCode GetGrantedPermission(AppExecFwk::AbilityInfo &abilityInfo, std::vector<std::string> &permissions, 38 AdminType type); 39 bool IsSuperAdminExist(); 40 void GetActiveAdmin(AdminType role, std::vector<std::string> &packageNameList); 41 void Init(); 42 void RestoreAdminFromFile(); 43 ErrCode SetAdminValue(AppExecFwk::AbilityInfo &abilityInfo, EntInfo &entInfo, AdminType role, 44 std::vector<std::string> &permissions); 45 ErrCode GetEntInfo(const std::string &packageName, EntInfo &entInfo); 46 ErrCode SetEntInfo(const std::string &packageName, EntInfo &entInfo); 47 virtual ~AdminManager(); 48 private: 49 AdminManager(); 50 void SaveAdmin(); 51 void ReadJsonAdminType(Json::Value &admin); 52 void ReadJsonAdmin(const std::string &filePath); 53 void WriteJsonAdminType(std::shared_ptr<Admin> &activeAdmin, Json::Value &tree); 54 void WriteJsonAdmin(const std::string &filePath); 55 56 std::vector<std::shared_ptr<Admin>> admins_; 57 static std::mutex mutexLock_; 58 static std::shared_ptr<AdminManager> instance_; 59 }; 60 } // namespace EDM 61 } // namespace OHOS 62 63 #endif // EDM_ADMIN_MANAGER_H 64