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 "bluetooth_hfp_ag.h"
25 #include "call_manager_connect.h"
26 #include "call_manager_service.h"
27 #include "surface_utils.h"
28 #include "telephony_types.h"
29 #include "voip_call.h"
30 
31 using namespace OHOS::Bluetooth;
32 namespace OHOS {
33 namespace Telephony {
34 using namespace testing::ext;
35 constexpr int16_t SIM2_SLOTID = 1;
36 constexpr int16_t SIM1_SLOTID_NO_CARD = 0;
37 constexpr int16_t RETURN_VALUE_IS_ZERO = 0;
38 constexpr int16_t INVALID_NEGATIVE_ID = -100;
39 constexpr int16_t INVALID_POSITIVE_ID = 100;
40 constexpr int INVALID_DIAL_TYPE = 3;
41 constexpr int WAIT_TIME = 3;
42 constexpr int16_t CAMERA_ROTATION_90 = 90;
43 constexpr int16_t CAMERA_ROTATION_ERROR = 50;
44 constexpr int16_t SLEEP_1000_MS = 1000;
45 constexpr int BASE_TIME_MS = 1000;
46 constexpr int SLEEP_TIME_MS = 50;
47 constexpr int MAX_LIMIT_TIME = 18000;
48 constexpr int16_t SIM1_SLOTID = 0;
49 const std::string PHONE_NUMBER = "0000000000";
50 
51 std::unordered_map<int32_t, std::unordered_set<int32_t>> g_callStateMap;
52 int32_t g_newCallId = -1;
53 std::mutex CallInfoManager::mutex_;
54 int16_t CallInfoManager::newCallState_;
55 CallAttributeInfo CallInfoManager::updateCallInfo_;
56 std::unordered_set<int32_t> CallInfoManager::callIdSet_;
57 
CallDetailsChange(const CallAttributeInfo & info)58 int32_t CallInfoManager::CallDetailsChange(const CallAttributeInfo &info)
59 {
60     TELEPHONY_LOGI("CallDetailsChange Start");
61     std::lock_guard<std::mutex> lock(mutex_);
62     updateCallInfo_ = info;
63     if (callIdSet_.find(updateCallInfo_.callId) == callIdSet_.end()) {
64         TELEPHONY_LOGI("CallDetailsChange new call");
65         callIdSet_.insert(updateCallInfo_.callId);
66         g_newCallId = updateCallInfo_.callId;
67         newCallState_ = (int32_t)updateCallInfo_.callState;
68         std::unordered_set<int32_t> newSet;
69         newSet.clear();
70         g_callStateMap.insert(std::pair<int32_t, std::unordered_set<int32_t>>(g_newCallId, newSet));
71     }
72     g_callStateMap[updateCallInfo_.callId].insert((int32_t)updateCallInfo_.callState);
73     return TELEPHONY_SUCCESS;
74 }
75 
HasActiveStatus()76 bool CallInfoManager::HasActiveStatus()
77 {
78     TELEPHONY_LOGI("Waiting for activation !");
79     int sumUseTime = 0;
80     int slipMs = SLEEP_TIME_MS;
81     do {
82         if (!(HasState(g_newCallId, static_cast<int32_t>(TelCallState::CALL_STATUS_ACTIVE)))) {
83             usleep(slipMs * BASE_TIME_MS);
84             sumUseTime += slipMs;
85         } else {
86             TELEPHONY_LOGI("===========wait %d ms callStatus:%d==============", sumUseTime, newCallState_);
87             return true;
88         }
89     } while (sumUseTime < MAX_LIMIT_TIME);
90     TELEPHONY_LOGI("===========wait %d ms callStatus:%d=====not active=========", sumUseTime, newCallState_);
91     return false;
92 }
93 
HasState(int callId,int32_t callState)94 bool CallInfoManager::HasState(int callId, int32_t callState)
95 {
96     if (g_callStateMap.find(callId) == g_callStateMap.end()) {
97         return false;
98     }
99     if (g_callStateMap[callId].find(callState) == g_callStateMap[callId].end()) {
100         return false;
101     }
102     return true;
103 }
104 
CallEventChange(const CallEventInfo & info)105 int32_t CallInfoManager::CallEventChange(const CallEventInfo &info)
106 {
107     return TELEPHONY_SUCCESS;
108 }
109 
Init()110 void CallInfoManager::Init()
111 {
112     g_newCallId = -1;
113     updateCallInfo_.speakerphoneOn = -1;
114     updateCallInfo_.startTime = -1;
115     updateCallInfo_.isEcc = -1;
116     updateCallInfo_.accountId = -1;
117     updateCallInfo_.callType = CallType::TYPE_CS;
118     updateCallInfo_.callId = -1;
119     updateCallInfo_.callState = TelCallState::CALL_STATUS_IDLE;
120     updateCallInfo_.videoState = VideoStateType::TYPE_VOICE;
121 }
122 
LockCallId(bool eq,int32_t targetId,int32_t slipMs,int32_t timeoutMs)123 void CallInfoManager::LockCallId(bool eq, int32_t targetId, int32_t slipMs, int32_t timeoutMs)
124 {
125     int32_t useTimeMs = 0;
126     std::cout << "wait for a few seconds......" << std::endl;
127     while ((updateCallInfo_.callId != targetId) && (useTimeMs < timeoutMs)) {
128         usleep(slipMs * SLEEP_1000_MS);
129         useTimeMs += slipMs;
130     }
131     std::cout << "\n===========wait " << useTimeMs << " ms target:" << updateCallInfo_.callId << std::endl;
132     if (eq) {
133         EXPECT_EQ(updateCallInfo_.callId, targetId);
134     } else {
135         EXPECT_NE(updateCallInfo_.callId, targetId);
136     }
137 }
138 
LockCallState(bool eq,int32_t targetState,int32_t slipMs,int32_t timeoutMs)139 void CallInfoManager::LockCallState(bool eq, int32_t targetState, int32_t slipMs, int32_t timeoutMs)
140 {
141     if (CallManagerGtest::clientPtr_->GetCallState() == targetState) {
142         return;
143     }
144     int32_t usedTimeMs = 0;
145     std::cout << "wait for a few seconds......" << std::endl;
146     while ((CallManagerGtest::clientPtr_->GetCallState() != targetState) && (usedTimeMs < timeoutMs)) {
147         usleep(slipMs * SLEEP_1000_MS);
148         usedTimeMs += slipMs;
149     }
150     int32_t callState = CallManagerGtest::clientPtr_->GetCallState();
151     std::cout << "waited " << usedTimeMs << " seconds" << std::endl;
152     std::cout << "target call state:" << targetState << std::endl;
153     EXPECT_EQ(callState, targetState);
154 }
155 
HangUpCall()156 void CallManagerGtest::HangUpCall()
157 {
158     clientPtr_->HangUpCall(INVALID_CALLID);
159 }
160 
161 class ClientErrorBranchTest : public testing::Test {
162 public:
SetUpTestCase()163     static void SetUpTestCase() {};
TearDownTestCase()164     static void TearDownTestCase() {};
SetUp()165     void SetUp() {};
TearDown()166     void TearDown() {};
167 };
168 
169 /**
170  * @tc.number   Telephony_CallManager_SetAudioDevice_0200
171  * @tc.name     make EARPIECE device type, set active EARPIECE device
172  * @tc.desc     Function test
173  * @tc.require: issueI5JUAQ
174  */
175 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0200, Function | MediumTest | Level2)
176 {
177     AccessToken token;
178     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
179         return;
180     }
181     std::string phoneNumber = "77777777777";
182     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
183     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
184         HangUpCall();
185     }
186     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
187     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
188     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
189     AudioDevice audioDevice = {
190         .deviceType = AudioDeviceType::DEVICE_EARPIECE,
191         .address = { 0 },
192     };
193     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
194     EXPECT_EQ(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
195     sleep(WAIT_TIME);
196 
197     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
198         HangUpCall();
199     }
200 }
201 
202 /**
203  * @tc.number   Telephony_CallManager_SetAudioDevice_0300
204  * @tc.name     make SPEAKER device type, set active SPEAKER device
205  * @tc.desc     Function test
206  * @tc.require: issueI5JUAQ
207  */
208 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0300, Function | MediumTest | Level2)
209 {
210     AccessToken token;
211     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
212         return;
213     }
214     std::string phoneNumber = "88888888888";
215     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
216     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
217         HangUpCall();
218     }
219     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
220     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
221     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
222     AudioDevice audioDevice = {
223         .deviceType = AudioDeviceType::DEVICE_SPEAKER,
224         .address = { 0 },
225     };
226     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
227     EXPECT_EQ(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
228     sleep(WAIT_TIME);
229 
230     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
231         HangUpCall();
232     }
233 }
234 
235 /**
236  * @tc.number   Telephony_CallManager_SetAudioDevice_0400
237  * @tc.name     make DEVICE_WIRED_HEADSET device type, set active DEVICE_WIRED_HEADSET device
238  * @tc.desc     Function test
239  * @tc.require: issueI5JUAQ
240  */
241 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0400, Function | MediumTest | Level2)
242 {
243     AccessToken token;
244     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
245         return;
246     }
247     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
248     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
249         HangUpCall();
250     }
251     std::string phoneNumber = "99999999999";
252     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
253     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
254     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
255     AudioDevice audioDevice = {
256         .deviceType = AudioDeviceType::DEVICE_WIRED_HEADSET,
257         .address = { 0 },
258     };
259     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
260     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
261     sleep(WAIT_TIME);
262 
263     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
264         HangUpCall();
265     }
266 }
267 
268 /**
269  * @tc.number   Telephony_CallManager_SetAudioDevice_0500
270  * @tc.name     make a empty buletoothAddress, set active bluetooth device
271  * @tc.desc     Function test
272  * @tc.require: issueI5JUAQ
273  */
274 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0500, Function | MediumTest | Level2)
275 {
276     AccessToken token;
277     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
278         return;
279     }
280     std::string phoneNumber = "00000001111";
281     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
282     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
283         HangUpCall();
284     }
285     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
286     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
287     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
288     AudioDevice audioDevice = {
289         .deviceType = AudioDeviceType::DEVICE_BLUETOOTH_SCO,
290         .address = { 0 },
291     };
292     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
293     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
294     sleep(WAIT_TIME);
295 
296     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
297         HangUpCall();
298     }
299 }
300 
301 /**
302  * @tc.number   Telephony_CallManager_SetAudioDevice_0600
303  * @tc.name     make SPEAKER device type, set disable device
304  * @tc.desc     Function test
305  * @tc.require: issueI5JUAQ
306  */
307 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0600, Function | MediumTest | Level2)
308 {
309     AccessToken token;
310     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
311         return;
312     }
313     std::string phoneNumber = "00000002222";
314     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
315     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
316         HangUpCall();
317     }
318     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
319     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
320     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
321     AudioDevice audioDevice = {
322         .deviceType = AudioDeviceType::DEVICE_DISABLE,
323         .address = { 0 },
324     };
325     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
326     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
327     sleep(WAIT_TIME);
328 
329     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
330         HangUpCall();
331     }
332 }
333 
334 /**
335  * @tc.number   Telephony_CallManager_SetAudioDevice_0700
336  * @tc.name     make SPEAKER device type, set unknown device
337  * @tc.desc     Function test
338  * @tc.require: issueI5JUAQ
339  */
340 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetAudioDevice_0700, Function | MediumTest | Level2)
341 {
342     AccessToken token;
343     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
344         return;
345     }
346     std::string phoneNumber = "00000003333";
347     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
348     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
349         HangUpCall();
350     }
351     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
352     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
353     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
354     AudioDevice audioDevice = {
355         .deviceType = AudioDeviceType::DEVICE_UNKNOWN,
356         .address = { 0 },
357     };
358     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
359     EXPECT_NE(clientPtr_->SetAudioDevice(audioDevice), RETURN_VALUE_IS_ZERO);
360     sleep(WAIT_TIME);
361 
362     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
363         HangUpCall();
364     }
365 }
366 
367 /********************************************* Test SetMuted()***********************************************/
368 /**
369  * @tc.number   Telephony_CallManager_SetMuted_0100
370  * @tc.name     set muted true
371  * @tc.desc     Function test
372  * @tc.require: issueI5K59I
373  */
374 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetMuted_0100, Function | MediumTest | Level2)
375 {
376     AccessToken token;
377     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
378         return;
379     }
380     std::string phoneNumber = "00000004444";
381     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
382     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
383         HangUpCall();
384     }
385     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
386     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
387     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
388     bool muted = true;
389     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
390     if (CallInfoManager::HasActiveStatus()) {
391         EXPECT_EQ(CallManagerGtest::clientPtr_->SetMuted(muted), RETURN_VALUE_IS_ZERO);
392     }
393 
394     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
395         sleep(WAIT_TIME);
396         HangUpCall();
397     }
398 }
399 
400 /**
401  * @tc.number   Telephony_CallManager_SetMuted_0200
402  * @tc.name     without call, set muted failed
403  * @tc.desc     Function test
404  * @tc.require: issueI5K59I
405  */
406 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetMuted_0200, Function | MediumTest | Level2)
407 {
408     AccessToken token;
409     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
410         return;
411     }
412 
413     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
414     bool muted = true;
415 
416     EXPECT_EQ(CallManagerGtest::clientPtr_->SetMuted(muted), CALL_ERR_AUDIO_SETTING_MUTE_FAILED);
417 }
418 
419 /**
420  * @tc.number   Telephony_CallManager_SetMuted_0300
421  * @tc.name     set muted true
422  * @tc.desc     Function test
423  * @tc.require: issueI5K59I
424  */
425 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetMuted_0300, Function | MediumTest | Level2)
426 {
427     AccessToken token;
428     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
429         return;
430     }
431 
432     EXPECT_EQ(CallManagerGtest::IsServiceConnected(), true);
433     std::string phoneNumber = "00000000000";
434     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
435         HangUpCall();
436     }
437     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_IDLE, SLEEP_200_MS, SLEEP_30000_MS);
438     int32_t ret = CallManagerGtest::clientPtr_->DialCall(Str8ToStr16(phoneNumber), dialInfo_);
439     EXPECT_EQ(ret, RETURN_VALUE_IS_ZERO);
440     bool muted = false;
441     CallInfoManager::LockCallState(false, (int32_t)CallStateToApp::CALL_STATE_OFFHOOK, SLEEP_200_MS, SLEEP_30000_MS);
442     if (CallInfoManager::HasActiveStatus()) {
443         EXPECT_EQ(CallManagerGtest::clientPtr_->SetMuted(muted), RETURN_VALUE_IS_ZERO);
444     }
445     if (clientPtr_->GetCallState() == static_cast<int>(CallStateToApp::CALL_STATE_OFFHOOK)) {
446         sleep(WAIT_TIME);
447         HangUpCall();
448     }
449 }
450 
451 /********************************************* Test RegisterCallBack() ***********************************************/
452 /**
453  * @tc.number   Telephony_CallManager_RegisterCallBack_0100
454  * @tc.name     test register callback
455  * @tc.desc     Function test
456  */
457 HWTEST_F(CallManagerGtest, Telephony_CallManager_RegisterCallBack_0100, Function | MediumTest | Level3)
458 {
459     AccessToken token;
460     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
461         return;
462     }
463 
464     std::unique_ptr<CallManagerCallback> callManagerCallbackPtr = std::make_unique<CallManagerCallBackStub>();
465     if (callManagerCallbackPtr == nullptr) {
466         return;
467     }
468     EXPECT_EQ(CallManagerGtest::clientPtr_->RegisterCallBack(std::move(callManagerCallbackPtr)), RETURN_VALUE_IS_ZERO);
469 }
470 
471 /*************************************** Test UnRegisterCallBack() ********************************************/
472 /**
473  * @tc.number   Telephony_CallManager_UnRegisterCallBack_0100
474  * @tc.name     test register callback
475  * @tc.desc     Function test
476  */
477 HWTEST_F(CallManagerGtest, Telephony_CallManager_UnRegisterCallBack_0100, Function | MediumTest | Level3)
478 {
479     AccessToken token;
480     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
481         return;
482     }
483 
484     EXPECT_EQ(CallManagerGtest::clientPtr_->UnRegisterCallBack(), RETURN_VALUE_IS_ZERO);
485 }
486 
487 /************************************ Test SetCallPreferenceMode() *****************************************/
488 /**
489  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0100
490  * @tc.name     test set call preference mode cs voice only
491  * @tc.desc     Function test
492  */
493 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0100, Function | MediumTest | Level3)
494 {
495     AccessToken token;
496     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
497         return;
498     }
499 
500     int32_t mode = CS_VOICE_ONLY;
501     if (HasSimCard(SIM1_SLOTID)) {
502         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
503     }
504     if (HasSimCard(SIM2_SLOTID)) {
505         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
506     }
507 }
508 
509 /**
510  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0200
511  * @tc.name     test set call preference mode with error mode
512  * @tc.desc     Function test
513  */
514 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0200, Function | MediumTest | Level3)
515 {
516     AccessToken token;
517     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
518         return;
519     }
520 
521     int32_t mode = 0;
522     if (HasSimCard(SIM1_SLOTID)) {
523         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
524     }
525     if (HasSimCard(SIM2_SLOTID)) {
526         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
527     }
528 }
529 
530 /**
531  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0300
532  * @tc.name     test set call preference mode with cs voice prefered
533  * @tc.desc     Function test
534  */
535 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0300, Function | MediumTest | Level3)
536 {
537     AccessToken token;
538     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
539         return;
540     }
541 
542     int32_t mode = CS_VOICE_PREFERRED;
543     if (HasSimCard(SIM1_SLOTID)) {
544         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
545     }
546     if (HasSimCard(SIM2_SLOTID)) {
547         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
548     }
549 }
550 
551 /**
552  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0400
553  * @tc.name     test set call preference mode with ims ps voice prefered
554  * @tc.desc     Function test
555  */
556 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0400, Function | MediumTest | Level3)
557 {
558     AccessToken token;
559     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
560         return;
561     }
562 
563     int32_t mode = IMS_PS_VOICE_PREFERRED;
564     if (HasSimCard(SIM1_SLOTID)) {
565         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
566     }
567     if (HasSimCard(SIM2_SLOTID)) {
568         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
569     }
570 }
571 
572 /**
573  * @tc.number   Telephony_CallManager_SetCallPreferenceMode_0500
574  * @tc.name     test set call preference mode with ims ps voice only
575  * @tc.desc     Function test
576  */
577 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetCallPreferenceMode_0500, Function | MediumTest | Level3)
578 {
579     AccessToken token;
580     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
581         return;
582     }
583 
584     int32_t mode = IMS_PS_VOICE_ONLY;
585     if (HasSimCard(SIM1_SLOTID)) {
586         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM1_SLOTID, mode), RETURN_VALUE_IS_ZERO);
587     }
588     if (HasSimCard(SIM2_SLOTID)) {
589         EXPECT_EQ(CallManagerGtest::clientPtr_->SetCallPreferenceMode(SIM2_SLOTID, mode), RETURN_VALUE_IS_ZERO);
590     }
591 }
592 
593 /*************************************** Test IsInEmergencyCall() **************************************/
594 /**
595  * @tc.number   Telephony_CallManager_IsInEmergencyCall_0100
596  * @tc.name     test is in emergency call
597  * @tc.desc     Function test
598  */
599 HWTEST_F(CallManagerGtest, Telephony_CallManager_IsInEmergencyCall_0100, Function | MediumTest | Level3)
600 {
601     AccessToken token;
602     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
603         return;
604     }
605     bool enabled = false;
606     EXPECT_EQ(CallManagerGtest::clientPtr_->IsInEmergencyCall(enabled), TELEPHONY_SUCCESS);
607     EXPECT_EQ(enabled, false);
608 }
609 
610 /**
611  * @tc.number   Telephony_CallManager_IsInEmergencyCall_0200
612  * @tc.name     test is in emergency call
613  * @tc.desc     Function test
614  */
615 HWTEST_F(CallManagerGtest, Telephony_CallManager_IsInEmergencyCall_0200, Function | MediumTest | Level3)
616 {
617     AccessToken token;
618     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
619         return;
620     }
621     ASSERT_TRUE(blueToothClientPtr_ != nullptr);
622     bool enabled = false;
623     EXPECT_EQ(CallManagerGtest::blueToothClientPtr_->IsInEmergencyCall(enabled), TELEPHONY_SUCCESS);
624     EXPECT_EQ(enabled, false);
625 }
626 
627 /**
628  * @tc.number   Telephony_CallManager_IsInEmergencyCall_0300
629  * @tc.name     test is in emergency call without permission
630  * @tc.desc     Function test
631  */
632 HWTEST_F(CallManagerGtest, Telephony_CallManager_IsInEmergencyCall_0300, Function | MediumTest | Level3)
633 {
634     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
635         return;
636     }
637     bool enabled = false;
638     EXPECT_NE(CallManagerGtest::clientPtr_->IsInEmergencyCall(enabled), TELEPHONY_SUCCESS);
639     EXPECT_EQ(enabled, false);
640 }
641 
642 /****************************************** Test MuteRinger() *******************************************/
643 /**
644  * @tc.number   Telephony_CallManager_MuteRinger_0100
645  * @tc.name     test mute ringer
646  * @tc.desc     Function test
647  */
648 HWTEST_F(CallManagerGtest, Telephony_CallManager_MuteRinger_0100, Function | MediumTest | Level3)
649 {
650     AccessToken token;
651     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
652         return;
653     }
654 
655     EXPECT_EQ(CallManagerGtest::clientPtr_->MuteRinger(), RETURN_VALUE_IS_ZERO);
656 }
657 
658 /********************************************* Test JoinConference() *********************************************/
659 /**
660  * @tc.number   Telephony_CallManager_JoinConference_0100
661  * @tc.name     test join conference
662  * @tc.desc     Function test
663  */
664 HWTEST_F(CallManagerGtest, Telephony_CallManager_JoinConference_0100, Function | MediumTest | Level3)
665 {
666     AccessToken token;
667     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
668         return;
669     }
670     int32_t callId = 1;
671     std::vector<std::u16string> numberList { u"0000000000" };
672     EXPECT_NE(CallManagerGtest::clientPtr_->JoinConference(callId, numberList), RETURN_VALUE_IS_ZERO);
673 }
674 
675 /**
676  * @tc.number   Telephony_CallManager_JoinConference_0200
677  * @tc.name     test join conference with empty numberList
678  * @tc.desc     Function test
679  */
680 HWTEST_F(CallManagerGtest, Telephony_CallManager_JoinConference_0200, Function | MediumTest | Level3)
681 {
682     AccessToken token;
683     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
684         return;
685     }
686     int32_t callId = 1;
687     std::vector<std::u16string> numberList;
688     EXPECT_NE(CallManagerGtest::clientPtr_->JoinConference(callId, numberList), CALL_ERR_PHONE_NUMBER_EMPTY);
689 }
690 
691 /*********************************** Test ReportOttCallDetailsInfo() ***********************************/
692 /**
693  * @tc.number   Telephony_CallManager_ReportOttCallDetailsInfo_0100
694  * @tc.name     test report ott call details info
695  * @tc.desc     Function test
696  */
697 HWTEST_F(CallManagerGtest, Telephony_CallManager_ReportOttCallDetailsInfo_0100, Function | MediumTest | Level3)
698 {
699     AccessToken token;
700     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
701         return;
702     }
703     OttCallDetailsInfo info;
704     const char *number = "000000";
705     memcpy_s(info.phoneNum, kMaxNumberLen, number, strlen(number));
706     const char *bundleName = "com.ohos.tddtest";
707     memcpy_s(info.bundleName, kMaxNumberLen, bundleName, strlen(bundleName));
708     info.callState = TelCallState::CALL_STATUS_DIALING;
709     info.videoState = VideoStateType::TYPE_VOICE;
710     std::vector<OttCallDetailsInfo> ottVec { info };
711     EXPECT_EQ(CallManagerGtest::clientPtr_->ReportOttCallDetailsInfo(ottVec), RETURN_VALUE_IS_ZERO);
712 }
713 
714 /**
715  * @tc.number   Telephony_CallManager_ReportOttCallDetailsInfo_0200
716  * @tc.name     test report ott call details info
717  * @tc.desc     Function test
718  */
719 HWTEST_F(CallManagerGtest, Telephony_CallManager_ReportOttCallDetailsInfo_0200, Function | MediumTest | Level3)
720 {
721     AccessToken token;
722     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
723         return;
724     }
725     std::vector<OttCallDetailsInfo> ottVec;
726     EXPECT_NE(CallManagerGtest::clientPtr_->ReportOttCallDetailsInfo(ottVec), RETURN_VALUE_IS_ZERO);
727 }
728 
729 /************************************* Test ReportOttCallEventInfo() ************************************/
730 /**
731  * @tc.number   Telephony_CallManager_ReportOttCallEventInfo_0100
732  * @tc.name     test report ott call details info
733  * @tc.desc     Function test
734  */
735 HWTEST_F(CallManagerGtest, Telephony_CallManager_ReportOttCallEventInfo_0100, Function | MediumTest | Level3)
736 {
737     AccessToken token;
738     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
739         return;
740     }
741     OttCallEventInfo info;
742     info.ottCallEventId = OttCallEventId::OTT_CALL_EVENT_FUNCTION_UNSUPPORTED;
743     char bundlename[] = "com.ohos.tddtest";
744     memcpy_s(info.bundleName, kMaxNumberLen, bundlename, strlen(bundlename));
745     EXPECT_EQ(CallManagerGtest::clientPtr_->ReportOttCallEventInfo(info), RETURN_VALUE_IS_ZERO);
746 }
747 
748 /*********************************** Test HasVoiceCapability() ***************************************/
749 /**
750  * @tc.number   Telephony_CallManager_HasVoiceCapability_0100
751  * @tc.name     test report ott call details info
752  * @tc.desc     Function test
753  */
754 HWTEST_F(CallManagerGtest, Telephony_CallManager_HasVoiceCapability_0100, Function | MediumTest | Level3)
755 {
756     AccessToken token;
757     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
758         return;
759     }
760 
761     EXPECT_EQ(CallManagerGtest::clientPtr_->HasVoiceCapability(), true);
762 }
763 
764 /************************************* Test CloseUnFinishedUssd() ************************************/
765 /**
766  * @tc.number   Telephony_CallManager_CloseUnFinishedUssd_0100
767  * @tc.name     test Close Unfinished ussd
768  * @tc.desc     Function test
769  */
770 HWTEST_F(CallManagerGtest, Telephony_CallManager_CloseUnFinishedUssd_0100, Function | MediumTest | Level3)
771 {
772     AccessToken token;
773     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
774         return;
775     }
776 
777     if (HasSimCard(SIM1_SLOTID)) {
778         EXPECT_EQ(CallManagerGtest::clientPtr_->CloseUnFinishedUssd(SIM1_SLOTID), RETURN_VALUE_IS_ZERO);
779     }
780 
781     if (HasSimCard(SIM2_SLOTID)) {
782         EXPECT_EQ(CallManagerGtest::clientPtr_->CloseUnFinishedUssd(SIM2_SLOTID), RETURN_VALUE_IS_ZERO);
783     }
784 }
785 
786 /************************************* Test InputDialerSpecialCode() ************************************/
787 /**
788  * @tc.number   Telephony_CallManager_InputDialerSpecialCode_0100
789  * @tc.name     test Input Dialer Special Code with support code
790  * @tc.desc     Function test
791  */
792 HWTEST_F(CallManagerGtest, Telephony_CallManager_InputDialerSpecialCode_0100, Function | MediumTest | Level3)
793 {
794     AccessToken token;
795     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
796         return;
797     }
798     std::string specialCode = "2846579";
799     EXPECT_EQ(CallManagerGtest::clientPtr_->InputDialerSpecialCode(specialCode), RETURN_VALUE_IS_ZERO);
800 }
801 
802 /**
803  * @tc.number   Telephony_CallManager_InputDialerSpecialCode_0200
804  * @tc.name     test Input Dialer Special Code with unsupport code
805  * @tc.desc     Function test
806  */
807 HWTEST_F(CallManagerGtest, Telephony_CallManager_InputDialerSpecialCode_0200, Function | MediumTest | Level3)
808 {
809     AccessToken token;
810     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
811         return;
812     }
813     std::string specialCode = "1234";
814     EXPECT_NE(CallManagerGtest::clientPtr_->InputDialerSpecialCode(specialCode), RETURN_VALUE_IS_ZERO);
815 }
816 
817 /**
818  * @tc.number   Telephony_CallManager_InputDialerSpecialCode_0300
819  * @tc.name     test Input Dialer Special Code without permission
820  * @tc.desc     Function test
821  */
822 HWTEST_F(CallManagerGtest, Telephony_CallManager_InputDialerSpecialCode_0300, Function | MediumTest | Level3)
823 {
824     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
825         return;
826     }
827     std::string specialCode = "2846579";
828     EXPECT_NE(CallManagerGtest::clientPtr_->InputDialerSpecialCode(specialCode), RETURN_VALUE_IS_ZERO);
829 }
830 
831 /**************************** Test RemoveMissedIncomingCallNotification() ****************************/
832 /**
833  * @tc.number   Telephony_CallManager_RemoveMissedIncomingCallNotification_0100
834  * @tc.name     test remove missed incoming call and mark as read
835  * @tc.desc     Function test
836  */
837 HWTEST_F(
838     CallManagerGtest, Telephony_CallManager_RemoveMissedIncomingCallNotification_0100, Function | MediumTest | Level3)
839 {
840     AccessToken token;
841     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
842         return;
843     }
844     EXPECT_EQ(CallManagerGtest::clientPtr_->RemoveMissedIncomingCallNotification(), RETURN_VALUE_IS_ZERO);
845 }
846 
847 /**
848  * @tc.number   Telephony_CallManager_RemoveMissedIncomingCallNotification_0200
849  * @tc.name     test cancel missed incoming call and mark as read without permission
850  * @tc.desc     Function test
851  */
852 HWTEST_F(
853     CallManagerGtest, Telephony_CallManager_RemoveMissedIncomingCallNotification_0200, Function | MediumTest | Level3)
854 {
855     if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
856         return;
857     }
858     EXPECT_NE(CallManagerGtest::clientPtr_->RemoveMissedIncomingCallNotification(), RETURN_VALUE_IS_ZERO);
859 }
860 
861 /******************************************* Test SetVoIPCallState() ********************************************/
862 /**
863  * @tc.number   Telephony_CallManager_SetVoIPCallState_0100
864  * @tc.name     input VoIP call state 0 test SetVoIPCallState
865  * @tc.desc     Function test
866  */
867 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0100, Function | MediumTest | Level3)
868 {
869     AccessToken token;
870     int32_t state = 0;
871     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
872 }
873 
874 /******************************************* Test SetVoIPCallState() ********************************************/
875 /**
876  * @tc.number   Telephony_CallManager_SetVoIPCallState_0200
877  * @tc.name     input VoIP call state 1 test SetVoIPCallState
878  * @tc.desc     Function test
879  */
880 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0200, Function | MediumTest | Level3)
881 {
882     AccessToken token;
883     int32_t state = 1;
884     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
885 }
886 
887 /******************************************* Test SetVoIPCallState() ********************************************/
888 /**
889  * @tc.number   Telephony_CallManager_SetVoIPCallState_0300
890  * @tc.name     input VoIP call state 2 test SetVoIPCallState
891  * @tc.desc     Function test
892  */
893 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0300, Function | MediumTest | Level3)
894 {
895     AccessToken token;
896     int32_t state = 2;
897     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
898 }
899 
900 /******************************************* Test SetVoIPCallState() ********************************************/
901 /**
902  * @tc.number   Telephony_CallManager_SetVoIPCallState_0400
903  * @tc.name     input VoIP call state 3 test SetVoIPCallState
904  * @tc.desc     Function test
905  */
906 HWTEST_F(CallManagerGtest, Telephony_CallManager_SetVoIPCallState_0400, Function | MediumTest | Level3)
907 {
908     AccessToken token;
909     int32_t state = 3;
910     EXPECT_EQ(CallManagerGtest::clientPtr_->SetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
911 }
912 
913 /******************************************* Test GetVoIPCallState() ********************************************/
914 /**
915  * @tc.number   Telephony_CallManager_GetVoIPCallState_0100
916  * @tc.name     test GetVoIPCallState
917  * @tc.desc     Function test
918  */
919 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetVoIPCallState_0100, Function | MediumTest | Level3)
920 {
921     AccessToken token;
922     int32_t state = -1;
923     EXPECT_EQ(CallManagerGtest::clientPtr_->GetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
924 }
925 
926 /**
927  * @tc.number   Telephony_CallManager_GetVoIPCallState_0200
928  * @tc.name     test GetVoIPCallState no permission
929  * @tc.desc     Function test
930  */
931 HWTEST_F(CallManagerGtest, Telephony_CallManager_GetVoIPCallState_0200, Function | MediumTest | Level3)
932 {
933     int32_t state = -1;
934     EXPECT_EQ(CallManagerGtest::clientPtr_->GetVoIPCallState(state), RETURN_VALUE_IS_ZERO);
935 }
936 
937 /*********************************** Test Dump() ***************************************/
938 /**
939  * @tc.number   Telephony_CallManager_TestDump_0100
940  * @tc.name     Test Dump
941  * @tc.desc     Function test
942  */
943 HWTEST_F(CallManagerGtest, Telephony_CallManager_TestDump_0100, Function | MediumTest | Level3)
944 {
945     std::vector<std::u16string> emptyArgs = {};
946     std::vector<std::u16string> args = { u"test", u"test1" };
947     EXPECT_GE(DelayedSingleton<CallManagerService>::GetInstance()->Dump(-1, args), 0);
948     EXPECT_GE(DelayedSingleton<CallManagerService>::GetInstance()->Dump(0, emptyArgs), 0);
949     EXPECT_GE(DelayedSingleton<CallManagerService>::GetInstance()->Dump(0, args), 0);
950 }
951 } // namespace Telephony
952 } // namespace OHOS
953