• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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_cs_gtest",
28     .userID = 1,
29     .instIndex = 0,
30     .appIDDesc = "test",
31 };
32 
33 inline PermissionDef testPermPlaceCallDef = {
34     .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE",
35     .bundleName = "tel_cellular_call_cs_gtest",
36     .grantMode = 1, // SYSTEM_GRANT
37     .label = "label",
38     .labelId = 1,
39     .description = "Test cellular call",
40     .descriptionId = 1,
41     .availableLevel = APL_SYSTEM_BASIC,
42 };
43 
44 inline PermissionStateFull testPlaceCallState = {
45     .grantFlags = { 2 }, // PERMISSION_USER_SET
46     .grantStatus = { PermissionState::PERMISSION_GRANTED },
47     .isGeneral = true,
48     .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE",
49     .resDeviceID = { "local" },
50 };
51 
52 inline HapPolicyParams testPolicyParams = {
53     .apl = APL_SYSTEM_BASIC,
54     .domain = "test.domain",
55     .permList = { testPermPlaceCallDef },
56     .permStateList = { testPlaceCallState },
57 };
58 
59 class AccessToken {
60 public:
AccessToken()61     AccessToken()
62     {
63         currentID_ = GetSelfTokenID();
64         AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
65         accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
66         SetSelfTokenID(accessID_);
67     }
~AccessToken()68     ~AccessToken()
69     {
70         AccessTokenKit::DeleteToken(accessID_);
71         SetSelfTokenID(currentID_);
72     }
73 
74 private:
75     AccessTokenID currentID_ = 0;
76     AccessTokenID accessID_ = 0;
77 };
78 } // namespace Telephony
79 } // namespace OHOS
80 #endif // TELEPHONY_TOKEN_H
81