1 /*
2 * Copyright (C) 2022-2024 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 #define private public
16 #define protected public
17 #include "bluetooth_call_client.h"
18 #include "bluetooth_call_manager.h"
19 #include "bluetooth_call_service.h"
20 #include "bluetooth_connection.h"
21 #include "iremote_broker.h"
22 #include "call_ability_callback.h"
23 #include "call_ability_connect_callback.h"
24 #include "call_ability_report_proxy.h"
25 #include "call_connect_ability.h"
26 #include "call_control_manager.h"
27 #include "call_manager_client.h"
28 #include "call_manager_hisysevent.h"
29 #include "call_number_utils.h"
30 #include "call_policy.h"
31 #include "call_records_manager.h"
32 #include "call_request_event_handler_helper.h"
33 #include "call_request_handler.h"
34 #include "call_request_process.h"
35 #include "call_setting_manager.h"
36 #include "call_state_report_proxy.h"
37 #include "call_status_manager.h"
38 #include "cellular_call_connection.h"
39 #include "common_event_manager.h"
40 #include "common_event_support.h"
41 #include "cs_call.h"
42 #include "cs_conference.h"
43 #include "distributed_call_manager.h"
44 #include "gtest/gtest.h"
45 #include "i_voip_call_manager_service.h"
46 #include "ims_call.h"
47 #include "ims_conference.h"
48 #include "incoming_call_notification.h"
49 #include "missed_call_notification.h"
50 #include "ott_call.h"
51 #include "ott_conference.h"
52 #include "reject_call_sms.h"
53 #include "report_call_info_handler.h"
54 #include "satellite_call.h"
55 #include "surface_utils.h"
56 #include "telephony_errors.h"
57 #include "telephony_hisysevent.h"
58 #include "telephony_log_wrapper.h"
59 #include "video_call_state.h"
60 #include "video_control_manager.h"
61 #include "voip_call_manager_proxy.h"
62 #include "voip_call.h"
63 #include "accesstoken_kit.h"
64 #include "token_setproc.h"
65 #include "nativetoken_kit.h"
66 #include "number_identity_data_base_helper.h"
67 #include "call_ability_callback_death_recipient.h"
68 #include "app_state_observer.h"
69 #include "call_ability_callback_proxy.h"
70 #include "super_privacy_manager_client.h"
71 #include "call_status_callback.h"
72 #include "satellite_call_control.h"
73 #include "proximity_sensor.h"
74 #include "status_bar.h"
75 #include "wired_headset.h"
76 #include "call_status_policy.h"
77
78 namespace OHOS {
79 namespace Telephony {
80 using namespace testing::ext;
81
82 namespace {
83 const int32_t INVALID_SLOTID = 2;
84 const int32_t SIM1_SLOTID = 0;
85 const int32_t DEFAULT_INDEX = 1;
86 const int16_t CAMERA_ROTATION_0 = 0;
87 const int16_t CAMERA_ROTATION_90 = 90;
88 const int16_t CAMERA_ROTATION_180 = 180;
89 const int16_t CAMERA_ROTATION_270 = 270;
90 const int32_t INVALID_MODE = 0;
91 const int32_t VALID_CALLID = 1;
92 const int32_t ERROR_CALLID = -1;
93 const int32_t ONE_TIME = 1;
94 const int32_t STEP_1 = 1;
95 const int32_t SOURCE_CALL = 2;
96 constexpr int16_t DEFAULT_TIME = 0;
97 constexpr const char *TEST_STR = "123";
98 constexpr const char *LONG_STR =
99 "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
100 "111111111";
101 } // namespace
102
103 class DemoHandler : public AppExecFwk::EventHandler {
104 public:
DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> & eventRunner)105 explicit DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> &eventRunner) : AppExecFwk::EventHandler(eventRunner)
106 {}
~DemoHandler()107 virtual ~DemoHandler() {}
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)108 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) {}
109 };
110
111 class ZeroBranch6Test : public testing::Test {
112 public:
113 void SetUp();
114 void TearDown();
115 static void SetUpTestCase();
116 static void TearDownTestCase();
117 };
118
SetUp()119 void ZeroBranch6Test::SetUp() {}
120
TearDown()121 void ZeroBranch6Test::TearDown() {}
122
SetUpTestCase()123 void ZeroBranch6Test::SetUpTestCase()
124 {
125 constexpr int permissionNum = 1;
126 const char *perms[permissionNum] = {
127 "ohos.permission.GET_TELEPHONY_STATE"
128 };
129 NativeTokenInfoParams infoInstance = {
130 .dcapsNum = 0, // Indicates the capsbility list of the sa.
131 .permsNum = permissionNum,
132 .aclsNum = 0, // acls is the list of rights thar can be escalated.
133 .dcaps = nullptr,
134 .perms = perms,
135 .acls = nullptr,
136 .processName = "ZeroBranch6Test",
137 .aplStr = "system_basic",
138 };
139 uint64_t tokenId = GetAccessTokenId(&infoInstance);
140 SetSelfTokenID(tokenId);
141 auto result = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
142 EXPECT_EQ(result, Security::AccessToken::RET_SUCCESS);
143 }
144
TearDownTestCase()145 void ZeroBranch6Test::TearDownTestCase() {}
146
CreateDataShareHelper(std::string uri)147 std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(std::string uri)
148 {
149 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
150 if (saManager == nullptr) {
151 printf("Get system ability mgr failed.");
152 return nullptr;
153 }
154 auto remoteObj = saManager->GetSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
155 if (remoteObj == nullptr) {
156 printf("GetSystemAbility Service Failed.");
157 return nullptr;
158 }
159 return DataShare::DataShareHelper::Creator(remoteObj, uri);
160 }
161
162 /**
163 * @tc.number Telephony_CallStatusCallbackStub_004
164 * @tc.name test error branch
165 * @tc.desc Function test
166 */
167 HWTEST_F(ZeroBranch6Test, Telephony_CallStatusCallbackStub_004, Function | MediumTest | Level3)
168 {
169 auto callStatusCallback = std::make_shared<CallStatusCallback>();
170 MessageParcel data;
171 data.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
172 MessageParcel reply;
173 int32_t vecSize = 1;
174 int32_t accountId = 0;
175 int32_t defaultNumber = 0;
176 std::string defaultString = "";
177 std::vector<uint8_t> userProfile = {};
178 char accountNum[kMaxNumberLen + 1] = { 0 };
179 data.WriteInt32(vecSize);
180 data.WriteInt32(0);
181 data.WriteCString(accountNum);
182 data.WriteInt32(accountId);
183 data.WriteInt32(static_cast<int32_t>(CallType::TYPE_VOIP));
184 data.WriteInt32(static_cast<int32_t>(VideoStateType::TYPE_VOICE));
185 data.WriteInt32(static_cast<int32_t>(TelCallState::CALL_STATUS_ACTIVE));
186 data.WriteInt32(defaultNumber);
187 data.WriteInt32(defaultNumber);
188 data.WriteInt32(defaultNumber);
189 data.WriteInt32(defaultNumber);
190 data.WriteString(defaultString);
191 data.WriteString(defaultString);
192 data.WriteString(defaultString);
193 data.WriteString(defaultString);
194 data.WriteString(defaultString);
195 data.WriteUInt8Vector(userProfile);
196 data.WriteInt32(SIM1_SLOTID);
197 data.RewindRead(0);
198 callStatusCallback->OnUpdateCallsReportInfo(data, reply);
199
200 MessageParcel dataParcel;
201 dataParcel.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
202 CellularCallEventInfo info;
203 int32_t length = sizeof(CellularCallEventInfo);
204 info.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
205 info.eventId = RequestResultEventId::INVALID_REQUEST_RESULT_EVENT_ID;
206 dataParcel.WriteInt32(length);
207 dataParcel.WriteRawData((const void *)&info, length);
208 dataParcel.RewindRead(0);
209 MessageParcel reply1;
210 ASSERT_NE(callStatusCallback->OnUpdateEventReport(dataParcel, reply1), TELEPHONY_SUCCESS);
211 }
212
213 /**
214 * @tc.number Telephony_CallStatusCallbackStub_005
215 * @tc.name test error branch
216 * @tc.desc Function test
217 */
218 HWTEST_F(ZeroBranch6Test, Telephony_CallStatusCallbackStub_005, Function | MediumTest | Level3)
219 {
220 auto callStatusCallback = std::make_shared<CallStatusCallback>();
221 MessageParcel data;
222 data.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
223 int32_t defaultNumber = 0;
224 MessageParcel reply;
225 CallWaitResponse callWaitResponse;
226 int32_t length = sizeof(CallWaitResponse);
227 data.WriteInt32(length);
228 callWaitResponse.result = defaultNumber;
229 callWaitResponse.status = defaultNumber;
230 callWaitResponse.classCw = defaultNumber;
231 data.WriteRawData((const void *)&callWaitResponse, length);
232 data.RewindRead(0);
233 callStatusCallback->OnUpdateGetWaitingResult(data, reply);
234 MessageParcel dataParcel;
235 dataParcel.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
236 CallRestrictionResponse callRestrictionResult;
237 length = sizeof(CallRestrictionResponse);
238 dataParcel.WriteInt32(length);
239 callRestrictionResult.result = 0;
240 callRestrictionResult.status = 0;
241 callRestrictionResult.classCw = 0;
242 dataParcel.WriteRawData((const void *)&callRestrictionResult, length);
243 dataParcel.RewindRead(0);
244 MessageParcel reply1;
245 callStatusCallback->OnUpdateGetRestrictionResult(dataParcel, reply1);
246 MessageParcel dataParcel2;
247 dataParcel2.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
248 CallTransferResponse callTransferResponse;
249 length = sizeof(CallTransferResponse);
250 dataParcel.WriteInt32(length);
251 callTransferResponse.result = defaultNumber;
252 callTransferResponse.status = defaultNumber;
253 callTransferResponse.classx = defaultNumber;
254 callTransferResponse.type = defaultNumber;
255 std::string msg("hello");
256 int32_t accountLength = msg.length() > kMaxNumberLen ? kMaxNumberLen : msg.length();
257 memcpy_s(callTransferResponse.number, kMaxNumberLen, msg.c_str(), accountLength);
258 callTransferResponse.reason = defaultNumber;
259 callTransferResponse.time = defaultNumber;
260 callTransferResponse.startHour = defaultNumber;
261 callTransferResponse.startMinute = defaultNumber;
262 callTransferResponse.endHour = defaultNumber;
263 callTransferResponse.endMinute = defaultNumber;
264 dataParcel2.WriteRawData((const void *)&callTransferResponse, length);
265 dataParcel2.RewindRead(0);
266 MessageParcel reply2;
267 ASSERT_NE(callStatusCallback->OnUpdateGetTransferResult(dataParcel2, reply2), TELEPHONY_SUCCESS);
268 }
269
270 /**
271 * @tc.number Telephony_CallStatusCallbackStub_006
272 * @tc.name test error branch
273 * @tc.desc Function test
274 */
275 HWTEST_F(ZeroBranch6Test, Telephony_CallStatusCallbackStub_006, Function | MediumTest | Level3)
276 {
277 auto callStatusCallback = std::make_shared<CallStatusCallback>();
278 MessageParcel dataParcel;
279 dataParcel.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
280 MessageParcel reply;
281 ClipResponse clipResponse;
282 int32_t length = sizeof(ClipResponse);
283 dataParcel.WriteInt32(length);
284 dataParcel.WriteRawData((const void *)&clipResponse, length);
285 dataParcel.RewindRead(0);
286 callStatusCallback->OnUpdateGetCallClipResult(dataParcel, reply);
287
288 MessageParcel dataParcel2;
289 dataParcel2.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
290 GetImsConfigResponse response;
291 length = sizeof(GetImsConfigResponse);
292 dataParcel2.WriteInt32(length);
293 dataParcel2.WriteRawData((const void *)&response, length);
294 dataParcel2.RewindRead(0);
295 MessageParcel reply2;
296 callStatusCallback->OnGetImsConfigResult(dataParcel2, reply2);
297
298 MessageParcel dataParcel3;
299 dataParcel3.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
300 GetImsFeatureValueResponse response1;
301 length = sizeof(GetImsFeatureValueResponse);
302 dataParcel3.WriteInt32(length);
303 dataParcel3.WriteRawData((const void *)&response1, length);
304 dataParcel3.RewindRead(0);
305 MessageParcel reply3;
306 callStatusCallback->OnGetImsFeatureValueResult(dataParcel3, reply3);
307
308 MessageParcel dataParcel4;
309 dataParcel4.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
310 MmiCodeInfo info;
311 length = sizeof(MmiCodeInfo);
312 dataParcel4.WriteInt32(length);
313 info.result = 0;
314 std::string msg("hello");
315 int32_t msgLength = msg.length() > kMaxNumberLen ? kMaxNumberLen : msg.length();
316 memcpy_s(info.message, kMaxNumberLen, msg.c_str(), msgLength);
317 dataParcel4.WriteRawData((const void *)&info, length);
318 dataParcel4.RewindRead(0);
319 ASSERT_NE(callStatusCallback->OnSendMmiCodeResult(dataParcel4, reply), TELEPHONY_SUCCESS);
320 }
321
322 /**
323 * @tc.number Telephony_CallStatusCallbackStub_007
324 * @tc.name test error branch
325 * @tc.desc Function test
326 */
327 HWTEST_F(ZeroBranch6Test, Telephony_CallStatusCallbackStub_007, Function | MediumTest | Level3)
328 {
329 auto callStatusCallback = std::make_shared<CallStatusCallback>();
330 MessageParcel dataParcel;
331 dataParcel.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
332 int32_t length = sizeof(CallModeReportInfo);
333 dataParcel.WriteInt32(length);
334 CallModeReportInfo callModeReportInfo;
335 dataParcel.WriteRawData((const void *)&callModeReportInfo, length);
336 dataParcel.RewindRead(0);
337 MessageParcel reply;
338 callStatusCallback->OnReceiveImsCallModeRequest(dataParcel, reply);
339
340 MessageParcel dataParcel2;
341 dataParcel2.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
342 length = sizeof(CallSessionReportInfo);
343 dataParcel2.WriteInt32(length);
344 CallSessionReportInfo callSessionReportInfo;
345 dataParcel2.WriteRawData((const void *)&callSessionReportInfo, length);
346 dataParcel2.RewindRead(0);
347 MessageParcel reply2;
348 callStatusCallback->OnCallSessionEventChange(dataParcel2, reply2);
349
350 MessageParcel dataParcel3;
351 dataParcel3.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
352 length = sizeof(PeerDimensionsReportInfo);
353 dataParcel3.WriteInt32(length);
354 PeerDimensionsReportInfo dimensionsReportInfo;
355 dataParcel3.WriteRawData((const void *)&dimensionsReportInfo, length);
356 dataParcel3.RewindRead(0);
357 MessageParcel reply3;
358 callStatusCallback->OnPeerDimensionsChange(dataParcel3, reply3);
359
360 MessageParcel dataParcel4;
361 dataParcel4.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
362 int64_t reportInfo = static_cast<int64_t>(10);
363 dataParcel4.WriteInt64(reportInfo);
364 dataParcel4.RewindRead(0);
365 MessageParcel reply4;
366 callStatusCallback->OnCallDataUsageChange(dataParcel4, reply4);
367
368 MessageParcel dataParcel5;
369 dataParcel5.WriteInterfaceToken(CallStatusCallbackStub::GetDescriptor());
370 length = sizeof(CameraCapabilitiesReportInfo);
371 dataParcel5.WriteInt32(length);
372 CameraCapabilitiesReportInfo cameraCapabilitiesReportInfo;
373 dataParcel5.WriteRawData((const void *)&cameraCapabilitiesReportInfo, length);
374 dataParcel5.RewindRead(0);
375 MessageParcel reply5;
376 ASSERT_NE(callStatusCallback->OnCameraCapabilitiesChange(dataParcel5, reply5), TELEPHONY_SUCCESS);
377 }
378
379 /**
380 * @tc.number Telephony_SatelliteCallControl_001
381 * @tc.name test error branch
382 * @tc.desc Function test
383 */
384 HWTEST_F(ZeroBranch6Test, Telephony_SatelliteCallControl_001, Function | MediumTest | Level3)
385 {
386 auto satelliteCallControl = DelayedSingleton<SatelliteCallControl>::GetInstance();
387 int32_t level = static_cast<int32_t>(SatCommTempLevel::TEMP_LEVEL_HIGH);
388 satelliteCallControl->SetSatcommTempLevel(level);
389 satelliteCallControl->IsAllowedSatelliteDialCall();
390 satelliteCallControl->IsSatelliteSwitchEnable();
391 satelliteCallControl->GetSatcommTempLevel();
392 sptr<CallBase> call = nullptr;
393 TelCallState priorState = TelCallState::CALL_STATUS_DIALING;
394 TelCallState nextState = TelCallState::CALL_STATUS_ALERTING;
395 satelliteCallControl->HandleSatelliteCallStateUpdate(call, priorState, nextState);
396 satelliteCallControl->IsShowDialog();
397 bool isShowDialog = true;
398 satelliteCallControl->SetShowDialog(isShowDialog);
399 ASSERT_EQ(isShowDialog, true);
400 }
401
402 /**
403 * @tc.number Telephony_ProximitySensor_001
404 * @tc.name test error branch
405 * @tc.desc Function test
406 */
407 HWTEST_F(ZeroBranch6Test, Telephony_ProximitySensor_001, Function | MediumTest | Level3)
408 {
409 auto proximitySensor = DelayedSingleton<ProximitySensor>::GetInstance();
410 sptr<CallBase> callObjectPtr = nullptr;
411 proximitySensor->NewCallCreated(callObjectPtr);
412 proximitySensor->CallStateUpdated(callObjectPtr, TelCallState::CALL_STATUS_IDLE,
413 TelCallState::CALL_STATUS_INCOMING);
414 proximitySensor->IncomingCallHungUp(callObjectPtr, false, "");
415 proximitySensor->IncomingCallActivated(callObjectPtr);
416 DisconnectedDetails details;
417 proximitySensor->CallDestroyed(details);
418 ASSERT_NE(proximitySensor, nullptr);
419 }
420
421 /**
422 * @tc.number Telephony_StatusBar_001
423 * @tc.name test error branch
424 * @tc.desc Function test
425 */
426 HWTEST_F(ZeroBranch6Test, Telephony_StatusBar_001, Function | MediumTest | Level3)
427 {
428 auto statusBar = DelayedSingleton<StatusBar>::GetInstance();
429 sptr<CallBase> callObjectPtr = nullptr;
430 statusBar->NewCallCreated(callObjectPtr);
431 bool isDisplayMute = false;
432 statusBar->UpdateMuteIcon(isDisplayMute);
433 statusBar->UpdateSpeakerphoneIcon(isDisplayMute);
434 statusBar->CallStateUpdated(callObjectPtr, TelCallState::CALL_STATUS_IDLE, TelCallState::CALL_STATUS_INCOMING);
435 statusBar->IncomingCallHungUp(callObjectPtr, false, "");
436 statusBar->IncomingCallActivated(callObjectPtr);
437 DisconnectedDetails details;
438 statusBar->CallDestroyed(details);
439 ASSERT_NE(statusBar, nullptr);
440 }
441
442 /**
443 * @tc.number Telephony_WiredHeadset_001
444 * @tc.name test error branch
445 * @tc.desc Function test
446 */
447 HWTEST_F(ZeroBranch6Test, Telephony_WiredHeadset_001, Function | MediumTest | Level3)
448 {
449 auto wiredHeadset = DelayedSingleton<WiredHeadset>::GetInstance();
450 sptr<CallBase> callObjectPtr = nullptr;
451 wiredHeadset->Init();
452 wiredHeadset->NewCallCreated(callObjectPtr);
453 wiredHeadset->CallStateUpdated(callObjectPtr, TelCallState::CALL_STATUS_IDLE, TelCallState::CALL_STATUS_INCOMING);
454 wiredHeadset->IncomingCallHungUp(callObjectPtr, false, "");
455 wiredHeadset->IncomingCallActivated(callObjectPtr);
456 DisconnectedDetails details;
457 wiredHeadset->CallDestroyed(details);
458 ASSERT_NE(wiredHeadset, nullptr);
459 }
460
461 /**
462 * @tc.number Telephony_CallStatusPolicy_001
463 * @tc.name test error branch
464 * @tc.desc Function test
465 */
466 HWTEST_F(ZeroBranch6Test, Telephony_CallStatusPolicy_001, Function | MediumTest | Level3)
467 {
468 CallStatusPolicy callStatusPolicy;
469 CallDetailInfo info;
470 callStatusPolicy.DialingHandlePolicy(info);
471 int32_t res = callStatusPolicy.FilterResultsDispose(nullptr);
472 ASSERT_NE(res, TELEPHONY_SUCCESS);
473 }
474
475 /**
476 * @tc.number Telephony_CallAbilityCallback_002
477 * @tc.name test error branch
478 * @tc.desc Function test
479 */
480 HWTEST_F(ZeroBranch6Test, Telephony_CallAbilityCallback_002, Function | MediumTest | Level3)
481 {
482 auto callAbilityCallback = std::make_shared<CallAbilityCallback>();
483 MessageParcel data;
484 MessageParcel reply;
485 MessageOption option;
486 callAbilityCallback->OnRemoteRequest(static_cast<uint32_t>(CallStatusInterfaceCode::UPDATE_VOIP_EVENT_INFO),
487 data, reply, option);
488 callAbilityCallback->OnUpdateCallStateInfo(data, reply);
489 callAbilityCallback->OnUpdateCallEvent(data, reply);
490 callAbilityCallback->OnUpdateCallDisconnectedCause(data, reply);
491 callAbilityCallback->OnUpdateAysncResults(data, reply);
492 callAbilityCallback->OnUpdateMmiCodeResults(data, reply);
493 callAbilityCallback->OnUpdateAudioDeviceChange(data, reply);
494 callAbilityCallback->OnUpdateOttCallRequest(data, reply);
495 callAbilityCallback->OnUpdatePostDialDelay(data, reply);
496 callAbilityCallback->OnUpdateImsCallModeChange(data, reply);
497 callAbilityCallback->OnUpdateCallSessionEventChange(data, reply);
498 callAbilityCallback->OnUpdatePeerDimensionsChange(data, reply);
499 callAbilityCallback->OnUpdateCallDataUsageChange(data, reply);
500 ASSERT_NE(callAbilityCallback->OnUpdateCameraCapabilities(data, reply), TELEPHONY_SUCCESS);
501 }
502 } // namespace Telephony
503 } // namespace OHOS
504