1 /* 2 * Copyright (C) 2023 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 #ifndef TELEPHONY_TOKEN_H 17 #define TELEPHONY_TOKEN_H 18 #include "accesstoken_kit.h" 19 #include "token_setproc.h" 20 21 namespace OHOS { 22 namespace Telephony { 23 using namespace Security::AccessToken; 24 using Security::AccessToken::AccessTokenID; 25 26 inline HapInfoParams testInfoParams = { 27 .bundleName = "tel_cellular_call_Satellite_gtest", 28 .userID = 1, 29 .instIndex = 0, 30 .appIDDesc = "test", 31 .isSystemApp = true, 32 }; 33 34 inline PermissionDef testConnectSatelliteServiceDef = { 35 .permissionName = "ohos.permission.CONNECT_SATELLITE_SERVICE", 36 .bundleName = "tel_cellular_call_Satellite_gtest", 37 .grantMode = 1, // SYSTEM_GRANT 38 .label = "label", 39 .labelId = 1, 40 .description = "Test cellular call", 41 .descriptionId = 1, 42 .availableLevel = APL_SYSTEM_BASIC, 43 }; 44 45 inline PermissionStateFull testConnectSatelliteServiceState = { 46 .grantFlags = { 2 }, // PERMISSION_USER_SET 47 .grantStatus = { PermissionState::PERMISSION_GRANTED }, 48 .isGeneral = true, 49 .permissionName = "ohos.permission.CONNECT_SATELLITE_SERVICE", 50 .resDeviceID = { "local" }, 51 }; 52 53 inline PermissionDef testPermPlaceCallDef = { 54 .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE", 55 .bundleName = "tel_cellular_call_Satellite_gtest", 56 .grantMode = 1, // SYSTEM_GRANT 57 .label = "label", 58 .labelId = 1, 59 .description = "Test cellular call", 60 .descriptionId = 1, 61 .availableLevel = APL_SYSTEM_BASIC, 62 }; 63 64 inline PermissionStateFull testPlaceCallState = { 65 .grantFlags = { 2 }, // PERMISSION_USER_SET 66 .grantStatus = { PermissionState::PERMISSION_GRANTED }, 67 .isGeneral = true, 68 .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE", 69 .resDeviceID = { "local" }, 70 }; 71 72 inline PermissionDef testGetTelephonyStateDef = { 73 .permissionName = "ohos.permission.GET_TELEPHONY_STATE", 74 .bundleName = "tel_cellular_call_Satellite_gtest", 75 .grantMode = 1, // SYSTEM_GRANT 76 .label = "label", 77 .labelId = 1, 78 .description = "Test cellular call", 79 .descriptionId = 1, 80 .availableLevel = APL_SYSTEM_BASIC, 81 }; 82 83 inline PermissionStateFull testGetTelephonyState = { 84 .grantFlags = { 2 }, // PERMISSION_USER_SET 85 .grantStatus = { PermissionState::PERMISSION_GRANTED }, 86 .isGeneral = true, 87 .permissionName = "ohos.permission.GET_TELEPHONY_STATE", 88 .resDeviceID = { "local" }, 89 }; 90 91 inline HapPolicyParams testPolicyParams = { 92 .apl = APL_SYSTEM_BASIC, 93 .domain = "test.domain", 94 .permList = { testPermPlaceCallDef, testConnectSatelliteServiceDef, testGetTelephonyStateDef }, 95 .permStateList = { testPlaceCallState, testConnectSatelliteServiceState, testGetTelephonyState }, 96 }; 97 98 class AccessToken { 99 public: AccessToken()100 AccessToken() 101 { 102 currentID_ = GetSelfTokenID(); 103 AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams); 104 accessID_ = tokenIdEx.tokenIdExStruct.tokenID; 105 SetSelfTokenID(tokenIdEx.tokenIDEx); 106 } ~AccessToken()107 ~AccessToken() 108 { 109 AccessTokenKit::DeleteToken(accessID_); 110 SetSelfTokenID(currentID_); 111 } 112 113 private: 114 AccessTokenID currentID_ = 0; 115 AccessTokenID accessID_ = 0; 116 }; 117 } // namespace Telephony 118 } // namespace OHOS 119 120 #endif // TELEPHONY_TOKEN_H 121