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 "bluetooth_call_test.h"
17
18 #include <iostream>
19
20 #include "call_manager_errors.h"
21
22 #include "bluetooth_call_client.h"
23 #include "call_manager_test_types.h"
24 #include "call_manager_callback_test.h"
25
26 namespace OHOS {
27 namespace Telephony {
28 std::shared_ptr<BluetoothCallClient> g_bluetoothCallPtr = nullptr;
29
Init()30 int32_t BluetoothCallTest::Init()
31 {
32 g_bluetoothCallPtr = DelayedSingleton<BluetoothCallClient>::GetInstance();
33 if (g_bluetoothCallPtr == nullptr) {
34 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
35 return TELEPHONY_ERROR;
36 }
37 g_bluetoothCallPtr->Init();
38 std::unique_ptr<CallManagerCallbackTest> callbackPtr = std::make_unique<CallManagerCallbackTest>();
39 if (callbackPtr == nullptr) {
40 std::cout << "make_unique CallManagerCallbackTest failed!" << std::endl;
41 return TELEPHONY_ERROR;
42 }
43 int32_t ret = g_bluetoothCallPtr->RegisterCallBack(std::move(callbackPtr));
44 if (ret != TELEPHONY_SUCCESS) {
45 std::cout << "RegisterCallBack failed!" << std::endl;
46 return TELEPHONY_ERROR;
47 }
48 std::cout << "RegisterCallBack success!" << std::endl;
49 InitFunMap();
50 return TELEPHONY_SUCCESS;
51 }
52
RunBluetoothCallTest()53 void BluetoothCallTest::RunBluetoothCallTest()
54 {
55 int32_t interfaceNum = OHOS::Telephony::DEFAULT_VALUE;
56 const int32_t exitNumber = 1000;
57 while (true) {
58 PrintfUsage();
59 std::cin >> interfaceNum;
60 if (interfaceNum == exitNumber) {
61 std::cout << "start to exit now...." << std::endl;
62 break;
63 }
64 auto itFunc = memberFuncMap_.find(interfaceNum);
65 if (itFunc != memberFuncMap_.end() && itFunc->second != nullptr) {
66 auto BluetoothCallFunc = itFunc->second;
67 (this->*BluetoothCallFunc)();
68 continue;
69 }
70 std::cout << "err: invalid input!" << std::endl;
71 }
72 memberFuncMap_.clear();
73 }
74
PrintfUsage()75 void BluetoothCallTest::PrintfUsage()
76 {
77 std::cout << "\n\n-----------bluetooth call test start--------------\n"
78 << "usage:please input a cmd num:\n"
79 << "0:dial\n"
80 << "1:answer\n"
81 << "2:reject\n"
82 << "3:hangup\n"
83 << "4:getCallState\n"
84 << "5:hold\n"
85 << "6:unhold\n"
86 << "7:switchCall\n"
87 << "8:combineConference\n"
88 << "9:separateConference\n"
89 << "10:startDtmf\n"
90 << "11:stopRtt\n"
91 << "12:isRinging\n"
92 << "13:hasCall\n"
93 << "14:isNewCallAllowed\n"
94 << "15:isInEmergencyCall\n"
95 << "16:setMuted\n"
96 << "17:muteRinger\n"
97 << "18:setAudioDevice\n"
98 << "19:GetCurrentCallList\n"
99 << "1000:exit\n";
100 }
101
InitFunMap()102 void BluetoothCallTest::InitFunMap()
103 {
104 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_DIAL)] = &BluetoothCallTest::DialCall;
105 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_ANSWER)] = &BluetoothCallTest::AnswerCall;
106 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_REJECT)] = &BluetoothCallTest::RejectCall;
107 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_HANGUP)] = &BluetoothCallTest::HangUpCall;
108 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_GET_CALL_STATE)] =
109 &BluetoothCallTest::GetCallState;
110 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_HOLD)] = &BluetoothCallTest::HoldCall;
111 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_UNHOLD)] = &BluetoothCallTest::UnHoldCall;
112 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_SWITCH)] = &BluetoothCallTest::SwitchCall;
113 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_COMBINE_CONFERENCE)] =
114 &BluetoothCallTest::CombineConference;
115 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_SEPARATE_CONFERENCE)] =
116 &BluetoothCallTest::SeparateConference;
117 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_START_DTMF)] = &BluetoothCallTest::StartDtmf;
118 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_STOP_DTMF)] = &BluetoothCallTest::StopDtmf;
119 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_IS_RINGING)] = &BluetoothCallTest::IsRinging;
120 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_HAS_CALL)] = &BluetoothCallTest::HasCall;
121 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_IS_NEW_CALL_ALLOWED)] =
122 &BluetoothCallTest::IsNewCallAllowed;
123 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_IS_IN_EMERGENCY_CALL)] =
124 &BluetoothCallTest::IsInEmergencyCall;
125 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_SET_MUTED)] = &BluetoothCallTest::SetMute;
126 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_MUTE_RINGER)] = &BluetoothCallTest::MuteRinger;
127 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_SET_AUDIO_DEVICE)] =
128 &BluetoothCallTest::SetAudioDevice;
129 memberFuncMap_[static_cast<uint32_t>(BluetoothCallFuncCode::TEST_GET_CURRENT_CALL_LIST)] =
130 &BluetoothCallTest::GetCurrentCallList;
131 }
132
DialCall()133 void BluetoothCallTest::DialCall()
134 {
135 int32_t accountId = DEFAULT_ACCOUNT_ID;
136 int32_t videoState = DEFAULT_VIDEO_STATE;
137 int32_t dialScene = DEFAULT_DIAL_SCENE;
138 int32_t dialType = DEFAULT_DIAL_TYPE;
139 int32_t callType = DEFAULT_CALL_TYPE;
140 std::u16string phoneNumber;
141 std::string tmpStr;
142 AppExecFwk::PacMap dialInfo;
143 std::cout << "------Dial------" << std::endl;
144 std::cout << "please input phone number:" << std::endl;
145 phoneNumber.clear();
146 tmpStr.clear();
147 std::cin >> tmpStr;
148 phoneNumber = Str8ToStr16(tmpStr);
149 std::cout << "you want to call " << tmpStr << std::endl;
150 std::cout << "please input accountId:" << std::endl;
151 std::cin >> accountId;
152 std::cout << "please input videoState[0:audio,1:video]:" << std::endl;
153 std::cin >> videoState;
154 std::cout << "please input dialScene[0:normal,1:privileged,2:emergency]:" << std::endl;
155 std::cin >> dialScene;
156 std::cout << "please input dialType[0:carrier,1:voice mail,2:ott]:" << std::endl;
157 std::cin >> dialType;
158 std::cout << "please input callType[0:cs,1:ims,2:ott]:" << std::endl;
159 std::cin >> callType;
160
161 dialInfo.PutIntValue("accountId", accountId);
162 dialInfo.PutIntValue("videoState", videoState);
163 dialInfo.PutIntValue("dialScene", dialScene);
164 dialInfo.PutIntValue("dialType", dialType);
165 dialInfo.PutIntValue("callType", callType);
166 if (g_bluetoothCallPtr == nullptr) {
167 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
168 return;
169 }
170 int32_t ret = g_bluetoothCallPtr->DialCall(phoneNumber, dialInfo);
171 std::cout << "return value:" << ret << std::endl;
172 }
173
AnswerCall()174 void BluetoothCallTest::AnswerCall()
175 {
176 std::cout << "------Answer------" << std::endl;
177 if (g_bluetoothCallPtr == nullptr) {
178 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
179 return;
180 }
181 int32_t ret = g_bluetoothCallPtr->AnswerCall();
182 std::cout << "return value:" << ret << std::endl;
183 }
184
RejectCall()185 void BluetoothCallTest::RejectCall()
186 {
187 std::cout << "------Reject------" << std::endl;
188 if (g_bluetoothCallPtr == nullptr) {
189 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
190 return;
191 }
192 int32_t ret = g_bluetoothCallPtr->RejectCall();
193 std::cout << "return value:" << ret << std::endl;
194 }
195
HangUpCall()196 void BluetoothCallTest::HangUpCall()
197 {
198 std::cout << "------HangUpCall------" << std::endl;
199 if (g_bluetoothCallPtr == nullptr) {
200 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
201 return;
202 }
203 int32_t ret = g_bluetoothCallPtr->HangUpCall();
204 std::cout << "return value:" << ret << std::endl;
205 }
206
GetCallState()207 void BluetoothCallTest::GetCallState()
208 {
209 std::cout << "------GetCallState------" << std::endl;
210 if (g_bluetoothCallPtr == nullptr) {
211 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
212 return;
213 }
214 int32_t ret = g_bluetoothCallPtr->GetCallState();
215 std::cout << "return value:" << ret << std::endl;
216 }
217
HoldCall()218 void BluetoothCallTest::HoldCall()
219 {
220 std::cout << "------HoldCall------" << std::endl;
221 if (g_bluetoothCallPtr == nullptr) {
222 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
223 return;
224 }
225 int32_t ret = g_bluetoothCallPtr->HoldCall();
226 std::cout << "return value:" << ret << std::endl;
227 }
228
UnHoldCall()229 void BluetoothCallTest::UnHoldCall()
230 {
231 std::cout << "------UnHoldCall------" << std::endl;
232 if (g_bluetoothCallPtr == nullptr) {
233 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
234 return;
235 }
236 int32_t ret = g_bluetoothCallPtr->UnHoldCall();
237 std::cout << "return value:" << ret << std::endl;
238 }
239
CombineConference()240 void BluetoothCallTest::CombineConference()
241 {
242 std::cout << "------CombineConference------" << std::endl;
243 if (g_bluetoothCallPtr == nullptr) {
244 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
245 return;
246 }
247 int32_t ret = g_bluetoothCallPtr->CombineConference();
248 std::cout << "return value:" << ret << std::endl;
249 }
250
SeparateConference()251 void BluetoothCallTest::SeparateConference()
252 {
253 std::cout << "------SeparateConference------" << std::endl;
254 if (g_bluetoothCallPtr == nullptr) {
255 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
256 return;
257 }
258 int32_t ret = g_bluetoothCallPtr->SeparateConference();
259 std::cout << "return value:" << ret << std::endl;
260 }
261
SwitchCall()262 void BluetoothCallTest::SwitchCall()
263 {
264 std::cout << "------SwitchCall------" << std::endl;
265 if (g_bluetoothCallPtr == nullptr) {
266 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
267 return;
268 }
269 int32_t ret = g_bluetoothCallPtr->SwitchCall();
270 std::cout << "return value:" << ret << std::endl;
271 }
272
HasCall()273 void BluetoothCallTest::HasCall()
274 {
275 std::cout << "------HasCall------" << std::endl;
276 if (g_bluetoothCallPtr == nullptr) {
277 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
278 return;
279 }
280 int32_t ret = g_bluetoothCallPtr->HasCall();
281 std::cout << "return value:" << ret << std::endl;
282 }
283
IsNewCallAllowed()284 void BluetoothCallTest::IsNewCallAllowed()
285 {
286 std::cout << "------IsNewCallAllowed------" << std::endl;
287 if (g_bluetoothCallPtr == nullptr) {
288 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
289 return;
290 }
291 int32_t ret = g_bluetoothCallPtr->IsNewCallAllowed();
292 std::cout << "return value:" << ret << std::endl;
293 }
294
IsRinging()295 void BluetoothCallTest::IsRinging()
296 {
297 std::cout << "------IsRinging------" << std::endl;
298 if (g_bluetoothCallPtr == nullptr) {
299 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
300 return;
301 }
302 int32_t ret = g_bluetoothCallPtr->IsRinging();
303 std::cout << "return value:" << ret << std::endl;
304 }
305
IsInEmergencyCall()306 void BluetoothCallTest::IsInEmergencyCall()
307 {
308 std::cout << "------IsInEmergencyCall------" << std::endl;
309 if (g_bluetoothCallPtr == nullptr) {
310 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
311 return;
312 }
313 int32_t ret = g_bluetoothCallPtr->IsInEmergencyCall();
314 std::cout << "return value:" << ret << std::endl;
315 }
316
StartDtmf()317 void BluetoothCallTest::StartDtmf()
318 {
319 char c = DEFAULT_VALUE;
320 std::cout << "------StartDtmf------" << std::endl;
321 std::cout << "Please enter to send dtmf characters:" << std::endl;
322 std::cin >> c;
323 if (g_bluetoothCallPtr == nullptr) {
324 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
325 return;
326 }
327 int32_t ret = g_bluetoothCallPtr->StartDtmf(c);
328 std::cout << "return value:" << ret << std::endl;
329 }
330
StopDtmf()331 void BluetoothCallTest::StopDtmf()
332 {
333 std::cout << "------StopDtmf------" << std::endl;
334 if (g_bluetoothCallPtr == nullptr) {
335 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
336 return;
337 }
338 int32_t ret = g_bluetoothCallPtr->StopDtmf();
339 std::cout << "return value:" << ret << std::endl;
340 }
341
SetMute()342 void BluetoothCallTest::SetMute()
343 {
344 int32_t isMute = DEFAULT_VALUE;
345 std::cout << "------SetMute------" << std::endl;
346 std::cout << "please input mute state(0:false 1:true):" << std::endl;
347 std::cin >> isMute;
348 if (g_bluetoothCallPtr == nullptr) {
349 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
350 return;
351 }
352 int32_t ret = g_bluetoothCallPtr->SetMuted((isMute == 1) ? true : false);
353 std::cout << "return value:" << ret << std::endl;
354 }
355
MuteRinger()356 void BluetoothCallTest::MuteRinger()
357 {
358 std::cout << "------MuteRinger------" << std::endl;
359 if (g_bluetoothCallPtr == nullptr) {
360 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
361 return;
362 }
363 int32_t ret = g_bluetoothCallPtr->MuteRinger();
364 std::cout << "return value:" << ret << std::endl;
365 }
366
SetAudioDevice()367 void BluetoothCallTest::SetAudioDevice()
368 {
369 int32_t deviceType = DEFAULT_VALUE;
370 std::cout << "------SetAudioDevice------" << std::endl;
371 std::cout << "please input device type(0:earpiece 1:speaker 2:wired headset 3:bluetooth sco):" << std::endl;
372 std::cin >> deviceType;
373 if (g_bluetoothCallPtr == nullptr) {
374 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
375 return;
376 }
377 AudioDevice device = AudioDevice::DEVICE_UNKNOWN;
378 device = static_cast<AudioDevice>(deviceType);
379 int32_t ret = g_bluetoothCallPtr->SetAudioDevice(device);
380 std::cout << "return value:" << ret << std::endl;
381 }
382
GetCurrentCallList()383 void BluetoothCallTest::GetCurrentCallList()
384 {
385 int32_t slotId = DEFAULT_VALUE;
386 std::cout << "------GetCurrentCallList------" << std::endl;
387 std::cout << "Please enter slotId:" << std::endl;
388 std::cin >> slotId;
389 if (g_bluetoothCallPtr == nullptr) {
390 std::cout << "g_bluetoothCallPtr is nullptr" << std::endl;
391 return;
392 }
393 std::vector<CallAttributeInfo> callVec = g_bluetoothCallPtr->GetCurrentCallList(slotId);
394 std::cout << "call list count:" << callVec.size() << std::endl;
395 std::vector<CallAttributeInfo>::iterator it = callVec.begin();
396 for (; it != callVec.end(); ++it) {
397 std::cout << "number:" << (*it).accountNumber << ", callState:"
398 << static_cast<int32_t>((*it).callState) << std::endl;
399 }
400 }
401 } // namespace Telephony
402 } // namespace OHOS
403