Files
liuleimin_hw cd0c0534d8 APN查询
Signed-off-by: liuleimin_hw <liuleimin1@huawei.com>
2025-06-17 20:09:19 +08:00

135 lines
4.2 KiB
C++

/*
* 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 <iostream>
#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" },
};
PermissionDef testPermGetTelephonyStateDef = {
.permissionName = "ohos.permission.GET_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 testGetTelephonyState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.resDeviceID = { "local" },
};
PermissionDef testPermManagerApnSettingDef = {
.permissionName = "ohos.permission.MANAGE_APN_SETTING",
.bundleName = "tel_cellular_data_test",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test cellular data",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
PermissionStateFull testManagerApnSetting = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.MANAGE_APN_SETTING",
.resDeviceID = { "local" },
};
HapPolicyParams testPolicyParams = {
.apl = APL_SYSTEM_BASIC,
.domain = "test.domain",
.permList = { testPermGetNetworkInfoDef, testPermSetTelephonyStateDef,
testPermGetTelephonyStateDef, testPermManagerApnSettingDef },
.permStateList = { testGetNetworkInfoState, testSetTelephonyState, testGetTelephonyState, testManagerApnSetting },
};
} // 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