1 /* 2 * Copyright (c) 2021-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 PERMISSION_DEFINITION_CACHE_H 17 #define PERMISSION_DEFINITION_CACHE_H 18 19 #include <map> 20 #include <vector> 21 22 #include "data_translator.h" 23 #include "permission_def.h" 24 25 #include "rwlock.h" 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace Security { 30 namespace AccessToken { 31 class PermissionDefinitionCache final { 32 public: 33 static PermissionDefinitionCache& GetInstance(); 34 35 virtual ~PermissionDefinitionCache(); 36 37 bool Insert(const PermissionDef& info, AccessTokenID tokenId); 38 39 bool Update(const PermissionDef& info, AccessTokenID tokenId); 40 41 void DeleteByBundleName(const std::string& bundleName); 42 43 int FindByPermissionName(const std::string& permissionName, PermissionDef& info); 44 45 bool IsSystemGrantedPermission(const std::string& permissionName); 46 47 bool IsUserGrantedPermission(const std::string& permissionName); 48 49 bool HasDefinition(const std::string& permissionName); 50 51 bool IsPermissionDefEmpty(); 52 53 void StorePermissionDef(std::vector<GenericValues>& valueList); 54 55 void GetDefPermissionsByTokenId(std::vector<PermissionDef>& permList, AccessTokenID tokenId); 56 57 int32_t RestorePermDefInfo(std::vector<GenericValues>& permDefRes); 58 59 private: 60 PermissionDefinitionCache(); 61 62 bool IsGrantedModeEqualInner(const std::string& permissionName, int grantMode) const; 63 64 DISALLOW_COPY_AND_MOVE(PermissionDefinitionCache); 65 66 /** 67 * key: the permission name. 68 * value: the object of PermissionDefData. 69 */ 70 std::map<std::string, PermissionDefData> permissionDefinitionMap_; 71 72 OHOS::Utils::RWLock cacheLock_; 73 }; 74 } // namespace AccessToken 75 } // namespace Security 76 } // namespace OHOS 77 #endif // PERMISSION_DEFINITION_CACHE_H 78