1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <memory>
17 #include <securec.h>
18 #include <string_ex.h>
19 
20 #include "audio_system_manager.h"
21 #include "system_ability_definition.h"
22 #include "i_call_manager_service.h"
23 #include "call_manager_client.h"
24 
25 #include "audio_player.h"
26 #include "bluetooth_call_test.h"
27 #include "call_manager_inner_type.h"
28 #include "call_manager_errors.h"
29 #include "call_manager_callback_test.h"
30 #include "call_manager_service_ipc_interface_code.h"
31 #include "call_manager_test_types.h"
32 #include "common_event_subscriber_test.h"
33 #include "surface_utils.h"
34 
35 namespace OHOS {
36 namespace Telephony {
37 using namespace OHOS::Security::AccessToken;
38 using OHOS::Security::AccessToken::AccessTokenID;
39 
40 enum class CallManagerInterfaceType {
41     INTERFACE_CALL_MANAGER_TYPE = 1,
42     INTERFACE_BLUETOOTH_CALL_TYPE,
43 };
44 
45 std::shared_ptr<CallManagerClient> g_clientPtr = nullptr;
46 using CallManagerServiceFunc = void (*)();
47 std::map<uint32_t, CallManagerServiceFunc> g_memberFuncMap;
48 
49 HapInfoParams testInfoParams = {
50     .userID = 1,
51     .bundleName = "tel_call_manager_ui_test",
52     .instIndex = 0,
53     .appIDDesc = "test",
54     .isSystemApp = true,
55 };
56 
57 PermissionDef testPermPlaceCallDef = {
58     .permissionName = "ohos.permission.PLACE_CALL",
59     .bundleName = "tel_call_manager_ui_test",
60     .grantMode = 1, // SYSTEM_GRANT
61     .availableLevel = APL_SYSTEM_BASIC,
62     .label = "label",
63     .labelId = 1,
64     .description = "Test call maneger",
65     .descriptionId = 1,
66 };
67 
68 PermissionStateFull testPlaceCallState = {
69     .permissionName = "ohos.permission.PLACE_CALL",
70     .isGeneral = true,
71     .resDeviceID = { "local" },
72     .grantStatus = { PermissionState::PERMISSION_GRANTED },
73     .grantFlags = { 2 }, // PERMISSION_USER_SET
74 };
75 
76 PermissionDef testPermSetTelephonyStateDef = {
77     .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
78     .bundleName = "tel_call_manager_ui_test",
79     .grantMode = 1, // SYSTEM_GRANT
80     .availableLevel = APL_SYSTEM_BASIC,
81     .label = "label",
82     .labelId = 1,
83     .description = "Test call maneger",
84     .descriptionId = 1,
85 };
86 
87 PermissionStateFull testSetTelephonyState = {
88     .permissionName = "ohos.permission.SET_TELEPHONY_STATE",
89     .isGeneral = true,
90     .resDeviceID = { "local" },
91     .grantStatus = { PermissionState::PERMISSION_GRANTED },
92     .grantFlags = { 2 }, // PERMISSION_USER_SET
93 };
94 
95 PermissionDef testPermGetTelephonyStateDef = {
96     .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
97     .bundleName = "tel_call_manager_ui_test",
98     .grantMode = 1, // SYSTEM_GRANT
99     .availableLevel = APL_SYSTEM_BASIC,
100     .label = "label",
101     .labelId = 1,
102     .description = "Test call maneger",
103     .descriptionId = 1,
104 };
105 
106 PermissionStateFull testGetTelephonyState = {
107     .permissionName = "ohos.permission.GET_TELEPHONY_STATE",
108     .isGeneral = true,
109     .resDeviceID = { "local" },
110     .grantStatus = { PermissionState::PERMISSION_GRANTED },
111     .grantFlags = { 2 }, // PERMISSION_USER_SET
112 };
113 
114 PermissionDef testPermAnswerCallDef = {
115     .permissionName = "ohos.permission.ANSWER_CALL",
116     .bundleName = "tel_call_manager_ui_test",
117     .grantMode = 1, // SYSTEM_GRANT
118     .availableLevel = APL_SYSTEM_BASIC,
119     .label = "label",
120     .labelId = 1,
121     .description = "Test call maneger",
122     .descriptionId = 1,
123 };
124 
125 PermissionStateFull testAnswerCallState = {
126     .permissionName = "ohos.permission.ANSWER_CALL",
127     .isGeneral = true,
128     .resDeviceID = { "local" },
129     .grantStatus = { PermissionState::PERMISSION_GRANTED },
130     .grantFlags = { 2 }, // PERMISSION_USER_SET
131 };
132 
133 PermissionDef testReadCallLogDef = {
134     .permissionName = "ohos.permission.READ_CALL_LOG",
135     .bundleName = "tel_call_manager_gtest",
136     .grantMode = 1, // SYSTEM_GRANT
137     .availableLevel = APL_SYSTEM_BASIC,
138     .label = "label",
139     .labelId = 1,
140     .description = "Test call manager",
141     .descriptionId = 1,
142 };
143 
144 PermissionStateFull testPermReadCallLog = {
145     .permissionName = "ohos.permission.READ_CALL_LOG",
146     .isGeneral = true,
147     .resDeviceID = { "local" },
148     .grantStatus = { PermissionState::PERMISSION_GRANTED },
149     .grantFlags = { 2 }, // PERMISSION_USER_SET
150 };
151 
152 PermissionDef testWriteCallLogDef = {
153     .permissionName = "ohos.permission.WRITE_CALL_LOG",
154     .bundleName = "tel_call_manager_gtest",
155     .grantMode = 1, // SYSTEM_GRANT
156     .availableLevel = APL_SYSTEM_BASIC,
157     .label = "label",
158     .labelId = 1,
159     .description = "Test call manager",
160     .descriptionId = 1,
161 };
162 
163 PermissionStateFull testPermWriteCallLog = {
164     .permissionName = "ohos.permission.WRITE_CALL_LOG",
165     .isGeneral = true,
166     .resDeviceID = { "local" },
167     .grantStatus = { PermissionState::PERMISSION_GRANTED },
168     .grantFlags = { 2 }, // PERMISSION_USER_SET
169 };
170 
171 PermissionDef testStartAbilityFromBGDef = {
172     .permissionName = "ohos.permission.START_ABILITIES_FROM_BACKGROUND",
173     .bundleName = "tel_call_manager_gtest",
174     .grantMode = 1, // SYSTEM_GRANT
175     .availableLevel = APL_SYSTEM_BASIC,
176     .label = "label",
177     .labelId = 1,
178     .description = "Test call manager",
179     .descriptionId = 1,
180 };
181 
182 PermissionStateFull testPermStartAbilityFromBG = {
183     .permissionName = "ohos.permission.START_ABILITIES_FROM_BACKGROUND",
184     .isGeneral = true,
185     .resDeviceID = { "local" },
186     .grantStatus = { PermissionState::PERMISSION_GRANTED },
187     .grantFlags = { 2 }, // PERMISSION_USER_SET
188 };
189 
190 HapPolicyParams testPolicyParams = {
191     .apl = APL_SYSTEM_BASIC,
192     .domain = "test.domain",
193     .permList = { testPermPlaceCallDef, testPermSetTelephonyStateDef, testPermGetTelephonyStateDef,
194         testPermAnswerCallDef, testReadCallLogDef, testWriteCallLogDef, testStartAbilityFromBGDef },
195     .permStateList = { testPlaceCallState, testSetTelephonyState, testGetTelephonyState, testAnswerCallState,
196         testPermReadCallLog, testPermWriteCallLog, testPermStartAbilityFromBG },
197 };
198 
199 class AccessToken {
200 public:
AccessToken()201     AccessToken()
202     {
203         currentID_ = GetSelfTokenID();
204         AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
205         accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
206         SetSelfTokenID(tokenIdEx.tokenIDEx);
207     }
~AccessToken()208     ~AccessToken()
209     {
210         AccessTokenKit::DeleteToken(accessID_);
211         SetSelfTokenID(currentID_);
212     }
213 
214 private:
215     AccessTokenID currentID_ = 0;
216     AccessTokenID accessID_ = 0;
217 };
218 
DialCall()219 void DialCall()
220 {
221     AccessToken token;
222     int32_t accountId = DEFAULT_ACCOUNT_ID;
223     int32_t videoState = DEFAULT_VIDEO_STATE;
224     int32_t dialScene = DEFAULT_DIAL_SCENE;
225     int32_t callDialType = DEFAULT_DIAL_TYPE;
226     int32_t callType = DEFAULT_CALL_TYPE;
227     std::u16string phoneNumber;
228     std::string numberStr;
229     AppExecFwk::PacMap dialInfo;
230     std::cout << "---------Dial---------" << std::endl;
231     std::cout << "please input phone number:" << std::endl;
232     phoneNumber.clear();
233     numberStr.clear();
234     std::cin >> numberStr;
235     phoneNumber = Str8ToStr16(numberStr);
236     std::cout << "phone number: " << numberStr << std::endl;
237     std::cout << "please input accountId:" << std::endl;
238     std::cin >> accountId;
239     std::cout << "please input videoState[0:audio,1:video]:" << std::endl;
240     std::cin >> videoState;
241     std::cout << "please input dialScene[0:normal,1:privileged,2:emergency]:" << std::endl;
242     std::cin >> dialScene;
243     std::cout << "please input dialType[0:carrier,1:voice mail,2:ott]:" << std::endl;
244     std::cin >> callDialType;
245     std::cout << "please input callType[0:cs,1:ims,2:ott]:" << std::endl;
246     std::cin >> callType;
247 
248     dialInfo.PutIntValue("accountId", accountId);
249     dialInfo.PutIntValue("videoState", videoState);
250     dialInfo.PutIntValue("dialScene", dialScene);
251     dialInfo.PutIntValue("dialType", callDialType);
252     dialInfo.PutIntValue("callType", callType);
253     if (g_clientPtr == nullptr) {
254         std::cout << "g_clientPtr is nullptr" << std::endl;
255         return;
256     }
257     int32_t ret = g_clientPtr->DialCall(phoneNumber, dialInfo);
258     std::cout << "return value:" << ret << std::endl;
259 }
260 
AnswerCall()261 void AnswerCall()
262 {
263     AccessToken token;
264     int32_t callId = DEFAULT_CALL_ID;
265     int32_t videoState = DEFAULT_VIDEO_STATE;
266     std::cout << "------Answer------" << std::endl;
267     std::cout << "please input callId:" << std::endl;
268     std::cin >> callId;
269     std::cout << "please input videoState[0:audio,1:video]:" << std::endl;
270     std::cin >> videoState;
271     int32_t ret = TELEPHONY_SUCCESS;
272     if (g_clientPtr == nullptr) {
273         std::cout << "g_clientPtr is nullptr" << std::endl;
274         return;
275     }
276     ret = g_clientPtr->AnswerCall(callId, videoState);
277     std::cout << "return value:" << ret << std::endl;
278 }
279 
RejectCall()280 void RejectCall()
281 {
282     AccessToken token;
283     int32_t callId = DEFAULT_CALL_ID;
284     int32_t boolValue = DEFAULT_VALUE;
285     bool flag = false;
286     std::u16string content;
287     content.clear();
288     std::cout << "------Reject------" << std::endl;
289     std::cout << "please input callId:" << std::endl;
290     std::cin >> callId;
291     std::cout << "Whether to enter the reason for rejection?[0:no,1:yes]:" << std::endl;
292     std::cin >> boolValue;
293     if (boolValue != DEFAULT_VALUE) {
294         flag = true;
295         std::string tmpStr;
296         tmpStr.clear();
297         std::cout << "please input reject message:" << std::endl;
298         std::cin >> tmpStr;
299         content = Str8ToStr16(tmpStr);
300     }
301     if (g_clientPtr == nullptr) {
302         std::cout << "g_clientPtr is nullptr" << std::endl;
303         return;
304     }
305     int32_t ret = g_clientPtr->RejectCall(callId, flag, content);
306     std::cout << "return value:" << ret << std::endl;
307 }
308 
HoldCall()309 void HoldCall()
310 {
311     AccessToken token;
312     int32_t callId = DEFAULT_CALL_ID;
313     std::cout << "------HoldCall------" << std::endl;
314     std::cout << "please input callId:" << std::endl;
315     std::cin >> callId;
316     if (g_clientPtr == nullptr) {
317         std::cout << "g_clientPtr is nullptr" << std::endl;
318         return;
319     }
320     int32_t ret = g_clientPtr->HoldCall(callId);
321     std::cout << "return value:" << ret << std::endl;
322 }
323 
UnHoldCall()324 void UnHoldCall()
325 {
326     AccessToken token;
327     int32_t callId = DEFAULT_CALL_ID;
328     std::cout << "------UnHoldCall------" << std::endl;
329     std::cout << "please input callId:" << std::endl;
330     std::cin >> callId;
331     if (g_clientPtr == nullptr) {
332         std::cout << "g_clientPtr is nullptr" << std::endl;
333         return;
334     }
335     int32_t ret = g_clientPtr->UnHoldCall(callId);
336     std::cout << "return value:" << ret << std::endl;
337 }
338 
HangUpCall()339 void HangUpCall()
340 {
341     AccessToken token;
342     int32_t callId = DEFAULT_CALL_ID;
343     std::cout << "------HangUpCall------" << std::endl;
344     std::cout << "please input callId:" << std::endl;
345     std::cin >> callId;
346     if (g_clientPtr == nullptr) {
347         std::cout << "g_clientPtr is nullptr" << std::endl;
348         return;
349     }
350     int32_t ret = g_clientPtr->HangUpCall(callId);
351     std::cout << "return value:" << ret << std::endl;
352 }
353 
CombineConference()354 void CombineConference()
355 {
356     int32_t mainCallId = DEFAULT_CALL_ID;
357     std::cout << "------CombineConference------" << std::endl;
358     std::cout << "please input mainCallId:" << std::endl;
359     std::cin >> mainCallId;
360     if (g_clientPtr == nullptr) {
361         std::cout << "g_clientPtr is nullptr" << std::endl;
362         return;
363     }
364     int32_t ret = g_clientPtr->CombineConference(mainCallId);
365     std::cout << "return value:" << ret << std::endl;
366 }
367 
SeparateConference()368 void SeparateConference()
369 {
370     int32_t callId = DEFAULT_CALL_ID;
371     std::cout << "------SeparateConference------" << std::endl;
372     std::cout << "please input callId:" << std::endl;
373     std::cin >> callId;
374     if (g_clientPtr == nullptr) {
375         std::cout << "g_clientPtr is nullptr" << std::endl;
376         return;
377     }
378     int32_t ret = g_clientPtr->SeparateConference(callId);
379     std::cout << "return value:" << ret << std::endl;
380 }
381 
KickOutFromConference()382 void KickOutFromConference()
383 {
384     int32_t callId = DEFAULT_CALL_ID;
385     std::cout << "------KickOutFromConference------" << std::endl;
386     std::cout << "please input callId:" << std::endl;
387     std::cin >> callId;
388     if (g_clientPtr == nullptr) {
389         std::cout << "g_clientPtr is nullptr" << std::endl;
390         return;
391     }
392     int32_t ret = g_clientPtr->KickOutFromConference(callId);
393     std::cout << "return value:" << ret << std::endl;
394 }
395 
GetCallState()396 void GetCallState()
397 {
398     std::cout << "------GetCallState------" << std::endl;
399     if (g_clientPtr == nullptr) {
400         std::cout << "g_clientPtr is nullptr" << std::endl;
401         return;
402     }
403     int32_t ret = g_clientPtr->GetCallState();
404     std::cout << "return value:" << ret << std::endl;
405 }
406 
SwitchCall()407 void SwitchCall()
408 {
409     AccessToken token;
410     int32_t callId = DEFAULT_CALL_ID;
411     std::cout << "------SwitchCall------" << std::endl;
412     std::cout << "please input callId:" << std::endl;
413     std::cin >> callId;
414     if (g_clientPtr == nullptr) {
415         std::cout << "g_clientPtr is nullptr" << std::endl;
416         return;
417     }
418     int32_t ret = g_clientPtr->SwitchCall(callId);
419     std::cout << "return value:" << ret << std::endl;
420 }
421 
HasCall()422 void HasCall()
423 {
424     std::cout << "------HasCall------" << std::endl;
425     if (g_clientPtr == nullptr) {
426         std::cout << "g_clientPtr is nullptr" << std::endl;
427         return;
428     }
429     int32_t ret = g_clientPtr->HasCall();
430     std::cout << "return value:" << ret << std::endl;
431 }
432 
IsNewCallAllowed()433 void IsNewCallAllowed()
434 {
435     std::cout << "------IsNewCallAllowed------" << std::endl;
436     if (g_clientPtr == nullptr) {
437         std::cout << "g_clientPtr is nullptr" << std::endl;
438         return;
439     }
440     bool enabled = false;
441     int32_t ret = g_clientPtr->IsNewCallAllowed(enabled);
442     std::cout << "return result:" << ret << std::endl;
443     std::cout << "enabled value:" << enabled << std::endl;
444 }
445 
IsRinging()446 void IsRinging()
447 {
448     AccessToken token;
449     std::cout << "------IsRinging------" << std::endl;
450     if (g_clientPtr == nullptr) {
451         std::cout << "g_clientPtr is nullptr" << std::endl;
452         return;
453     }
454     bool enabled = false;
455     int32_t ret = g_clientPtr->IsRinging(enabled);
456     std::cout << "return result:" << ret << std::endl;
457     std::cout << "enabled value:" << enabled << std::endl;
458 }
459 
IsInEmergencyCall()460 void IsInEmergencyCall()
461 {
462     AccessToken token;
463     std::cout << "------IsInEmergencyCall------" << std::endl;
464     if (g_clientPtr == nullptr) {
465         std::cout << "g_clientPtr is nullptr" << std::endl;
466         return;
467     }
468     bool enabled = false;
469     int32_t ret = g_clientPtr->IsInEmergencyCall(enabled);
470     std::cout << "return result:" << ret << std::endl;
471     std::cout << "enabled value:" << enabled << std::endl;
472 }
473 
StartDtmf()474 void StartDtmf()
475 {
476     char c = DEFAULT_VALUE;
477     int32_t callId = DEFAULT_CALL_ID;
478     std::cout << "please input StartDtmf callId:" << std::endl;
479     std::cin >> callId;
480     std::cout << "Please enter to send dtmf characters:" << std::endl;
481     std::cin >> c;
482     int32_t ret = g_clientPtr->StartDtmf(callId, c);
483     std::cout << "return value:" << ret << std::endl;
484 }
485 
StopDtmf()486 void StopDtmf()
487 {
488     int32_t callId = DEFAULT_CALL_ID;
489     std::cout << "please input StopDtmf callId:" << std::endl;
490     std::cin >> callId;
491     int32_t ret = g_clientPtr->StopDtmf(callId);
492     std::cout << "return value:" << ret << std::endl;
493 }
494 
GetCallWaiting()495 void GetCallWaiting()
496 {
497     AccessToken token;
498     int32_t slotId = SIM1_SLOTID;
499     std::cout << "------GetCallWaiting------" << std::endl;
500     std::cout << "please input slotId:" << std::endl;
501     std::cin >> slotId;
502     if (g_clientPtr == nullptr) {
503         std::cout << "g_clientPtr is nullptr" << std::endl;
504         return;
505     }
506     int32_t ret = g_clientPtr->GetCallWaiting(slotId);
507     std::cout << "return value:" << ret << std::endl;
508 }
509 
SetCallWaiting()510 void SetCallWaiting()
511 {
512     AccessToken token;
513     int32_t slotId = SIM1_SLOTID;
514     int32_t flag = DEFAULT_VALUE;
515     std::cout << "------SetCallWaiting------" << std::endl;
516     std::cout << "please input slotId:" << std::endl;
517     std::cin >> slotId;
518     std::cout << "whether open(0:no 1:yes):" << std::endl;
519     std::cin >> flag;
520     if (g_clientPtr == nullptr) {
521         std::cout << "g_clientPtr is nullptr" << std::endl;
522         return;
523     }
524     int32_t ret = g_clientPtr->SetCallWaiting(slotId, (flag == 1) ? true : false);
525     std::cout << "return value:" << ret << std::endl;
526 }
527 
GetCallRestriction()528 void GetCallRestriction()
529 {
530     AccessToken token;
531     int32_t slotId = SIM1_SLOTID;
532     int32_t tmpType = DEFAULT_VALUE;
533     CallRestrictionType type;
534     std::cout << "------GetCallRestriction------" << std::endl;
535     std::cout << "please input slotId:" << std::endl;
536     std::cin >> slotId;
537     std::cout << "please input restriction type:" << std::endl;
538     std::cin >> tmpType;
539     type = static_cast<CallRestrictionType>(tmpType);
540     if (g_clientPtr == nullptr) {
541         std::cout << "g_clientPtr is nullptr" << std::endl;
542         return;
543     }
544     int32_t ret = g_clientPtr->GetCallRestriction(slotId, type);
545     std::cout << "return value:" << ret << std::endl;
546 }
547 
SetCallRestriction()548 void SetCallRestriction()
549 {
550     AccessToken token;
551     int32_t slotId = SIM1_SLOTID;
552     int32_t tmpType = DEFAULT_VALUE;
553     CallRestrictionInfo info;
554     std::cout << "------SetCallRestriction------" << std::endl;
555     std::cout << "please input slotId:" << std::endl;
556     std::cin >> slotId;
557     std::cout << "please input restriction type:" << std::endl;
558     std::cin >> tmpType;
559     info.fac = static_cast<CallRestrictionType>(tmpType);
560     std::cout << "is open(1: open, 0: close):" << std::endl;
561     std::cin >> tmpType;
562     info.mode = static_cast<CallRestrictionMode>(tmpType);
563     std::cout << "please input password:" << std::endl;
564     std::cin >> info.password;
565     if (g_clientPtr == nullptr) {
566         std::cout << "g_clientPtr is nullptr" << std::endl;
567         return;
568     }
569     int32_t ret = g_clientPtr->SetCallRestriction(slotId, info);
570     std::cout << "return value:" << ret << std::endl;
571 }
572 
SetCallRestrictionPassword()573 void SetCallRestrictionPassword()
574 {
575     AccessToken token;
576     int32_t slotId = SIM1_SLOTID;
577     char oldPassword[kMaxNumberLen + 1] = { 0 };
578     char newPassword[kMaxNumberLen + 1] = { 0 };
579     CallRestrictionType fac = CallRestrictionType::RESTRICTION_TYPE_ALL_CALLS;
580     std::cout << "------SetCallRestrictionPassword------" << std::endl;
581     std::cout << "please input slotId:" << std::endl;
582     std::cin >> slotId;
583     std::cout << "please input old password:" << std::endl;
584     std::cin >> oldPassword;
585     std::cout << "please input new password:" << std::endl;
586     std::cin >> newPassword;
587     if (g_clientPtr == nullptr) {
588         std::cout << "g_clientPtr is nullptr" << std::endl;
589         return;
590     }
591     int32_t ret = g_clientPtr->SetCallRestrictionPassword(slotId, fac, oldPassword, newPassword);
592     std::cout << "return value:" << ret << std::endl;
593     (void)memset_s(oldPassword, sizeof(oldPassword), 0, sizeof(oldPassword));
594     (void)memset_s(newPassword, sizeof(newPassword), 0, sizeof(newPassword));
595 }
596 
SetCallPreferenceMode()597 void SetCallPreferenceMode()
598 {
599     AccessToken token;
600     int32_t slotId = SIM1_SLOTID;
601     int32_t mode = DEFAULT_PREFERENCEMODE;
602     std::cout << "------CallPreferenceMode------" << std::endl;
603     std::cout << "please input slotId:" << std::endl;
604     std::cin >> slotId;
605     std::cout << "please input PreferenceMode:" << std::endl;
606     std::cout << "CS_VOICE_ONLY = 1" << std::endl;
607     std::cout << "CS_VOICE_PREFERRED = 2" << std::endl;
608     std::cout << "IMS_PS_VOICE_PREFERRED = 3" << std::endl;
609     std::cout << "IMS_PS_VOICE_ONLY = 4" << std::endl;
610     std::cin >> mode;
611     if (g_clientPtr == nullptr) {
612         std::cout << "g_clientPtr is nullptr" << std::endl;
613         return;
614     }
615     int32_t ret = g_clientPtr->SetCallPreferenceMode(slotId, mode);
616     std::cout << "return value:" << ret << std::endl;
617 }
618 
GetCallTransferInfo()619 void GetCallTransferInfo()
620 {
621     AccessToken token;
622     int32_t slotId = SIM1_SLOTID;
623     int32_t tmpType = DEFAULT_VALUE;
624     CallTransferType type;
625     std::cout << "------GetCallTransferInfo------" << std::endl;
626     std::cout << "please input slotId:" << std::endl;
627     std::cin >> slotId;
628     std::cout << "please input transfer type:" << std::endl;
629     std::cin >> tmpType;
630     type = static_cast<CallTransferType>(tmpType);
631     if (g_clientPtr == nullptr) {
632         std::cout << "g_clientPtr is nullptr" << std::endl;
633         return;
634     }
635     int32_t ret = g_clientPtr->GetCallTransferInfo(slotId, type);
636     std::cout << "return value:" << ret << std::endl;
637 }
638 
SetCallTransferInfo()639 void SetCallTransferInfo()
640 {
641     AccessToken token;
642     int32_t slotId = SIM1_SLOTID;
643     int32_t tmpType = DEFAULT_VALUE;
644     CallTransferInfo info;
645     std::cout << "------SetCallTransferInfo------" << std::endl;
646     std::cout << "please input slotId:" << std::endl;
647     std::cin >> slotId;
648     std::cout << "please input transfer type:" << std::endl;
649     std::cin >> tmpType;
650     info.type = static_cast<CallTransferType>(tmpType);
651     std::cout << "please input transfer setting type:" << std::endl;
652     std::cin >> tmpType;
653     info.settingType = static_cast<CallTransferSettingType>(tmpType);
654     std::cout << "please input phone number:" << std::endl;
655     std::cin >> info.transferNum;
656     if (g_clientPtr == nullptr) {
657         std::cout << "g_clientPtr is nullptr" << std::endl;
658         return;
659     }
660     int32_t ret = g_clientPtr->SetCallTransferInfo(slotId, info);
661     std::cout << "return value:" << ret << std::endl;
662 }
663 
CanSetCallTransferTime()664 void CanSetCallTransferTime()
665 {
666     AccessToken token;
667     int32_t slotId = SIM1_SLOTID;
668     std::cout << "------CanSetCallTransferTime------" << std::endl;
669     std::cout << "please input slotId:" << std::endl;
670     std::cin >> slotId;
671     if (g_clientPtr == nullptr) {
672         std::cout << "g_clientPtr is nullptr" << std::endl;
673         return;
674     }
675     bool result;
676     int32_t ret = g_clientPtr->CanSetCallTransferTime(slotId, result);
677     std::cout << "return value:" << ret << std::endl;
678     std::cout << "return result:" << result << std::endl;
679 }
680 
IsEmergencyPhoneNumber()681 void IsEmergencyPhoneNumber()
682 {
683     int32_t slotId = SIM1_SLOTID;
684     std::u16string phoneNumber;
685     std::string tmpStr;
686     std::cout << "------IsEmergencyPhoneNumber------" << std::endl;
687     std::cout << "please input phone number:" << std::endl;
688     phoneNumber.clear();
689     tmpStr.clear();
690     std::cin >> tmpStr;
691     phoneNumber = Str8ToStr16(tmpStr);
692     std::cout << "The number is " << tmpStr << std::endl;
693     std::cout << "please input slotId:" << std::endl;
694     std::cin >> slotId;
695     if (g_clientPtr == nullptr) {
696         std::cout << "g_clientPtr is nullptr" << std::endl;
697         return;
698     }
699     bool enabled = false;
700     int32_t ret = g_clientPtr->IsEmergencyPhoneNumber(phoneNumber, slotId, enabled);
701     std::cout << "return value:" << enabled << std::endl;
702     std::cout << "return errorCode:" << ret << std::endl;
703 }
704 
FormatPhoneNumber()705 void FormatPhoneNumber()
706 {
707     std::u16string phoneNumber;
708     std::u16string countryCode;
709     std::u16string formatNumber;
710     std::string tmpStr;
711     std::cout << "------FormatPhoneNumber------" << std::endl;
712     std::cout << "please input phone number:" << std::endl;
713     phoneNumber.clear();
714     countryCode.clear();
715     formatNumber.clear();
716     tmpStr.clear();
717     std::cin >> tmpStr;
718     phoneNumber = Str8ToStr16(tmpStr);
719     std::cout << "The number is " << tmpStr << std::endl;
720     tmpStr.clear();
721     std::cout << "please input countryCode:" << std::endl;
722     std::cin >> tmpStr;
723     countryCode = Str8ToStr16(tmpStr);
724     if (g_clientPtr == nullptr) {
725         std::cout << "g_clientPtr is nullptr" << std::endl;
726         return;
727     }
728     int32_t ret = g_clientPtr->FormatPhoneNumber(phoneNumber, countryCode, formatNumber);
729     std::cout << "return value:" << ret << std::endl;
730     std::cout << "return number:" << Str16ToStr8(formatNumber) << std::endl;
731 }
732 
FormatPhoneNumberToE164()733 void FormatPhoneNumberToE164()
734 {
735     std::u16string phoneNumberE164;
736     std::u16string countryCode;
737     std::u16string formatNumber;
738     std::string tmpStr;
739     std::cout << "------FormatPhoneNumberToE164------" << std::endl;
740     std::cout << "please input phone number:" << std::endl;
741     phoneNumberE164.clear();
742     countryCode.clear();
743     formatNumber.clear();
744     tmpStr.clear();
745     std::cin >> tmpStr;
746     phoneNumberE164 = Str8ToStr16(tmpStr);
747     std::cout << "The number is " << tmpStr << std::endl;
748     tmpStr.clear();
749     std::cout << "please input countryCode:" << std::endl;
750     std::cin >> tmpStr;
751     countryCode = Str8ToStr16(tmpStr);
752     if (g_clientPtr == nullptr) {
753         std::cout << "g_clientPtr is nullptr" << std::endl;
754         return;
755     }
756     int32_t ret = g_clientPtr->FormatPhoneNumberToE164(phoneNumberE164, countryCode, formatNumber);
757     std::cout << "return value:" << ret << std::endl;
758     std::cout << "return number:" << Str16ToStr8(formatNumber) << std::endl;
759 }
760 
GetMainCallId()761 void GetMainCallId()
762 {
763     int callId = DEFAULT_CALL_ID;
764     std::cout << "please input callId:" << std::endl;
765     std::cin >> callId;
766     int mainCallId = DEFAULT_CALL_ID;
767     int32_t ret = g_clientPtr->GetMainCallId(callId, mainCallId);
768     std::cout << "return value:" << ret << std::endl;
769     std::cout << "mainCallId value:" << mainCallId << std::endl;
770 }
771 
GetSubCallIdList()772 void GetSubCallIdList()
773 {
774     int32_t callId = DEFAULT_CALL_ID;
775     std::cout << "please input callId:" << std::endl;
776     std::cin >> callId;
777     std::vector<std::u16string> result;
778     result.clear();
779     int32_t ret = g_clientPtr->GetSubCallIdList(callId, result);
780     if (ret != TELEPHONY_SUCCESS) {
781         std::cout << "GetSubCallIdList ret value:" << ret << std::endl;
782     }
783     std::vector<std::u16string>::iterator it = result.begin();
784     for (; it != result.end(); ++it) {
785         std::cout << "callId:" << Str16ToStr8(*it) << std::endl;
786     }
787 }
788 
GetCallIdListForConference()789 void GetCallIdListForConference()
790 {
791     int32_t callId = DEFAULT_CALL_ID;
792     std::cout << "please input callId:" << std::endl;
793     std::cin >> callId;
794     std::vector<std::u16string> result;
795     result.clear();
796     int32_t ret = g_clientPtr->GetCallIdListForConference(callId, result);
797     if (ret != TELEPHONY_SUCCESS) {
798         std::cout << "GetCallIdListForConference ret value:" << ret << std::endl;
799     }
800     std::vector<std::u16string>::iterator it = result.begin();
801     for (; it != result.end(); ++it) {
802         std::cout << "callId:" << Str16ToStr8(*it) << std::endl;
803     }
804 }
805 
InviteToConference()806 void InviteToConference()
807 {
808     int32_t callId = DEFAULT_CALL_ID;
809     std::cout << "please input callId:" << std::endl;
810     std::cin >> callId;
811     std::string number;
812     std::vector<std::u16string> numberList;
813     std::cout << "please input participate phone number:[-1]end" << std::endl;
814     while (std::cin >> number) {
815         numberList.push_back(Str8ToStr16(number));
816         if (number == "-1") {
817             break;
818         }
819     }
820     int32_t ret = g_clientPtr->JoinConference(callId, numberList);
821     std::cout << "return value:" << ret << std::endl;
822 }
823 
SetMute()824 void SetMute()
825 {
826     int32_t isMute = DEFAULT_VALUE;
827     std::cout << "------SetMute------" << std::endl;
828     std::cout << "please input mute state(0:false 1:true):" << std::endl;
829     std::cin >> isMute;
830     if (g_clientPtr == nullptr) {
831         std::cout << "g_clientPtr is nullptr" << std::endl;
832         return;
833     }
834     int32_t ret = g_clientPtr->SetMuted((isMute == 1) ? true : false);
835     std::cout << "return value:" << ret << std::endl;
836 }
837 
MuteRinger()838 void MuteRinger()
839 {
840     AccessToken token;
841     std::cout << "------MuteRinger------" << std::endl;
842     if (g_clientPtr == nullptr) {
843         std::cout << "g_clientPtr is nullptr" << std::endl;
844         return;
845     }
846     int32_t ret = g_clientPtr->MuteRinger();
847     std::cout << "return value:" << ret << std::endl;
848 }
849 
SetAudioDevice()850 void SetAudioDevice()
851 {
852     int32_t deviceType = DEFAULT_VALUE;
853     AudioDevice audioDevice;
854     std::cout << "------SetAudioDevice------" << std::endl;
855     std::cout << "please input device type(0:earpiece 1:speaker 2:wired headset 3:bluetooth sco):" << std::endl;
856     std::cin >> deviceType;
857     if (deviceType == static_cast<int32_t>(AudioDeviceType::DEVICE_BLUETOOTH_SCO)) {
858         std::cout << "please input bluetoothAddress:" << std::endl;
859         std::cin >> audioDevice.address;
860     }
861     audioDevice.deviceType = static_cast<AudioDeviceType>(deviceType);
862     if (g_clientPtr == nullptr) {
863         std::cout << "g_clientPtr is nullptr" << std::endl;
864         return;
865     }
866     int32_t ret = g_clientPtr->SetAudioDevice(audioDevice);
867     std::cout << "return value:" << ret << std::endl;
868 }
869 
GetVolume()870 void GetVolume()
871 {
872     int32_t type = DEFAULT_VALUE;
873     std::cout << "------GetVolume------" << std::endl;
874     std::cout << "please input volume type(3:ring 4:music)" << std::endl;
875     std::cin >> type;
876     AudioStandard::AudioVolumeType audioVolumeType = AudioStandard::AudioVolumeType::STREAM_MUSIC;
877     switch (type) {
878         case AudioStandard::AudioVolumeType::STREAM_RING:
879             audioVolumeType = AudioStandard::AudioVolumeType::STREAM_RING;
880             break;
881         case AudioStandard::AudioVolumeType::STREAM_MUSIC:
882             audioVolumeType = AudioStandard::AudioVolumeType::STREAM_MUSIC;
883             break;
884         default:
885             break;
886     }
887     AudioStandard::AudioSystemManager *audioSystemMgr = AudioStandard::AudioSystemManager::GetInstance();
888     int32_t ret = audioSystemMgr->GetVolume(audioVolumeType);
889     std::cout << "return value:" << ret << std::endl;
890 }
891 
SetVolume()892 void SetVolume()
893 {
894     int32_t volume = DEFAULT_VALUE;
895     int32_t type = DEFAULT_VALUE;
896     std::cout << "------SetVolume------" << std::endl;
897     std::cout << "please input volume value(0~15) :" << std::endl;
898     std::cin >> volume;
899     std::cout << "please input volume type(3:ring 4:music)" << std::endl;
900     std::cin >> type;
901     if (volume < MIN_VOLUME || volume > MAX_VOLUME) {
902         std::cout << "volume value error" << std::endl;
903         return;
904     }
905     AudioStandard::AudioVolumeType volumeType = AudioStandard::AudioVolumeType::STREAM_MUSIC;
906     switch (type) {
907         case AudioStandard::AudioVolumeType::STREAM_RING:
908             volumeType = AudioStandard::AudioVolumeType::STREAM_RING;
909             break;
910         case AudioStandard::AudioVolumeType::STREAM_MUSIC:
911             volumeType = AudioStandard::AudioVolumeType::STREAM_MUSIC;
912             break;
913         default:
914             break;
915     }
916     AudioStandard::AudioSystemManager *audioSystemMgr = AudioStandard::AudioSystemManager::GetInstance();
917     int32_t ret = audioSystemMgr->SetVolume(volumeType, volume);
918     std::cout << "return value:" << ret << std::endl;
919 }
920 
InitRenderer(const std::unique_ptr<AudioStandard::AudioRenderer> & audioRenderer,const wav_hdr & wavHeader)921 bool InitRenderer(const std::unique_ptr<AudioStandard::AudioRenderer> &audioRenderer, const wav_hdr &wavHeader)
922 {
923     if (audioRenderer == nullptr) {
924         std::cout << "audioRenderer is null" << std::endl;
925         return false;
926     }
927     AudioStandard::AudioRendererParams rendererParams;
928     rendererParams.sampleFormat = AudioStandard::AudioSampleFormat::SAMPLE_S16LE;
929     rendererParams.sampleRate = static_cast<AudioStandard::AudioSamplingRate>(wavHeader.SamplesPerSec);
930     rendererParams.channelCount = static_cast<AudioStandard::AudioChannel>(wavHeader.NumOfChan);
931     rendererParams.encodingType = static_cast<AudioStandard::AudioEncodingType>(AudioStandard::ENCODING_PCM);
932     if (audioRenderer->SetParams(rendererParams) != TELEPHONY_SUCCESS) {
933         std::cout << "audio renderer set params error" << std::endl;
934         if (!audioRenderer->Release()) {
935             std::cout << "audio renderer release error" << std::endl;
936         }
937         return false;
938     }
939     if (!audioRenderer->Start()) {
940         std::cout << "audio renderer start error" << std::endl;
941         return false;
942     }
943     uint32_t frameCount;
944     if (audioRenderer->GetFrameCount(frameCount)) {
945         return false;
946     }
947     std::cout << "frame count : " << frameCount << std::endl;
948     return true;
949 }
950 
PlayRingtone()951 bool PlayRingtone()
952 {
953     wav_hdr wavHeader;
954     std::cout << "please input ringtone file path : " << std::endl;
955     char path[RING_PATH_MAX_LENGTH];
956     std::cin >> path;
957     FILE *wavFile = fopen(path, "rb");
958     if (wavFile == nullptr) {
959         std::cout << "wav file nullptr" << std::endl;
960         return false;
961     }
962     (void)fread(&wavHeader, READ_SIZE, sizeof(wav_hdr), wavFile);
963     std::unique_ptr<AudioStandard::AudioRenderer> audioRenderer =
964         AudioStandard::AudioRenderer::Create(AudioStandard::AudioStreamType::STREAM_MUSIC);
965     if (!InitRenderer(audioRenderer, wavHeader)) {
966         (void)fclose(wavFile);
967         return false;
968     }
969     size_t bufferLen, bytesToWrite = DEFAULT_SIZE, bytesWritten = DEFAULT_SIZE;
970     if (audioRenderer->GetBufferSize(bufferLen)) {
971         (void)fclose(wavFile);
972         return false;
973     }
974     std::unique_ptr<uint8_t> buffer = std::make_unique<uint8_t>(bufferLen + bufferLen);
975     if (buffer == nullptr) {
976         std::cout << "malloc memory nullptr" << std::endl;
977         (void)fclose(wavFile);
978         return false;
979     }
980     while (!feof(wavFile)) {
981         bytesToWrite = fread(buffer.get(), READ_SIZE, bufferLen, wavFile);
982         bytesWritten = DEFAULT_SIZE;
983         while ((bytesWritten < bytesToWrite) && ((bytesToWrite - bytesWritten) > MIN_BYTES)) {
984             bytesWritten += audioRenderer->Write(buffer.get() + bytesWritten, bytesToWrite - bytesWritten);
985         }
986     }
987     audioRenderer->Flush();
988     audioRenderer->Drain();
989     audioRenderer->Stop();
990     audioRenderer->Release();
991     (void)fclose(wavFile);
992     std::cout << "audio renderer plackback done" << std::endl;
993     return true;
994 }
995 
ControlCamera()996 void ControlCamera()
997 {
998     AccessToken token;
999     std::cout << "------ControlCamera test------" << std::endl;
1000     std::cout << "please input callId:" << std::endl;
1001     int32_t callId = DEFAULT_CALL_ID;
1002     std::cin >> callId;
1003     std::cout << "please input cameraId(1~3):" << std::endl;
1004     std::string cameraId = "";
1005     std::cin >> cameraId;
1006     std::u16string cameraId16;
1007     cameraId16.clear();
1008     cameraId16 = Str8ToStr16(cameraId);
1009 
1010     int32_t ret = g_clientPtr->ControlCamera(callId, cameraId16);
1011     std::cout << "return value:" << ret << std::endl;
1012 
1013     std::cout << "ControlCamera done" << std::endl;
1014 }
1015 
SetPreviewWindow()1016 void SetPreviewWindow()
1017 {
1018     AccessToken token;
1019     std::cout << "------SetPreviewWindow test------" << std::endl;
1020     std::cout << "please input callId:" << std::endl;
1021     int32_t ret = -1;
1022     int32_t callId = DEFAULT_CALL_ID;
1023     std::cin >> callId;
1024     std::cout << "please input surfaceId:" << std::endl;
1025     std::string surfaceId = "";
1026     std::cin >> surfaceId;
1027     if (surfaceId.empty() || surfaceId[0] < '0' || surfaceId[0] > '9') {
1028         surfaceId = "";
1029         ret = g_clientPtr->SetPreviewWindow(callId, surfaceId);
1030     } else {
1031         int len = static_cast<int>(surfaceId.length());
1032         std::string subSurfaceId = surfaceId;
1033         if (len >= 1) {
1034             subSurfaceId = surfaceId.substr(0, 1);
1035         }
1036         ret = g_clientPtr->SetPreviewWindow(callId, subSurfaceId);
1037     }
1038     std::cout << "return value:" << ret << std::endl;
1039     std::cout << "SetPreviewWindow done" << std::endl;
1040 }
1041 
SetDisplayWindow()1042 void SetDisplayWindow()
1043 {
1044     AccessToken token;
1045     std::cout << "------SetDisplayWindow test------" << std::endl;
1046     std::cout << "please input callId:" << std::endl;
1047     int32_t ret = -1;
1048     int32_t callId = DEFAULT_CALL_ID;
1049     std::cin >> callId;
1050     std::cout << "please input surfaceId:" << std::endl;
1051     std::string surfaceId = "";
1052     std::cin >> surfaceId;
1053     if (surfaceId.empty() || surfaceId[0] < '0' || surfaceId[0] > '9') {
1054         surfaceId = "";
1055         ret = g_clientPtr->SetDisplayWindow(callId, surfaceId);
1056     } else {
1057         int len = static_cast<int>(surfaceId.length());
1058         std::string subSurfaceId = surfaceId;
1059         if (len >= 1) {
1060             subSurfaceId = surfaceId.substr(0, 1);
1061         }
1062         ret = g_clientPtr->SetDisplayWindow(callId, subSurfaceId);
1063     }
1064     std::cout << "return value:" << ret << std::endl;
1065     std::cout << "SetDisplayWindow done" << std::endl;
1066 }
1067 
SetCameraZoom()1068 void SetCameraZoom()
1069 {
1070     AccessToken token;
1071     std::cout << "------SetCameraZoom test------" << std::endl;
1072     const float CameraZoomMax = 12.0;
1073     const float CameraZoomMin = -0.1;
1074     const float CameraZoom = 2.0;
1075     std::cout << "------SetCameraZoom test------" << std::endl;
1076     int32_t ret = g_clientPtr->SetCameraZoom(CameraZoomMax);
1077     std::cout << "return value:" << ret << std::endl;
1078 
1079     ret = g_clientPtr->SetCameraZoom(CameraZoomMin);
1080     std::cout << "return value:" << ret << std::endl;
1081 
1082     ret = g_clientPtr->SetCameraZoom(CameraZoom);
1083     std::cout << "return value:" << ret << std::endl;
1084     std::cout << "SetCameraZoom done" << std::endl;
1085 }
1086 
SetPausePicture()1087 void SetPausePicture()
1088 {
1089     AccessToken token;
1090     std::cout << "------SetPausePicture test------" << std::endl;
1091     std::cout << "please input callId:" << std::endl;
1092     int32_t callId = DEFAULT_CALL_ID;
1093     std::cin >> callId;
1094     std::u16string path;
1095     std::string tmpStr = "/system/bin/1.png";
1096     path.clear();
1097     path = Str8ToStr16(tmpStr);
1098     int32_t ret = g_clientPtr->SetPausePicture(callId, path);
1099     std::cout << "return value:" << ret << std::endl;
1100     std::cout << "SetPausePicture done" << std::endl;
1101 }
1102 
SetDeviceDirection()1103 void SetDeviceDirection()
1104 {
1105     AccessToken token;
1106     const int32_t deviceDirectionError1 = 50;
1107     const int32_t deviceDirectionError2 = 350;
1108     const int32_t deviceDirection90 = 90;
1109     std::cout << "------SetDeviceDirection test------" << std::endl;
1110     std::cout << "please input callId:" << std::endl;
1111     int32_t callId = DEFAULT_CALL_ID;
1112     std::cin >> callId;
1113     int32_t ret = g_clientPtr->SetDeviceDirection(callId, deviceDirectionError1);
1114     std::cout << "\n return value:" << ret << std::endl;
1115 
1116     ret = g_clientPtr->SetDeviceDirection(callId, deviceDirectionError2);
1117     std::cout << "\n return value:" << ret << std::endl;
1118 
1119     ret = g_clientPtr->SetDeviceDirection(callId, deviceDirection90);
1120     std::cout << "\n return value:" << ret << std::endl;
1121     std::cout << "SetDeviceDirection done" << std::endl;
1122 }
1123 
SubscribeCommonEvent()1124 void SubscribeCommonEvent()
1125 {
1126     std::cout << "------SubscribeCommonEvent------" << std::endl;
1127     std::cout << "please input common event type : " << std::endl;
1128     char eventType[RING_PATH_MAX_LENGTH];
1129     std::cin >> eventType;
1130     OHOS::EventFwk::MatchingSkills matchingSkills;
1131     std::string event(eventType);
1132     matchingSkills.AddEvent(event);
1133     // make subcriber info
1134     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
1135     // make a subcriber object
1136     std::shared_ptr<CommonEventSubscriberTest> subscriberTest =
1137         std::make_shared<CommonEventSubscriberTest>(subscriberInfo);
1138     if (subscriberTest == nullptr) {
1139         std::cout << "subscriber nullptr" << std::endl;
1140     }
1141     // subscribe a common event
1142     bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
1143     std::cout << "subscribe common event : " << eventType << ", result : " << result << std::endl;
1144 }
1145 
GetImsConfig()1146 void GetImsConfig()
1147 {
1148     int32_t slotId = SIM1_SLOTID;
1149     int32_t item = DEFAULT_ITEM_VALUE;
1150     std::cout << "------GetImsConfig------" << std::endl;
1151     std::cout << "please input slotId:" << std::endl;
1152     std::cin >> slotId;
1153     std::cout << "please input item:" << std::endl;
1154     std::cin >> item;
1155     int32_t ret = TELEPHONY_SUCCESS;
1156     if (g_clientPtr == nullptr) {
1157         std::cout << "g_clientPtr is nullptr" << std::endl;
1158         return;
1159     }
1160     ret = g_clientPtr->GetImsConfig(slotId, static_cast<ImsConfigItem>(item));
1161     std::cout << "return value:" << ret << std::endl;
1162 }
1163 
SetImsConfig()1164 void SetImsConfig()
1165 {
1166     int32_t slotId = SIM1_SLOTID;
1167     int32_t item = DEFAULT_ITEM_VALUE;
1168     std::string tmpValue;
1169     std::u16string value;
1170     std::cout << "------SetImsConfig------" << std::endl;
1171     std::cout << "please input slotId:" << std::endl;
1172     std::cin >> slotId;
1173     std::cout << "please input item:" << std::endl;
1174     std::cin >> item;
1175     std::cout << "please input item value:" << std::endl;
1176     std::cin >> tmpValue;
1177     int32_t ret = TELEPHONY_SUCCESS;
1178     if (g_clientPtr == nullptr) {
1179         std::cout << "g_clientPtr is nullptr" << std::endl;
1180         return;
1181     }
1182     value = Str8ToStr16(tmpValue);
1183     ret = g_clientPtr->SetImsConfig(slotId, static_cast<ImsConfigItem>(item), value);
1184     std::cout << "return value:" << ret << std::endl;
1185 }
1186 
GetImsFeatureValue()1187 void GetImsFeatureValue()
1188 {
1189     int32_t slotId = SIM1_SLOTID;
1190     int32_t tmpType = FeatureType::TYPE_VOICE_OVER_LTE;
1191     FeatureType type = FeatureType::TYPE_VOICE_OVER_LTE;
1192     std::cout << "------GetImsFeatureValue------" << std::endl;
1193     std::cout << "please input slotId:" << std::endl;
1194     std::cin >> slotId;
1195     std::cout << "please input feature type:" << std::endl;
1196     std::cin >> tmpType;
1197     type = static_cast<FeatureType>(tmpType);
1198     int32_t ret = TELEPHONY_SUCCESS;
1199     if (g_clientPtr == nullptr) {
1200         std::cout << "g_clientPtr is nullptr" << std::endl;
1201         return;
1202     }
1203     ret = g_clientPtr->GetImsFeatureValue(slotId, type);
1204     std::cout << "return value:" << ret << std::endl;
1205 }
1206 
SetImsFeatureValue()1207 void SetImsFeatureValue()
1208 {
1209     int32_t slotId = SIM1_SLOTID;
1210     int32_t tmpType = FeatureType::TYPE_VOICE_OVER_LTE;
1211     FeatureType type;
1212     int32_t value = DEFAULT_NET_TYPE;
1213     std::cout << "------SetImsNetworkValue------" << std::endl;
1214     std::cout << "please input slotId:" << std::endl;
1215     std::cin >> slotId;
1216     std::cout << "please input feature type:" << std::endl;
1217     std::cin >> tmpType;
1218     type = (FeatureType)tmpType;
1219     std::cout << "please input value:" << std::endl;
1220     std::cin >> value;
1221     int32_t ret = TELEPHONY_SUCCESS;
1222     if (g_clientPtr == nullptr) {
1223         std::cout << "g_clientPtr is nullptr" << std::endl;
1224         return;
1225     }
1226     ret = g_clientPtr->SetImsFeatureValue(slotId, type, value);
1227     std::cout << "return value:" << ret << std::endl;
1228 }
1229 
UpdateImsCallMode()1230 void UpdateImsCallMode()
1231 {
1232     int32_t callId = DEFAULT_CALL_ID;
1233     uint32_t mediaMode = DEFAULT_VIDEO_STATE;
1234     std::cout << "------UpdateImsCallMode------" << std::endl;
1235     std::cout << "please input callId:" << std::endl;
1236     std::cin >> callId;
1237     std::cout << "please input media mode[0:voice, 3:video]:" << std::endl;
1238     std::cin >> mediaMode;
1239     ImsCallMode mode = static_cast<ImsCallMode>(mediaMode);
1240     int32_t ret = TELEPHONY_SUCCESS;
1241     if (g_clientPtr == nullptr) {
1242         std::cout << "g_clientPtr is nullptr" << std::endl;
1243         return;
1244     }
1245     ret = g_clientPtr->UpdateImsCallMode(callId, mode);
1246     std::cout << "return value:" << ret << std::endl;
1247 }
1248 
EnableImsSwitch()1249 void EnableImsSwitch()
1250 {
1251     AccessToken token;
1252     int32_t slotId = SIM1_SLOTID;
1253     std::cout << "------EnableImsSwitch------" << std::endl;
1254     std::cout << "please input slot id:" << std::endl;
1255     std::cin >> slotId;
1256     int32_t ret = TELEPHONY_SUCCESS;
1257     if (g_clientPtr == nullptr) {
1258         std::cout << "g_clientPtr is nullptr" << std::endl;
1259         return;
1260     }
1261     ret = g_clientPtr->EnableImsSwitch(slotId);
1262     std::cout << "return value:" << ret << std::endl;
1263 }
1264 
DisableImsSwitch()1265 void DisableImsSwitch()
1266 {
1267     AccessToken token;
1268     int32_t slotId = SIM1_SLOTID;
1269     std::cout << "------DisableImsSwitch------" << std::endl;
1270     std::cout << "please input slot id:" << std::endl;
1271     std::cin >> slotId;
1272     int32_t ret = TELEPHONY_SUCCESS;
1273     if (g_clientPtr == nullptr) {
1274         std::cout << "g_clientPtr is nullptr" << std::endl;
1275         return;
1276     }
1277     ret = g_clientPtr->DisableImsSwitch(slotId);
1278     std::cout << "return value:" << ret << std::endl;
1279 }
1280 
IsImsSwitchEnabled()1281 void IsImsSwitchEnabled()
1282 {
1283     int32_t slotId = SIM1_SLOTID;
1284     std::cout << "------IsImsSwitchEnabled------" << std::endl;
1285     std::cout << "please input slot id:" << std::endl;
1286     std::cin >> slotId;
1287     int32_t ret = TELEPHONY_SUCCESS;
1288     if (g_clientPtr == nullptr) {
1289         std::cout << "g_clientPtr is nullptr" << std::endl;
1290         return;
1291     }
1292     bool enabled;
1293     ret = g_clientPtr->IsImsSwitchEnabled(slotId, enabled);
1294     std::cout << "enabled:" << enabled << std::endl;
1295     std::cout << "return value:" << ret << std::endl;
1296 }
1297 
SetVoNRState()1298 void SetVoNRState()
1299 {
1300     AccessToken token;
1301     int32_t slotId = SIM1_SLOTID;
1302     int32_t state = 0;
1303     std::cout << "------SetVoNRState------" << std::endl;
1304     std::cout << "please input slot id:" << std::endl;
1305     std::cin >> slotId;
1306     std::cout << "please input state:" << std::endl;
1307     std::cin >> state;
1308     int32_t ret = TELEPHONY_SUCCESS;
1309     if (g_clientPtr == nullptr) {
1310         std::cout << "g_clientPtr is nullptr" << std::endl;
1311         return;
1312     }
1313     ret = g_clientPtr->SetVoNRState(slotId, state);
1314     std::cout << "return value:" << ret << std::endl;
1315 }
1316 
GetVoNRState()1317 void GetVoNRState()
1318 {
1319     AccessToken token;
1320     int32_t slotId = SIM1_SLOTID;
1321     std::cout << "------GetVoNRState------" << std::endl;
1322     std::cout << "please input slot id:" << std::endl;
1323     std::cin >> slotId;
1324     int32_t ret = TELEPHONY_SUCCESS;
1325     if (g_clientPtr == nullptr) {
1326         std::cout << "g_clientPtr is nullptr" << std::endl;
1327         return;
1328     }
1329     int32_t state;
1330     ret = g_clientPtr->GetVoNRState(slotId, state);
1331     std::cout << "state:" << state << std::endl;
1332     std::cout << "return value:" << ret << std::endl;
1333 }
1334 
StartRtt()1335 void StartRtt()
1336 {
1337     int32_t callId = DEFAULT_CALL_ID;
1338     std::u16string msg;
1339     std::string tmpMsg;
1340     std::cout << "------StartRtt------" << std::endl;
1341     std::cout << "please input call id:" << std::endl;
1342     std::cin >> callId;
1343     std::cout << "please input Rtt msg:" << std::endl;
1344     msg.clear();
1345     tmpMsg.clear();
1346     std::cin >> tmpMsg;
1347     msg = Str8ToStr16(tmpMsg);
1348     if (g_clientPtr == nullptr) {
1349         std::cout << "g_clientPtr is nullptr" << std::endl;
1350         return;
1351     }
1352     int32_t ret = g_clientPtr->StartRtt(callId, msg);
1353     std::cout << "return value:" << ret << std::endl;
1354 }
1355 
StopRtt()1356 void StopRtt()
1357 {
1358     int32_t callId = DEFAULT_CALL_ID;
1359     std::cout << "------StopRtt------" << std::endl;
1360     std::cout << "please input call id:" << std::endl;
1361     std::cin >> callId;
1362     if (g_clientPtr == nullptr) {
1363         std::cout << "g_clientPtr is nullptr" << std::endl;
1364         return;
1365     }
1366     int32_t ret = g_clientPtr->StopRtt(callId);
1367     std::cout << "return value:" << ret << std::endl;
1368 }
1369 
InputDialerSpecialCode()1370 void InputDialerSpecialCode()
1371 {
1372     AccessToken token;
1373     std::string specialCode;
1374     std::cout << "------InputDialerSpecialCode------" << std::endl;
1375     std::cout << "please input special code:" << std::endl;
1376     std::cin >> specialCode;
1377     if (g_clientPtr == nullptr) {
1378         std::cout << "g_clientPtr is nullptr" << std::endl;
1379         return;
1380     }
1381     int32_t ret = g_clientPtr->InputDialerSpecialCode(specialCode);
1382     std::cout << "return value:" << ret << std::endl;
1383 }
1384 
RemoveMissedIncomingCallNotification()1385 void RemoveMissedIncomingCallNotification()
1386 {
1387     AccessToken token;
1388     std::cout << "------RemoveMissedIncomingCallNotification------" << std::endl;
1389     if (g_clientPtr == nullptr) {
1390         std::cout << "g_clientPtr is nullptr" << std::endl;
1391         return;
1392     }
1393     int32_t ret = g_clientPtr->RemoveMissedIncomingCallNotification();
1394     std::cout << "return value:" << ret << std::endl;
1395 }
1396 
CancelCallUpgrade()1397 void CancelCallUpgrade()
1398 {
1399     int32_t callId = DEFAULT_CALL_ID;
1400     std::cout << "------CancelCallUpgrade------" << std::endl;
1401     std::cout << "please input call id:" << std::endl;
1402     std::cin >> callId;
1403     if (g_clientPtr == nullptr) {
1404         std::cout << "g_clientPtr is nullptr" << std::endl;
1405         return;
1406     }
1407     int32_t ret = g_clientPtr->CancelCallUpgrade(callId);
1408     std::cout << "return value:" << ret << std::endl;
1409 }
1410 
RequestCameraCapabilities()1411 void RequestCameraCapabilities()
1412 {
1413     int32_t callId = DEFAULT_CALL_ID;
1414     std::cout << "------RequestCameraCapabilities------" << std::endl;
1415     std::cout << "please input call id:" << std::endl;
1416     std::cin >> callId;
1417     if (g_clientPtr == nullptr) {
1418         std::cout << "g_clientPtr is nullptr" << std::endl;
1419         return;
1420     }
1421     int32_t ret = g_clientPtr->RequestCameraCapabilities(callId);
1422     std::cout << "return value:" << ret << std::endl;
1423 }
1424 
AddPermission()1425 void AddPermission()
1426 {
1427     return;
1428 }
1429 
InitPermission()1430 void InitPermission()
1431 {
1432     return;
1433 }
1434 
VerifyPermission()1435 void VerifyPermission()
1436 {
1437     return;
1438 }
1439 
InitCallBasicPower()1440 void InitCallBasicPower()
1441 {
1442     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_DIAL_CALL)] = &OHOS::Telephony::DialCall;
1443     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_ANSWER_CALL)] =
1444         &OHOS::Telephony::AnswerCall;
1445     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_REJECT_CALL)] =
1446         &OHOS::Telephony::RejectCall;
1447     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_HOLD_CALL)] = &OHOS::Telephony::HoldCall;
1448     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_UNHOLD_CALL)] =
1449         &OHOS::Telephony::UnHoldCall;
1450     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_DISCONNECT_CALL)] =
1451         &OHOS::Telephony::HangUpCall;
1452     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_CALL_STATE)] =
1453         &OHOS::Telephony::GetCallState;
1454     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SWAP_CALL)] =
1455         &OHOS::Telephony::SwitchCall;
1456     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_START_RTT)] = &OHOS::Telephony::StartRtt;
1457     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_STOP_RTT)] = &OHOS::Telephony::StopRtt;
1458     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_INPUT_DIALER_SPECIAL_CODE)] =
1459         &OHOS::Telephony::InputDialerSpecialCode;
1460 }
1461 
InitCallUtils()1462 void InitCallUtils()
1463 {
1464     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_HAS_CALL)] = &OHOS::Telephony::HasCall;
1465     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_NEW_CALL_ALLOWED)] =
1466         &OHOS::Telephony::IsNewCallAllowed;
1467     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_RINGING)] =
1468         &OHOS::Telephony::IsRinging;
1469     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_EMERGENCY_CALL)] =
1470         &OHOS::Telephony::IsInEmergencyCall;
1471     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_EMERGENCY_NUMBER)] =
1472         &OHOS::Telephony::IsEmergencyPhoneNumber;
1473     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_FORMAT_NUMBER)] =
1474         &OHOS::Telephony::FormatPhoneNumber;
1475     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_FORMAT_NUMBER_E164)] =
1476         &OHOS::Telephony::FormatPhoneNumberToE164;
1477     g_memberFuncMap[static_cast<int32_t>(
1478         CallManagerInterfaceCode::INTERFACE_CANCEL_MISSED_INCOMING_CALL_NOTIFICATION)] =
1479         &OHOS::Telephony::RemoveMissedIncomingCallNotification;
1480 }
1481 
InitCallConferencePower()1482 void InitCallConferencePower()
1483 {
1484     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_COMBINE_CONFERENCE)] =
1485         &OHOS::Telephony::CombineConference;
1486     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SEPARATE_CONFERENCE)] =
1487         &OHOS::Telephony::SeparateConference;
1488     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_KICK_OUT_CONFERENCE)] =
1489         &OHOS::Telephony::KickOutFromConference;
1490 }
1491 
InitCallDtmfPower()1492 void InitCallDtmfPower()
1493 {
1494     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_START_DTMF)] =
1495         &OHOS::Telephony::StartDtmf;
1496     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_STOP_DTMF)] = &OHOS::Telephony::StopDtmf;
1497 }
1498 
InitCallSupplementPower()1499 void InitCallSupplementPower()
1500 {
1501     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_CALL_WAITING)] =
1502         &OHOS::Telephony::GetCallWaiting;
1503     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_CALL_WAITING)] =
1504         &OHOS::Telephony::SetCallWaiting;
1505     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_CALL_RESTRICTION)] =
1506         &OHOS::Telephony::GetCallRestriction;
1507     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_CALL_RESTRICTION)] =
1508         &OHOS::Telephony::SetCallRestriction;
1509     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_CALL_RESTRICTION_PASSWORD)] =
1510         &OHOS::Telephony::SetCallRestrictionPassword;
1511     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_CALL_TRANSFER)] =
1512         &OHOS::Telephony::GetCallTransferInfo;
1513     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_CALL_TRANSFER)] =
1514         &OHOS::Telephony::SetCallTransferInfo;
1515     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_CAN_SET_CALL_TRANSFER_TIME)] =
1516         &OHOS::Telephony::CanSetCallTransferTime;
1517     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SETCALL_PREFERENCEMODE)] =
1518         &OHOS::Telephony::SetCallPreferenceMode;
1519 }
1520 
initCallConferenceExPower()1521 void initCallConferenceExPower()
1522 {
1523     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_MAINID)] =
1524         &OHOS::Telephony::GetMainCallId;
1525     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_SUBCALL_LIST_ID)] =
1526         &OHOS::Telephony::GetSubCallIdList;
1527     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_CALL_LIST_ID_FOR_CONFERENCE)] =
1528         &OHOS::Telephony::GetCallIdListForConference;
1529     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_JOIN_CONFERENCE)] =
1530         &OHOS::Telephony::InviteToConference;
1531 }
1532 
InitCallMultimediaPower()1533 void InitCallMultimediaPower()
1534 {
1535     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_MUTE)] = &OHOS::Telephony::SetMute;
1536     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_MUTE_RINGER)] =
1537         &OHOS::Telephony::MuteRinger;
1538     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_AUDIO_DEVICE)] =
1539         &OHOS::Telephony::SetAudioDevice;
1540     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_CTRL_CAMERA)] =
1541         &OHOS::Telephony::ControlCamera;
1542     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_PREVIEW_WINDOW)] =
1543         &OHOS::Telephony::SetPreviewWindow;
1544     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_DISPLAY_WINDOW)] =
1545         &OHOS::Telephony::SetDisplayWindow;
1546     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_CAMERA_ZOOM)] =
1547         &OHOS::Telephony::SetCameraZoom;
1548     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_PAUSE_IMAGE)] =
1549         &OHOS::Telephony::SetPausePicture;
1550     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_DEVICE_DIRECTION)] =
1551         &OHOS::Telephony::SetDeviceDirection;
1552     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_UPDATE_CALL_MEDIA_MODE)] =
1553         &OHOS::Telephony::UpdateImsCallMode;
1554     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_CANCEL_CALL_UPGRADE)] =
1555         &OHOS::Telephony::CancelCallUpgrade;
1556     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_REQUEST_CAMERA_CAPABILITIES)] =
1557         &OHOS::Telephony::RequestCameraCapabilities;
1558     g_memberFuncMap[DEFINE_INIT_PERMISSIONS] = &OHOS::Telephony::InitPermission;
1559     g_memberFuncMap[DEFINE_VERIFY_PERMISSIONS] = &OHOS::Telephony::VerifyPermission;
1560 }
1561 
InitImsServicePower()1562 void InitImsServicePower()
1563 {
1564     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_IMS_CONFIG)] =
1565         &OHOS::Telephony::GetImsConfig;
1566     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_IMS_CONFIG)] =
1567         &OHOS::Telephony::SetImsConfig;
1568     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_IMS_FEATURE_VALUE)] =
1569         &OHOS::Telephony::GetImsFeatureValue;
1570     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_IMS_FEATURE_VALUE)] =
1571         &OHOS::Telephony::SetImsFeatureValue;
1572     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_ENABLE_VOLTE)] =
1573         &OHOS::Telephony::EnableImsSwitch;
1574     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_DISABLE_VOLTE)] =
1575         &OHOS::Telephony::DisableImsSwitch;
1576     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_IS_VOLTE_ENABLED)] =
1577         &OHOS::Telephony::IsImsSwitchEnabled;
1578     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_SET_VONR_STATE)] =
1579         &OHOS::Telephony::SetVoNRState;
1580     g_memberFuncMap[static_cast<int32_t>(CallManagerInterfaceCode::INTERFACE_GET_VONR_STATE)] =
1581         &OHOS::Telephony::GetVoNRState;
1582 }
1583 
Init()1584 int32_t Init()
1585 {
1586     AccessToken token;
1587     g_clientPtr = DelayedSingleton<CallManagerClient>::GetInstance();
1588     if (g_clientPtr == nullptr) {
1589         std::cout << "g_clientPtr is nullptr" << std::endl;
1590         return TELEPHONY_ERROR;
1591     }
1592     g_clientPtr->Init(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
1593     std::unique_ptr<CallManagerCallbackTest> callbackPtr = std::make_unique<CallManagerCallbackTest>();
1594     if (callbackPtr == nullptr) {
1595         std::cout << "make_unique CallManagerCallbackTest failed!" << std::endl;
1596         return TELEPHONY_ERROR;
1597     }
1598     int32_t ret = g_clientPtr->RegisterCallBack(std::move(callbackPtr));
1599     if (ret != TELEPHONY_SUCCESS) {
1600         std::cout << "RegisterCallBack failed!" << std::endl;
1601         return TELEPHONY_ERROR;
1602     }
1603     std::cout << "RegisterCallBack success!" << std::endl;
1604     InitCallBasicPower();
1605     InitCallUtils();
1606     InitCallConferencePower();
1607     InitCallDtmfPower();
1608     InitCallSupplementPower();
1609     initCallConferenceExPower();
1610     InitCallMultimediaPower();
1611     InitImsServicePower();
1612     return TELEPHONY_SUCCESS;
1613 }
1614 
PrintfCallBasisInterface()1615 void PrintfCallBasisInterface()
1616 {
1617     std::cout << "\n\n-----------start--------------\n"
1618               << "usage:please input a cmd num:\n"
1619               << "2:dial\n"
1620               << "3:answer\n"
1621               << "4:reject\n"
1622               << "5:hold\n"
1623               << "6:unhold\n"
1624               << "7:hangUpCall\n"
1625               << "8:getCallState\n"
1626               << "9:switchCall\n";
1627 }
1628 
PrintfCallUtilsInterface()1629 void PrintfCallUtilsInterface()
1630 {
1631     std::cout << "10:hasCall\n"
1632               << "11:isNewCallAllowed\n"
1633               << "12:isRinging\n"
1634               << "13:isInEmergencyCall\n"
1635               << "14:isEmergencyPhoneNumber\n"
1636               << "15:formatPhoneNumber\n"
1637               << "16:formatPhoneNumberToE164\n"
1638               << "58:RemoveMissedIncomingCallNotification\n";
1639 }
1640 
PrintfCallConferenceInterface()1641 void PrintfCallConferenceInterface()
1642 {
1643     std::cout << "17:combine conference\n"
1644               << "18:separate conference\n"
1645               << "62:kick out conference\n";
1646 }
1647 
PrintfCallDtmfInterface()1648 void PrintfCallDtmfInterface()
1649 {
1650     std::cout << "19:StartDtmf\n"
1651               << "20:StopDtmf\n";
1652 }
1653 
PrintfCallSupplementInterface()1654 void PrintfCallSupplementInterface()
1655 {
1656     std::cout << "21:getCallWaiting\n"
1657               << "22:setCallWaiting\n"
1658               << "23:getCallRestriction\n"
1659               << "24:setCallRestriction\n"
1660               << "25:getCallTransferInfo\n"
1661               << "26:setCallTransferInfo\n"
1662               << "27:CanSetCallTransferTime\n"
1663               << "61:setCallRestrictionPassword\n";
1664 }
1665 
PrintfCallConferenceExInterface()1666 void PrintfCallConferenceExInterface()
1667 {
1668     std::cout << "28:GetMainCallId\n"
1669               << "29:GetSubCallIdList\n"
1670               << "30:GetCallIdListForConference\n";
1671 }
1672 
PrintfCallMultimediaInterface()1673 void PrintfCallMultimediaInterface()
1674 {
1675     std::cout << "31:SetMute\n"
1676               << "32:MuteRinger\n"
1677               << "33:SetAudioDevice\n"
1678               << "34:ControlCamera\n"
1679               << "35:SetPreviewWindow\n"
1680               << "36:SetDisplayWindow\n"
1681               << "37:SetCameraZoom\n"
1682               << "38:SetPausePicture\n"
1683               << "39:SetDeviceDirection\n"
1684               << "40:SetCallPreferenceMode\n"
1685               << "41:GetImsConfig\n"
1686               << "42:SetImsConfig\n"
1687               << "43:GetImsNetworkValue\n"
1688               << "44:SetImsNetworkValue\n"
1689               << "45:UpdateImsCallMode\n"
1690               << "46:EnableImsSwitch\n"
1691               << "47:DisableImsSwitch\n"
1692               << "48:IsImsSwitchEnabled\n"
1693               << "49:StartRtt\n"
1694               << "50:StopRtt\n"
1695               << "57:InputDialerSpecialCode\n"
1696               << "59:SetVoNRState\n"
1697               << "60:GetVoNRState\n"
1698               << "62:CancelCallUpgrade\n"
1699               << "63:RequestCameraCapabilities\n"
1700               << "93:InitPermission\n"
1701               << "94:VerifyPermission\n"
1702               << "95:SendConnectBluetoothScoBroadcast\n"
1703               << "96:SendDisconnectBluetoothScoBroadcast\n"
1704               << "97:SubscribeCommonEvent\n"
1705               << "98:GetVolume\n"
1706               << "99:SetVolume\n"
1707               << "100:PlayRintone\n";
1708 }
1709 
PrintfUsage()1710 void PrintfUsage()
1711 {
1712     PrintfCallBasisInterface();
1713     PrintfCallUtilsInterface();
1714     PrintfCallConferenceInterface();
1715     PrintfCallDtmfInterface();
1716     PrintfCallSupplementInterface();
1717     PrintfCallConferenceExInterface();
1718     PrintfCallMultimediaInterface();
1719     std::cout << "1000:exit\n";
1720 }
1721 
MainExit()1722 int32_t MainExit()
1723 {
1724     if (OHOS::Telephony::g_clientPtr == nullptr) {
1725         std::cout << "g_clientPtr is nullptr" << std::endl;
1726         return OHOS::Telephony::TELEPHONY_ERR_FAIL;
1727     }
1728     OHOS::Telephony::g_memberFuncMap.clear();
1729     OHOS::Telephony::g_clientPtr->UnInit();
1730     std::cout << "exit success" << std::endl;
1731     return OHOS::Telephony::TELEPHONY_SUCCESS;
1732 }
1733 
RunTest()1734 int32_t RunTest()
1735 {
1736     std::cout << "callManager test start...." << std::endl;
1737     int32_t interfaceNum = DEFAULT_VALUE;
1738     const int32_t exitNumber = 1000;
1739     const int32_t getVolumeNumber = 98;
1740     const int32_t setVolumeNumber = 99;
1741     const int32_t playRingtoneNumber = 100;
1742     if (Init() != TELEPHONY_SUCCESS) {
1743         std::cout << "callManager test init failed!" << std::endl;
1744         return TELEPHONY_SUCCESS;
1745     }
1746     while (true) {
1747         PrintfUsage();
1748         std::cin >> interfaceNum;
1749         if (interfaceNum == exitNumber) {
1750             std::cout << "start to exit now...." << std::endl;
1751             break;
1752         } else if (interfaceNum == playRingtoneNumber) {
1753             PlayRingtone();
1754             continue;
1755         } else if (interfaceNum == setVolumeNumber) {
1756             SetVolume();
1757             continue;
1758         } else if (interfaceNum == getVolumeNumber) {
1759             GetVolume();
1760             continue;
1761         }
1762         auto itFunc = g_memberFuncMap.find(interfaceNum);
1763         if (itFunc != g_memberFuncMap.end() && itFunc->second != nullptr) {
1764             auto memberFunc = itFunc->second;
1765             (*memberFunc)();
1766             continue;
1767         }
1768         std::cout << "err: invalid input!" << std::endl;
1769     }
1770     return MainExit();
1771 }
1772 } // namespace Telephony
1773 } // namespace OHOS
1774 
main()1775 int32_t main()
1776 {
1777     int32_t code = OHOS::Telephony::DEFAULT_VALUE;
1778     const int32_t exitCode = 1000;
1779     std::cout << "Please select interface type...." << std::endl;
1780     while (true) {
1781         std::cout << "1:callManager interface\n"
1782                   << "2:bluetooth call interface\n"
1783                   << "1000:exit\n";
1784         std::cin >> code;
1785         switch (code) {
1786             case static_cast<int32_t>(OHOS::Telephony::CallManagerInterfaceType::INTERFACE_CALL_MANAGER_TYPE):
1787                 OHOS::Telephony::RunTest();
1788                 OHOS::Telephony::MainExit();
1789                 break;
1790             case static_cast<int32_t>(OHOS::Telephony::CallManagerInterfaceType::INTERFACE_BLUETOOTH_CALL_TYPE): {
1791                 std::unique_ptr<OHOS::Telephony::BluetoothCallTest> testPtr =
1792                     std::make_unique<OHOS::Telephony::BluetoothCallTest>();
1793                 if (testPtr != nullptr) {
1794                     testPtr->Init();
1795                     testPtr->RunBluetoothCallTest();
1796                 }
1797                 break;
1798             }
1799             default:
1800                 std::cout << "invalid input" << std::endl;
1801                 break;
1802         }
1803         if (code == exitCode) {
1804             break;
1805         }
1806     }
1807     return OHOS::Telephony::TELEPHONY_SUCCESS;
1808 }
1809