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 16 #include "mock_accesstoken_kit.h" 17 18 using namespace OHOS::Security::AccessToken; 19 namespace OHOS { 20 namespace PowerMgr { 21 namespace { 22 ATokenTypeEnum g_mockGetTokenTypeFlagRet = ATokenTypeEnum::TOKEN_INVALID; 23 PermissionState g_mockState = PermissionState::PERMISSION_DENIED; 24 bool g_isSystemApp = false; 25 } // namespace 26 MockSetTokenTypeFlag(ATokenTypeEnum mockRet)27void MockAccesstokenKit::MockSetTokenTypeFlag(ATokenTypeEnum mockRet) 28 { 29 g_mockGetTokenTypeFlagRet = mockRet; 30 } 31 MockSetPermissionState(PermissionState mockState)32void MockAccesstokenKit::MockSetPermissionState(PermissionState mockState) 33 { 34 g_mockState = mockState; 35 } 36 MockSetSystemApp(bool isSystemApp)37void MockAccesstokenKit::MockSetSystemApp(bool isSystemApp) 38 { 39 g_isSystemApp = isSystemApp; 40 } 41 } // namespace PowerMgr 42 } // namespace OHOS 43 44 namespace OHOS { 45 namespace Security { 46 namespace AccessToken { VerifyAccessToken(AccessTokenID tokenID,const std::string & permissionName)47int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) 48 { 49 return PowerMgr::g_mockState; 50 } 51 GetTokenTypeFlag(AccessTokenID tokenID)52ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) 53 { 54 return PowerMgr::g_mockGetTokenTypeFlagRet; 55 } 56 IsSystemAppByFullTokenID(uint64_t tokenId)57bool TokenIdKit::IsSystemAppByFullTokenID(uint64_t tokenId) 58 { 59 return PowerMgr::g_isSystemApp; 60 } 61 } // namespace AccessToken 62 } // namespace Security 63 } // namespace OHOS 64