• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "accesstoken_kit.h"
18 #include "tokenid_kit.h"
19 
20 using namespace OHOS::Security::AccessToken;
21 namespace OHOS::Rosen {
22 namespace {
23 bool g_isSystemApp = true;
24 bool g_isMockGetTokenTypeFlagRet = true;
25 int32_t g_accessTokenKitRet = 0;
26 }
27 
MockIsSystemApp(const bool isSystemApp)28 void MockAccesstokenKit::MockIsSystemApp(const bool isSystemApp)
29 {
30     g_isSystemApp = isSystemApp;
31 }
32 
MockIsSACalling(const bool mockGetTokenTypeFlagRet)33 void MockAccesstokenKit::MockIsSACalling(const bool mockGetTokenTypeFlagRet)
34 {
35     g_isMockGetTokenTypeFlagRet = mockGetTokenTypeFlagRet;
36 }
37 
MockAccessTokenKitRet(int32_t accessTokenKitRet)38 void MockAccesstokenKit::MockAccessTokenKitRet(int32_t accessTokenKitRet)
39 {
40     g_accessTokenKitRet = accessTokenKitRet;
41 }
42 
ChangeMockStateToInit()43 void MockAccesstokenKit::ChangeMockStateToInit()
44 {
45     g_isSystemApp = true;
46     g_isMockGetTokenTypeFlagRet = true;
47     g_accessTokenKitRet = 0;
48 }
49 }
50 
51 namespace OHOS::Security::AccessToken {
IsSystemAppByFullTokenID(uint64_t tokenId)52 bool TokenIdKit::IsSystemAppByFullTokenID(uint64_t tokenId)
53 {
54     return Rosen::g_isSystemApp;
55 }
56 
GetTokenTypeFlag(AccessTokenID tokenId)57 ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenId)
58 {
59     if (Rosen::g_isMockGetTokenTypeFlagRet) {
60         return Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE;
61     }
62     return Security::AccessToken::ATokenTypeEnum::TOKEN_INVALID;
63 }
64 
VerifyAccessToken(uint32_t AccessTokenID,const std::string & permissionName)65 int32_t AccessTokenKit::VerifyAccessToken(uint32_t AccessTokenID, const std::string& permissionName)
66 {
67     return Rosen::g_accessTokenKitRet;
68 }
69 } // namespace OHOS::Security::AccessToken