1 /* 2 * Copyright (c) 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 #ifndef SECURITY_COMPONENT_ENTITY_H 16 #define SECURITY_COMPONENT_ENTITY_H 17 18 #include <memory> 19 #include "accesstoken_kit.h" 20 #include "sec_comp_base.h" 21 #include "sec_comp_info.h" 22 #include "sec_comp_perm_manager.h" 23 24 namespace OHOS { 25 namespace Security { 26 namespace SecurityComponent { 27 class SecCompEntity { 28 public: SecCompEntity(std::shared_ptr<SecCompBase> component,AccessToken::AccessTokenID token,int32_t scId)29 SecCompEntity(std::shared_ptr<SecCompBase> component, 30 AccessToken::AccessTokenID token, int32_t scId) : componentInfo_(component), 31 tokenId_(token), scId_(scId) {}; 32 ~SecCompEntity() = default; 33 int32_t RevokeTempPermission(); 34 int32_t GrantTempPermission(); GetScId()35 int32_t GetScId() const 36 { 37 return scId_; 38 }; 39 GetType()40 SecCompType GetType() const 41 { 42 if (componentInfo_ == nullptr) { 43 return UNKNOWN_SC_TYPE; 44 } 45 return componentInfo_->type_; 46 }; 47 IsGrant()48 bool IsGrant() const 49 { 50 return isGrant_; 51 } 52 GetComponentInfo()53 std::shared_ptr<SecCompBase> GetComponentInfo() const 54 { 55 return componentInfo_; 56 }; 57 SetComponentInfo(const std::shared_ptr<SecCompBase> & com)58 void SetComponentInfo(const std::shared_ptr<SecCompBase>& com) 59 { 60 componentInfo_ = com; 61 }; 62 GetComponentInfo()63 std::shared_ptr<SecCompBase> GetComponentInfo() 64 { 65 return componentInfo_; 66 }; 67 68 bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; 69 int32_t CheckClickInfo(const SecCompClickEvent& clickInfo) const; 70 71 private: 72 int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo) const; 73 int32_t CheckPointEvent(const SecCompClickEvent& clickInfo) const; 74 std::shared_ptr<SecCompBase> componentInfo_; 75 bool isGrant_ = false; 76 AccessToken::AccessTokenID tokenId_; 77 int32_t scId_; 78 }; 79 } // namespace SecurityComponent 80 } // namespace Security 81 } // namespace OHOS 82 #endif // SECURITY_COMPONENT_ENTITY_H 83