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