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 SetCustomAuthorizationStatus(bool isCustomAuthorized)48 void SetCustomAuthorizationStatus(bool isCustomAuthorized) 49 { 50 isCustomAuthorized_ = isCustomAuthorized; 51 } 52 AllowToBypassSecurityCheck(const std::string & errMessage)53 bool AllowToBypassSecurityCheck(const std::string& errMessage) 54 { 55 if (errMessage.empty()) { 56 return false; 57 } 58 if (!isCustomAuthorized_) { 59 return false; 60 } 61 if (GetType() != SecCompType::SAVE_COMPONENT) { 62 return false; 63 } 64 bypassSecurityCheck_ = true; 65 return true; 66 } 67 AllowToShowToast()68 bool AllowToShowToast() const 69 { 70 if (componentInfo_ == nullptr) { 71 return false; 72 } 73 if (!isCustomAuthorized_) { 74 return false; 75 } 76 if (GetType() != SecCompType::SAVE_COMPONENT) { 77 return false; 78 } 79 if (!(componentInfo_->isCustomizable_ || bypassSecurityCheck_)) { 80 return false; 81 } 82 return true; 83 } 84 85 bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; 86 int32_t CheckClickInfo(SecCompClickEvent& clickInfo, int32_t superFoldOffsetY, const CrossAxisState crossAxisState, 87 std::string& message); 88 bool IsInPCVirtualScreen(const CrossAxisState crossAxisState) const; 89 90 std::shared_ptr<SecCompBase> componentInfo_; 91 AccessToken::AccessTokenID tokenId_; 92 int32_t scId_; 93 int32_t pid_; 94 int32_t uid_; 95 bool isCustomAuthorized_ = false; 96 bool bypassSecurityCheck_ = false; 97 98 private: 99 int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo) const; 100 int32_t CheckPointEvent(SecCompClickEvent& clickInfo, int32_t superFoldOffsetY, 101 const CrossAxisState crossAxisState) const; 102 bool isGrant_ = false; 103 }; 104 } // namespace SecurityComponent 105 } // namespace Security 106 } // namespace OHOS 107 #endif // SECURITY_COMPONENT_ENTITY_H 108