• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "input/camera_manager.h"
23 #include "permission_kit.h"
24 #include "i_call_manager_service.h"
25 #include "call_manager_client.h"
26 
27 #include "audio_player.h"
28 #include "bluetooth_call_test.h"
29 #include "call_manager_inner_type.h"
30 #include "call_manager_errors.h"
31 #include "call_manager_callback_test.h"
32 #include "call_manager_test_types.h"
33 #include "common_event_subscriber_test.h"
34 
35 namespace OHOS {
36 namespace Telephony {
37 enum class CallManagerInterfaceType {
38     INTERFACE_CALL_MANAGER_TYPE = 1,
39     INTERFACE_BLUETOOTH_CALL_TYPE,
40 };
41 
42 std::shared_ptr<CallManagerClient> g_clientPtr = nullptr;
43 using CallManagerServiceFunc = void (*)();
44 std::map<uint32_t, CallManagerServiceFunc> g_memberFuncMap;
45 std::vector<Security::Permission::PermissionDef> permDefList;
46 
DialCall()47 void DialCall()
48 {
49     int32_t accountId = DEFAULT_ACCOUNT_ID;
50     int32_t videoState = DEFAULT_VIDEO_STATE;
51     int32_t dialScene = DEFAULT_DIAL_SCENE;
52     int32_t dialType = DEFAULT_DIAL_TYPE;
53     int32_t callType = DEFAULT_CALL_TYPE;
54     std::u16string phoneNumber;
55     std::string tmpStr;
56     AppExecFwk::PacMap dialInfo;
57     std::cout << "------Dial------" << std::endl;
58     std::cout << "please input phone number:" << std::endl;
59     phoneNumber.clear();
60     tmpStr.clear();
61     std::cin >> tmpStr;
62     phoneNumber = Str8ToStr16(tmpStr);
63     std::cout << "you want to call " << tmpStr << std::endl;
64     std::cout << "please input accountId:" << std::endl;
65     std::cin >> accountId;
66     std::cout << "please input videoState[0:audio,1:video]:" << std::endl;
67     std::cin >> videoState;
68     std::cout << "please input dialScene[0:normal,1:privileged,2:emergency]:" << std::endl;
69     std::cin >> dialScene;
70     std::cout << "please input dialType[0:carrier,1:voice mail,2:ott]:" << std::endl;
71     std::cin >> dialType;
72     std::cout << "please input callType[0:cs,1:ims,2:ott]:" << std::endl;
73     std::cin >> callType;
74 
75     dialInfo.PutIntValue("accountId", accountId);
76     dialInfo.PutIntValue("videoState", videoState);
77     dialInfo.PutIntValue("dialScene", dialScene);
78     dialInfo.PutIntValue("dialType", dialType);
79     dialInfo.PutIntValue("callType", callType);
80     if (g_clientPtr == nullptr) {
81         std::cout << "g_clientPtr is nullptr" << std::endl;
82         return;
83     }
84     int32_t ret = g_clientPtr->DialCall(phoneNumber, dialInfo);
85     std::cout << "return value:" << ret << std::endl;
86 }
87 
AnswerCall()88 void AnswerCall()
89 {
90     int32_t callId = DEFAULT_CALL_ID;
91     int32_t videoState = DEFAULT_VIDEO_STATE;
92     std::cout << "------Answer------" << std::endl;
93     std::cout << "please input callId:" << std::endl;
94     std::cin >> callId;
95     std::cout << "please input videoState[0:audio,1:video]:" << std::endl;
96     std::cin >> videoState;
97     int32_t ret = TELEPHONY_SUCCESS;
98     if (g_clientPtr == nullptr) {
99         std::cout << "g_clientPtr is nullptr" << std::endl;
100         return;
101     }
102     ret = g_clientPtr->AnswerCall(callId, videoState);
103     std::cout << "return value:" << ret << std::endl;
104 }
105 
RejectCall()106 void RejectCall()
107 {
108     int32_t callId = DEFAULT_CALL_ID;
109     int32_t boolValue = DEFAULT_VALUE;
110     bool flag = false;
111     std::u16string content;
112     std::string tmpStr;
113     content.clear();
114     std::cout << "------Reject------" << std::endl;
115     std::cout << "please input callId:" << std::endl;
116     std::cin >> callId;
117     std::cout << "Whether to enter the reason for rejection?[0:no,1:yes]:" << std::endl;
118     std::cin >> boolValue;
119     if (boolValue != DEFAULT_VALUE) {
120         flag = true;
121         std::cout << "please input reject message:" << std::endl;
122         tmpStr.clear();
123         std::cin >> tmpStr;
124         content = Str8ToStr16(tmpStr);
125     }
126     if (g_clientPtr == nullptr) {
127         std::cout << "g_clientPtr is nullptr" << std::endl;
128         return;
129     }
130     int32_t ret = g_clientPtr->RejectCall(callId, flag, content);
131     std::cout << "return value:" << ret << std::endl;
132 }
133 
HoldCall()134 void HoldCall()
135 {
136     int32_t callId = DEFAULT_CALL_ID;
137     std::cout << "------HoldCall------" << std::endl;
138     std::cout << "please input callId:" << std::endl;
139     std::cin >> callId;
140     if (g_clientPtr == nullptr) {
141         std::cout << "g_clientPtr is nullptr" << std::endl;
142         return;
143     }
144     int32_t ret = g_clientPtr->HoldCall(callId);
145     std::cout << "return value:" << ret << std::endl;
146 }
147 
UnHoldCall()148 void UnHoldCall()
149 {
150     int32_t callId = DEFAULT_CALL_ID;
151     std::cout << "------UnHoldCall------" << std::endl;
152     std::cout << "please input callId:" << std::endl;
153     std::cin >> callId;
154     if (g_clientPtr == nullptr) {
155         std::cout << "g_clientPtr is nullptr" << std::endl;
156         return;
157     }
158     int32_t ret = g_clientPtr->UnHoldCall(callId);
159     std::cout << "return value:" << ret << std::endl;
160 }
161 
HangUpCall()162 void HangUpCall()
163 {
164     int32_t callId = DEFAULT_CALL_ID;
165     std::cout << "------HangUpCall------" << std::endl;
166     std::cout << "please input callId:" << std::endl;
167     std::cin >> callId;
168     if (g_clientPtr == nullptr) {
169         std::cout << "g_clientPtr is nullptr" << std::endl;
170         return;
171     }
172     int32_t ret = g_clientPtr->HangUpCall(callId);
173     std::cout << "return value:" << ret << std::endl;
174 }
175 
CombineConference()176 void CombineConference()
177 {
178     int32_t mainCallId = DEFAULT_CALL_ID;
179     std::cout << "------CombineConference------" << std::endl;
180     std::cout << "please input mainCallId:" << std::endl;
181     std::cin >> mainCallId;
182     if (g_clientPtr == nullptr) {
183         std::cout << "g_clientPtr is nullptr" << std::endl;
184         return;
185     }
186     int32_t ret = g_clientPtr->CombineConference(mainCallId);
187     std::cout << "return value:" << ret << std::endl;
188 }
189 
SeparateConference()190 void SeparateConference()
191 {
192     int32_t callId = DEFAULT_CALL_ID;
193     std::cout << "------SeparateConference------" << std::endl;
194     std::cout << "please input callId:" << std::endl;
195     std::cin >> callId;
196     if (g_clientPtr == nullptr) {
197         std::cout << "g_clientPtr is nullptr" << std::endl;
198         return;
199     }
200     int32_t ret = g_clientPtr->SeparateConference(callId);
201     std::cout << "return value:" << ret << std::endl;
202 }
203 
GetCallState()204 void GetCallState()
205 {
206     std::cout << "------GetCallState------" << std::endl;
207     if (g_clientPtr == nullptr) {
208         std::cout << "g_clientPtr is nullptr" << std::endl;
209         return;
210     }
211     int32_t ret = g_clientPtr->GetCallState();
212     std::cout << "return value:" << ret << std::endl;
213 }
214 
SwitchCall()215 void SwitchCall()
216 {
217     int32_t callId = DEFAULT_CALL_ID;
218     std::cout << "------SwitchCall------" << std::endl;
219     std::cout << "please input callId:" << std::endl;
220     std::cin >> callId;
221     if (g_clientPtr == nullptr) {
222         std::cout << "g_clientPtr is nullptr" << std::endl;
223         return;
224     }
225     int32_t ret = g_clientPtr->SwitchCall(callId);
226     std::cout << "return value:" << ret << std::endl;
227 }
228 
HasCall()229 void HasCall()
230 {
231     std::cout << "------HasCall------" << std::endl;
232     if (g_clientPtr == nullptr) {
233         std::cout << "g_clientPtr is nullptr" << std::endl;
234         return;
235     }
236     int32_t ret = g_clientPtr->HasCall();
237     std::cout << "return value:" << ret << std::endl;
238 }
239 
IsNewCallAllowed()240 void IsNewCallAllowed()
241 {
242     std::cout << "------IsNewCallAllowed------" << std::endl;
243     if (g_clientPtr == nullptr) {
244         std::cout << "g_clientPtr is nullptr" << std::endl;
245         return;
246     }
247     int32_t ret = g_clientPtr->IsNewCallAllowed();
248     std::cout << "return value:" << ret << std::endl;
249 }
250 
IsRinging()251 void IsRinging()
252 {
253     std::cout << "------IsRinging------" << std::endl;
254     if (g_clientPtr == nullptr) {
255         std::cout << "g_clientPtr is nullptr" << std::endl;
256         return;
257     }
258     int32_t ret = g_clientPtr->IsRinging();
259     std::cout << "return value:" << ret << std::endl;
260 }
261 
IsInEmergencyCall()262 void IsInEmergencyCall()
263 {
264     std::cout << "------IsInEmergencyCall------" << std::endl;
265     if (g_clientPtr == nullptr) {
266         std::cout << "g_clientPtr is nullptr" << std::endl;
267         return;
268     }
269     int32_t ret = g_clientPtr->IsInEmergencyCall();
270     std::cout << "return value:" << ret << std::endl;
271 }
272 
StartDtmf()273 void StartDtmf()
274 {
275     char c = DEFAULT_VALUE;
276     int32_t callId = DEFAULT_CALL_ID;
277     std::cout << "please input StartDtmf callId:" << std::endl;
278     std::cin >> callId;
279     std::cout << "Please enter to send dtmf characters:" << std::endl;
280     std::cin >> c;
281     int32_t ret = g_clientPtr->StartDtmf(callId, c);
282     std::cout << "return value:" << ret << std::endl;
283 }
284 
StopDtmf()285 void StopDtmf()
286 {
287     int32_t callId = DEFAULT_CALL_ID;
288     std::cout << "please input StopDtmf callId:" << std::endl;
289     std::cin >> callId;
290     int32_t ret = g_clientPtr->StopDtmf(callId);
291     std::cout << "return value:" << ret << std::endl;
292 }
293 
GetCallWaiting()294 void GetCallWaiting()
295 {
296     int32_t slotId = SIM1_SLOTID;
297     std::cout << "------GetCallWaiting------" << std::endl;
298     std::cout << "please input slotId:" << std::endl;
299     std::cin >> slotId;
300     if (g_clientPtr == nullptr) {
301         std::cout << "g_clientPtr is nullptr" << std::endl;
302         return;
303     }
304     int32_t ret = g_clientPtr->GetCallWaiting(slotId);
305     std::cout << "return value:" << ret << std::endl;
306 }
307 
SetCallWaiting()308 void SetCallWaiting()
309 {
310     int32_t slotId = SIM1_SLOTID;
311     int32_t flag = DEFAULT_VALUE;
312     std::cout << "------SetCallWaiting------" << std::endl;
313     std::cout << "please input slotId:" << std::endl;
314     std::cin >> slotId;
315     std::cout << "whether open(0:no 1:yes):" << std::endl;
316     std::cin >> flag;
317     if (g_clientPtr == nullptr) {
318         std::cout << "g_clientPtr is nullptr" << std::endl;
319         return;
320     }
321     int32_t ret = g_clientPtr->SetCallWaiting(slotId, (flag == 1) ? true : false);
322     std::cout << "return value:" << ret << std::endl;
323 }
324 
GetCallRestriction()325 void GetCallRestriction()
326 {
327     int32_t slotId = SIM1_SLOTID;
328     int32_t tmpType = DEFAULT_VALUE;
329     CallRestrictionType type;
330     std::cout << "------GetCallRestriction------" << std::endl;
331     std::cout << "please input slotId:" << std::endl;
332     std::cin >> slotId;
333     std::cout << "please input restriction type:" << std::endl;
334     std::cin >> tmpType;
335     type = static_cast<CallRestrictionType>(tmpType);
336     if (g_clientPtr == nullptr) {
337         std::cout << "g_clientPtr is nullptr" << std::endl;
338         return;
339     }
340     int32_t ret = g_clientPtr->GetCallRestriction(slotId, type);
341     std::cout << "return value:" << ret << std::endl;
342 }
343 
SetCallRestriction()344 void SetCallRestriction()
345 {
346     int32_t slotId = SIM1_SLOTID;
347     int32_t tmpType = DEFAULT_VALUE;
348     CallRestrictionInfo info;
349     std::cout << "------SetCallRestriction------" << std::endl;
350     std::cout << "please input slotId:" << std::endl;
351     std::cin >> slotId;
352     std::cout << "please input restriction type:" << std::endl;
353     std::cin >> tmpType;
354     info.fac = static_cast<CallRestrictionType>(tmpType);
355     std::cout << "is open(1: open, 0: close):" << std::endl;
356     std::cin >> tmpType;
357     info.mode = static_cast<CallRestrictionMode>(tmpType);
358     std::cout << "please input password:" << std::endl;
359     std::cin >> info.password;
360     if (g_clientPtr == nullptr) {
361         std::cout << "g_clientPtr is nullptr" << std::endl;
362         return;
363     }
364     int32_t ret = g_clientPtr->SetCallRestriction(slotId, info);
365     std::cout << "return value:" << ret << std::endl;
366 }
367 
SetCallPreferenceMode()368 void SetCallPreferenceMode()
369 {
370     int32_t slotId = SIM1_SLOTID;
371     int32_t mode = DEFAULT_PREFERENCEMODE;
372     std::cout << "------CallPreferenceMode------" << std::endl;
373     std::cout << "please input slotId:" << std::endl;
374     std::cin >> slotId;
375     std::cout << "please input PreferenceMode:" << std::endl;
376     std::cout << "CS_VOICE_ONLY = 1" << std::endl;
377     std::cout << "CS_VOICE_PREFERRED = 2" << std::endl;
378     std::cout << "IMS_PS_VOICE_PREFERRED = 3" << std::endl;
379     std::cout << "IMS_PS_VOICE_ONLY = 4" << std::endl;
380     std::cin >> mode;
381     if (g_clientPtr == nullptr) {
382         std::cout << "g_clientPtr is nullptr" << std::endl;
383         return;
384     }
385     int32_t ret = g_clientPtr->SetCallPreferenceMode(slotId, mode);
386     std::cout << "return value:" << ret << std::endl;
387 }
388 
GetCallTransferInfo()389 void GetCallTransferInfo()
390 {
391     int32_t slotId = SIM1_SLOTID;
392     int32_t tmpType = DEFAULT_VALUE;
393     CallTransferType type;
394     std::cout << "------GetCallTransferInfo------" << std::endl;
395     std::cout << "please input slotId:" << std::endl;
396     std::cin >> slotId;
397     std::cout << "please input transfer type:" << std::endl;
398     std::cin >> tmpType;
399     type = static_cast<CallTransferType>(tmpType);
400     if (g_clientPtr == nullptr) {
401         std::cout << "g_clientPtr is nullptr" << std::endl;
402         return;
403     }
404     int32_t ret = g_clientPtr->GetCallTransferInfo(slotId, type);
405     std::cout << "return value:" << ret << std::endl;
406 }
407 
SetCallTransferInfo()408 void SetCallTransferInfo()
409 {
410     int32_t slotId = SIM1_SLOTID;
411     int32_t tmpType = DEFAULT_VALUE;
412     CallTransferInfo info;
413     std::cout << "------SetCallTransferInfo------" << std::endl;
414     std::cout << "please input slotId:" << std::endl;
415     std::cin >> slotId;
416     std::cout << "please input transfer type:" << std::endl;
417     std::cin >> tmpType;
418     info.type = static_cast<CallTransferType>(tmpType);
419     std::cout << "please input transfer setting type:" << std::endl;
420     std::cin >> tmpType;
421     info.settingType = static_cast<CallTransferSettingType>(tmpType);
422     std::cout << "please input phone number:" << std::endl;
423     std::cin >> info.transferNum;
424     if (g_clientPtr == nullptr) {
425         std::cout << "g_clientPtr is nullptr" << std::endl;
426         return;
427     }
428     int32_t ret = g_clientPtr->SetCallTransferInfo(slotId, info);
429     std::cout << "return value:" << ret << std::endl;
430 }
431 
IsEmergencyPhoneNumber()432 void IsEmergencyPhoneNumber()
433 {
434     int32_t slotId = SIM1_SLOTID;
435     int32_t errorCode = TELEPHONY_ERROR;
436     std::u16string phoneNumber;
437     std::string tmpStr;
438     std::cout << "------IsEmergencyPhoneNumber------" << std::endl;
439     std::cout << "please input phone number:" << std::endl;
440     phoneNumber.clear();
441     tmpStr.clear();
442     std::cin >> tmpStr;
443     phoneNumber = Str8ToStr16(tmpStr);
444     std::cout << "The number is " << tmpStr << std::endl;
445     std::cout << "please input slotId:" << std::endl;
446     std::cin >> slotId;
447     if (g_clientPtr == nullptr) {
448         std::cout << "g_clientPtr is nullptr" << std::endl;
449         return;
450     }
451     int32_t ret = g_clientPtr->IsEmergencyPhoneNumber(phoneNumber, slotId, errorCode);
452     std::cout << "return value:" << ret << std::endl;
453     std::cout << "return errorCode:" << errorCode << std::endl;
454 }
455 
FormatPhoneNumber()456 void FormatPhoneNumber()
457 {
458     std::u16string phoneNumber;
459     std::u16string countryCode;
460     std::u16string formatNumber;
461     std::string tmpStr;
462     std::cout << "------FormatPhoneNumber------" << std::endl;
463     std::cout << "please input phone number:" << std::endl;
464     phoneNumber.clear();
465     countryCode.clear();
466     formatNumber.clear();
467     tmpStr.clear();
468     std::cin >> tmpStr;
469     phoneNumber = Str8ToStr16(tmpStr);
470     std::cout << "The number is " << tmpStr << std::endl;
471     tmpStr.clear();
472     std::cout << "please input countryCode:" << std::endl;
473     std::cin >> tmpStr;
474     countryCode = Str8ToStr16(tmpStr);
475     if (g_clientPtr == nullptr) {
476         std::cout << "g_clientPtr is nullptr" << std::endl;
477         return;
478     }
479     int32_t ret = g_clientPtr->FormatPhoneNumber(phoneNumber, countryCode, formatNumber);
480     std::cout << "return value:" << ret << std::endl;
481     std::cout << "return number:" << Str16ToStr8(formatNumber) << std::endl;
482 }
483 
FormatPhoneNumberToE164()484 void FormatPhoneNumberToE164()
485 {
486     std::u16string phoneNumber;
487     std::u16string countryCode;
488     std::u16string formatNumber;
489     std::string tmpStr;
490     std::cout << "------FormatPhoneNumberToE164------" << std::endl;
491     std::cout << "please input phone number:" << std::endl;
492     phoneNumber.clear();
493     countryCode.clear();
494     formatNumber.clear();
495     tmpStr.clear();
496     std::cin >> tmpStr;
497     phoneNumber = Str8ToStr16(tmpStr);
498     std::cout << "The number is " << tmpStr << std::endl;
499     tmpStr.clear();
500     std::cout << "please input countryCode:" << std::endl;
501     std::cin >> tmpStr;
502     countryCode = Str8ToStr16(tmpStr);
503     if (g_clientPtr == nullptr) {
504         std::cout << "g_clientPtr is nullptr" << std::endl;
505         return;
506     }
507     int32_t ret = g_clientPtr->FormatPhoneNumberToE164(phoneNumber, countryCode, formatNumber);
508     std::cout << "return value:" << ret << std::endl;
509     std::cout << "return number:" << Str16ToStr8(formatNumber) << std::endl;
510 }
511 
GetMainCallId()512 void GetMainCallId()
513 {
514     int callId = DEFAULT_CALL_ID;
515     std::cout << "please input callId:" << std::endl;
516     std::cin >> callId;
517     int32_t ret = g_clientPtr->GetMainCallId(callId);
518     std::cout << "return value:" << ret << std::endl;
519 }
520 
GetSubCallIdList()521 void GetSubCallIdList()
522 {
523     int32_t callId = DEFAULT_CALL_ID;
524     std::cout << "please input callId:" << std::endl;
525     std::cin >> callId;
526     std::vector<std::u16string> ret = g_clientPtr->GetSubCallIdList(callId);
527     std::vector<std::u16string>::iterator it = ret.begin();
528     for (; it != ret.end(); ++it) {
529         std::cout << "callId:" << Str16ToStr8(*it) << std::endl;
530     }
531 }
532 
GetCallIdListForConference()533 void GetCallIdListForConference()
534 {
535     int32_t callId = DEFAULT_CALL_ID;
536     std::cout << "please input callId:" << std::endl;
537     std::cin >> callId;
538     std::vector<std::u16string> ret = g_clientPtr->GetCallIdListForConference(callId);
539     std::vector<std::u16string>::iterator it = ret.begin();
540     for (; it != ret.end(); ++it) {
541         std::cout << "callId:" << Str16ToStr8(*it) << std::endl;
542     }
543 }
544 
InviteToConference()545 void InviteToConference()
546 {
547     int32_t callId = DEFAULT_CALL_ID;
548     std::cout << "please input callId:" << std::endl;
549     std::cin >> callId;
550     std::string number;
551     std::vector<std::u16string> numberList;
552     std::cout << "please input participate phone number:[-1]end" << std::endl;
553     while (std::cin >> number) {
554         numberList.push_back(Str8ToStr16(number));
555         if (number == "-1") {
556             break;
557         }
558     }
559     int32_t ret = g_clientPtr->JoinConference(callId, numberList);
560     std::cout << "return value:" << ret << std::endl;
561 }
562 
SetMute()563 void SetMute()
564 {
565     int32_t isMute = DEFAULT_VALUE;
566     std::cout << "------SetMute------" << std::endl;
567     std::cout << "please input mute state(0:false 1:true):" << std::endl;
568     std::cin >> isMute;
569     if (g_clientPtr == nullptr) {
570         std::cout << "g_clientPtr is nullptr" << std::endl;
571         return;
572     }
573     int32_t ret = g_clientPtr->SetMuted((isMute == 1) ? true : false);
574     std::cout << "return value:" << ret << std::endl;
575 }
576 
MuteRinger()577 void MuteRinger()
578 {
579     std::cout << "------MuteRinger------" << std::endl;
580     if (g_clientPtr == nullptr) {
581         std::cout << "g_clientPtr is nullptr" << std::endl;
582         return;
583     }
584     int32_t ret = g_clientPtr->MuteRinger();
585     std::cout << "return value:" << ret << std::endl;
586 }
587 
SetAudioDevice()588 void SetAudioDevice()
589 {
590     int32_t deviceType = DEFAULT_VALUE;
591     std::cout << "------SetAudioDevice------" << std::endl;
592     std::cout << "please input device type(0:earpiece 1:speaker 2:wired headset 3:bluetooth sco):" << std::endl;
593     std::cin >> deviceType;
594     if (g_clientPtr == nullptr) {
595         std::cout << "g_clientPtr is nullptr" << std::endl;
596         return;
597     }
598     AudioDevice device = AudioDevice::DEVICE_UNKNOWN;
599     device = static_cast<AudioDevice>(deviceType);
600     int32_t ret = g_clientPtr->SetAudioDevice(device);
601     std::cout << "return value:" << ret << std::endl;
602 }
603 
GetVolume()604 void GetVolume()
605 {
606     int32_t type = DEFAULT_VALUE;
607     std::cout << "------GetVolume------" << std::endl;
608     std::cout << "please input volume type(3:ring 4:music)" << std::endl;
609     std::cin >> type;
610     AudioStandard::AudioSystemManager::AudioVolumeType volumeType =
611         AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_MUSIC;
612     switch (type) {
613         case AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_RING:
614             volumeType = AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_RING;
615             break;
616         case AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_MUSIC:
617             volumeType = AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_MUSIC;
618             break;
619         default:
620             break;
621     }
622     AudioStandard::AudioSystemManager *audioSystemMgr = AudioStandard::AudioSystemManager::GetInstance();
623     int32_t ret = audioSystemMgr->GetVolume(volumeType);
624     std::cout << "return value:" << ret << std::endl;
625 }
626 
SetVolume()627 void SetVolume()
628 {
629     int32_t volume = DEFAULT_VALUE;
630     int32_t type = DEFAULT_VALUE;
631     std::cout << "------SetVolume------" << std::endl;
632     std::cout << "please input volume value(0~15) :" << std::endl;
633     std::cin >> volume;
634     std::cout << "please input volume type(3:ring 4:music)" << std::endl;
635     std::cin >> type;
636     if (volume < MIN_VOLUME || volume > MAX_VOLUME) {
637         std::cout << "volume value error" << std::endl;
638         return;
639     }
640     AudioStandard::AudioSystemManager::AudioVolumeType volumeType =
641         AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_MUSIC;
642     switch (type) {
643         case AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_RING:
644             volumeType = AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_RING;
645             break;
646         case AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_MUSIC:
647             volumeType = AudioStandard::AudioSystemManager::AudioVolumeType::STREAM_MUSIC;
648             break;
649         default:
650             break;
651     }
652     AudioStandard::AudioSystemManager *audioSystemMgr = AudioStandard::AudioSystemManager::GetInstance();
653     int32_t ret = audioSystemMgr->SetVolume(volumeType, volume);
654     std::cout << "return value:" << ret << std::endl;
655 }
656 
InitRenderer(const std::unique_ptr<AudioStandard::AudioRenderer> & audioRenderer,const wav_hdr & wavHeader)657 bool InitRenderer(const std::unique_ptr<AudioStandard::AudioRenderer> &audioRenderer, const wav_hdr &wavHeader)
658 {
659     AudioStandard::AudioRendererParams rendererParams;
660     rendererParams.sampleFormat = static_cast<AudioStandard::AudioSampleFormat>(wavHeader.bitsPerSample);
661     rendererParams.sampleRate = static_cast<AudioStandard::AudioSamplingRate>(wavHeader.SamplesPerSec);
662     rendererParams.channelCount = static_cast<AudioStandard::AudioChannel>(wavHeader.NumOfChan);
663     rendererParams.encodingType = static_cast<AudioStandard::AudioEncodingType>(AudioStandard::ENCODING_PCM);
664     if (audioRenderer->SetParams(rendererParams) != TELEPHONY_SUCCESS) {
665         std::cout << "audio renderer set params error" << std::endl;
666         if (!audioRenderer->Release()) {
667             std::cout << "audio renderer release error" << std::endl;
668         }
669         return false;
670     }
671     if (!audioRenderer->Start()) {
672         std::cout << "audio renderer start error" << std::endl;
673         return false;
674     }
675     uint32_t frameCount;
676     if (audioRenderer->GetFrameCount(frameCount)) {
677         return false;
678     }
679     std::cout << "frame count : " << frameCount << std::endl;
680     return true;
681 }
682 
PlayRingtone()683 bool PlayRingtone()
684 {
685     wav_hdr wavHeader;
686     std::cout << "please input ringtone file path : " << std::endl;
687     char path[RING_PATH_MAX_LENGTH];
688     std::cin >> path;
689     FILE *wavFile = fopen(path, "rb");
690     if (wavFile == nullptr) {
691         std::cout << "wav file nullptr" << std::endl;
692         return false;
693     }
694     (void)fread(&wavHeader, READ_SIZE, sizeof(wav_hdr), wavFile);
695     std::unique_ptr<AudioStandard::AudioRenderer> audioRenderer =
696         AudioStandard::AudioRenderer::Create(AudioStandard::AudioStreamType::STREAM_MUSIC);
697     if (!InitRenderer(audioRenderer, wavHeader)) {
698         (void)fclose(wavFile);
699         return false;
700     }
701     size_t bufferLen, bytesToWrite = DEFAULT_SIZE, bytesWritten = DEFAULT_SIZE;
702     if (audioRenderer->GetBufferSize(bufferLen)) {
703         (void)fclose(wavFile);
704         return false;
705     }
706     std::unique_ptr<uint8_t> buffer = std::make_unique<uint8_t>(bufferLen + bufferLen);
707     if (buffer == nullptr) {
708         std::cout << "malloc memory nullptr" << std::endl;
709         (void)fclose(wavFile);
710         return false;
711     }
712     while (!feof(wavFile)) {
713         bytesToWrite = fread(buffer.get(), READ_SIZE, bufferLen, wavFile);
714         bytesWritten = DEFAULT_SIZE;
715         while ((bytesWritten < bytesToWrite) && ((bytesToWrite - bytesWritten) > MIN_BYTES)) {
716             bytesWritten += audioRenderer->Write(buffer.get() + bytesWritten, bytesToWrite - bytesWritten);
717         }
718     }
719     audioRenderer->Flush();
720     audioRenderer->Drain();
721     audioRenderer->Stop();
722     audioRenderer->Release();
723     (void)fclose(wavFile);
724     std::cout << "audio renderer plackback done" << std::endl;
725     return true;
726 }
727 
ControlCamera()728 void ControlCamera()
729 {
730     std::cout << "------ControlCamera test------" << std::endl;
731     std::string tmpStr = "";
732     sptr<CameraStandard::CameraManager> camManagerObj = CameraStandard::CameraManager::GetInstance();
733     std::vector<sptr<CameraStandard::CameraInfo>> cameraObjList = camManagerObj->GetCameras();
734 
735     for (auto &it : cameraObjList) {
736         tmpStr = it->GetID();
737         std::cout << "camManagerObj->GetCameras Camera ID:" << tmpStr.c_str() << std::endl;
738         break;
739     }
740 
741     std::u16string CameraID;
742     CameraID.clear();
743     CameraID = Str8ToStr16(tmpStr);
744     int32_t ret = g_clientPtr->ControlCamera(CameraID);
745     std::cout << "ok return value:" << ret << std::endl;
746 
747     std::cout << "ControlCamera done" << std::endl;
748 }
749 
SetPreviewWindow()750 void SetPreviewWindow()
751 {
752     std::cout << "------SetPreviewWindow test------" << std::endl;
753     VideoWindow window;
754     window.x = WINDOWS_X_START;
755     window.y = WINDOWS_Y_START;
756     window.z = WINDOWS_Z_ERROR;
757     window.width = WINDOWS_WIDTH;
758     window.height = WINDOWS_HEIGHT;
759     int32_t ret = g_clientPtr->SetPreviewWindow(window);
760     std::cout << "error return value:" << ret << std::endl;
761 
762     window.z = WINDOWS_Z_BOTTOM;
763     ret = g_clientPtr->SetPreviewWindow(window);
764     std::cout << "return value:" << ret << std::endl;
765 
766     window.z = WINDOWS_Z_TOP;
767     ret = g_clientPtr->SetPreviewWindow(window);
768     std::cout << "return value:" << ret << std::endl;
769 
770     std::cout << "SetPreviewWindow done" << std::endl;
771 }
772 
SetDisplayWindow()773 void SetDisplayWindow()
774 {
775     std::cout << "------SetDisplayWindow test------" << std::endl;
776     VideoWindow window;
777     window.x = WINDOWS_X_START;
778     window.y = WINDOWS_Y_START;
779     window.z = WINDOWS_WIDTH;
780     window.width = WINDOWS_WIDTH;
781     window.height = WINDOWS_HEIGHT;
782     int32_t ret = g_clientPtr->SetDisplayWindow(window);
783     std::cout << "error return value:" << ret << std::endl;
784 
785     window.z = WINDOWS_Z_TOP;
786     ret = g_clientPtr->SetDisplayWindow(window);
787     std::cout << "ok return value:" << ret << std::endl;
788 
789     window.z = WINDOWS_Z_BOTTOM;
790     ret = g_clientPtr->SetDisplayWindow(window);
791     std::cout << "ok return value:" << ret << std::endl;
792 
793     std::cout << "SetDisplayWindow done" << std::endl;
794 }
795 
SetCameraZoom()796 void SetCameraZoom()
797 {
798     const float CameraZoomMax = 12.0;
799     const float CameraZoomMin = -0.1;
800     const float CameraZoom = 2.0;
801     std::cout << "------SetCameraZoom test------" << std::endl;
802     int32_t ret = g_clientPtr->SetCameraZoom(CameraZoomMax);
803     std::cout << "return value:" << ret << std::endl;
804 
805     ret = g_clientPtr->SetCameraZoom(CameraZoomMin);
806     std::cout << "return value:" << ret << std::endl;
807 
808     ret = g_clientPtr->SetCameraZoom(CameraZoom);
809     std::cout << "return value:" << ret << std::endl;
810     std::cout << "SetCameraZoom done" << std::endl;
811 }
812 
SetPausePicture()813 void SetPausePicture()
814 {
815     std::cout << "------SetPausePicture test------" << std::endl;
816     std::u16string path;
817     std::string tmpStr = "/system/bin/1.png";
818     path.clear();
819     path = Str8ToStr16(tmpStr);
820     int32_t ret = g_clientPtr->SetPausePicture(path);
821     std::cout << "\n return value:" << ret << std::endl;
822     std::cout << "SetPausePicture done" << std::endl;
823 }
824 
SetDeviceDirection()825 void SetDeviceDirection()
826 {
827     const int32_t DeviceDirectionError1 = 50;
828     const int32_t DeviceDirectionError2 = 350;
829     const int32_t DeviceDirection90 = 90;
830     std::cout << "------SetDeviceDirection test------" << std::endl;
831     int32_t ret = g_clientPtr->SetDeviceDirection(DeviceDirectionError1);
832     std::cout << "\n return value:" << ret << std::endl;
833 
834     ret = g_clientPtr->SetDeviceDirection(DeviceDirectionError2);
835     std::cout << "\n return value:" << ret << std::endl;
836 
837     ret = g_clientPtr->SetDeviceDirection(DeviceDirection90);
838     std::cout << "\n return value:" << ret << std::endl;
839     std::cout << "SetDeviceDirection done" << std::endl;
840 }
841 
SubscribeCommonEvent()842 void SubscribeCommonEvent()
843 {
844     std::cout << "------SubscribeCommonEvent------" << std::endl;
845     std::cout << "please input common event type : " << std::endl;
846     char eventType[RING_PATH_MAX_LENGTH];
847     std::cin >> eventType;
848     OHOS::EventFwk::MatchingSkills matchingSkills;
849     std::string event(eventType);
850     matchingSkills.AddEvent(event);
851     // make subcriber info
852     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
853     // make a subcriber object
854     std::shared_ptr<CommonEventSubscriberTest> subscriberTest =
855         std::make_shared<CommonEventSubscriberTest>(subscriberInfo);
856     if (subscriberTest == nullptr) {
857         std::cout << "subscriber nullptr" << std::endl;
858     }
859     // subscribe a common event
860     bool result = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
861     std::cout << "subscribe common event : " << eventType << ", result : " << result << std::endl;
862 }
863 
GetImsConfig()864 void GetImsConfig()
865 {
866     int32_t slotId = SIM1_SLOTID;
867     int32_t item = DEFAULT_ITEM_VALUE;
868     std::cout << "------GetImsConfig------" << std::endl;
869     std::cout << "please input slotId:" << std::endl;
870     std::cin >> slotId;
871     std::cout << "please input item:" << std::endl;
872     std::cin >> item;
873     int32_t ret = TELEPHONY_SUCCESS;
874     if (g_clientPtr == nullptr) {
875         std::cout << "g_clientPtr is nullptr" << std::endl;
876         return;
877     }
878     ret = g_clientPtr->GetImsConfig(slotId, static_cast<ImsConfigItem>(item));
879     std::cout << "return value:" << ret << std::endl;
880 }
881 
SetImsConfig()882 void SetImsConfig()
883 {
884     int32_t slotId = SIM1_SLOTID;
885     int32_t item = DEFAULT_ITEM_VALUE;
886     std::string tmpValue;
887     std::u16string value;
888     std::cout << "------SetImsConfig------" << std::endl;
889     std::cout << "please input slotId:" << std::endl;
890     std::cin >> slotId;
891     std::cout << "please input item:" << std::endl;
892     std::cin >> item;
893     std::cout << "please input item value:" << std::endl;
894     std::cin >> tmpValue;
895     int32_t ret = TELEPHONY_SUCCESS;
896     if (g_clientPtr == nullptr) {
897         std::cout << "g_clientPtr is nullptr" << std::endl;
898         return;
899     }
900     value = Str8ToStr16(tmpValue);
901     ret = g_clientPtr->SetImsConfig(slotId, static_cast<ImsConfigItem>(item), value);
902     std::cout << "return value:" << ret << std::endl;
903 }
904 
GetImsFeatureValue()905 void GetImsFeatureValue()
906 {
907     int32_t slotId = SIM1_SLOTID;
908     int32_t tmpType = FeatureType::TYPE_VOICE_OVER_LTE;
909     FeatureType type = FeatureType::TYPE_VOICE_OVER_LTE;
910     std::cout << "------GetImsFeatureValue------" << std::endl;
911     std::cout << "please input slotId:" << std::endl;
912     std::cin >> slotId;
913     std::cout << "please input feature type:" << std::endl;
914     std::cin >> tmpType;
915     type = static_cast<FeatureType>(tmpType);
916     int32_t ret = TELEPHONY_SUCCESS;
917     if (g_clientPtr == nullptr) {
918         std::cout << "g_clientPtr is nullptr" << std::endl;
919         return;
920     }
921     ret = g_clientPtr->GetImsFeatureValue(slotId, type);
922     std::cout << "return value:" << ret << std::endl;
923 }
924 
SetImsFeatureValue()925 void SetImsFeatureValue()
926 {
927     int32_t slotId = SIM1_SLOTID;
928     int32_t tmpType = FeatureType::TYPE_VOICE_OVER_LTE;
929     FeatureType type;
930     int32_t value = DEFAULT_NET_TYPE;
931     std::cout << "------SetImsNetworkValue------" << std::endl;
932     std::cout << "please input slotId:" << std::endl;
933     std::cin >> slotId;
934     std::cout << "please input feature type:" << std::endl;
935     std::cin >> tmpType;
936     type = (FeatureType)tmpType;
937     std::cout << "please input value:" << std::endl;
938     std::cin >> value;
939     int32_t ret = TELEPHONY_SUCCESS;
940     if (g_clientPtr == nullptr) {
941         std::cout << "g_clientPtr is nullptr" << std::endl;
942         return;
943     }
944     ret = g_clientPtr->SetImsFeatureValue(slotId, type, value);
945     std::cout << "return value:" << ret << std::endl;
946 }
947 
UpdateImsCallMode()948 void UpdateImsCallMode()
949 {
950     int32_t callId = DEFAULT_CALL_ID;
951     uint32_t mediaMode = DEFAULT_VIDEO_STATE;
952     std::cout << "------UpdateImsCallMode------" << std::endl;
953     std::cout << "please input callId:" << std::endl;
954     std::cin >> callId;
955     std::cout << "please input media mode[0:voice, 3:video]:" << std::endl;
956     std::cin >> mediaMode;
957     ImsCallMode mode = static_cast<ImsCallMode>(mediaMode);
958     int32_t ret = TELEPHONY_SUCCESS;
959     if (g_clientPtr == nullptr) {
960         std::cout << "g_clientPtr is nullptr" << std::endl;
961         return;
962     }
963     ret = g_clientPtr->UpdateImsCallMode(callId, mode);
964     std::cout << "return value:" << ret << std::endl;
965 }
966 
EnableImsSwitch()967 void EnableImsSwitch()
968 {
969     int32_t slotId = SIM1_SLOTID;
970     std::cout << "------EnableImsSwitch------" << std::endl;
971     std::cout << "please input slot id:" << std::endl;
972     std::cin >> slotId;
973     int32_t ret = TELEPHONY_SUCCESS;
974     if (g_clientPtr == nullptr) {
975         std::cout << "g_clientPtr is nullptr" << std::endl;
976         return;
977     }
978     ret = g_clientPtr->EnableImsSwitch(slotId);
979     std::cout << "return value:" << ret << std::endl;
980 }
981 
DisableImsSwitch()982 void DisableImsSwitch()
983 {
984     int32_t slotId = SIM1_SLOTID;
985     std::cout << "------DisableImsSwitch------" << std::endl;
986     std::cout << "please input slot id:" << std::endl;
987     std::cin >> slotId;
988     int32_t ret = TELEPHONY_SUCCESS;
989     if (g_clientPtr == nullptr) {
990         std::cout << "g_clientPtr is nullptr" << std::endl;
991         return;
992     }
993     ret = g_clientPtr->DisableImsSwitch(slotId);
994     std::cout << "return value:" << ret << std::endl;
995 }
996 
IsImsSwitchEnabled()997 void IsImsSwitchEnabled()
998 {
999     int32_t slotId = SIM1_SLOTID;
1000     std::cout << "------IsImsSwitchEnabled------" << std::endl;
1001     std::cout << "please input slot id:" << std::endl;
1002     std::cin >> slotId;
1003     int32_t ret = TELEPHONY_SUCCESS;
1004     if (g_clientPtr == nullptr) {
1005         std::cout << "g_clientPtr is nullptr" << std::endl;
1006         return;
1007     }
1008     ret = g_clientPtr->IsImsSwitchEnabled(slotId);
1009     std::cout << "return value:" << ret << std::endl;
1010 }
1011 
EnableLteEnhanceMode()1012 void EnableLteEnhanceMode()
1013 {
1014     int32_t slotId = SIM1_SLOTID;
1015     std::cout << "------EnableLteEnhanceMode------" << std::endl;
1016     std::cout << "please input slot id:" << std::endl;
1017     std::cin >> slotId;
1018     int32_t ret = TELEPHONY_SUCCESS;
1019     if (g_clientPtr == nullptr) {
1020         std::cout << "g_clientPtr is nullptr" << std::endl;
1021         return;
1022     }
1023     ret = g_clientPtr->EnableLteEnhanceMode(slotId);
1024     std::cout << "return value:" << ret << std::endl;
1025 }
1026 
DisableLteEnhanceMode()1027 void DisableLteEnhanceMode()
1028 {
1029     int slotId = SIM1_SLOTID;
1030     std::cout << "------DisableLteEnhanceMode------" << std::endl;
1031     std::cout << "please input slot id:" << std::endl;
1032     std::cin >> slotId;
1033     int32_t ret = TELEPHONY_SUCCESS;
1034     if (g_clientPtr == nullptr) {
1035         std::cout << "g_clientPtr is nullptr" << std::endl;
1036         return;
1037     }
1038     ret = g_clientPtr->DisableLteEnhanceMode(slotId);
1039     std::cout << "return value:" << ret << std::endl;
1040 }
1041 
IsLteEnhanceModeEnabled()1042 void IsLteEnhanceModeEnabled()
1043 {
1044     int32_t slotId = SIM1_SLOTID;
1045     std::cout << "------IsLteEnhanceModeEnabled------" << std::endl;
1046     std::cout << "please input slot id:" << std::endl;
1047     std::cin >> slotId;
1048     int32_t ret = TELEPHONY_SUCCESS;
1049     if (g_clientPtr == nullptr) {
1050         std::cout << "g_clientPtr is nullptr" << std::endl;
1051         return;
1052     }
1053     ret = g_clientPtr->IsLteEnhanceModeEnabled(slotId);
1054     std::cout << "return value:" << ret << std::endl;
1055 }
1056 
StartRtt()1057 void StartRtt()
1058 {
1059     int32_t callId = DEFAULT_CALL_ID;
1060     std::u16string msg;
1061     std::string tmpMsg;
1062     std::cout << "------StartRtt------" << std::endl;
1063     std::cout << "please input call id:" << std::endl;
1064     std::cin >> callId;
1065     std::cout << "please input Rtt msg:" << std::endl;
1066     msg.clear();
1067     tmpMsg.clear();
1068     std::cin >> tmpMsg;
1069     msg = Str8ToStr16(tmpMsg);
1070     if (g_clientPtr == nullptr) {
1071         std::cout << "g_clientPtr is nullptr" << std::endl;
1072         return;
1073     }
1074     int32_t ret = g_clientPtr->StartRtt(callId, msg);
1075     std::cout << "return value:" << ret << std::endl;
1076 }
1077 
StopRtt()1078 void StopRtt()
1079 {
1080     int32_t callId = DEFAULT_CALL_ID;
1081     std::cout << "------StopRtt------" << std::endl;
1082     std::cout << "please input call id:" << std::endl;
1083     std::cin >> callId;
1084     if (g_clientPtr == nullptr) {
1085         std::cout << "g_clientPtr is nullptr" << std::endl;
1086         return;
1087     }
1088     int32_t ret = g_clientPtr->StopRtt(callId);
1089     std::cout << "return value:" << ret << std::endl;
1090 }
1091 
AddPermission()1092 void AddPermission()
1093 {
1094     using namespace OHOS::Security::Permission;
1095     PermissionDef permissionDefAlpha = {.permissionName = TEST_PERMISSION_NAME_CAMERA,
1096         .bundleName = TEST_BUNDLE_NAME,
1097         .grantMode = GrantMode::USER_GRANT,
1098         .availableScope = AVAILABLE_SCOPE_ALL,
1099         .label = TEST_LABEL,
1100         .labelId = TEST_LABEL_ID,
1101         .description = TEST_DESCRIPTION,
1102         .descriptionId = TEST_DESCRIPTION_ID};
1103 
1104     PermissionDef permissionDefBeta = {.permissionName = TEST_PERMISSION_NAME_CAMERA,
1105         .bundleName = CALL_UI_BUNDLE_NAME,
1106         .grantMode = GrantMode::SYSTEM_GRANT,
1107         .availableScope = AVAILABLE_SCOPE_ALL,
1108         .label = TEST_LABEL,
1109         .labelId = TEST_LABEL_ID,
1110         .description = TEST_DESCRIPTION,
1111         .descriptionId = TEST_DESCRIPTION_ID};
1112 
1113     permDefList.emplace_back(permissionDefAlpha);
1114     permDefList.emplace_back(permissionDefBeta);
1115     PermissionKit::AddDefPermissions(permDefList);
1116 
1117     std::vector<std::string> permList;
1118     permList.push_back(TEST_PERMISSION_NAME_CAMERA);
1119     int32_t ret = PermissionKit::AddUserGrantedReqPermissions(TEST_BUNDLE_NAME, permList, TEST_USER_ID);
1120     std::cout << TEST_BUNDLE_NAME << " AddPermission AddUserGrantedReqPermissions return:" << ret << std::endl;
1121     ret = PermissionKit::GrantUserGrantedPermission(TEST_BUNDLE_NAME, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1122     std::cout << TEST_BUNDLE_NAME << " AddPermission GrantUserGrantedPermission return:" << ret << std::endl;
1123 
1124     ret = PermissionKit::AddUserGrantedReqPermissions(CALL_UI_BUNDLE_NAME, permList, TEST_USER_ID);
1125     std::cout << CALL_UI_BUNDLE_NAME << " AddPermission AddUserGrantedReqPermissions return:" << ret << std::endl;
1126     ret = PermissionKit::GrantUserGrantedPermission(CALL_UI_BUNDLE_NAME, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1127     std::cout << CALL_UI_BUNDLE_NAME << " AddPermission GrantUserGrantedPermission return:" << ret << std::endl;
1128 }
1129 
InitPermission()1130 void InitPermission()
1131 {
1132     using namespace OHOS::Security::Permission;
1133     std::cout << "------InitPermission------" << std::endl;
1134     int32_t ret = PermissionKit::VerifyPermission(TEST_BUNDLE_NAME, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1135     std::cout << "VerifyPermission return ret:" << ret << std::endl;
1136 
1137     int32_t retCallUI =
1138         PermissionKit::VerifyPermission(CALL_UI_BUNDLE_NAME, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1139     std::cout << "VerifyPermission return retCallUI:" << retCallUI << std::endl;
1140     if (ret != PermissionKitRet::RET_SUCCESS || retCallUI != PermissionKitRet::RET_SUCCESS) {
1141         AddPermission();
1142     }
1143 }
1144 
VerifyPermission()1145 void VerifyPermission()
1146 {
1147     using namespace OHOS::Security::Permission;
1148     std::cout << "------VerifyPermission------" << std::endl;
1149     int32_t ret = PermissionKit::VerifyPermission(TEST_BUNDLE_NAME, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1150     if (ret == PermissionKitRet::RET_SUCCESS) {
1151         std::cout << TEST_BUNDLE_NAME << " VerifyPermission success:" << ret << std::endl;
1152     } else {
1153         std::cout << TEST_BUNDLE_NAME << " VerifyPermission failed:" << ret << std::endl;
1154     }
1155 
1156     ret = PermissionKit::VerifyPermission(CALL_UI_BUNDLE_NAME, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1157     if (ret == PermissionKitRet::RET_SUCCESS) {
1158         std::cout << CALL_UI_BUNDLE_NAME << " VerifyPermission success:" << ret << std::endl;
1159     } else {
1160         std::cout << CALL_UI_BUNDLE_NAME << " VerifyPermission failed:" << ret << std::endl;
1161     }
1162 
1163     const std::string bundleName = "com.ohos.errorpkg";
1164     ret = PermissionKit::VerifyPermission(bundleName, TEST_PERMISSION_NAME_CAMERA, TEST_USER_ID);
1165     if (ret == PermissionKitRet::RET_SUCCESS) {
1166         std::cout << bundleName << " VerifyPermission success:" << ret << std::endl;
1167     } else {
1168         std::cout << bundleName << " VerifyPermission failed:" << ret << std::endl;
1169     }
1170 }
1171 
InitCallBasicPower()1172 void InitCallBasicPower()
1173 {
1174     g_memberFuncMap[OHOS::Telephony::INTERFACE_DIAL_CALL] = &OHOS::Telephony::DialCall;
1175     g_memberFuncMap[OHOS::Telephony::INTERFACE_ANSWER_CALL] = &OHOS::Telephony::AnswerCall;
1176     g_memberFuncMap[OHOS::Telephony::INTERFACE_REJECT_CALL] = &OHOS::Telephony::RejectCall;
1177     g_memberFuncMap[OHOS::Telephony::INTERFACE_HOLD_CALL] = &OHOS::Telephony::HoldCall;
1178     g_memberFuncMap[OHOS::Telephony::INTERFACE_UNHOLD_CALL] = &OHOS::Telephony::UnHoldCall;
1179     g_memberFuncMap[OHOS::Telephony::INTERFACE_DISCONNECT_CALL] = &OHOS::Telephony::HangUpCall;
1180     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_CALL_STATE] = &OHOS::Telephony::GetCallState;
1181     g_memberFuncMap[OHOS::Telephony::INTERFACE_SWAP_CALL] = &OHOS::Telephony::SwitchCall;
1182     g_memberFuncMap[OHOS::Telephony::INTERFACE_START_RTT] = &OHOS::Telephony::StartRtt;
1183     g_memberFuncMap[OHOS::Telephony::INTERFACE_STOP_RTT] = &OHOS::Telephony::StopRtt;
1184 }
1185 
InitCallUtils()1186 void InitCallUtils()
1187 {
1188     g_memberFuncMap[OHOS::Telephony::INTERFACE_HAS_CALL] = &OHOS::Telephony::HasCall;
1189     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_NEW_CALL_ALLOWED] = &OHOS::Telephony::IsNewCallAllowed;
1190     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_RINGING] = &OHOS::Telephony::IsRinging;
1191     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_EMERGENCY_CALL] = &OHOS::Telephony::IsInEmergencyCall;
1192     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_EMERGENCY_NUMBER] = &OHOS::Telephony::IsEmergencyPhoneNumber;
1193     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_FORMAT_NUMBER] = &OHOS::Telephony::FormatPhoneNumber;
1194     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_FORMAT_NUMBER_E164] = &OHOS::Telephony::FormatPhoneNumberToE164;
1195 }
1196 
InitCallConferencePower()1197 void InitCallConferencePower()
1198 {
1199     g_memberFuncMap[OHOS::Telephony::INTERFACE_COMBINE_CONFERENCE] = &OHOS::Telephony::CombineConference;
1200     g_memberFuncMap[OHOS::Telephony::INTERFACE_SEPARATE_CONFERENCE] = &OHOS::Telephony::SeparateConference;
1201 }
1202 
InitCallDtmfPower()1203 void InitCallDtmfPower()
1204 {
1205     g_memberFuncMap[OHOS::Telephony::INTERFACE_START_DTMF] = &OHOS::Telephony::StartDtmf;
1206     g_memberFuncMap[OHOS::Telephony::INTERFACE_STOP_DTMF] = &OHOS::Telephony::StopDtmf;
1207 }
1208 
InitCallSupplementPower()1209 void InitCallSupplementPower()
1210 {
1211     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_CALL_WAITING] = &OHOS::Telephony::GetCallWaiting;
1212     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_CALL_WAITING] = &OHOS::Telephony::SetCallWaiting;
1213     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_CALL_RESTRICTION] = &OHOS::Telephony::GetCallRestriction;
1214     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_CALL_RESTRICTION] = &OHOS::Telephony::SetCallRestriction;
1215     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_CALL_TRANSFER] = &OHOS::Telephony::GetCallTransferInfo;
1216     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_CALL_TRANSFER] = &OHOS::Telephony::SetCallTransferInfo;
1217     g_memberFuncMap[OHOS::Telephony::INTERFACE_SETCALL_PREFERENCEMODE] = &OHOS::Telephony::SetCallPreferenceMode;
1218 }
1219 
initCallConferenceExPower()1220 void initCallConferenceExPower()
1221 {
1222     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_MAINID] = &OHOS::Telephony::GetMainCallId;
1223     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_SUBCALL_LIST_ID] = &OHOS::Telephony::GetSubCallIdList;
1224     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_CALL_LIST_ID_FOR_CONFERENCE] =
1225         &OHOS::Telephony::GetCallIdListForConference;
1226     g_memberFuncMap[OHOS::Telephony::INTERFACE_JOIN_CONFERENCE] = &OHOS::Telephony::InviteToConference;
1227 }
1228 
InitCallMultimediaPower()1229 void InitCallMultimediaPower()
1230 {
1231     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_MUTE] = &OHOS::Telephony::SetMute;
1232     g_memberFuncMap[OHOS::Telephony::INTERFACE_MUTE_RINGER] = &OHOS::Telephony::MuteRinger;
1233     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_AUDIO_DEVICE] = &OHOS::Telephony::SetAudioDevice;
1234     g_memberFuncMap[OHOS::Telephony::INTERFACE_CTRL_CAMERA] = &OHOS::Telephony::ControlCamera;
1235     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_PREVIEW_WINDOW] = &OHOS::Telephony::SetPreviewWindow;
1236     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_DISPLAY_WINDOW] = &OHOS::Telephony::SetDisplayWindow;
1237     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_CAMERA_ZOOM] = &OHOS::Telephony::SetCameraZoom;
1238     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_PAUSE_IMAGE] = &OHOS::Telephony::SetPausePicture;
1239     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_DEVICE_DIRECTION] = &OHOS::Telephony::SetDeviceDirection;
1240     g_memberFuncMap[OHOS::Telephony::INTERFACE_UPDATE_CALL_MEDIA_MODE] = &OHOS::Telephony::UpdateImsCallMode;
1241 
1242     g_memberFuncMap[DEFINE_INIT_PERMISSIONS] = &OHOS::Telephony::InitPermission;
1243     g_memberFuncMap[DEFINE_VERIFY_PERMISSIONS] = &OHOS::Telephony::VerifyPermission;
1244 }
1245 
InitImsServicePower()1246 void InitImsServicePower()
1247 {
1248     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_IMS_CONFIG] = &OHOS::Telephony::GetImsConfig;
1249     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_IMS_CONFIG] = &OHOS::Telephony::SetImsConfig;
1250     g_memberFuncMap[OHOS::Telephony::INTERFACE_GET_IMS_FEATURE_VALUE] = &OHOS::Telephony::GetImsFeatureValue;
1251     g_memberFuncMap[OHOS::Telephony::INTERFACE_SET_IMS_FEATURE_VALUE] = &OHOS::Telephony::SetImsFeatureValue;
1252     g_memberFuncMap[OHOS::Telephony::INTERFACE_ENABLE_VOLTE] = &OHOS::Telephony::EnableImsSwitch;
1253     g_memberFuncMap[OHOS::Telephony::INTERFACE_DISABLE_VOLTE] = &OHOS::Telephony::DisableImsSwitch;
1254     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_VOLTE_ENABLED] = &OHOS::Telephony::IsImsSwitchEnabled;
1255     g_memberFuncMap[OHOS::Telephony::INTERFACE_ENABLE_LTE_ENHANCE_MODE] = &OHOS::Telephony::EnableLteEnhanceMode;
1256     g_memberFuncMap[OHOS::Telephony::INTERFACE_DISABLE_LTE_ENHANCE_MODE] = &OHOS::Telephony::DisableLteEnhanceMode;
1257     g_memberFuncMap[OHOS::Telephony::INTERFACE_IS_LTE_ENHANCE_MODE_ENABLED] =
1258         &OHOS::Telephony::IsLteEnhanceModeEnabled;
1259 }
1260 
Init()1261 int32_t Init()
1262 {
1263     g_clientPtr = DelayedSingleton<CallManagerClient>::GetInstance();
1264     if (g_clientPtr == nullptr) {
1265         std::cout << "g_clientPtr is nullptr" << std::endl;
1266         return TELEPHONY_ERROR;
1267     }
1268     g_clientPtr->Init(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
1269     std::unique_ptr<CallManagerCallbackTest> callbackPtr = std::make_unique<CallManagerCallbackTest>();
1270     if (callbackPtr == nullptr) {
1271         std::cout << "make_unique CallManagerCallbackTest failed!" << std::endl;
1272         return TELEPHONY_ERROR;
1273     }
1274     int32_t ret = g_clientPtr->RegisterCallBack(std::move(callbackPtr));
1275     if (ret != TELEPHONY_SUCCESS) {
1276         std::cout << "RegisterCallBack failed!" << std::endl;
1277         return TELEPHONY_ERROR;
1278     }
1279     std::cout << "RegisterCallBack success!" << std::endl;
1280     InitCallBasicPower();
1281     InitCallUtils();
1282     InitCallConferencePower();
1283     InitCallDtmfPower();
1284     InitCallSupplementPower();
1285     initCallConferenceExPower();
1286     InitCallMultimediaPower();
1287     InitImsServicePower();
1288     return TELEPHONY_SUCCESS;
1289 }
1290 
PrintfCallBasisInterface()1291 void PrintfCallBasisInterface()
1292 {
1293     std::cout << "\n\n-----------start--------------\n"
1294               << "usage:please input a cmd num:\n"
1295               << "2:dial\n"
1296               << "3:answer\n"
1297               << "4:reject\n"
1298               << "5:hold\n"
1299               << "6:unhold\n"
1300               << "7:hangUpCall\n"
1301               << "8:getCallState\n"
1302               << "9:switchCall\n";
1303 }
1304 
PrintfCallUtilsInterface()1305 void PrintfCallUtilsInterface()
1306 {
1307     std::cout << "10:hasCall\n"
1308               << "11:isNewCallAllowed\n"
1309               << "12:isRinging\n"
1310               << "13:isInEmergencyCall\n"
1311               << "14:isEmergencyPhoneNumber\n"
1312               << "15:formatPhoneNumber\n"
1313               << "16:formatPhoneNumberToE164\n";
1314 }
1315 
PrintfCallConferenceInterface()1316 void PrintfCallConferenceInterface()
1317 {
1318     std::cout << "17:combine conference\n"
1319               << "18:separate conference\n";
1320 }
1321 
PrintfCallDtmfInterface()1322 void PrintfCallDtmfInterface()
1323 {
1324     std::cout << "19:StartDtmf\n"
1325               << "20:StopDtmf\n";
1326 }
1327 
PrintfCallSupplementInterface()1328 void PrintfCallSupplementInterface()
1329 {
1330     std::cout << "21:getCallWaiting\n"
1331               << "22:setCallWaiting\n"
1332               << "23:getCallRestriction\n"
1333               << "24:setCallRestriction\n"
1334               << "25:getCallTransferInfo\n"
1335               << "26:setCallTransferInfo\n";
1336 }
1337 
PrintfCallConferenceExInterface()1338 void PrintfCallConferenceExInterface()
1339 {
1340     std::cout << "27:GetMainCallId\n"
1341               << "28:GetSubCallIdList\n"
1342               << "29:GetCallIdListForConference\n";
1343 }
1344 
PrintfCallMultimediaInterface()1345 void PrintfCallMultimediaInterface()
1346 {
1347     std::cout << "30:SetMute\n"
1348               << "31:MuteRinger\n"
1349               << "32:SetAudioDevice\n"
1350               << "33:ControlCamera\n"
1351               << "34:SetPreviewWindow\n"
1352               << "35:SetDisplayWindow\n"
1353               << "36:SetCameraZoom\n"
1354               << "37:SetPausePicture\n"
1355               << "38:SetDeviceDirection\n"
1356               << "39:SetCallPreferenceMode\n"
1357               << "40:GetImsConfig\n"
1358               << "41:SetImsConfig\n"
1359               << "42:GetImsNetworkValue\n"
1360               << "43:SetImsNetworkValue\n"
1361               << "44:UpdateImsCallMode\n"
1362               << "45:EnableImsSwitch\n"
1363               << "46:DisableImsSwitch\n"
1364               << "47:IsImsSwitchEnabled\n"
1365               << "48:EnableLteEnhanceMode\n"
1366               << "49:DisableLteEnhanceMode\n"
1367               << "50:IsLteEnhanceModeEnabled\n"
1368               << "51:StartRtt\n"
1369               << "52:StopRtt\n"
1370               << "93:InitPermission\n"
1371               << "94:VerifyPermission\n"
1372               << "95:SendConnectBluetoothScoBroadcast\n"
1373               << "96:SendDisconnectBluetoothScoBroadcast\n"
1374               << "97:SubscribeCommonEvent\n"
1375               << "98:GetVolume\n"
1376               << "99:SetVolume\n"
1377               << "100:PlayRintone\n";
1378 }
1379 
PrintfUsage()1380 void PrintfUsage()
1381 {
1382     PrintfCallBasisInterface();
1383     PrintfCallUtilsInterface();
1384     PrintfCallConferenceInterface();
1385     PrintfCallDtmfInterface();
1386     PrintfCallSupplementInterface();
1387     PrintfCallConferenceExInterface();
1388     PrintfCallMultimediaInterface();
1389     std::cout << "1000:exit\n";
1390 }
1391 
mainExit()1392 int32_t mainExit()
1393 {
1394     if (OHOS::Telephony::g_clientPtr == nullptr) {
1395         std::cout << "g_clientPtr is nullptr" << std::endl;
1396         return OHOS::Telephony::TELEPHONY_ERR_FAIL;
1397     }
1398     OHOS::Telephony::g_memberFuncMap.clear();
1399     OHOS::Telephony::g_clientPtr->UnInit();
1400     std::cout << "exit success" << std::endl;
1401     return OHOS::Telephony::TELEPHONY_SUCCESS;
1402 }
1403 
RunTest()1404 int32_t RunTest()
1405 {
1406     std::cout << "callManager test start...." << std::endl;
1407     int32_t interfaceNum = DEFAULT_VALUE;
1408     const int32_t exitNumber = 1000;
1409     const int32_t getVolumeNumber = 98;
1410     const int32_t setVolumeNumber = 99;
1411     const int32_t playRingtoneNumber = 100;
1412     if (Init() != TELEPHONY_SUCCESS) {
1413         std::cout << "callManager test init failed!" << std::endl;
1414         return TELEPHONY_SUCCESS;
1415     }
1416     while (true) {
1417         PrintfUsage();
1418         std::cin >> interfaceNum;
1419         if (interfaceNum == exitNumber) {
1420             std::cout << "start to exit now...." << std::endl;
1421             break;
1422         } else if (interfaceNum == playRingtoneNumber) {
1423             PlayRingtone();
1424             continue;
1425         } else if (interfaceNum == setVolumeNumber) {
1426             SetVolume();
1427             continue;
1428         } else if (interfaceNum == getVolumeNumber) {
1429             GetVolume();
1430             continue;
1431         }
1432         auto itFunc = g_memberFuncMap.find(interfaceNum);
1433         if (itFunc != g_memberFuncMap.end() && itFunc->second != nullptr) {
1434             auto memberFunc = itFunc->second;
1435             (*memberFunc)();
1436             continue;
1437         }
1438         std::cout << "err: invalid input!" << std::endl;
1439     }
1440     return mainExit();
1441 }
1442 } // namespace Telephony
1443 } // namespace OHOS
1444 
main()1445 int32_t main()
1446 {
1447     int32_t code = OHOS::Telephony::DEFAULT_VALUE;
1448     const int32_t exitCode = 1000;
1449     std::cout << "Please select interface type...." << std::endl;
1450     while (true) {
1451         std::cout << "1:callManager interface\n"
1452             << "2:bluetooth call interface\n"
1453             << "1000:exit\n";
1454         std::cin >> code;
1455         switch (code) {
1456             case static_cast<int32_t>(OHOS::Telephony::CallManagerInterfaceType::INTERFACE_CALL_MANAGER_TYPE):
1457                 OHOS::Telephony::RunTest();
1458                 OHOS::Telephony::mainExit();
1459                 break;
1460             case static_cast<int32_t>(OHOS::Telephony::CallManagerInterfaceType::INTERFACE_BLUETOOTH_CALL_TYPE): {
1461                 std::unique_ptr<OHOS::Telephony::BluetoothCallTest> testPtr =
1462                     std::make_unique<OHOS::Telephony::BluetoothCallTest>();
1463                 if (testPtr != nullptr) {
1464                     testPtr->Init();
1465                     testPtr->RunBluetoothCallTest();
1466                 }
1467                 break;
1468             }
1469             default:
1470                 std::cout << "invalid input" << std::endl;
1471                 break;
1472         }
1473         if (code == exitCode) {
1474             break;
1475         }
1476     }
1477     return OHOS::Telephony::TELEPHONY_SUCCESS;
1478 }
1479