• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 #include "call_manager_special_mock.h"
17 #include <thread>
18 #include <chrono>
19 #include "call_manager_connect.h"
20 #include "call_voice_assistant_manager.h"
21 #include "spam_call_adapter.h"
22 #include "bluetooth_call_client.h"
23 #include "bluetooth_call_manager.h"
24 #include "bluetooth_call_service.h"
25 #include "bluetooth_connection.h"
26 #include "iremote_broker.h"
27 #include "call_ability_connect_callback.h"
28 #include "call_ability_report_proxy.h"
29 #include "call_connect_ability.h"
30 #include "call_control_manager.h"
31 #include "call_manager_client.h"
32 #include "call_manager_hisysevent.h"
33 #include "call_number_utils.h"
34 #include "call_policy.h"
35 #include "call_records_manager.h"
36 #include "call_request_event_handler_helper.h"
37 #include "call_request_handler.h"
38 #include "call_request_process.h"
39 #include "call_setting_manager.h"
40 #include "call_state_report_proxy.h"
41 #include "call_status_manager.h"
42 #include "cellular_call_connection.h"
43 #include "common_event_manager.h"
44 #include "common_event_support.h"
45 #include "cs_call.h"
46 #include "cs_conference.h"
47 #include "distributed_call_manager.h"
48 #include "gtest/gtest.h"
49 #include "i_voip_call_manager_service.h"
50 #include "ims_call.h"
51 #include "ims_conference.h"
52 #include "incoming_call_notification.h"
53 #include "missed_call_notification.h"
54 #include "ott_call.h"
55 #include "ott_conference.h"
56 #include "reject_call_sms.h"
57 #include "report_call_info_handler.h"
58 #include "satellite_call.h"
59 #include "surface_utils.h"
60 #include "telephony_errors.h"
61 #include "telephony_hisysevent.h"
62 #include "telephony_log_wrapper.h"
63 #include "video_call_state.h"
64 #include "video_control_manager.h"
65 #include "voip_call_manager_proxy.h"
66 #include "voip_call.h"
67 #include "accesstoken_kit.h"
68 #include "token_setproc.h"
69 #include "nativetoken_kit.h"
70 #include "number_identity_data_base_helper.h"
71 #include "call_ability_callback_death_recipient.h"
72 #include "app_state_observer.h"
73 #include "call_ability_callback_proxy.h"
74 #include "super_privacy_manager_client.h"
75 #include "call_status_callback.h"
76 #include "satellite_call_control.h"
77 #include "proximity_sensor.h"
78 #include "status_bar.h"
79 #include "wired_headset.h"
80 #include "call_status_policy.h"
81 #include "call_superprivacy_control_manager.h"
82 #include "bluetooth_hfp_ag.h"
83 #include "call_manager_service.h"
84 #include "telephony_types.h"
85 #include "telephony_permission.h"
86 #include "voip_call_connection.h"
87 #include "number_identity_service.h"
88 #include "bluetooth_call.h"
89 #include "bluetooth_call_connection.h"
90 #include "bluetooth_call_state.h"
91 #include "call_broadcast_subscriber.h"
92 #include "call_incoming_filter_manager.h"
93 #include "call_object_manager.h"
94 #include "call_wired_headset.h"
95 #include "fold_status_manager.h"
96 #include "audio_control_manager.h"
97 #include "call_state_processor.h"
98 
99 namespace OHOS {
100 namespace Telephony {
101 using namespace testing::ext;
102 
103 class SpecialBranch2Test : public testing::Test {
104 public:
105     static void SetUpTestCase();
106     static void TearDownTestCase();
107     void SetUp();
108     void TearDown();
109 };
110 
SetUpTestCase()111 void SpecialBranch2Test::SetUpTestCase()
112 {
113     const char *perms[1] = {
114         "ohos.permission.WRITE_CALL_LOG",
115     };
116     NativeTokenInfoParams infoInstance = {
117         .dcapsNum = 0,
118         .permsNum = 1,
119         .aclsNum = 0,
120         .dcaps = nullptr,
121         .perms = perms,
122         .acls = nullptr,
123         .processName = "SpecialBranch2Test",
124         .aplStr = "system_basic",
125     };
126     uint64_t tokenId = GetAccessTokenId(&infoInstance);
127     SetSelfTokenID(tokenId);
128     auto result = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
129     EXPECT_EQ(result, Security::AccessToken::RET_SUCCESS);
130 }
131 
TearDownTestCase()132 void SpecialBranch2Test::TearDownTestCase()
133 {
134 }
135 
SetUp()136 void SpecialBranch2Test::SetUp()
137 {
138 }
139 
TearDown()140 void SpecialBranch2Test::TearDown()
141 {
142     sleep(1);
143 }
144 
145 /**
146  * @tc.number   Telephony_CSCall_001
147  * @tc.name     test branch
148  * @tc.desc     Function test
149  */
150 HWTEST_F(SpecialBranch2Test, Telephony_CSCall_001, TestSize.Level0)
151 {
152     DialParaInfo info;
153     auto csCall = std::make_shared<CSCall>(info);
154     ASSERT_TRUE(csCall != nullptr);
155     std::vector<std::u16string> callIdList;
156     csCall->GetSubCallIdList(callIdList);
157     int32_t ret = csCall->GetCallIdListForConference(callIdList);
158     EXPECT_NE(ret, 0);
159 }
160 
161 /**
162  * @tc.number   Telephony_CallStateListener_001
163  * @tc.name     test branch
164  * @tc.desc     Function test
165  */
166 HWTEST_F(SpecialBranch2Test, Telephony_CallStateListener_001, TestSize.Level0)
167 {
168     auto callStateListener = std::make_shared<CallStateListener>();
169     CallAttributeInfo info = {};
170     TelCallState priorState = TelCallState::CALL_STATUS_UNKNOWN;
171     TelCallState nextState = TelCallState::CALL_STATUS_UNKNOWN;
172     callStateListener->MeeTimeStateUpdated(info, priorState, nextState);
173     ASSERT_TRUE(callStateListener != nullptr);
174 }
175 
176 /**
177  * @tc.number   Telephony_CallControlManager_001
178  * @tc.name     test branch
179  * @tc.desc     Function test
180  */
181 HWTEST_F(SpecialBranch2Test, Telephony_CallControlManager_001, TestSize.Level0)
182 {
183     auto callControlManager = std::make_shared<CallControlManager>();
184     ASSERT_TRUE(callControlManager != nullptr);
185     std::u16string cameraId;
186     callControlManager->ControlCamera(cameraId, 0, 0);
187 
188     VideoWindow window;
189     callControlManager->SetPreviewWindow(window);
190     int32_t ret = callControlManager->SetDisplayWindow(window);
191     EXPECT_EQ(ret, 0);
192 }
193 
194 /**
195  * @tc.number   Telephony_CellularCallConnection_001
196  * @tc.name     test branch
197  * @tc.desc     Function test
198  */
199 HWTEST_F(SpecialBranch2Test, Telephony_CellularCallConnection_001, TestSize.Level0)
200 {
201     auto cellularCallConnection = std::make_shared<CellularCallConnection>();
202     ASSERT_TRUE(cellularCallConnection != nullptr);
203     CellularCallInfo callInfo;
204     cellularCallConnection->Dial(callInfo);
205 
206     CallSupplementType type = CallSupplementType::TYPE_DEFAULT;
207     cellularCallConnection->HangUp(callInfo, type);
208     cellularCallConnection->Reject(callInfo);
209     cellularCallConnection->Answer(callInfo);
210     cellularCallConnection->HoldCall(callInfo);
211     cellularCallConnection->UnHoldCall(callInfo);
212     cellularCallConnection->SwitchCall(callInfo);
213     cellularCallConnection->CombineConference(callInfo);
214     cellularCallConnection->SeparateConference(callInfo);
215     cellularCallConnection->KickOutFromConference(callInfo);
216     cellularCallConnection->StartDtmf('a', callInfo);
217     cellularCallConnection->StopDtmf(callInfo);
218     cellularCallConnection->PostDialProceed(callInfo, false);
219     cellularCallConnection->SendDtmf('b', "abc");
220     cellularCallConnection->SendDtmfString("abc", "abc", PhoneNetType::PHONE_TYPE_GSM, 0, 0);
221 
222     CallTransferInfo callTransferInfo;
223     cellularCallConnection->SetCallTransferInfo(callTransferInfo, 0);
224 
225     bool result;
226     cellularCallConnection->CanSetCallTransferTime(0, result);
227     cellularCallConnection->GetCallTransferInfo(CallTransferType::TRANSFER_TYPE_BUSY, 0);
228     cellularCallConnection->GetVideoCallWaiting(0, result);
229     cellularCallConnection->SetCallPreferenceMode(0, 0);
230 
231     std::u16string msg;
232     cellularCallConnection->StartRtt(callInfo, msg);
233     int ret = cellularCallConnection->StopRtt(callInfo);
234     EXPECT_NE(ret, 0);
235 }
236 
237 /**
238  * @tc.number   Telephony_CellularCallConnection_002
239  * @tc.name     test branch
240  * @tc.desc     Function test
241  */
242 HWTEST_F(SpecialBranch2Test, Telephony_CellularCallConnection_002, TestSize.Level0)
243 {
244     auto cellularCallConnection = std::make_shared<CellularCallConnection>();
245     ASSERT_TRUE(cellularCallConnection != nullptr);
246     std::string cameraId;
247     cellularCallConnection->ControlCamera(0, 0, cameraId, 0, 0);
248 
249     std::string surfaceId;
250     cellularCallConnection->SetPreviewWindow(0, 0, surfaceId, nullptr);
251     cellularCallConnection->SetPreviewWindow(0, 0, surfaceId, nullptr);
252     cellularCallConnection->SetCameraZoom(0.0f);
253 
254     std::string path;
255     cellularCallConnection->SetPausePicture(0, 0, path);
256     cellularCallConnection->SetDeviceDirection(0, 0, 0);
257 
258     bool enabled;
259     cellularCallConnection->GetCarrierVtConfig(0, enabled);
260 
261     CellularCallInfo callInfo;
262     cellularCallConnection->SendUpdateCallMediaModeRequest(callInfo, ImsCallMode::CALL_MODE_AUDIO_ONLY);
263     cellularCallConnection->SendUpdateCallMediaModeResponse(callInfo, ImsCallMode::CALL_MODE_AUDIO_ONLY);
264 
265     std::string value;
266     cellularCallConnection->SetImsConfig(ImsConfigItem::ITEM_VIDEO_QUALITY, value, 0);
267 
268     std::vector<std::string> numberList;
269     cellularCallConnection->InviteToConference(numberList, 0);
270     cellularCallConnection->SetMute(0, 0);
271     cellularCallConnection->CancelCallUpgrade(0, 0);
272     int ret = cellularCallConnection->RequestCameraCapabilities(0, 0);
273     EXPECT_NE(ret, 0);
274 }
275 
276 /**
277  * @tc.number   Telephony_CellularCallConnection_003
278  * @tc.name     test branch
279  * @tc.desc     Function test
280  */
281 HWTEST_F(SpecialBranch2Test, Telephony_CellularCallConnection_003, TestSize.Level1)
282 {
283     auto cellularCallConnection = std::make_shared<CellularCallConnection>();
284     ASSERT_TRUE(cellularCallConnection != nullptr);
285     CellularCallInfo callInfo;
286     int ret = cellularCallConnection->SetCallRestrictionPassword(0, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING,
287         "abc", "bcd");
288     EXPECT_NE(ret, 0);
289 }
290 
291 /**
292  * @tc.number   Telephony_MyLocationEngine_001
293  * @tc.name     test branch
294  * @tc.desc     Function test
295  */
296 HWTEST_F(SpecialBranch2Test, Telephony_MyLocationEngine_001, TestSize.Level0)
297 {
298     auto myLocationEngine = std::make_shared<MyLocationEngine>();
299     myLocationEngine->mylocator = nullptr;
300     ASSERT_TRUE(myLocationEngine->GetInstance() != nullptr);
301 }
302 
303 /**
304  * @tc.number   Telephony_MyLocationEngine_002
305  * @tc.name     test branch
306  * @tc.desc     Function test
307  */
308 HWTEST_F(SpecialBranch2Test, Telephony_MyLocationEngine_002, TestSize.Level0)
309 {
310     auto myLocationEngine = std::make_shared<MyLocationEngine>();
311     myLocationEngine->mylocator = nullptr;
312     myLocationEngine->RegisterLocationChange();
313     ASSERT_TRUE(myLocationEngine->locatorCallback_ == nullptr);
314 }
315 
316 /**
317  * @tc.number   Telephony_MyLocationEngine_003
318  * @tc.name     test branch
319  * @tc.desc     Function test
320  */
321 HWTEST_F(SpecialBranch2Test, Telephony_MyLocationEngine_003, TestSize.Level0)
322 {
323     auto myLocationEngine = std::make_shared<MyLocationEngine>();
324     myLocationEngine->mylocator = nullptr;
325     myLocationEngine->RegisterSwitchCallback();
326     ASSERT_TRUE(myLocationEngine->locatorCallback_ == nullptr);
327 }
328 
329 /**
330  * @tc.number   Telephony_MyLocationEngine_004
331  * @tc.name     test branch
332  * @tc.desc     Function test
333  */
334 HWTEST_F(SpecialBranch2Test, Telephony_MyLocationEngine_004, TestSize.Level0)
335 {
336     auto myLocationEngine = std::make_shared<MyLocationEngine>();
337     myLocationEngine->mylocator = nullptr;
338     myLocationEngine->LocationSwitchChange();
339     ASSERT_TRUE(myLocationEngine->locatorCallback_ == nullptr);
340 }
341 
342 /**
343  * @tc.number   Telephony_MyLocationEngine_005
344  * @tc.name     test branch
345  * @tc.desc     Function test
346  */
347 HWTEST_F(SpecialBranch2Test, Telephony_MyLocationEngine_005, TestSize.Level0)
348 {
349     auto oOBESwitchObserver = std::make_shared<OOBESwitchObserver>("");
350     oOBESwitchObserver->OnChange();
351     ASSERT_TRUE(oOBESwitchObserver != nullptr);
352 }
353 
354 /**
355  * @tc.number   Telephony_MyLocationEngine_006
356  * @tc.name     test branch
357  * @tc.desc     Function test
358  */
359 HWTEST_F(SpecialBranch2Test, Telephony_MyLocationEngine_006, TestSize.Level0)
360 {
361     auto myLocationEngine = std::make_shared<MyLocationEngine>();
362     EmergencyCallConnectCallback::isStartEccService = true;
363     DialParaInfo info;
364     AppExecFwk::PacMap extras;
365     sptr<CallBase> call = (std::make_unique<IMSCall>(info, extras)).release();
366     CallDetailInfo info2;
367     myLocationEngine->StartEccService(call, info2);
368     ASSERT_TRUE(myLocationEngine != nullptr);
369 }
370 
371 /**
372  * @tc.number   Telephony_NetCallBase_001
373  * @tc.name     test branch
374  * @tc.desc     Function test
375  */
376 HWTEST_F(SpecialBranch2Test, Telephony_NetCallBase_001, TestSize.Level0)
377 {
378     DialParaInfo paraInfo;
379     sptr<NetCallBase> netCallBase = (std::make_unique<OTTCall>(paraInfo)).release();
380     ASSERT_TRUE(netCallBase != nullptr);
381     netCallBase->StartConference();
382     netCallBase->JoinConference();
383     netCallBase->KickOutConference();
384     netCallBase->LeaveConference();
385     netCallBase->GetNetCallType();
386     int32_t ret = netCallBase->ChangeNetCallType();
387     EXPECT_EQ(ret, 0);
388 }
389 
390 /**
391  * @tc.number   Telephony_CallRequestProcess_002
392  * @tc.name     test branch
393  * @tc.desc     Function test
394  */
395 HWTEST_F(SpecialBranch2Test, Telephony_CallRequestProcess_002, TestSize.Level0)
396 {
397     std::shared_ptr<CallRequestProcess> callRequestProcess = std::make_shared<CallRequestProcess>();
398     ASSERT_TRUE(callRequestProcess != nullptr);
399     DelayedSingleton<CallControlManager>::GetInstance()->dialSrcInfo_.isDialing = true;
400     int32_t ret = callRequestProcess->DialRequest();
401     EXPECT_NE(ret, 0);
402 }
403 
404 /**
405  * @tc.number   Telephony_CallRequestProcess_003
406  * @tc.name     test branch
407  * @tc.desc     Function test
408  */
409 HWTEST_F(SpecialBranch2Test, Telephony_CallRequestProcess_003, TestSize.Level0)
410 {
411     std::shared_ptr<CallRequestProcess> callRequestProcess = std::make_shared<CallRequestProcess>();
412     ASSERT_TRUE(callRequestProcess != nullptr);
413     DialParaInfo info;
414     info.callState = TelCallState::CALL_STATUS_ALERTING;
415     AppExecFwk::PacMap extras;
416     sptr<CallBase> call = (std::make_unique<IMSCall>(info, extras)).release();
417     CallObjectManager::AddOneCallObject(call);
418     callRequestProcess->HasConnectingCall(false);
419 
420     DialParaInfo info2;
421     info2.callState = TelCallState::CALL_STATUS_DIALING;
422     sptr<CallBase> call2 = (std::make_unique<IMSCall>(info2, extras)).release();
423     CallObjectManager::AddOneCallObject(call2);
424     callRequestProcess->HasConnectingCall(false);
425 
426     callRequestProcess->voipCallObjectList_.clear();
427     ASSERT_TRUE(callRequestProcess->voipCallObjectList_.empty());
428 }
429 
430 /**
431  * @tc.number   Telephony_CallRequestProcess_004
432  * @tc.name     test branch
433  * @tc.desc     Function test
434  */
435 HWTEST_F(SpecialBranch2Test, Telephony_CallRequestProcess_004, TestSize.Level0)
436 {
437     std::shared_ptr<CallRequestProcess> callRequestProcess = std::make_shared<CallRequestProcess>();
438     ASSERT_TRUE(callRequestProcess != nullptr);
439     DialParaInfo info;
440     info.callState = TelCallState::CALL_STATUS_ALERTING;
441     AppExecFwk::PacMap extras;
442     sptr<CallBase> call = (std::make_unique<IMSCall>(info, extras)).release();
443     CallObjectManager::AddOneCallObject(call);
444     callRequestProcess->HasActivedCall(false);
445 
446     DialParaInfo info2;
447     info2.callState = TelCallState::CALL_STATUS_HOLDING;
448     sptr<CallBase> call2 = (std::make_unique<IMSCall>(info2, extras)).release();
449     CallObjectManager::AddOneCallObject(call2);
450     callRequestProcess->HasActivedCall(false);
451 
452     callRequestProcess->voipCallObjectList_.clear();
453     ASSERT_TRUE(callRequestProcess->voipCallObjectList_.empty());
454 }
455 
456 /**
457  * @tc.number   Telephony_CallRequestProcess_005
458  * @tc.name     test branch
459  * @tc.desc     Function test
460  */
461 HWTEST_F(SpecialBranch2Test, Telephony_CallRequestProcess_005, TestSize.Level0)
462 {
463     std::shared_ptr<CallRequestProcess> callRequestProcess = std::make_shared<CallRequestProcess>();
464     ASSERT_TRUE(callRequestProcess != nullptr);
465     DialParaInfo info4;
466     info4.callId = 4;
467     info4.callType = CallType::TYPE_IMS;
468     AppExecFwk::PacMap extras;
469     sptr<CallBase> call4 = (std::make_unique<IMSCall>(info4, extras)).release();
470     call4->callRunningState_ = CallRunningState::CALL_RUNNING_STATE_CREATE;
471     CallObjectManager::AddOneCallObject(call4);
472     callRequestProcess->DisconnectOtherCallForVideoCall(0);
473 
474     DialParaInfo info;
475     info.callId = 1;
476     info.callType = CallType::TYPE_IMS;
477     sptr<CallBase> call = (std::make_unique<IMSCall>(info, extras)).release();
478     CallObjectManager::AddOneCallObject(call);
479     call->callRunningState_ = CallRunningState::CALL_RUNNING_STATE_HOLD;
480     callRequestProcess->DisconnectOtherCallForVideoCall(2);
481 
482     DialParaInfo info2;
483     info2.callId = 2;
484     info2.callType = CallType::TYPE_IMS;
485     sptr<CallBase> call2 = (std::make_unique<IMSCall>(info2, extras)).release();
486     call2->callRunningState_ = CallRunningState::CALL_RUNNING_STATE_DIALING;
487     CallObjectManager::AddOneCallObject(call2);
488     callRequestProcess->DisconnectOtherCallForVideoCall(3);
489 
490     DialParaInfo info3;
491     info3.callId = 3;
492     info3.callType = CallType::TYPE_IMS;
493     sptr<CallBase> call3 = (std::make_unique<IMSCall>(info3, extras)).release();
494     call3->callRunningState_ = CallRunningState::CALL_RUNNING_STATE_ACTIVE;
495     CallObjectManager::AddOneCallObject(call3);
496     callRequestProcess->DisconnectOtherCallForVideoCall(4);
497 
498     callRequestProcess->DisconnectOtherCallForVideoCall(1);
499     callRequestProcess->DisconnectOtherCallForVideoCall(1);
500 
501     callRequestProcess->voipCallObjectList_.clear();
502     ASSERT_TRUE(callRequestProcess->voipCallObjectList_.empty());
503 }
504 
505 /**
506  * @tc.number   Telephony_CallRequestProcess_006
507  * @tc.name     test branch
508  * @tc.desc     Function test
509  */
510 HWTEST_F(SpecialBranch2Test, Telephony_CallRequestProcess_006, TestSize.Level0)
511 {
512     std::shared_ptr<CallRequestProcess> callRequestProcess = std::make_shared<CallRequestProcess>();
513     ASSERT_TRUE(callRequestProcess != nullptr);
514     DialParaInfo info;
515     callRequestProcess->needWaitHold_ = true;
516     callRequestProcess->HandleStartDial(false, info);
517     callRequestProcess->HandleStartDial(true, info);
518     callRequestProcess->needWaitHold_ = false;
519     int32_t ret = callRequestProcess->HandleStartDial(false, info);
520     EXPECT_NE(ret, 0);
521 }
522 
523 /**
524  * @tc.number   Telephony_VideoReceiveState_001
525  * @tc.name     test branch
526  * @tc.desc     Function test
527  */
528 HWTEST_F(SpecialBranch2Test, Telephony_VideoReceiveState_001, TestSize.Level0)
529 {
530     DialParaInfo paraInfo;
531     sptr<NetCallBase> netCallBase = (std::make_unique<OTTCall>(paraInfo)).release();
532     auto videoReceiveState = std::make_shared<VideoReceiveState>(netCallBase);
533     ASSERT_TRUE(videoReceiveState != nullptr);
534     int32_t ret = videoReceiveState->SendUpdateCallMediaModeResponse(ImsCallMode::CALL_MODE_SEND_RECEIVE);
535     EXPECT_NE(ret, 0);
536 }
537 } // namespace Telephony
538 } // namespace OHOS
539