• 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 "accesstoken_kit_mock.h"
17 
18 using namespace OHOS::DistributedHardware;
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
GetTokenTypeFlag(AccessTokenID tokenID)23 ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID)
24 {
25     return AccessTokenKitInterface::GetOrCreateAccessTokenKit()->GetTokenTypeFlag(tokenID);
26 }
27 
GetHapTokenInfo(AccessTokenID tokenID,HapTokenInfo & hapTokenInfoRes)28 int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo &hapTokenInfoRes)
29 {
30     return AccessTokenKitInterface::GetOrCreateAccessTokenKit()->GetHapTokenInfo(tokenID, hapTokenInfoRes);
31 }
32 
GetNativeTokenInfo(AccessTokenID tokenID,NativeTokenInfo & nativeTokenInfoRes)33 int AccessTokenKit::GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo &nativeTokenInfoRes)
34 {
35     return AccessTokenKitInterface::GetOrCreateAccessTokenKit()->GetNativeTokenInfo(tokenID, nativeTokenInfoRes);
36 }
37 
GetNativeTokenId(const std::string & nativeTokenId)38 AccessTokenID AccessTokenKit::GetNativeTokenId(const std::string &nativeTokenId)
39 {
40     return AccessTokenKitInterface::GetOrCreateAccessTokenKit()->GetNativeTokenId(nativeTokenId);
41 }
42 
GetHapTokenID(int32_t userID,const std::string & bundleName,int32_t instIndex)43 AccessTokenID AccessTokenKit::GetHapTokenID(int32_t userID, const std::string &bundleName, int32_t instIndex)
44 {
45     return AccessTokenKitInterface::GetOrCreateAccessTokenKit()->GetHapTokenID(userID, bundleName, instIndex);
46 }
47 
VerifyAccessToken(AccessTokenID tokenID,const std::string & permissionName)48 int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName)
49 {
50     return AccessTokenKitInterface::GetOrCreateAccessTokenKit()->VerifyAccessToken(tokenID, permissionName);
51 }
52 } // namespace AccessToken
53 } // namespace Security
54 
55 namespace DistributedHardware {
56 std::shared_ptr<AccessTokenKitInterface> AccessTokenKitInterface::token_ = nullptr;
57 
GetOrCreateAccessTokenKit()58 std::shared_ptr<AccessTokenKitInterface> AccessTokenKitInterface::GetOrCreateAccessTokenKit()
59 {
60     if (!token_) {
61         token_ = std::make_shared<AccessTokenKitMock>();
62     }
63     return token_;
64 }
65 
ReleaseAccessTokenKit()66 void AccessTokenKitInterface::ReleaseAccessTokenKit()
67 {
68     token_.reset();
69     token_ = nullptr;
70 }
71 } // namespace DistributedHardware
72 } // namespace OHOS
73