1 /* 2 * Copyright (c) 2024 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 IMF_TEST_IDENTITY_CHECKER_MOCK_H 17 #define IMF_TEST_IDENTITY_CHECKER_MOCK_H 18 19 #include "identity_checker.h" 20 21 namespace OHOS { 22 namespace MiscServices { 23 class IdentityCheckerMock : public IdentityChecker { 24 public: 25 IdentityCheckerMock() = default; 26 virtual ~IdentityCheckerMock() = default; 27 bool IsFocused(int64_t callingPid, uint32_t callingTokenId, int64_t focusedPid = INVALID_PID) override 28 { 29 return isFocused_; 30 } IsSystemApp(uint64_t fullTokenId)31 bool IsSystemApp(uint64_t fullTokenId) override 32 { 33 return isSystemApp_; 34 } IsBundleNameValid(uint32_t tokenId,const std::string & validBundleName)35 bool IsBundleNameValid(uint32_t tokenId, const std::string &validBundleName) override 36 { 37 return isBundleNameValid_; 38 } HasPermission(uint32_t tokenId,const std::string & permission)39 bool HasPermission(uint32_t tokenId, const std::string &permission) override 40 { 41 return hasPermission_; 42 } IsBroker(Security::AccessToken::AccessTokenID tokenId)43 bool IsBroker(Security::AccessToken::AccessTokenID tokenId) override 44 { 45 return isBroker_; 46 } IsNativeSa(Security::AccessToken::AccessTokenID tokenId)47 bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) override 48 { 49 return isNativeSa_; 50 } GetBundleNameByToken(uint32_t tokenId)51 std::string GetBundleNameByToken(uint32_t tokenId) override 52 { 53 return bundleName_; 54 } ResetParam()55 static void ResetParam() 56 { 57 isFocused_ = false; 58 isSystemApp_ = false; 59 isBundleNameValid_ = false; 60 hasPermission_ = false; 61 isBroker_ = false; 62 isNativeSa_ = false; 63 bundleName_ = ""; 64 } SetFocused(bool isFocused)65 static void SetFocused(bool isFocused) 66 { 67 isFocused_ = isFocused; 68 } SetSystemApp(bool isSystemApp)69 static void SetSystemApp(bool isSystemApp) 70 { 71 isSystemApp_ = isSystemApp; 72 } SetBundleNameValid(bool isBundleNameValid)73 static void SetBundleNameValid(bool isBundleNameValid) 74 { 75 isBundleNameValid_ = isBundleNameValid; 76 } SetBroker(bool isBroker)77 static void SetBroker(bool isBroker) 78 { 79 isBroker_ = isBroker; 80 } SetNativeSa(bool isNativeSa)81 static void SetNativeSa(bool isNativeSa) 82 { 83 isNativeSa_ = isNativeSa; 84 } SetPermission(bool hasPermission)85 static void SetPermission(bool hasPermission) 86 { 87 hasPermission_ = hasPermission; 88 } 89 SetBundleName(const std::string & bundleName)90 static void SetBundleName(const std::string &bundleName) 91 { 92 bundleName_ = bundleName; 93 } 94 95 private: 96 static bool isFocused_; 97 static bool isSystemApp_; 98 static bool isBundleNameValid_; 99 static bool hasPermission_; 100 static bool isBroker_; 101 static bool isNativeSa_; 102 static std::string bundleName_; 103 }; 104 bool IdentityCheckerMock::isFocused_{ false }; 105 bool IdentityCheckerMock::isSystemApp_{ false }; 106 bool IdentityCheckerMock::isBundleNameValid_{ false }; 107 bool IdentityCheckerMock::hasPermission_{ false }; 108 bool IdentityCheckerMock::isBroker_{ false }; 109 bool IdentityCheckerMock::isNativeSa_{ false }; 110 std::string IdentityCheckerMock::bundleName_; 111 } // namespace MiscServices 112 } // namespace OHOS 113 #endif // IMF_TEST_IDENTITY_CHECKER_MOCK_H 114