/* * Copyright (C) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TELEPHONY_TOKEN_H #define TELEPHONY_TOKEN_H #include "accesstoken_kit.h" #include "token_setproc.h" namespace OHOS { namespace Telephony { using namespace Security::AccessToken; using Security::AccessToken::AccessTokenID; inline HapInfoParams testInfoParams = { .bundleName = "tel_cellular_call_cs_gtest", .userID = 1, .instIndex = 0, .appIDDesc = "test", }; inline PermissionDef testPermPlaceCallDef = { .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE", .bundleName = "tel_cellular_call_cs_gtest", .grantMode = 1, // SYSTEM_GRANT .label = "label", .labelId = 1, .description = "Test cellular call", .descriptionId = 1, .availableLevel = APL_SYSTEM_BASIC, }; inline PermissionStateFull testPlaceCallState = { .grantFlags = { 2 }, // PERMISSION_USER_SET .grantStatus = { PermissionState::PERMISSION_GRANTED }, .isGeneral = true, .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE", .resDeviceID = { "local" }, }; inline HapPolicyParams testPolicyParams = { .apl = APL_SYSTEM_BASIC, .domain = "test.domain", .permList = { testPermPlaceCallDef }, .permStateList = { testPlaceCallState }, }; class AccessToken { public: AccessToken() { currentID_ = GetSelfTokenID(); AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams); accessID_ = tokenIdEx.tokenIdExStruct.tokenID; SetSelfTokenID(accessID_); } ~AccessToken() { AccessTokenKit::DeleteToken(accessID_); SetSelfTokenID(currentID_); } private: AccessTokenID currentID_ = 0; AccessTokenID accessID_ = 0; }; } // namespace Telephony } // namespace OHOS #endif // TELEPHONY_TOKEN_H