• 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 #define private public
17 #define protected public
18 #include "call_manager_gtest.h"
19 
20 #include <gtest/gtest.h>
21 #include <cstring>
22 #include <string>
23 
24 #include "antifraud_cloud_service.h"
25 #include "bluetooth_hfp_ag.h"
26 #include "call_manager_connect.h"
27 #include "call_manager_service.h"
28 #include "surface_utils.h"
29 #include "telephony_types.h"
30 #include "voip_call.h"
31 #include "anonymize_adapter.h"
32 #include "antifraud_adapter.h"
33 #include "antifraud_service.h"
34 #include "number_identity_service.h"
35 #include "call_setting_ability_connection.h"
36 
37 using namespace OHOS::Bluetooth;
38 namespace OHOS {
39 namespace Telephony {
40 using namespace testing::ext;
41 constexpr int16_t SIM2_SLOTID = 1;
42 constexpr int16_t SIM1_SLOTID_NO_CARD = 0;
43 constexpr int16_t RETURN_VALUE_IS_ZERO = 0;
44 constexpr int16_t INVALID_NEGATIVE_ID = -100;
45 constexpr int16_t INVALID_POSITIVE_ID = 100;
46 constexpr int INVALID_DIAL_TYPE = 3;
47 constexpr int WAIT_TIME = 3;
48 constexpr int16_t CAMERA_ROTATION_90 = 90;
49 constexpr int16_t CAMERA_ROTATION_ERROR = 50;
50 constexpr int16_t SLEEP_1000_MS = 1000;
51 constexpr int BASE_TIME_MS = 1000;
52 constexpr int SLEEP_TIME_MS = 50;
53 constexpr int MAX_LIMIT_TIME = 18000;
54 constexpr int16_t SIM1_SLOTID = 0;
55 const std::string PHONE_NUMBER = "0000000000";
56 
57 BluetoothCallClient &bluetoothCallClient = DelayedRefSingleton<BluetoothCallClient>::GetInstance();
58 std::unordered_map<int32_t, std::unordered_set<int32_t>> g_callStateMap;
59 int32_t g_newCallId = -1;
60 std::mutex CallInfoManager::mutex_;
61 int16_t CallInfoManager::newCallState_;
62 CallAttributeInfo CallInfoManager::updateCallInfo_;
63 std::unordered_set<int32_t> CallInfoManager::callIdSet_;
64 
CallDetailsChange(const CallAttributeInfo & info)65 int32_t CallInfoManager::CallDetailsChange(const CallAttributeInfo &info)
66 {
67     TELEPHONY_LOGI("CallDetailsChange Start");
68     std::lock_guard<std::mutex> lock(mutex_);
69     updateCallInfo_ = info;
70     if (callIdSet_.find(updateCallInfo_.callId) == callIdSet_.end()) {
71         TELEPHONY_LOGI("CallDetailsChange new call");
72         callIdSet_.insert(updateCallInfo_.callId);
73         g_newCallId = updateCallInfo_.callId;
74         newCallState_ = (int32_t)updateCallInfo_.callState;
75         std::unordered_set<int32_t> newSet;
76         newSet.clear();
77         g_callStateMap.insert(std::pair<int32_t, std::unordered_set<int32_t>>(g_newCallId, newSet));
78     }
79     g_callStateMap[updateCallInfo_.callId].insert((int32_t)updateCallInfo_.callState);
80     return TELEPHONY_SUCCESS;
81 }
82 
MeeTimeDetailsChange(const CallAttributeInfo & info)83 int32_t CallInfoManager::MeeTimeDetailsChange(const CallAttributeInfo &info)
84 {
85     TELEPHONY_LOGI("MeeTimeDetailsChange Start");
86     std::lock_guard<std::mutex> lock(mutex_);
87     updateCallInfo_ = info;
88     if (callIdSet_.find(updateCallInfo_.callId) == callIdSet_.end()) {
89         TELEPHONY_LOGI("MeeTimeDetailsChange new call");
90         callIdSet_.insert(updateCallInfo_.callId);
91         g_newCallId = updateCallInfo_.callId;
92         newCallState_ = (int32_t)updateCallInfo_.callState;
93         std::unordered_set<int32_t> newSet;
94         newSet.clear();
95         g_callStateMap.insert(std::pair<int32_t, std::unordered_set<int32_t>>(g_newCallId, newSet));
96     }
97     g_callStateMap[updateCallInfo_.callId].insert((int32_t)updateCallInfo_.callState);
98     return TELEPHONY_SUCCESS;
99 }
100 
HasActiveStatus()101 bool CallInfoManager::HasActiveStatus()
102 {
103     TELEPHONY_LOGI("Waiting for activation !");
104     int sumUseTime = 0;
105     int slipMs = SLEEP_TIME_MS;
106     do {
107         if (!(HasState(g_newCallId, static_cast<int32_t>(TelCallState::CALL_STATUS_ACTIVE)))) {
108             usleep(slipMs * BASE_TIME_MS);
109             sumUseTime += slipMs;
110         } else {
111             TELEPHONY_LOGI("===========wait %d ms callStatus:%d==============", sumUseTime, newCallState_);
112             return true;
113         }
114     } while (sumUseTime < MAX_LIMIT_TIME);
115     TELEPHONY_LOGI("===========wait %d ms callStatus:%d=====not active=========", sumUseTime, newCallState_);
116     return false;
117 }
118 
HasState(int callId,int32_t callState)119 bool CallInfoManager::HasState(int callId, int32_t callState)
120 {
121     if (g_callStateMap.find(callId) == g_callStateMap.end()) {
122         return false;
123     }
124     if (g_callStateMap[callId].find(callState) == g_callStateMap[callId].end()) {
125         return false;
126     }
127     return true;
128 }
129 
CallEventChange(const CallEventInfo & info)130 int32_t CallInfoManager::CallEventChange(const CallEventInfo &info)
131 {
132     return TELEPHONY_SUCCESS;
133 }
134 
Init()135 void CallInfoManager::Init()
136 {
137     g_newCallId = -1;
138     updateCallInfo_.speakerphoneOn = -1;
139     updateCallInfo_.startTime = -1;
140     updateCallInfo_.isEcc = -1;
141     updateCallInfo_.accountId = -1;
142     updateCallInfo_.callType = CallType::TYPE_CS;
143     updateCallInfo_.callId = -1;
144     updateCallInfo_.callState = TelCallState::CALL_STATUS_IDLE;
145     updateCallInfo_.videoState = VideoStateType::TYPE_VOICE;
146 }
147 
LockCallId(bool eq,int32_t targetId,int32_t slipMs,int32_t timeoutMs)148 void CallInfoManager::LockCallId(bool eq, int32_t targetId, int32_t slipMs, int32_t timeoutMs)
149 {
150     int32_t useTimeMs = 0;
151     std::cout << "wait for a few seconds......" << std::endl;
152     while ((updateCallInfo_.callId != targetId) && (useTimeMs < timeoutMs)) {
153         usleep(slipMs * SLEEP_1000_MS);
154         useTimeMs += slipMs;
155     }
156     std::cout << "\n===========wait " << useTimeMs << " ms target:" << updateCallInfo_.callId << std::endl;
157     if (eq) {
158         EXPECT_EQ(updateCallInfo_.callId, targetId);
159     } else {
160         EXPECT_NE(updateCallInfo_.callId, targetId);
161     }
162 }
163 
LockCallState(bool eq,int32_t targetState,int32_t slipMs,int32_t timeoutMs)164 void CallInfoManager::LockCallState(bool eq, int32_t targetState, int32_t slipMs, int32_t timeoutMs)
165 {
166     if (CallManagerGtest::clientPtr_->GetCallState() == targetState) {
167         return;
168     }
169     int32_t usedTimeMs = 0;
170     std::cout << "wait for a few seconds......" << std::endl;
171     while ((CallManagerGtest::clientPtr_->GetCallState() != targetState) && (usedTimeMs < timeoutMs)) {
172         usleep(slipMs * SLEEP_1000_MS);
173         usedTimeMs += slipMs;
174     }
175     int32_t callState = CallManagerGtest::clientPtr_->GetCallState();
176     std::cout << "waited " << usedTimeMs << " seconds" << std::endl;
177     std::cout << "target call state:" << targetState << std::endl;
178     if (eq) {
179         EXPECT_EQ(callState, targetState);
180     } else {
181         EXPECT_NE(callState, targetState);
182     }
183 }
184 
HangUpCall()185 void CallManagerGtest::HangUpCall()
186 {
187     clientPtr_->HangUpCall(INVALID_CALLID);
188 }
189 
190 class ClientErrorBranchTest : public testing::Test {
191 public:
SetUpTestCase()192     static void SetUpTestCase() {};
TearDownTestCase()193     static void TearDownTestCase() {};
SetUp()194     void SetUp() {};
TearDown()195     void TearDown() {};
196 };
197 
198 /**
199  * @tc.number   Telephony_CallManager_SetAudioDevice_0200
200  * @tc.name     make EARPIECE device type, set active EARPIECE device
201  * @tc.desc     Function test
202  * @tc.require: issueI5JUAQ
203  */
204 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0200, Function | MediumTest | Level2)
205 {
206     AccessToken token;
207     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
208         return;
209     }
210     std::string phoneNumber = "77777777777";
211     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
212     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
213         HangUpCall();
214     }
215     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
216     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
217     AudioDevice audioDevice = {
218         .deviceType = AudioDeviceType::DEVICE_EARPIECE,
219         .address = { 0 },
220     };
221     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
222     sleep(WAIT_TIME);
223 
224     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
225         HangUpCall();
226     }
227 }
228 
229 /**
230  * @tc.number   Telephony_CallManager_SetAudioDevice_0300
231  * @tc.name     make SPEAKER device type, set active SPEAKER device
232  * @tc.desc     Function test
233  * @tc.require: issueI5JUAQ
234  */
235 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0300, Function | MediumTest | Level2)
236 {
237     AccessToken token;
238     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
239         return;
240     }
241     std::string phoneNumber = "88888888888";
242     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
243     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
244         HangUpCall();
245     }
246     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
247     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
248     AudioDevice audioDevice = {
249         .deviceType = AudioDeviceType::DEVICE_SPEAKER,
250         .address = { 0 },
251     };
252     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
253     sleep(WAIT_TIME);
254 
255     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
256         HangUpCall();
257     }
258 }
259 
260 /**
261  * @tc.number   Telephony_CallManager_SetAudioDevice_0400
262  * @tc.name     make DEVICE_WIRED_HEADSET device type, set active DEVICE_WIRED_HEADSET device
263  * @tc.desc     Function test
264  * @tc.require: issueI5JUAQ
265  */
266 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0400, Function | MediumTest | Level2)
267 {
268     AccessToken token;
269     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
270         return;
271     }
272     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
273     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
274         HangUpCall();
275     }
276     std::string phoneNumber = "99999999999";
277     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
278     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
279     AudioDevice audioDevice = {
280         .deviceType = AudioDeviceType::DEVICE_WIRED_HEADSET,
281         .address = { 0 },
282     };
283     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
284     sleep(WAIT_TIME);
285 
286     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
287         HangUpCall();
288     }
289 }
290 
291 /**
292  * @tc.number   Telephony_CallManager_SetAudioDevice_0500
293  * @tc.name     make a empty buletoothAddress, set active bluetooth device
294  * @tc.desc     Function test
295  * @tc.require: issueI5JUAQ
296  */
297 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0500, Function | MediumTest | Level2)
298 {
299     AccessToken token;
300     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
301         return;
302     }
303     std::string phoneNumber = "00000001111";
304     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
305     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
306         HangUpCall();
307     }
308     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
309     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
310     AudioDevice audioDevice = {
311         .deviceType = AudioDeviceType::DEVICE_BLUETOOTH_SCO,
312         .address = { 0 },
313     };
314     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
315     sleep(WAIT_TIME);
316 
317     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
318         HangUpCall();
319     }
320 }
321 
322 /**
323  * @tc.number   Telephony_CallManager_SetAudioDevice_0600
324  * @tc.name     make SPEAKER device type, set disable device
325  * @tc.desc     Function test
326  * @tc.require: issueI5JUAQ
327  */
328 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0600, Function | MediumTest | Level2)
329 {
330     AccessToken token;
331     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
332         return;
333     }
334     std::string phoneNumber = "00000002222";
335     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
336     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
337         HangUpCall();
338     }
339     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
340     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
341     AudioDevice audioDevice = {
342         .deviceType = AudioDeviceType::DEVICE_DISABLE,
343         .address = { 0 },
344     };
345     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
346     sleep(WAIT_TIME);
347 
348     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
349         HangUpCall();
350     }
351 }
352 
353 /**
354  * @tc.number   Telephony_CallManager_SetAudioDevice_0700
355  * @tc.name     make SPEAKER device type, set unknown device
356  * @tc.desc     Function test
357  * @tc.require: issueI5JUAQ
358  */
359 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0700, Function | MediumTest | Level2)
360 {
361     AccessToken token;
362     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
363         return;
364     }
365     std::string phoneNumber = "00000003333";
366     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
367     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
368         HangUpCall();
369     }
370     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
371     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
372     AudioDevice audioDevice = {
373         .deviceType = AudioDeviceType::DEVICE_UNKNOWN,
374         .address = { 0 },
375     };
376     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
377     sleep(WAIT_TIME);
378 
379     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
380         HangUpCall();
381     }
382 }
383 
384 /********************************************* Test SetMuted()***********************************************/
385 /**
386  * @tc.number   Telephony_CallManager_SetMuted_0100
387  * @tc.name     set muted true
388  * @tc.desc     Function test
389  * @tc.require: issueI5K59I
390  */
391 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetMuted_0100, Function | MediumTest | Level2)
392 {
393     AccessToken token;
394     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
395         return;
396     }
397     std::string phoneNumber = "00000004444";
398     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
399     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
400         HangUpCall();
401     }
402     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
403     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
404     bool muted = true;
405     if (CallInfoManager::HasActiveStatus()) {
406         EXPECT_EQ(CallManagerGtest::clientPtr_->SetMuted(muted), RETURN_VALUE_IS_ZERO);
407     }
408 
409     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
410         sleep(WAIT_TIME);
411         HangUpCall();
412     }
413 }
414 
415 /**
416  * @tc.number   Telephony_CallManager_SetMuted_0200
417  * @tc.name     without call, set muted failed
418  * @tc.desc     Function test
419  * @tc.require: issueI5K59I
420  */
421 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetMuted_0200, Function | MediumTest | Level2)
422 {
423     AccessToken token;
424     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
425         return;
426     }
427 
428     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
429     bool muted = true;
430 
431     EXPECT_EQ(CallManagerGtest::clientPtr_->SetMuted(muted), CALL_ERR_AUDIO_SETTING_MUTE_FAILED);
432 }
433 
434 /**
435  * @tc.number   Telephony_CallManager_SetMuted_0300
436  * @tc.name     set muted true
437  * @tc.desc     Function test
438  * @tc.require: issueI5K59I
439  */
440 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetMuted_0300, Function | MediumTest | Level2)
441 {
442     AccessToken token;
443     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
444         return;
445     }
446 
447     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
448     std::string phoneNumber = "00000000000";
449     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
450         HangUpCall();
451     }
452     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
453     EXPECT_GE(ret, RETURN_VALUE_IS_ZERO);
454     bool muted = false;
455     if (CallInfoManager::HasActiveStatus()) {
456         EXPECT_EQ(CallManagerGtest::clientPtr_->SetMuted(muted), RETURN_VALUE_IS_ZERO);
457     }
458     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
459         sleep(WAIT_TIME);
460         HangUpCall();
461     }
462 }
463 
464 /********************************************* Test RegisterCallBack() ***********************************************/
465 /**
466  * @tc.number   Telephony_CallManager_RegisterCallBack_0100
467  * @tc.name     test register callback
468  * @tc.desc     Function test
469  */
470 HWTEST_F(CallManagerGtest, Telephony_CallManager_RegisterCallBack_0100, TestSize.Level0)
471 {
472     AccessToken token;
473     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
474         return;
475     }
476 
477     std::unique_ptr<CallManagerCallback> callManagerCallbackPtr = std::make_unique<CallManagerCallBackStub>();
478     if (callManagerCallbackPtr == nullptr) {
479         return;
480     }
481     EXPECT_EQ(CallManagerGtest::clientPtr_->RegisterCallBack(std::move(callManagerCallbackPtr)), RETURN_VALUE_IS_ZERO);
482 }
483 
484 /*************************************** Test UnRegisterCallBack() ********************************************/
485 /**
486  * @tc.number   Telephony_CallManager_UnRegisterCallBack_0100
487  * @tc.name     test register callback
488  * @tc.desc     Function test
489  */
490 HWTEST_F(CallManagerGtest, Telephony_CallManager_UnRegisterCallBack_0100, TestSize.Level0)
491 {
492     AccessToken token;
493     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
494         return;
495     }
496 
497     EXPECT_EQ(CallManagerGtest::clientPtr_->UnRegisterCallBack(), RETURN_VALUE_IS_ZERO);
498 }
499 
500 /************************************ Test SetCallPreferenceMode() *****************************************/
501 /**
502  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0100
503  * @tc.name     test set call preference mode cs voice only
504  * @tc.desc     Function test
505  */
506 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0100, TestSize.Level0)
507 {
508     AccessToken token;
509     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
510         return;
511     }
512 
513     int32_t mode = CS_VOICE_ONLY;
514     if (HasSimCard(SIM1_SLOTID)) {
515         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
516     }
517     if (HasSimCard(SIM2_SLOTID)) {
518         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
519     }
520 }
521 
522 /**
523  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0200
524  * @tc.name     test set call preference mode with error mode
525  * @tc.desc     Function test
526  */
527 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0200, TestSize.Level0)
528 {
529     AccessToken token;
530     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
531         return;
532     }
533 
534     int32_t mode = 0;
535     if (HasSimCard(SIM1_SLOTID)) {
536         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
537     }
538     if (HasSimCard(SIM2_SLOTID)) {
539         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
540     }
541 }
542 
543 /**
544  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0300
545  * @tc.name     test set call preference mode with cs voice prefered
546  * @tc.desc     Function test
547  */
548 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0300, TestSize.Level0)
549 {
550     AccessToken token;
551     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
552         return;
553     }
554 
555     int32_t mode = CS_VOICE_PREFERRED;
556     if (HasSimCard(SIM1_SLOTID)) {
557         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
558     }
559     if (HasSimCard(SIM2_SLOTID)) {
560         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
561     }
562 }
563 
564 /**
565  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0400
566  * @tc.name     test set call preference mode with ims ps voice prefered
567  * @tc.desc     Function test
568  */
569 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0400, TestSize.Level0)
570 {
571     AccessToken token;
572     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
573         return;
574     }
575 
576     int32_t mode = IMS_PS_VOICE_PREFERRED;
577     if (HasSimCard(SIM1_SLOTID)) {
578         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
579     }
580     if (HasSimCard(SIM2_SLOTID)) {
581         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
582     }
583 }
584 
585 /**
586  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0500
587  * @tc.name     test set call preference mode with ims ps voice only
588  * @tc.desc     Function test
589  */
590 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0500, TestSize.Level0)
591 {
592     AccessToken token;
593     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
594         return;
595     }
596 
597     int32_t mode = IMS_PS_VOICE_ONLY;
598     if (HasSimCard(SIM1_SLOTID)) {
599         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
600     }
601     if (HasSimCard(SIM2_SLOTID)) {
602         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
603     }
604 }
605 
606 /*************************************** Test IsInEmergencyCall() **************************************/
607 /**
608  * @tc.number   Telephony_CallManager_IsInEmergencyCall_0100
609  * @tc.name     test is in emergency call
610  * @tc.desc     Function test
611  */
612 HWTEST_F(CallManagerGtest, Telephony_CallManager_IsInEmergencyCall_0100, TestSize.Level1)
613 {
614     AccessToken token;
615     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
616         return;
617     }
618     bool enabled = false;
619     EXPECT_EQ(CallManagerGtest::clientPtr_->IsInEmergencyCall(enabled), TELEPHONY_SUCCESS);
620     EXPECT_EQ(enabled, false);
621 }
622 
623 /**
624  * @tc.number   Telephony_CallManager_IsInEmergencyCall_0200
625  * @tc.name     test is in emergency call
626  * @tc.desc     Function test
627  */
628 HWTEST_F(CallManagerGtest, Telephony_CallManager_IsInEmergencyCall_0200, TestSize.Level0)
629 {
630     AccessToken token;
631     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
632         return;
633     }
634     bool enabled = false;
635     EXPECT_EQ(bluetoothCallClient.IsInEmergencyCall(enabled), TELEPHONY_SUCCESS);
636     EXPECT_EQ(enabled, false);
637 }
638 
639 /**
640  * @tc.number   Telephony_CallManager_IsInEmergencyCall_0300
641  * @tc.name     test is in emergency call without permission
642  * @tc.desc     Function test
643  */
644 HWTEST_F(CallManagerGtest, Telephony_CallManager_IsInEmergencyCall_0300, TestSize.Level0)
645 {
646     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
647         return;
648     }
649     bool enabled = false;
650     EXPECT_NE(CallManagerGtest::clientPtr_->IsInEmergencyCall(enabled), TELEPHONY_SUCCESS);
651     EXPECT_EQ(enabled, false);
652 }
653 
654 /****************************************** Test MuteRinger() *******************************************/
655 /**
656  * @tc.number   Telephony_CallManager_MuteRinger_0100
657  * @tc.name     test mute ringer
658  * @tc.desc     Function test
659  */
660 HWTEST_F(CallManagerGtest, Telephony_CallManager_MuteRinger_0100, TestSize.Level0)
661 {
662     AccessToken token;
663     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
664         return;
665     }
666 
667     EXPECT_EQ(CallManagerGtest::clientPtr_->MuteRinger(), RETURN_VALUE_IS_ZERO);
668 }
669 
670 /********************************************* Test JoinConference() *********************************************/
671 /**
672  * @tc.number   Telephony_CallManager_JoinConference_0100
673  * @tc.name     test join conference
674  * @tc.desc     Function test
675  */
676 HWTEST_F(CallManagerGtest, Telephony_CallManager_JoinConference_0100, TestSize.Level0)
677 {
678     AccessToken token;
679     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
680         return;
681     }
682     int32_t callId = 1;
683     std::vector<std::u16string> numberList { u"0000000000" };
684     EXPECT_NE(CallManagerGtest::clientPtr_->JoinConference(callId, numberList), RETURN_VALUE_IS_ZERO);
685 }
686 
687 /**
688  * @tc.number   Telephony_CallManager_JoinConference_0200
689  * @tc.name     test join conference with empty numberList
690  * @tc.desc     Function test
691  */
692 HWTEST_F(CallManagerGtest, Telephony_CallManager_JoinConference_0200, TestSize.Level0)
693 {
694     AccessToken token;
695     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
696         return;
697     }
698     int32_t callId = 1;
699     std::vector<std::u16string> numberList;
700     EXPECT_NE(CallManagerGtest::clientPtr_->JoinConference(callId, numberList), CALL_ERR_PHONE_NUMBER_EMPTY);
701 }
702 
703 /*********************************** Test ReportOttCallDetailsInfo() ***********************************/
704 /**
705  * @tc.number   Telephony_CallManager_ReportOttCallDetailsInfo_0100
706  * @tc.name     test report ott call details info
707  * @tc.desc     Function test
708  */
709 HWTEST_F(CallManagerGtest, Telephony_CallManager_ReportOttCallDetailsInfo_0100, TestSize.Level0)
710 {
711     AccessToken token;
712     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
713         return;
714     }
715     OttCallDetailsInfo info;
716     const char *number = "000000";
717     memcpy_s(info.phoneNum, kMaxNumberLen, number, strlen(number));
718     const char *bundleName = "com.ohos.tddtest";
719     memcpy_s(info.bundleName, kMaxNumberLen, bundleName, strlen(bundleName));
720     info.callState = TelCallState::CALL_STATUS_DIALING;
721     info.videoState = VideoStateType::TYPE_VOICE;
722     std::vector<OttCallDetailsInfo> ottVec { info };
723     EXPECT_EQ(CallManagerGtest::clientPtr_->ReportOttCallDetailsInfo(ottVec), RETURN_VALUE_IS_ZERO);
724 }
725 
726 /**
727  * @tc.number   Telephony_CallManager_ReportOttCallDetailsInfo_0200
728  * @tc.name     test report ott call details info
729  * @tc.desc     Function test
730  */
731 HWTEST_F(CallManagerGtest, Telephony_CallManager_ReportOttCallDetailsInfo_0200, TestSize.Level0)
732 {
733     AccessToken token;
734     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
735         return;
736     }
737     std::vector<OttCallDetailsInfo> ottVec;
738     EXPECT_NE(CallManagerGtest::clientPtr_->ReportOttCallDetailsInfo(ottVec), RETURN_VALUE_IS_ZERO);
739 }
740 
741 /************************************* Test ReportOttCallEventInfo() ************************************/
742 /**
743  * @tc.number   Telephony_CallManager_ReportOttCallEventInfo_0100
744  * @tc.name     test report ott call details info
745  * @tc.desc     Function test
746  */
747 HWTEST_F(CallManagerGtest, Telephony_CallManager_ReportOttCallEventInfo_0100, TestSize.Level0)
748 {
749     AccessToken token;
750     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
751         return;
752     }
753     OttCallEventInfo info;
754     info.ottCallEventId = OttCallEventId::OTT_CALL_EVENT_FUNCTION_UNSUPPORTED;
755     char bundlename[] = "com.ohos.tddtest";
756     memcpy_s(info.bundleName, kMaxNumberLen, bundlename, strlen(bundlename));
757     EXPECT_EQ(CallManagerGtest::clientPtr_->ReportOttCallEventInfo(info), RETURN_VALUE_IS_ZERO);
758 }
759 
760 /*********************************** Test HasVoiceCapability() ***************************************/
761 /**
762  * @tc.number   Telephony_CallManager_HasVoiceCapability_0100
763  * @tc.name     test report ott call details info
764  * @tc.desc     Function test
765  */
766 HWTEST_F(CallManagerGtest, Telephony_CallManager_HasVoiceCapability_0100, TestSize.Level0)
767 {
768     AccessToken token;
769     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
770         return;
771     }
772 
773     EXPECT_EQ(CallManagerGtest::clientPtr_->HasVoiceCapability(), true);
774 }
775 
776 /************************************* Test CloseUnFinishedUssd() ************************************/
777 /**
778  * @tc.number   Telephony_CallManager_CloseUnFinishedUssd_0100
779  * @tc.name     test Close Unfinished ussd
780  * @tc.desc     Function test
781  */
782 HWTEST_F(CallManagerGtest, Telephony_CallManager_CloseUnFinishedUssd_0100, TestSize.Level1)
783 {
784     AccessToken token;
785     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
786         return;
787     }
788 
789     if (HasSimCard(SIM1_SLOTID)) {
790         EXPECT_GE(CallManagerGtest::clientPtr_->CloseUnFinishedUssd(SIM1_SLOTID), RETURN_VALUE_IS_ZERO);
791     }
792 
793     if (HasSimCard(SIM2_SLOTID)) {
794         EXPECT_EQ(CallManagerGtest::clientPtr_->CloseUnFinishedUssd(SIM2_SLOTID), RETURN_VALUE_IS_ZERO);
795     }
796 }
797 
798 /************************************* Test InputDialerSpecialCode() ************************************/
799 /**
800  * @tc.number   Telephony_CallManager_InputDialerSpecialCode_0100
801  * @tc.name     test Input Dialer Special Code with support code
802  * @tc.desc     Function test
803  */
804 HWTEST_F(CallManagerGtest, Telephony_CallManager_InputDialerSpecialCode_0100, TestSize.Level1)
805 {
806     AccessToken token;
807     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
808         return;
809     }
810     std::string specialCode = "2846579";
811     EXPECT_NE(CallManagerGtest::clientPtr_->InputDialerSpecialCode(specialCode), RETURN_VALUE_IS_ZERO);
812 }
813 
814 /**
815  * @tc.number   Telephony_CallManager_InputDialerSpecialCode_0200
816  * @tc.name     test Input Dialer Special Code with unsupport code
817  * @tc.desc     Function test
818  */
819 HWTEST_F(CallManagerGtest, Telephony_CallManager_InputDialerSpecialCode_0200, TestSize.Level0)
820 {
821     AccessToken token;
822     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
823         return;
824     }
825     std::string specialCode = "1234";
826     EXPECT_NE(CallManagerGtest::clientPtr_->InputDialerSpecialCode(specialCode), RETURN_VALUE_IS_ZERO);
827 }
828 
829 /**
830  * @tc.number   Telephony_CallManager_InputDialerSpecialCode_0300
831  * @tc.name     test Input Dialer Special Code without permission
832  * @tc.desc     Function test
833  */
834 HWTEST_F(CallManagerGtest, Telephony_CallManager_InputDialerSpecialCode_0300, TestSize.Level0)
835 {
836     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
837         return;
838     }
839     std::string specialCode = "2846579";
840     EXPECT_NE(CallManagerGtest::clientPtr_->InputDialerSpecialCode(specialCode), RETURN_VALUE_IS_ZERO);
841 }
842 
843 /**************************** Test RemoveMissedIncomingCallNotification() ****************************/
844 /**
845  * @tc.number   Telephony_CallManager_RemoveMissedIncomingCallNotification_0100
846  * @tc.name     test remove missed incoming call and mark as read
847  * @tc.desc     Function test
848  */
849 HWTEST_F(
850     CallManagerGtest, Telephony_CallManager_RemoveMissedIncomingCallNotification_0100, TestSize.Level0)
851 {
852     AccessToken token;
853     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
854         return;
855     }
856     EXPECT_EQ(CallManagerGtest::clientPtr_->RemoveMissedIncomingCallNotification(), RETURN_VALUE_IS_ZERO);
857 }
858 
859 /**
860  * @tc.number   Telephony_CallManager_RemoveMissedIncomingCallNotification_0200
861  * @tc.name     test cancel missed incoming call and mark as read without permission
862  * @tc.desc     Function test
863  */
864 HWTEST_F(
865     CallManagerGtest, Telephony_CallManager_RemoveMissedIncomingCallNotification_0200, TestSize.Level0)
866 {
867     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
868         return;
869     }
870     EXPECT_NE(CallManagerGtest::clientPtr_->RemoveMissedIncomingCallNotification(), RETURN_VALUE_IS_ZERO);
871 }
872 
873 /******************************************* Test SetVoIPCallState() ********************************************/
874 /**
875  * @tc.number   Telephony_CallManager_SetVoIPCallState_0100
876  * @tc.name     input VoIP call state 0 test SetVoIPCallState
877  * @tc.desc     Function test
878  */
879 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0100, TestSize.Level0)
880 {
881     AccessToken token;
882     int32_t state = 0;
883     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
884 }
885 
886 /******************************************* Test SetVoIPCallState() ********************************************/
887 /**
888  * @tc.number   Telephony_CallManager_SetVoIPCallState_0200
889  * @tc.name     input VoIP call state 1 test SetVoIPCallState
890  * @tc.desc     Function test
891  */
892 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0200, TestSize.Level0)
893 {
894     AccessToken token;
895     int32_t state = 1;
896     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
897 }
898 
899 /******************************************* Test SetVoIPCallState() ********************************************/
900 /**
901  * @tc.number   Telephony_CallManager_SetVoIPCallState_0300
902  * @tc.name     input VoIP call state 2 test SetVoIPCallState
903  * @tc.desc     Function test
904  */
905 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0300, TestSize.Level0)
906 {
907     AccessToken token;
908     int32_t state = 2;
909     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
910 }
911 
912 /******************************************* Test SetVoIPCallState() ********************************************/
913 /**
914  * @tc.number   Telephony_CallManager_SetVoIPCallState_0400
915  * @tc.name     input VoIP call state 3 test SetVoIPCallState
916  * @tc.desc     Function test
917  */
918 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0400, TestSize.Level0)
919 {
920     AccessToken token;
921     int32_t state = 3;
922     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
923 }
924 
925 /******************************************* Test GetVoIPCallState() ********************************************/
926 /**
927  * @tc.number   Telephony_CallManager_GetVoIPCallState_0100
928  * @tc.name     test GetVoIPCallState
929  * @tc.desc     Function test
930  */
931 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetVoIPCallState_0100, TestSize.Level0)
932 {
933     AccessToken token;
934     int32_t state = -1;
935     EXPECT_EQ(CallManagerGtest::clientPtr_->GetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
936 }
937 
938 /**
939  * @tc.number   Telephony_CallManager_GetVoIPCallState_0200
940  * @tc.name     test GetVoIPCallState no permission
941  * @tc.desc     Function test
942  */
943 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetVoIPCallState_0200, TestSize.Level0)
944 {
945     int32_t state = -1;
946     EXPECT_EQ(CallManagerGtest::clientPtr_->GetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
947 }
948 
949 /******************************************* Test SetVoIPCallInfo() ********************************************/
950 /**
951  * @tc.number   Telephony_CallManager_SetVoIPCallInfo_0100
952  * @tc.name     test SetVoIPCallInfo
953  * @tc.desc     Function test
954  */
955 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallInfo_0100, TestSize.Level1)
956 {
957     AccessToken token;
958     int32_t callId = 10001;
959     int32_t state = 4;
960     std::string phoneNumber = "12345678901";
961     std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
962     EXPECT_NE(callManagerService->SetVoIPCallInfo(callId, state, phoneNumber), TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
963 }
964 
965 /**
966  * @tc.number   Telephony_CallManager_SetVoIPCallInfo_0200
967  * @tc.name     test SetVoIPCallInfo
968  * @tc.desc     Function test
969  */
970 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallInfo_0200, TestSize.Level1)
971 {
972     std::shared_ptr<CallManagerClient> client = std::make_shared<CallManagerClient>();
973     AccessToken token;
974     int32_t callId = 10020;
975     int32_t state = 5;
976     std::string phoneNumber = "12345678901";
977     int32_t systemAbilityId = 100;
978     client->Init(systemAbilityId);
979     ASSERT_NE(client->SetVoIPCallInfo(callId, state, phoneNumber), TELEPHONY_ERR_PERMISSION_ERR);
980     ASSERT_EQ(client->GetVoIPCallInfo(callId, state, phoneNumber), TELEPHONY_SUCCESS);
981     client->UnInit();
982     ASSERT_NE(client->SetVoIPCallInfo(callId, state, phoneNumber), TELEPHONY_ERR_UNINIT);
983     ASSERT_NE(client->GetVoIPCallInfo(callId, state, phoneNumber), TELEPHONY_ERR_UNINIT);
984 }
985 
986 /**
987  * @tc.number   Telephony_CallControlManager_SetVoIPCallInfo_0300
988  * @tc.name     test SetVoIPCallInfo
989  * @tc.desc     Function test
990  */
991 HWTEST_F(CallManagerGtest, Telephony_CallControlManager_SetVoIPCallInfo_0300, TestSize.Level0)
992 {
993     std::shared_ptr<CallControlManager> callControlManager = std::make_shared<CallControlManager>();
994     int32_t callId = 10020;
995     std::string phoneNumber = "12345678901";
996     ASSERT_EQ(callControlManager->SetVoIPCallInfo(callId, static_cast<int32_t>(TelCallState::CALL_STATUS_IDLE),
997                                                     phoneNumber), TELEPHONY_SUCCESS);
998     ASSERT_EQ(callControlManager->SetVoIPCallInfo(callId, static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING),
999                                                     phoneNumber), TELEPHONY_SUCCESS);
1000     ASSERT_EQ(callControlManager->SetVoIPCallInfo(callId, static_cast<int32_t>(TelCallState::CALL_STATUS_DISCONNECTED),
1001                                                     phoneNumber), TELEPHONY_SUCCESS);
1002     ASSERT_EQ(callControlManager->SetVoIPCallInfo(callId, static_cast<int32_t>(TelCallState::CALL_STATUS_ALERTING),
1003                                                     phoneNumber), TELEPHONY_SUCCESS);
1004     int32_t state = 5;
1005     ASSERT_EQ(callControlManager->GetVoIPCallInfo(callId, state, phoneNumber), TELEPHONY_SUCCESS);
1006 }
1007 
1008 /**
1009  * @tc.number   Telephony_CallManagerServiceStub_SetVoIPCallInfo_0400
1010  * @tc.name     test SetVoIPCallInfo
1011  * @tc.desc     Function test
1012  */
1013 HWTEST_F(CallManagerGtest, Telephony_CallManagerServiceStub_SetVoIPCallInfo_0400, TestSize.Level0)
1014 {
1015     std::shared_ptr<CallManagerService> callManagerService = std::make_shared<CallManagerService>();
1016     MessageParcel data;
1017     MessageParcel reply;
1018     int32_t callId = 0;
1019     data.WriteInt32(callId);
1020     data.RewindRead(0);
1021     ASSERT_EQ(callManagerService->OnSetVoIPCallInfo(data, reply), TELEPHONY_SUCCESS);
1022     ASSERT_EQ(callManagerService->OnGetVoIPCallInfo(data, reply), TELEPHONY_SUCCESS);
1023 }
1024 
1025 /*********************************** Test Dump() ***************************************/
1026 /**
1027  * @tc.number   Telephony_CallManager_TestDump_0100
1028  * @tc.name     Test Dump
1029  * @tc.desc     Function test
1030  */
1031 HWTEST_F(CallManagerGtest, Telephony_CallManager_TestDump_0100, TestSize.Level0)
1032 {
1033     std::vector<std::u16string> emptyArgs = {};
1034     std::vector<std::u16string> args = { u"test", u"test1" };
1035     EXPECT_GE(DelayedSingleton<CallManagerService>::GetInstance()->Dump(-1, args), 0);
1036     EXPECT_GE(DelayedSingleton<CallManagerService>::GetInstance()->Dump(0, emptyArgs), 0);
1037     EXPECT_GE(DelayedSingleton<CallManagerService>::GetInstance()->Dump(0, args), 0);
1038 }
1039 
1040 /******************************************* Test VoipCallObject() ********************************************/
1041 /**
1042  * @tc.number   Telephony_VoipCallObject_0100
1043  * @tc.name     Test VoipCallObject
1044  * @tc.desc     Function test
1045  */
1046 HWTEST_F(CallManagerGtest, Telephony_VoipCallObject_0100, TestSize.Level1)
1047 {
1048     CallObjectManager::ClearVoipList();
1049     CallAttributeInfo callAttrInfo;
1050     int32_t callId = 12345;
1051     callAttrInfo.callId = callId;
1052     callAttrInfo.callState = TelCallState::CALL_STATUS_WAITING;
1053     EXPECT_NE(CallObjectManager::IsVoipCallExist(), true);
1054 
1055     EXPECT_NE(CallObjectManager::IsVoipCallExist(TelCallState::CALL_STATUS_WAITING, callId), true);
1056 
1057     int32_t newCallId = -1;
1058     EXPECT_NE(CallObjectManager::IsVoipCallExist(TelCallState::CALL_STATUS_WAITING, newCallId), true);
1059 
1060     CallAttributeInfo retrievedCallAttrInfo = CallObjectManager::GetVoipCallInfo();
1061     EXPECT_EQ(retrievedCallAttrInfo.callId, 0);
1062 
1063     TelCallState nextState = TelCallState::CALL_STATUS_ACTIVE;
1064     CallObjectManager::UpdateOneVoipCallObjectByCallId(callId, nextState);
1065 
1066     EXPECT_NE(CallObjectManager::DeleteOneVoipCallObject(callId), TELEPHONY_SUCCESS);
1067 
1068     CallObjectManager::ClearVoipList();
1069 }
1070 
1071 /**
1072  * @tc.number   Telephony_VoipCallObject_0200
1073  * @tc.name     Test VoipCallObject
1074  * @tc.desc     Function test
1075  */
1076 HWTEST_F(CallManagerGtest, Telephony_VoipCallObject_0200, TestSize.Level0)
1077 {
1078     CallObjectManager::ClearVoipList();
1079     int32_t callId = 10010;
1080     int32_t secondCallId = 10011;
1081     CallAttributeInfo callAttrInfo;
1082     callAttrInfo.callId = callId;
1083     CallAttributeInfo secondCallAttrInfo;
1084     secondCallAttrInfo.callId = secondCallId;
1085     EXPECT_EQ(CallObjectManager::AddOneVoipCallObject(callAttrInfo), TELEPHONY_SUCCESS);
1086 
1087     EXPECT_EQ(CallObjectManager::AddOneVoipCallObject(secondCallAttrInfo), TELEPHONY_SUCCESS);
1088 
1089     EXPECT_EQ(CallObjectManager::AddOneVoipCallObject(callAttrInfo), CALL_ERR_PHONE_CALL_ALREADY_EXISTS);
1090 
1091     TelCallState nextState = TelCallState::CALL_STATUS_DISCONNECTED;
1092     EXPECT_EQ(CallObjectManager::UpdateOneVoipCallObjectByCallId(secondCallId, nextState), TELEPHONY_SUCCESS);
1093 
1094     int32_t newCallId = -1;
1095     EXPECT_EQ(CallObjectManager::UpdateOneVoipCallObjectByCallId(newCallId, nextState), TELEPHONY_ERROR);
1096 
1097     EXPECT_EQ(CallObjectManager::DeleteOneVoipCallObject(newCallId), TELEPHONY_ERROR);
1098 
1099     EXPECT_TRUE(CallObjectManager::IsVoipCallExist());
1100 
1101     CallObjectManager::ClearVoipList();
1102 
1103     EXPECT_FALSE(CallObjectManager::IsVoipCallExist());
1104 }
1105 
1106 /**
1107  * @tc.number   Telephony_AntiFraudCloudService_0001
1108  * @tc.name     Test antiFraud cloud service
1109  * @tc.desc     Function test
1110  */
1111 HWTEST_F(CallManagerGtest, Telephony_AntiFraudCloudService_0001, TestSize.Level0)
1112 {
1113     auto service = std::make_shared<AntiFraudCloudService>("10000");
1114     std::string fileContent = "abcdefghij";
1115     OHOS::AntiFraudService::AntiFraudResult antiFraudResult = {0, true, 0, 0, fileContent, 1.0f};
1116     EXPECT_FALSE(service->UploadPostRequest(antiFraudResult));
1117     EXPECT_TRUE(service->EncryptSync("", nullptr).first.empty());
1118     EXPECT_TRUE(service->ProcessEncryptResult("{\"key\":\"value\"}").first.empty());
1119     EXPECT_TRUE(service->ProcessEncryptResult("{\"ak\":0}").first.empty());
1120     EXPECT_EQ(service->ProcessEncryptResult("{\"ak\":\"ak\"}").first, "ak");
1121     EXPECT_TRUE(service->ProcessEncryptResult("{\"ak\":\"ak\"}").second.empty());
1122     EXPECT_TRUE(service->ProcessEncryptResult("{\"ak\":\"ak\",\"data\":0}").second.empty());
1123     EXPECT_EQ(service->ProcessEncryptResult("{\"ak\":\"ak\",\"data\":\"data\"}").second, "data");
1124     EXPECT_TRUE(service->GetAuthSync("", "", nullptr).empty());
1125     EXPECT_TRUE(service->ProcessSignResult("").empty());
1126     EXPECT_TRUE(service->ProcessSignResult("{\"key\":\"value\"}").empty());
1127     EXPECT_TRUE(service->ProcessSignResult("{\"data\":0}").empty());
1128     EXPECT_EQ(service->ProcessSignResult("{\"data\":\"data\"}"), "data");
1129     auto headers = service->GenerateHeadersMap("", "", "");
1130     EXPECT_FALSE(headers.empty());
1131     EXPECT_EQ(service->CalculateDigest("abcdefghij"),
1132         "72399361da6a7754fec986dca5b7cbaf1c810a28ded4abaf56b2106d06cb78b0");
1133     EXPECT_FALSE(service->GenerateRequestJson(headers, "").empty());
1134     EXPECT_FALSE(service->GetDeviceSerial().empty());
1135     EXPECT_EQ(service->GetSubstringBeforeSymbol("1234", "."), "1234");
1136     EXPECT_TRUE(service->EncodeBase64("").empty());
1137     EXPECT_FALSE(service->EncodeBase64("1234").empty());
1138 }
1139 
1140 constexpr int UCS_SERVICE_COMMAND = 0;
1141 constexpr int CLOUD_CONNECT_SERVICE_COMMAND = 1;
1142 class MockRemoteObject : public IRemoteObject {
1143 public:
MockRemoteObject(int command)1144     explicit MockRemoteObject(int command) : IRemoteObject(u"default")
1145     {
1146         command_ = command;
1147     }
1148 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1149     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
1150     {
1151         if (command_ == -1) {
1152             return -1;
1153         }
1154         reply.WriteInt32(0);
1155         if (command_ == UCS_SERVICE_COMMAND) {
1156             std::vector<std::u16string> responseBuffer{u"0"};
1157             reply.WriteString16Vector(responseBuffer);
1158         }
1159         return 0;
1160     }
1161 
GetObjectRefCount()1162     int32_t GetObjectRefCount()
1163     {
1164         return 0;
1165     }
1166 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)1167     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient)
1168     {
1169         return true;
1170     }
1171 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)1172     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient)
1173     {
1174         return true;
1175     }
1176 
IsObjectDead() const1177     bool IsObjectDead() const
1178     {
1179         return command_ != UCS_SERVICE_COMMAND && command_ != CLOUD_CONNECT_SERVICE_COMMAND;
1180     }
1181 
Dump(int fd,const std::vector<std::u16string> & args)1182     int Dump(int fd, const std::vector<std::u16string> &args)
1183     {
1184         return 0;
1185     }
1186 private:
1187     int command_;
1188 };
1189 
1190 /**
1191  * @tc.number   Telephony_AntiFraudCloudService_0002
1192  * @tc.name     Test antiFraud cloud service
1193  * @tc.desc     Function test
1194  */
1195 HWTEST_F(CallManagerGtest, Telephony_AntiFraudCloudService_0002, TestSize.Level0)
1196 {
1197     auto service = std::make_shared<AntiFraudCloudService>("10000");
1198     sptr<OHOS::IRemoteObject> failRemoteObj = new MockRemoteObject(-1);
1199     EXPECT_FALSE(service->GetAuthSync("", "", failRemoteObj).empty());
1200     sptr<OHOS::IRemoteObject> ucsRemoteObj = new MockRemoteObject(UCS_SERVICE_COMMAND);
1201     EXPECT_FALSE(service->GetAuthSync("", "", ucsRemoteObj).empty());
1202     sptr<OHOS::IRemoteObject> cloudConnectRemoteObj = new MockRemoteObject(CLOUD_CONNECT_SERVICE_COMMAND);
1203     OHOS::AntiFraudService::AntiFraudResult antiFraudResult = {0, true, 0, 0, "fileContent", 1.0f};
1204     EXPECT_FALSE(service->ConnectCloudAsync("", "", antiFraudResult, nullptr));
1205     EXPECT_FALSE(service->ConnectCloudAsync("", "", antiFraudResult, failRemoteObj));
1206     EXPECT_TRUE(service->ConnectCloudAsync("", "", antiFraudResult, cloudConnectRemoteObj));
1207 }
1208 
1209 /**
1210  * @tc.number   Telephony_AntiFraudHsdrHelper_0001
1211  * @tc.name     Test antiFraud hsdr helper
1212  * @tc.desc     Function test
1213  */
1214 HWTEST_F(CallManagerGtest, Telephony_AntiFraudHsdrHelper_0001, TestSize.Level0)
1215 {
1216     sptr<HsdrConnection> connection = new (std::nothrow) HsdrConnection(
__anonfad100660102(const sptr<IRemoteObject> &remoteObject) 1217         [](const sptr<IRemoteObject> &remoteObject) {});
1218     if (connection == nullptr) {
1219         std::cout << "connection is nullptr" << std::endl;
1220         return;
1221     }
1222     AppExecFwk::ElementName element;
1223     sptr<OHOS::IRemoteObject> failRemoteObj = new MockRemoteObject(-1);
1224     connection->OnAbilityConnectDone(element, failRemoteObj, -1);
1225     EXPECT_EQ(connection->remoteObject_, nullptr);
1226     connection->OnAbilityConnectDone(element, nullptr, 0);
1227     EXPECT_EQ(connection->remoteObject_, nullptr);
1228     EXPECT_FALSE(connection->IsAlive());
1229     connection->OnAbilityConnectDone(element, failRemoteObj, 0);
1230     EXPECT_NE(connection->remoteObject_, nullptr);
1231     EXPECT_FALSE(connection->IsAlive());
1232     connection->OnAbilityDisconnectDone(element, 0);
1233     EXPECT_EQ(connection->remoteObject_, nullptr);
1234     sptr<OHOS::IRemoteObject> ucsRemoteObj = new MockRemoteObject(UCS_SERVICE_COMMAND);
1235     connection->remoteObject_ = ucsRemoteObj;
1236     EXPECT_TRUE(connection->IsAlive());
1237     connection->OnAbilityDisconnectDone(element, -1);
1238     EXPECT_EQ(connection->remoteObject_, nullptr);
1239     connection->connectedCallback_ = nullptr;
1240     connection->OnAbilityConnectDone(element, failRemoteObj, 0);
1241     EXPECT_EQ(connection->remoteObject_, nullptr);
1242     auto &helper = DelayedRefSingleton<HsdrHelper>().GetInstance();
1243     helper.connection_ = connection;
1244     connection->remoteObject_ = ucsRemoteObj;
__anonfad100660202(const sptr<IRemoteObject> &remoteObject) 1245     EXPECT_EQ(helper.ConnectHsdr([](const sptr<IRemoteObject> &remoteObject) {}), 0);
1246     connection->remoteObject_ = failRemoteObj;
__anonfad100660302(const sptr<IRemoteObject> &remoteObject) 1247     EXPECT_NE(helper.ConnectHsdr([](const sptr<IRemoteObject> &remoteObject) {}), 0);
1248     helper.DisconnectHsdr();
__anonfad100660402(const sptr<IRemoteObject> &remoteObject) 1249     EXPECT_NE(helper.ConnectHsdr([](const sptr<IRemoteObject> &remoteObject) {}), 0);
1250     helper.DisconnectHsdr();
1251     helper.DisconnectHsdr();
1252     EXPECT_EQ(helper.connection_, nullptr);
1253 }
1254 
1255 /**
1256  * @tc.number   Telephony_AntiFraudHsdrHelper_0002
1257  * @tc.name     Test antiFraud hsdr helper
1258  * @tc.desc     Function test
1259  */
1260 HWTEST_F(CallManagerGtest, Telephony_AntiFraudHsdrHelper_0002, TestSize.Level0)
1261 {
__anonfad100660502(const HsdrResponse &response) 1262     OnResponse onResponse = [](const HsdrResponse &response) {};
__anonfad100660602(int errCode) 1263     OnError onError = [](int errCode) {};
1264     sptr<HsdrCallbackStub> callbackStub =
1265         new (std::nothrow) HsdrCallbackStub("123456", onResponse, onError);
1266     if (callbackStub == nullptr) {
1267         std::cout << "callbackStub is nullptr" << std::endl;
1268         return;
1269     }
1270     MessageParcel data;
1271     MessageParcel reply;
1272     MessageOption option;
1273     EXPECT_NE(callbackStub->OnRemoteRequest(0, data, reply, option), 0);
1274     data.WriteInterfaceToken(u"");
1275     EXPECT_NE(callbackStub->OnRemoteRequest(0, data, reply, option), 0);
1276 
1277     data.WriteInterfaceToken(u"OHOS.Security.CloudConnectCallback");
1278     EXPECT_NE(callbackStub->OnRemoteRequest(0, data, reply, option), 0);
1279 
1280     data.WriteInterfaceToken(u"OHOS.Security.CloudConnectCallback");
1281     data.WriteString16(u"123456");
1282     std::vector<std::u16string> responseBuffer{u"0"};
1283     data.WriteString16Vector(responseBuffer);
1284     EXPECT_EQ(callbackStub->OnRemoteRequest(0, data, reply, option), 0);
1285 
1286     MessageParcel data2;
1287     data2.WriteInterfaceToken(u"OHOS.Security.CloudConnectCallback");
1288     data2.WriteString16(u"1234567");
1289     data2.WriteString16Vector(responseBuffer);
1290     EXPECT_EQ(callbackStub->OnRemoteRequest(0, data2, reply, option), 0);
1291 }
1292 
1293 /**
1294  * @tc.number   Telephony_AnonymizeAdapter_0100
1295  * @tc.name     Test AnonymizeAdapter
1296  * @tc.desc     Function test
1297  */
1298 HWTEST_F(CallManagerGtest, Telephony_AnonymizeAdapter_0100, TestSize.Level0)
1299 {
1300     auto antiFraudService = DelayedSingleton<AntiFraudService>::GetInstance();
1301     EXPECT_EQ(antiFraudService->AnonymizeText(), -1);
1302 
1303     auto anonymizeAdapter = DelayedSingleton<AnonymizeAdapter>::GetInstance();
1304     anonymizeAdapter->ReleaseLibAnonymize();
1305     EXPECT_EQ(anonymizeAdapter->libAnonymize_, nullptr);
1306     anonymizeAdapter->GetLibAnonymize();
1307     anonymizeAdapter->ReleaseLibAnonymize();
1308     EXPECT_EQ(anonymizeAdapter->libAnonymize_, nullptr);
1309 
1310     void *config = nullptr;
1311     void *assistant = nullptr;
1312     EXPECT_NE(anonymizeAdapter->ReleaseConfig(&config), 0);
1313     EXPECT_NE(anonymizeAdapter->ReleaseAnonymize(&assistant), 0);
1314 }
1315 
1316 /**
1317  * @tc.number   Telephony_AntiFraud_0100
1318  * @tc.name     Test AntiFraud
1319  * @tc.desc     Function test
1320  */
1321 HWTEST_F(CallManagerGtest, Telephony_AntiFraud_0100, TestSize.Level0)
1322 {
1323     auto antiFraudService = DelayedSingleton<AntiFraudService>::GetInstance();
1324     EXPECT_EQ(antiFraudService->CreateDataShareHelper(-1, USER_SETTINGSDATA_URI.c_str()), nullptr);
1325     EXPECT_NE(antiFraudService->CreateDataShareHelper(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID,
1326         USER_SETTINGSDATA_URI.c_str()), nullptr);
1327 
1328     std::string switchName = "noswitch";
1329     EXPECT_FALSE(antiFraudService->IsSwitchOn(switchName));
1330     EXPECT_FALSE(antiFraudService->IsSwitchOn(ANTIFRAUD_SWITCH));
1331 
1332     OHOS::AntiFraudService::AntiFraudResult fraudResult;
1333     std::string phoneNum = "123456";
1334     antiFraudService->stoppedSlotId_ = 0;
1335     antiFraudService->stoppedIndex_ = 0;
1336     antiFraudService->RecordDetectResult(fraudResult, phoneNum, 1, 1);
1337     EXPECT_EQ(antiFraudService->antiFraudState_, 3);
1338     antiFraudService->RecordDetectResult(fraudResult, phoneNum, 0, 1);
1339     EXPECT_EQ(antiFraudService->antiFraudState_, 3);
1340     fraudResult.result = true;
1341     antiFraudService->RecordDetectResult(fraudResult, phoneNum, 1, 0);
1342     EXPECT_EQ(antiFraudService->antiFraudState_, 2);
1343     antiFraudService->RecordDetectResult(fraudResult, phoneNum, 0, 0);
1344     EXPECT_EQ(antiFraudService->stoppedIndex_, -1);
1345 
1346     EXPECT_NE(antiFraudService->CheckAntiFraudService(phoneNum, 0, 0), 0);
1347     EXPECT_NE(antiFraudService->StartAntiFraudService(phoneNum, 0, 0), 0);
1348     EXPECT_NE(antiFraudService->StopAntiFraudService(0, 0), 0);
1349 
1350     auto antiFraudAdapter = DelayedSingleton<AntiFraudAdapter>::GetInstance();
1351     antiFraudAdapter->DetectAntiFraud(nullptr);
1352     antiFraudAdapter->ReleaseAntiFraud();
1353     EXPECT_EQ(antiFraudAdapter->libAntiFraud_, nullptr);
1354 }
1355 
1356 /**
1357  * @tc.number   Telephony_NumberIdentityConnection_0001
1358  * @tc.name     Test antiFraud hsdr helper
1359  * @tc.desc     Function test
1360  */
1361 HWTEST_F(CallManagerGtest, Telephony_NumberIdentityConnection_0001, TestSize.Level1)
1362 {
1363     sptr<NumberIdentityConnection> connection = new (std::nothrow) NumberIdentityConnection(
__anonfad100660802() 1364         [](const sptr<IRemoteObject> &remoteObject) {}, []() {});
1365     if (connection == nullptr) {
1366         std::cout << "connection is nullptr" << std::endl;
1367         return;
1368     }
1369     AppExecFwk::ElementName element;
1370     sptr<OHOS::IRemoteObject> failRemoteObj = new MockRemoteObject(-1);
1371     connection->OnAbilityConnectDone(element, failRemoteObj, -1);
1372     EXPECT_NE(connection->remoteObject_, nullptr);
1373     connection->OnAbilityConnectDone(element, nullptr, 0);
1374     EXPECT_NE(connection->remoteObject_, nullptr);
1375     EXPECT_FALSE(connection->IsAlive());
1376     connection->OnAbilityConnectDone(element, failRemoteObj, 0);
1377     EXPECT_NE(connection->remoteObject_, nullptr);
1378     EXPECT_FALSE(connection->IsAlive());
1379     connection->OnAbilityDisconnectDone(element, 0);
1380     EXPECT_EQ(connection->remoteObject_, nullptr);
1381     sptr<OHOS::IRemoteObject> ucsRemoteObj = new MockRemoteObject(UCS_SERVICE_COMMAND);
1382     connection->remoteObject_ = ucsRemoteObj;
1383     EXPECT_TRUE(connection->IsAlive());
1384     connection->OnAbilityDisconnectDone(element, -1);
1385     EXPECT_EQ(connection->remoteObject_, nullptr);
1386     connection->connectedCallback_ = nullptr;
1387     connection->OnAbilityConnectDone(element, failRemoteObj, 0);
1388     EXPECT_NE(connection->remoteObject_, nullptr);
1389     auto &helper = DelayedRefSingleton<NumberIdentityServiceHelper>().GetInstance();
1390     helper.connection_ = connection;
1391     connection->remoteObject_ = ucsRemoteObj;
__anonfad100660a02() 1392     EXPECT_EQ(helper.Connect([](const sptr<IRemoteObject> &remoteObject) {}, []() {}), 0);
1393     connection->remoteObject_ = failRemoteObj;
1394     helper.Disconnect();
1395     EXPECT_EQ(helper.connection_, nullptr);
1396     helper.NotifyNumberMarkDataUpdate();
1397 }
1398 
1399 /**
1400  * @tc.number   Telephony_CallSettingAbilityConnection_0001
1401  * @tc.name     Test branch
1402  * @tc.desc     Function test
1403  */
1404 HWTEST_F(CallManagerGtest, Telephony_CallSettingAbilityConnection_0001, TestSize.Level0)
1405 {
1406     sptr<CallSettingAbilityConnection> connection = new (std::nothrow) CallSettingAbilityConnection("str");
1407     if (connection == nullptr) {
1408         return;
1409     }
1410     AppExecFwk::ElementName element;
1411     connection->OnAbilityConnectDone(element, nullptr, 0);
1412     sptr<OHOS::IRemoteObject> remoteObj = new MockRemoteObject(0);
1413     connection->OnAbilityConnectDone(element, remoteObj, 0);
1414     EXPECT_TRUE(connection != nullptr);
1415 }
1416 } // namespace Telephony
1417 } // namespace OHOS
1418