• 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 CALL_MANAGER_CONNECT_H
17 #define CALL_MANAGER_CONNECT_H
18 #include <string_ex.h>
19 #include <list>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 #include <unordered_set>
24 
25 #include "accesstoken_kit.h"
26 #include "call_manager_client.h"
27 #include "call_manager_errors.h"
28 #include "call_manager_service_proxy.h"
29 #include "native_call_manager_hisysevent.h"
30 #include "i_call_ability_callback.h"
31 #include "if_system_ability_manager.h"
32 #include "iremote_object.h"
33 #include "iremote_stub.h"
34 #include "iservice_registry.h"
35 #include "pac_map.h"
36 #include "refbase.h"
37 #include "rwlock.h"
38 #include "surface_utils.h"
39 #include "system_ability.h"
40 #include "system_ability_definition.h"
41 #include "telephony_log_wrapper.h"
42 #include "token_setproc.h"
43 
44 namespace OHOS {
45 namespace Telephony {
46 const int32_t MAX_LEN = 100000;
47 using namespace Security::AccessToken;
48 using Security::AccessToken::AccessTokenID;
49 
50 inline HapInfoParams testInfoParams = {
51     .bundleName = "tel_call_manager_gtest",
52     .userID = 1,
53     .instIndex = 0,
54     .appIDDesc = "test",
55     .isSystemApp = true,
56 };
57 
58 inline HapInfoParams testInfoParamsfalse = {
59     .bundleName = "tel_call_manager_gtest",
60     .userID = 1,
61     .instIndex = 0,
62     .appIDDesc = "test",
63     .isSystemApp = false,
64 };
65 
66 inline PermissionDef testPermPlaceCallDef = {
67     .permissionName = "ohos.permission.PLACE_CALL",
68     .bundleName = "tel_call_manager_gtest",
69     .grantMode = 1, // SYSTEM_GRANT
70     .label = "label",
71     .labelId = 1,
72     .description = "Test call manager",
73     .descriptionId = 1,
74     .availableLevel = APL_SYSTEM_BASIC,
75 };
76 
77 inline PermissionStateFull testPlaceCallState = {
78     .grantFlags = { 2 }, // PERMISSION_USER_SET
79     .grantStatus = { PermissionState::PERMISSION_GRANTED },
80     .isGeneral = true,
81     .permissionName = "ohos.permission.PLACE_CALL",
82     .resDeviceID = { "local" },
83 };
84 
85 inline PermissionDef testPermSetTelephonyStateDef = {
86     .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
87     .bundleName = "tel_call_manager_gtest",
88     .grantMode = 1, // SYSTEM_GRANT
89     .label = "label",
90     .labelId = 1,
91     .description = "Test call manager",
92     .descriptionId = 1,
93     .availableLevel = APL_SYSTEM_BASIC,
94 };
95 
96 inline PermissionStateFull testSetTelephonyState = {
97     .grantFlags = { 2 }, // PERMISSION_USER_SET
98     .grantStatus = { PermissionState::PERMISSION_GRANTED },
99     .isGeneral = true,
100     .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
101     .resDeviceID = { "local" },
102 };
103 
104 inline PermissionDef testPermGetTelephonyStateDef = {
105     .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
106     .bundleName = "tel_call_manager_gtest",
107     .grantMode = 1, // SYSTEM_GRANT
108     .label = "label",
109     .labelId = 1,
110     .description = "Test call manager",
111     .descriptionId = 1,
112     .availableLevel = APL_SYSTEM_BASIC,
113 };
114 
115 inline PermissionStateFull testGetTelephonyState = {
116     .grantFlags = { 2 }, // PERMISSION_USER_SET
117     .grantStatus = { PermissionState::PERMISSION_GRANTED },
118     .isGeneral = true,
119     .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
120     .resDeviceID = { "local" },
121 };
122 
123 inline PermissionDef testPermAnswerCallDef = {
124     .permissionName = "ohos.permission.ANSWER_CALL",
125     .bundleName = "tel_call_manager_gtest",
126     .grantMode = 1, // SYSTEM_GRANT
127     .label = "label",
128     .labelId = 1,
129     .description = "Test call manager",
130     .descriptionId = 1,
131     .availableLevel = APL_SYSTEM_BASIC,
132 };
133 
134 inline PermissionStateFull testAnswerCallState = {
135     .grantFlags = { 2 }, // PERMISSION_USER_SET
136     .grantStatus = { PermissionState::PERMISSION_GRANTED },
137     .isGeneral = true,
138     .permissionName = "ohos.permission.ANSWER_CALL",
139     .resDeviceID = { "local" },
140 };
141 
142 inline PermissionDef testReadCallLogDef = {
143     .permissionName = "ohos.permission.READ_CALL_LOG",
144     .bundleName = "tel_call_manager_gtest",
145     .grantMode = 1, // SYSTEM_GRANT
146     .label = "label",
147     .labelId = 1,
148     .description = "Test call manager",
149     .descriptionId = 1,
150     .availableLevel = APL_SYSTEM_BASIC,
151 };
152 
153 inline PermissionStateFull testPermReadCallLog = {
154     .grantFlags = { 2 }, // PERMISSION_USER_SET
155     .grantStatus = { PermissionState::PERMISSION_GRANTED },
156     .isGeneral = true,
157     .permissionName = "ohos.permission.READ_CALL_LOG",
158     .resDeviceID = { "local" },
159 };
160 
161 inline PermissionDef testWriteCallLogDef = {
162     .permissionName = "ohos.permission.WRITE_CALL_LOG",
163     .bundleName = "tel_call_manager_gtest",
164     .grantMode = 1, // SYSTEM_GRANT
165     .label = "label",
166     .labelId = 1,
167     .description = "Test call manager",
168     .descriptionId = 1,
169     .availableLevel = APL_SYSTEM_BASIC,
170 };
171 
172 inline PermissionStateFull testPermWriteCallLog = {
173     .grantFlags = { 2 }, // PERMISSION_USER_SET
174     .grantStatus = { PermissionState::PERMISSION_GRANTED },
175     .isGeneral = true,
176     .permissionName = "ohos.permission.WRITE_CALL_LOG",
177     .resDeviceID = { "local" },
178 };
179 
180 inline PermissionDef testStartAbilityFromBGDef = {
181     .permissionName = "ohos.permission.START_ABILITIES_FROM_BACKGROUND",
182     .bundleName = "tel_call_manager_gtest",
183     .grantMode = 1, // SYSTEM_GRANT
184     .label = "label",
185     .labelId = 1,
186     .description = "Test call manager",
187     .descriptionId = 1,
188     .availableLevel = APL_SYSTEM_BASIC,
189 };
190 
191 inline PermissionStateFull testPermStartAbilityFromBG = {
192     .grantFlags = { 2 }, // PERMISSION_USER_SET
193     .grantStatus = { PermissionState::PERMISSION_GRANTED },
194     .isGeneral = true,
195     .permissionName = "ohos.permission.START_ABILITIES_FROM_BACKGROUND",
196     .resDeviceID = { "local" },
197 };
198 
199 inline PermissionDef testConCellularCallDef = {
200     .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE",
201     .bundleName = "tel_cellular_call_cs_gtest",
202     .grantMode = 1, // SYSTEM_GRANT
203     .label = "label",
204     .labelId = 1,
205     .description = "Test cellular call",
206     .descriptionId = 1,
207     .availableLevel = APL_SYSTEM_BASIC,
208 };
209 
210 inline PermissionStateFull testPermConCellularCall = {
211     .grantFlags = { 2 }, // PERMISSION_USER_SET
212     .grantStatus = { PermissionState::PERMISSION_GRANTED },
213     .isGeneral = true,
214     .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE",
215     .resDeviceID = { "local" },
216 };
217 
218 inline HapPolicyParams testPolicyParams = {
219     .apl = APL_SYSTEM_BASIC,
220     .domain = "test.domain",
221     .permList = { testPermPlaceCallDef, testPermSetTelephonyStateDef, testPermGetTelephonyStateDef,
222         testPermAnswerCallDef, testReadCallLogDef, testWriteCallLogDef, testStartAbilityFromBGDef,
223         testConCellularCallDef },
224     .permStateList = { testPlaceCallState, testSetTelephonyState, testGetTelephonyState, testAnswerCallState,
225         testPermReadCallLog, testPermWriteCallLog, testPermStartAbilityFromBG, testPermConCellularCall },
226 };
227 
228 class AccessToken {
229 public:
AccessToken()230     AccessToken()
231     {
232         currentID_ = GetSelfTokenID();
233         AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
234         accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
235         SetSelfTokenID(tokenIdEx.tokenIDEx);
236     }
~AccessToken()237     ~AccessToken()
238     {
239         AccessTokenKit::DeleteToken(accessID_);
240         SetSelfTokenID(currentID_);
241     }
242 private:
243     AccessTokenID currentID_ = 0;
244     AccessTokenID accessID_ = 0;
245 };
246 
247 class AccessFalseToken {
248 public:
AccessFalseToken()249     AccessFalseToken()
250     {
251         currentID_ = GetSelfTokenID();
252         AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParamsfalse, testPolicyParams);
253         accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
254         SetSelfTokenID(tokenIdEx.tokenIDEx);
255     }
~AccessFalseToken()256     ~AccessFalseToken()
257     {
258         AccessTokenKit::DeleteToken(accessID_);
259         SetSelfTokenID(currentID_);
260     }
261 private:
262     AccessTokenID currentID_ = 0;
263     AccessTokenID accessID_ = 0;
264 };
265 } // namespace Telephony
266 } // namespace OHOS
267 
268 #endif
269