• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ACCESS_MMS_TOKEN_H
17 #define ACCESS_MMS_TOKEN_H
18 
19 #include "accesstoken_kit.h"
20 #include "token_setproc.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 using namespace Security::AccessToken;
25 using Security::AccessToken::AccessTokenID;
26 
27 class AccessMmsToken {
28     HapInfoParams testMmsInfoParams = {
29         .userID = 1,
30         .bundleName = "tel_sms_mms_test",
31         .instIndex = 0,
32         .appIDDesc = "test",
33         .isSystemApp = true,
34     };
35     PermissionDef testPermReceiveSmsDef = {
36         .permissionName = "ohos.permission.RECEIVE_SMS",
37         .bundleName = "tel_sms_mms_test",
38         .grantMode = 1, // SYSTEM_GRANT
39         .availableLevel = APL_SYSTEM_BASIC,
40         .label = "label",
41         .labelId = 1,
42         .description = "Test sms manager",
43         .descriptionId = 1,
44     };
45     PermissionStateFull testReceiveSmsState = {
46         .permissionName = "ohos.permission.RECEIVE_SMS",
47         .isGeneral = true,
48         .resDeviceID = { "local" },
49         .grantStatus = { PermissionState::PERMISSION_GRANTED },
50         .grantFlags = { 2 }, // PERMISSION_USER_SET
51     };
52     PermissionDef testPermSendSmsDef = {
53         .permissionName = "ohos.permission.SEND_MESSAGES",
54         .bundleName = "tel_sms_mms_test",
55         .grantMode = 1, // SYSTEM_GRANT
56         .availableLevel = APL_SYSTEM_BASIC,
57         .label = "label",
58         .labelId = 1,
59         .description = "Test sms manager",
60         .descriptionId = 1,
61     };
62     PermissionStateFull testSendSmsState = {
63         .permissionName = "ohos.permission.SEND_MESSAGES",
64         .isGeneral = true,
65         .resDeviceID = { "local" },
66         .grantStatus = { PermissionState::PERMISSION_GRANTED },
67         .grantFlags = { 2 }, // PERMISSION_USER_SET
68     };
69     PermissionDef testPermSetTelephonyDef = {
70         .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
71         .bundleName = "tel_sms_mms_test",
72         .grantMode = 1, // SYSTEM_GRANT
73         .availableLevel = APL_SYSTEM_BASIC,
74         .label = "label",
75         .labelId = 1,
76         .description = "Test sms manager",
77         .descriptionId = 1,
78     };
79     PermissionStateFull testSetTelephonyState = {
80         .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
81         .isGeneral = true,
82         .resDeviceID = { "local" },
83         .grantStatus = { PermissionState::PERMISSION_GRANTED },
84         .grantFlags = { 2 }, // PERMISSION_USER_SET
85     };
86 
87     PermissionDef testPermGetTelephonyDef = {
88         .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
89         .bundleName = "tel_sms_mms_test",
90         .grantMode = 1, // SYSTEM_GRANT
91         .availableLevel = APL_SYSTEM_BASIC,
92         .label = "label",
93         .labelId = 1,
94         .description = "Test sms manager",
95         .descriptionId = 1,
96     };
97     PermissionStateFull testGetTelephonyState = {
98         .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
99         .isGeneral = true,
100         .resDeviceID = { "local" },
101         .grantStatus = { PermissionState::PERMISSION_GRANTED },
102         .grantFlags = { 2 }, // PERMISSION_USER_SET
103     };
104     HapPolicyParams testMmsPolicyParams = {
105         .apl = APL_SYSTEM_BASIC,
106         .domain = "test.domain",
107         .permList = { testPermReceiveSmsDef, testPermSendSmsDef, testPermSetTelephonyDef, testPermGetTelephonyDef },
108         .permStateList = { testReceiveSmsState, testSendSmsState, testSetTelephonyState, testGetTelephonyState },
109     };
110 
111 public:
AccessMmsToken()112     AccessMmsToken()
113     {
114         currentID_ = GetSelfTokenID();
115         AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testMmsInfoParams, testMmsPolicyParams);
116         accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
117         SetSelfTokenID(tokenIdEx.tokenIDEx);
118     }
~AccessMmsToken()119     ~AccessMmsToken()
120     {
121         AccessTokenKit::DeleteToken(accessID_);
122         SetSelfTokenID(currentID_);
123     }
124 
125 private:
126     AccessTokenID currentID_ = 0;
127     AccessTokenID accessID_ = 0;
128 };
129 } // namespace Telephony
130 } // namespace OHOS
131 #endif