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,int32_t pid,int32_t uid)29 SecCompEntity(std::shared_ptr<SecCompBase> component, 30 AccessToken::AccessTokenID token, int32_t scId, int32_t pid, int32_t uid) 31 : componentInfo_(component), tokenId_(token), scId_(scId), pid_(pid), uid_(uid) {}; 32 ~SecCompEntity() = default; 33 int32_t RevokeTempPermission(); 34 int32_t GrantTempPermission(); GetType()35 SecCompType GetType() const 36 { 37 if (componentInfo_ == nullptr) { 38 return UNKNOWN_SC_TYPE; 39 } 40 return componentInfo_->type_; 41 }; 42 IsGrant()43 bool IsGrant() const 44 { 45 return isGrant_; 46 } 47 48 bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; 49 int32_t CheckClickInfo(const SecCompClickEvent& clickInfo) const; 50 51 std::shared_ptr<SecCompBase> componentInfo_; 52 AccessToken::AccessTokenID tokenId_; 53 int32_t scId_; 54 int32_t pid_; 55 int32_t uid_; 56 57 private: 58 int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo) const; 59 int32_t CheckPointEvent(const SecCompClickEvent& clickInfo) const; 60 bool isGrant_ = false; 61 }; 62 } // namespace SecurityComponent 63 } // namespace Security 64 } // namespace OHOS 65 #endif // SECURITY_COMPONENT_ENTITY_H 66