/* * Copyright (c) 2024 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. */ #include "data_access_token.h" #include #include "nativetoken_kit.h" #include "token_setproc.h" namespace OHOS { namespace Telephony { using namespace Security::AccessToken; using Security::AccessToken::AccessTokenID; namespace { HapInfoParams testInfoParams = { .bundleName = "tel_cellular_data_test", .userID = 1, .instIndex = 0, .appIDDesc = "test", .isSystemApp = true, }; PermissionDef testPermGetNetworkInfoDef = { .permissionName = "ohos.permission.GET_NETWORK_INFO", .bundleName = "tel_cellular_data_test", .grantMode = 1, // SYSTEM_GRANT .label = "label", .labelId = 1, .description = "Test cellular data", .descriptionId = 1, .availableLevel = APL_SYSTEM_BASIC, }; PermissionStateFull testGetNetworkInfoState = { .grantFlags = { 2 }, // PERMISSION_USER_SET .grantStatus = { PermissionState::PERMISSION_GRANTED }, .isGeneral = true, .permissionName = "ohos.permission.GET_NETWORK_INFO", .resDeviceID = { "local" }, }; PermissionDef testPermSetTelephonyStateDef = { .permissionName = "ohos.permission.SET_TELEPHONY_STATE", .bundleName = "tel_cellular_data_test", .grantMode = 1, // SYSTEM_GRANT .label = "label", .labelId = 1, .description = "Test cellular data", .descriptionId = 1, .availableLevel = APL_SYSTEM_BASIC, }; PermissionStateFull testSetTelephonyState = { .grantFlags = { 2 }, // PERMISSION_USER_SET .grantStatus = { PermissionState::PERMISSION_GRANTED }, .isGeneral = true, .permissionName = "ohos.permission.SET_TELEPHONY_STATE", .resDeviceID = { "local" }, }; HapPolicyParams testPolicyParams = { .apl = APL_SYSTEM_BASIC, .domain = "test.domain", .permList = { testPermGetNetworkInfoDef, testPermSetTelephonyStateDef }, .permStateList = { testGetNetworkInfoState, testSetTelephonyState }, }; } // namespace DataAccessToken::DataAccessToken() { currentID_ = GetSelfTokenID(); AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams); accessID_ = tokenIdEx.tokenIdExStruct.tokenID; SetSelfTokenID(tokenIdEx.tokenIDEx); } DataAccessToken::~DataAccessToken() { AccessTokenKit::DeleteToken(accessID_); SetSelfTokenID(currentID_); } } // namespace Telephony } // namespace OHOS