1bc2ed2b3Sopenharmony_ci/*
2bc2ed2b3Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License.
5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at
6bc2ed2b3Sopenharmony_ci *
7bc2ed2b3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc2ed2b3Sopenharmony_ci *
9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and
13bc2ed2b3Sopenharmony_ci * limitations under the License.
14bc2ed2b3Sopenharmony_ci */
15bc2ed2b3Sopenharmony_ci#include "nfc_permission_checker.h"
16bc2ed2b3Sopenharmony_ci#include "accesstoken_kit.h"
17bc2ed2b3Sopenharmony_ci#include "ipc_skeleton.h"
18bc2ed2b3Sopenharmony_ci#include "loghelper.h"
19bc2ed2b3Sopenharmony_ci
20bc2ed2b3Sopenharmony_cinamespace OHOS {
21bc2ed2b3Sopenharmony_cinamespace NFC {
22bc2ed2b3Sopenharmony_cibool NfcPermissionChecker::IsGranted(std::string permission)
23bc2ed2b3Sopenharmony_ci{
24bc2ed2b3Sopenharmony_ci    Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
25bc2ed2b3Sopenharmony_ci    int result = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
26bc2ed2b3Sopenharmony_ci    if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) ==
27bc2ed2b3Sopenharmony_ci        Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
28bc2ed2b3Sopenharmony_ci        result =  Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permission);
29bc2ed2b3Sopenharmony_ci    } else if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) ==
30bc2ed2b3Sopenharmony_ci        Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) {
31bc2ed2b3Sopenharmony_ci        result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permission);
32bc2ed2b3Sopenharmony_ci    }
33bc2ed2b3Sopenharmony_ci    return result == Security::AccessToken::PermissionState::PERMISSION_GRANTED;
34bc2ed2b3Sopenharmony_ci}
35bc2ed2b3Sopenharmony_ci} // namespace NFC
36bc2ed2b3Sopenharmony_ci}  // namespace OHOS
37